diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index e90af4d627f..8dd3ff712c8 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -646,6 +646,7 @@ public: MarginSettings m_marginSettings; // apply when making visible the first time, for the split case bool m_fontSettingsNeedsApply = true; + bool m_wasNotYetShown = true; BehaviorSettings m_behaviorSettings; int extraAreaSelectionAnchorBlockNumber = -1; @@ -4331,16 +4332,12 @@ void TextEditorWidgetPrivate::paintCurrentLineHighlight(const PaintEventData &da QRectF lineRect = data.block.layout()->lineForTextPosition(data.textCursor.positionInBlock()).rect(); lineRect.moveTop(lineRect.top() + blockRect.top()); lineRect.setLeft(0); - lineRect.setRight(data.viewportRect.width() - data.offset.x()); + lineRect.setRight(data.viewportRect.width()); QColor color = m_document->fontSettings().toTextCharFormat(C_CURRENT_LINE).background().color(); // set alpha, otherwise we cannot see block highlighting and find scope underneath color.setAlpha(128); - if (!data.eventRect.contains(lineRect.toRect())) { - QRect updateRect = data.eventRect; - updateRect.setLeft(0); - updateRect.setRight(data.viewportRect.width() - int(data.offset.x())); - q->viewport()->update(updateRect); - } + if (!data.eventRect.contains(lineRect.toRect())) + q->viewport()->update(lineRect.toRect()); painter.fillRect(lineRect, color); } @@ -7217,10 +7214,20 @@ void TextEditorWidget::encourageApply() void TextEditorWidget::showEvent(QShowEvent* e) { triggerPendingUpdates(); + // QPlainTextEdit::showEvent scrolls to make the cursor visible on first show + // which we don't want, since we restore previous states when + // opening editors, and when splitting/duplicating. + // So restore the previous state after that. + QByteArray state; + if (d->m_wasNotYetShown) + state = saveState(); QPlainTextEdit::showEvent(e); + if (d->m_wasNotYetShown) { + restoreState(state); + d->m_wasNotYetShown = false; + } } - void TextEditorWidgetPrivate::applyFontSettingsDelayed() { m_fontSettingsNeedsApply = true;