Commit dc30a4a2 authored by hjk's avatar hjk

FakeVim: Prevent crash in scrollToLine with Qt 4

There seem to be cases where QTextLines::isValid() returns true but
its lines_ are empty.

Change-Id: Ia4b9a66aec8d10754f7ff7dd0c90e7295e2a2220
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 391dea86
......@@ -6477,10 +6477,19 @@ void FakeVimHandler::Private::scrollToLine(int line)
EDITOR(setTextCursor(tc2));
EDITOR(ensureCursorVisible());
int offset = 0;
const QTextBlock block = document()->findBlockByLineNumber(line);
const QTextLine textLine = block.isValid()
? block.layout()->lineAt(line - block.firstLineNumber()) : QTextLine();
tc2.setPosition(block.position() + (textLine.isValid() ? textLine.textStart() : 0));
if (block.isValid()) {
const int blockLineCount = block.layout()->lineCount();
const int lineInBlock = line - block.firstLineNumber();
if (0 <= lineInBlock && lineInBlock < blockLineCount) {
QTextLine textLine = block.layout()->lineAt(lineInBlock);
offset = textLine.textStart();
} else {
// QTC_CHECK(false);
}
}
tc2.setPosition(block.position() + offset);
EDITOR(setTextCursor(tc2));
EDITOR(ensureCursorVisible());
......
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