forked from qt-creator/qt-creator
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:
@@ -2713,24 +2713,19 @@ void TextEditorWidget::gotoLine(int line, int column, bool centerLine, bool anim
|
|||||||
|
|
||||||
const DisplaySettings &ds = d->m_displaySettings;
|
const DisplaySettings &ds = d->m_displaySettings;
|
||||||
if (animate && ds.m_animateNavigationWithinFile) {
|
if (animate && ds.m_animateNavigationWithinFile) {
|
||||||
const QScrollBar *scrollBar = verticalScrollBar();
|
QScrollBar *scrollBar = verticalScrollBar();
|
||||||
const int start = scrollBar->value();
|
const int start = scrollBar->value();
|
||||||
|
|
||||||
setTextCursor(cursor);
|
|
||||||
ensureBlockIsUnfolded(block);
|
ensureBlockIsUnfolded(block);
|
||||||
|
setUpdatesEnabled(false);
|
||||||
const int visibleLines = lastVisibleLine() - firstVisibleLine();
|
setTextCursor(cursor);
|
||||||
|
|
||||||
int end = 0;
|
|
||||||
auto it = document()->firstBlock();
|
|
||||||
while (it.isValid() && it != block) {
|
|
||||||
if (it.isVisible())
|
|
||||||
++end;
|
|
||||||
it = it.next();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (centerLine)
|
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;
|
const int delta = end - start;
|
||||||
// limit the number of steps for the animation otherwise you wont be able to tell
|
// limit the number of steps for the animation otherwise you wont be able to tell
|
||||||
|
Reference in New Issue
Block a user