TextEditor: Allow to programmatically highlight a block by cursor

This can be used in QmlDesigner to highlight the currently selected
QML object.

Change-Id: I9907d54f767c7d034739d4111a46cd994c961426
Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
Reviewed-by: Henning Gründl <henning.gruendl@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Thomas Hartmann
2023-11-08 15:34:06 +01:00
parent ad49605ea9
commit 070022e9e2
2 changed files with 16 additions and 6 deletions

View File

@@ -6240,9 +6240,6 @@ void TextEditorWidget::updateFoldingHighlight(const QPoint &pos)
QTextCursor cursor = cursorForPosition(QPoint(0, pos.y()));
// Update which folder marker is highlighted
const int highlightBlockNumber = d->extraAreaHighlightFoldedBlockNumber;
d->extraAreaHighlightFoldedBlockNumber = -1;
int boxWidth = 0;
if (TextEditorSettings::fontSettings().relativeLineSpacing() == 100)
boxWidth = foldBoxWidth(fontMetrics());
@@ -6250,13 +6247,25 @@ void TextEditorWidget::updateFoldingHighlight(const QPoint &pos)
boxWidth = foldBoxWidth();
if (pos.x() > extraArea()->width() - boxWidth) {
d->extraAreaHighlightFoldedBlockNumber = cursor.blockNumber();
updateFoldingHighlight(cursor);
} else if (d->m_displaySettings.m_highlightBlocks) {
QTextCursor cursor = textCursor();
d->extraAreaHighlightFoldedBlockNumber = cursor.blockNumber();
updateFoldingHighlight(cursor);
} else {
updateFoldingHighlight(QTextCursor());
}
}
if (highlightBlockNumber != d->extraAreaHighlightFoldedBlockNumber)
void TextEditorWidget::updateFoldingHighlight(const QTextCursor &cursor)
{
const int highlightBlockNumber = d->extraAreaHighlightFoldedBlockNumber;
const bool curserIsNull = !cursor.isNull();
if (curserIsNull)
d->extraAreaHighlightFoldedBlockNumber = cursor.blockNumber();
else
d->extraAreaHighlightFoldedBlockNumber = -1;
if (curserIsNull || (highlightBlockNumber != d->extraAreaHighlightFoldedBlockNumber))
d->m_highlightBlocksTimer.start(d->m_highlightBlocksInfo.isEmpty() ? 120 : 0);
}