From 38c0dd993488aa009678d06f9df9a8099cdee79b Mon Sep 17 00:00:00 2001 From: tyru Date: Sun, 29 Apr 2018 15:36:00 +0900 Subject: [PATCH] fix: transition between v,V, is wrong * `vv` -> normal mode * `VV` -> normal mode * `` -> normal mode * `vV` -> visual line mode * `v` -> visual block mode * `Vv` -> visual (char) mode * `V` -> visual block mode * `v` -> visual (char) mode * `V` -> visual line mode --- src/actions/commands/actions.ts | 26 +++++++++++------- test/mode/modeVisual.test.ts | 47 +++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/src/actions/commands/actions.ts b/src/actions/commands/actions.ts index 190d42d19dab..844b307bf23c 100644 --- a/src/actions/commands/actions.ts +++ b/src/actions/commands/actions.ts @@ -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 { @@ -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; @@ -2122,15 +2122,23 @@ class CommandReselectVisual extends BaseCommand { @RegisterAction class CommandVisualBlockMode extends BaseCommand { - modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualBlock]; + modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine]; keys = ['']; public async exec(position: Position, vimState: VimState): Promise { - 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 = ['']; + + public async exec(position: Position, vimState: VimState): Promise { + vimState.currentMode = ModeName.Normal; return vimState; } @@ -2138,7 +2146,7 @@ class CommandVisualBlockMode extends BaseCommand { @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 { diff --git a/test/mode/modeVisual.test.ts b/test/mode/modeVisual.test.ts index 52aa2a5704fd..cfce02563bdc 100644 --- a/test/mode/modeVisual.test.ts +++ b/test/mode/modeVisual.test.ts @@ -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 will transit to visual block mode', async () => { + await modeHandler.handleMultipleKeyEvents(['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 will transit to visual block mode', async () => { + await modeHandler.handleMultipleKeyEvents(['V', '']); + assertEqual(modeHandler.currentMode.name, ModeName.VisualBlock); + }); + + test('v will transit to visual (char) mode', async () => { + await modeHandler.handleMultipleKeyEvents(['', 'v']); + assertEqual(modeHandler.currentMode.name, ModeName.Visual); + }); + + test('V will back to visual line mode', async () => { + await modeHandler.handleMultipleKeyEvents(['', 'V']); + assertEqual(modeHandler.currentMode.name, ModeName.VisualLine); + }); + + test(' will back to normal mode', async () => { + await modeHandler.handleMultipleKeyEvents(['', '']); + assertEqual(modeHandler.currentMode.name, ModeName.Normal); + }); + }); });