Commit 609e3c7f authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Update the current line highlight when its color might have changed

Fixes the issue where it would stay the color of the previous color
scheme until you change the cursor position.
parent fd3fb099
...@@ -1245,7 +1245,7 @@ bool BaseTextEditor::isParenthesesMatchingEnabled() const ...@@ -1245,7 +1245,7 @@ bool BaseTextEditor::isParenthesesMatchingEnabled() const
void BaseTextEditor::setHighlightCurrentLine(bool b) void BaseTextEditor::setHighlightCurrentLine(bool b)
{ {
d->m_highlightCurrentLine = b; d->m_highlightCurrentLine = b;
slotCursorPositionChanged(); updateCurrentLineHighlight();
} }
bool BaseTextEditor::highlightCurrentLine() const bool BaseTextEditor::highlightCurrentLine() const
...@@ -2582,6 +2582,22 @@ void BaseTextEditor::saveCurrentCursorPositionForNavigation() ...@@ -2582,6 +2582,22 @@ void BaseTextEditor::saveCurrentCursorPositionForNavigation()
d->m_tempNavigationState = saveState(); d->m_tempNavigationState = saveState();
} }
void BaseTextEditor::updateCurrentLineHighlight()
{
QList<QTextEdit::ExtraSelection> extraSelections;
if (d->m_highlightCurrentLine) {
QTextEdit::ExtraSelection sel;
sel.format.setBackground(d->m_currentLineFormat.background());
sel.format.setProperty(QTextFormat::FullWidthSelection, true);
sel.cursor = textCursor();
sel.cursor.clearSelection();
extraSelections.append(sel);
}
setExtraSelections(CurrentLineSelection, extraSelections);
}
void BaseTextEditor::slotCursorPositionChanged() void BaseTextEditor::slotCursorPositionChanged()
{ {
if (!d->m_contentsChanged && d->m_lastCursorChangeWasInteresting) { if (!d->m_contentsChanged && d->m_lastCursorChangeWasInteresting) {
...@@ -2602,18 +2618,7 @@ void BaseTextEditor::slotCursorPositionChanged() ...@@ -2602,18 +2618,7 @@ void BaseTextEditor::slotCursorPositionChanged()
} }
} }
QList<QTextEdit::ExtraSelection> extraSelections; updateCurrentLineHighlight();
if (d->m_highlightCurrentLine) {
QTextEdit::ExtraSelection sel;
sel.format.setBackground(d->m_currentLineFormat.background());
sel.format.setProperty(QTextFormat::FullWidthSelection, true);
sel.cursor = textCursor();
sel.cursor.clearSelection();
extraSelections.append(sel);
}
setExtraSelections(CurrentLineSelection, extraSelections);
if (d->m_displaySettings.m_highlightBlocks) { if (d->m_displaySettings.m_highlightBlocks) {
QTextCursor cursor = textCursor(); QTextCursor cursor = textCursor();
...@@ -3898,7 +3903,8 @@ void BaseTextEditor::setFontSettings(const TextEditor::FontSettings &fs) ...@@ -3898,7 +3903,8 @@ void BaseTextEditor::setFontSettings(const TextEditor::FontSettings &fs)
d->m_matchFormat.setForeground(parenthesesFormat.foreground()); d->m_matchFormat.setForeground(parenthesesFormat.foreground());
d->m_rangeFormat.setBackground(parenthesesFormat.background()); d->m_rangeFormat.setBackground(parenthesesFormat.background());
slotUpdateExtraAreaWidth(); slotUpdateExtraAreaWidth(); // Adjust to new font width
updateCurrentLineHighlight(); // Make sure it takes the new color
} }
void BaseTextEditor::setTabSettings(const TabSettings &ts) void BaseTextEditor::setTabSettings(const TabSettings &ts)
......
...@@ -526,6 +526,7 @@ private: ...@@ -526,6 +526,7 @@ private:
void moveLineUpDown(bool up); void moveLineUpDown(bool up);
void copyLineUpDown(bool up); void copyLineUpDown(bool up);
void saveCurrentCursorPositionForNavigation(); void saveCurrentCursorPositionForNavigation();
void updateCurrentLineHighlight();
void drawFoldingMarker(QPainter *painter, const QPalette &pal, void drawFoldingMarker(QPainter *painter, const QPalette &pal,
const QRect &rect, const QRect &rect,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment