From 76ec7e15990319c81e8265076adef45ad5cff4b9 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 21 Dec 2023 14:38:29 +0100 Subject: [PATCH] TextEditor: use blocknumber instead of position to identify blocks It is used more commenly in the code for that purpose. Change-Id: I48112d2c80485d204137da36fadbe85ad1db802b Reviewed-by: Artem Sokolovskii --- .../texteditor/syntaxhighlighterrunner.cpp | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/plugins/texteditor/syntaxhighlighterrunner.cpp b/src/plugins/texteditor/syntaxhighlighterrunner.cpp index a1241d87e2f..99ff3564941 100644 --- a/src/plugins/texteditor/syntaxhighlighterrunner.cpp +++ b/src/plugins/texteditor/syntaxhighlighterrunner.cpp @@ -53,7 +53,7 @@ public: cursor.insertText(textAdded); for (auto it = blocksPreedit.cbegin(); it != blocksPreedit.cend(); ++it) { - const QTextBlock block = m_document->findBlock(it.key()); + const QTextBlock block = m_document->findBlockByNumber(it.key()); block.layout()->setPreeditArea(it.value().position, it.value().text); } } @@ -160,19 +160,15 @@ void BaseSyntaxHighlighterRunner::cloneDocumentData(int from, int charsRemoved, { m_syntaxInfoUpdated = SyntaxHighlighter::State::InProgress; QMap blocksPreedit; - QTextBlock firstBlock = m_document->findBlock(from); - QTextBlock endBlock = m_document->findBlock(from + charsAdded); - while (firstBlock.isValid() && firstBlock.position() < endBlock.position()) { - const int position = firstBlock.position(); - if (firstBlock.layout()) { - const int preeditAreaPosition = firstBlock.layout()->preeditAreaPosition(); - const QString preeditAreaText = firstBlock.layout()->preeditAreaText(); - if (preeditAreaPosition != -1) - blocksPreedit[position] = {preeditAreaPosition, preeditAreaText}; + QTextBlock block = m_document->findBlock(from); + const QTextBlock endBlock = m_document->findBlock(from + charsAdded); + while (block.isValid() && block != endBlock) { + if (QTextLayout *layout = block.layout()) { + if (const int pos = layout->preeditAreaPosition(); pos != -1) + blocksPreedit[block.blockNumber()] = {pos, layout->preeditAreaText()}; } - firstBlock = firstBlock.next(); + block = block.next(); } - const QString text = Utils::Text::textAt(QTextCursor(m_document), from, charsAdded); cloneDocument(from, charsRemoved, text, blocksPreedit); }