LibreOffice XParagraphCursor 在空行时卡住

LibreOffice XParagraphCursor stuck when blank line

我有一个代码在 LibreOffice 5 之前一直运行良好。但是在 LibreOffice 6(32 位和 64 位)中它停止工作了。

public String getNextSentenceOO() {
    while (moreParagraphsOO) {
        while (moreSentencesOO) {
            xSentenceCursor.gotoEndOfSentence(true);
            textSentence = xSentenceCursor.getString();
            xTextViewCursor.gotoRange(xSentenceCursor.getStart(), false);
            xTextViewCursor.gotoRange(xSentenceCursor.getEnd(), true);
            if (!textSentence.equals("")) {
                return textSentence;
            }

            moreSentencesOO = xSentenceCursor.gotoNextSentence(false);

            if (xSentenceCursor.isEndOfSentence() && !xSentenceCursor.isStartOfSentence()){
                moreSentencesOO = false;
            }                
        }
        
        moreParagraphsOO = xParagraphCursor.gotoNextParagraph(false);
        moreSentencesOO = xSentenceCursor.gotoStartOfSentence(false);
    }
    return null;
}

文档中存在空行时出现问题。在那种情况下,指令:

moreParagraphsOO = xParagraphCursor.gotoNextParagraph(false);

并没有使光标前进到下一段,它停留在原处,因此函数进入死循环。有什么想法吗?

正如我所说,这在 LibreOffice 4 和 5(甚至在 LO5 的最新版本)中运行完美。它在 LO6 中停止工作。

枚举段落,而不是段落光标。来自 Andrew Pitonyak's Macro Document 的清单 7.52:

oParEnum = ThisComponent.getText().createEnumeration()
Do While oParEnum.hasMoreElements()
    oPar = oParEnum.nextElement()

此外,清单 7.65 中有一条注释可能与您的问题相关:

REM In this example, I assume that there is text after
REM the text section. If there is not, then this is
REM an infinite loop. You had better verify that
REM gotoNextParagraph does not return False.
Do While NOT IsEmpty(oCurs.TextSection)
    oCurs.gotoNextParagraph(False)
Loop