TextEditor: fix selection highlight

Also compare the anchor when looking for the selection. Otherwise we
might get a selection highlight that expands on adjacent extra
selections like code model warnings.

Change-Id: Ib8460c1089ed69d14b7a408ca70e7ac1f8642f6e
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2020-10-16 14:36:17 +02:00
parent 4946677df4
commit 05ad4e3daa

View File

@@ -4745,7 +4745,8 @@ void TextEditorWidgetPrivate::setupSelections(const PaintEventData &data,
o.start = ts.positionAtColumn(text, m_blockSelection.firstVisualColumn());
o.length = ts.positionAtColumn(text, m_blockSelection.lastVisualColumn()) - o.start;
}
if (data.textCursor.hasSelection() && data.textCursor == range.cursor) {
if (data.textCursor.hasSelection() && data.textCursor == range.cursor
&& data.textCursor.anchor() == range.cursor.anchor()) {
const QTextCharFormat selectionFormat = data.fontSettings.toTextCharFormat(C_SELECTION);
if (selectionFormat.background().style() != Qt::NoBrush)
o.format.setBackground(selectionFormat.background());