Skip to content

Commit

Permalink
fix: transition between v,V,<C-v> is wrong
Browse files Browse the repository at this point in the history
* `vv` -> normal mode
* `VV` -> normal mode
* `<C-v>` -> normal mode

* `vV` -> visual line mode
* `v<C-v>` -> visual block mode
* `Vv` -> visual (char) mode
* `V<C-v>` -> visual block mode
* `<C-v>v` -> visual (char) mode
* `<C-v>V` -> visual line mode
  • Loading branch information
tyru committed Apr 29, 2018
1 parent 2271337 commit 38c0dd9
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/actions/commands/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2075,7 +2075,7 @@ class CommandClearLine extends BaseCommand {

@RegisterAction
class CommandExitVisualMode extends BaseCommand {
modes = [ModeName.Visual, ModeName.VisualLine];
modes = [ModeName.Visual];
keys = ['v'];

public async exec(position: Position, vimState: VimState): Promise<VimState> {
Expand All @@ -2087,7 +2087,7 @@ class CommandExitVisualMode extends BaseCommand {

@RegisterAction
class CommandVisualMode extends BaseCommand {
modes = [ModeName.Normal];
modes = [ModeName.Normal, ModeName.VisualLine, ModeName.VisualBlock];
keys = ['v'];
isCompleteAction = false;

Expand Down Expand Up @@ -2122,23 +2122,31 @@ class CommandReselectVisual extends BaseCommand {

@RegisterAction
class CommandVisualBlockMode extends BaseCommand {
modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualBlock];
modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine];
keys = ['<C-v>'];

public async exec(position: Position, vimState: VimState): Promise<VimState> {
if (vimState.currentMode === ModeName.VisualBlock) {
vimState.currentMode = ModeName.Normal;
} else {
vimState.currentMode = ModeName.VisualBlock;
}
vimState.currentMode = ModeName.VisualBlock;

return vimState;
}
}

@RegisterAction
class CommandExitVisualBlockMode extends BaseCommand {
modes = [ModeName.VisualBlock];
keys = ['<C-v>'];

public async exec(position: Position, vimState: VimState): Promise<VimState> {
vimState.currentMode = ModeName.Normal;

return vimState;
}
}

@RegisterAction
class CommandVisualLineMode extends BaseCommand {
modes = [ModeName.Normal, ModeName.Visual];
modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualBlock];
keys = ['V'];

public async exec(position: Position, vimState: VimState): Promise<VimState> {
Expand Down
47 changes: 47 additions & 0 deletions test/mode/modeVisual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -874,4 +874,51 @@ suite('Mode Visual', () => {
end: [' func() {', ' hi;', ' alw;', '| hi;', ' alw;', ' }'],
});
});

suite('Transition between visual mode', () => {
test('vv will back to normal mode', async () => {
await modeHandler.handleMultipleKeyEvents(['v', 'v']);
assertEqual(modeHandler.currentMode.name, ModeName.Normal);
});

test('vV will transit to visual line mode', async () => {
await modeHandler.handleMultipleKeyEvents(['v', 'V']);
assertEqual(modeHandler.currentMode.name, ModeName.VisualLine);
});

test('v<C-v> will transit to visual block mode', async () => {
await modeHandler.handleMultipleKeyEvents(['v', '<C-v>']);
assertEqual(modeHandler.currentMode.name, ModeName.VisualBlock);
});

test('Vv will transit to visual (char) mode', async () => {
await modeHandler.handleMultipleKeyEvents(['V', 'v']);
assertEqual(modeHandler.currentMode.name, ModeName.Visual);
});

test('VV will back to normal mode', async () => {
await modeHandler.handleMultipleKeyEvents(['V', 'V']);
assertEqual(modeHandler.currentMode.name, ModeName.Normal);
});

test('V<C-v> will transit to visual block mode', async () => {
await modeHandler.handleMultipleKeyEvents(['V', '<C-v>']);
assertEqual(modeHandler.currentMode.name, ModeName.VisualBlock);
});

test('<C-v>v will transit to visual (char) mode', async () => {
await modeHandler.handleMultipleKeyEvents(['<C-v>', 'v']);
assertEqual(modeHandler.currentMode.name, ModeName.Visual);
});

test('<C-v>V will back to visual line mode', async () => {
await modeHandler.handleMultipleKeyEvents(['<C-v>', 'V']);
assertEqual(modeHandler.currentMode.name, ModeName.VisualLine);
});

test('<C-v><C-v> will back to normal mode', async () => {
await modeHandler.handleMultipleKeyEvents(['<C-v>', '<C-v>']);
assertEqual(modeHandler.currentMode.name, ModeName.Normal);
});
});
});

0 comments on commit 38c0dd9

Please sign in to comment.