diff --git a/src/actions/commands/put.ts b/src/actions/commands/put.ts index e0037631f90..198a5fca26f 100644 --- a/src/actions/commands/put.ts +++ b/src/actions/commands/put.ts @@ -494,12 +494,9 @@ function PlaceCursorAfterText PutCommand>( return new Position(line, 0); } else if (registerMode === RegisterMode.BlockWise) { const lines = text.split('\n'); - return new Position( - rangeStart.line + lines.length - 1, - rangeStart.character + - lines[0].length + - (this.putBefore() && mode === Mode.Normal ? 1 : 0) - ); + const lastLine = rangeStart.line + lines.length - 1; + const longestLineLength = Math.max(...lines.map((line) => line.length)); + return new Position(lastLine, rangeStart.character + longestLineLength); } } else if (mode === Mode.VisualLine) { return new Position(rangeStart.line + text.split('\n').length, 0); diff --git a/test/operator/put.test.ts b/test/operator/put.test.ts index 98d01bf0376..133aebb03f9 100644 --- a/test/operator/put.test.ts +++ b/test/operator/put.test.ts @@ -329,6 +329,13 @@ suite('put operator', () => { end: ['ABCD', 'ab[1][1]cd', 'wx[2][2]|yz', 'WXYZ'], }); + newTest({ + title: 'Yank ragged block-wise selection, gp', + start: ['|abcd', 'ABCDEFG', 'wxyz', 'WXYZ'], + keysPressed: '2l' + 'j$' + 'y' + '2gp', + end: ['abccd cd d', 'ABCCDEFGCDEFG|DEFG', 'wxyz', 'WXYZ'], + }); + newTest({ title: 'Yank block-wise, gp past last line', start: ['|[1]ABCD', '[2]abcd', 'wxyz', 'WXYZ'], @@ -457,7 +464,14 @@ suite('put operator', () => { title: 'Yank block-wise, gP', start: ['|[1]ABCD', '[2]abcd', 'wxyz', 'WXYZ'], keysPressed: 'llj' + 'd' + 'jl' + '2gP', - end: ['ABCD', 'a[1][1]bcd', 'w[2][2]x|yz', 'WXYZ'], + end: ['ABCD', 'a[1][1]bcd', 'w[2][2]|xyz', 'WXYZ'], + }); + + newTest({ + title: 'Yank ragged block-wise selection, gP', + start: ['|abcd', 'ABCDEFG', 'wxyz', 'WXYZ'], + keysPressed: '2l' + 'j$' + 'y' + '2gP', + end: ['abcd cd cd', 'ABCDEFGCDEFG|CDEFG', 'wxyz', 'WXYZ'], }); newTest({