Skip to content

Commit

Permalink
Update to new extension APIs. No longer requests binding to every sin…
Browse files Browse the repository at this point in the history
…gle letter in package.json.

* Update outdated npm packages
* Update typings
* Fixes #157, #126, #188
  • Loading branch information
jpoon committed May 19, 2016
1 parent 807d883 commit d10b34e
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 142 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ out
node_modules
typings
*.sw?
.vscode-test
.DS_Store
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[![Stories in Ready](https://badge.waffle.io/VSCodeVim/Vim.png?label=ready&title=Ready)](https://waffle.io/VSCodeVim/Vim)
[![Build Status](https://travis-ci.org/VSCodeVim/Vim.svg?branch=master)](https://travis-ci.org/VSCodeVim/Vim) [![Build status](https://ci.appveyor.com/api/projects/status/github/vscodevim/vim?branch=master&svg=true&retina=true)](https://ci.appveyor.com/project/jpoon/vim/branch/master) [![Slack Status](https://vscodevim-slackin.azurewebsites.net/badge.svg)](https://vscodevim-slackin.azurewebsites.net)

# Vim
Expand Down
28 changes: 22 additions & 6 deletions extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,34 @@ var modeHandler : ModeHandler;
var extensionContext : vscode.ExtensionContext;

export function activate(context: vscode.ExtensionContext) {
console.log('Congratulations, your extension "vim" is now active!');

extensionContext = context;

registerCommand(context, 'type', async (args) => {
if (!vscode.window.activeTextEditor) {
return;
}

var isHandled = await handleKeyEvent(args.text);

console.log(args.text);
console.log(isHandled);

if (!isHandled) {
vscode.commands.executeCommand('default:type', {
text: args.text
});
}
});

registerCommand(context, 'extension.vim_esc', () => handleKeyEvent("esc"));
registerCommand(context, 'extension.showCmdLine', () => {
if (!modeHandler) {
modeHandler = new ModeHandler();
extensionContext.subscriptions.push(modeHandler);
}
showCmdLine("", modeHandler);
});

/*
registerCommand(context, 'extension.vim_esc', () => handleKeyEvent("esc"));
registerCommand(context, 'extension.vim_colon', () => handleKeyEvent(":"));
registerCommand(context, 'extension.vim_space', () => handleKeyEvent("space"));
Expand Down Expand Up @@ -114,7 +130,7 @@ export function activate(context: vscode.ExtensionContext) {
registerCommand(context, 'extension.vim_oem_102', () => handleKeyEvent("oem_102"));
registerCommand(context, 'extension.vim_shift_oem_102', () => handleKeyEvent("shift+oem_102"));

*/
context.subscriptions.push(modeHandler);
}

Expand All @@ -123,11 +139,11 @@ function registerCommand(context: vscode.ExtensionContext, command: string, call
context.subscriptions.push(disposable);
}

function handleKeyEvent(key: string) {
function handleKeyEvent(key: string) : Promise<Boolean> {
if (!modeHandler) {
modeHandler = new ModeHandler();
extensionContext.subscriptions.push(modeHandler);
}

modeHandler.handleKeyEvent(key);
return modeHandler.handleKeyEvent(key);
}
113 changes: 13 additions & 100 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"url": "https://github.com/VSCodeVim/Vim/issues"
},
"engines": {
"vscode": "^0.10.8"
"vscode": "^1.0.0"
},
"categories": [
"Other"
Expand All @@ -39,94 +39,7 @@
{ "command": "extension.showCmdLine", "title": "Vim: Show Command Line" }
],
"keybindings": [
{ "key": "Escape", "command": "extension.vim_esc", "when": "editorTextFocus" },
{ "key": "Shift+;", "command": "extension.vim_colon", "when": "editorTextFocus" },
{ "key": ":", "command": "extension.vim_colon", "when": "editorTextFocus" },
{ "key": "space", "command": "extension.vim_space", "when": "editorTextFocus" },
{ "key": "\\", "command": "extension.vim_backslash", "when": "editorTextFocus" },
{ "key": "Shift+[", "command": "extension.vim_left_curly_bracket", "when": "editorTextFocus" },
{ "key": "Shift+]", "command": "extension.vim_right_curly_bracket", "when": "editorTextFocus" },
{ "key": "/", "command": "extension.vim_forwardslash", "when": "editorTextFocus" },

{ "key": "a", "command": "extension.vim_a", "when": "editorTextFocus" },
{ "key": "b", "command": "extension.vim_b", "when": "editorTextFocus" },
{ "key": "c", "command": "extension.vim_c", "when": "editorTextFocus" },
{ "key": "d", "command": "extension.vim_d", "when": "editorTextFocus" },
{ "key": "e", "command": "extension.vim_e", "when": "editorTextFocus" },
{ "key": "f", "command": "extension.vim_f", "when": "editorTextFocus" },
{ "key": "g", "command": "extension.vim_g", "when": "editorTextFocus" },
{ "key": "h", "command": "extension.vim_h", "when": "editorTextFocus" },
{ "key": "i", "command": "extension.vim_i", "when": "editorTextFocus" },
{ "key": "j", "command": "extension.vim_j", "when": "editorTextFocus" },
{ "key": "k", "command": "extension.vim_k", "when": "editorTextFocus" },
{ "key": "l", "command": "extension.vim_l", "when": "editorTextFocus" },
{ "key": "m", "command": "extension.vim_m", "when": "editorTextFocus" },
{ "key": "n", "command": "extension.vim_n", "when": "editorTextFocus" },
{ "key": "o", "command": "extension.vim_o", "when": "editorTextFocus" },
{ "key": "p", "command": "extension.vim_p", "when": "editorTextFocus" },
{ "key": "q", "command": "extension.vim_q", "when": "editorTextFocus" },
{ "key": "r", "command": "extension.vim_r", "when": "editorTextFocus" },
{ "key": "s", "command": "extension.vim_s", "when": "editorTextFocus" },
{ "key": "t", "command": "extension.vim_t", "when": "editorTextFocus" },
{ "key": "u", "command": "extension.vim_u", "when": "editorTextFocus" },
{ "key": "v", "command": "extension.vim_v", "when": "editorTextFocus" },
{ "key": "w", "command": "extension.vim_w", "when": "editorTextFocus" },
{ "key": "x", "command": "extension.vim_x", "when": "editorTextFocus" },
{ "key": "y", "command": "extension.vim_y", "when": "editorTextFocus" },
{ "key": "z", "command": "extension.vim_z", "when": "editorTextFocus" },

{ "key": "Shift+a", "command": "extension.vim_A", "when": "editorTextFocus" },
{ "key": "Shift+b", "command": "extension.vim_B", "when": "editorTextFocus" },
{ "key": "Shift+c", "command": "extension.vim_C", "when": "editorTextFocus" },
{ "key": "Shift+d", "command": "extension.vim_D", "when": "editorTextFocus" },
{ "key": "Shift+e", "command": "extension.vim_E", "when": "editorTextFocus" },
{ "key": "Shift+f", "command": "extension.vim_F", "when": "editorTextFocus" },
{ "key": "Shift+g", "command": "extension.vim_G", "when": "editorTextFocus" },
{ "key": "Shift+h", "command": "extension.vim_H", "when": "editorTextFocus" },
{ "key": "Shift+i", "command": "extension.vim_I", "when": "editorTextFocus" },
{ "key": "Shift+j", "command": "extension.vim_J", "when": "editorTextFocus" },
{ "key": "Shift+k", "command": "extension.vim_K", "when": "editorTextFocus" },
{ "key": "Shift+l", "command": "extension.vim_L", "when": "editorTextFocus" },
{ "key": "Shift+m", "command": "extension.vim_M", "when": "editorTextFocus" },
{ "key": "Shift+n", "command": "extension.vim_N", "when": "editorTextFocus" },
{ "key": "Shift+o", "command": "extension.vim_O", "when": "editorTextFocus" },
{ "key": "Shift+p", "command": "extension.vim_P", "when": "editorTextFocus" },
{ "key": "Shift+q", "command": "extension.vim_Q", "when": "editorTextFocus" },
{ "key": "Shift+r", "command": "extension.vim_R", "when": "editorTextFocus" },
{ "key": "Shift+s", "command": "extension.vim_S", "when": "editorTextFocus" },
{ "key": "Shift+t", "command": "extension.vim_T", "when": "editorTextFocus" },
{ "key": "Shift+u", "command": "extension.vim_U", "when": "editorTextFocus" },
{ "key": "Shift+v", "command": "extension.vim_V", "when": "editorTextFocus" },
{ "key": "Shift+w", "command": "extension.vim_W", "when": "editorTextFocus" },
{ "key": "Shift+x", "command": "extension.vim_X", "when": "editorTextFocus" },
{ "key": "Shift+y", "command": "extension.vim_Y", "when": "editorTextFocus" },
{ "key": "Shift+z", "command": "extension.vim_Z", "when": "editorTextFocus" },

{ "key": "0", "command": "extension.vim_0", "when": "editorTextFocus" },
{ "key": "1", "command": "extension.vim_1", "when": "editorTextFocus" },
{ "key": "2", "command": "extension.vim_2", "when": "editorTextFocus" },
{ "key": "3", "command": "extension.vim_3", "when": "editorTextFocus" },
{ "key": "4", "command": "extension.vim_4", "when": "editorTextFocus" },
{ "key": "5", "command": "extension.vim_5", "when": "editorTextFocus" },
{ "key": "6", "command": "extension.vim_6", "when": "editorTextFocus" },
{ "key": "7", "command": "extension.vim_7", "when": "editorTextFocus" },
{ "key": "8", "command": "extension.vim_8", "when": "editorTextFocus" },
{ "key": "9", "command": "extension.vim_9", "when": "editorTextFocus" },

{ "key": "Shift+4", "command": "extension.vim_$", "when": "editorTextFocus" },
{ "key": "Shift+6", "command": "extension.vim_^", "when": "editorTextFocus" },

{ "key": "Ctrl+[", "command": "extension.vim_ctrl_[", "when": "editorTextFocus" },
{ "key": "Ctrl+r", "command": "extension.vim_ctrl_r", "when": "editorTextFocus" },
{ "key": "Ctrl+f", "command": "extension.vim_ctrl_f", "when": "editorTextFocus" },
{ "key": "Ctrl+b", "command": "extension.vim_ctrl_b", "when": "editorTextFocus" },

{ "key": "Shift+5", "command": "extension.vim_%", "when": "editorTextFocus" },

{ "key": "Shift+,", "command": "extension.vim_<", "when": "editorTextFocus" },
{ "key": "Shift+.", "command": "extension.vim_>", "when": "editorTextFocus" },
{ "key": "oem_102", "command": "extension.vim_oem_102", "when": "editorTextFocus" },
{ "key": "Shift+oem_102", "command": "extension.vim_shift_oem_102", "when": "editorTextFocus" }
{ "key": "Escape", "command": "extension.vim_esc", "when": "editorTextFocus" }
],
"configuration": {
"title": "Vim Configuration",
Expand Down Expand Up @@ -159,25 +72,25 @@
"postinstall": "node ./node_modules/vscode/bin/install && gulp init"
},
"dependencies": {
"lodash": "^4.5.1",
"copy-paste": "^1.1.4"
"lodash": "^4.12.0",
"copy-paste": "^1.2.0"
},
"devDependencies": {
"gulp": "^3.9.1",
"gulp-bump": "^2.0.1",
"gulp-bump": "^2.1.0",
"gulp-filter": "^4.0.0",
"gulp-git": "^1.7.0",
"gulp-git": "^1.7.1",
"gulp-mocha": "^2.2.0",
"gulp-shell": "^0.5.2",
"gulp-soften": "^0.0.1",
"gulp-tag-version": "^1.3.0",
"gulp-trimlines": "^1.0.0",
"gulp-tslint": "^4.3.2",
"gulp-typescript": "^2.12.0",
"gulp-typings": "^1.1.0",
"tslint": "^3.5.0",
"typescript": "^1.8.2",
"typings": "^0.6.8",
"vscode": "^0.11.1"
"gulp-tslint": "^5.0.0",
"gulp-typescript": "^2.13.4",
"gulp-typings": "^2.0.0",
"tslint": "^3.10.2",
"typescript": "^1.8.10",
"typings": "^1.0.4",
"vscode": "^0.11.13"
}
}
12 changes: 3 additions & 9 deletions src/cmd_line/commands/quit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,10 @@ export class QuitCommand extends node.CommandBase {
}

execute() : void {
this.quit();
}

private quit() {
// See https://github.com/Microsoft/vscode/issues/723
if ((this.activeTextEditor.document.isDirty || this.activeTextEditor.document.isUntitled)
&& !this.arguments.bang) {
throw error.VimError.fromCode(error.ErrorCode.E37);
if (this.activeTextEditor.document.isDirty && !this.arguments.bang) {
throw error.VimError.fromCode(error.ErrorCode.E37);
}

vscode.commands.executeCommand('workbench.action.closeActiveEditor');
};
}
}
2 changes: 1 addition & 1 deletion src/mode/mode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ export abstract class Mode {

abstract handleActivation(key : string) : Promise<void>;

abstract handleKeyEvent(key : string) : Promise<boolean>;
abstract handleKeyEvent(key : string) : Promise<Boolean>;
}
8 changes: 4 additions & 4 deletions src/mode/modeHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class ModeHandler implements vscode.Disposable {
this.setupStatusBarItem(statusBarText ? `-- ${statusBarText.toUpperCase()} --` : '');
}

handleKeyEvent(key : string) : void {
handleKeyEvent(key : string) : Promise<Boolean> {
// Due to a limitation in Electron, en-US QWERTY char codes are used in international keyboards.
// We'll try to mitigate this problem until it's fixed upstream.
// https://github.com/Microsoft/vscode/issues/713
Expand All @@ -99,9 +99,9 @@ export class ModeHandler implements vscode.Disposable {
if (nextMode) {
this.currentMode.handleDeactivation();
this.setCurrentModeByName(nextMode.name);
nextMode.handleActivation(key);
return nextMode.handleActivation(key).then(() => { return true; });
} else {
this.currentMode.handleKeyEvent(key);
return this.currentMode.handleKeyEvent(key);
}
}

Expand All @@ -117,6 +117,6 @@ export class ModeHandler implements vscode.Disposable {
dispose() {
this._statusBarItem.hide();
this._statusBarItem.dispose();
this._motion.dispose();
this._motion.dispose();
}
}
4 changes: 1 addition & 3 deletions src/mode/modeInsert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ export class InsertMode extends Mode {
await this.handleActivationKey(command)(this.motion);
}

async handleKeyEvent(key : string) : Promise<boolean> {
async handleKeyEvent(key : string) : Promise<Boolean> {
await TextEditor.insert(this.resolveKeyValue(key));
await vscode.commands.executeCommand("editor.action.triggerSuggest");

return true;
}

Expand Down
4 changes: 2 additions & 2 deletions src/mode/modeNormal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ export class NormalMode extends Mode {
this.motion.left().move();
}

async handleKeyEvent(key : string): Promise<boolean> {
async handleKeyEvent(key : string): Promise<Boolean> {
this._keyHistory.push(key);

let keyHandled = false;
Expand All @@ -240,6 +240,6 @@ export class NormalMode extends Mode {
await this.handleKey(command)(this.motion);
}

return keyHandled;
return true;
}
}
4 changes: 2 additions & 2 deletions src/mode/modeVisual.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class VisualMode extends Mode {
this._keyHistory = [];
}

return keyHandled;
return true;
}

private async _handleOperator(): Promise<boolean> {
Expand All @@ -130,7 +130,7 @@ export class VisualMode extends Mode {
return !!operator;
}

async handleKeyEvent(key: string): Promise<boolean> {
async handleKeyEvent(key: string): Promise<Boolean> {
this._keyHistory.push(key);

const wasMotion = await this._handleMotion();
Expand Down
2 changes: 1 addition & 1 deletion src/motion/motion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,4 @@ export class Motion implements vscode.Disposable {
d.dispose();
});
}
}
}
22 changes: 10 additions & 12 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out",
"noLib": true,
"sourceMap": true
},
"exclude": [
"node_modules",
"typings/browser.d.ts",
"typings/browser"
]
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"outDir": "out",
"noLib": true,
"sourceMap": true
},
"exclude": [
"node_modules"
]
}
5 changes: 4 additions & 1 deletion typings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"name": "vim",
"ambientDependencies": {
"copy-paste": "registry:dt/copy-paste#1.1.3+20160117130525"
},
"globalDependencies": {
"copy-paste": "registry:dt/copy-paste#1.1.3+20160117130525",
"lodash": "github:DefinitelyTyped/DefinitelyTyped/lodash/lodash.d.ts#7b7aa2027a8fb6219a8bcf1b6bb12bcd0ff9539d"
"lodash": "registry:dt/lodash#3.10.0+20160330154726"
}
}

0 comments on commit d10b34e

Please sign in to comment.