TextEditor: Improve splitting top/bottom

If the text cursor is visible, but in the bottom area of the editor, it
would be no longer visible after splitting. That makes the probable
"area of interest" vanish from sight.

Check that condition (visible before, but would not be visible
afterwards), and if that is the case center the text cursor in both
resulting editors.

Change-Id: I8c8dccd2d9db439c82d0aca34b8ef99fa97aa48e
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2020-02-27 13:45:24 +01:00
parent bd03041428
commit 956fd44c3e
2 changed files with 26 additions and 1 deletions

View File

@@ -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;
}