diff options
author | David Schulz <david.schulz@qt.io> | 2020-09-10 14:05:30 +0200 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2020-09-11 11:48:29 +0000 |
commit | 3b23cab38579ab719e5aa7726c2007b9cb040f1e (patch) | |
tree | ae4d3f5b899617fc14eca4c566d61dd27469e52d | |
parent | a89e3e22b9058298ae881ca4cb48f2e0c573ca86 (diff) |
TextEditor: Use selection format from the setting
Overwrites the format generated by QPlainTextEdit::getPaintContext()
Amends 9182d4eda75033bbbebf50e87e518adc33d499f6.
Fixes: QTCREATORBUG-24479
Change-Id: Ia226a74442dbbdbae42e8da5dee9e4d7399b677c
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
-rw-r--r-- | src/plugins/texteditor/texteditor.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index fc9310607c..07f8570483 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -468,7 +468,6 @@ struct PaintEventBlockData { QRectF boundingRect; QVector<QTextLayout::FormatRange> selections; - QVector<QTextLayout::FormatRange> prioritySelections; QRectF blockSelectionCursorRect; QTextLayout *layout = nullptr; int position = 0; @@ -4704,6 +4703,7 @@ void TextEditorWidgetPrivate::setupBlockLayout(const PaintEventData &data, void TextEditorWidgetPrivate::setupSelections(const PaintEventData &data, PaintEventBlockData &blockData) const { + QVector<QTextLayout::FormatRange> prioritySelections; for (int i = 0; i < data.context.selections.size(); ++i) { const QAbstractTextDocumentLayout::Selection &range = data.context.selections.at(i); const int selStart = range.cursor.selectionStart() - blockData.position; @@ -4720,18 +4720,25 @@ 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) { + const QTextCharFormat selectionFormat = data.fontSettings.toTextCharFormat(C_SELECTION); + if (selectionFormat.background().style() != Qt::NoBrush) + o.format.setBackground(selectionFormat.background()); + if (selectionFormat.foreground().style() != Qt::NoBrush) + o.format.setForeground(selectionFormat.foreground()); + } if ((data.textCursor.hasSelection() && i == data.context.selections.size() - 1) || (o.format.foreground().style() == Qt::NoBrush && o.format.underlineStyle() != QTextCharFormat::NoUnderline && o.format.background() == Qt::NoBrush)) { if (q->selectionVisible(data.block.blockNumber())) - blockData.prioritySelections.append(o); + prioritySelections.append(o); } else { blockData.selections.append(o); } } } - blockData.selections += blockData.prioritySelections; + blockData.selections.append(prioritySelections); } void TextEditorWidgetPrivate::setupCursorPosition(PaintEventData &data, |