From 5d067f4e96f3c98f38dbec69069d5364edd6869d Mon Sep 17 00:00:00 2001 From: Tristan Koch <73974+trkoch@users.noreply.github.com> Date: Sat, 9 Nov 2019 21:23:54 +0100 Subject: [PATCH] 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` --- src/actions/commands/actions.ts | 10 ++-------- test/mode/modeNormal.test.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/actions/commands/actions.ts b/src/actions/commands/actions.ts index f4770ea85..456ae1cde 100644 --- a/src/actions/commands/actions.ts +++ b/src/actions/commands/actions.ts @@ -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, }); } diff --git a/test/mode/modeNormal.test.ts b/test/mode/modeNormal.test.ts index 1ac8b4982..a11675776 100644 --- a/test/mode/modeNormal.test.ts +++ b/test/mode/modeNormal.test.ts @@ -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'],