diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 1608cb58dde..625bb8bee56 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -4219,7 +4219,7 @@ void BaseTextEditor::setExtraSelections(ExtraSelectionKind kind, const QListm_overlay->clear(); foreach (const QTextEdit::ExtraSelection &selection, d->m_extraSelections[kind]) { - d->m_overlay->addOverlaySelection(selection.cursor, selection.format.background().color()); + d->m_overlay->addOverlaySelection(selection.cursor, selection.format.background().color(), true); } d->m_overlay->setVisible(!d->m_overlay->isEmpty()); diff --git a/src/plugins/texteditor/texteditoroverlay.cpp b/src/plugins/texteditor/texteditoroverlay.cpp index 0639a2f5817..5c9d621a836 100644 --- a/src/plugins/texteditor/texteditoroverlay.cpp +++ b/src/plugins/texteditor/texteditoroverlay.cpp @@ -36,9 +36,9 @@ void TextEditorOverlay::clear() update(); } -void TextEditorOverlay::addOverlaySelection(int begin, int end, const QColor &color) +void TextEditorOverlay::addOverlaySelection(int begin, int end, const QColor &color, bool lockSize) { - if (end <= begin) + if (end < begin) return; QTextDocument *document = m_editor->document(); @@ -52,16 +52,17 @@ void TextEditorOverlay::addOverlaySelection(int begin, int end, const QColor &co selection.m_cursor_end = QTextCursor(document); selection.m_cursor_end.setPosition(end); + if (lockSize) + selection.m_fixedLength = (end - begin); + m_selections += selection; update(); } -void TextEditorOverlay::addOverlaySelection(const QTextCursor &cursor, const QColor &color) +void TextEditorOverlay::addOverlaySelection(const QTextCursor &cursor, const QColor &color, bool lockSize) { - if (!cursor.hasSelection()) - return; - addOverlaySelection(cursor.selectionStart(), cursor.selectionEnd(), color); + addOverlaySelection(cursor.selectionStart(), cursor.selectionEnd(), color, lockSize); } QRect TextEditorOverlay::rect() const @@ -243,6 +244,11 @@ void TextEditorOverlay::paint(QPainter *painter, const QRect &clip) Q_UNUSED(clip); for (int i = 0; i < m_selections.size(); ++i) { const OverlaySelection &selection = m_selections.at(i); + if (selection.m_fixedLength >= 0 + && selection.m_cursor_end.position() - selection.m_cursor_begin.position() + != selection.m_fixedLength) + continue; + paintSelection(painter, selection.m_cursor_begin, selection.m_cursor_end, diff --git a/src/plugins/texteditor/texteditoroverlay.h b/src/plugins/texteditor/texteditoroverlay.h index a60e0ed8d23..6516b69bca9 100644 --- a/src/plugins/texteditor/texteditoroverlay.h +++ b/src/plugins/texteditor/texteditoroverlay.h @@ -8,9 +8,11 @@ namespace TextEditor { namespace Internal { struct TEXTEDITOR_EXPORT OverlaySelection { + OverlaySelection():m_fixedLength(-1){} QTextCursor m_cursor_begin; QTextCursor m_cursor_end; QColor m_color; + int m_fixedLength; }; class TEXTEDITOR_EXPORT TextEditorOverlay : public QObject @@ -38,8 +40,8 @@ public: void update(); void clear(); - void addOverlaySelection(const QTextCursor &cursor, const QColor &color); - void addOverlaySelection(int begin, int end, const QColor &color); + void addOverlaySelection(const QTextCursor &cursor, const QColor &color, bool lockSize = false); + void addOverlaySelection(int begin, int end, const QColor &color, bool lockSize = false); inline bool isEmpty() const { return m_selections.isEmpty(); }