From 6780ad22b4969f7750b1ed5549cdfa32ccfc47c1 Mon Sep 17 00:00:00 2001 From: Jason Poon Date: Fri, 12 Jan 2018 02:22:49 -0800 Subject: [PATCH] fix: status bar not updating following toggle --- extension.ts | 9 ++-- src/actions/commands/actions.ts | 33 +++++++++++++ src/mode/mode.ts | 1 + src/mode/modeHandler.ts | 1 + src/mode/modes.ts | 84 ++++++++++++++++++--------------- 5 files changed, 83 insertions(+), 45 deletions(-) diff --git a/extension.ts b/extension.ts index d871f82f57a..2b52dad250d 100644 --- a/extension.ts +++ b/extension.ts @@ -252,14 +252,11 @@ export async function activate(context: vscode.ExtensionContext) { await vscode.commands.executeCommand('setContext', 'vim.active', !isDisabled); let mh = await getAndUpdateModeHandler(); if (isDisabled) { - vscode.window.visibleTextEditors.forEach(e => { - e.options.cursorStyle = Configuration.userCursor; - }); - StatusBar.SetText('-- VIM: DISABLED --', mh.currentMode.name, true); - } else { + await mh.handleKeyEvent(''); compositionState = new CompositionState(); modeHandlerToEditorIdentity = {}; - mh.updateView(mh.vimState, { drawSelection: false, revealRange: false }); + } else { + await mh.handleKeyEvent(''); } } diff --git a/src/actions/commands/actions.ts b/src/actions/commands/actions.ts index 3b30d0d7553..ed71b20ccb5 100644 --- a/src/actions/commands/actions.ts +++ b/src/actions/commands/actions.ts @@ -239,6 +239,39 @@ export abstract class BaseCommand extends BaseAction { // begin actions +@RegisterAction +class DisableExtension extends BaseCommand { + modes = [ + ModeName.Normal, + ModeName.Insert, + ModeName.Visual, + ModeName.VisualBlock, + ModeName.VisualLine, + ModeName.SearchInProgressMode, + ModeName.Replace, + ModeName.EasyMotionMode, + ModeName.EasyMotionInputMode, + ModeName.SurroundInputMode, + ]; + keys = ['']; + + public async exec(position: Position, vimState: VimState): Promise { + vimState.currentMode = ModeName.Disabled; + return vimState; + } +} + +@RegisterAction +class EnableExtension extends BaseCommand { + modes = [ModeName.Disabled]; + keys = ['']; + + public async exec(position: Position, vimState: VimState): Promise { + vimState.currentMode = ModeName.Normal; + return vimState; + } +} + @RegisterAction export class CommandNumber extends BaseCommand { modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine, ModeName.VisualBlock]; diff --git a/src/mode/mode.ts b/src/mode/mode.ts index 9036c69c67a..f395ffa44ce 100644 --- a/src/mode/mode.ts +++ b/src/mode/mode.ts @@ -12,6 +12,7 @@ export enum ModeName { EasyMotionMode, EasyMotionInputMode, SurroundInputMode, + Disabled, } export enum VSCodeVimCursorType { diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index e1f3bbe00e8..06aa522f108 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -55,6 +55,7 @@ export class ModeHandler implements vscode.Disposable { new modes.EasyMotionMode(), new modes.EasyMotionInputMode(), new modes.SurroundInputMode(), + new modes.DisabledMode(), ]; this.vimState = new VimState(vscode.window.activeTextEditor!, Configuration.startInInsertMode); diff --git a/src/mode/modes.ts b/src/mode/modes.ts index be50df9dfbc..f0db3638b85 100644 --- a/src/mode/modes.ts +++ b/src/mode/modes.ts @@ -15,54 +15,45 @@ export enum VisualBlockInsertionType { Append, } -export class EasyMotionMode extends Mode { +export class NormalMode extends Mode { constructor() { - super(ModeName.EasyMotionMode, '-- EasyMotion --', VSCodeVimCursorType.Block); - } - - getStatusBarCommandText(vimState: VimState): string { - return `Target key: ${vimState.easyMotion.accumulation}`; + super(ModeName.Normal, '-- Normal --', VSCodeVimCursorType.Block); } } -export class EasyMotionInputMode extends Mode { +export class InsertMode extends Mode { constructor() { - super(ModeName.EasyMotionInputMode, '-- EasyMotion Input --', VSCodeVimCursorType.Block); + super(ModeName.Insert, '-- Insert --', VSCodeVimCursorType.Native); } getStatusBarCommandText(vimState: VimState): string { - if (!vimState.easyMotion) { - return ''; - } + return ''; + } +} - const searchCharCount = vimState.easyMotion.searchAction.searchCharCount; - const message = - searchCharCount > 0 - ? `Search for ${searchCharCount} character(s): ` - : 'Search for characters: '; - return message + vimState.easyMotion.searchAction.getSearchString(); +export class VisualMode extends Mode { + constructor() { + super(ModeName.Visual, '-- Visual --', VSCodeVimCursorType.TextDecoration, true); } } -export class InsertMode extends Mode { +export class VisualBlockMode extends Mode { constructor() { - super(ModeName.Insert, '-- Insert --', VSCodeVimCursorType.Native); + super(ModeName.VisualBlock, '-- Visual Block --', VSCodeVimCursorType.TextDecoration, true); } - getStatusBarCommandText(vimState: VimState): string { - return ''; + public static getTopLeftPosition(start: Position, stop: Position): Position { + return new Position(Math.min(start.line, stop.line), Math.min(start.character, stop.character)); } -} -export class NormalMode extends Mode { - constructor() { - super(ModeName.Normal, '-- Normal --', VSCodeVimCursorType.Block); + public static getBottomRightPosition(start: Position, stop: Position): Position { + return new Position(Math.max(start.line, stop.line), Math.max(start.character, stop.character)); } } -export class ReplaceMode extends Mode { +export class VisualLineMode extends Mode { constructor() { - super(ModeName.Replace, '-- Replace --', VSCodeVimCursorType.Underline); + super(ModeName.VisualLine, '-- Visual Line --', VSCodeVimCursorType.Block, true); } } @@ -80,29 +71,38 @@ export class SearchInProgressMode extends Mode { } } -export class VisualMode extends Mode { +export class ReplaceMode extends Mode { constructor() { - super(ModeName.Visual, '-- Visual --', VSCodeVimCursorType.TextDecoration, true); + super(ModeName.Replace, '-- Replace --', VSCodeVimCursorType.Underline); } } -export class VisualBlockMode extends Mode { +export class EasyMotionMode extends Mode { constructor() { - super(ModeName.VisualBlock, '-- Visual Block --', VSCodeVimCursorType.TextDecoration, true); - } - - public static getTopLeftPosition(start: Position, stop: Position): Position { - return new Position(Math.min(start.line, stop.line), Math.min(start.character, stop.character)); + super(ModeName.EasyMotionMode, '-- EasyMotion --', VSCodeVimCursorType.Block); } - public static getBottomRightPosition(start: Position, stop: Position): Position { - return new Position(Math.max(start.line, stop.line), Math.max(start.character, stop.character)); + getStatusBarCommandText(vimState: VimState): string { + return `Target key: ${vimState.easyMotion.accumulation}`; } } -export class VisualLineMode extends Mode { +export class EasyMotionInputMode extends Mode { constructor() { - super(ModeName.VisualLine, '-- Visual Line --', VSCodeVimCursorType.Block, true); + super(ModeName.EasyMotionInputMode, '-- EasyMotion Input --', VSCodeVimCursorType.Block); + } + + getStatusBarCommandText(vimState: VimState): string { + if (!vimState.easyMotion) { + return ''; + } + + const searchCharCount = vimState.easyMotion.searchAction.searchCharCount; + const message = + searchCharCount > 0 + ? `Search for ${searchCharCount} character(s): ` + : 'Search for characters: '; + return message + vimState.easyMotion.searchAction.getSearchString(); } } @@ -115,3 +115,9 @@ export class SurroundInputMode extends Mode { return vimState.surround && vimState.surround.replacement ? vimState.surround.replacement : ''; } } + +export class DisabledMode extends Mode { + constructor() { + super(ModeName.Disabled, '-- VIM: Disabled --', VSCodeVimCursorType.Line); + } +}