diff --git a/src/plugins/coreplugin/editormanager/editorview.cpp b/src/plugins/coreplugin/editormanager/editorview.cpp index 9d2fe45ba70..67bbf228322 100644 --- a/src/plugins/coreplugin/editormanager/editorview.cpp +++ b/src/plugins/coreplugin/editormanager/editorview.cpp @@ -746,6 +746,7 @@ void SplitterOrView::split(Qt::Orientation orientation, bool activateView) editorView->setCloseSplitEnabled(true); // might have been disabled for root view m_view = nullptr; IEditor *e = editorView->currentEditor(); + const QByteArray state = e ? e->saveState() : QByteArray(); SplitterOrView *view = nullptr; SplitterOrView *otherView = nullptr; @@ -766,6 +767,14 @@ void SplitterOrView::split(Qt::Orientation orientation, bool activateView) otherView->view()->setCloseSplitIcon(Utils::Icons::CLOSE_SPLIT_BOTTOM.icon()); } + if (orientation == Qt::Vertical) { + // give the editor(s) the chance to adapt to the new layout, given the old state + if (duplicate) + duplicate->restoreState(state); + if (e) + e->restoreState(state); + } + if (activateView) EditorManagerPrivate::activateView(otherView->view()); emit splitStateChanged(); diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 8dd3ff712c8..8feac6cbdac 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -2930,7 +2930,7 @@ QByteArray TextEditorWidget::saveState() const { QByteArray state; QDataStream stream(&state, QIODevice::WriteOnly); - stream << 1; // version number + stream << 2; // version number stream << verticalScrollBar()->value(); stream << horizontalScrollBar()->value(); int line, column; @@ -2950,6 +2950,9 @@ QByteArray TextEditorWidget::saveState() const } stream << foldedBlocks; + stream << firstVisibleBlockNumber(); + stream << lastVisibleBlockNumber(); + return state; } @@ -3000,6 +3003,19 @@ bool TextEditorWidget::restoreState(const QByteArray &state) gotoLine(lineVal, columnVal - 1); verticalScrollBar()->setValue(vval); horizontalScrollBar()->setValue(hval); + + if (version >= 2) { + int firstBlock, lastBlock; + stream >> firstBlock; + stream >> lastBlock; + // If current line was visible in the old state, make sure it is visible in the new state. + // This can happen if the height of the editor changed in the meantime + if (firstBlock <= lineVal && lineVal <= lastBlock + && (lineVal < firstVisibleBlockNumber() || lastVisibleBlockNumber() <= lineVal)) { + centerCursor(); + } + } + d->saveCurrentCursorPositionForNavigation(); return true; }