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: hjk <hjk121@nokiamail.com>
This commit is contained in:
hjk
2013-11-29 17:03:57 +01:00
parent 391dea86a7
commit dc30a4a2bd

View File

@@ -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());