Fix gp when pasting more than three lines (#4247)

* Fix `gp` when pasting more than three lines

Respect added lines count when creating new PositionDiff.

Fixes #4246.

* Fix `gp` when there is text after paste

* Match line counting logic of `gP` and `gp`
This commit is contained in:
Tristan Koch 2019-11-09 21:23:54 +01:00 committed by Jason Fields
parent a3256bb8c6
commit 5d067f4e96
2 changed files with 16 additions and 8 deletions

View File

@ -1725,12 +1725,9 @@ export class GPutCommand extends BaseCommand {
const result = await super.execCount(position, vimState);
if (vimState.effectiveRegisterMode === RegisterMode.LineWise) {
const line = TextEditor.getLineAt(position).text;
const addAnotherLine = line.length > 0 && addedLinesCount > 1;
result.recordedState.transformations.push({
type: 'moveCursor',
diff: PositionDiff.NewBOLDiff(1 + (addAnotherLine ? 1 : 0), 0),
diff: PositionDiff.NewBOLDiff(addedLinesCount, 0),
cursorIndex: this.multicursorIndex,
});
}
@ -1871,12 +1868,9 @@ export class GPutBeforeCommand extends BaseCommand {
}
if (vimState.effectiveRegisterMode === RegisterMode.LineWise) {
const line = TextEditor.getLineAt(position).text;
const addAnotherLine = line.length > 0 && addedLinesCount > 1;
result.recordedState.transformations.push({
type: 'moveCursor',
diff: PositionDiff.NewBOLDiff(1 + (addAnotherLine ? 1 : 0), 0),
diff: PositionDiff.NewBOLDiff(addedLinesCount, 0),
cursorIndex: this.multicursorIndex,
});
}

View File

@ -1148,6 +1148,13 @@ suite('Mode Normal', () => {
end: ['one', 'two', 'one', 'two', '|three'],
});
newTest({
title: "Can handle 'gp' after 'Nyy' if pasting more than three lines",
start: ['on|e', 'two', 'three', 'four'],
keysPressed: '4yyGgp',
end: ['one', 'two', 'three', 'four', 'one', 'two', 'three', '|four'],
});
newTest({
title: "Can handle 'gp' after 'Nyy' if cursor is on the last line",
start: ['on|e', 'two', 'three'],
@ -1169,6 +1176,13 @@ suite('Mode Normal', () => {
end: ['one', 'two', '|one', 'two', 'three'],
});
newTest({
title: "Can handle 'gP' after 'Nyy' if pasting more than three lines",
start: ['on|e', 'two', 'three', 'four'],
keysPressed: '4yygP',
end: ['one', 'two', 'three', 'four', '|one', 'two', 'three', 'four'],
});
newTest({
title: "Can handle ']p' after yy",
start: [' |one', ' two'],