Writer - UNO API - Java - Cursor error when creates a table with start and end dynamic fields

Hello everyone,

I’m having trouble solving a bug that is happening after version 7.4 of LibreOffice.

In short, I have my own java plugin that creates a table with start and end dynamic fields to be processed later.

Following there is a snippet of the code that works correctly up to version 7.3

final XTextTable xTextTable = getCurrentTable(currentCursor);
final XTextRange xStartTable = xTextTable.getAnchor().getStart();
final XTextRange xEndTable = xTextTable.getAnchor().getEnd();        
final XTextViewCursor textViewCursor = getTextViewCursor();
final XLineCursor lineCursor = getLineCursor(textViewCursor);
final XText xText = getTextFromCurrentDocument();
final XTextCursor xCursor = createTextCursor(xText);
final XParagraphCursor xParagraphCursor = getParagraphCursor(xCursor);

// moves the cursor to the line right before the table
textViewCursor.gotoRange(xStartTable, false);

// moves the cursor to the end of the line right before the table
lineCursor.gotoEndOfLine(false);
xCursor.gotoRange(textViewCursor.getStart(), false);

// creates a new dynamic field in a new paragraph
createDynamicFieldInsideParagraph(xParagraphCursor.getStart());

// moves the cursor to the line right after the table
textViewCursor.gotoRange(xEndTable, false);
textViewCursor.gotoEnd(false);

// moves the cursor to the beginning of the line right after the table
lineCursor.gotoStartOfLine(false);
xCursor.gotoRange(textViewCursor.getEnd(), false);

// creates a new dynamic field in a new paragraph
createDynamicFieldInsideParagraph(xParagraphCursor.getStart(), true);

// moves the cursor to the position the user first selected
textViewCursor.gotoRange(currentCursor, false);

Here is an example of how it should be in the document:

All my attempts of fixing the problem were unsuccessful and I’m out of ideas.
It always end up in some internal error at UNO API. Sometimes is a generic error, sometimes a cursor error (“there’s no beginning/end”) and sometimes the dynamic fields end up inside the table cells (as unwanted).

Is there anyone who can give an idea of solution? Any help?

Unfortunately, that is completely impossible to reproduce your problem using that snippet, to be able to advise anything. Please provide a reliable reproducer code. Indeed, try also with a clean user profile, and with a current version of LibreOffice. Your OS details are also important. It all would possibly require to file a bug report.

2 Likes

Hi,
I pushed an code on GH for reproduces this bug.

Thanks for support.