From 41e835a1dffb13bee867e7210dc655d319d96e06 Mon Sep 17 00:00:00 2001 From: rebornix Date: Thu, 20 Oct 2016 17:41:58 -0700 Subject: [PATCH] fix #922 --- src/actions/actions.ts | 11 +++++++++-- test/mode/modeNormal.test.ts | 7 +++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/actions/actions.ts b/src/actions/actions.ts index 0eeb613efac..77d54d412f9 100644 --- a/src/actions/actions.ts +++ b/src/actions/actions.ts @@ -2153,9 +2153,16 @@ export class PutCommandVisual extends BaseCommand { canBePrefixedWithDot = true; public async exec(position: Position, vimState: VimState, after: boolean = false): Promise { - const result = await new DeleteOperator().run(vimState, vimState.cursorStartPosition, vimState.cursorPosition, false); + let start = vimState.cursorStartPosition; + let end = vimState.cursorPosition; - return await new PutCommand().exec(vimState.cursorStartPosition, result, true); + if (start.isAfter(end)) { + [start, end] = [end, start]; + } + + const result = await new DeleteOperator().run(vimState, start, end, false); + + return await new PutCommand().exec(start, result, true); } // TODO - execWithCount diff --git a/test/mode/modeNormal.test.ts b/test/mode/modeNormal.test.ts index 5c52cf9bb92..1cca4ec2bdb 100644 --- a/test/mode/modeNormal.test.ts +++ b/test/mode/modeNormal.test.ts @@ -1095,6 +1095,13 @@ suite("Mode Normal", () => { end: ["abc abc |dhi"] }); + newTest({ + title: "can handle p with selection", + start: ["one", "two", "|three"], + keysPressed: "yykVkp", + end: ["|three", "three"] + }); + newTest({ title: "can handle P with selection", start: ["|abc def ghi"],