Skip to content

Commit

Permalink
stop repeating myself
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Sep 8, 2016
1 parent dd5b2f5 commit 9f16a2f
Showing 1 changed file with 12 additions and 32 deletions.
44 changes: 12 additions & 32 deletions extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,6 @@ export async function activate(context: vscode.ExtensionContext) {
});

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

if (vscode.window.activeTextEditor.document && vscode.window.activeTextEditor.document.uri.toString() === "debug:input") {
await vscode.commands.executeCommand("default:type", args);
return;
}

taskQueue.enqueueTask({
promise: async () => {
const mh = await getAndUpdateModeHandler();
Expand All @@ -152,15 +143,6 @@ export async function activate(context: vscode.ExtensionContext) {
});

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

if (vscode.window.activeTextEditor.document && vscode.window.activeTextEditor.document.uri.toString() === "debug:input") {
await vscode.commands.executeCommand("default:replacePreviousChar", args);
return;
}

taskQueue.enqueueTask({
promise: async () => {
const mh = await getAndUpdateModeHandler();
Expand All @@ -181,10 +163,6 @@ export async function activate(context: vscode.ExtensionContext) {
});

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

if (vscode.window.activeTextEditor.document && vscode.window.activeTextEditor.document.uri.toString() === "debug:input") {
await vscode.commands.executeCommand("default:compositionStart", args);
return;
Expand All @@ -200,15 +178,6 @@ export async function activate(context: vscode.ExtensionContext) {
});

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

if (vscode.window.activeTextEditor.document && vscode.window.activeTextEditor.document.uri.toString() === "debug:input") {
await vscode.commands.executeCommand("default:compositionEnd", args);
return;
}

taskQueue.enqueueTask({
promise: async () => {
const mh = await getAndUpdateModeHandler();
Expand Down Expand Up @@ -237,7 +206,18 @@ export async function activate(context: vscode.ExtensionContext) {
}

function registerCommand(context: vscode.ExtensionContext, command: string, callback: (...args: any[]) => any) {
let disposable = vscode.commands.registerCommand(command, callback);
let disposable = vscode.commands.registerCommand(command, async (args) => {
if (!vscode.window.activeTextEditor) {
return;
}

if (vscode.window.activeTextEditor.document && vscode.window.activeTextEditor.document.uri.toString() === "debug:input") {
await vscode.commands.executeCommand("default:" + command, args);
return;
}

callback(args);
});
context.subscriptions.push(disposable);
}

Expand Down

0 comments on commit 9f16a2f

Please sign in to comment.