Skip to content

Commit

Permalink
Fix cursor position after VisualBlock gp and gP operations (#8080)
Browse files Browse the repository at this point in the history
  • Loading branch information
burnsdy authored Nov 7, 2022
1 parent 9430416 commit d57ae1d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/actions/commands/put.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,12 +494,9 @@ function PlaceCursorAfterText<TBase extends new (...args: any[]) => 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);
Expand Down
16 changes: 15 additions & 1 deletion test/operator/put.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, <count>gp',
start: ['|abcd', 'ABCDEFG', 'wxyz', 'WXYZ'],
keysPressed: '2l' + '<C-v>j$' + 'y' + '2gp',
end: ['abccd cd d', 'ABCCDEFGCDEFG|DEFG', 'wxyz', 'WXYZ'],
});

newTest({
title: 'Yank block-wise, <count>gp past last line',
start: ['|[1]ABCD', '[2]abcd', 'wxyz', 'WXYZ'],
Expand Down Expand Up @@ -457,7 +464,14 @@ suite('put operator', () => {
title: 'Yank block-wise, <count>gP',
start: ['|[1]ABCD', '[2]abcd', 'wxyz', 'WXYZ'],
keysPressed: '<C-v>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, <count>gP',
start: ['|abcd', 'ABCDEFG', 'wxyz', 'WXYZ'],
keysPressed: '2l' + '<C-v>j$' + 'y' + '2gP',
end: ['abcd cd cd', 'ABCDEFGCDEFG|CDEFG', 'wxyz', 'WXYZ'],
});

newTest({
Expand Down

0 comments on commit d57ae1d

Please sign in to comment.