diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-24 19:37:15 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-24 19:38:18 -0300 |
| commit | 480f36b85299fa7407c20a2d6482dd093f842bf7 (patch) | |
| tree | 5d07c37c3e4eae82ec35ed100799d5810a8912aa /core/look.zig | |
| parent | f44d1b7d040acf674814be3cde336527833450e9 (diff) | |
| parent | 9f63733156853c925c31a948b50d4a3a7b77aa70 (diff) | |
| download | pardes-480f36b85299fa7407c20a2d6482dd093f842bf7.tar.gz pardes-480f36b85299fa7407c20a2d6482dd093f842bf7.zip | |
walk UI wave-2 base: line A items 1-4 (kquzozvs) merged with line B items 1-5 (mqmtqvtt)
Diffstat (limited to 'core/look.zig')
| -rw-r--r-- | core/look.zig | 134 |
1 files changed, 105 insertions, 29 deletions
diff --git a/core/look.zig b/core/look.zig index ee6debf9..cc3e750f 100644 --- a/core/look.zig +++ b/core/look.zig @@ -20,6 +20,7 @@ const Color = @import("surface.zig").Color; const Pane = panes.Pane; const MAX_PANES = pardes.MAX_PANES; const Layer = @import("Layer.zig"); +const Trail = @import("Trail.zig"); const TagHit = pardes.TagHit; const BOX_H = pardes.BOX_H; const TAG_TEXT_INSET = pardes.TAG_TEXT_INSET; @@ -1164,14 +1165,14 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void { // own clean start would collapse its dot (and the looker's) before the // address ever read it, so `f:/re/` again would find the same match. var realbuf: [4096]u8 = undefined; - const open: ?usize = if (path.len == 0) null else switch (resolveLookTarget(p, id, path, &realbuf)) { + const there: ?usize = if (path.len == 0) null else switch (resolveLookTarget(p, id, path, &realbuf)) { .pane => |t| if (t.id < MAX_PANES and p.panes[t.id] != null) t.id else null, else => null, }; // `@p<serial>:<address>`: that pane, or, not open, a miss said as one. const by_serial = std.mem.startsWith(u8, path, config.pane_addr); - if (by_serial and open == null) return missed(p, id, "no pane {s}", .{path[0..@min(path.len, 32)]}); - if (open) |o| target = o else if (path.len > 0) { + if (by_serial and there == null) return missed(p, id, "no pane {s}", .{path[0..@min(path.len, 32)]}); + if (there) |o| target = o else if (path.len > 0) { // A path that names nothing to open: the whole of what was written // is looked for, as `zzq:2` is, and a miss quotes it as written. if (!by_serial and resolveLookTarget(p, id, path, &realbuf) == .none) @@ -1189,7 +1190,7 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void { } const pane = p.panes[target] orelse return; const f = pane.file orelse { - if (pane.addon != null) return lookKind(p, id, target, expr, open == null and target != id); + if (pane.addon != null) return lookKind(p, id, target, expr, there == null and target != id); if ((by_serial or path.len == 0) and pane.isTerminal()) return lookTerminalAddress(p, id, target, expr); // Named as the pane is, the bare `:addr` (path empty) included. var serial_name: [32]u8 = undefined; @@ -1206,7 +1207,7 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void { const name = missText(f.path, &cut); // A look whose address fails opens nothing: a pane it opened to read // the address in goes again, the miss said from the pane it came from. - const opened_here = open == null and target != id; + const opened_here = there == null and target != id; const r = a.address(ninep_pane.fileDot(pane)) orelse { // A line past the end says so as `file:N` does, whichever way it // was written: `<file>:N has no line N`. @@ -1497,6 +1498,90 @@ fn settleLine(p: *Pardes, id: usize, path: []const u8, at: Spot, before: usize, } } +/// Where a jump lands: in the pane it walks (`replace`), or always in a +/// new pane under the asking one (`below`, as `Jumps new-pane` opens one). +pub const How = enum { replace, below }; + +/// What a jump did: nothing (refused, said), showed it in a pane there +/// was, or opened a pane for it, which a miss of its line closes again. +pub const Landed = union(enum) { none, shown, opened: usize }; + +/// A jump from pane `from` to `path` at `at`, the keyboard with it: a +/// Look at a place, a definition, an error's place, a list's row (pick-ui +/// SPEC ยง6.1). With `Jumps walk`: a held pane showing the file is focused +/// and nothing replaced; the asking pane showing it moves in it (a step +/// when it is reading); a reading pane steps in place, a held one steps +/// its reader (Trail.zig), made under it on its first jump. With +/// `Jumps new-pane` as before the walk: a pane showing the file focused, +/// else a new one. +pub fn open(p: *Pardes, from: usize, path: []const u8, at: Spot, how: How) Landed { + if (how == .replace and p.settings.jumps == .walk and path.len <= Trail.max_text and p.panes[from] != null) return walk(p, from, path, at); + if (how == .replace and focusPaneByPath(p, path, at)) return .shown; + return if (openNew(p, from, path, at, .doc)) |free| .{ .opened = free } else .none; +} + +fn walk(p: *Pardes, from: usize, path: []const u8, at: Spot) Landed { + const src = p.panes[from].?; + for (p.panes, 0..) |slot, k| { + const held = slot orelse continue; + if (k == from or !Trail.isFile(held) or Trail.reading(p, held) or !std.mem.eql(u8, held.file.?.path, path)) continue; + clearNavigationSelection(p, held); + focusPaneLine(p, k, at, .center); + return .shown; + } + const reads = Trail.reading(p, src); + if (!reads and if (src.file) |f| std.mem.eql(u8, f.path, path) else false) { + clearNavigationSelection(p, src); + focusPaneLine(p, from, at, .center); + return .shown; + } + const into = if (reads) from else Trail.readerOf(p, src) orelse { + const free = openNew(p, from, path, at, .reader) orelse return .none; + p.panes[free].?.trail = Trail.reader(src.serial, path, at); + return .{ .opened = free }; + }; + _ = Trail.step(p, into, path, at) catch |err| { + switch (err) { + error.LineMissing => missedLine(p, from, path, at.line), + error.NoPaneSlots => p.reportError(.at(from), "look", err), + else => lookOpenFailed(p, from, path, err), + } + return .none; + }; + return .shown; +} + +/// `path` opened at `at` in a new pane placed as `kind` places one from +/// `from`, its line half its body's rows down; null when it is not +/// (refused, said). +fn openNew(p: *Pardes, from: usize, path: []const u8, at: Spot, kind: layout.NewPane) ?usize { + const v = p.view(); + const free = p.freeSlot() orelse { + p.reportError(.at(from), "look", error.NoPaneSlots); + return null; + }; + const nt = panes.File.open(p, free, path, at.line) catch |err| { + lookOpenFailed(p, from, path, err); + return null; + }; + nt.body.cur_col = columnOn(nt, nt.body.cur_row, at.col); + const failures = p.fs.failures; + layout.placeNew(p, from, from, free, kind); + // Refused a place: that is the look's one failure, not a miss of its + // line too. + if (p.fs.failures != failures) return null; + layout.compute(p); + // Its line half the body's rows down, a wrapped line's rows above it + // counted. + const centered = panes.File.walkRows(p.settings.tab, nt, .{ .line = nt.file.?.scroll }, -@as(i64, @max(1, v.rects[free].h -| BOX_H) / 2)).to; + panes.File.setTop(nt, centered); + if (at.end_line != 0) { + selectSpan(p, nt, at); + panes.File.setTop(nt, centered); + } + return free; +} + fn focusPaneByPath(p: *Pardes, path: []const u8, at: Spot) bool { const target = openPaneTarget(p, path, at) orelse return false; clearNavigationSelection(p, p.panes[target.pane.id].?); @@ -1654,6 +1739,16 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { // A directory's pane, looked at again: read again. if (target.file) |f| if (f.listing != null) return panes.Dir.show(p, id, t.id); const before = v.active; + // A file's pane found by its path, not named `@pN`: a jump to + // the file, which walks (open). + if (p.settings.jumps == .walk and Trail.isFile(target) and !std.mem.startsWith(u8, pl.path, config.pane_addr)) { + switch (open(p, id, target.file.?.path, t.at, .replace)) { + .none => {}, + .shown => settleLine(p, id, trimmed, t.at, before, null), + .opened => |free| settleLine(p, id, trimmed, t.at, before, free), + } + return; + } clearNavigationSelection(p, target); focusPaneLine(p, t.id, t.at, .center); settleLine(p, id, trimmed, t.at, before, null); @@ -1673,34 +1768,15 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { .file => |target| { // An open pane on this path too short for the line: a miss that // touches nothing. - if (openPaneTarget(p, target.path, target.at)) |open| if (p.panes[open.pane.id].?.file) |*f| + if (openPaneTarget(p, target.path, target.at)) |there| if (p.panes[there.pane.id].?.file) |*f| if (target.at.line > panes.File.nlines(p.gpa, f)) return missedLine(p, id, target.path, target.at.line); - // focus an existing pane on this path (rescrolled), else open const before = v.active; - var opened: ?usize = null; - if (!focusPaneByPath(p, target.path, target.at)) { - const free = p.freeSlot() orelse return p.reportError(.at(id), "look", error.NoPaneSlots); - const nt = panes.File.open(p, free, target.path, target.at.line) catch |err| - return lookOpenFailed(p, id, target.path, err); - nt.body.cur_col = columnOn(nt, nt.body.cur_row, target.at.col); - const failures = p.fs.failures; - layout.placeNew(p, id, id, free, .doc); - // Refused a place: that is the look's one failure, not a - // miss of its line too. - if (p.fs.failures != failures) return; - layout.compute(p); - // Its line half the body's rows down, a wrapped line's - // rows above it counted. - const centered = panes.File.walkRows(p.settings.tab, nt, .{ .line = nt.file.?.scroll }, -@as(i64, @max(1, v.rects[free].h -| BOX_H) / 2)).to; - panes.File.setTop(nt, centered); - if (target.at.end_line != 0) { - selectSpan(p, nt, target.at); - panes.File.setTop(nt, centered); - } - opened = free; + switch (open(p, id, target.path, target.at, .replace)) { + .none => {}, + .shown => settleLine(p, id, target.path, target.at, before, null), + .opened => |free| settleLine(p, id, target.path, target.at, before, free), } - settleLine(p, id, target.path, target.at, before, opened); }, .kind => |target| { var place: [41]u8 = undefined; |
