diff options
| -rw-r--r-- | core/builtins.zig | 4 | ||||
| -rw-r--r-- | core/look.zig | 19 | ||||
| -rw-r--r-- | core/normal.zig | 5 | ||||
| -rw-r--r-- | core/replica.zig | 54 |
4 files changed, 71 insertions, 11 deletions
diff --git a/core/builtins.zig b/core/builtins.zig index b3e8d638..0d2e4c20 100644 --- a/core/builtins.zig +++ b/core/builtins.zig @@ -1641,7 +1641,7 @@ pub const Forward = struct { pub const LookNext = struct { pub const quiet = true; pub fn run(c: Ctx) void { - look.lookWalk(c.p, 1); + look.lookWalk(c.p, 1, true); } }; @@ -1649,7 +1649,7 @@ pub const LookNext = struct { pub const LookPrev = struct { pub const quiet = true; pub fn run(c: Ctx) void { - look.lookWalk(c.p, -1); + look.lookWalk(c.p, -1, true); } }; diff --git a/core/look.zig b/core/look.zig index 6ff1da66..7ca8914f 100644 --- a/core/look.zig +++ b/core/look.zig @@ -335,7 +335,7 @@ fn lookFirstHit(p: *Pardes, id: usize) void { const rp = p.panes[rid] orelse return; if ((rp.file orelse return).content.len == 0) return; p.view().active = rid; - lookWalk(p, 1); + lookWalk(p, 1, true); if (p.view().active != rid) return; // walked out of the list; leave it there const txt = edit.currentSelText(p, rp) orelse return; // spent, exactly as the look chord spends it (handleKey) @@ -546,7 +546,7 @@ pub fn wordSpan(p: ?*pardes.Pardes, word: []const u8, cwd: []const u8, realbuf: return .{ .start = 0, .end = word.len }; } -fn lookSpanIn(p: *Pardes, pane: *Pane, from: LookFrom, delta: i32, budget: *usize) ?Pane.LookSpot { +fn lookSpanIn(p: *Pardes, pane: *Pane, from: LookFrom, delta: i32, budget: *usize, disk: bool) ?Pane.LookSpot { const lines = edit.paneCursorLines(p.editor(), &pane.body) catch return null; const nrows: i32 = @intCast(lines.len); if (nrows == 0) return null; @@ -562,7 +562,8 @@ fn lookSpanIn(p: *Pardes, pane: *Pane, from: LookFrom, delta: i32, budget: *usiz if (pane.file) |*f| if (!panes.Output.isWalkRow(f, @intCast(r), ln)) continue; const on_start = r == start; switch (grain) { - .word => { + // Which words name a file is the disk's to say. + .word => if (disk) { var best: ?Pane.LookSpot = null; var i: usize = 0; while (i < ln.len) { @@ -577,7 +578,7 @@ fn lookSpanIn(p: *Pardes, pane: *Pane, from: LookFrom, delta: i32, budget: *usiz if (delta > 0) break; // first one forward; keep the last one back } if (best) |b| return b; - }, + } else return null, // one span per row, so there is nothing to keep and nothing to // scan past: the row either offers it or it does not .line, .whole => { @@ -593,7 +594,7 @@ fn lookSpanIn(p: *Pardes, pane: *Pane, from: LookFrom, delta: i32, budget: *usiz break :span @as(?Span, .{ .start = start_byte, .end = end }); } }; - break :span lineSpan(p, ln, dir, &realbuf); + break :span if (disk) lineSpan(p, ln, dir, &realbuf) else null; } orelse continue; const col0: i32 = @intCast(sp.start); if (lookPast(col0, from, on_start, delta)) @@ -610,7 +611,11 @@ fn commandPaneActive(p: *Pardes) bool { return pane.command != null and pane.file == null and p.view().header == null; } -pub fn lookWalk(p: *Pardes, delta: i32) void { +/// `disk`: a word or a row with no place of its own is look-able when it +/// names a file, which the disk says (LookNext, a Look's walk, may wait); +/// without, only the places the rows hold are (`n` in a kind's pane, a +/// motion: what it reads is the core's). +pub fn lookWalk(p: *Pardes, delta: i32, disk: bool) void { var buf: [MAX_PANES]usize = undefined; const order = lookWalkPanes(p, &buf); if (order.len == 0) return; @@ -628,7 +633,7 @@ pub fn lookWalk(p: *Pardes, delta: i32) void { // `+ 2 * len` only so the backward subtraction stays unsigned const idx = (if (delta > 0) at + k else at + 2 * order.len - k) % order.len; const pane = p.panes[order[idx]] orelse continue; - if (lookSpanIn(p, pane, from, delta, &budget)) |spot| + if (lookSpanIn(p, pane, from, delta, &budget, disk)) |spot| return landLookSpot(p, order[idx], pane, spot); if (budget == 0) return; // gave up mid-pane: stay put, stay reversible from = lookEdge(delta); diff --git a/core/normal.zig b/core/normal.zig index fb392647..66df9608 100644 --- a/core/normal.zig +++ b/core/normal.zig @@ -1277,9 +1277,10 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) edit.Error! return panes.startPrompt(p, pane, &pane.body, .{ .search = config.search_marker }), // In a file's text, n and N step its places while they answer for // the register (Places.answersN); else helix's search of the register. - // A kind's pane walks its `/`'s +Search (look.zig runSearch). + // A kind's pane walks its `/`'s +Search (look.zig runSearch): the + // places the rows hold, never the disk (a motion). .search_next, .search_prev => if (t.what == .body and pane.addon != null) - return look.lookWalk(p, if (a.role == .search_next) 1 else -1) + return look.lookWalk(p, if (a.role == .search_next) 1 else -1, false) else if (t.what == .body and pane.file != null and pane.places.answersN(p, pane)) return pane.places.step(p, pane, a.role == .search_next, a.count, t.select) else 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); +} |
