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 cursor position after executing J in visual mode #4702

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/actions/commands/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3160,7 +3160,8 @@ class ActionJoin extends BaseCommand {
manuallySetCursorPositions: true,
});

vimState.cursorStartPosition = vimState.cursorStopPosition = startPosition.withColumn(
J-Fields marked this conversation as resolved.
Show resolved Hide resolved
vimState.cursorStartPosition = vimState.cursorStopPosition = new Position(
startPosition.line,
trimmedLinesContent.length - columnDeltaOffset
);
await vimState.setCurrentMode(Mode.Normal);
Expand Down
8 changes: 8 additions & 0 deletions test/mode/modeVisual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1446,4 +1446,12 @@ suite('Mode Visual', () => {
endMode: Mode.Normal,
});
});

newTest({
title: "Can handle 'J' when the selected area spans multiple lines",
start: ['o|ne', 'two', 'three', 'four'],
keysPressed: 'vjjJ',
end: ['one two| three', 'four'],
endMode: Mode.Normal,
});
});
4 changes: 2 additions & 2 deletions test/mode/modeVisualBlock.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,15 @@ suite('Mode Visual Block', () => {
title: "Can handle 'J' when the visual block spans multiple lines",
start: ['o|ne', 'two', 'three', 'four'],
keysPressed: '<C-v>jjlJ',
end: ['one| two three', 'four'],
end: ['one two| three', 'four'],
endMode: Mode.Normal,
});

newTest({
title: "Can handle 'J' when start position of the visual block is below the stop",
start: ['one', 'two', 't|hree', 'four'],
keysPressed: '<C-v>kkJ',
end: ['one| two three', 'four'],
end: ['one two| three', 'four'],
endMode: Mode.Normal,
});

Expand Down
8 changes: 8 additions & 0 deletions test/mode/modeVisualLine.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,4 +520,12 @@ suite('Mode Visual Line', () => {
endMode: Mode.Normal,
});
});

newTest({
title: "Can handle 'J' when the selected area spans multiple lines",
start: ['o|ne', 'two', 'three', 'four'],
keysPressed: 'VjjJ',
end: ['one two| three', 'four'],
endMode: Mode.Normal,
});
});