Commit 4481a199 authored by hluk's avatar hluk Committed by hjk
Browse files

FakeVim: Don't use scroll bar to scroll to line or get first line



Possible scroll bar values (range from minimum to maximum) cannot -- in
some cases -- be linearly mapped to line numbers.

Change-Id: I8833dae057e2be39295f3aae906bb79e16269db7
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 7688754b
......@@ -6297,28 +6297,28 @@ int FakeVimHandler::Private::linesInDocument() const
void FakeVimHandler::Private::scrollToLine(int line)
{
QScrollBar *scrollBar = EDITOR(verticalScrollBar());
const QTextCursor tc = EDITOR(textCursor());
// Convert line number to scroll bar value.
const int maxValue = scrollBar->maximum();
const int scrollLines = qMax(1, linesInDocument() - linesOnScreen() + 1);
const int value = maxValue >= scrollLines ? line * maxValue / scrollLines : line;
QTextCursor tc2 = tc;
tc2.setPosition(document()->lastBlock().position());
EDITOR(setTextCursor(tc2));
EDITOR(ensureCursorVisible());
scrollBar->setValue(value);
tc2.setPosition(document()->findBlockByLineNumber(line).position());
EDITOR(setTextCursor(tc2));
EDITOR(ensureCursorVisible());
updateFirstVisibleLine();
EDITOR(setTextCursor(tc));
if (isVisualBlockMode())
emit q->requestSetBlockSelection(true);
m_firstVisibleLine = line;
}
void FakeVimHandler::Private::updateFirstVisibleLine()
{
QScrollBar *scrollBar = EDITOR(verticalScrollBar());
// Convert scroll bar value to line number.
const int maxValue = qMax(1, scrollBar->maximum());
const int scrollLines = qMax(1, linesInDocument() - linesOnScreen() + 1);
const int value = scrollBar->value();
m_firstVisibleLine = maxValue >= scrollLines ? value * scrollLines / maxValue : value;
const QTextCursor tc = EDITOR(cursorForPosition(QPoint(0,0)));
m_firstVisibleLine = tc.block().firstLineNumber();
}
int FakeVimHandler::Private::firstVisibleLine() const
......@@ -6328,8 +6328,8 @@ int FakeVimHandler::Private::firstVisibleLine() const
int FakeVimHandler::Private::lastVisibleLine() const
{
const int blockNumber = lineToBlockNumber(m_firstVisibleLine + linesOnScreen());
const QTextBlock block = document()->findBlockByNumber(blockNumber);
const QTextBlock block =
document()->findBlockByLineNumber(m_firstVisibleLine + linesOnScreen());
return block.isValid() ? block.firstLineNumber() : document()->lastBlock().firstLineNumber();
}
......@@ -6825,6 +6825,8 @@ bool FakeVimHandler::Private::passEventToEditor(QEvent &event)
EDITOR(setOverwriteMode(false));
emit q->requestSetBlockSelection(false);
bool accepted = QApplication::sendEvent(editor(), &event);
if (isVisualBlockMode())
emit q->requestSetBlockSelection(true);
updateCursorShape();
installEventFilter();
......
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