Commit d0bf2a45 authored by David Schulz's avatar David Schulz

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's avatarChristian Stenger <christian.stenger@qt.io>
parent 09f0d1a2
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment