Skip to content

Commit

Permalink
Lazy load motion in attempt to fix #93
Browse files Browse the repository at this point in the history
  • Loading branch information
jpoon committed Dec 9, 2015
1 parent 12ae0ba commit 9bae9fb
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
5 changes: 3 additions & 2 deletions extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ var modeHandler : ModeHandler;
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {
modeHandler = new ModeHandler();

console.log('Congratulations, your extension "vim" is now active!');

registerCommand(context, 'extension.showCmdLine', () => showCmdLine());
Expand Down Expand Up @@ -97,6 +95,8 @@ export function activate(context: vscode.ExtensionContext) {
registerCommand(context, 'extension.vim_>', () => handleKeyEvent(">"));

registerCommand(context, 'extension.vim_backslash', () => handleKeyEvent("\\"));

context.subscriptions.push(modeHandler);
}

function registerCommand(context: vscode.ExtensionContext, command: string, callback: (...args: any[]) => any) {
Expand All @@ -105,5 +105,6 @@ function registerCommand(context: vscode.ExtensionContext, command: string, call
}

function handleKeyEvent(key:string) {
modeHandler = modeHandler || new ModeHandler();
modeHandler.handleKeyEvent(key);
}
7 changes: 2 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"displayName": "Vim",
"description": "Vim emulation for Visual Studio Code",
"icon": "images/icon.png",
"version": "0.0.3",
"version": "0.0.5",
"publisher": "vscodevim",
"galleryBanner": {
"color": "#a5c9a2",
Expand Down Expand Up @@ -36,10 +36,7 @@
"main": "./out/extension",
"contributes": {
"commands": [
{
"command": "extension.showCmdLine",
"title": "Vim: Show Command Line"
}
{ "command": "extension.showCmdLine", "title": "Vim: Show Command Line" }
],
"keybindings": [
{ "key": "Escape", "command": "extension.vim_esc", "when": "editorTextFocus" },
Expand Down
4 changes: 4 additions & 0 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,8 @@ export default class ModeHandler {
this.statusBarItem.text = (text) ? '-- ' + text + ' --' : '';
this.statusBarItem.show();
}

dispose() {
this.statusBarItem.dispose();
}
}
8 changes: 6 additions & 2 deletions src/mode/modeInsert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import TextEditor from './../textEditor';
import {Cursor} from './../motion/motion';

export default class InsertMode extends Mode {
private cursor : Cursor;
private _cursor : Cursor;
private get cursor() : Cursor {
this._cursor = this._cursor || new Cursor();
return this._cursor;
}

private activationKeyHandler : { [ key : string] : (cursor : Cursor) => Thenable<{}> } = {
"i" : () => {
// insert at cursor
Expand Down Expand Up @@ -34,7 +39,6 @@ export default class InsertMode extends Mode {

constructor() {
super(ModeName.Insert);
this.cursor = new Cursor();
}

ShouldBeActivated(key : string, currentMode : ModeName) : boolean {
Expand Down
8 changes: 6 additions & 2 deletions src/mode/modeNormal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import {showCmdLine} from './../cmd_line/main';
import {Caret} from './../motion/motion';

export default class NormalMode extends Mode {
private caret : Caret;
private _caret : Caret;
private get caret() : Caret {
this._caret = this._caret || new Caret();
return this._caret;
}

private keyHandler : { [key : string] : (caret : Caret) => Thenable<{}>; } = {
":" : () => { return showCmdLine(); },
"u" : () => { return vscode.commands.executeCommand("undo"); },
Expand All @@ -31,7 +36,6 @@ export default class NormalMode extends Mode {

constructor() {
super(ModeName.Normal);
this.caret = new Caret();
}

ShouldBeActivated(key : string, currentMode : ModeName) : boolean {
Expand Down

0 comments on commit 9bae9fb

Please sign in to comment.