summaryrefslogtreecommitdiff
path: root/src/look.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/look.zig')
-rw-r--r--src/look.zig83
1 files changed, 12 insertions, 71 deletions
diff --git a/src/look.zig b/src/look.zig
index eed3dbd9..cd8df4fc 100644
--- a/src/look.zig
+++ b/src/look.zig
@@ -532,7 +532,6 @@ pub fn cursorWordSel(p: *Pardes, pane: *Pane) Pane.Sel {
return .{ .state = .done, .c0 = vcol, .c1 = vcol, .r0 = vrow, .r1 = vrow };
}
-const Search = enum { text, find, grep };
const SearchStart = enum { top, cursor };
@@ -550,20 +549,13 @@ pub fn submitSearch(p: *Pardes, id: usize) void {
const slash = std.mem.indexOfScalar(u8, armed, '/') orelse return;
if (std.mem.startsWith(u8, armed, config.rename_marker)) return p.lspRequest(id, .rename, armed[slash + 1 ..]);
if (std.mem.startsWith(u8, armed, config.symbol_marker)) return p.lspRequest(id, .workspace_symbols, armed[slash + 1 ..]);
- const kind: Search = if (std.mem.startsWith(u8, armed, config.find_marker))
- .find
- else if (std.mem.startsWith(u8, armed, config.grep_marker))
- .grep
- else
- .text;
- _ = runSearch(p, id, armed[slash + 1 ..], kind, .top, true) catch |err| return p.reportError(id, "search", err);
- if (kind == .text) {
- var pattern: std.ArrayList(u8) = .empty;
- normal.appendSearchLiteral(&pattern, p.scratch.allocator(), armed[slash + 1 ..]) catch return;
- p.registers.put(p.gpa, '/', pattern.items, 0, 1, true);
- p.registers.last_search = '/';
- lookFirstHit(p, id);
- }
+ // A PDF's `/` and a terminal's: a text's is its query pane (Query.zig).
+ _ = runSearch(p, id, armed[slash + 1 ..], .top, true) catch |err| return p.reportError(id, "search", err);
+ var pattern: std.ArrayList(u8) = .empty;
+ normal.appendSearchLiteral(&pattern, p.scratch.allocator(), armed[slash + 1 ..]) catch return;
+ p.registers.put(p.gpa, '/', pattern.items, 0, 1, true);
+ p.registers.last_search = '/';
+ lookFirstHit(p, id);
}
fn lookFirstHit(p: *Pardes, id: usize) void {
@@ -589,7 +581,7 @@ fn lookFirstHit(p: *Pardes, id: usize) void {
/// 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, kind: Search, start: SearchStart, open_empty: bool) !usize {
+pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, start: SearchStart, open_empty: bool) !usize {
const pane = p.panes[id] orelse return 0;
// Blanks at either end are the pattern's (a look of an indented line);
// a builtin's argument comes trimmed already.
@@ -607,49 +599,7 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, kind: Search, start
var nrows: usize = 0;
var anchor: ?usize = null;
var notes: filesystem.WalkNotes = .{};
- if (kind == .grep) {
- var roots: [MAX_PANES][]const u8 = undefined;
- var nroots: usize = 0;
- for (p.panes) |slot| {
- const pp = slot orelse continue;
- // A pane of the served tree (/virtual/, /n/<peer>/) has no
- // directory on this host to walk, and one that named `/` would
- // swallow every other root: passed over.
- const d = filesystem.localPath(Pardes.paneDir(pp)) orelse continue;
- if (filesystem.isVirtual(if (pp.file) |f| f.path else d)) continue;
- var covered = false;
- var k: usize = 0;
- while (k < nroots) {
- if (pathUnder(d, roots[k])) {
- covered = true;
- break;
- }
- if (pathUnder(roots[k], d)) { // this one swallows a root already kept
- nroots -= 1;
- roots[k] = roots[nroots];
- continue;
- }
- k += 1;
- }
- if (covered) continue;
- roots[nroots] = d;
- nroots += 1;
- }
- out = try @import("memory.zig").unfilled(arena, @max(1, nroots) * filesystem.search_root_output_bytes);
- // A pane's directory that is not there (a scratch named into one
- // not made yet, a peer's) has nothing to grep: passed over, not the
- // search's failure.
- for (roots[0..nroots]) |r|
- out_len += filesystem.grep(arena, p.gpa, r, dir, pat, out[out_len..], &notes) catch |err| switch (err) {
- error.FileNotFound, error.NotDir, error.AccessDenied => continue,
- else => return err,
- };
- nrows = std.mem.count(u8, out[0..out_len], "\n");
- } else if (kind == .find) {
- out = try @import("memory.zig").unfilled(arena, filesystem.search_root_output_bytes);
- out_len = try filesystem.find(arena, dir, pat, out, &notes);
- nrows = std.mem.count(u8, out[0..out_len], "\n");
- } else if (pane.hasPdf()) {
+ if (pane.hasPdf()) {
out = try @import("memory.zig").unfilled(arena, search_text_output_bytes);
if (comptime pdf_enabled) {
const found = try panes.Pdf.searchRows(
@@ -700,19 +650,10 @@ pub fn runSearch(p: *Pardes, id: usize, pat_raw: []const u8, kind: Search, start
const noted = notes.write(out[out_len..]);
out_len += noted;
nrows += std.mem.count(u8, out[out_len - noted .. out_len], "\n");
- // A Find or Grep that finds nothing leaves its directory's +Search as
- // it was: the failure says why, and the last search's rows are still
- // that search's (its tag names it).
+ // 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]);
- // the buffer records WHICH search filled it, pattern and all: Find and
- // Grep are builtins (words you can execute), the bare `/` is a key
- const from: panes.Output.Origin = switch (kind) {
- .text => .search,
- .find => .{ .cmd = .Find },
- .grep => .{ .cmd = .Grep },
- };
- try panes.Output.fillResults(p, id, dir, from, pat, content, anchor);
+ try panes.Output.fillResults(p, id, dir, .search, pat, content, anchor);
return nrows;
}
@@ -1466,7 +1407,7 @@ fn lookUnresolved(p: *Pardes, id: usize, pane: *Pane, trimmed: []const u8, text:
if (p.settings.look_word == .search and pane.file != null) return lookWord(p, id, pane, text);
p.word_look = true;
defer p.word_look = false;
- const rows = runSearch(p, id, text, .text, .cursor, false) catch |err| {
+ const rows = runSearch(p, id, text, .cursor, false) catch |err| {
p.reportError(id, "search", err);
return;
};