diff options
author | David Schulz <david.schulz@qt.io> | 2017-11-29 12:45:16 +0100 |
---|---|---|
committer | David Schulz <david.schulz@qt.io> | 2017-12-01 07:58:43 +0000 |
commit | d0bf2a45283e663104a3e6ba7720f9a345ae9b63 (patch) | |
tree | ba873cdf47afb24ba076f7dc7b07f3f90a80d07e | |
parent | 09f0d1a2ca0deb7606dcc51e0aa787fdad36441e (diff) |
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>
-rw-r--r-- | src/plugins/texteditor/texteditor.cpp | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/plugins/texteditor/texteditor.cpp b/src/plugins/texteditor/texteditor.cpp index 6b6b881779..81d2bb64fb 100644 --- a/src/plugins/texteditor/texteditor.cpp +++ b/src/plugins/texteditor/texteditor.cpp @@ -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 |