diff options
Diffstat (limited to 'core/Trail.zig')
| -rw-r--r-- | core/Trail.zig | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/core/Trail.zig b/core/Trail.zig index 96d505ae..3003a7df 100644 --- a/core/Trail.zig +++ b/core/Trail.zig @@ -79,6 +79,25 @@ pub fn reading(p: *const Pardes, pane: *const Pane) bool { return p.settings.jumps == .walk and isFile(pane) and !pane.trail.held; } +/// An untouched pane (UX J1): a `+New` never typed into (no undo +/// history), its body empty, still so named, not kept, not folded, and no +/// 9P open holding it: a look or exec open answered with it (exec.leased), +/// or an open of one of its own files (a script's look or exec at it, an +/// event helper's event), so that a script's pane/new stays its own. It is +/// free space: the next pane made takes its place (layout.freeSpace), a +/// jump from it among them. +pub fn untouched(p: *const Pardes, pane: *const Pane) bool { + const f = pane.file orelse return false; + const o = f.output orelse return false; + if (o.from != .cmd or o.from.cmd != .New or f.pager) return false; + if (f.content.len != 0 or f.history.journal.steps.items.len != 0 or pane.trail.held or pane.collapsed) return false; + if (!std.mem.eql(u8, std.Io.Dir.path.basename(f.path), config.scratch_buffer) or @import("exec.zig").leased(p, pane.serial)) return false; + for (p.fs.opens[0..p.fs.opens_len]) |open| if (open.node != 0) if (pardes.ctlfs.Node.target(open.node)) |t| { + if (t == .pane and t.pane.serial == pane.serial) return false; + }; + return true; +} + /// The reading pane that is held pane `owner`'s reader, if it has one. pub fn readerOf(p: *const Pardes, owner: *const Pane) ?usize { for (p.panes, 0..) |slot, id| { @@ -89,12 +108,14 @@ pub fn readerOf(p: *const Pardes, owner: *const Pane) ?usize { return null; } -/// A new reader's trail: its owner, then where it opened. -pub fn reader(owner: u32, path: []const u8, at: Spot) Trail { +/// A new reader's trail: its owner, then where it opened. With no owner, +/// a jump's from an untouched pane, whose place it takes (UX J1): its +/// trail starts at the file. +pub fn reader(owner: ?u32, path: []const u8, at: Spot) Trail { var t: Trail = .{}; - push(&t, .{ .owner = owner }); + if (owner) |o| push(&t, .{ .owner = o }); if (placeOf(path, at.line, at.col)) |s| push(&t, s); - t.cur = t.n - 1; + t.cur = t.n -| 1; return t; } |
