diff options
| -rw-r--r-- | core/Pick.zig | 7 | ||||
| -rw-r--r-- | core/fs.zig | 6 | ||||
| -rw-r--r-- | core/ninep/ctl.zig | 4 | ||||
| -rw-r--r-- | test/behaviour/other_files.zig | 16 |
4 files changed, 29 insertions, 4 deletions
diff --git a/core/Pick.zig b/core/Pick.zig index 3bab0970..e19866d3 100644 --- a/core/Pick.zig +++ b/core/Pick.zig @@ -149,10 +149,11 @@ pub fn deinit(pk: *Pick, gpa: std.mem.Allocator) void { /// Whether a search a builtin asks for from pane `id` is a picker in the /// tag (SPEC §14.3 phase 4): in a session whose jumps walk, from the -/// keyboard or a click, never a script's (a 9P write's: the query pane, -/// whose rows it reads back, and whose `not found` it hears). +/// keyboard or a click (kbdin's and mousein's too), never a script's word +/// (a 9P exec's: the query pane, whose rows it reads back, and whose `not +/// found` it hears). pub fn asked(p: *const Pardes) bool { - return p.settings.jumps == .walk and !p.fs.serving; + return p.settings.jumps == .walk and (!p.fs.serving or p.fs.typed); } /// Picker `id`, kept or live. diff --git a/core/fs.zig b/core/fs.zig index 6b43ba67..594c89cf 100644 --- a/core/fs.zig +++ b/core/fs.zig @@ -868,7 +868,7 @@ pub const Namespace = struct { .authority = .{ "socket_path", "tcp_address", "mounts", "node_name", "os_paths", "out", "listeners", "origin", "no_prompt", "session_write", "unlogged", "capturing", - "serving", "refused", "failure", "failure_len", "no_pane_slot", "no_pane_slot_len", + "serving", "typed", "refused", "failure", "failure_len", "no_pane_slot", "no_pane_slot_len", "said", "said_len", "said_at", "late_failure", "late_failure_len", "lsp_answer_at", "edit_started", "edit_hold", "edit_said", "lsp_result", "write_room", "write_waits", "log_full_hash", "pages", "closed_lines", "ran_at", "refilled", @@ -910,6 +910,10 @@ pub const Namespace = struct { /// A 9P request is being served (Pardes.serveFs): a prompt it opens is /// a question for the log (`ask`), answered with `answer`. serving: bool = false, + /// The request is keys or a mouse written to `kbdin` or `mousein`: + /// the user's own, so a builtin they reach routes as typed + /// (Pick.asked), though their write is served as any other. + typed: bool = false, refused: bool = false, failure: [256]u8 = undefined, failure_len: u16 = 0, diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig index 637999c2..2411b20f 100644 --- a/core/ninep/ctl.zig +++ b/core/ninep/ctl.zig @@ -890,6 +890,8 @@ const e_no_pane = "no such pane"; /// or Ctrl to the key after them. pub fn writeKbdin(p: *Pardes, req: Req) Reply { const view = std.unicode.Utf8View.init(req.data) catch return tree.failText(req.tag, E.INVAL, "invalid UTF-8"); + p.fs.typed = true; + defer p.fs.typed = false; var it = view.iterator(); var mods: pardes.Key = .{ .cp = 0 }; while (it.nextCodepointSlice()) |rune| { @@ -944,6 +946,8 @@ fn kbdKey(rune: []const u8) pardes.Key { /// changed since the last line is pressed or released there, in that order /// of buttons; a move with one held drags, with none moves. pub fn writeMousein(p: *Pardes, req: Req) Reply { + p.fs.typed = true; + defer p.fs.typed = false; var lines = std.mem.tokenizeScalar(u8, req.data, '\n'); while (lines.next()) |line| { var words = std.mem.tokenizeAny(u8, line, " \t\r"); diff --git a/test/behaviour/other_files.zig b/test/behaviour/other_files.zig index b19ffa0f..e6c104c3 100644 --- a/test/behaviour/other_files.zig +++ b/test/behaviour/other_files.zig @@ -22,6 +22,22 @@ test "other-files: kbdin types at the pane with the keyboard and mousein clicks, try std.testing.expectError(error.Refused, s.read("/kbdin")); } +test "other-files: kbdin's keys are the user's: SPC f f opens Find's picker in the pane's tag where jumps walk, not the +Search a script's Find opens" { + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "a\n" }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "b.txt", .data = "b\n" }); + var s = try Session.initFile(std.testing.allocator, "x\n"); + defer s.deinit(); + var buf: [4096]u8 = undefined; + _ = try s.lookFile(s.at("{s}/a.txt", .{buf[0..try tmp.dir.realPath(std.testing.io, &buf)]})); + try s.keys(" ff"); + try std.testing.expect(std.mem.indexOf(u8, try s.read("/index"), "+Search") == null); + // Its rows under the tag of the pane typed at, the cursor on the first. + _ = try s.where("▶ a.txt"); + _ = try s.where(" b.txt"); +} + test "other-files: kbdin's Kalt rune is Alt on the key after it alone, and an Alt key types nothing" { var s = try Session.initFile(std.testing.allocator, "x\n"); defer s.deinit(); |
