summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 23:02:59 -0300
committerGabriel Schneider <[email protected]>2026-11-04 23:02:59 -0300
commitcdbb06a5de858a721bdbfa127ea839f791b0dc24 (patch)
tree8c629563136a581bf09625f321a13c55cb1194bd
parent40daa61865ae7bcc8d60e67e3cb930a382c6a2d6 (diff)
downloadpardes-cdbb06a5de858a721bdbfa127ea839f791b0dc24.tar.gz
pardes-cdbb06a5de858a721bdbfa127ea839f791b0dc24.zip
look: runSearch prints each row straight into its buffer, allocated once for both kinds of pane, and says its one note, cut at N lines, itself: the per-row allocPrint and copy, and the WalkNotes of which only rows_cut was ever set, go, as do its comments about Find and Grep, which no longer come here
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
-rw-r--r--src/look.zig42
1 files changed, 16 insertions, 26 deletions
diff --git a/src/look.zig b/src/look.zig
index 09a22266..18fca334 100644
--- a/src/look.zig
+++ b/src/look.zig
@@ -575,10 +575,9 @@ fn lookFirstHit(p: *Pardes, id: usize) void {
}
/// Fills the results buffer, and answers how many rows a text or PDF
-/// search found (0 for Find and Grep, which do not count). With
-/// `open_empty` false a text search that found nothing opens no buffer.
-/// A search of one pane's text (or its PDF) writes at most this many bytes
-/// of rows: past it, the rows stop and say where.
+/// search found. With `open_empty` false a text search that found nothing
+/// opens no buffer. A search of one pane's text (or its PDF) writes at
+/// most this many bytes of rows: past it, the rows stop and say where.
pub const search_text_output_bytes = 16 << 20;
pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, start: SearchStart, open_empty: bool) !usize {
@@ -588,19 +587,15 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, start: SearchStart,
const pat = std.mem.trimEnd(u8, pat_raw, "\r\n");
if (std.mem.trim(u8, pat, " \t").len == 0) return 0;
const arena = p.scratch.allocator();
- // where the pane lives: a file's directory, a shell's cwd — the walk
- // root, and the directory the results buffer is named in. From a
- // column's or the workspace's tag, the session's.
+ // where the pane lives: a file's directory, a shell's cwd — the
+ // directory the results buffer is named in. From a column's or the
+ // workspace's tag, the session's.
const dir = if (p.exec_header) p.sessionDir() else Pardes.paneDir(pane);
- // As much as the search can write and no more: a root's hits for each
- // root Grep walks, one for Find, `search_text_output_bytes` in a pane.
- var out: []u8 = &.{};
+ const out = try @import("memory.zig").unfilled(arena, search_text_output_bytes);
var out_len: usize = 0;
var nrows: usize = 0;
var anchor: ?usize = null;
- var notes: filesystem.WalkNotes = .{};
if (pane.hasPdf()) {
- out = try @import("memory.zig").unfilled(arena, search_text_output_bytes);
if (comptime pdf_enabled) {
const found = try panes.Pdf.searchRows(
&pane.pdf.?,
@@ -615,7 +610,6 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, start: SearchStart,
anchor = found.anchor;
}
} else {
- out = try @import("memory.zig").unfilled(arena, search_text_output_bytes);
const lines = try edit.paneCursorLines(p, &pane.body);
// a real file names itself; a terminal or an output buffer has no path
const has_path = if (pane.file) |f| f.output == null else false;
@@ -630,26 +624,22 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, start: SearchStart,
const cc: usize = @intCast(@max(0, pane.body.cur_col));
for (lines, 0..) |ln, i| {
const at = std.ascii.findIgnoreCase(ln, pat) orelse continue;
- const row = try std.fmt.allocPrint(arena, "{s}:{d}:{d}{c}{d} {s}\n", .{
+ const row = std.fmt.bufPrint(out[out_len..], "{s}:{d}:{d}{c}{d} {s}\n", .{
loc, i + 1, at + 1, config.range_sep, at + pat.len, std.mem.trimEnd(u8, ln, " \t"),
- });
- if (row.len > out.len - out_len) {
- notes.rows_cut = nrows;
+ }) catch {
+ // Past what it may write: the rows stop, and say where.
+ if (nrows > 0) {
+ const note = std.fmt.bufPrint(out[out_len..], "cut at {d} lines\n", .{nrows}) catch "";
+ out_len += note.len;
+ nrows += @intFromBool(note.len > 0);
+ }
break;
- }
+ };
if (start == .cursor and (i < cl or (i == cl and at <= cc))) anchor = nrows;
- @memcpy(out[out_len..][0..row.len], row);
out_len += row.len;
nrows += 1;
}
}
- // What the walk passed over -- a directory it might not open, a file
- // read in part, a cap it stopped at -- is said in lines under the hits,
- // so a search that found nothing where it did not look says so, never
- // just "not found".
- const noted = notes.write(out[out_len..]);
- out_len += noted;
- nrows += std.mem.count(u8, out[out_len - noted .. out_len], "\n");
// A word looked for that is nowhere opens nothing.
if (!open_empty and nrows == 0) return 0;
const content = try p.gpa.dupe(u8, out[0..out_len]);