diff options
Diffstat (limited to 'core/body_layer.zig')
| -rw-r--r-- | core/body_layer.zig | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/core/body_layer.zig b/core/body_layer.zig index 82bfcebc..8bc38e23 100644 --- a/core/body_layer.zig +++ b/core/body_layer.zig @@ -875,21 +875,34 @@ fn targetLine(p: *Pardes, pane: *Pane, f: *panes.File.State, role: modal.Normal. if (forward) return if (a < hits.len) lineOf(f, hits[a].start) else null; return if (a > 0) lineOf(f, hits[a - 1].start) else null; }, - inline .goto_function, .goto_comment, .goto_test => |r| { - // The tree as the motion reads it, made once a revision; with - // the Changes layer's lines in the buffer its offsets are not the - // buffer's: not painted then. - if (f.layer.lines.len > 0) return null; - const tree = normal.fileTree(p, f) orelse return null; - const object = @field(modal.Normal.Object, @tagName(r)["goto_".len..]); - const at = lineStart(f, caret) + @as(usize, @intCast(@max(0, pane.body.cur_col))); - const span = @import("syntax.zig").objectNext(f.path, tree, f.content, object, forward, @min(at, f.content.len), .{ lineStart(f, lo), lineStart(f, hi + 1) }) orelse return null; - return lineOf(f, span.from); - }, + // With the Changes layer's lines in the buffer the tree's offsets + // are not the buffer's: not painted then. + .goto_function => return if (f.layer.lines.len > 0) null else treeTargets(p, pane, f, forward, lo, hi)[0], + .goto_comment => return if (f.layer.lines.len > 0) null else treeTargets(p, pane, f, forward, lo, hi)[1], + .goto_test => return if (f.layer.lines.len > 0) null else treeTargets(p, pane, f, forward, lo, hi)[2], else => return null, } } +/// The lines `]f`, `]c` and `]T` (or `[`'s) go to from the caret, in lines +/// `lo` to `hi` (the rows shown): one pass of the grammar's query over the +/// tree the motions read (made once a revision), kept on the pane while +/// its text, its caret and those lines stay (`Pane.targets`), so a frame +/// that paints them again asks nothing. +fn treeTargets(p: *Pardes, pane: *Pane, f: *panes.File.State, forward: bool, lo: usize, hi: usize) [3]?usize { + const at = lineStart(f, @intCast(@max(0, pane.body.cur_row))) + @as(usize, @intCast(@max(0, pane.body.cur_col))); + const key: panes.TargetsKey = .{ .revision = f.revision, .at = at, .lo = lo, .hi = hi, .forward = forward }; + if (pane.targets.key) |was| if (std.meta.eql(was, key)) return pane.targets.lines; + var lines: [3]?usize = @splat(null); + if (normal.fileTree(p, f)) |tree| { + var spans: [3]?@import("syntax.zig").Span = undefined; + @import("syntax.zig").objectNext(f.path, tree, f.content, &.{ .function, .comment, .@"test" }, forward, @min(at, f.content.len), .{ lineStart(f, lo), lineStart(f, hi + 1) }, &spans); + for (spans, &lines) |span, *line| line.* = if (span) |s| lineOf(f, s.from) else null; + } + pane.targets = .{ .key = key, .lines = lines }; + return lines; +} + fn blank(pane: *const Pane, line: usize) bool { return std.mem.trim(u8, File.sourceLine(pane, @intCast(line)), " \t\r").len == 0; } |
