Description: I have a document with bookmarks. Each bookmark has text. There is a macro that makes the bookmark text empty. After running the macro, some bookmarks disappear. Those bookmarks that consist of one paragraph completely disappear. Steps to Reproduce: 1.Open document 'whereIsMyBookmark' 2.Look at the bookmarks (Insert->Bookmark) 3.Run macro 'Main' 4.Look at the bookmarks again Actual Results: Not only the bookmark text disappears, but also the bookmark itself Expected Results: The bookmark should not disappear Reproducible: Always User Profile Reset: No Additional Info: 1. A bookmark whose text consists of a paragraph disappears. 2. A bookmark whose text consists of a word does not disappear. But a bookmark created immediately without text and one created by a macro look different.
Created attachment 190812 [details] Document showing the disappearance of a bookmark
In the previous version it works as it should: Version: 7.4.2.3 / LibreOffice Community Build ID: 40(Build:3) CPU threads: 4; OS: FreeBSD 13.1; UI render: default; VCL: qt5 (cairo+xcb) Locale: en-US (en_EN.UTF-8); UI: en-US Calc: threaded
I think I can reproduce it on my MacOS as well. However, if I add more text before the {PARAGRAPH} bookmark, all the bookmarks remain. Can you confirm @JBrown?
Created attachment 190879 [details] add-text-before-bookmark
Created attachment 190880 [details] Reproducible-MacOS
(In reply to ToanTran from comment #3) That is exactly what JBrown reported, isn't it? Are you asking JBrown to confirm comment 0?
thinking the basic problem here is that the API only has this "setString" method, but no way to indicate whether the intent is to *delete* or to *replace* text. these are different operations: deleting means that things like objects anchored in the deletion range and bookmarks should be deleted too, while replacing means that the current text should be deleted but the anchored objects should remain. so the best idea i had is that setString("") would be interpreted as *delete* and any other setString call as *replace*. the behavior when selecting an entire paragraph was changed in commit baf8d2c1c16cb3bdc4edad2560f95fea807a034f because in this situation it was actually quite difficult to get rid of the bookmark if the user does want to delete it, as no selection that is larger than the bookmark is possible inside the paragraph (and there may be no preceding or following paragraph). so i'm going to call the new behavior a feature not a bug, but of course i'm biased...
(In reply to Michael Stahl (allotropia) from comment #7) > > the behavior when selecting an entire paragraph was changed in commit > baf8d2c1c16cb3bdc4edad2560f95fea807a034f => bibisectNotNeeded
Michael Stahl committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/b0d4b4664a295631ce4d8dee2ceb5cd94ae12edb tdf#158198 sw: prevent xBookmark.getAnchor().setString("") from deleting It will be available in 25.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
a new idea occurred to me, we can special case the anchor of a bookmark so that calling setString() on it will replace rather than delete the text, then the bookmark survives that. of course this only works on the XTextRange that's returned from getAnchor() fixed on master
Michael Stahl committed a patch related to this issue. It has been pushed to "libreoffice-25-2": https://git.libreoffice.org/core/commit/aca6f30c6769ad5573724ffa3a42a595cb20b7fb tdf#158198 sw: prevent xBookmark.getAnchor().setString("") from deleting It will be available in 25.2.1. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Michael Stahl committed a patch related to this issue. It has been pushed to "libreoffice-24-8": https://git.libreoffice.org/core/commit/fe5635c78557ef9f51e3bac1d782cf1c8555655d tdf#158198 sw: prevent xBookmark.getAnchor().setString("") from deleting It will be available in 24.8.6. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Xisco Fauli committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/core/commit/6a680ef017e5a842113f4eb4b555acb51e921f20 tdf#158198: sw_uiwriter6: Add unittest It will be available in 25.8.0. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
Michael Stahl committed a patch related to this issue. It has been pushed to "libreoffice-24-8-5": https://git.libreoffice.org/core/commit/2273885b0785b91546962925e5ec44326eb302de tdf#158198 sw: prevent xBookmark.getAnchor().setString("") from deleting It will be available in 24.8.5. The patch should be included in the daily builds available at https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: https://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.