Skip to content

Commit ba0f269

Browse files
committed
added support for gv in visual mode
1 parent d1080ad commit ba0f269

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/actions/commands/visual.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class EnterVisualMode extends BaseCommand {
1313
if (vimState.currentMode === Mode.Normal && vimState.recordedState.count > 1) {
1414
vimState.cursorStopPosition = position.getRight(vimState.recordedState.count - 1);
1515
}
16+
vimState.nextSelectionToUseForVisualGv = vimState.lastVisualSelection;
1617
await vimState.setCurrentMode(Mode.Visual);
1718
}
1819
}
@@ -75,15 +76,20 @@ class ExitVisualBlockMode extends BaseCommand {
7576

7677
@RegisterAction
7778
class RestoreVisualSelection extends BaseCommand {
78-
modes = [Mode.Normal];
79+
modes = [Mode.Normal, Mode.Visual];
7980
keys = ['g', 'v'];
8081

8182
public override async exec(position: Position, vimState: VimState): Promise<void> {
82-
if (vimState.lastVisualSelection === undefined) {
83+
let selectionFromHistoryToSelect = vimState.lastVisualSelection;
84+
if (vimState.currentMode === Mode.Visual) {
85+
selectionFromHistoryToSelect = vimState.nextSelectionToUseForVisualGv;
86+
vimState.nextSelectionToUseForVisualGv = vimState.lastVisualSelection;
87+
}
88+
if (selectionFromHistoryToSelect === undefined) {
8389
return;
8490
}
8591

86-
let { start, end, mode } = vimState.lastVisualSelection;
92+
let { start, end, mode } = selectionFromHistoryToSelect;
8793
if (mode !== Mode.Visual || !start.isEqual(end)) {
8894
if (end.line <= vimState.document.lineCount - 1) {
8995
if (mode === Mode.Visual && start.isBefore(end)) {

src/state/vimState.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,14 @@ export class VimState implements vscode.Disposable {
209209
}
210210
| undefined = undefined;
211211

212+
public nextSelectionToUseForVisualGv:
213+
| {
214+
mode: Mode.Visual | Mode.VisualLine | Mode.VisualBlock;
215+
start: Position;
216+
end: Position;
217+
}
218+
| undefined = undefined;
219+
212220
/**
213221
* The current mode and its associated state.
214222
*/

0 commit comments

Comments
 (0)