fix(vim): run an <Action>(id) mapping made at the : prompt (#8291)

Typed at the : prompt, a mapping to <Action>(id) replayed its right-hand side as keys, typing into the document. The map commands now turn such a right-hand side into the action command rc mappings use.
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-12-06 04:20:53 +08:00
1 джерело ecd8404e66
коміт 201ab6f54b
3 files changed
+47 -8

No files matched your search

+22 -5
Переглянути файл
@@ -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: '"<register>', type: 'action', action: 'setRegister' },
{ keys: '<C-r><register>', type: 'action', action: 'insertRegister', context: 'insert', isEdit: true },
{ keys: '<C-o>', 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: '<C-t>', type: 'action', action: 'indent', actionArgs: { indentRight: true }, context: 'insert' },
{ keys: '<C-d>', 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<register>', type: 'motion', motion: 'textObjectManipulation' },
{ keys: 'i<register>', 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 `<Action>(id)` right-hand side runs the IDE action, as rc mappings do.
+ var ideAction = /^<Action>\(([^)\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 = {
Створено
+3 -3
Переглянути файл
@@ -11,7 +11,7 @@ patchedDependencies:
'@codemirror/[email protected]': eb0f811cd8918704234484dcb1f6740e5cd133ac639d82b968e5b87ae992b9dc
'@codemirror/view': 3b03bac82db7f12cd29725565880e68e8313a585ca1262b19f3d9785f860ce3e
'@lezer/lr': 1561ac9e9bbbc302f48ea274ae33602e598a7833edaadd7031559c893c7853b8
'@replit/[email protected]': 9342a63bb360d0e59c906874d06f35281b15f933a43889566f74554fe12d3263
'@replit/[email protected]': e5f0b0d3fd721504269ba2268124524f764f83a04ac4ffa6a0ff8fd121583e4f
importers:
@@ -3752,7 +3752,7 @@ snapshots:
'@lezer/highlight': 1.2.5
'@lezer/lr': 1.4.11(patch_hash=1561ac9e9bbbc302f48ea274ae33602e598a7833edaadd7031559c893c7853b8)
'@replit/[email protected](patch_hash=9342a63bb360d0e59c906874d06f35281b15f933a43889566f74554fe12d3263)': {}
'@replit/[email protected](patch_hash=e5f0b0d3fd721504269ba2268124524f764f83a04ac4ffa6a0ff8fd121583e4f)': {}
'@replit/[email protected](@codemirror/[email protected])(@codemirror/[email protected](patch_hash=eb0f811cd8918704234484dcb1f6740e5cd133ac639d82b968e5b87ae992b9dc))(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected](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/[email protected]':
optional: true
+22
Переглянути файл
@@ -291,6 +291,28 @@ describe("Vim engine", () => {
d();
});
it.each(["nmap", "nnoremap", "map"])("runs an <Action> 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 <Action>(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 = " "', ["<Space>", "f", "f"]],
['let mapleader = ","', [",", "f", "f"]],