diff --git a/README.md b/README.md index 67d7a37d1b1d..74ef2e7d30c9 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ On OS X, open Terminal and run the following command: defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false ``` -#### How can I bind `jj` to ``? +#### How can I bind `jj` to ``? 1. Add the following to `settings.json` (open the Command Pallete and search for "User Settings"): @@ -50,18 +50,18 @@ defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false "vim.insertModeKeyBindings": [ { "before": ["j", "j"], - "after": [""] + "after": [""] } ] ``` -2. If you want to press `jj` in modes which are not Insert Mode and still have it trigger ``, do the following as well: +2. If you want to press `jj` in modes which are not Insert Mode and still have it trigger ``, do the following as well: ``` "vim.otherModesKeyBindings": [ { "before": ["j", "j"], - "after": [""] + "after": [""] } ] ``` @@ -83,7 +83,7 @@ Notice the problem is that if you did this normally, the `j` in `gj` would be ex Don't forget to restart! -#### How can I enable `ctrl-c` or `ctrl-[` as an alternative to ``? +#### How can I enable `ctrl-c` or `ctrl-[` as an alternative to ``? Put the following in your `settings.json`: diff --git a/extension.ts b/extension.ts index 7c9a193aeb63..d5ab92455bec 100644 --- a/extension.ts +++ b/extension.ts @@ -191,16 +191,22 @@ export async function activate(context: vscode.ExtensionContext) { }); for (let { key } of packagejson.contributes.keybindings) { - if (key.startsWith("ctrl+")) { - registerCommand(context, `extension.vim_${ key }`, () => handleKeyEvent(key)); - } else { - let bracketedKey = `<${ key.toLowerCase() }>`; - - registerCommand(context, `extension.vim_${ key.toLowerCase() }`, () => handleKeyEvent(`${ bracketedKey }`)); + key = key.toLowerCase(); + + const keyNotationTranslations = { + 'ctrl+' : 'C-', + 'escape': 'Esc', + 'backspace': 'BS', + 'delete': 'Del', + }; + + let bracketedKey = `<${ key }>`; + for (let searchKey in keyNotationTranslations) { + bracketedKey = bracketedKey.replace(searchKey, keyNotationTranslations[searchKey]); } - } - registerCommand(context, `extension.vim_esc`, () => handleKeyEvent(``)); + registerCommand(context, `extension.vim_${ key }`, () => handleKeyEvent(`${ bracketedKey }`)); + } // Initialize mode handler for current active Text Editor at startup. if (vscode.window.activeTextEditor) { diff --git a/src/actions/actions.ts b/src/actions/actions.ts index fde977d68542..c18d865953a3 100644 --- a/src/actions/actions.ts +++ b/src/actions/actions.ts @@ -238,7 +238,7 @@ export abstract class BaseMovement extends BaseAction { } /** - * A command is something like , :, v, i, etc. + * A command is something like , :, v, i, etc. */ export abstract class BaseCommand extends BaseAction { /** @@ -413,7 +413,7 @@ class CommandEsc extends BaseCommand { ModeName.SearchInProgressMode, ModeName.Replace ]; - keys = [""]; + keys = [""]; public async exec(position: Position, vimState: VimState): Promise { if (vimState.currentMode !== ModeName.Visual && @@ -435,13 +435,13 @@ class CommandEsc extends BaseCommand { @RegisterAction class CommandCtrlOpenBracket extends CommandEsc { - keys = ["ctrl+["]; + keys = [""]; } @RegisterAction class CommandCtrlW extends BaseCommand { modes = [ModeName.Insert]; - keys = ["ctrl+w"]; + keys = [""]; public async exec(position: Position, vimState: VimState): Promise { const wordBegin = position.getWordLeft(); @@ -456,7 +456,7 @@ class CommandCtrlW extends BaseCommand { @RegisterAction class CommandCtrlE extends BaseCommand { modes = [ModeName.Normal]; - keys = ["ctrl+e"]; + keys = [""]; public async exec(position: Position, vimState: VimState): Promise { await vscode.commands.executeCommand("scrollLineDown"); @@ -468,7 +468,7 @@ class CommandCtrlE extends BaseCommand { @RegisterAction class CommandCtrlY extends BaseCommand { modes = [ModeName.Normal]; - keys = ["ctrl+y"]; + keys = [""]; public async exec(position: Position, vimState: VimState): Promise { await vscode.commands.executeCommand("scrollLineUp"); @@ -479,7 +479,7 @@ class CommandCtrlY extends BaseCommand { @RegisterAction class CommandCtrlC extends CommandEsc { - keys = ["ctrl+c"]; + keys = [""]; } @RegisterAction @@ -520,7 +520,7 @@ class CommandReplaceInReplaceMode extends BaseCommand { const replaceState = vimState.replaceState!; - if (char === "") { + if (char === "") { if (position.isBeforeOrEqual(replaceState.replaceCursorStartPosition)) { vimState.cursorPosition = position.getLeft(); vimState.cursorStartPosition = position.getLeft(); @@ -608,7 +608,7 @@ class CommandInsertInSearchMode extends BaseCommand { const searchState = vimState.searchState!; // handle special keys first - if (key === "") { + if (key === "") { searchState.searchString = searchState.searchString.slice(0, -1); } else if (key === "\n") { vimState.currentMode = ModeName.Normal; @@ -625,12 +625,12 @@ class CommandInsertInSearchMode extends BaseCommand { vimState.searchStatePrevious = searchState; return vimState; - } else if (key === "") { + } else if (key === "") { vimState.currentMode = ModeName.Normal; vimState.searchState = undefined; return vimState; - } else if (key === "ctrl+v") { + } else if (key === "") { const text = await new Promise((resolve, reject) => clipboard.paste((err, text) => err ? reject(err) : resolve(text)) ); @@ -754,7 +754,7 @@ class CommandInsertInInsertMode extends BaseCommand { public async exec(position: Position, vimState: VimState): Promise { const char = this.keysPressed[this.keysPressed.length - 1]; - if (char === "") { + if (char === "") { const newPosition = await TextEditor.backspace(position); vimState.cursorPosition = newPosition; @@ -1511,7 +1511,7 @@ class CommandUndo extends BaseCommand { @RegisterAction class CommandRedo extends BaseCommand { modes = [ModeName.Normal]; - keys = ["ctrl+r"]; + keys = [""]; public async exec(position: Position, vimState: VimState): Promise { const newPosition = await vimState.historyTracker.goForwardHistoryStep(); @@ -1527,7 +1527,7 @@ class CommandRedo extends BaseCommand { @RegisterAction class CommandMoveFullPageDown extends BaseCommand { modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine, ModeName.VisualBlock]; - keys = ["ctrl+f"]; + keys = [""]; public async exec(position: Position, vimState: VimState): Promise { await vscode.commands.executeCommand("cursorPageDown"); @@ -1538,7 +1538,7 @@ class CommandMoveFullPageDown extends BaseCommand { @RegisterAction class CommandMoveFullPageUp extends BaseCommand { modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine, ModeName.VisualBlock]; - keys = ["ctrl+b"]; + keys = [""]; public async exec(position: Position, vimState: VimState): Promise { await vscode.commands.executeCommand("cursorPageUp"); @@ -1548,7 +1548,7 @@ class CommandMoveFullPageUp extends BaseCommand { @RegisterAction class CommandMoveHalfPageDown extends BaseMovement { - keys = ["ctrl+d"]; + keys = [""]; public async execAction(position: Position, vimState: VimState): Promise { return new Position( @@ -1560,7 +1560,7 @@ class CommandMoveHalfPageDown extends BaseMovement { @RegisterAction class CommandMoveHalfPageUp extends BaseMovement { - keys = ["ctrl+u"]; + keys = [""]; public async execAction(position: Position, vimState: VimState): Promise { return new Position(Math.max(0, position.line - Configuration.getInstance().scroll), position.character); @@ -1641,7 +1641,7 @@ class CommandVisualMode extends BaseCommand { @RegisterAction class CommandVisualBlockMode extends BaseCommand { modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualBlock]; - keys = ["ctrl+v"]; + keys = [""]; public async exec(position: Position, vimState: VimState): Promise { @@ -1820,7 +1820,7 @@ class MoveLeftArrow extends MoveLeft { @RegisterAction class BackSpaceInNormalMode extends BaseMovement { modes = [ModeName.Normal]; - keys = [""]; + keys = [""]; public async execAction(position: Position, vimState: VimState): Promise { return position.getLeftThroughLineBreaks(); @@ -1896,7 +1896,7 @@ class MoveRightWithSpace extends BaseMovement { @RegisterAction class MoveToRightPane extends BaseCommand { modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine]; - keys = ["ctrl+w", "l"]; + keys = ["", "l"]; public async exec(position: Position, vimState: VimState): Promise { vimState.focusChanged = true; @@ -1908,7 +1908,7 @@ class MoveToRightPane extends BaseCommand { @RegisterAction class MoveToLeftPane extends BaseCommand { modes = [ModeName.Normal, ModeName.Visual, ModeName.VisualLine]; - keys = ["ctrl+w", "h"]; + keys = ["", "h"]; public async exec(position: Position, vimState: VimState): Promise { vimState.focusChanged = true; @@ -2505,7 +2505,7 @@ class ActionDeleteChar extends BaseCommand { @RegisterAction class ActionDeleteCharWithDeleteKey extends BaseCommand { modes = [ModeName.Normal]; - keys = [""]; + keys = [""]; canBePrefixedWithCount = true; canBeRepeatedWithDot = true; @@ -2788,14 +2788,14 @@ class InsertInInsertVisualBlockMode extends BaseCommand { return vimState; } - if (char === '' && vimState.topLeft.character === 0) { + if (char === '' && vimState.topLeft.character === 0) { return vimState; } for (const { start, end } of Position.IterateLine(vimState)) { const insertPos = insertAtStart ? start : end; - if (char === '') { + if (char === '') { await TextEditor.backspace(insertPos.getLeft()); posChange = -1; @@ -3626,13 +3626,13 @@ abstract class IncrementDecrementNumberAction extends BaseCommand { @RegisterAction class IncrementNumberAction extends IncrementDecrementNumberAction { - keys = ["ctrl+a"]; + keys = [""]; offset = +1; } @RegisterAction class DecrementNumberAction extends IncrementDecrementNumberAction { - keys = ["ctrl+x"]; + keys = [""]; offset = -1; } diff --git a/src/history/historyTracker.ts b/src/history/historyTracker.ts index df56dc8ca324..2265856a64a9 100644 --- a/src/history/historyTracker.ts +++ b/src/history/historyTracker.ts @@ -139,7 +139,7 @@ class HistoryStep { // collapse add+del into add. this might make current.text.length === 0, see beginning of loop current.text = current.text.slice(0, -next.text.length); } else { - // del+add must be two separate DocumentChanges. e.g. start with "a|b", do `ix` you end up with "|xb" + // del+add must be two separate DocumentChanges. e.g. start with "a|b", do `ix` you end up with "|xb" // also handles multiple changes in distant locations in the document merged.push(current); current = next; diff --git a/src/mode/modeHandler.ts b/src/mode/modeHandler.ts index 838cc01a120e..9b8df188ab4c 100644 --- a/src/mode/modeHandler.ts +++ b/src/mode/modeHandler.ts @@ -375,7 +375,7 @@ export class RecordedState { public get command(): BaseCommand { const list = _.filter(this.actionsRun, a => a instanceof BaseCommand); - // TODO - disregard , then assert this is of length 1. + // TODO - disregard , then assert this is of length 1. return list[0] as any; } @@ -625,16 +625,6 @@ export class ModeHandler implements vscode.Disposable { } async handleKeyEvent(key: string): Promise { - if (key === "") { key = "ctrl+r"; } // TODO - temporary hack for tests only! - if (key === "") { key = "ctrl+a"; } // TODO - temporary hack for tests only! - if (key === "") { key = "ctrl+x"; } // TODO - temporary hack for tests only! - - if (key === "") { key = ""; } - - // 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 - this._vimState.cursorPositionJustBeforeAnythingHappened = this._vimState.cursorPosition; try { diff --git a/test/cmd_line/substitute.test.ts b/test/cmd_line/substitute.test.ts index b44aaa95bdd7..3c1c6b63aaae 100644 --- a/test/cmd_line/substitute.test.ts +++ b/test/cmd_line/substitute.test.ts @@ -15,7 +15,7 @@ suite("Basic substitute", () => { teardown(cleanUpWorkspace); test("Replace single word once", async () => { - await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '']); + await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '']); await runCmdLine("%s/a/d", modeHandler); assertEqualLines([ @@ -24,7 +24,7 @@ suite("Basic substitute", () => { }); test("Replace with `g` flag", async () => { - await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '']); + await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '']); await runCmdLine("%s/a/d/g", modeHandler); assertEqualLines([ @@ -33,7 +33,7 @@ suite("Basic substitute", () => { }); test("Replace multiple lines", async () => { - await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '', 'o', 'a', 'b']); + await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '', 'o', 'a', 'b']); await runCmdLine("%s/a/d/g", modeHandler); assertEqualLines([ @@ -43,7 +43,7 @@ suite("Basic substitute", () => { }); test("Replace across specific lines", async () => { - await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '', 'o', 'a', 'b']); + await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '', 'o', 'a', 'b']); await runCmdLine("1,1s/a/d/g", modeHandler); assertEqualLines([ @@ -53,7 +53,7 @@ suite("Basic substitute", () => { }); test("Replace current line with no active selection", async () => { - await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '', 'o', 'a', 'b', '']); + await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '', 'o', 'a', 'b', '']); await runCmdLine("s/a/d/g", modeHandler); assertEqualLines([ @@ -63,7 +63,7 @@ suite("Basic substitute", () => { }); test("Replace text in selection", async () => { - await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '', 'o', 'a', 'b', '', '$', 'v', 'k', '0']); + await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '', 'o', 'a', 'b', '', '$', 'v', 'k', '0']); await runCmdLine("'<,'>s/a/d/g", modeHandler); assertEqualLines([ diff --git a/test/cmd_line/writequit.test.ts b/test/cmd_line/writequit.test.ts index 5440d46c5a7c..9dff0f1bf84e 100644 --- a/test/cmd_line/writequit.test.ts +++ b/test/cmd_line/writequit.test.ts @@ -51,7 +51,7 @@ suite("Basic write-quit", () => { teardown(cleanUpWorkspace); test("Run write and quit", async () => { - await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '']); + await modeHandler.handleMultipleKeyEvents(['i', 'a', 'b', 'a', '']); await runCmdLine("wq", modeHandler); await WaitForVsCodeClose(); diff --git a/test/mode/modeInsert.test.ts b/test/mode/modeInsert.test.ts index fc9273aaf4e8..665125bbffba 100644 --- a/test/mode/modeInsert.test.ts +++ b/test/mode/modeInsert.test.ts @@ -23,7 +23,7 @@ suite("Mode Insert", () => { await modeHandler.handleKeyEvent(key); assertEqual(modeHandler.currentMode.name, ModeName.Insert); - await modeHandler.handleKeyEvent(''); + await modeHandler.handleKeyEvent(''); } }); @@ -33,21 +33,21 @@ suite("Mode Insert", () => { return assertEqualLines(["!"]); }); - test(" should change cursor position", async () => { + test(" should change cursor position", async () => { await modeHandler.handleMultipleKeyEvents([ 'i', 'h', 'e', 'l', 'l', 'o', - '' + '' ]); - assertEqual(TextEditor.getSelection().start.character, 4, " moved cursor position."); + assertEqual(TextEditor.getSelection().start.character, 4, " moved cursor position."); }); - test("Can handle 'o'", async () => { + test("", async () => { await modeHandler.handleMultipleKeyEvents([ 'i', 't', 'e', 'x', 't', - '', + '', 'o' ]); @@ -58,7 +58,7 @@ suite("Mode Insert", () => { await modeHandler.handleMultipleKeyEvents([ 'i', 't', 'e', 'x', 't', - '', + '', 'O' ]); @@ -69,7 +69,7 @@ suite("Mode Insert", () => { await modeHandler.handleMultipleKeyEvents([ 'i', 't', 'e', 'x', 't', 't', 'e', 'x', 't', // insert 'texttext' - '', + '', '^', 'l', 'l', 'l', 'l', // move to the 4th character 'i', '!' // insert a ! @@ -82,7 +82,7 @@ suite("Mode Insert", () => { await modeHandler.handleMultipleKeyEvents([ 'i', 't', 'e', 'x', 't', - '', + '', '^', 'l', 'l', 'l', 'I', '!', @@ -95,7 +95,7 @@ suite("Mode Insert", () => { await modeHandler.handleMultipleKeyEvents([ 'i', 't', 'e', 'x', 't', 't', 'e', 'x', 't', // insert 'texttext' - '', + '', '^', 'l', 'l', 'l', 'l', // move to the 4th character 'a', '!' // append a ! @@ -108,7 +108,7 @@ suite("Mode Insert", () => { await modeHandler.handleMultipleKeyEvents([ 'i', 't', 'e', 'x', 't', - '', + '', '^', 'A', '!', @@ -117,11 +117,11 @@ suite("Mode Insert", () => { assertEqualLines(["text!"]); }); - test("Can handle 'ctrl+w'", async () => { + test("Can handle ''", async () => { await modeHandler.handleMultipleKeyEvents([ 'i', 't', 'e', 'x', 't', ' ', 't', 'e', 'x', 't', - 'ctrl+w', + '', ]); assertEqualLines(["text "]); @@ -132,11 +132,11 @@ suite("Mode Insert", () => { 'i', 'o', 'n', 'e', '\n', 't', 'w', 'o', '', '', '', - '' + '' ]); assertEqualLines(["onetwo"]); - assertEqual(TextEditor.getSelection().start.character, 3, " moved cursor to correct position"); + assertEqual(TextEditor.getSelection().start.character, 3, " moved cursor to correct position"); }); }); diff --git a/test/mode/modeNormal.test.ts b/test/mode/modeNormal.test.ts index c0cc26c582ca..2f4d01a9c5a5 100644 --- a/test/mode/modeNormal.test.ts +++ b/test/mode/modeNormal.test.ts @@ -21,7 +21,7 @@ suite("Mode Normal", () => { teardown(cleanUpWorkspace); test("can be activated", async () => { - let activationKeys = ['', 'ctrl+[']; + let activationKeys = ['', '']; for (let key of activationKeys) { await modeHandler.handleKeyEvent('i'); @@ -766,21 +766,21 @@ suite("Mode Normal", () => { newTest({ title: "Can handle backspace", start: ['text |text'], - keysPressed: '', + keysPressed: '', end: ['tex|t text'] }); newTest({ title: "Can handle backspace across lines", start: ['one', '|two'], - keysPressed: '', + keysPressed: '', end: ['o|ne', 'two'] }); newTest({ title: "Can handle A and backspace", start: ['|text text'], - keysPressed: 'A', + keysPressed: 'A', end: ['text te|x'] }); @@ -935,14 +935,14 @@ suite("Mode Normal", () => { newTest({ title: "I works correctly", start: ['| one'], - keysPressed: 'Itest ', + keysPressed: 'Itest ', end: [' test| one'] }); newTest({ title: "gI works correctly", start: ['| one'], - keysPressed: 'gItest', + keysPressed: 'gItest', end: ['tes|t one'] }); @@ -963,63 +963,63 @@ suite("Mode Normal", () => { newTest({ title: "Undo 1", start: ['|'], - keysPressed: 'iabcadefuu', + keysPressed: 'iabcadefuu', end: ['|'] }); newTest({ title: "Undo 2", start: ['|'], - keysPressed: 'iabcadefu', + keysPressed: 'iabcadefu', end: ['ab|c'] }); newTest({ title: "Undo cursor", start: ['|'], - keysPressed: 'IabcIdefIghiuuu', + keysPressed: 'IabcIdefIghiuuu', end: ['|'] }); newTest({ title: "Undo cursor 2", start: ['|'], - keysPressed: 'IabcIdefIghiuu', + keysPressed: 'IabcIdefIghiuu', end: ['|abc'] }); newTest({ title: "Undo cursor 3", start: ['|'], - keysPressed: 'IabcIdefIghiu', + keysPressed: 'IabcIdefIghiu', end: ['|defabc'] }); newTest({ title: "Undo with movement first", start: ['|'], - keysPressed: 'iabcadefhlhlu', + keysPressed: 'iabcadefhlhlu', end: ['ab|c'] }); newTest({ title: "Redo", start: ['|'], - keysPressed: 'iabcadefuu', + keysPressed: 'iabcadefuu', end: ['|abc'] }); newTest({ title: "Redo", start: ['|'], - keysPressed: 'iabcadefuu', + keysPressed: 'iabcadefuu', end: ['abc|def'] }); newTest({ title: "Redo", start: ['|'], - keysPressed: 'iabcadefuuhlhl', + keysPressed: 'iabcadefuuhlhl', end: ['abc|def'] }); @@ -1054,7 +1054,7 @@ suite("Mode Normal", () => { newTest({ title: "can handle s in visual mode", start: ["|abc def ghi"], - keysPressed: "vwshi ", + keysPressed: "vwshi ", end: ["hi| ef ghi"] }); @@ -1082,7 +1082,7 @@ suite("Mode Normal", () => { newTest({ title: "can repeat backspace twice", start: ["|11223344"], - keysPressed: "A0.", + keysPressed: "A0.", end: ["112|2"] }); @@ -1117,56 +1117,56 @@ suite("Mode Normal", () => { newTest({ title: "can ctrl-a correctly behind a word", start: ["|one 9"], - keysPressed: "", + keysPressed: "", end: ["one 1|0"] }); newTest({ title: "can ctrl-a on word", start: ["one -|11"], - keysPressed: "", + keysPressed: "", end: ["one -1|0"] }); newTest({ title: "can ctrl-a on a hex number", start: ["|0xf"], - keysPressed: "", + keysPressed: "", end: ["0x1|0"] }); newTest({ title: "can ctrl-a on decimal", start: ["1|1.123"], - keysPressed: "", + keysPressed: "", end: ["1|2.123"] }); newTest({ title: "can ctrl-a with numeric prefix", start: ["|-10"], - keysPressed: "15", + keysPressed: "15", end: ["|5"] }); newTest({ title: "can ctrl-a on a decimal", start: ["-10.|1"], - keysPressed: "10", + keysPressed: "10", end: ["-10.1|1"] }); newTest({ title: "can ctrl-a on an octal ", start: ["07|"], - keysPressed: "", + keysPressed: "", end: ["01|0"] }); newTest({ title: "can ctrl-x correctly behind a word", start: ["|one 10"], - keysPressed: "", + keysPressed: "", end: ["one |9"] }); diff --git a/test/mode/modeReplace.test.ts b/test/mode/modeReplace.test.ts index 8d2b9f8697c8..af670f5d7ddd 100644 --- a/test/mode/modeReplace.test.ts +++ b/test/mode/modeReplace.test.ts @@ -43,42 +43,42 @@ suite("Mode Replace", () => { newTest({ title: "Can handle backspace", start: ['123|456'], - keysPressed: 'Rabc', + keysPressed: 'Rabc', end: ["123|456"] }); newTest({ title: "Can handle backspace", start: ['123|456'], - keysPressed: 'Rabcd', + keysPressed: 'Rabcd', end: ["12|3456"] }); newTest({ title: "Can handle backspace across lines", start: ['123|456'], - keysPressed: 'Rabcd\nef', + keysPressed: 'Rabcd\nef', end: ["123ab|6"] }); newTest({ title: "Can handle arrows", start: ['123|456'], - keysPressed: 'Rabc', + keysPressed: 'Rabc', end: ["123|abc"] }); newTest({ title: "Can handle .", start: ['123|456', '123456'], - keysPressed: 'Rabcj0.', + keysPressed: 'Rabcj0.', end: ["123abc", "ab|c456"] }); newTest({ title: "Can handle . across lines", start: ['123|456', '123456'], - keysPressed: 'Rabc\ndefj0.', + keysPressed: 'Rabc\ndefj0.', end: ["123abc", "def", "abc", "de|f"] }); }); \ No newline at end of file diff --git a/test/mode/modeVisual.test.ts b/test/mode/modeVisual.test.ts index 27d6d14d96f3..0a907d55ab55 100644 --- a/test/mode/modeVisual.test.ts +++ b/test/mode/modeVisual.test.ts @@ -32,7 +32,7 @@ suite("Mode Visual", () => { test("Can handle w", async () => { await modeHandler.handleMultipleKeyEvents("itest test test\ntest\n".split("")); await modeHandler.handleMultipleKeyEvents([ - '', 'g', 'g', + '', 'g', 'g', 'v', 'w' ]); @@ -50,7 +50,7 @@ suite("Mode Visual", () => { test("Can handle wd", async () => { await modeHandler.handleMultipleKeyEvents("ione two three".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'v', 'w', 'd' ]); @@ -60,7 +60,7 @@ suite("Mode Visual", () => { test("Can handle x", async () => { await modeHandler.handleMultipleKeyEvents("ione two three".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'v', 'x' ]); @@ -72,7 +72,7 @@ suite("Mode Visual", () => { test("Can handle x across a selection", async () => { await modeHandler.handleMultipleKeyEvents("ione two three".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'v', 'w', 'x' ]); @@ -84,7 +84,7 @@ suite("Mode Visual", () => { test("Can do vwd in middle of sentence", async () => { await modeHandler.handleMultipleKeyEvents("ione two three foar".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'l', 'l', 'l', 'l', 'v', 'w', 'd' ]); @@ -95,7 +95,7 @@ suite("Mode Visual", () => { test("Can do vwd in middle of sentence", async () => { await modeHandler.handleMultipleKeyEvents("ione two three".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'l', 'l', 'l', 'l', 'v', 'w', 'd' ]); @@ -106,7 +106,7 @@ suite("Mode Visual", () => { test("Can do vwd multiple times", async () => { await modeHandler.handleMultipleKeyEvents("ione two three four".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'v', 'w', 'd', 'v', 'w', 'd', 'v', 'w', 'd' @@ -118,7 +118,7 @@ suite("Mode Visual", () => { test("handles case where we go from selecting on right side to selecting on left side", async () => { await modeHandler.handleMultipleKeyEvents("ione two three".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'l', 'l', 'l', 'l', 'v', 'w', 'b', 'b', 'd' ]); @@ -129,7 +129,7 @@ suite("Mode Visual", () => { test("handles case where we delete over a newline", async () => { await modeHandler.handleMultipleKeyEvents("ione two\n\nthree four".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '0', 'k', 'k', + '', '0', 'k', 'k', 'v', '}', 'd' ]); @@ -139,7 +139,7 @@ suite("Mode Visual", () => { test("handles change operator", async () => { await modeHandler.handleMultipleKeyEvents("ione two three".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'v', 'w', 'c' ]); @@ -155,7 +155,7 @@ suite("Mode Visual", () => { ); await modeHandler.handleMultipleKeyEvents([ - '', + '', '^', 'g', 'g', 'v', 'l', 'l', 'l', 'd' @@ -170,7 +170,7 @@ suite("Mode Visual", () => { ); await modeHandler.handleMultipleKeyEvents([ - '', + '', 'g', 'g', 'l', 'v', 'l', 'l', 'd' @@ -185,7 +185,7 @@ suite("Mode Visual", () => { ); await modeHandler.handleMultipleKeyEvents([ - '', + '', 'g', 'g', 'd', '$' ]); @@ -199,7 +199,7 @@ suite("Mode Visual", () => { ); await modeHandler.handleMultipleKeyEvents([ - '', + '', 'g', 'g', 'v', '$', 'd' ]); diff --git a/test/mode/modeVisualLine.test.ts b/test/mode/modeVisualLine.test.ts index d28f500a59c5..3e60798b0fff 100644 --- a/test/mode/modeVisualLine.test.ts +++ b/test/mode/modeVisualLine.test.ts @@ -27,7 +27,7 @@ suite("Mode Visual", () => { test("Can handle w", async () => { await modeHandler.handleMultipleKeyEvents("itest test test\ntest\n".split("")); await modeHandler.handleMultipleKeyEvents([ - '', 'g', 'g', + '', 'g', 'g', 'v', 'w' ]); @@ -45,7 +45,7 @@ suite("Mode Visual", () => { test("Can handle wd", async () => { await modeHandler.handleMultipleKeyEvents("ione two three".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'v', 'w', 'd' ]); @@ -55,7 +55,7 @@ suite("Mode Visual", () => { test("Can handle x", async () => { await modeHandler.handleMultipleKeyEvents("ione two three".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'v', 'x' ]); @@ -67,7 +67,7 @@ suite("Mode Visual", () => { test("Can handle U", async () => { await modeHandler.handleMultipleKeyEvents("ione two three".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'v', 'U' ]); @@ -79,7 +79,7 @@ suite("Mode Visual", () => { test("Can handle x across a selection", async () => { await modeHandler.handleMultipleKeyEvents("ione two three".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'v', 'w', 'x' ]); @@ -91,7 +91,7 @@ suite("Mode Visual", () => { test("Can do vwd in middle of sentence", async () => { await modeHandler.handleMultipleKeyEvents("ione two three foar".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'l', 'l', 'l', 'l', 'v', 'w', 'd' ]); @@ -102,7 +102,7 @@ suite("Mode Visual", () => { test("Can do vwd in middle of sentence", async () => { await modeHandler.handleMultipleKeyEvents("ione two three".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'l', 'l', 'l', 'l', 'v', 'w', 'd' ]); @@ -113,7 +113,7 @@ suite("Mode Visual", () => { test("Can do vwd multiple times", async () => { await modeHandler.handleMultipleKeyEvents("ione two three four".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'v', 'w', 'd', 'v', 'w', 'd', 'v', 'w', 'd' @@ -125,7 +125,7 @@ suite("Mode Visual", () => { test("Can handle U across a selection", async () => { await modeHandler.handleMultipleKeyEvents("ione two three".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'v', 'l', 'l', 'l', 'l', 'U' ]); @@ -137,7 +137,7 @@ suite("Mode Visual", () => { test("Can handle U across a selection in reverse order", async () => { await modeHandler.handleMultipleKeyEvents("ione two three".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'w', 'v', 'h', 'h', 'U' ]); @@ -149,7 +149,7 @@ suite("Mode Visual", () => { test("handles case where we go from selecting on right side to selecting on left side", async () => { await modeHandler.handleMultipleKeyEvents("ione two three".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'l', 'l', 'l', 'l', 'v', 'w', 'b', 'b', 'd' ]); @@ -160,7 +160,7 @@ suite("Mode Visual", () => { test("handles case where we delete over a newline", async () => { await modeHandler.handleMultipleKeyEvents("ione two\n\nthree four".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '0', 'k', 'k', + '', '0', 'k', 'k', 'v', '}', 'd' ]); @@ -170,7 +170,7 @@ suite("Mode Visual", () => { test("handles change operator", async () => { await modeHandler.handleMultipleKeyEvents("ione two three".split("")); await modeHandler.handleMultipleKeyEvents([ - '', '^', + '', '^', 'v', 'w', 'c' ]); @@ -186,7 +186,7 @@ suite("Mode Visual", () => { ); await modeHandler.handleMultipleKeyEvents([ - '', + '', '^', 'g', 'g', 'v', 'l', 'l', 'l', 'd' @@ -201,7 +201,7 @@ suite("Mode Visual", () => { ); await modeHandler.handleMultipleKeyEvents([ - '', + '', 'g', 'g', 'l', 'v', 'l', 'l', 'd' @@ -216,7 +216,7 @@ suite("Mode Visual", () => { ); await modeHandler.handleMultipleKeyEvents([ - '', + '', 'g', 'g', 'd', '$' ]); @@ -230,7 +230,7 @@ suite("Mode Visual", () => { ); await modeHandler.handleMultipleKeyEvents([ - '', + '', 'g', 'g', 'v', '$', 'd' ]); diff --git a/test/mode/normalModeTests/commands.test.ts b/test/mode/normalModeTests/commands.test.ts index c1cb916ee82a..944ae002f6ef 100644 --- a/test/mode/normalModeTests/commands.test.ts +++ b/test/mode/normalModeTests/commands.test.ts @@ -40,44 +40,44 @@ suite("Mode Normal", () => { }); newTest({ - title: "Can handle ''", + title: "Can handle ''", start: ['te|xt'], - keysPressed: '', + keysPressed: '', end: ["te|t"], }); newTest({ - title: "Can handle 'N', which should be a no-op", + title: "Can handle 'N', which should be a no-op", start: ['te|xt'], - keysPressed: '2', + keysPressed: '2', end: ["te|xt"], }); newTest({ - title: "Can handle '' at end of line", + title: "Can handle '' at end of line", start: ['one tw|o'], - keysPressed: '^ll', + keysPressed: '^ll', end: ['|'], }); newTest({ title: "Can handle 'cc'", start: ['one', '|one two', 'three'], - keysPressed: 'cca', + keysPressed: 'cca', end: ["one", "|a", "three"], }); newTest({ title: "Can handle 'Ncc'", start: ['one', '|one two', 'three four', 'five'], - keysPressed: '2cca', + keysPressed: '2cca', end: ["one", "|a", "five"] }); newTest({ title: "Can handle 'yy'", start: ['|one'], - keysPressed: 'yyOp', + keysPressed: 'yyOp', end: ["", "|one", "one"], }); @@ -203,9 +203,9 @@ suite("Mode Normal", () => { }); newTest({ - title: "Can handle '' in insert mode", + title: "Can handle '' in insert mode", start: ['one', '|'], - keysPressed: 'i', + keysPressed: 'i', end: ['on|e'] }); diff --git a/test/mode/normalModeTests/dot.test.ts b/test/mode/normalModeTests/dot.test.ts index 87505bd94682..65de5ea38c46 100644 --- a/test/mode/normalModeTests/dot.test.ts +++ b/test/mode/normalModeTests/dot.test.ts @@ -42,14 +42,14 @@ suite("Dot Operator", () => { newTest({ title: "Can handle dot with A", start: ['|one', 'two', 'three'], - keysPressed: 'A!j.j.', + keysPressed: 'A!j.j.', end: ['one!', 'two!', 'three|!'] }); newTest({ title: "Can handle dot with I", start: ['on|e', 'two', 'three'], - keysPressed: 'I!j.j.', + keysPressed: 'I!j.j.', end: ['!one', '!two', '|!three'] }); diff --git a/test/mode/normalModeTests/motions.test.ts b/test/mode/normalModeTests/motions.test.ts index cdc7a2f1f851..3917693285c8 100644 --- a/test/mode/normalModeTests/motions.test.ts +++ b/test/mode/normalModeTests/motions.test.ts @@ -8,7 +8,8 @@ suite("Motions in Normal Mode", () => { let modeHandler: ModeHandler = new ModeHandler(); let { - newTest + newTest, + newTestOnly, } = getTestingFunctions(modeHandler); setup(async () => { @@ -342,14 +343,14 @@ suite("Motions in Normal Mode", () => { newTest({ title: "Can handle dot with A", start: ['|one', 'two', 'three'], - keysPressed: 'A!j.j.', + keysPressed: 'A!j.j.', end: ['one!', 'two!', 'three|!'] }); newTest({ title: "Can handle dot with I", start: ['on|e', 'two', 'three'], - keysPressed: 'I!j.j.', + keysPressed: 'I!j.j.', end: ['!one', '!two', '|!three'] }); diff --git a/test/operator/put.test.ts b/test/operator/put.test.ts index 44783bd6fdb6..941d0c6541d7 100644 --- a/test/operator/put.test.ts +++ b/test/operator/put.test.ts @@ -21,7 +21,7 @@ suite("put operator", () => { ); await modeHandler.handleMultipleKeyEvents([ - '', + '', '^', 'D', 'p', 'p' ]); @@ -34,7 +34,7 @@ suite("put operator", () => { ); await modeHandler.handleMultipleKeyEvents([ - '', + '', '^', 'y', 'y', 'p' ]); @@ -47,7 +47,7 @@ suite("put operator", () => { ); await modeHandler.handleMultipleKeyEvents([ - '', + '', 'g', 'g', 'y', 'y', 'p' ]); @@ -60,7 +60,7 @@ suite("put operator", () => { ); await modeHandler.handleMultipleKeyEvents([ - '', + '', 'k', 'y', 'y', 'p' ]); diff --git a/test/testSimplifier.ts b/test/testSimplifier.ts index fa2a9121bf6a..4e2b5c94c064 100644 --- a/test/testSimplifier.ts +++ b/test/testSimplifier.ts @@ -146,7 +146,7 @@ class TestObjectHelper { } /** - * Tokenize a string like "abcd" into ["a", "b", "c", "", "d", ""] + * Tokenize a string like "abcd" into ["a", "b", "c", "", "d", ""] */ function tokenizeKeySequence(sequence: string): string[] { let isBracketedKey = false; @@ -168,6 +168,16 @@ function tokenizeKeySequence(sequence: string): string[] { continue; } + const bracketedKeyTranslations = { + '' : 'ctrl+r', + '' : 'ctrl+a', + '' : 'ctrl+x', + }; + + if (key in bracketedKeyTranslations) { + key = bracketedKeyTranslations[key]; + } + result.push(key); key = ""; } @@ -181,7 +191,7 @@ async function testIt(modeHandler: ModeHandler, testObj: ITestObject): Promise'); + await modeHandler.handleKeyEvent(''); // start: // @@ -189,7 +199,7 @@ async function testIt(modeHandler: ModeHandler, testObj: ITestObject): Promise'); + await modeHandler.handleKeyEvent(''); // move cursor to start position using 'hjkl' await modeHandler.handleMultipleKeyEvents(helper.getKeyPressesToMoveToStartPosition());