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: status bar not updating following toggle #2283

Merged
merged 1 commit into from
Jan 12, 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
9 changes: 3 additions & 6 deletions extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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('<ExtensionDisable>');
compositionState = new CompositionState();
modeHandlerToEditorIdentity = {};
mh.updateView(mh.vimState, { drawSelection: false, revealRange: false });
} else {
await mh.handleKeyEvent('<ExtensionEnable>');
}
}

Expand Down
33 changes: 33 additions & 0 deletions src/actions/commands/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ['<ExtensionDisable>'];

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

@RegisterAction
class EnableExtension extends BaseCommand {
modes = [ModeName.Disabled];
keys = ['<ExtensionEnable>'];

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

@RegisterAction
export class CommandNumber extends BaseCommand {
modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine, ModeName.VisualBlock];
Expand Down
1 change: 1 addition & 0 deletions src/mode/mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export enum ModeName {
EasyMotionMode,
EasyMotionInputMode,
SurroundInputMode,
Disabled,
}

export enum VSCodeVimCursorType {
Expand Down
1 change: 1 addition & 0 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
84 changes: 45 additions & 39 deletions src/mode/modes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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();
}
}

Expand All @@ -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);
}
}