AsposeBookmarkTest.zip (46.8 KB)
Good afternoon Aspose.Words Support, we have recently updated from 20.2.0 to 22.7.0 and we noticed a change in behavior with Bookmarks.
We have a template that has the following structure
Para - P1
Run
Para2 - P2
Run - R2.1
Run - R2.2
BookmarkStart - BM1
Run
Run
BookmarkStart - _GoBack
BookmarkEnd - _GoBack
BookmarkEnd - BM1
Para - P3
Run - R3.1
If we get a reference to BM1 and then call
bookmark.Text = "";
bookmark.Remove();
we are seeing different results starting with Aspose.Words 21.10.0
In the upgrades from 20.2.0 up to 21.9.0 we would see the nodes inside of P3 moved into P2 because we would see the styling of P2 used in the output document. The output would look like
Para - P1
Run
Para2 - P2
Run - R2.1
Run - R2.2
Run - R3.1
In the upgrade to 21.10 we are seeing the two Runs at the start of P2 are moved to P3 and P2 is removed
Para - P1
Run
Para - P3
Run - R2.1
Run - R2.2
Run - R3.1
Both of these behaviors are different than what Word does if I follow these steps which conceptually sound the same as what Aspose.Words is doing. The steps I take in Word are
- Go to Insert > Bookmark
- Select the bookmark “false” and hit the “Go To” button
- Close the Bookmark dialog
- hit DEL key on keyboard to remove the text Word has selected
- hit DEL key on keyboard to remove the Bookmark that has nothing in it
Word will create an output document with the structure
Para - P1
Run
Para2 - P2
Run - R2.1
Run - R2.2
Run - R3.1
I liked the way Aspose.Words 21.9.0 and before handled it and is the way many Templates have been setup to handle where it would combine P2 and P3 into P2. That behavior is what happens in Word when you hit the DEL key twice and generates the documents they way they are used to.
I will attach a sample sln/csproj that shows the code used to test this.
There will also be 4 documents in there
- FormatChange.dotx - this is the starting template that contains the Bookmark
- FormatChange-20.2.0.docx - this is the output document when using Aspose.Words 20.2.0
- FormatChange-21.10.0.docx - this is the output document when using Aspose.Words 21.10.0
- FormatChange-WordEdit.docx - this is output document using using Word to perform the same steps
This change in behavior seems likely to have been caused by WORDSNET-19767 that was created from this forum post
https://forum.aspose.com/t/paragraphformat-issues-after-removing-bookmark-content/207013