Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error when count exceeds max number of rows in "[count]Y/J" #4628

Merged
merged 7 commits into from
Mar 30, 2020
Merged
4 changes: 2 additions & 2 deletions src/actions/commands/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2145,7 +2145,7 @@ export class CommandYankFullLine extends BaseCommand {
public async exec(position: Position, vimState: VimState): Promise<VimState> {
const linesDown = (vimState.recordedState.count || 1) - 1;
const start = position.getLineBegin();
const end = new Position(position.line + linesDown, 0).getLineEnd().getLeft();
const end = position.getDownByCount(linesDown).getLeft();
J-Fields marked this conversation as resolved.
Show resolved Hide resolved

vimState.currentRegisterMode = RegisterMode.LineWise;

Expand Down Expand Up @@ -3096,7 +3096,7 @@ class ActionJoin extends BaseCommand {
if (position.line + 1 < TextEditor.getLineCount()) {
startLineNumber = position.line;
startColumn = 0;
endLineNumber = startLineNumber + count;
endLineNumber = position.getDownByCount(count).line;
endColumn = TextEditor.getLineLength(endLineNumber);
} else {
startLineNumber = position.line;
Expand Down
14 changes: 14 additions & 0 deletions test/mode/modeNormal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1805,6 +1805,20 @@ suite('Mode Normal', () => {
end: ['blah blah', '|blah blah'],
});

newTest({
title: 'can do [count]Y',
start: ['|one', 'two', 'three'],
keysPressed: '2Yp',
end: ['one', '|one', 'two', 'two', 'three'],
});

newTest({
title: 'can do [count]Y if count is larger than EOF',
start: ['|one', 'two', 'three'],
keysPressed: '100Yp',
end: ['one', '|one', 'two', 'three', 'two', 'three'],
});

lusingander marked this conversation as resolved.
Show resolved Hide resolved
newTest({
title: 'Can do S',
start: [' one', ' tw|o', ' three'],
Expand Down
14 changes: 14 additions & 0 deletions test/mode/normalModeTests/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,20 @@ suite('Mode Normal', () => {
end: ['one|two'],
});

newTest({
title: "Can handle 'J' with count",
start: ['|one', 'two', 'three', 'four'],
keysPressed: '3J',
end: ['one two| three', 'four'],
});

newTest({
title: "Can handle 'J' with count if count is larger than EOF",
start: ['|one', 'two', 'three', 'four'],
keysPressed: '100J',
end: ['one two three| four'],
});

lusingander marked this conversation as resolved.
Show resolved Hide resolved
newTest({
title: "Can handle 'J' in Visual Line mode",
start: ['on|e', 'two'],
Expand Down