Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 21c7de45d9 fix(vim): let af / if work on the right-hand side of a noremap
A noremap runs its keys against codemirror-vim's built-in keymap only, and
the function text objects were mapped after it as user mappings, so
`nnoremap X daf` deleted nothing. af / if are now part of the built-in
keymap through the existing vim-core patch (as <C-g>u is), and are no
longer re-mapped after every mapclear.
2026-12-02 12:58:26 +08:00
5 змінених файлів з 46 додано та 26 видалено

No files matched your search

+23 -2
Переглянути файл
@@ -1,7 +1,7 @@
diff --git a/vim.js b/vim.js
--- a/vim.js
+++ b/vim.js
@@ -236,6 +236,8 @@ export function initVim(CM) {
@@ -236,6 +236,8 @@
{ 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 +10,28 @@ 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' }},
@@ -3423,6 +3425,8 @@ export function initVim(CM) {
@@ -248,6 +250,11 @@
{ 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
@@ -2582,6 +2589,8 @@
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 +3432,8 @@
cm.replaceSelection(text);
}
},
Створено
+3 -3
Переглянути файл
@@ -11,7 +11,7 @@ patchedDependencies:
'@codemirror/[email protected]': 749248c048d621c100ca4d4d8c59c6d826adfaa4913010d11406330a93682a2b
'@codemirror/view': bcc394e0b3a7448b934ebb02620609bd95feb4ef66112bc6aad0a23ef0af3589
'@lezer/lr': 1561ac9e9bbbc302f48ea274ae33602e598a7833edaadd7031559c893c7853b8
'@replit/[email protected]': 5a91a670fe5ac2e3e8499f25bed297c44814090902532223383440f52b825e1c
'@replit/[email protected]': e502665b2969d19575a5671f9555ed0433a92fb42ae5f92121ef355c04b8f49c
importers:
@@ -3744,7 +3744,7 @@ snapshots:
'@lezer/highlight': 1.2.5
'@lezer/lr': 1.4.11(patch_hash=1561ac9e9bbbc302f48ea274ae33602e598a7833edaadd7031559c893c7853b8)
'@replit/[email protected](patch_hash=5a91a670fe5ac2e3e8499f25bed297c44814090902532223383440f52b825e1c)': {}
'@replit/[email protected](patch_hash=e502665b2969d19575a5671f9555ed0433a92fb42ae5f92121ef355c04b8f49c)': {}
'@replit/[email protected](@codemirror/[email protected])(@codemirror/[email protected](patch_hash=749248c048d621c100ca4d4d8c59c6d826adfaa4913010d11406330a93682a2b))(@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected](patch_hash=bcc394e0b3a7448b934ebb02620609bd95feb4ef66112bc6aad0a23ef0af3589))':
dependencies:
@@ -3753,7 +3753,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=5a91a670fe5ac2e3e8499f25bed297c44814090902532223383440f52b825e1c)
'@replit/codemirror-vim-core': 0.1.0(patch_hash=e502665b2969d19575a5671f9555ed0433a92fb42ae5f92121ef355c04b8f49c)
'@rolldown/[email protected]':
optional: true
+13
Переглянути файл
@@ -103,4 +103,17 @@ describe("af / if in Vim", () => {
keys(cm, "a");
expect((cm as unknown as { state: { vim: { insertMode: boolean } } }).state.vim.insertMode).toBe(true);
});
it("works on the right-hand side of a noremap", () => {
// noremap runs its keys against the built-in keymap only, so af / if must be part of it.
applyRcCommands(parseVimrc("nnoremap X daf\nnnoremap Y vif").commands);
let cm = open(JAVA, JAVA.indexOf("return 1"));
keys(cm, "X");
expect(view!.state.doc.toString()).not.toContain("one()");
cm = open(JAVA, JAVA.indexOf("return 1"));
keys(cm, "Y");
const sel = view!.state.selection.main;
expect(view!.state.sliceDoc(sel.from, sel.to)).toContain("return 1;");
applyRcCommands([]);
});
});
+2 -4
Переглянути файл
@@ -25,7 +25,7 @@ import {
import { useVimMode, type VimModeState } from "./mode";
import { resolveActionId, type RcCommand, type SetOp } from "./rc";
import { useVimSettings } from "./settings";
import { mapFunctionTextObjects } from "./textObjects";
import { defineFunctionTextObjects } from "./textObjects";
import { resetLineNumberOptions } from "./lineNumbers";
export { setLineNumberOptionsActive } from "./lineNumbers";
@@ -523,7 +523,7 @@ export function defineExCommands() {
Vim.defineEx("wq", "wq", saveThenClose);
Vim.defineEx("xit", "x", saveThenClose);
Vim.defineEx("action", "action", (_cm, params) => void runIdeAction(params.args?.[0]));
mapFunctionTextObjects();
defineFunctionTextObjects();
}
/**
@@ -608,8 +608,6 @@ export function applyRcCommands(commands: readonly RcCommand[]): string[] {
Vim.mapclear();
resetLineNumberOptions();
shadowLeaderBuiltins(commands);
// `mapclear` drops them with the user mappings; before those, which may remap them.
mapFunctionTextObjects();
const problems: string[] = [];
for (const c of commands) {
try {
+5 -17
Переглянути файл
@@ -110,8 +110,11 @@ interface VimState {
let defined = false;
/** Defines the motion behind `af` / `if` (once). */
function defineFunctionTextObjects() {
/**
* Defines the motion behind `af` / `if` (once). The keys are part of the built-in keymap
* (patches/@replit__codemirror-vim-core), so a `noremap` right-hand side reaches them too.
*/
export function defineFunctionTextObjects() {
if (defined) return;
defined = true;
Vim.defineMotion("openideaFunction", ((
@@ -148,18 +151,3 @@ function defineFunctionTextObjects() {
return [cm.posFromIndex(r.from), cm.posFromIndex(vim.visualMode ? r.to - 1 : r.to)];
}) as never);
}
/** Maps `af` / `if` in Operator-pending and Visual mode; again after every `mapclear`. */
export function mapFunctionTextObjects() {
defineFunctionTextObjects();
for (const context of ["operatorPending", "visual"]) {
Vim._mapCommand({ keys: "af", type: "motion", motion: "openideaFunction", context } as never);
Vim._mapCommand({
keys: "if",
type: "motion",
motion: "openideaFunction",
motionArgs: { textObjectInner: true },
context,
} as never);
}
}