forked from qt-creator/qt-creator
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 <artem.sokolovskii@qt.io>
This commit is contained in:
@@ -53,7 +53,7 @@ public:
|
|||||||
cursor.insertText(textAdded);
|
cursor.insertText(textAdded);
|
||||||
|
|
||||||
for (auto it = blocksPreedit.cbegin(); it != blocksPreedit.cend(); ++it) {
|
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);
|
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;
|
m_syntaxInfoUpdated = SyntaxHighlighter::State::InProgress;
|
||||||
QMap<int, BaseSyntaxHighlighterRunner::BlockPreeditData> blocksPreedit;
|
QMap<int, BaseSyntaxHighlighterRunner::BlockPreeditData> blocksPreedit;
|
||||||
QTextBlock firstBlock = m_document->findBlock(from);
|
QTextBlock block = m_document->findBlock(from);
|
||||||
QTextBlock endBlock = m_document->findBlock(from + charsAdded);
|
const QTextBlock endBlock = m_document->findBlock(from + charsAdded);
|
||||||
while (firstBlock.isValid() && firstBlock.position() < endBlock.position()) {
|
while (block.isValid() && block != endBlock) {
|
||||||
const int position = firstBlock.position();
|
if (QTextLayout *layout = block.layout()) {
|
||||||
if (firstBlock.layout()) {
|
if (const int pos = layout->preeditAreaPosition(); pos != -1)
|
||||||
const int preeditAreaPosition = firstBlock.layout()->preeditAreaPosition();
|
blocksPreedit[block.blockNumber()] = {pos, layout->preeditAreaText()};
|
||||||
const QString preeditAreaText = firstBlock.layout()->preeditAreaText();
|
|
||||||
if (preeditAreaPosition != -1)
|
|
||||||
blocksPreedit[position] = {preeditAreaPosition, preeditAreaText};
|
|
||||||
}
|
}
|
||||||
firstBlock = firstBlock.next();
|
block = block.next();
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString text = Utils::Text::textAt(QTextCursor(m_document), from, charsAdded);
|
const QString text = Utils::Text::textAt(QTextCursor(m_document), from, charsAdded);
|
||||||
cloneDocument(from, charsRemoved, text, blocksPreedit);
|
cloneDocument(from, charsRemoved, text, blocksPreedit);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user