Файли
openidea/patches/@[email protected]
T
l0ng-ai 201ab6f54b 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.
2026-12-06 04:20:53 +08:00

69 рядки
3.8 KiB
Diff

diff --git a/vim.js b/vim.js
index 3cafa6bcf0c99f2ae25a5da8936d3f29445f2d6d..64c9c9bbf2bfa5fd6313d36ac6495b605a8a79d7 100644
--- a/vim.js
+++ b/vim.js
@@ -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' },
+ // OpenIDEA: insert-mode undo break; the host defines this action.
+ { keys: '<C-g>u', type: 'action', action: 'openideaUndoBreak', context: 'insert' },
{ 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 @@ 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
+ // OpenIDEA: function text objects; the host defines the motion. Built in, so a noremap's keys reach them.
+ { keys: 'af', type: 'motion', motion: 'openideaFunction', context: 'operatorPending' },
+ { keys: 'if', type: 'motion', motion: 'openideaFunction', motionArgs: { textObjectInner: true }, context: 'operatorPending' },
+ { keys: 'af', type: 'motion', motion: 'openideaFunction', context: 'visual' },
+ { keys: 'if', type: 'motion', motion: 'openideaFunction', motionArgs: { textObjectInner: true }, context: 'visual' },
{ keys: 'a<register>', type: 'motion', motion: 'textObjectManipulation' },
{ keys: 'i<register>', type: 'motion', motion: 'textObjectManipulation', motionArgs: { textObjectInner: true }},
// Search
@@ -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);
+ // 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 @@ export function initVim(CM) {
if (head.sticky == "before") head.ch--;
return head;
},
+ // OpenIDEA: the host overrides this with the function text object.
+ openideaFunction: function(cm, head) { return head; },
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 @@ export function initVim(CM) {
cm.replaceSelection(text);
}
},
+ // OpenIDEA: the host overrides this with the undo-break implementation.
+ openideaUndoBreak: function() {},
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 = {