summaryrefslogtreecommitdiff
path: root/core/Trail.zig
diff options
context:
space:
mode:
Diffstat (limited to 'core/Trail.zig')
-rw-r--r--core/Trail.zig42
1 files changed, 36 insertions, 6 deletions
diff --git a/core/Trail.zig b/core/Trail.zig
index 7166d810..b88215d9 100644
--- a/core/Trail.zig
+++ b/core/Trail.zig
@@ -162,6 +162,32 @@ pub fn go(p: *Pardes, id: usize, i: u8) !usize {
return show(p, id, s.place.path.slice(), .{ .line = s.place.line, .col = s.place.col });
}
+/// A list the pane's newest step came through (§6.2: a picker's Enter,
+/// Pick.zig): its word before the step's place.
+pub fn through(t: *Trail, s: Step) void {
+ if (t.cur >= t.n or t.steps[t.cur] != .place) return;
+ if (t.n == max_steps) {
+ const first: usize = @intFromBool(t.steps[0] == .owner);
+ if (t.cur <= first) return;
+ std.mem.copyForwards(Step, t.steps[first .. max_steps - 1], t.steps[first + 1 ..]);
+ t.n -= 1;
+ t.cur -= 1;
+ }
+ std.mem.copyBackwards(Step, t.steps[t.cur + 1 .. t.n + 1], t.steps[t.cur..t.n]);
+ t.steps[t.cur] = s;
+ t.n += 1;
+ t.cur += 1;
+}
+
+/// Reading pane `id`'s current step replaced by `path` at `at`, no step
+/// pushed (a list's `n`, §5.6); its slot after it, as `step`'s.
+pub fn replaceStep(p: *Pardes, id: usize, path: []const u8, at: Spot) !usize {
+ const to = placeOf(path, at.line, at.col) orelse return error.NameTooLong;
+ const t = &p.panes[id].?.trail;
+ if (t.cur < t.n) t.steps[t.cur] = to;
+ return show(p, id, path, at);
+}
+
/// Pane `id` showing `path` at `at`, the keyboard on it: its caret moved
/// in the file it shows, or a new pane on `path` in its place, its walk
/// with it. A line past the new file's end is a miss that changes nothing.
@@ -248,10 +274,11 @@ pub const Part = enum { back, forward };
fn wordOf(t: *const Trail, i: usize, buf: *[max_text + 16]u8) []const u8 {
const s = t.steps[i];
if (s != .owner and i < t.cur and t.cur - i > shown_steps) return "·";
- return switch (s) {
+ // The step's own bytes, not a copy's (a copy is gone at the return).
+ return switch (t.steps[i]) {
.owner => |serial| std.fmt.bufPrint(buf, "‹" ++ config.pane_addr ++ "{d}", .{serial}) catch unreachable, // a u32 fits
.place => |at| std.fmt.bufPrint(buf, "{s}:{d}", .{ std.Io.Dir.path.basename(at.path.slice()), at.line }) catch unreachable, // a basename and a u32 fit
- .list, .search, .recipe => |w| w.text.slice(),
+ .list, .search, .recipe => |*w| w.text.slice(),
};
}
@@ -302,8 +329,9 @@ pub fn stepAt(t: *const Trail, part: Part, off: usize) ?u8 {
}
/// Look on step `i` of pane `id`'s trail (§6.3): a place is gone back or
-/// forward to, the owner focused; a list, a search or a recipe is the
-/// pickers' and the prompts' to take (not yet: said).
+/// forward to, the owner focused, a list unrolled again as it was
+/// (Pick.reopen); a search or a recipe is the prompts' to take (not yet:
+/// said).
pub fn lookStep(p: *Pardes, id: usize, i: u8) void {
const pane = p.panes[id] orelse return;
switch (pane.trail.steps[i]) {
@@ -311,7 +339,8 @@ pub fn lookStep(p: *Pardes, id: usize, i: u8) void {
.owner => |serial| if (p.paneBySerial(serial)) |owner| {
p.view().active = owner;
} else p.reportFailure(id, "walk: its owner is closed"),
- .list, .search, .recipe => p.setMessage(.at(id), "walk: a list, a search or a recipe is not walked yet"),
+ .list => |w| pardes.Pick.reopen(p, id, w.index),
+ .search, .recipe => p.setMessage(.at(id), "walk: a search or a recipe is not walked yet"),
}
}
@@ -321,7 +350,8 @@ pub fn execStep(p: *Pardes, id: usize, i: u8) void {
const pane = p.panes[id] orelse return;
switch (pane.trail.steps[i]) {
.place, .owner => lookStep(p, id, i),
- .list, .search, .recipe => p.setMessage(.at(id), "walk: a list, a search or a recipe is not run again yet"),
+ .list => |w| pardes.Pick.rerun(p, id, w.index),
+ .search, .recipe => p.setMessage(.at(id), "walk: a search or a recipe is not run again yet"),
}
}