summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/File.zig5
-rw-r--r--src/Query.zig18
-rw-r--r--src/builtins.zig18
-rw-r--r--src/ninep/ctl.zig9
-rw-r--r--test/fs.py13
5 files changed, 50 insertions, 13 deletions
diff --git a/src/File.zig b/src/File.zig
index f633cad0..24dc9318 100644
--- a/src/File.zig
+++ b/src/File.zig
@@ -244,7 +244,10 @@ pub fn dumpPane(
.collapsed = pane.collapsed,
.file = .{
.tree_context = file.tree_context,
- .location_rows = try dumpLocationRows(arena, file.location_rows),
+ // A query pane's rows are its own (line 1 the query, gutter
+ // numbers), not location rows Restore reads: it comes back as
+ // plain text.
+ .location_rows = if (pane.query != null) &.{} else try dumpLocationRows(arena, file.location_rows),
.path = file.path,
.content_b64 = if (from_disk) "" else try dump.encodeBytes(arena, file.content),
.dirty = dirty,
diff --git a/src/Query.zig b/src/Query.zig
index 6374ce42..a871b71e 100644
--- a/src/Query.zig
+++ b/src/Query.zig
@@ -1998,6 +1998,24 @@ test "a / query: keystroke by keystroke, the owner shows the set, rows from its
try std.testing.expectEqual(@as(i32, 2), pane.body.cur_row);
}
+test "a dump holding a query pane, live or frozen, restores, the pane as plain text" {
+ const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 });
+ defer p.deinit();
+ _ = try p.setTestFile("alpha one\nbeta\nalphabet\n");
+ typeKeys(p, "/alpha");
+ for (0..2) |_| {
+ const qid = queryPane(p).?;
+ try pardes.dump.dumpState(p);
+ const restored = try pardes.dump.initFromDump(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 }, p.dump_out.?);
+ defer restored.deinit();
+ const back = restored.panes[qid].?;
+ try std.testing.expect(back.query == null);
+ try std.testing.expectEqual(@as(usize, 0), back.file.?.location_rows.len);
+ try std.testing.expect(std.mem.startsWith(u8, back.file.?.content, "/alpha\n"));
+ p.update(.{ .key = .{ .cp = Key.enter } });
+ }
+}
+
test "a / query: Enter lands and freezes, the register filled, n and N step silently, a later / reuses the pane and Esc brings the frozen rows back" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true, .cols = 100, .rows = 40 });
defer p.deinit();
diff --git a/src/builtins.zig b/src/builtins.zig
index cda962de..d2f215d7 100644
--- a/src/builtins.zig
+++ b/src/builtins.zig
@@ -1720,8 +1720,9 @@ pub const Find = struct {
// (SPC f f) typed into; with a word (B2, a script) listed, the
// keyboard left where it was, a script told of a miss.
const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
+ const had = panes.Query.ofOwner(c.p, c.pane.serial) != null;
panes.Query.open(c.p, c.id, .find, pat, pat.len == 0);
- if (pat.len > 0) missed(c, e_search_miss_find);
+ if (pat.len > 0) missed(c, e_search_miss_find, had);
}
};
@@ -1733,19 +1734,22 @@ pub const Grep = struct {
pub const output: OutputTraits = .{ .name = config.search_buffer, .steps = true, .locations = true };
pub fn run(c: Ctx) void {
const pat = std.mem.trim(u8, c.arg orelse "", " \t\r\n");
+ const had = panes.Query.ofOwner(c.p, c.pane.serial) != null;
panes.Query.open(c.p, c.id, .grep, pat, pat.len == 0);
- if (pat.len > 0) missed(c, e_search_miss_grep);
+ if (pat.len > 0) missed(c, e_search_miss_grep, had);
}
};
/// A script's Find or Grep (a 9P write runs it to its end before it
-/// answers) that found nothing fails as one: the query pane stays, its
-/// count 0, and the write hears `not found`.
-fn missed(c: Ctx, text: []const u8) void {
+/// answers) that found nothing fails as one, opening nothing: a query pane
+/// it made goes as an Esc takes it, one it reused stays, its count 0; the
+/// write hears `not found`.
+fn missed(c: Ctx, text: []const u8, reused: bool) void {
if (!c.p.fs.serving) return;
const qid = panes.Query.ofOwner(c.p, c.pane.serial) orelse return;
- const q = c.p.panes[qid].?.query.?;
- if (q.total == 0) c.p.reportFailure(c.id, text);
+ if (c.p.panes[qid].?.query.?.total != 0) return;
+ if (!reused) panes.Query.cancel(c.p, qid);
+ c.p.reportFailure(c.id, text);
}
/// Search in a query pane under this pane, line 1 the argument (`Panes`,
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index 635e03a6..258ea1ee 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -3069,6 +3069,15 @@ test "a script's Grep and Find fill the pane's one query pane, a row a line unde
var after: usize = 0;
for (p.panes) |slot| after += @intFromBool(slot != null);
try testing.expectEqual(count, after);
+ // With no query pane under it, a miss leaves none: the one it made goes.
+ _ = wr(p, Node.of(found.serial, .ctl), "Del\n");
+ var closed: usize = 0;
+ for (p.panes) |slot| closed += @intFromBool(slot != null);
+ try testing.expectEqual(E.NOENT, wr(p, Node.of(serialOf(p), .exec), "Find zzqqnomatchzz\n").errno());
+ var left: usize = 0;
+ for (p.panes) |slot| left += @intFromBool(slot != null);
+ try testing.expectEqual(closed, left);
+ try testing.expect(panes.Query.ofOwner(p, serialOf(p)) == null);
}
test "Unmount of a name not mounted says no such mount, which a mount reads as ENOENT" {
diff --git a/test/fs.py b/test/fs.py
index 97af9e6b..841dd32a 100644
--- a/test/fs.py
+++ b/test/fs.py
@@ -715,10 +715,13 @@ def recent_survives_restart(binary):
with session(binary, root, 'recent2') as (client, _):
listed = client.read('/recent').decode()
assert f'closed {kept}\n' in listed, listed
- # Recent shows it, and a look at its row opens it again.
+ # Recent fills a query pane with it, its row relative to the
+ # pane's directory, and a look at the row opens it again.
client.write('/pane/1/exec', b'Recent\n')
rows = int(client.read('/pane/1/exec').split()[-1])
- row = next(r for r in client.read(f'/pane/{rows}/body').decode().splitlines() if r.startswith(f'{kept}:'))
+ body = client.read(f'/pane/{rows}/body').decode()
+ assert body.startswith('Recent '), body
+ row = next(r for r in body.splitlines() if r.startswith('kept.txt:'))
client.write(f'/pane/{rows}/look', (row.split(' ')[0] + '\n').encode())
assert f'open {kept}\n' in client.read('/recent').decode()
@@ -759,11 +762,11 @@ def workflow_canary(binary):
assert client.read(f'/pane/{a}/body') == b'alpha one\nshared word\n'
assert f'new {a} {root}/a.txt\n' in log() and f'new {b} {root}/b.txt\n' in log()
- # Grep and Find: a hit opens its +Search, rows and all; a miss
- # fails ENOENT, opening nothing.
+ # Grep and Find: a hit fills its query pane, line 1 the query and
+ # the lines under each file's name; a miss fails ENOENT.
grep = made_by(a, b'Grep shared\n')
rows = client.read(f'/pane/{grep}/body').decode()
- assert 'a.txt:2' in rows and 'b.txt:2' in rows, rows
+ assert rows == 'Grep shared\na.txt\n 2 shared word\nb.txt\n 2 shared word\n', rows
client.remove(f'/pane/{grep}')
execute_refused(client, a, 'Grep zzqqnomatch', 'Grep: text not found')
found = made_by(a, b'Find b.txt\n')