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] Transition between v,V,<C-v> is different with original Vim behavior #2581

Merged
merged 2 commits into from
Apr 30, 2018
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
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
65 changes: 65 additions & 0 deletions test/mode/modeVisual.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -874,4 +874,69 @@ 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']);
assertEqual(modeHandler.currentMode.name, ModeName.Visual);
await modeHandler.handleMultipleKeyEvents(['v']);
assertEqual(modeHandler.currentMode.name, ModeName.Normal);
});

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

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

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

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

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

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

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

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