diff --git a/patches/@replit__codemirror-vim-core@0.1.0.patch b/patches/@replit__codemirror-vim-core@0.1.0.patch index 930848ddcf..ef044729dc 100644 --- a/patches/@replit__codemirror-vim-core@0.1.0.patch +++ b/patches/@replit__codemirror-vim-core@0.1.0.patch @@ -1,7 +1,8 @@ diff --git a/vim.js b/vim.js +index 3cafa6bcf0c99f2ae25a5da8936d3f29445f2d6d..64c9c9bbf2bfa5fd6313d36ac6495b605a8a79d7 100644 --- a/vim.js +++ b/vim.js -@@ -236,6 +236,8 @@ +@@ -236,6 +236,8 @@ export function initVim(CM) { { keys: '"', type: 'action', action: 'setRegister' }, { keys: '', type: 'action', action: 'insertRegister', context: 'insert', isEdit: true }, { keys: '', type: 'action', action: 'oneNormalCommand', context: 'insert' }, @@ -10,7 +11,7 @@ diff --git a/vim.js b/vim.js { keys: 'zz', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'center' }}, { keys: 'z.', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'center' }, motion: 'moveToFirstNonWhiteSpaceCharacter' }, { keys: 'zt', type: 'action', action: 'scrollToCursor', actionArgs: { position: 'top' }}, -@@ -248,6 +250,11 @@ +@@ -248,6 +250,11 @@ export function initVim(CM) { { keys: '', type: 'action', action: 'indent', actionArgs: { indentRight: true }, context: 'insert' }, { keys: '', type: 'action', action: 'indent', actionArgs: { indentRight: false }, context: 'insert' }, // Text object motions @@ -22,7 +23,7 @@ diff --git a/vim.js b/vim.js { keys: 'a', type: 'motion', motion: 'textObjectManipulation' }, { keys: 'i', type: 'motion', motion: 'textObjectManipulation', motionArgs: { textObjectInner: true }}, // Search -@@ -1974,6 +1981,8 @@ +@@ -1974,6 +1981,8 @@ export function initVim(CM) { if (command.type == 'keyToEx') { // Handle user defined Ex to Ex mappings exCommandDispatcher.processCommand(cm, command.exArgs.input); @@ -31,7 +32,7 @@ diff --git a/vim.js b/vim.js } else { /**@type{import("./types").PromptOptions} */ var promptOptions = { -@@ -2582,6 +2591,8 @@ +@@ -2582,6 +2591,8 @@ export function initVim(CM) { if (head.sticky == "before") head.ch--; return head; }, @@ -40,7 +41,7 @@ diff --git a/vim.js b/vim.js textObjectManipulation: function(cm, head, motionArgs, vim) { // TODO: lots of possible exceptions that can be thrown here. Try da( // outside of a () block. -@@ -3423,6 +3434,8 @@ +@@ -3423,6 +3434,8 @@ export function initVim(CM) { cm.replaceSelection(text); } }, @@ -49,3 +50,19 @@ diff --git a/vim.js b/vim.js oneNormalCommand: function(cm, actionArgs, vim) { exitInsertMode(cm, true); vim.insertModeReturn = true; +@@ -5870,6 +5883,15 @@ export function initVim(CM) { + }; + } + } else { ++ // OpenIDEA: IdeaVim's `(id)` right-hand side runs the IDE action, as rc mappings do. ++ var ideAction = /^\(([^)\s]+)\)$/i.exec(rhs); ++ if (ideAction) { ++ /**@type {any} */ ++ var exMapping = { keys: lhs, type: 'keyToEx', exArgs: { input: 'action ' + ideAction[1] } }; ++ if (ctx) { exMapping.context = ctx; } ++ _mapCommand(exMapping); ++ return; ++ } + // Key to key or ex mapping + /**@type {vimKey} */ + var mapping = { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9cb9c78b2f..ab51f4f900 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,7 +11,7 @@ patchedDependencies: '@codemirror/language@6.13.1': eb0f811cd8918704234484dcb1f6740e5cd133ac639d82b968e5b87ae992b9dc '@codemirror/view': 3b03bac82db7f12cd29725565880e68e8313a585ca1262b19f3d9785f860ce3e '@lezer/lr': 1561ac9e9bbbc302f48ea274ae33602e598a7833edaadd7031559c893c7853b8 - '@replit/codemirror-vim-core@0.1.0': 9342a63bb360d0e59c906874d06f35281b15f933a43889566f74554fe12d3263 + '@replit/codemirror-vim-core@0.1.0': e5f0b0d3fd721504269ba2268124524f764f83a04ac4ffa6a0ff8fd121583e4f importers: @@ -3752,7 +3752,7 @@ snapshots: '@lezer/highlight': 1.2.5 '@lezer/lr': 1.4.11(patch_hash=1561ac9e9bbbc302f48ea274ae33602e598a7833edaadd7031559c893c7853b8) - '@replit/codemirror-vim-core@0.1.0(patch_hash=9342a63bb360d0e59c906874d06f35281b15f933a43889566f74554fe12d3263)': {} + '@replit/codemirror-vim-core@0.1.0(patch_hash=e5f0b0d3fd721504269ba2268124524f764f83a04ac4ffa6a0ff8fd121583e4f)': {} '@replit/codemirror-vim@6.4.0(@codemirror/commands@6.11.1)(@codemirror/language@6.13.1(patch_hash=eb0f811cd8918704234484dcb1f6740e5cd133ac639d82b968e5b87ae992b9dc))(@codemirror/search@6.7.2)(@codemirror/state@6.7.6)(@codemirror/view@6.44.2(patch_hash=3b03bac82db7f12cd29725565880e68e8313a585ca1262b19f3d9785f860ce3e))': dependencies: @@ -3761,7 +3761,7 @@ snapshots: '@codemirror/search': 6.7.2 '@codemirror/state': 6.7.6 '@codemirror/view': 6.44.2(patch_hash=3b03bac82db7f12cd29725565880e68e8313a585ca1262b19f3d9785f860ce3e) - '@replit/codemirror-vim-core': 0.1.0(patch_hash=9342a63bb360d0e59c906874d06f35281b15f933a43889566f74554fe12d3263) + '@replit/codemirror-vim-core': 0.1.0(patch_hash=e5f0b0d3fd721504269ba2268124524f764f83a04ac4ffa6a0ff8fd121583e4f) '@rolldown/binding-android-arm-eabi@1.2.14': optional: true diff --git a/src/features/vim/__tests__/vim.test.ts b/src/features/vim/__tests__/vim.test.ts index 416aaab22a..352a449687 100644 --- a/src/features/vim/__tests__/vim.test.ts +++ b/src/features/vim/__tests__/vim.test.ts @@ -291,6 +291,28 @@ describe("Vim engine", () => { d(); }); + it.each(["nmap", "nnoremap", "map"])("runs an mapping made at the : prompt (%s)", async (cmd) => { + const d = registerAction({ + id: "navigate.declaration", + title: "x", + run: () => void ran.push("navigate.declaration"), + }); + const view = makeView(); + const cm = getCM(view)!; + applyRcCommands([]); + const before = view.state.doc.toString(); + _handleEx(view, `${cmd} X (GotoDeclaration)`); + Vim.handleKey(cm as never, "X", "user"); + await tick(); + expect(ran).toEqual(["navigate.declaration"]); + // Before: the right-hand side was replayed as keys, typing into the document. + expect(view.state.doc.toString()).toBe(before); + expect(cm.state.vim!.insertMode).toBe(false); + applyRcCommands([]); + view.destroy(); + d(); + }); + it.each([ ['let mapleader = " "', ["", "f", "f"]], ['let mapleader = ","', [",", "f", "f"]],