From 3b23cab38579ab719e5aa7726c2007b9cb040f1e Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 10 Sep 2020 14:05:30 +0200 Subject: 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 --- src/plugins/texteditor/texteditor.cpp | 13 ++++++++++--- 1 file 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 selections; - QVector 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 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, -- cgit v1.2.3