Skip to content

Commit

Permalink
Initialize mode and cursor after startup
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Jul 17, 2016
1 parent f152ee1 commit fd85fc5
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export async function getAndUpdateModeHandler(): Promise<ModeHandler> {
return handler;
}

export function activate(context: vscode.ExtensionContext) {
export async function activate(context: vscode.ExtensionContext) {
extensionContext = context;

registerCommand(context, 'type', async (args) => {
Expand All @@ -68,7 +68,7 @@ export function activate(context: vscode.ExtensionContext) {
const mh = await getAndUpdateModeHandler();
await mh.handleKeyEvent(args.text);
},
isRunning : false
isRunning: false
});
});

Expand All @@ -87,9 +87,9 @@ export function activate(context: vscode.ExtensionContext) {
mh.vimState.cursorPosition = Position.FromVSCodePosition(vscode.window.activeTextEditor.selection.start);
mh.vimState.cursorStartPosition = Position.FromVSCodePosition(vscode.window.activeTextEditor.selection.start);
},
isRunning : false
isRunning: false
});
});
});

registerCommand(context, 'extension.vim_esc', () => handleKeyEvent("<esc>"));
registerCommand(context, 'extension.vim_backspace', () => handleKeyEvent("<backspace>"));
Expand All @@ -105,6 +105,12 @@ export function activate(context: vscode.ExtensionContext) {
['left', 'right', 'up', 'down'].forEach(key => {
registerCommand(context, `extension.vim_${key}`, () => handleKeyEvent(`<${key}>`));
});

// Initialize mode handler for current active Text Editor at startup.
if (vscode.window.activeTextEditor) {
let mh = await getAndUpdateModeHandler()
mh.updateView(mh.vimState, false);
}
}

function registerCommand(context: vscode.ExtensionContext, command: string, callback: (...args: any[]) => any) {
Expand Down

0 comments on commit fd85fc5

Please sign in to comment.