TextEditor: fix animate navigation within file

The calculation based on visible lines is not working as
expected when we have collapsed blocks. Using QPlainTextEdit
functions to get the correct target scroll bar value.

Task-number: QTCREATORBUG-19327
Change-Id: I0393fc94ba2a11caeaa77d6d87bc69c6c7de1bb7
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
David Schulz
2017-11-29 12:45:16 +01:00
parent 09f0d1a2ca
commit d0bf2a4528

View File

@@ -2713,24 +2713,19 @@ void TextEditorWidget::gotoLine(int line, int column, bool centerLine, bool anim
const DisplaySettings &ds = d->m_displaySettings;
if (animate && ds.m_animateNavigationWithinFile) {
const QScrollBar *scrollBar = verticalScrollBar();
QScrollBar *scrollBar = verticalScrollBar();
const int start = scrollBar->value();
setTextCursor(cursor);
ensureBlockIsUnfolded(block);
const int visibleLines = lastVisibleLine() - firstVisibleLine();
int end = 0;
auto it = document()->firstBlock();
while (it.isValid() && it != block) {
if (it.isVisible())
++end;
it = it.next();
}
setUpdatesEnabled(false);
setTextCursor(cursor);
if (centerLine)
end = qMin(scrollBar->maximum(), qMax(scrollBar->minimum(), end - visibleLines / 2));
centerCursor();
else
ensureCursorVisible();
const int end = scrollBar->value();
scrollBar->setValue(start);
setUpdatesEnabled(true);
const int delta = end - start;
// limit the number of steps for the animation otherwise you wont be able to tell