Commit 66780b84 authored by Krzysztof Szatan's avatar Krzysztof Szatan Committed by hjk
Browse files

fakevim: fix paste/yank/delete on last line



Merge-request: 282
Reviewed-by: default avatarhjk <qtc-committer@nokia.com>
parent 58111b2d
......@@ -4228,11 +4228,11 @@ QString FakeVimHandler::Private::selectText(const Range &range) const
QTextCursor tc = cursor();
int firstPos = firstPositionInLine(lineForPosition(range.beginPos));
int lastLine = lineForPosition(range.endPos);
int lastPos = lastLine == document()->lastBlock().blockNumber() + 1
? lastPositionInDocument() : firstPositionInLine(lastLine + 1);
bool endOfDoc = lastLine == document()->lastBlock().blockNumber() + 1;
int lastPos = endOfDoc ? lastPositionInDocument() : firstPositionInLine(lastLine + 1);
tc.setPosition(firstPos, MoveAnchor);
tc.setPosition(lastPos, KeepAnchor);
return tc.selection().toPlainText();
return tc.selection().toPlainText() + QString((endOfDoc? "\n" : ""));
}
// FIXME: Performance?
int beginLine = lineForPosition(range.beginPos);
......@@ -4436,14 +4436,30 @@ void FakeVimHandler::Private::pasteText(bool afterCursor)
case RangeLineModeExclusive: {
moveToStartOfLine();
m_targetColumn = 0;
beginEditBlock();
QTextCursor tc = cursor();
for (int i = count(); --i >= 0; ) {
if (afterCursor)
bool lastLine = document()->lastBlock() == this->block();
if (afterCursor) {
if (lastLine) {
tc.movePosition(EndOfLine, MoveAnchor);
tc.insertBlock();
}
moveDown();
}
setAnchor();
insertText(text);
moveUp(lines.size() - 1);
if (afterCursor && lastLine) {
tc.movePosition(Left, KeepAnchor);
tc.removeSelectedText();
setAnchor();
moveUp(lines.size() - 2);
} else {
moveUp(lines.size() - 1);
}
}
moveToFirstNonBlankOnLine();
endEditBlock();
break;
}
case RangeBlockAndTailMode:
......
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