diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-17 07:24:58 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | f233d87376bbdfde3918f803e31b52a214ea9bdb (patch) | |
| tree | f62cc8df1c9c4ad3c635b189631bbda08f9086ae /src | |
| parent | 946e96c0ec793d6b546da8ebef19555d639ccda6 (diff) | |
| download | pardes-f233d87376bbdfde3918f803e31b52a214ea9bdb.tar.gz pardes-f233d87376bbdfde3918f803e31b52a214ea9bdb.zip | |
+171 -73 lib: the tree-sitter walks run in the library on a parse its caller hands in (docs/next-editor.md): `key(a, syn, k)` and `run(a, syn, act)` take a `?*Syntax`, which keeps the grammar it parses in, the tree, made on the first walk after the text changes, and helix's object_selections (Alt-o's history, for Alt-i to go back the way it came) in the page allocator; with one, Alt-o, Alt-i, Alt-n, Alt-p, Alt-a, Alt-I, Alt-e, Alt-b and `]f` and kin run in the library, and `mif` and kin find the grammar's textobjects; without, they come back as actions, as before; normal.nodeTree is the parse they read, a file's (fileTree) in pardes and the one handed in in the library, `Editor.Tree` its tree, path and history, so nodeSelect and objectJump take the editor's context and are textAction's, textRole saying the walks are the text's with a parse at hand, and edit.textobjectSelect reads it too; NodeStep moves to Editor.zig (File.zig names it); nothing a pane does changes; hxlib hands each case a parse with no grammar (a case's text has none): 538 of 658 compared with 0 mismatches (expand_node's one case moved from the caller's), --parity 618 of 738 with 0 mismatches; test/lib: Alt-o and Alt-i on C, back the way they came, `maf` from a textobjects query handed in, and Alt-o without a parse the caller's; core-test 811 of 950, shell-test 990 of 993, hxdiff 658 / parity 738 / hxgolf 124 with 0 mismatches, replicas pass, lib-test pass
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src')
| -rw-r--r-- | src/Editor.zig | 13 | ||||
| -rw-r--r-- | src/File.zig | 2 | ||||
| -rw-r--r-- | src/edit.zig | 9 | ||||
| -rw-r--r-- | src/lib_editor.zig | 79 | ||||
| -rw-r--r-- | src/normal.zig | 74 |
5 files changed, 117 insertions, 60 deletions
diff --git a/src/Editor.zig b/src/Editor.zig index 014d1923..b7c7057d 100644 --- a/src/Editor.zig +++ b/src/Editor.zig @@ -12,9 +12,18 @@ const Registers = @import("Registers.zig"); /// on this at compile time, so the library never compiles the core. pub const lib = @import("pardes_config").lib; const Pardes = if (lib) void else @import("Core.zig"); +const Syntax = if (lib) @import("lib_editor.zig").Syntax else void; +const modal = @import("modal.zig"); const Editor = @This(); +/// A text's parse as the tree-sitter walks read it (normal.nodeTree): the +/// tree, a path its grammar's queries are found by, and helix's +/// object_selections, what Alt-o grew from for Alt-i to go back to, its +/// ranges in `gpa`. Dropped with the tree when the text changes. +pub const Tree = struct { root: *anyopaque, path: []const u8, history: *std.ArrayList(NodeStep), gpa: std.mem.Allocator }; +pub const NodeStep = struct { ranges: []modal.Selection, primary: usize }; + gpa: std.mem.Allocator, /// What an edit makes and drops: the update's scratch. scratch: std.mem.Allocator, @@ -39,6 +48,9 @@ p: if (lib) void else *Pardes, /// The library's: an edit failed (its allocator ran out) and the key is /// refused. failed: if (lib) *bool else void, +/// The library's: the parse its caller handed in, which the tree-sitter +/// walks read; null, and they are the caller's (`textRole`). +syntax: if (lib) ?*Syntax else void, pub fn of(p: *Pardes) Editor { return .{ @@ -53,6 +65,7 @@ pub fn of(p: *Pardes) Editor { .retired_edit = &p.retired_edit, .p = p, .failed = {}, + .syntax = {}, }; } diff --git a/src/File.zig b/src/File.zig index 0c3c3a2f..d049fc27 100644 --- a/src/File.zig +++ b/src/File.zig @@ -181,7 +181,7 @@ pub const State = struct { follow: bool = false, }; -pub const NodeStep = struct { ranges: []modal.Selection, primary: usize }; +pub const NodeStep = @import("Editor.zig").NodeStep; pub fn graphemeDisplayWidth(grapheme: []const u8) usize { if (std.mem.eql(u8, grapheme, "\t")) return config.tab_now; diff --git a/src/edit.zig b/src/edit.zig index 105b9abf..8c59ffa1 100644 --- a/src/edit.zig +++ b/src/edit.zig @@ -1261,7 +1261,7 @@ fn insertEdit(e: Editor, t: *Text, key: Key) Error!void { const pane = t.pane() orelse break :smart; const f = pane.file orelse break :smart; if (!syntax.supportsPath(f.path)) break :smart; - return normal.nodeSelect(e.p, pane, t, .parent_node_end); + return normal.nodeSelect(e, t, f.content, .parent_node_end); } try insertTab(e, t); }, @@ -1943,11 +1943,8 @@ pub fn textobjectSelect(e: Editor, t: *Text, text: []const u8, obj: u21, around: else => null, }; if (object) |o| { - if (t.what != .body) return; - const pane = t.pane() orelse return; - const f = if (pane.file) |*file| file else return; - const tree = normal.fileTree(e.p, f) orelse return; - const s = syntax.objectAt(f.path, tree, text, o, around, modal.selectionCursor(text, range)) orelse return; + const tree = normal.nodeTree(e, t, text) orelse return; + const s = syntax.objectAt(tree.path, tree.root, text, o, around, modal.selectionCursor(text, range)) orelse return; return t.setRange(text, 0, .{ .anchor = s.from, .head = s.to }, false); } switch (obj) { diff --git a/src/lib_editor.zig b/src/lib_editor.zig index 86e494e1..f9149ef0 100644 --- a/src/lib_editor.zig +++ b/src/lib_editor.zig @@ -221,6 +221,7 @@ const Live = struct { multi_count: usize = 1, retired_edit: ?[]u8 = null, failed: bool = false, + syntax: ?*Syntax = null, undo_thawed: usize = 0, redo_thawed: usize = 0, /// The ring records thawed, by their text's address: a snapshot still @@ -241,6 +242,7 @@ const Live = struct { .retired_edit = &l.retired_edit, .p = {}, .failed = &l.failed, + .syntax = l.syntax, }; } }; @@ -318,21 +320,24 @@ pub fn Editor(comptime cap: Capacity) type { /// The ranges in document order and which is the primary. pub fn ranges(ed: *const Self, a: std.mem.Allocator, out: *[max_selections]Selection) error{OutOfMemory}!struct { n: usize, primary: usize } { - const live = try ed.thaw(a); + const live = try ed.thaw(a, null); const got = live.text.ranges(live.text.own.?, 0, out); return .{ .n = got.n, .primary = got.pri }; } - /// A key, as a text pane in normal or insert mode takes it. - pub fn key(ed: *Self, a: std.mem.Allocator, k: Key) Outcome { - const live = ed.thaw(a) catch return .{ .refused = .out_of_memory }; + /// A key, as a text pane in normal or insert mode takes it. With + /// `syn`, the tree-sitter walks (Alt-o and kin, `]f`, `mif`) run on + /// its parse, made again if the text has changed; without, they + /// come back as actions (`mif` does nothing). + pub fn key(ed: *Self, a: std.mem.Allocator, syn: ?*Syntax, k: Key) Outcome { + const live = ed.thaw(a, syn) catch return .{ .refused = .out_of_memory }; const parsed = normal.textKey(live.context(a), &live.text, k); switch (parsed) { .unbound => return ed.keep(a, live, .{ .unbound = k }), .pending => return ed.keep(a, live, .pending), .ignored => return ed.keep(a, live, .done), .action => |act| { - if (!normal.textRole(act.role)) { + if (!normal.textRole(act.role, syn != null)) { // the parse's state goes on; nothing ran ed.cursor.normal = live.text.normal; return .{ .action = act }; @@ -344,9 +349,9 @@ pub fn Editor(comptime cap: Capacity) type { /// A normal-mode action, as its key would run it: across every /// range unless it is the selection's as a whole. - pub fn run(ed: *Self, a: std.mem.Allocator, act: Action) Outcome { - if (!normal.textRole(act.role)) return .{ .action = act }; - const live = ed.thaw(a) catch return .{ .refused = .out_of_memory }; + pub fn run(ed: *Self, a: std.mem.Allocator, syn: ?*Syntax, act: Action) Outcome { + if (!normal.textRole(act.role, syn != null)) return .{ .action = act }; + const live = ed.thaw(a, syn) catch return .{ .refused = .out_of_memory }; normal.runAction(live.context(a), &live.text, act); return ed.keep(a, live, .done); } @@ -354,7 +359,7 @@ pub fn Editor(comptime cap: Capacity) type { /// helix's `s` (select), `S` (split), `K` (keep) and `Alt-K` /// (remove) with `pattern` over the ranges there are. pub fn selectRegex(ed: *Self, a: std.mem.Allocator, pattern: []const u8, how: RegexMode) Outcome { - const live = ed.thaw(a) catch return .{ .refused = .out_of_memory }; + const live = ed.thaw(a, null) catch return .{ .refused = .out_of_memory }; const t = &live.text; // as pardes's prompt answers it (look.submitSearch): helix // keeps the pattern in `/` @@ -370,7 +375,7 @@ pub fn Editor(comptime cap: Capacity) type { /// Replace the whole text with `text`, as one step to undo. pub fn setText(ed: *Self, a: std.mem.Allocator, text: []const u8) Outcome { - const live = ed.thaw(a) catch return .{ .refused = .out_of_memory }; + const live = ed.thaw(a, null) catch return .{ .refused = .out_of_memory }; const e = live.context(a); const t = &live.text; edit.pushUndo(e, t) catch return .{ .refused = .out_of_memory }; @@ -390,14 +395,15 @@ pub fn Editor(comptime cap: Capacity) type { /// Write register `name` (the system clipboard's `+`, a pattern's /// `/`): one value. pub fn setRegister(ed: *Self, a: std.mem.Allocator, name: u21, value: []const u8) Outcome { - const live = ed.thaw(a) catch return .{ .refused = .out_of_memory }; + const live = ed.thaw(a, null) catch return .{ .refused = .out_of_memory }; live.registers.put(a, name, value, 0, 1, true) catch return .{ .refused = .out_of_memory }; return ed.keep(a, live, .done); } - fn thaw(ed: *const Self, a: std.mem.Allocator) error{OutOfMemory}!*Live { + fn thaw(ed: *const Self, a: std.mem.Allocator, syn: ?*Syntax) error{OutOfMemory}!*Live { const live = try a.create(Live); - live.* = .{ .text = .{ .what = .body, .own = try ed.bytes(a), .gpa = a } }; + live.* = .{ .text = .{ .what = .body, .own = try ed.bytes(a), .gpa = a }, .syntax = syn }; + if (syn) |s| s.at(ed.revision); const t = &live.text; inline for (@typeInfo(Cursor).@"struct".field_names) |name| @field(t, name) = @field(ed.cursor, name); if (ed.cursor.nsel > 0) { @@ -523,19 +529,50 @@ pub fn Editor(comptime cap: Capacity) type { pub const Syntax = struct { tree: ?*syntax.ts.Tree = null, revision: u32 = 0, + /// The grammar the tree is parsed in: the last `parse`'s, or set by a + /// caller that hands this to `key` before parsing. None, and a walk + /// does nothing, as in a text without a grammar. + lang: ?Language = null, + /// helix's object_selections, what Alt-o grew from for Alt-i to go back + /// to (normal.nodeSelect): the tree's, dropped with it. In the page + /// allocator, which holds nothing of the code that made it. + history: std.ArrayList(Context.NodeStep) = .empty, + path: [64]u8 = undefined, /// The tree of `ed`'s text in `lang`, parsed again when the text has /// changed since the last; null when the language cannot parse. pub fn parse(s: *Syntax, a: std.mem.Allocator, ed: anytype, lang: Language) ?*syntax.ts.Tree { - if (s.tree != null and s.revision == ed.revision) return s.tree; + s.lang = lang; + s.at(ed.revision); + if (s.tree == null) _ = s.walkTree(ed.bytes(a) catch return null); + return s.tree; + } + + /// What is kept of another revision of the text dropped: the tree and + /// Alt-o's history. + fn at(s: *Syntax, revision: u32) void { + if (s.revision == revision) return; + s.drop(); + s.revision = revision; + } + + fn drop(s: *Syntax) void { if (s.tree) |tree| tree.destroy(); s.tree = null; - const text = ed.bytes(a) catch return null; - if (!syntax_impl.addLanguage(lang)) return null; - var buf: [64]u8 = undefined; - s.tree = @ptrCast(@alignCast(syntax_impl.parseTree(lang.path(&buf), text, null) orelse return null)); - s.revision = ed.revision; - return s.tree; + for (s.history.items) |step| std.heap.page_allocator.free(step.ranges); + s.history.clearAndFree(std.heap.page_allocator); + } + + /// The parse of `text`, the text at `revision`, as a key's walks read + /// it (normal.nodeTree): made the first time one asks for it. + pub fn walkTree(s: *Syntax, text: []const u8) ?Context.Tree { + const lang = s.lang orelse return null; + const path = lang.path(&s.path); + if (s.tree == null) { + if (!syntax_impl.addLanguage(lang)) return null; + s.tree = @ptrCast(@alignCast(syntax_impl.parseTree(path, text, null) orelse return null)); + } + return .{ .root = s.tree.?, .path = path, .history = &s.history, .gpa = std.heap.page_allocator }; } /// One `Syn` a byte of `ed`'s text from `from` to `to`, in `a`. @@ -549,7 +586,7 @@ pub const Syntax = struct { /// The tree gone, and every language handed in (at a reload: their /// code is about to go). pub fn forget(s: *Syntax) void { - if (s.tree) |tree| tree.destroy(); + s.drop(); s.* = .{}; syntax_impl.forgetLanguages(); } diff --git a/src/normal.zig b/src/normal.zig index c4c00824..70933607 100644 --- a/src/normal.zig +++ b/src/normal.zig @@ -225,16 +225,25 @@ pub fn fileTree(p: *Pardes, f: *panes.File.State) ?*anyopaque { return f.node_tree; } +/// The parse a body's tree-sitter walks read: its file's (`fileTree`), or +/// in the library the one its caller handed in (lib_editor.Syntax); null +/// without a grammar, and the walk leaves the ranges as they are. +pub fn nodeTree(e: Editor, t: *Text, text: []const u8) ?Editor.Tree { + if (t.what != .body) return null; + if (comptime Editor.lib) return (e.syntax orelse return null).walkTree(text); + const pane = t.pane() orelse return null; + const f = if (pane.file) |*file| file else return null; + return .{ .root = fileTree(e.p, f) orelse return null, .path = f.path, .history = &f.node_history, .gpa = e.gpa }; +} + /// `]f`/`[f` and kin (helix goto_ts_object): to the next object starting /// after the cursor or the previous one ending before it, count times; select /// mode stretches the range to it. -fn objectJump(p: *Pardes, pane: *Pane, t: *Text, text: []const u8, range: modal.Selection, object: modal.Normal.Object, forward: bool, count: u32) void { - if (t.what != .body) return; - const f = if (pane.file) |*file| file else return; - const tree = fileTree(p, f) orelse return; +fn objectJump(e: Editor, t: *Text, text: []const u8, range: modal.Selection, object: modal.Normal.Object, forward: bool, count: u32) void { + const tree = nodeTree(e, t, text) orelse return; var last = range; for (0..count) |_| { - const s = syntax.objectNext(f.path, tree, text, object, forward, modal.selectionCursor(text, last)) orelse break; + const s = syntax.objectNext(tree.path, tree.root, text, object, forward, modal.selectionCursor(text, last)) orelse break; const next: modal.Selection = .{ .anchor = s.from, .head = s.to }; if (std.meta.eql(next, last)) break; last = next; @@ -248,21 +257,19 @@ fn objectJump(p: *Pardes, pane: *Pane, t: *Text, text: []const u8, range: modal. t.setRange(text, 0, out, false); } -/// helix's tree-sitter selection keys: every range walks the file's parse, -/// which is made on the first of these keys after an edit and kept, never -/// made again for a key that changed nothing. A range the tree has nothing -/// to say about stays as it was; a text without a grammar, all of them. -pub fn nodeSelect(p: *Pardes, pane: *Pane, t: *Text, walk: modal.Normal.NodeWalk) edit.Error!void { - if (t.what != .body) return; - const f = if (pane.file) |*file| file else return; - const tree = fileTree(p, f) orelse return; - const text = f.content; +/// helix's tree-sitter selection keys: every range walks the text's parse +/// (`nodeTree`), which is made on the first of these keys after an edit and +/// kept, never made again for a key that changed nothing. A range the tree +/// has nothing to say about stays as it was; a text without a grammar, all +/// of them. +pub fn nodeSelect(e: Editor, t: *Text, text: []const u8, walk: modal.Normal.NodeWalk) edit.Error!void { + const tree = nodeTree(e, t, text) orelse return; const expl = t.vsel.active and t.vsel.explicit; - const arena = p.scratch.allocator(); + const arena = e.scratch; const rs = try arena.alloc(modal.Selection, Text.max_selections); const got = t.ranges(text, 0, rs[0..Text.max_selections]); - if (walk == .shrink_node) if (f.node_history.pop()) |prev| { - defer p.gpa.free(prev.ranges); + if (walk == .shrink_node) if (tree.history.pop()) |prev| { + defer tree.gpa.free(prev.ranges); // back to what Alt-o grew from, while the selection still holds it const holds = for (prev.ranges) |pr| { const pf = @min(pr.anchor, pr.head); @@ -273,8 +280,8 @@ pub fn nodeSelect(p: *Pardes, pane: *Pane, t: *Text, walk: modal.Normal.NodeWalk break false; } else true; if (holds) return t.setRanges(text, prev.ranges, &.{}, prev.primary, expl); - for (f.node_history.items) |step| p.gpa.free(step.ranges); - f.node_history.clearRetainingCapacity(); + for (tree.history.items) |step| tree.gpa.free(step.ranges); + tree.history.clearRetainingCapacity(); }; const out = try arena.alloc(modal.Selection, Text.max_selections); const spans = try arena.alloc(syntax.Span, Text.max_selections); @@ -284,7 +291,7 @@ pub fn nodeSelect(p: *Pardes, pane: *Pane, t: *Text, walk: modal.Normal.NodeWalk const from = @min(r.anchor, r.head); const to = @max(r.anchor, r.head); const back = r.head < r.anchor; - const n = syntax.walkNodes(tree, walk, from, to, modal.selectionCursor(text, r), spans[0 .. out.len - m]); + const n = syntax.walkNodes(tree.root, walk, from, to, modal.selectionCursor(text, r), spans[0 .. out.len - m]); if (n == 0) { out[m] = r; m += 1; @@ -312,8 +319,8 @@ pub fn nodeSelect(p: *Pardes, pane: *Pane, t: *Text, walk: modal.Normal.NodeWalk } const same = m == got.n and std.mem.eql(u8, std.mem.sliceAsBytes(out[0..m]), std.mem.sliceAsBytes(rs[0..m])); if (walk == .expand_node and !same) remember: { - const ranges = p.gpa.dupe(modal.Selection, rs[0..got.n]) catch break :remember; - f.node_history.append(p.gpa, .{ .ranges = ranges, .primary = got.pri }) catch p.gpa.free(ranges); + const ranges = tree.gpa.dupe(modal.Selection, rs[0..got.n]) catch break :remember; + tree.history.append(tree.gpa, .{ .ranges = ranges, .primary = got.pri }) catch tree.gpa.free(ranges); } t.setRanges(text, out[0..m], &.{}, @min(got.pri, m - 1), expl); } @@ -552,7 +559,7 @@ pub fn handleNormal(e: Editor, t: *Text, key: Key) modal.Normal.Result { }; t.normal.register = 0; // the core's roles are the library's caller's - if (comptime Editor.lib) if (!textRole(action.role)) return parsed; + if (comptime Editor.lib) if (!textRole(action.role, e.syntax != null)) return parsed; e.register.* = named; defer e.register.* = 0; runAction(e, t, action); @@ -984,10 +991,13 @@ fn shrinkSelToLineBounds(t: *Text, text: []const u8, range: modal.Selection) voi /// Whether a normal-mode role is the text's alone (`textAction`), or /// reaches past it: a view, a builtin, a prompt, a language server, the -/// look ring, the jump labels, a macro. -pub fn textRole(role: modal.Normal.Role) bool { +/// look ring, the jump labels, a macro. The tree-sitter walks are the +/// text's with a parse at hand (`tree`, `nodeTree`): a pane's file has +/// one, the library's caller may hand one in. +pub fn textRole(role: modal.Normal.Role, tree: bool) bool { return switch (role) { - .all_children, .all_siblings, .append_output, .command_line, .expand_node, .format, .goto_callstack, .goto_class, .goto_comment, .goto_declaration, .goto_definition, .goto_diagnostic, .goto_diagnostic_end, .goto_entry, .goto_function, .goto_implementation, .goto_parameter, .goto_references, .goto_test, .goto_type_definition, .goto_view_bottom, .goto_view_top, .goto_word, .goto_xml_element, .half_page_down, .half_page_up, .insert_output, .keep_pipe, .keep_regex, .leader, .macro_record, .macro_replay, .next_sibling, .page_down, .page_up, .parent_node_end, .parent_node_start, .pipe_selection, .pipe_selection_to, .prev_sibling, .remove_regex, .repeat_insert, .search, .search_next, .search_prev, .select_regex, .shrink_node, .split_regex, .view_bottom, .view_center, .view_middle, .view_scroll_down, .view_scroll_up, .view_top => false, + .all_children, .all_siblings, .expand_node, .goto_class, .goto_comment, .goto_entry, .goto_function, .goto_parameter, .goto_test, .goto_xml_element, .next_sibling, .parent_node_end, .parent_node_start, .prev_sibling, .shrink_node => tree, + .append_output, .command_line, .format, .goto_callstack, .goto_declaration, .goto_definition, .goto_diagnostic, .goto_diagnostic_end, .goto_implementation, .goto_references, .goto_type_definition, .goto_view_bottom, .goto_view_top, .goto_word, .half_page_down, .half_page_up, .insert_output, .keep_pipe, .keep_regex, .leader, .macro_record, .macro_replay, .page_down, .page_up, .pipe_selection, .pipe_selection_to, .remove_regex, .repeat_insert, .search, .search_next, .search_prev, .select_regex, .split_regex, .view_bottom, .view_center, .view_middle, .view_scroll_down, .view_scroll_up, .view_top => false, else => true, }; } @@ -1059,6 +1069,11 @@ pub fn textAction(e: Editor, t: *Text, a: modal.Normal.Action) edit.Error!void { return pointMove(t, text, range, modal.offsetAt(text, mc)); }, .match_inside, .match_around => return edit.textobjectSelect(e, t, text, a.char, a.role == .match_around), + inline .goto_function, .goto_class, .goto_parameter, .goto_comment, .goto_test, .goto_entry, .goto_xml_element => |role| { + const object = @field(modal.Normal.Object, @tagName(role)["goto_".len..]); + return objectJump(e, t, text, range, object, a.forward, a.count); + }, + inline .expand_node, .shrink_node, .next_sibling, .prev_sibling, .all_siblings, .all_children, .parent_node_end, .parent_node_start => |role| return nodeSelect(e, t, text, @field(modal.Normal.NodeWalk, @tagName(role))), .surround_add => return edit.surroundAdd(e, t, a.char), .surround_delete => return edit.surroundDelete(e, t, a.char), .surround_replace => return edit.surroundReplace(e, t, a.from, a.char), @@ -1175,7 +1190,7 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) edit.Error! pane.sel[sel_slot].state = .none; }; if (raw_selection and a.role == .yank) return edit.normalYank(p.editor(), t); - if (textRole(a.role)) return textAction(p.editor(), t, a); + if (textRole(a.role, true)) return textAction(p.editor(), t, a); edit.pinPaneCursor(p.editor(), t); const text = try edit.flatSurface(p.editor(), t); const range = t.primaryRange(text, 0); @@ -1222,10 +1237,6 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) edit.Error! if (set.hits.items.len == 0) return; set.goTo(pane, if (a.forward) set.hits.items.len - 1 else 0, false); }, - inline .goto_function, .goto_class, .goto_parameter, .goto_comment, .goto_test, .goto_entry, .goto_xml_element => |role| { - const object = @field(modal.Normal.Object, @tagName(role)["goto_".len..]); - return objectJump(p, pane, t, text, range, object, a.forward, a.count); - }, // These four move exactly one viewport unit, whatever the count. .half_page_down => return halfPageMove(t, text, range, true), .half_page_up => return halfPageMove(t, text, range, false), @@ -1234,7 +1245,6 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) edit.Error! // s, S and | answer for the text they are pressed in; `/` searches // the body wherever it is pressed, as acme's Look from a tag does. inline .select_regex, .split_regex, .keep_regex, .remove_regex => |role| return startSelRegex(p, pane, t, @field(modal.Normal.RegexMode, @tagName(role)[0 .. @tagName(role).len - "_regex".len])), - inline .expand_node, .shrink_node, .next_sibling, .prev_sibling, .all_siblings, .all_children, .parent_node_end, .parent_node_start => |role| return nodeSelect(p, pane, t, @field(modal.Normal.NodeWalk, @tagName(role))), // Language shortcuts run the same builtins as tags and leader commands. .goto_definition => return exec.runBuiltin(p, .Def, v.active, "", null), .goto_references => return exec.runBuiltin(p, .Refs, v.active, "", null), |
