2016-05-28 01:49:35 +03:00
|
|
|
/**
|
|
|
|
* Extension.ts is a lightweight wrapper around ModeHandler. It converts key
|
|
|
|
* events to their string names and passes them on to ModeHandler via
|
|
|
|
* handleKeyEvent().
|
|
|
|
*/
|
2016-02-07 09:37:46 +03:00
|
|
|
|
2015-11-13 10:38:13 +03:00
|
|
|
import * as vscode from 'vscode';
|
2017-06-28 03:02:35 +03:00
|
|
|
import * as _ from 'lodash';
|
2016-06-30 19:35:56 +03:00
|
|
|
import { showCmdLine } from './src/cmd_line/main';
|
|
|
|
import { ModeHandler } from './src/mode/modeHandler';
|
2016-08-19 11:55:15 +03:00
|
|
|
import { taskQueue } from './src/taskQueue';
|
2017-05-05 00:26:56 +03:00
|
|
|
import { Position } from './src/common/motion/position';
|
2016-08-28 22:20:32 +03:00
|
|
|
import { Globals } from './src/globals';
|
2016-09-06 21:26:15 +03:00
|
|
|
import { AngleBracketNotation } from './src/notation';
|
2016-10-10 06:41:28 +03:00
|
|
|
import { ModeName } from './src/mode/mode';
|
2017-05-04 01:48:10 +03:00
|
|
|
import { Configuration } from './src/configuration/configuration';
|
2017-04-22 00:57:32 +03:00
|
|
|
import { ICodeKeybinding } from './src/mode/remapper';
|
|
|
|
import { runCmdLine } from './src/cmd_line/main';
|
2015-11-12 22:51:40 +03:00
|
|
|
|
2017-05-04 23:15:10 +03:00
|
|
|
import './src/actions/vim.all';
|
2017-06-28 03:02:35 +03:00
|
|
|
import { attach } from 'promised-neovim-client';
|
|
|
|
import { spawn } from 'child_process';
|
|
|
|
import { Neovim } from './src/neovim/nvimUtil';
|
2017-05-04 01:48:10 +03:00
|
|
|
|
2016-08-03 09:27:23 +03:00
|
|
|
interface VSCodeKeybinding {
|
|
|
|
key: string;
|
2016-10-03 22:36:21 +03:00
|
|
|
mac?: string;
|
2016-10-03 22:59:45 +03:00
|
|
|
linux?: string;
|
2016-08-03 09:27:23 +03:00
|
|
|
command: string;
|
|
|
|
when: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
const packagejson: {
|
|
|
|
contributes: {
|
|
|
|
keybindings: VSCodeKeybinding[];
|
2017-06-28 03:02:35 +03:00
|
|
|
};
|
2016-08-03 09:27:23 +03:00
|
|
|
} = require('../package.json'); // out/../package.json
|
|
|
|
|
2016-07-21 03:17:50 +03:00
|
|
|
export class EditorIdentity {
|
|
|
|
private _fileName: string;
|
|
|
|
private _viewColumn: vscode.ViewColumn;
|
|
|
|
|
|
|
|
constructor(textEditor?: vscode.TextEditor) {
|
2017-06-28 03:02:35 +03:00
|
|
|
this._fileName = (textEditor && textEditor.document.fileName) || '';
|
|
|
|
this._viewColumn = (textEditor && textEditor.viewColumn) || vscode.ViewColumn.One;
|
2016-07-21 03:17:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
get fileName() {
|
|
|
|
return this._fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
get viewColumn() {
|
|
|
|
return this._viewColumn;
|
|
|
|
}
|
|
|
|
|
|
|
|
public hasSameBuffer(identity: EditorIdentity): boolean {
|
|
|
|
return this.fileName === identity.fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
public isEqual(identity: EditorIdentity): boolean {
|
|
|
|
return this.fileName === identity.fileName && this.viewColumn === identity.viewColumn;
|
|
|
|
}
|
|
|
|
|
|
|
|
public toString() {
|
|
|
|
return this.fileName + this.viewColumn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-30 19:35:56 +03:00
|
|
|
let extensionContext: vscode.ExtensionContext;
|
2016-06-18 10:21:17 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Note: We can't initialize modeHandler here, or even inside activate(), because some people
|
|
|
|
* see a bug where VSC hasn't fully initialized yet, which pretty much breaks VSCodeVim entirely.
|
|
|
|
*/
|
2016-07-21 03:17:50 +03:00
|
|
|
let modeHandlerToEditorIdentity: { [key: string]: ModeHandler } = {};
|
|
|
|
let previousActiveEditorId: EditorIdentity = new EditorIdentity();
|
2016-06-30 19:35:56 +03:00
|
|
|
|
2016-07-04 02:09:48 +03:00
|
|
|
export async function getAndUpdateModeHandler(): Promise<ModeHandler> {
|
2017-05-02 23:15:15 +03:00
|
|
|
const prevHandler = modeHandlerToEditorIdentity[previousActiveEditorId.toString()];
|
2016-07-21 03:17:50 +03:00
|
|
|
const activeEditorId = new EditorIdentity(vscode.window.activeTextEditor);
|
2016-07-04 02:09:48 +03:00
|
|
|
|
2017-05-02 23:15:15 +03:00
|
|
|
let curHandler = modeHandlerToEditorIdentity[activeEditorId.toString()];
|
|
|
|
if (!curHandler) {
|
2017-05-22 21:15:17 +03:00
|
|
|
if (!Configuration.disableAnnoyingNeovimMessage) {
|
2017-06-28 03:02:35 +03:00
|
|
|
vscode.window
|
|
|
|
.showInformationMessage(
|
|
|
|
'We have now added neovim integration for Ex-commands.\
|
|
|
|
Enable it with vim.enableNeovim in settings',
|
|
|
|
'Never show again'
|
|
|
|
)
|
|
|
|
.then(result => {
|
|
|
|
if (result !== 'Close') {
|
|
|
|
vscode.workspace
|
|
|
|
.getConfiguration('vim')
|
|
|
|
.update('disableAnnoyingNeovimMessage', true, true);
|
2017-05-22 21:15:17 +03:00
|
|
|
Configuration.disableAnnoyingNeovimMessage = true;
|
2017-05-22 10:15:47 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2017-05-21 19:51:40 +03:00
|
|
|
const newModeHandler = await new ModeHandler();
|
2017-05-21 20:25:15 +03:00
|
|
|
if (Configuration.enableNeovim) {
|
2017-06-28 03:02:35 +03:00
|
|
|
await Neovim.initNvim(newModeHandler.vimState);
|
2017-05-21 20:25:15 +03:00
|
|
|
}
|
2016-07-21 03:17:50 +03:00
|
|
|
modeHandlerToEditorIdentity[activeEditorId.toString()] = newModeHandler;
|
2017-05-02 23:21:15 +03:00
|
|
|
extensionContext.subscriptions.push(newModeHandler);
|
|
|
|
|
2017-05-02 23:15:15 +03:00
|
|
|
curHandler = newModeHandler;
|
2016-07-16 20:02:31 +03:00
|
|
|
}
|
2016-07-04 02:09:48 +03:00
|
|
|
|
2017-05-02 23:15:15 +03:00
|
|
|
curHandler.vimState.editor = vscode.window.activeTextEditor!;
|
|
|
|
if (!prevHandler || curHandler.identity !== prevHandler.identity) {
|
|
|
|
setTimeout(() => {
|
|
|
|
curHandler.syncCursors();
|
|
|
|
}, 0);
|
|
|
|
}
|
2017-03-03 08:08:43 +03:00
|
|
|
|
2016-07-21 03:17:50 +03:00
|
|
|
if (previousActiveEditorId.hasSameBuffer(activeEditorId)) {
|
|
|
|
if (!previousActiveEditorId.isEqual(activeEditorId)) {
|
|
|
|
// We have opened two editors, working on the same file.
|
|
|
|
previousActiveEditorId = activeEditorId;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
previousActiveEditorId = activeEditorId;
|
2016-07-04 02:09:48 +03:00
|
|
|
|
2017-06-28 03:02:35 +03:00
|
|
|
await curHandler.updateView(curHandler.vimState, { drawSelection: false, revealRange: false });
|
2016-07-16 20:02:31 +03:00
|
|
|
}
|
2016-07-04 02:09:48 +03:00
|
|
|
|
2017-05-02 23:15:15 +03:00
|
|
|
if (prevHandler && curHandler.vimState.focusChanged) {
|
|
|
|
curHandler.vimState.focusChanged = false;
|
|
|
|
prevHandler.vimState.focusChanged = true;
|
2016-07-16 20:02:31 +03:00
|
|
|
}
|
2016-06-30 19:35:56 +03:00
|
|
|
|
2017-05-02 23:15:15 +03:00
|
|
|
vscode.commands.executeCommand('setContext', 'vim.mode', curHandler.vimState.currentModeName());
|
2017-01-21 09:00:51 +03:00
|
|
|
|
2017-03-18 06:19:00 +03:00
|
|
|
// Temporary workaround for vscode bug not changing cursor style properly
|
|
|
|
// https://github.com/Microsoft/vscode/issues/17472
|
|
|
|
// https://github.com/Microsoft/vscode/issues/17513
|
2017-05-02 23:15:15 +03:00
|
|
|
const options = curHandler.vimState.editor.options;
|
2017-03-18 06:19:00 +03:00
|
|
|
const desiredStyle = options.cursorStyle;
|
|
|
|
|
|
|
|
// Temporarily change to any other cursor style besides the desired type, then change back
|
|
|
|
if (desiredStyle === vscode.TextEditorCursorStyle.Block) {
|
2017-05-02 23:15:15 +03:00
|
|
|
curHandler.vimState.editor.options.cursorStyle = vscode.TextEditorCursorStyle.Line;
|
|
|
|
curHandler.vimState.editor.options.cursorStyle = desiredStyle;
|
2017-03-18 06:19:00 +03:00
|
|
|
} else {
|
2017-05-02 23:15:15 +03:00
|
|
|
curHandler.vimState.editor.options.cursorStyle = vscode.TextEditorCursorStyle.Block;
|
|
|
|
curHandler.vimState.editor.options.cursorStyle = desiredStyle;
|
2017-03-18 06:19:00 +03:00
|
|
|
}
|
|
|
|
|
2017-05-02 23:15:15 +03:00
|
|
|
return curHandler;
|
2016-06-30 19:35:56 +03:00
|
|
|
}
|
2015-11-17 09:14:48 +03:00
|
|
|
|
2016-07-22 01:16:37 +03:00
|
|
|
class CompositionState {
|
|
|
|
public isInComposition: boolean = false;
|
2017-06-28 03:02:35 +03:00
|
|
|
public composingText: string = '';
|
2016-07-22 01:16:37 +03:00
|
|
|
}
|
|
|
|
|
2016-07-17 06:39:30 +03:00
|
|
|
export async function activate(context: vscode.ExtensionContext) {
|
2016-07-16 20:02:31 +03:00
|
|
|
extensionContext = context;
|
2016-07-22 01:16:37 +03:00
|
|
|
let compositionState = new CompositionState();
|
2016-07-16 20:02:31 +03:00
|
|
|
|
2017-03-05 23:37:25 +03:00
|
|
|
// Event to update active configuration items when changed without restarting vscode
|
|
|
|
vscode.workspace.onDidChangeConfiguration((e: void) => {
|
|
|
|
Configuration.updateConfiguration();
|
|
|
|
|
2017-05-04 21:24:00 +03:00
|
|
|
/* tslint:disable:forin */
|
2017-03-05 23:37:25 +03:00
|
|
|
// Update the remappers foreach modehandler
|
|
|
|
for (let mh in modeHandlerToEditorIdentity) {
|
2017-03-06 04:21:37 +03:00
|
|
|
modeHandlerToEditorIdentity[mh].createRemappers();
|
2017-03-05 23:37:25 +03:00
|
|
|
}
|
2017-05-04 21:24:00 +03:00
|
|
|
});
|
2017-03-05 23:37:25 +03:00
|
|
|
|
2016-08-28 22:20:32 +03:00
|
|
|
vscode.window.onDidChangeActiveTextEditor(handleActiveEditorChange, this);
|
|
|
|
|
2017-06-28 03:02:35 +03:00
|
|
|
vscode.workspace.onDidChangeTextDocument(event => {
|
2017-03-07 02:32:47 +03:00
|
|
|
if (!Globals.active) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-03 10:36:44 +03:00
|
|
|
/**
|
|
|
|
* Change from vscode editor should set document.isDirty to true but they initially don't!
|
|
|
|
* There is a timing issue in vscode codebase between when the isDirty flag is set and
|
|
|
|
* when registered callbacks are fired. https://github.com/Microsoft/vscode/issues/11339
|
|
|
|
*/
|
2016-10-10 06:41:28 +03:00
|
|
|
|
|
|
|
let contentChangeHandler = (modeHandler: ModeHandler) => {
|
|
|
|
if (modeHandler.vimState.currentMode === ModeName.Insert) {
|
|
|
|
if (modeHandler.vimState.historyTracker.currentContentChanges === undefined) {
|
|
|
|
modeHandler.vimState.historyTracker.currentContentChanges = [];
|
|
|
|
}
|
|
|
|
|
2017-06-28 03:02:35 +03:00
|
|
|
modeHandler.vimState.historyTracker.currentContentChanges = modeHandler.vimState.historyTracker.currentContentChanges.concat(
|
|
|
|
event.contentChanges
|
|
|
|
);
|
2016-10-10 06:41:28 +03:00
|
|
|
}
|
2017-05-04 21:24:00 +03:00
|
|
|
};
|
2016-10-10 06:41:28 +03:00
|
|
|
|
|
|
|
if (Globals.isTesting) {
|
|
|
|
contentChangeHandler(Globals.modeHandlerForTesting as ModeHandler);
|
|
|
|
} else {
|
2017-06-28 03:02:35 +03:00
|
|
|
_.filter(
|
|
|
|
modeHandlerToEditorIdentity,
|
|
|
|
modeHandler => modeHandler.identity.fileName === event.document.fileName
|
|
|
|
).forEach(modeHandler => {
|
|
|
|
contentChangeHandler(modeHandler);
|
|
|
|
});
|
2016-10-10 06:41:28 +03:00
|
|
|
}
|
2017-06-11 05:22:29 +03:00
|
|
|
setTimeout(() => {
|
2017-06-28 03:02:35 +03:00
|
|
|
if (!event.document.isDirty && !event.document.isUntitled && event.contentChanges.length) {
|
|
|
|
handleContentChangedFromDisk(event.document);
|
|
|
|
}
|
|
|
|
}, 0);
|
2016-09-03 10:36:44 +03:00
|
|
|
});
|
2016-07-16 20:02:31 +03:00
|
|
|
|
2017-06-28 03:02:35 +03:00
|
|
|
overrideCommand(context, 'type', async args => {
|
2016-07-16 20:02:31 +03:00
|
|
|
taskQueue.enqueueTask({
|
|
|
|
promise: async () => {
|
|
|
|
const mh = await getAndUpdateModeHandler();
|
2016-07-22 01:16:37 +03:00
|
|
|
|
|
|
|
if (compositionState.isInComposition) {
|
|
|
|
compositionState.composingText += args.text;
|
|
|
|
} else {
|
|
|
|
await mh.handleKeyEvent(args.text);
|
|
|
|
}
|
2016-07-16 20:02:31 +03:00
|
|
|
},
|
2017-06-28 03:02:35 +03:00
|
|
|
isRunning: false,
|
2016-03-24 10:28:55 +03:00
|
|
|
});
|
2016-07-16 20:02:31 +03:00
|
|
|
});
|
2016-05-28 01:49:35 +03:00
|
|
|
|
2017-06-28 03:02:35 +03:00
|
|
|
overrideCommand(context, 'replacePreviousChar', async args => {
|
2016-07-16 20:02:31 +03:00
|
|
|
taskQueue.enqueueTask({
|
|
|
|
promise: async () => {
|
|
|
|
const mh = await getAndUpdateModeHandler();
|
2016-07-22 01:16:37 +03:00
|
|
|
|
|
|
|
if (compositionState.isInComposition) {
|
2017-06-28 03:02:35 +03:00
|
|
|
compositionState.composingText =
|
|
|
|
compositionState.composingText.substr(
|
|
|
|
0,
|
|
|
|
compositionState.composingText.length - args.replaceCharCnt
|
|
|
|
) + args.text;
|
2016-07-22 01:16:37 +03:00
|
|
|
} else {
|
|
|
|
await vscode.commands.executeCommand('default:replacePreviousChar', {
|
|
|
|
text: args.text,
|
2017-06-28 03:02:35 +03:00
|
|
|
replaceCharCnt: args.replaceCharCnt,
|
2016-07-22 01:16:37 +03:00
|
|
|
});
|
2017-06-28 03:02:35 +03:00
|
|
|
mh.vimState.cursorPosition = Position.FromVSCodePosition(
|
|
|
|
mh.vimState.editor.selection.start
|
|
|
|
);
|
|
|
|
mh.vimState.cursorStartPosition = Position.FromVSCodePosition(
|
|
|
|
mh.vimState.editor.selection.start
|
|
|
|
);
|
|
|
|
}
|
2016-07-22 01:16:37 +03:00
|
|
|
},
|
2017-06-28 03:02:35 +03:00
|
|
|
isRunning: false,
|
2016-07-22 01:16:37 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-06-28 03:02:35 +03:00
|
|
|
overrideCommand(context, 'compositionStart', async args => {
|
2016-07-22 01:16:37 +03:00
|
|
|
taskQueue.enqueueTask({
|
|
|
|
promise: async () => {
|
|
|
|
compositionState.isInComposition = true;
|
|
|
|
},
|
2017-06-28 03:02:35 +03:00
|
|
|
isRunning: false,
|
2016-07-22 01:16:37 +03:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-06-28 03:02:35 +03:00
|
|
|
overrideCommand(context, 'compositionEnd', async args => {
|
2016-07-22 01:16:37 +03:00
|
|
|
taskQueue.enqueueTask({
|
|
|
|
promise: async () => {
|
|
|
|
const mh = await getAndUpdateModeHandler();
|
|
|
|
let text = compositionState.composingText;
|
|
|
|
compositionState = new CompositionState();
|
2017-06-28 03:02:35 +03:00
|
|
|
await mh.handleMultipleKeyEvents(text.split(''));
|
2016-07-16 20:02:31 +03:00
|
|
|
},
|
2017-06-28 03:02:35 +03:00
|
|
|
isRunning: false,
|
2016-07-16 20:02:31 +03:00
|
|
|
});
|
2016-07-17 06:39:30 +03:00
|
|
|
});
|
2016-07-14 20:54:04 +03:00
|
|
|
|
2016-07-16 20:02:31 +03:00
|
|
|
registerCommand(context, 'extension.showCmdLine', () => {
|
2017-06-28 03:02:35 +03:00
|
|
|
showCmdLine(
|
|
|
|
'',
|
|
|
|
modeHandlerToEditorIdentity[new EditorIdentity(vscode.window.activeTextEditor).toString()]
|
|
|
|
);
|
2016-07-16 20:02:31 +03:00
|
|
|
});
|
2015-11-17 23:41:38 +03:00
|
|
|
|
2017-04-22 00:57:32 +03:00
|
|
|
registerCommand(context, 'vim.remap', async (args: ICodeKeybinding) => {
|
|
|
|
taskQueue.enqueueTask({
|
|
|
|
promise: async () => {
|
|
|
|
const mh = await getAndUpdateModeHandler();
|
|
|
|
if (args.after) {
|
|
|
|
for (const key of args.after) {
|
|
|
|
await mh.handleKeyEvent(AngleBracketNotation.Normalize(key));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (args.commands) {
|
|
|
|
for (const command of args.commands) {
|
|
|
|
// Check if this is a vim command by looking for :
|
2017-06-28 03:02:35 +03:00
|
|
|
if (command.command.slice(0, 1) === ':') {
|
2017-04-22 00:57:32 +03:00
|
|
|
await runCmdLine(command.command.slice(1, command.command.length), mh);
|
|
|
|
await mh.updateView(mh.vimState);
|
|
|
|
} else {
|
|
|
|
await vscode.commands.executeCommand(command.command, command.args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2017-06-28 03:02:35 +03:00
|
|
|
isRunning: false,
|
2017-04-22 00:57:32 +03:00
|
|
|
});
|
|
|
|
});
|
2017-03-07 02:32:47 +03:00
|
|
|
|
|
|
|
registerCommand(context, 'toggleVim', async () => {
|
|
|
|
Globals.active = !Globals.active;
|
|
|
|
if (Globals.active) {
|
|
|
|
await vscode.commands.executeCommand('setContext', 'vim.active', Globals.active);
|
|
|
|
compositionState = new CompositionState();
|
|
|
|
modeHandlerToEditorIdentity = {};
|
|
|
|
let mh = await getAndUpdateModeHandler();
|
|
|
|
mh.updateView(mh.vimState, { drawSelection: false, revealRange: false });
|
|
|
|
} else {
|
2017-06-28 03:02:35 +03:00
|
|
|
let cursorStyle = await vscode.workspace
|
|
|
|
.getConfiguration('editor')
|
|
|
|
.get('cursorStyle', 'line');
|
2017-03-07 22:31:01 +03:00
|
|
|
vscode.window.visibleTextEditors.forEach(editor => {
|
|
|
|
let options = editor.options;
|
2017-03-07 02:32:47 +03:00
|
|
|
switch (cursorStyle) {
|
|
|
|
case 'line':
|
|
|
|
options.cursorStyle = vscode.TextEditorCursorStyle.Line;
|
|
|
|
break;
|
|
|
|
case 'block':
|
|
|
|
options.cursorStyle = vscode.TextEditorCursorStyle.Block;
|
|
|
|
break;
|
|
|
|
case 'underline':
|
|
|
|
options.cursorStyle = vscode.TextEditorCursorStyle.Underline;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2017-03-07 22:31:01 +03:00
|
|
|
editor.options = options;
|
|
|
|
});
|
2017-03-07 02:32:47 +03:00
|
|
|
await vscode.commands.executeCommand('setContext', 'vim.active', Globals.active);
|
2017-05-01 06:15:52 +03:00
|
|
|
let mh = await getAndUpdateModeHandler();
|
|
|
|
mh.setStatusBarText('-- VIM: DISABLED --');
|
2017-03-07 02:32:47 +03:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
vscode.commands.executeCommand('setContext', 'vim.active', Globals.active);
|
|
|
|
|
2017-03-25 19:20:12 +03:00
|
|
|
// Clear boundKeyCombinations array incase there are any entries in it so
|
|
|
|
// that we have a clean list of keys with no duplicates
|
|
|
|
Configuration.boundKeyCombinations = [];
|
|
|
|
|
2016-10-02 11:34:11 +03:00
|
|
|
for (let keybinding of packagejson.contributes.keybindings) {
|
2017-06-28 03:02:35 +03:00
|
|
|
if (keybinding.when.indexOf('listFocus') !== -1) {
|
2017-06-20 13:45:56 +03:00
|
|
|
continue;
|
|
|
|
}
|
2017-06-28 03:02:35 +03:00
|
|
|
let keyToBeBound = '';
|
2016-10-03 22:36:21 +03:00
|
|
|
/**
|
|
|
|
* On OSX, handle mac keybindings if we specified one.
|
|
|
|
*/
|
2017-06-28 03:02:35 +03:00
|
|
|
if (process.platform === 'darwin') {
|
2016-10-03 22:36:21 +03:00
|
|
|
keyToBeBound = keybinding.mac || keybinding.key;
|
2017-06-28 03:02:35 +03:00
|
|
|
} else if (process.platform === 'linux') {
|
2016-10-03 22:59:45 +03:00
|
|
|
keyToBeBound = keybinding.linux || keybinding.key;
|
2016-10-03 22:36:21 +03:00
|
|
|
} else {
|
|
|
|
keyToBeBound = keybinding.key;
|
|
|
|
}
|
|
|
|
|
2017-03-25 19:20:12 +03:00
|
|
|
const bracketedKey = AngleBracketNotation.Normalize(keyToBeBound);
|
2016-10-03 22:36:21 +03:00
|
|
|
|
2017-03-25 09:11:09 +03:00
|
|
|
// Store registered key bindings in bracket notation form
|
|
|
|
Configuration.boundKeyCombinations.push(bracketedKey);
|
2016-10-03 22:36:21 +03:00
|
|
|
|
2017-06-28 03:02:35 +03:00
|
|
|
registerCommand(context, keybinding.command, () => handleKeyEvent(`${bracketedKey}`));
|
2016-08-03 09:27:23 +03:00
|
|
|
}
|
2016-07-17 06:39:30 +03:00
|
|
|
|
2017-03-25 09:11:09 +03:00
|
|
|
// Update configuration now that bound keys array is populated
|
|
|
|
Configuration.updateConfiguration();
|
|
|
|
|
2016-07-17 06:39:30 +03:00
|
|
|
// Initialize mode handler for current active Text Editor at startup.
|
|
|
|
if (vscode.window.activeTextEditor) {
|
2016-10-03 22:36:21 +03:00
|
|
|
let mh = await getAndUpdateModeHandler();
|
2017-06-28 03:02:35 +03:00
|
|
|
mh.updateView(mh.vimState, { drawSelection: false, revealRange: false });
|
2016-07-17 06:39:30 +03:00
|
|
|
}
|
2015-11-29 10:11:55 +03:00
|
|
|
}
|
|
|
|
|
2017-06-28 03:02:35 +03:00
|
|
|
function overrideCommand(
|
|
|
|
context: vscode.ExtensionContext,
|
|
|
|
command: string,
|
|
|
|
callback: (...args: any[]) => any
|
|
|
|
) {
|
|
|
|
let disposable = vscode.commands.registerCommand(command, async args => {
|
2017-03-07 02:32:47 +03:00
|
|
|
if (!Globals.active) {
|
2017-06-28 03:02:35 +03:00
|
|
|
await vscode.commands.executeCommand('default:' + command, args);
|
2017-03-07 02:32:47 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-14 08:20:53 +03:00
|
|
|
if (!vscode.window.activeTextEditor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-06-28 03:02:35 +03:00
|
|
|
if (
|
|
|
|
vscode.window.activeTextEditor.document &&
|
|
|
|
vscode.window.activeTextEditor.document.uri.toString() === 'debug:input'
|
|
|
|
) {
|
|
|
|
await vscode.commands.executeCommand('default:' + command, args);
|
2016-09-14 08:20:53 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(args);
|
|
|
|
});
|
2016-07-16 20:02:31 +03:00
|
|
|
context.subscriptions.push(disposable);
|
2015-11-17 09:14:48 +03:00
|
|
|
}
|
|
|
|
|
2017-06-28 03:02:35 +03:00
|
|
|
function registerCommand(
|
|
|
|
context: vscode.ExtensionContext,
|
|
|
|
command: string,
|
|
|
|
callback: (...args: any[]) => any
|
|
|
|
) {
|
|
|
|
let disposable = vscode.commands.registerCommand(command, async args => {
|
2017-03-07 02:32:47 +03:00
|
|
|
if (!vscode.window.activeTextEditor) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(args);
|
|
|
|
});
|
|
|
|
context.subscriptions.push(disposable);
|
|
|
|
}
|
|
|
|
|
2016-07-04 02:09:48 +03:00
|
|
|
async function handleKeyEvent(key: string): Promise<void> {
|
2016-07-16 20:02:31 +03:00
|
|
|
const mh = await getAndUpdateModeHandler();
|
2016-01-30 22:41:53 +03:00
|
|
|
|
2016-07-16 20:02:31 +03:00
|
|
|
taskQueue.enqueueTask({
|
2017-06-28 03:02:35 +03:00
|
|
|
promise: async () => {
|
2016-12-06 01:29:51 +03:00
|
|
|
await mh.handleKeyEvent(key);
|
|
|
|
},
|
2017-06-28 03:02:35 +03:00
|
|
|
isRunning: false,
|
2016-07-16 20:02:31 +03:00
|
|
|
});
|
2016-06-30 19:35:56 +03:00
|
|
|
}
|
|
|
|
|
2017-06-28 03:02:35 +03:00
|
|
|
function handleContentChangedFromDisk(document: vscode.TextDocument): void {
|
|
|
|
_.filter(
|
|
|
|
modeHandlerToEditorIdentity,
|
|
|
|
modeHandler => modeHandler.identity.fileName === document.fileName
|
|
|
|
).forEach(modeHandler => {
|
|
|
|
modeHandler.vimState.historyTracker.clear();
|
|
|
|
});
|
2016-09-03 10:36:44 +03:00
|
|
|
}
|
|
|
|
|
2016-08-28 22:20:32 +03:00
|
|
|
async function handleActiveEditorChange(): Promise<void> {
|
2017-03-07 02:32:47 +03:00
|
|
|
if (!Globals.active) {
|
|
|
|
return;
|
|
|
|
}
|
2016-08-28 22:20:32 +03:00
|
|
|
|
|
|
|
// Don't run this event handler during testing
|
|
|
|
if (Globals.isTesting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-09-04 08:54:10 +03:00
|
|
|
taskQueue.enqueueTask({
|
|
|
|
promise: async () => {
|
|
|
|
if (vscode.window.activeTextEditor !== undefined) {
|
|
|
|
const mh = await getAndUpdateModeHandler();
|
|
|
|
|
2017-06-28 03:02:35 +03:00
|
|
|
mh.updateView(mh.vimState, { drawSelection: false, revealRange: false });
|
2016-09-04 08:54:10 +03:00
|
|
|
}
|
|
|
|
},
|
2017-06-28 03:02:35 +03:00
|
|
|
isRunning: false,
|
2016-09-04 08:54:10 +03:00
|
|
|
});
|
2016-08-28 22:20:32 +03:00
|
|
|
}
|
|
|
|
|
2016-06-30 19:35:56 +03:00
|
|
|
process.on('unhandledRejection', function(reason: any, p: any) {
|
2017-06-28 03:02:35 +03:00
|
|
|
console.log('Unhandled Rejection at: Promise ', p, ' reason: ', reason);
|
2016-07-15 10:59:08 +03:00
|
|
|
});
|