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 03a980b
Show file tree
Hide file tree
Showing 15 changed files with 74 additions and 245 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
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ notifications:

sudo: false

os:
- osx
- linux

addons:
apt:
packages:
Expand All @@ -12,6 +16,7 @@ language: node_js

node_js:
- "4.2"

env:
- GITHUB_TOKEN=1b17d62d38a4846efa7ea4de4b773b581787b0f1

Expand All @@ -28,4 +33,4 @@ install:

script:
- gulp
- npm test --silent
- npm test --silent
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
116 changes: 19 additions & 97 deletions extension.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
"use strict"

// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below

import * as vscode from 'vscode';
import {showCmdLine} from './src/cmd_line/main';
import * as cc from './src/cmd_line/lexer';
Expand All @@ -13,10 +10,25 @@ 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;
}

console.log(args.text);
console.log(args);
var isHandled = await handleKeyEvent(args.text);

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();
Expand All @@ -25,96 +37,6 @@ export function activate(context: vscode.ExtensionContext) {
showCmdLine("", modeHandler);
});

registerCommand(context, 'extension.vim_esc', () => handleKeyEvent("esc"));
registerCommand(context, 'extension.vim_colon', () => handleKeyEvent(":"));
registerCommand(context, 'extension.vim_space', () => handleKeyEvent("space"));
registerCommand(context, 'extension.vim_left_curly_bracket', () => handleKeyEvent("{"));
registerCommand(context, 'extension.vim_right_curly_bracket', () => handleKeyEvent("}"));
registerCommand(context, 'extension.vim_forwardslash', () => handleKeyEvent("/"));

registerCommand(context, 'extension.vim_a', () => handleKeyEvent("a"));
registerCommand(context, 'extension.vim_b', () => handleKeyEvent("b"));
registerCommand(context, 'extension.vim_c', () => handleKeyEvent("c"));
registerCommand(context, 'extension.vim_d', () => handleKeyEvent("d"));
registerCommand(context, 'extension.vim_e', () => handleKeyEvent("e"));
registerCommand(context, 'extension.vim_f', () => handleKeyEvent("f"));
registerCommand(context, 'extension.vim_g', () => handleKeyEvent("g"));
registerCommand(context, 'extension.vim_h', () => handleKeyEvent("h"));
registerCommand(context, 'extension.vim_i', () => handleKeyEvent("i"));
registerCommand(context, 'extension.vim_j', () => handleKeyEvent("j"));
registerCommand(context, 'extension.vim_k', () => handleKeyEvent("k"));
registerCommand(context, 'extension.vim_l', () => handleKeyEvent("l"));
registerCommand(context, 'extension.vim_m', () => handleKeyEvent("m"));
registerCommand(context, 'extension.vim_n', () => handleKeyEvent("n"));
registerCommand(context, 'extension.vim_o', () => handleKeyEvent("o"));
registerCommand(context, 'extension.vim_p', () => handleKeyEvent("p"));
registerCommand(context, 'extension.vim_q', () => handleKeyEvent("q"));
registerCommand(context, 'extension.vim_r', () => handleKeyEvent("r"));
registerCommand(context, 'extension.vim_s', () => handleKeyEvent("s"));
registerCommand(context, 'extension.vim_t', () => handleKeyEvent("t"));
registerCommand(context, 'extension.vim_u', () => handleKeyEvent("u"));
registerCommand(context, 'extension.vim_v', () => handleKeyEvent("v"));
registerCommand(context, 'extension.vim_w', () => handleKeyEvent("w"));
registerCommand(context, 'extension.vim_x', () => handleKeyEvent("x"));
registerCommand(context, 'extension.vim_y', () => handleKeyEvent("y"));
registerCommand(context, 'extension.vim_z', () => handleKeyEvent("z"));

registerCommand(context, 'extension.vim_A', () => handleKeyEvent("A"));
registerCommand(context, 'extension.vim_B', () => handleKeyEvent("B"));
registerCommand(context, 'extension.vim_C', () => handleKeyEvent("C"));
registerCommand(context, 'extension.vim_D', () => handleKeyEvent("D"));
registerCommand(context, 'extension.vim_E', () => handleKeyEvent("E"));
registerCommand(context, 'extension.vim_F', () => handleKeyEvent("F"));
registerCommand(context, 'extension.vim_G', () => handleKeyEvent("G"));
registerCommand(context, 'extension.vim_H', () => handleKeyEvent("H"));
registerCommand(context, 'extension.vim_I', () => handleKeyEvent("I"));
registerCommand(context, 'extension.vim_J', () => handleKeyEvent("J"));
registerCommand(context, 'extension.vim_K', () => handleKeyEvent("K"));
registerCommand(context, 'extension.vim_L', () => handleKeyEvent("L"));
registerCommand(context, 'extension.vim_M', () => handleKeyEvent("M"));
registerCommand(context, 'extension.vim_N', () => handleKeyEvent("N"));
registerCommand(context, 'extension.vim_O', () => handleKeyEvent("O"));
registerCommand(context, 'extension.vim_P', () => handleKeyEvent("P"));
registerCommand(context, 'extension.vim_Q', () => handleKeyEvent("Q"));
registerCommand(context, 'extension.vim_R', () => handleKeyEvent("R"));
registerCommand(context, 'extension.vim_S', () => handleKeyEvent("S"));
registerCommand(context, 'extension.vim_T', () => handleKeyEvent("T"));
registerCommand(context, 'extension.vim_U', () => handleKeyEvent("U"));
registerCommand(context, 'extension.vim_V', () => handleKeyEvent("V"));
registerCommand(context, 'extension.vim_W', () => handleKeyEvent("W"));
registerCommand(context, 'extension.vim_X', () => handleKeyEvent("X"));
registerCommand(context, 'extension.vim_Y', () => handleKeyEvent("Y"));
registerCommand(context, 'extension.vim_Z', () => handleKeyEvent("Z"));

registerCommand(context, 'extension.vim_0', () => handleKeyEvent("0"));
registerCommand(context, 'extension.vim_1', () => handleKeyEvent("1"));
registerCommand(context, 'extension.vim_2', () => handleKeyEvent("2"));
registerCommand(context, 'extension.vim_3', () => handleKeyEvent("3"));
registerCommand(context, 'extension.vim_4', () => handleKeyEvent("4"));
registerCommand(context, 'extension.vim_5', () => handleKeyEvent("5"));
registerCommand(context, 'extension.vim_6', () => handleKeyEvent("6"));
registerCommand(context, 'extension.vim_7', () => handleKeyEvent("7"));
registerCommand(context, 'extension.vim_8', () => handleKeyEvent("8"));
registerCommand(context, 'extension.vim_9', () => handleKeyEvent("9"));

registerCommand(context, 'extension.vim_$', () => handleKeyEvent("$"));
registerCommand(context, 'extension.vim_^', () => handleKeyEvent("^"));

registerCommand(context, 'extension.vim_ctrl_r', () => handleKeyEvent("ctrl+r"));
registerCommand(context, 'extension.vim_ctrl_[', () => handleKeyEvent("ctrl+["));
registerCommand(context, 'extension.vim_ctrl_f', () => handleKeyEvent("ctrl+f"));
registerCommand(context, 'extension.vim_ctrl_b', () => handleKeyEvent("ctrl+b"));

registerCommand(context, 'extension.vim_%', () => handleKeyEvent("%"));

registerCommand(context, 'extension.vim_<', () => handleKeyEvent("<"));
registerCommand(context, 'extension.vim_>', () => handleKeyEvent(">"));

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

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 +45,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>;
}
Loading

0 comments on commit 03a980b

Please sign in to comment.