diff --git a/README.md b/README.md index 4cf982ee3c9..8ff99a5bd83 100644 --- a/README.md +++ b/README.md @@ -25,22 +25,21 @@ _Note_: Currently, by defining keybindings for a mode, all bindings for that mod Example: ```json { - "vim.normalModeKeybindings": { + "vim.normalModeKeyBindings": { "d": "DeleteChar", "D": "DeleteLastChar" }, - "vim.insertModeKeybindings": { + "vim.insertModeKeyBindings": { "e": "InsertAtCursor", "E": "InsertAfterCursor" } } ``` -Supported Actions +* vim.normalModeKeyBindings + * Supported Actions: -* vim.normalModeKeybindings - - ``` + ``` MoveUp MoveDown MoveLeft @@ -70,7 +69,13 @@ Supported Actions // Find Find - + + // Folding + Fold + Unfold + FoldAll + UnfoldAll + // Text Modification Undo Redo @@ -103,9 +108,9 @@ Supported Actions ExitMessages ``` -* vim.insertModeKeybindings - - ``` +* vim.insertModeKeyBindings + * Supported Actions: + ``` // Enter insert mode InsertAtCursor InsertAtLineBegin @@ -115,8 +120,8 @@ Supported Actions InsertNewLineAbove ``` -* vim.visualModeKeybindings - +* vim.visualModeKeyBindings + * Supported Actions: ``` EnterVisualMode ``` diff --git a/extension.ts b/extension.ts index f0122077539..31b2aee7b85 100644 --- a/extension.ts +++ b/extension.ts @@ -18,7 +18,7 @@ export function activate(context: vscode.ExtensionContext) { } console.log(args.text); - console.log(args); + var isHandled = await handleKeyEvent(args.text); if (!isHandled) { diff --git a/package.json b/package.json index d66becfe29f..c33f99f99f4 100644 --- a/package.json +++ b/package.json @@ -50,15 +50,15 @@ "type": "string", "description": "Keyboard layout to use to translated key presses." }, - "vim.normalModeKeybindings": { + "vim.normalModeKeyBindings": { "type": "object", "description": "Keybinding overrides to use for normal mode." }, - "vim.insertModeKeybindings": { + "vim.insertModeKeyBindings": { "type": "object", "description": "Keybinding overrides to use for insert mode." }, - "vim.visualModeKeybindings": { + "vim.visualModeKeyBindings": { "type": "object", "description": "Keybinding overrides to use for visual mode." } diff --git a/src/configuration.ts b/src/configuration.ts deleted file mode 100644 index 38c75501f9f..00000000000 --- a/src/configuration.ts +++ /dev/null @@ -1,17 +0,0 @@ -"use strict"; - -import {KeyboardLayout} from "./keyboard"; - -export class Configuration { - - keyboardLayout : KeyboardLayout; - - constructor(keyboard : KeyboardLayout) { - this.keyboardLayout = keyboard; - } - - static fromUserFile() { - // TODO: read .vimrc or a similar file. - return new Configuration(KeyboardLayout.fromUserConfiguration()); - } -} \ No newline at end of file diff --git a/src/configuration/commandKeyMap.ts b/src/configuration/commandKeyMap.ts new file mode 100644 index 00000000000..99891938eb2 --- /dev/null +++ b/src/configuration/commandKeyMap.ts @@ -0,0 +1,205 @@ +import * as vscode from 'vscode'; + +export enum Command { + // Enter insert mode + InsertAtCursor = 1, + InsertAtLineBegin, + InsertAfterCursor, + InsertAtLineEnd, + InsertNewLineBelow, + InsertNewLineAbove, + + // Movement + MoveUp, + MoveDown, + MoveLeft, + MoveRight, + + MoveLineBegin, + MoveLineEnd, + MoveWordBegin, + MoveWordEnd, + MoveFullWordBegin, + MoveFullWordEnd, + MoveLastWord, + MoveLastFullWord, + MoveLastWordEnd, + MoveLastFullWordEnd, + + // MoveHalfPageUp, + // MoveHalfPageDown, + MoveFullPageUp, + MoveFullPageDown, + // MoveFirstLine, + // MoveLastLine, + + MoveParagraphBegin, + MoveParagraphEnd, + + MoveNonBlank, + MoveNonBlankFirst, + MoveNonBlankLast, + MoveMatchingBracket, + + // Find + Find, + + // Folding + Fold, + Unfold, + FoldAll, + UnfoldAll, + + // Text Modification + Undo, + Redo, + Copy, + Paste, + + ChangeWord, + ChangeFullWord, + ChangeCurrentWord, + ChangeCurrentWordToNext, + ChangeToLineEnd, + + DeleteLine, + DeleteToNextWord, + DeleteToFullNextWord, + DeleteToWordEnd, + DeleteToFullWordEnd, + DeleteToWordBegin, + DeleteToFullWordBegin, + DeleteToLineEnd, + + DeleteChar, + DeleteLastChar, + + Indent, + Outdent, + + // Misc + EnterVisualMode, + EnterCommand, + ExitMessages, +} + +export type CommandKeyHandler = {[key: string]: Command}; + +export class CommandKeyMap { + + public normalModeKeyMap : CommandKeyHandler; + public insertModeKeyMap : CommandKeyHandler; + public visualModeKeyMap : CommandKeyHandler; + + constructor( + normalModeKeyMap : CommandKeyHandler, + insertModeKeyMap : CommandKeyHandler, + visualModeKeyMap : CommandKeyHandler) { + this.normalModeKeyMap = normalModeKeyMap; + this.insertModeKeyMap = insertModeKeyMap; + this.visualModeKeyMap = visualModeKeyMap; + } + + static fromUserConfiguration() : CommandKeyMap { + let getConfig = function(keyHandlers : CommandKeyHandler, configName : string) : CommandKeyHandler { + let overrides = vscode.workspace.getConfiguration("vim") + .get(configName, keyHandlers); + + // merge + for (let key in overrides) { + if (overrides.hasOwnProperty(key)) { + keyHandlers[key] = overrides[key]; + } + } + return keyHandlers; + }; + + let normalMode = getConfig(CommandKeyMap.DefaultNormalKeyMap(), "normalModeKeyBindings"); + let insertMode = getConfig(CommandKeyMap.DefaultInsertKeyMap(), "insertModeKeyBindings"); + let visualMode = getConfig(CommandKeyMap.DefaultVisualKeyMap(), "visualModeKeyBindings"); + + return new CommandKeyMap(normalMode, insertMode, visualMode); + } + + static DefaultNormalKeyMap() : CommandKeyHandler { + return { + "h": Command.MoveLeft, + "j": Command.MoveDown, + "k": Command.MoveUp, + "l": Command.MoveRight, + "0": Command.MoveLineBegin, + "$": Command.MoveLineEnd, + + "^": Command.MoveNonBlank, + "gg": Command.MoveNonBlankFirst, + "G": Command.MoveNonBlankLast, + + "w": Command.MoveWordBegin, + "W": Command.MoveFullWordBegin, + "e": Command.MoveWordEnd, + "E": Command.MoveLastFullWordEnd, + "ge": Command.MoveLastWordEnd, + "gE": Command.MoveLastFullWordEnd, + "b": Command.MoveLastWord, + "B": Command.MoveLastFullWord, + + "{": Command.MoveParagraphBegin, + "}": Command.MoveParagraphEnd, + "%": Command.MoveMatchingBracket, + + ">>": Command.Indent, + "<<": Command.Outdent, + + "u": Command.Undo, + "ctrl+r": Command.Redo, + "yy": Command.Copy, + "p": Command.Paste, + + "cw": Command.ChangeWord, + "cW": Command.ChangeFullWord, + "ciw": Command.ChangeCurrentWord, + "caw": Command.ChangeCurrentWordToNext, + "C": Command.ChangeToLineEnd, + + "dd": Command.DeleteLine, + "dw": Command.DeleteToNextWord, + "dW": Command.DeleteToFullNextWord, + "db": Command.DeleteToWordBegin, + "dB": Command.DeleteToFullWordBegin, + "de": Command.DeleteToWordEnd, + "dE": Command.DeleteToFullWordEnd, + "D" : Command.DeleteToLineEnd, + + "x": Command.DeleteChar, + "X": Command.DeleteLastChar, + + "/": Command.Find, + + "zc": Command.Fold, + "zo": Command.Unfold, + "zC": Command.FoldAll, + "zO": Command.UnfoldAll, + + ":": Command.EnterCommand, + "v": Command.EnterVisualMode, + "esc": Command.ExitMessages + }; + } + + static DefaultInsertKeyMap() : CommandKeyHandler { + return { + "i": Command.InsertAtCursor, + "I": Command.InsertAtLineBegin, + "a": Command.InsertAfterCursor, + "A": Command.InsertAtLineEnd, + "o": Command.InsertNewLineBelow, + "O": Command.InsertNewLineAbove, + }; + } + + static DefaultVisualKeyMap() : CommandKeyHandler { + return { + "v": Command.EnterVisualMode + }; + } +} \ No newline at end of file diff --git a/src/configuration/configuration.ts b/src/configuration/configuration.ts new file mode 100644 index 00000000000..fefad3f08f4 --- /dev/null +++ b/src/configuration/configuration.ts @@ -0,0 +1,22 @@ +"use strict"; + +import { CommandKeyMap } from './commandKeyMap'; +import { KeyboardLayout } from './keyboard'; + +export class Configuration { + + keyboardLayout : KeyboardLayout; + commandKeyMap : CommandKeyMap; + + constructor(keyboard : KeyboardLayout, keyMap : CommandKeyMap) { + this.keyboardLayout = keyboard; + this.commandKeyMap = keyMap; + } + + static fromUserFile() { + return new Configuration( + KeyboardLayout.fromUserConfiguration(), + CommandKeyMap.fromUserConfiguration() + ); + } +} \ No newline at end of file diff --git a/src/configuration/keyboard.ts b/src/configuration/keyboard.ts new file mode 100644 index 00000000000..edb8bee12b3 --- /dev/null +++ b/src/configuration/keyboard.ts @@ -0,0 +1,123 @@ +"use strict"; + +import * as vscode from "vscode"; + +export class KeyboardLayout { + private _mapper : IKeyMapper; + private _defaultKeyboardLayout = 'en-US (QWERTY)'; + + constructor(mapper? : IKeyMapper) { + this._mapper = mapper; + } + + get name() : string { + return this._mapper ? this._mapper.name : this._defaultKeyboardLayout; + } + + translate (key : string) : string { + return this._mapper ? this._mapper.get(key) : key; + } + + static fromUserConfiguration() : KeyboardLayout { + const supportedKeyMappers : IKeyMapper[] = [ + new KeyMapperEsEsQwerty(), + new KeyMapperDeDeQwertz(), + new KeyMapperDaDKQwerty(), + new KeyMapperSvSEQwerty(), + ]; + let requestedKeyboardLayout = vscode.workspace.getConfiguration('vim').get("keyboardLayout", ""); + let keyboardLayout = supportedKeyMappers.find(layout => layout.name.toLowerCase() === requestedKeyboardLayout.toLowerCase()); + + if (keyboardLayout) { + return new KeyboardLayout(keyboardLayout); + } else { + return new KeyboardLayout(); + } + } +} + +export interface IKeyMapper { + name : string; + get(key : string) : string; +} + +class KeyMapperEsEsQwerty implements IKeyMapper { + private _name = 'es-ES (QWERTY)'; + private _mappings = { + '>': ':', + '<': ';', + '`': '<', + '~': '>', + ';': 'ñ', + ':': 'Ñ', + "'": "´", + '\\': 'ç', + '}': '*' + }; + + get name() : string { + return this._name; + } + + get(key : string) : string { + return this._mappings[key] || key; + } +} + +class KeyMapperDeDeQwertz implements IKeyMapper { + private _name = 'de-DE (QWERTZ)'; + private _mappings = { + '>': ':', + '\\': '<', + '<': ';', + '^': '&' + }; + + get name() : string { + return this._name; + } + + get(key : string) : string { + return this._mappings[key] || key; + } +} + + +class KeyMapperDaDKQwerty implements IKeyMapper { + private _name = 'da-DK (QWERTY)'; + private _mappings = { + '>': ':', + '\\': '<', + '<': ';', + ':': '^', + '^': '&' + }; + + get name() : string { + return this._name; + } + + get(key : string) : string { + return this._mappings[key] || key; + } +} + +class KeyMapperSvSEQwerty implements IKeyMapper { + private _name = "sv-SE (QWERTY)"; + private _mappings = { + 'oem_102': '<', + 'shift+oem_102': '>', + '>': ':', + '<': ';', + ':': '^', + '^': '&' + }; + + get name() : string { + return this._name; + } + + get(key : string) : string { + return this._mappings[key] || key; + } +} diff --git a/src/error.ts b/src/error.ts index 1c4864311c2..381e922dc88 100644 --- a/src/error.ts +++ b/src/error.ts @@ -18,7 +18,6 @@ const errors : IVimErrors = { 488: "Trailing characters" }; - export class VimError extends Error { private _code : number; private _message : string; diff --git a/src/keyboard.ts b/src/keyboard.ts deleted file mode 100644 index 396c0fd1e81..00000000000 --- a/src/keyboard.ts +++ /dev/null @@ -1,140 +0,0 @@ -"use strict"; - -import * as vscode from "vscode"; - -export class KeyboardLayout { - private mapper : IKeyMapper; - - constructor(mapper? : IKeyMapper) { - this.mapper = mapper; - } - - get name() : string { - return this.mapper ? this.mapper.name : 'en-US (QWERTY)'; - } - - translate (key : string) : string { - return this.mapper ? this.mapper.get(key) : key; - } - - static fromUserConfiguration() : KeyboardLayout { - const layout = vscode.workspace.getConfiguration('vim').get("keyboardLayout"); - - console.log("Using Vim keyboard layout: " + layout); - - switch (layout) { - case 'es-ES (QWERTY)': - return new KeyboardLayout(new KeyMapperEsEsQwerty()); - case 'de-DE (QWERTZ)': - return new KeyboardLayout(new KeyMapperDeDeQwertz()); - case 'da-DK (QWERTY)': - return new KeyboardLayout(new KeyMapperDaDKQwerty()); - case 'sv-SE (QWERTY)': - return new KeyboardLayout(new KeyMapperSvSEQwerty()); - default: - return new KeyboardLayout(); - } - } -} - -export interface IKeyMapper { - name : string; - get(key : string) : string; -} - -class KeyMapperEsEsQwerty implements IKeyMapper { - - private mappings = {}; - - constructor() { - this.mappings = { - '>': ':', - '<': ';', - '`': '<', - '~': '>', - ';': 'ñ', - ':': 'Ñ', - "'": "´", - '\\': 'ç', - '}': '*' - }; - } - - get name() : string { - return 'es-ES (QWERTY)'; - } - - get(key : string) : string { - return this.mappings[key] || key; - } -} - -class KeyMapperDeDeQwertz implements IKeyMapper { - - private mappings = {}; - - constructor() { - this.mappings = { - '>': ':', - '\\': '<', - '<': ';', - '^': '&' - }; - } - - get name() : string { - return 'de-DE (QWERTZ)'; - } - - get(key : string) : string { - return this.mappings[key] || key; - } -} - - -class KeyMapperDaDKQwerty implements IKeyMapper { - - private mappings = {}; - - constructor() { - this.mappings = { - '>': ':', - '\\': '<', - '<': ';', - ':': '^', - '^': '&' - }; - } - - get name() : string { - return 'da-DK (QWERTY)'; - } - - get(key : string) : string { - return this.mappings[key] || key; - } -} - -class KeyMapperSvSEQwerty implements IKeyMapper { - - private mappings = {}; - - constructor() { - this.mappings = { - 'oem_102': '<', // Only works when building from source atm, should work next vscode update - 'shift+oem_102': '>', // Only works when building from source atm, should work next vscode update - '>': ':', - '<': ';', - ':': '^', - '^': '&' - }; - } - - get name() : string { - return 'sv-SE (QWERTY)'; - } - - get(key : string) : string { - return this.mappings[key] || key; - } -} diff --git a/src/mode/commands.ts b/src/mode/commands.ts deleted file mode 100644 index 335f793af21..00000000000 --- a/src/mode/commands.ts +++ /dev/null @@ -1,167 +0,0 @@ - -// An enum of all bindable actions in Vim -// TODO: Split off commands into normal, insert, and visual catagories -export enum Command { - // Enter insert mode - InsertAtCursor = 1, - InsertAtLineBegin, - InsertAfterCursor, - InsertAtLineEnd, - InsertNewLineBelow, - InsertNewLineAbove, - - // Movement - MoveUp, - MoveDown, - MoveLeft, - MoveRight, - - MoveLineBegin, - MoveLineEnd, - MoveWordBegin, - MoveWordEnd, - MoveFullWordBegin, - MoveFullWordEnd, - MoveLastWord, - MoveLastFullWord, - MoveLastWordEnd, - MoveLastFullWordEnd, - - // MoveHalfPageUp, - // MoveHalfPageDown, - MoveFullPageUp, - MoveFullPageDown, - // MoveFirstLine, - // MoveLastLine, - - MoveParagraphBegin, - MoveParagraphEnd, - - MoveNonBlank, - MoveNonBlankFirst, - MoveNonBlankLast, - MoveMatchingBracket, - - // Find - Find, - - // Folding - Fold, - Unfold, - FoldAll, - UnfoldAll, - - // Text Modification - Undo, - Redo, - Copy, - Paste, - - ChangeWord, - ChangeFullWord, - ChangeCurrentWord, - ChangeCurrentWordToNext, - ChangeToLineEnd, - - DeleteLine, - DeleteToNextWord, - DeleteToFullNextWord, - DeleteToWordEnd, - DeleteToFullWordEnd, - DeleteToWordBegin, - DeleteToFullWordBegin, - DeleteToLineEnd, - - DeleteChar, - DeleteLastChar, - - Indent, - Outdent, - - // Misc - EnterVisualMode, - EnterCommand, - ExitMessages, -} - -export function newDefaultNormalKeymap() : {[key: string]: Command} { - return { - "h": Command.MoveLeft, - "j": Command.MoveDown, - "k": Command.MoveUp, - "l": Command.MoveRight, - "0": Command.MoveLineBegin, - "$": Command.MoveLineEnd, - - "^": Command.MoveNonBlank, - "gg": Command.MoveNonBlankFirst, - "G": Command.MoveNonBlankLast, - - "w": Command.MoveWordBegin, - "W": Command.MoveFullWordBegin, - "e": Command.MoveWordEnd, - "E": Command.MoveLastFullWordEnd, - "ge": Command.MoveLastWordEnd, - "gE": Command.MoveLastFullWordEnd, - "b": Command.MoveLastWord, - "B": Command.MoveLastFullWord, - - "{": Command.MoveParagraphBegin, - "}": Command.MoveParagraphEnd, - "%": Command.MoveMatchingBracket, - - ">>": Command.Indent, - "<<": Command.Outdent, - - "u": Command.Undo, - "ctrl+r": Command.Redo, - "y": Command.Copy, - "p": Command.Paste, - - "cw": Command.ChangeWord, - "cW": Command.ChangeFullWord, - "ciw": Command.ChangeCurrentWord, - "caw": Command.ChangeCurrentWordToNext, - "C": Command.ChangeToLineEnd, - - "dd": Command.DeleteLine, - "dw": Command.DeleteToNextWord, - "dW": Command.DeleteToFullNextWord, - "db": Command.DeleteToWordBegin, - "dB": Command.DeleteToFullWordBegin, - "de": Command.DeleteToWordEnd, - "dE": Command.DeleteToFullWordEnd, - "D" : Command.DeleteToLineEnd, - - "x": Command.DeleteChar, - "X": Command.DeleteLastChar, - - "/": Command.Find, - - "zc": Command.Fold, - "zo": Command.Unfold, - "zC": Command.FoldAll, - "zO": Command.UnfoldAll, - - ":": Command.EnterCommand, - "v": Command.EnterVisualMode, - "esc": Command.ExitMessages - }; -} - -export function newDefaultInsertKeymap() : {[key: string]: Command} { - return { - "i": Command.InsertAtCursor, - "I": Command.InsertAtLineBegin, - "a": Command.InsertAfterCursor, - "A": Command.InsertAtLineEnd, - "o": Command.InsertNewLineBelow, - "O": Command.InsertNewLineAbove, - }; -} - -export function newDefaultVisualKeymap() : {[key: string]: Command} { - return { - "v": Command.EnterVisualMode - }; -} \ No newline at end of file diff --git a/src/mode/mode.ts b/src/mode/mode.ts index 87bf51f1645..f87cf3f6f78 100644 --- a/src/mode/mode.ts +++ b/src/mode/mode.ts @@ -1,6 +1,6 @@ "use strict"; -import {Command} from './commands'; +import {CommandKeyHandler} from './../configuration/commandKeyMap'; import {Motion} from './../motion/motion'; import {Position} from './../motion/position'; @@ -15,9 +15,9 @@ export abstract class Mode { private _name : ModeName; private _motion : Motion; protected _keyHistory : string[]; - protected _keymap : {[key: string]: Command}; + protected _keymap : CommandKeyHandler; - constructor(name: ModeName, motion: Motion, keymap: {[key: string]: Command}) { + constructor(name: ModeName, motion: Motion, keymap: CommandKeyHandler) { this._name = name; this._motion = motion; this._isActive = false; diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index 640c599c8f2..051752d84c2 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -3,13 +3,12 @@ import * as _ from 'lodash'; import * as vscode from 'vscode'; -import * as cmds from './commands'; import {Mode, ModeName} from './mode'; import {Motion, MotionMode} from './../motion/motion'; import {NormalMode} from './modeNormal'; import {InsertMode} from './modeInsert'; import {VisualMode} from './modeVisual'; -import {Configuration} from '../configuration'; +import {Configuration} from '../configuration/configuration'; export class ModeHandler implements vscode.Disposable { private _motion : Motion; @@ -20,33 +19,11 @@ export class ModeHandler implements vscode.Disposable { constructor() { this._configuration = Configuration.fromUserFile(); - // This probably should be somewhere else but will work for now. - let normalKeymap = cmds.newDefaultNormalKeymap(); - let insertKeymap = cmds.newDefaultInsertKeymap(); - let visualKeymap = cmds.newDefaultVisualKeymap(); - let normalKeymapConf = vscode.workspace.getConfiguration("vim") - .get("normalModeKeybindings", cmds.newDefaultNormalKeymap()); - let insertKeymapConf = vscode.workspace.getConfiguration("vim") - .get("insertModeKeybindings", cmds.newDefaultInsertKeymap()); - let visualKeymapConf = vscode.workspace.getConfiguration("vim") - .get("visualModeKeybindings", cmds.newDefaultVisualKeymap()); - - let copyFunc = function (to: {[key: string]: cmds.Command}, - source: {[key: string]: cmds.Command}) { - for (var key in source) { - if (source.hasOwnProperty(key)) { - to[key] = source[key]; - } - } - }; - copyFunc(normalKeymap, normalKeymapConf); - copyFunc(insertKeymap, insertKeymapConf); - copyFunc(visualKeymap, visualKeymapConf); this._motion = new Motion(null); this._modes = [ - new NormalMode(this._motion, this, normalKeymap), - new InsertMode(this._motion, insertKeymap), - new VisualMode(this._motion, this, visualKeymap), + new NormalMode(this._motion, this, this._configuration.commandKeyMap.normalModeKeyMap), + new InsertMode(this._motion, this._configuration.commandKeyMap.insertModeKeyMap), + new VisualMode(this._motion, this, this._configuration.commandKeyMap.visualModeKeyMap), ]; this.setCurrentModeByName(ModeName.Normal); diff --git a/src/mode/modeInsert.ts b/src/mode/modeInsert.ts index 9886fa95dfb..b9240a284a2 100644 --- a/src/mode/modeInsert.ts +++ b/src/mode/modeInsert.ts @@ -2,7 +2,7 @@ import * as vscode from 'vscode'; -import {Command} from './commands'; +import {CommandKeyHandler, Command} from './../configuration/commandKeyMap'; import {ModeName, Mode} from './mode'; import {TextEditor} from './../textEditor'; import {Motion} from './../motion/motion'; @@ -31,7 +31,7 @@ export class InsertMode extends Mode { } } - constructor(motion : Motion, keymap : {[key: string]: Command}) { + constructor(motion : Motion, keymap : CommandKeyHandler) { super(ModeName.Insert, motion, keymap); } @@ -45,18 +45,7 @@ export class InsertMode extends Mode { } async handleKeyEvent(key : string) : Promise { - await TextEditor.insert(this.resolveKeyValue(key)); + await TextEditor.insert(key); return true; } - - // Some keys have names that are different to their value. - // TODO: we probably need to put this somewhere else. - private resolveKeyValue(key : string) : string { - switch (key) { - case 'space': - return ' '; - default: - return key; - } - } } diff --git a/src/mode/modeNormal.ts b/src/mode/modeNormal.ts index 6db9b2db067..544289fe7bb 100644 --- a/src/mode/modeNormal.ts +++ b/src/mode/modeNormal.ts @@ -3,7 +3,7 @@ import * as _ from 'lodash'; import * as vscode from 'vscode'; -import {Command} from './commands'; +import {Command, CommandKeyHandler} from './../configuration/commandKeyMap'; import {ModeName, Mode} from './mode'; import {showCmdLine} from './../cmd_line/main'; import {Motion, MotionMode} from './../motion/motion'; @@ -198,13 +198,13 @@ export class NormalMode extends Mode { case Command.ExitMessages: return async () => { return vscode.commands.executeCommand("workbench.action.closeMessages"); }; default: - return async () => {return {}; }; + return async () => { return {}; }; } } private _modeHandler: ModeHandler; - constructor(motion : Motion, modeHandler: ModeHandler, keymap: {[key: string]: Command}) { + constructor(motion : Motion, modeHandler: ModeHandler, keymap: CommandKeyHandler) { super(ModeName.Normal, motion, keymap); this._modeHandler = modeHandler; diff --git a/src/mode/modeVisual.ts b/src/mode/modeVisual.ts index d9f2062e209..0ae09ef7828 100644 --- a/src/mode/modeVisual.ts +++ b/src/mode/modeVisual.ts @@ -2,7 +2,7 @@ import * as _ from 'lodash'; -import {Command} from './commands'; +import { Command, CommandKeyHandler } from './../configuration/commandKeyMap'; import { ModeName, Mode } from './mode'; import { Motion} from './../motion/motion'; import { Position } from './../motion/position'; @@ -25,13 +25,11 @@ export class VisualMode extends Mode { private _keysToOperators: { [key: string]: Operator }; - constructor(motion: Motion, modeHandler: ModeHandler, keymap: {[key: string]: Command}) { + constructor(motion: Motion, modeHandler: ModeHandler, keymap: CommandKeyHandler) { super(ModeName.Visual, motion, keymap); this._modeHandler = modeHandler; this._keysToOperators = { - // TODO: use DeleteOperator.key() - // TODO: Don't pass in mode handler to DeleteOperators, // simply allow the operators to say what mode they transition into. 'd': new DeleteOperator(modeHandler), diff --git a/src/operator/change.ts b/src/operator/change.ts index 9be2c47ab77..455dc0a8d01 100644 --- a/src/operator/change.ts +++ b/src/operator/change.ts @@ -12,7 +12,7 @@ export class ChangeOperator extends Operator { super(modeHandler); } - public key(): string { return "d"; } + // public key(): string { return "d"; } /** * Run this operator on a range. diff --git a/src/operator/delete.ts b/src/operator/delete.ts index 80243a5a24e..0c6d7d99dc3 100644 --- a/src/operator/delete.ts +++ b/src/operator/delete.ts @@ -13,7 +13,7 @@ export class DeleteOperator extends Operator { super(modeHandler); } - public key(): string { return "d"; } + // public key(): string { return "d"; } /** * Run this operator on a range. diff --git a/src/operator/operator.ts b/src/operator/operator.ts index d52058cc14c..f200de44f38 100644 --- a/src/operator/operator.ts +++ b/src/operator/operator.ts @@ -17,7 +17,7 @@ export abstract class Operator { /** * What key triggers this operator? */ - abstract key(): string; + // abstract key(): string; /** * Run this operator on a range. diff --git a/src/operator/put.ts b/src/operator/put.ts index 7775a3bd5ca..0e3c9b379f5 100644 --- a/src/operator/put.ts +++ b/src/operator/put.ts @@ -12,7 +12,7 @@ export class PutOperator extends Operator { super(modeHandler); } - public key(): string { return "p"; } + // public key(): string { return "p"; } /** * Run this operator on a range. diff --git a/src/util.ts b/src/util.ts index 1a216f46991..9264074c493 100644 --- a/src/util.ts +++ b/src/util.ts @@ -8,4 +8,4 @@ export async function showInfo(message : string): Promise<{}> { export async function showError(message : string): Promise<{}> { return vscode.window.showErrorMessage("Vim: " + message); -} +} \ No newline at end of file diff --git a/test/keyboard.test.ts b/test/keyboard.test.ts index 6473970ae95..69348e9c85f 100644 --- a/test/keyboard.test.ts +++ b/test/keyboard.test.ts @@ -2,7 +2,7 @@ // The module 'assert' provides assertion methods from node import * as assert from 'assert'; -import {KeyboardLayout, IKeyMapper} from '../src/keyboard'; +import {KeyboardLayout, IKeyMapper} from '../src/configuration/keyboard'; suite("KeyboardLayout", () => { diff --git a/test/mode/modeInsert.test.ts b/test/mode/modeInsert.test.ts index 47a62d04caf..44b41730f83 100644 --- a/test/mode/modeInsert.test.ts +++ b/test/mode/modeInsert.test.ts @@ -1,7 +1,7 @@ "use strict"; import * as assert from 'assert'; -import {newDefaultInsertKeymap} from '../../src/mode/commands'; +import {CommandKeyMap} from '../../src/configuration/commandKeyMap'; import {setupWorkspace, cleanUpWorkspace, assertEqualLines} from './../testUtils'; import {InsertMode} from '../../src/mode/modeInsert'; import {ModeName} from '../../src/mode/mode'; @@ -17,7 +17,7 @@ suite("Mode Insert", () => { await setupWorkspace(); motion = new Motion(MotionMode.Cursor); - modeInsert = new InsertMode(motion, newDefaultInsertKeymap()); + modeInsert = new InsertMode(motion, CommandKeyMap.DefaultInsertKeyMap()); }); teardown(cleanUpWorkspace); diff --git a/test/mode/modeNormal.test.ts b/test/mode/modeNormal.test.ts index 7411dc297cf..272ef624460 100644 --- a/test/mode/modeNormal.test.ts +++ b/test/mode/modeNormal.test.ts @@ -1,7 +1,7 @@ "use strict"; import * as assert from 'assert'; -import {newDefaultNormalKeymap} from '../../src/mode/commands'; +import {CommandKeyMap} from '../../src/configuration/commandKeyMap'; import {setupWorkspace, cleanUpWorkspace, assertEqualLines} from './../testUtils'; import {NormalMode} from '../../src/mode/modeNormal'; import {ModeName} from '../../src/mode/mode'; @@ -20,7 +20,7 @@ suite("Mode Normal", () => { modeHandler = new ModeHandler(); motion = new Motion(MotionMode.Cursor); - modeNormal = new NormalMode(motion, modeHandler, newDefaultNormalKeymap()); + modeNormal = new NormalMode(motion, modeHandler, CommandKeyMap.DefaultNormalKeyMap()); }); teardown(cleanUpWorkspace); diff --git a/test/mode/modeVisual.test.ts b/test/mode/modeVisual.test.ts index 753a8870d79..83f9dee9c9f 100644 --- a/test/mode/modeVisual.test.ts +++ b/test/mode/modeVisual.test.ts @@ -1,7 +1,7 @@ "use strict"; import * as assert from 'assert'; -import {newDefaultVisualKeymap} from '../../src/mode/commands'; +import {CommandKeyMap} from '../../src/configuration/commandKeyMap'; import {ModeHandler} from '../../src/mode/modeHandler'; import {setupWorkspace, cleanUpWorkspace, assertEqualLines} from './../testUtils'; import {VisualMode} from '../../src/mode/modeVisual'; @@ -19,7 +19,7 @@ suite("Mode Visual", () => { modeHandler = new ModeHandler(); motion = new Motion(MotionMode.Cursor); - visualMode = new VisualMode(motion, modeHandler, newDefaultVisualKeymap()); + visualMode = new VisualMode(motion, modeHandler, CommandKeyMap.DefaultVisualKeyMap()); }); teardown(cleanUpWorkspace);