diff options
Diffstat (limited to 'core/replica.zig')
| -rw-r--r-- | core/replica.zig | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/core/replica.zig b/core/replica.zig index 5ce8454e..fd691e04 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -5192,3 +5192,57 @@ test "a client's own Zerox and Del of a file pane are instant: what Recent keeps try std.testing.expectEqual(@as(u32, 0), r.stats.mispredicted); try std.testing.expect(a.core.recent.get(path) != null); } + +/// A kind whose state is plain and that takes no keys: normal mode has +/// them in its pane. +const Still = struct { + const pa = pardes.Kind.c; + fn open(_: [*c]const u8, _: [*c]const u8, _: u64) callconv(.c) ?*anyopaque { + return pardes.Kind.api.alloc.?(4); + } + fn paint(_: ?*anyopaque, _: [*c]const pa.pa_window, _: [*c]pa.pa_paint) callconv(.c) void {} + const words = [_]pa.pa_word{std.mem.zeroInit(pa.pa_word, .{ .name = "Still", .opens = 1, .doc = "a pane that takes no keys" })}; + const ops = std.mem.zeroInit(pardes.Kind.Ops, .{ + .head = std.mem.zeroInit(pa.pa_head, .{ .size = @sizeOf(pa.pa_head), .abi = pardes.Kind.abi, .name = "still".* ++ @as([11]u8, @splat(0)), .version = 1, .exts = "", .flags = pa.PA_PLAIN, .words = &words, .nwords = 1 }), + .open = open, + .paint = paint, + }); +}; + +test "a client's n in a kind's pane is a motion: it steps to the next place a result row holds at once, asking the disk nothing of words that might name files" { + const gpa = std.testing.allocator; + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + defer a.deinit(); + var cwd: [std.Io.Dir.max_path_bytes]u8 = undefined; + const dir = std.mem.span(@as([*:0]u8, @ptrCast(std.c.getcwd(&cwd, cwd.len) orelse return error.NoCwd))); + var words: [64]pardes.Kind.LoadedWord = undefined; + const still = pardes.Kind.loadedOf(&Still.ops, "/x/still.so", @splat(7), &words); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &still } }); + // The kind's pane, its +Search (a place a row, as a kind's `/` leaves + // it), and a scratch whose words name files in the session's directory + // (as a command's output would). + _ = try a.local(.{ .command = "Still" }); + const kid = a.core.view().active; + try pardes.panes.Output.fillResults(a.core, kid, dir, .search, "first", try a.core.gpa.dupe(u8, "build.zig:1:1 first\n"), null); + const rid = a.core.panes[kid].?.search_pane.?; + _ = try a.local(.{ .command = "New" }); + for ("ibuild.zig mise.toml") |ch| _ = try a.local(.{ .key = .{ .cp = ch, .text = &[1]u8{ch} } }); + _ = try a.local(.{ .key = .{ .cp = pardes.Key.escape } }); + // The walk last stood in the scratch, at its start: its words first. + const scratch = a.core.panes[a.core.view().active].?; + scratch.body.cur_row = 0; + scratch.body.cur_col = 0; + a.core.look_walk_owner = scratch.serial; + a.core.view().active = kid; + const r = try joinedFresh(a); + defer r.deinit(); + r.core().kinds.ops[r.core().kinds.byName("still").?] = &Still.ops; + const msg = try gpa.dupe(u8, try r.input(.{ .key = .{ .cp = 'n', .text = "n" } })); + defer gpa.free(msg); + try std.testing.expectEqual(@as(u32, 0), r.stats.stopped); + try std.testing.expectEqual(rid, r.core().view().active); + r.confirm(try a.take(msg)); + r.settle(); + try std.testing.expectEqual(@as(u32, 1), r.stats.fast); + try agrees(a, r); +} |
