fix(vim): end the command after an <Action> mapping (#8132)

A keyToEx mapping such as `nnoremap gd <Action>(GotoDeclaration)` ran its Ex command without clearing the input state, so the typed keys stayed in the Vim status and the destination editor drew the half-height pending cursor until the next command. The mapped Ex command now ends the command the same way the `:` prompt does. Covers every keyToEx mapping (<Action>(...), :action ...<CR>, :w<CR>-style).

Closes #8128

Co-authored-by: aliatli <[email protected]>
Цей коміт міститься в:
Ali Atliтаaliatli authored and GitHub committed 2026-12-05 07:17:14 +08:00
1 джерело 72aa411d2b
коміт bb628998cc
3 files changed
+43 -5

No files matched your search

+11 -2
Переглянути файл
@@ -22,7 +22,16 @@ 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
@@ -2582,6 +2589,8 @@
@@ -1974,6 +1981,8 @@
if (command.type == 'keyToEx') {
// Handle user defined Ex to Ex mappings
exCommandDispatcher.processCommand(cm, command.exArgs.input);
+ // OpenIDEA: end the command like the `:` prompt does, so the typed keys leave the status.
+ if (cm.state.vim) clearInputState(cm);
} else {
/**@type{import("./types").PromptOptions} */
var promptOptions = {
@@ -2582,6 +2591,8 @@
if (head.sticky == "before") head.ch--;
return head;
},
@@ -31,7 +40,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 +3432,8 @@
@@ -3423,6 +3434,8 @@
cm.replaceSelection(text);
}
},
Створено
+3 -3
Переглянути файл
@@ -11,7 +11,7 @@ patchedDependencies:
'@codemirror/[email protected]': eb0f811cd8918704234484dcb1f6740e5cd133ac639d82b968e5b87ae992b9dc
'@codemirror/view': bcc394e0b3a7448b934ebb02620609bd95feb4ef66112bc6aad0a23ef0af3589
'@lezer/lr': 1561ac9e9bbbc302f48ea274ae33602e598a7833edaadd7031559c893c7853b8
'@replit/[email protected]': e502665b2969d19575a5671f9555ed0433a92fb42ae5f92121ef355c04b8f49c
'@replit/[email protected]': 9342a63bb360d0e59c906874d06f35281b15f933a43889566f74554fe12d3263
importers:
@@ -3752,7 +3752,7 @@ snapshots:
'@lezer/highlight': 1.2.5
'@lezer/lr': 1.4.11(patch_hash=1561ac9e9bbbc302f48ea274ae33602e598a7833edaadd7031559c893c7853b8)
'@replit/[email protected](patch_hash=e502665b2969d19575a5671f9555ed0433a92fb42ae5f92121ef355c04b8f49c)': {}
'@replit/[email protected](patch_hash=9342a63bb360d0e59c906874d06f35281b15f933a43889566f74554fe12d3263)': {}
'@replit/[email protected](@codemirror/[email protected])(@codemirror/[email protected](patch_hash=eb0f811cd8918704234484dcb1f6740e5cd133ac639d82b968e5b87ae992b9dc))(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected](patch_hash=bcc394e0b3a7448b934ebb02620609bd95feb4ef66112bc6aad0a23ef0af3589))':
dependencies:
@@ -3761,7 +3761,7 @@ snapshots:
'@codemirror/search': 6.7.2
'@codemirror/state': 6.7.6
'@codemirror/view': 6.44.2(patch_hash=bcc394e0b3a7448b934ebb02620609bd95feb4ef66112bc6aad0a23ef0af3589)
'@replit/codemirror-vim-core': 0.1.0(patch_hash=e502665b2969d19575a5671f9555ed0433a92fb42ae5f92121ef355c04b8f49c)
'@replit/codemirror-vim-core': 0.1.0(patch_hash=9342a63bb360d0e59c906874d06f35281b15f933a43889566f74554fe12d3263)
'@rolldown/[email protected]':
optional: true
+29
Переглянути файл
@@ -262,6 +262,35 @@ describe("Vim engine", () => {
view.destroy();
});
it.each([
["gd", "navigate.declaration"],
["gi", "navigate.implementation"],
])("ends the command after an <Action> mapping (%s)", async (lhs, id) => {
const d = registerAction({ id, title: id, run: () => void ran.push(id) });
const view = makeView();
const cm = getCM(view)!;
applyRcCommands(
parseVimrc(`nnoremap gd <Action>(GotoDeclaration)\nnnoremap gi <Action>(GotoImplementation)`).commands,
);
// Through keydown: the view plugin, not Vim.handleKey, keeps the typed keys in `status`.
const press = (key: string) =>
view.contentDOM.dispatchEvent(new KeyboardEvent("keydown", { key, bubbles: true, cancelable: true }));
press(lhs[0]!);
await tick();
// `g` alone is only a prefix of the mapping.
expect(ran).toEqual([]);
press(lhs[1]!);
await tick();
expect(ran).toEqual([id]);
// A leftover status draws the half-height pending cursor until the next command.
expect(cm.state.vim!.status).toBe("");
expect(cm.state.vim!.inputState.keyBuffer).toEqual([]);
expect(cm.state.vim!.insertMode).toBe(false);
applyRcCommands([]);
view.destroy();
d();
});
it.each([
['let mapleader = " "', ["<Space>", "f", "f"]],
['let mapleader = ","', [",", "f", "f"]],