diff --git a/src/actions/commands/actions.ts b/src/actions/commands/actions.ts index dc9becb4e03..9b70c679722 100644 --- a/src/actions/commands/actions.ts +++ b/src/actions/commands/actions.ts @@ -502,7 +502,6 @@ class CommandEsc extends BaseCommand { ModeName.VisualLine, ModeName.VisualBlock, ModeName.Normal, - ModeName.SearchInProgressMode, ModeName.SurroundInputMode, ModeName.EasyMotionMode, ModeName.EasyMotionInputMode, @@ -536,12 +535,6 @@ class CommandEsc extends BaseCommand { vimState.cursors = vimState.cursors.map(x => x.withNewStop(x.stop.getLeft())); } - if (vimState.currentMode === ModeName.SearchInProgressMode) { - if (vimState.globalState.searchState) { - vimState.cursorStopPosition = vimState.globalState.searchState.searchCursorStartPosition; - } - } - if (vimState.currentMode === ModeName.Normal && vimState.isMultiCursor) { vimState.isMultiCursor = false; } @@ -961,8 +954,16 @@ class CommandEscInSearchMode extends BaseCommand { } public async exec(position: Position, vimState: VimState): Promise { - await vimState.setCurrentMode(ModeName.Normal); - vimState.globalState.searchState = undefined; + const searchState = vimState.globalState.searchState!; + + vimState.cursorStopPosition = searchState.searchCursorStartPosition; + + const prevSearchList = vimState.globalState.searchStatePrevious; + vimState.globalState.searchState = prevSearchList + ? prevSearchList[prevSearchList.length - 1] + : undefined; + + await vimState.setCurrentMode(searchState.previousMode); return vimState; } diff --git a/test/mode/normalModeTests/motions.test.ts b/test/mode/normalModeTests/motions.test.ts index 9da26a64309..9859460761e 100644 --- a/test/mode/normalModeTests/motions.test.ts +++ b/test/mode/normalModeTests/motions.test.ts @@ -381,6 +381,13 @@ suite('Motions in Normal Mode', () => { // }); // }); + newTest({ + title: 'cancelled search reverts to previous search state', + start: ['|one', 'two two', 'three three three'], + keysPressed: '/two\n/threen', + end: ['one', 'two |two', 'three three three'], + }); + newTest({ title: 'Backspace on empty search cancels', start: ['|one two three'],