Bug 158198 - My macro changes the bookmark text and the bookmark disappears
Summary: My macro changes the bookmark text and the bookmark disappears
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
7.5.4.2 release
Hardware: x86-64 (AMD64) All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: bibisectNotNeeded, regression
Depends on:
Blocks: Bookmarks 104659
  Show dependency treegraph
 
Reported: 2023-11-13 15:25 UTC by JBrown
Modified: 2023-11-29 19:33 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
Document showing the disappearance of a bookmark (12.92 KB, application/vnd.oasis.opendocument.text)
2023-11-13 15:29 UTC, JBrown
Details
add-text-before-bookmark (37.55 KB, image/png)
2023-11-16 18:06 UTC, ToanTran
Details
Reproducible-MacOS (12.39 MB, video/quicktime)
2023-11-16 18:07 UTC, ToanTran
Details

Note You need to log in before you can comment on or make changes to this bug.
Description JBrown 2023-11-13 15:25:06 UTC
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.
Comment 1 JBrown 2023-11-13 15:29:34 UTC
Created attachment 190812 [details]
Document showing the disappearance of a bookmark
Comment 2 JBrown 2023-11-13 15:34:03 UTC
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
Comment 3 ToanTran 2023-11-16 18:06:00 UTC
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?
Comment 4 ToanTran 2023-11-16 18:06:37 UTC
Created attachment 190879 [details]
add-text-before-bookmark
Comment 5 ToanTran 2023-11-16 18:07:22 UTC
Created attachment 190880 [details]
Reproducible-MacOS
Comment 6 Mike Kaganski 2023-11-19 17:34:49 UTC
(In reply to ToanTran from comment #3)

That is exactly what JBrown reported, isn't it? Are you asking JBrown to confirm comment 0?
Comment 7 Michael Stahl (allotropia) 2023-11-22 18:44:02 UTC
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...
Comment 8 raal 2023-11-26 08:54:36 UTC
(In reply to Michael Stahl (allotropia) from comment #7)
> 
> the behavior when selecting an entire paragraph was changed in commit
> baf8d2c1c16cb3bdc4edad2560f95fea807a034f 

=> bibisectNotNeeded