Bug: unexpected result of deleting contents of a bookmark

I have an input word document with an enumerated list in it that is bookmarked and some text right after the list. Using Aspose.Words I try to delete the contents of that bookmark. (using Java, lib aspose-words-17.9-jdk16.jar)

When selecting the contents in MS Word and deleting them manually, list is deleted, text after the list isn’t changed. This was the expected result of the output of the attached snippet. Instead, after deleting the contents of the bookmark and saving the edited document, the text that was after the bookmark gets formatted like a first element in a list.

Attaching java snippet and the doc file that replicates the bug:

bookmark.zip (22.6 KB)

@virtus,

You can get the desired output by using any of the following codes:

Document doc = new Document("D:\\Temp\\bookmark\\test.doc");

Bookmark bm = doc.getRange().getBookmarks().get("mark_one");

Paragraph start = (Paragraph) bm.getBookmarkStart().getAncestor(NodeType.PARAGRAPH);
Paragraph end = (Paragraph) bm.getBookmarkEnd().getAncestor(NodeType.PARAGRAPH);

bm.setText("");
bm.remove();

start.getListFormat().setList(null);
end.getListFormat().setList(null);

doc.save("D:\\Temp\\bookmark\\awjava-18.3.doc");

Long workaround code:

Document doc = new Document("D:\\Temp\\bookmark\\test.doc");

Bookmark bm = doc.getRange().getBookmarks().get("mark_one");

Paragraph start = (Paragraph) bm.getBookmarkStart().getAncestor(NodeType.PARAGRAPH);
Paragraph end = (Paragraph) bm.getBookmarkEnd().getAncestor(NodeType.PARAGRAPH);

ArrayList arrayList = new ArrayList();

Node currentNode = bm.getBookmarkStart();
boolean isContinue = true;
while (currentNode != null && isContinue) {
    if (currentNode == bm.getBookmarkEnd())
        isContinue = false;

    if (currentNode.getNodeType() == (NodeType.RUN)) {
        arrayList.add(currentNode);
    }

    Node nextNode = currentNode.nextPreOrder(currentNode.getDocument());
    currentNode = nextNode;
}

for(int i=0; i<arrayList.size();i++) {
    ((Node) arrayList.get(i)).remove();
}

arrayList = new ArrayList();
currentNode = bm.getBookmarkStart();
isContinue = true;
while (currentNode != null && isContinue) {
    if (currentNode == bm.getBookmarkEnd())
        isContinue = false;

    if (currentNode.getNodeType() == (NodeType.PARAGRAPH)) {
        if (currentNode.toString(SaveFormat.TEXT).trim().equals(""))
            arrayList.add(currentNode);
    }

    Node nextNode = currentNode.nextPreOrder(currentNode.getDocument());
    currentNode = nextNode;
}

for(int i=0; i<arrayList.size();i++) {
    ((Node) arrayList.get(i)).remove();
}

start.remove();
bm.remove();

doc.save("D:\\Temp\\bookmark\\awjava-18.3.doc");