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);
|
||||
|
||||
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<int, BaseSyntaxHighlighterRunner::BlockPreeditData> 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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user