diff options
Diffstat (limited to 'core/Pick.zig')
| -rw-r--r-- | core/Pick.zig | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/core/Pick.zig b/core/Pick.zig index 5499809a..09ecb521 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -94,6 +94,9 @@ word: Kind.Buf(24) = .{}, keys: Kind.Buf(4) = .{}, /// Where Find and Grep look; what the rows' paths are relative to. dir: Kind.Buf(4096) = .{}, +/// Asked by Root (`SPC f F`, `SPC f G`): `dir` is the project's root above +/// the asking pane's, and its head and list word say `root`. +root: bool = false, /// The pane that asked, under whose tag it hangs, and the one its Enter /// lands in, whose body previews, by serial. owner: u32 = 0, @@ -255,7 +258,9 @@ pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: [] const pk = make(p, source) catch |err| return p.reportError(.at(from), "pick", err); pk.word.set(if (word.len > 0) word else words.get(source).word); pk.keys.set(words.get(source).keys); - pk.dir.set(Pardes.paneDir(asker)); + // Root's (`SPC f F`): from the project's root above the asking pane's. + pk.root = p.exec_root; + pk.dir.set(if (pk.root) workTree(p, Pardes.paneDir(asker)) else Pardes.paneDir(asker)); pk.rows = p.gpa.dupe(u8, rows) catch |err| return p.reportError(.at(from), "pick", err); pk.cap = p.view().rects[from].h * 2 / 5; hostIn(p, pk, from) catch |err| return p.reportError(.at(from), "pick", err); @@ -268,8 +273,8 @@ pub fn open(p: *Pardes, from: usize, source: Source, word: []const u8, query: [] /// The work tree `dir` is in: the nearest directory at or above it that /// holds a `.jj` or a `.git` (a git worktree's is a file); `dir` itself -/// when none does. -fn workTree(p: *Pardes, dir: []const u8) []const u8 { +/// when none does. Root's words run there (Pardes.execDir, `open`). +pub fn workTree(p: *Pardes, dir: []const u8) []const u8 { var d = dir; while (true) { var buf: [4096]u8 = undefined; @@ -838,6 +843,7 @@ pub fn head(p: *Pardes, arena: std.mem.Allocator, pane: *Pane) !?TagState.Head { // One Resume opened: where it stands among the kept (UX L'2). if (p.resume_at != 0) try text.print(arena, "Resume {d}/{d} ", .{ p.resume_at, nkept(p) }); try text.appendSlice(arena, pk.word.slice()); + if (pk.root) try text.appendSlice(arena, " root"); try text.append(arena, ' '); for (pk.refined[0..pk.nrefined]) |r| try text.print(arena, "{s} | ", .{r.query.slice()}); if (pk.spine == .edit) try text.print(arena, "{s} | Edit ", .{pk.query.slice()}); @@ -1784,6 +1790,7 @@ fn land(p: *Pardes, wanted: How) void { fn wordOf(p: *const Pardes, pk: *const Pick, buf: *Kind.Buf(Trail.max_text)) []const u8 { var w: std.Io.Writer = .fixed(&buf.bytes); w.writeAll(pk.word.slice()) catch {}; + if (pk.root) w.writeAll(" root") catch {}; for (pk.refined[0..pk.nrefined]) |r| w.print(" {s} |", .{r.query.slice()}) catch {}; if (pk.query.len > 0) w.print(" {s}", .{pk.query.slice()}) catch {}; const n = count(p, pk); @@ -1889,6 +1896,10 @@ pub fn rerun(p: *Pardes, id: usize, index: u32) void { const pk = byId(p, index) orelse return p.setMessage(.at(id), "walk: that list is gone: the last 8 are kept"); var query: Kind.Buf(256) = .{}; query.set(pk.query.slice()); + // One Root asked runs at the root again. + const was = p.exec_root; + p.exec_root = was or pk.root; + defer p.exec_root = was; open(p, id, pk.source, pk.word.slice(), query.slice(), pk.rows); } |
