From 2f187232227dde2755a7f2f2ce717f3e1f685f5c Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 29 Sep 2026 11:40:03 -0300 Subject: Recent keeps only files on disk, and its cap never drops an open one A renamed scratch never saved and a /virtual/ pane were recorded as recent files, and at 200 the oldest entry went even when that file was open. Opens, renames and closes now record a path only when it is a file on this host, and the cap drops the oldest closed entry. A name with a newline is not written to the kept list, where it would read back as two. Co-Authored-By: Claude Opus 5.5 --- src/pardes.zig | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'src/pardes.zig') diff --git a/src/pardes.zig b/src/pardes.zig index 76ec2176..2bf594c4 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -4700,6 +4700,21 @@ pub const Pardes = struct { } /// A file pane's path and dot, for the recent list (0 when none). + /// Whether `path` is one Recent keeps: a file on this host's disk, not + /// the served tree's (`/virtual/`) nor a name never saved. + pub fn recentKeeps(path: []const u8) bool { + const local = filesystem.localPath(path) orelse return false; + if (comptime !hosted) return true; + return exec.isFile(local); + } + + /// A file pane closing: its place noted in Recent, when Recent keeps it. + fn noteClosed(p: *Pardes, pane: *const Pane) void { + const d = recentDot(pane) orelse return; + if (p.recent.get(d.path) == null and !recentKeeps(d.path)) return; + p.recent.closedSel(p.recentGpa(), d.path, d.line, d.col, d.aline, d.acol); + } + fn recentDot(pane: *const Pane) ?struct { path: []const u8, line: u32, col: u32, aline: u32 = 0, acol: u32 = 0 } { const f = pane.file orelse return null; if (f.output != null) return null; @@ -4722,7 +4737,7 @@ pub const Pardes = struct { pub fn deinit(p: *Pardes) void { // Every file open now is closed with its dot, and the list kept. - for (p.panes) |slot| if (slot) |pane| if (recentDot(pane)) |d| p.recent.closedSel(p.recentGpa(), d.path, d.line, d.col, d.aline, d.acol); + for (p.panes) |slot| if (slot) |pane| p.noteClosed(pane); p.saveRecent(); p.recent.deinit(p.recentGpa()); look.cancelLookHover(p); @@ -4835,7 +4850,7 @@ pub const Pardes = struct { fn retirePane(p: *Pardes, pane: *Pane) void { // Closed, a file is remembered with its dot: Recent and a jump back // to it reopen it there. - if (recentDot(pane)) |d| p.recent.closedSel(p.recentGpa(), d.path, d.line, d.col, d.aline, d.acol); + p.noteClosed(pane); const watched = (if (pane.file) |f| f.output == null else false) or pane.hasPdf(); for (p.panes, 0..) |slot, id| if (slot == pane) { if (watched) p.emit(.{ .watch = .{ .pane = @intCast(id), .on = false } }); -- cgit v1.3