diff options
Diffstat (limited to 'core/Pick.zig')
| -rw-r--r-- | core/Pick.zig | 41 |
1 files changed, 19 insertions, 22 deletions
diff --git a/core/Pick.zig b/core/Pick.zig index 398354b5..5499809a 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -255,8 +255,7 @@ 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); - // Find and Grep from the work tree's root (W8), as other finders search. - pk.dir.set(if (source == .find or source == .grep) workTree(p, Pardes.paneDir(asker)) else Pardes.paneDir(asker)); + pk.dir.set(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); @@ -269,8 +268,7 @@ 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. Find and Grep search from it, their rows' paths -/// relative to it, wherever in the tree the asking pane is. +/// when none does. fn workTree(p: *Pardes, dir: []const u8) []const u8 { var d = dir; while (true) { @@ -284,9 +282,9 @@ fn workTree(p: *Pardes, dir: []const u8) []const u8 { } /// Where a Grep's query `q` searches and for what (SPEC §5.1): a leading -/// directory, the root's or absolute, then a blank, narrows it to that +/// directory, the picker's or absolute, then a blank, narrows it to that /// directory (`src/torque Macro`), the rest the pattern; else all of it -/// from the root. The directory joined in `buf`. +/// from the picker's. The directory joined in `buf`. fn grepScope(p: *Pardes, pk: *const Pick, q: []const u8, buf: *[4096]u8) struct { dir: []const u8, pat: []const u8 } { const root = pk.dir.slice(); const sp = std.mem.indexOfScalar(u8, q, ' ') orelse return .{ .dir = root, .pat = q }; @@ -565,7 +563,7 @@ fn allPanes(p: *const Pardes, pk: *const Pick, out: *[pardes.MAX_PANES]usize) [] pub fn take(p: *Pardes, target: u32, kind: Stream.Kind, rows: []const u8) bool { const pk = byId(p, target) orelse return false; // A Grep narrowed to a directory (grepScope): its rows' paths from the - // root, as an unnarrowed one's are. + // picker's directory, as an unnarrowed one's are. var buf: [4096]u8 = undefined; const searched = p.stream.dir.items; const under = if (kind == .grep and !std.mem.eql(u8, searched, pk.dir.slice())) std.fmt.bufPrint(&buf, "{s}/", .{relative(searched, pk.dir.slice())}) catch "" else ""; @@ -2218,9 +2216,6 @@ pub fn execWord(p: *Pardes, txt: []const u8) bool { } fn testFile(p: *Pardes, tmp: *std.testing.TmpDir, name: []const u8, text: []const u8) ![]u8 { - // The directory a work tree of its own, as a project is: Find and Grep - // search it, not the tree the test runs in. - tmp.dir.createDir(std.testing.io, ".git", .default_dir) catch |err| if (err != error.PathAlreadyExists) return err; try tmp.dir.writeFile(std.testing.io, .{ .sub_path = name, .data = text }); var base_buf: [std.Io.Dir.max_path_bytes]u8 = undefined; const dir = base_buf[0..try tmp.dir.realPath(std.testing.io, &base_buf)]; @@ -3742,14 +3737,14 @@ test "Symbols: every row is ordinary text: no header rows, the cursor steps onto try std.testing.expect(std.mem.indexOf(u8, kept.?, "\ncounts.zig:2 t Counts = struct\n") != null); } -test "Find and Grep search the work tree (W8): from a pane deep in a repo Find lists the files from its root and `sub/name` narrows it, a leading directory narrows Grep, and outside a repo they search the pane's directory" { +test "Find and Grep search from the asking pane's directory, as a command runs in its window's (acme; the user's ruling of 2026-11-26 taking W8's work-tree root back): from deep in a repository Find lists that directory alone; from its top `sub/name` narrows Find, and a leading directory, the pane's directory's, narrows Grep" { const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 30 }); defer p.deinit(); p.settings.jumps = .walk; p.stream.engine = .walk; var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); - for ([_][]const u8{ "src/deep", "sub", "other" }) |d| try tmp.dir.createDirPath(std.testing.io, d); + for ([_][]const u8{ ".git", "src/deep", "sub", "other" }) |d| try tmp.dir.createDirPath(std.testing.io, d); const deep = try testFile(p, &tmp, "src/deep/x.txt", "deep\n"); defer p.gpa.free(deep); for ([_][2][]const u8{ .{ "sub/name.txt", "needle one\n" }, .{ "other/name.txt", "needle two\n" } }) |f| p.gpa.free(try testFile(p, &tmp, f[0], f[1])); @@ -3762,9 +3757,18 @@ test "Find and Grep search the work tree (W8): from a pane deep in a repo Find l var frame = std.heap.ArenaAllocator.init(std.testing.allocator); defer frame.deinit(); const a = frame.allocator(); - // Find from src/deep: the root's files, by their paths from it. + // Find from src/deep: its own file alone, the repository's root not asked. open(p, asker, .find, "", "", ""); var pk = live(p).?; + try std.testing.expectEqualStrings(std.Io.Dir.path.dirname(deep).?, pk.dir.slice()); + settle(p); + try std.testing.expectEqual(@as(usize, 1), count(p, pk)); + p.update(.{ .key = .{ .cp = Key.escape } }); + // From the top: every file, `sub/name` narrowing them to one. + p.gpa.free(p.panes[asker].?.file.?.path); + p.panes[asker].?.file.?.path = try std.Io.Dir.path.join(p.gpa, &.{ root, "top.txt" }); + open(p, asker, .find, "", "", ""); + pk = live(p).?; try std.testing.expectEqualStrings(root, pk.dir.slice()); settle(p); try std.testing.expectEqual(@as(usize, 3), count(p, pk)); @@ -3773,8 +3777,8 @@ test "Find and Grep search the work tree (W8): from a pane deep in a repo Find l try std.testing.expectEqual(@as(usize, 1), count(p, pk)); try std.testing.expectEqualStrings("sub/name.txt", (try rowAt(p, pk, a, 0)).text); p.update(.{ .key = .{ .cp = Key.escape } }); - // Grep: the whole tree, then `sub needle` in sub/ alone, its row's - // path from the root, landing on the file there. + // Grep: the whole directory, then `sub needle` in sub/ alone, its + // row's path from the pane's directory, landing on the file there. open(p, asker, .grep, "", "", ""); pk = live(p).?; for ("needle") |c| p.update(.{ .key = .{ .cp = c, .text = &[_]u8{c} } }); @@ -3794,13 +3798,6 @@ test "Find and Grep search the work tree (W8): from a pane deep in a repo Find l try std.testing.expect(std.mem.startsWith(u8, row.text, "sub/name.txt:1 needle one")); try std.testing.expectEqualStrings(try std.Io.Dir.path.join(a, &.{ root, "sub/name.txt" }), row.target.place.path); p.update(.{ .key = .{ .cp = Key.escape } }); - // Outside a repo (`/`, the test text's directory, holds no .jj nor - // .git): the pane's directory, as before. - p.gpa.free(p.panes[asker].?.file.?.path); - p.panes[asker].?.file.?.path = try p.gpa.dupe(u8, "/held.txt"); - open(p, asker, .find, "", "", ""); - try std.testing.expectEqualStrings("/", live(p).?.dir.slice()); - p.update(.{ .key = .{ .cp = Key.escape } }); } test "a pane made for a picker has no rest: its tag is its owner's word alone, `‹@pN ›`, its body under it; the head hangs under the asking pane's tag (UX DESIGN M3, O1)" { |
