Commit cfb0af25 authored by loh.tar's avatar loh.tar
Browse files

ViewInternal: Fix makeVisible(..)

Summary:
- Proper calculation of new position to scroll
- Don't force to center cursor in view in most cases.
  This change looks slightly dangerous but nobody knows
  why that was done. So we give it a try now!

BUG: 399014
BUG: 306745
FIXED-IN: 5.58

Differential Revision: https://phabricator.kde.org/D17857
parent 9c957a36
......@@ -354,7 +354,7 @@ void KateViewTest::testKillline()
void KateViewTest::testScrollPastEndOfDocument()
{
#if 0 // bug still exists, see bug 306745
// bug 306745
KTextEditor::DocumentPrivate doc;
doc.setText(QStringLiteral("0000000000\n"
"1111111111\n"
......@@ -384,7 +384,6 @@ void KateViewTest::testScrollPastEndOfDocument()
QCOMPARE(view->cursorPosition(), KTextEditor::Cursor(4, 5));
// verify, that only lines 3333333333 and 4444444444 are still visible.
QCOMPARE(view->firstDisplayedLineInternal(KTextEditor::View::RealLine), 3);
#endif
}
void KateViewTest::testFoldFirstLine()
......
......@@ -1491,7 +1491,7 @@ bool KTextEditor::ViewPrivate::setCursorPositionInternal(const KTextEditor::Curs
x += position.column() - z;
}
m_viewInternal->updateCursor(KTextEditor::Cursor(position.line(), x), false, true, calledExternally);
m_viewInternal->updateCursor(KTextEditor::Cursor(position.line(), x), false, false, calledExternally);
return true;
}
......
......@@ -708,14 +708,17 @@ void KateViewInternal::makeVisible(const KTextEditor::Cursor &c, int endCol, boo
//if ( doc()->foldingTree()->findNodeForLine( c.line )->visible )
// qCDebug(LOG_KTE)<<"line ("<<c.line<<") should be visible";
const int lnDisp = linesDisplayed();
const bool curBelowScreen = (cache()->displayViewLine(c, true) < 0 && cache()->displayViewLine(c, false) > 0);
if (force) {
KTextEditor::Cursor scroll = c;
scrollPos(scroll, force, calledExternally);
} else if (center && (c < startPos() || c > endPos())) {
KTextEditor::Cursor scroll = viewLineOffset(c, -int(linesDisplayed()) / 2);
KTextEditor::Cursor scroll = viewLineOffset(c, -int(lnDisp) / 2);
scrollPos(scroll, false, calledExternally);
} else if (c > viewLineOffset(startPos(), linesDisplayed() - m_minLinesVisible - 1)) {
KTextEditor::Cursor scroll = viewLineOffset(c, -(linesDisplayed() - m_minLinesVisible - 1));
} else if ((cache()->displayViewLine(c, true) >= (lnDisp - m_minLinesVisible)) || (curBelowScreen)) {
KTextEditor::Cursor scroll = viewLineOffset(c, -(lnDisp - m_minLinesVisible - 1));
scrollPos(scroll, false, calledExternally);
} else if (c < viewLineOffset(startPos(), m_minLinesVisible)) {
KTextEditor::Cursor scroll = viewLineOffset(c, -m_minLinesVisible);
......
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