diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-06 06:24:42 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-06 11:19:44 -0300 |
| commit | c1917b949b9580de8bf0977874a210f0266812da (patch) | |
| tree | 447dd2235ea00634f662cd3becf4bceb8a895f41 /src/Jump.zig | |
| parent | 76c55b5bce0f181b0b15b16596c900397dfef544 (diff) | |
| download | pardes-c1917b949b9580de8bf0977874a210f0266812da.tar.gz pardes-c1917b949b9580de8bf0977874a210f0266812da.zip | |
kinds #14, the core's PDF code gone: pdf.zig and pdf_view.zig leave and every pdf_enabled branch with them; look, Jump, Recent, dumps (one from before the addon opens as its pane), the watch, mouse, keys, the rail and the tag go through Kind for any kind's pane; test/pdf.zig's behaviours are T1 cases over 9P (addons_pdf.zig) and pane cases (a Shadow over a replica, a file changed under it), the harnesses load pdf.so by path
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/Jump.zig')
| -rw-r--r-- | src/Jump.zig | 77 |
1 files changed, 56 insertions, 21 deletions
diff --git a/src/Jump.zig b/src/Jump.zig index 0d82d104..10014e9e 100644 --- a/src/Jump.zig +++ b/src/Jump.zig @@ -41,10 +41,43 @@ pub const Loc = struct { col: u32, /// The file it is in (Wyhash of the path), 0 for a pane with none. path_hash: u64 = 0, - /// A PDF's place: `line` its page (one-based), `col` how far down it - /// (pdf_view.Place.at, a fraction of the page in 2^-32). - pdf: bool = false, + /// A kind's pane's place, its `where` (a PDF's `12:0.330000`), with + /// `line` its first number. + place: Kind.Buf(32) = .{}, }; +const Kind = @import("Kind.zig"); + +/// A kind's pane's place now, its `where`. +fn kindPlace(pane: *Pane) ?Kind.Buf(32) { + const slot = pane.addon orelse return null; + if (!slot.live) return null; + var buf: [32]u8 = undefined; + const w = Kind.placeOf(slot, &buf); + if (w.len == 0) return null; + var out: Kind.Buf(32) = .{}; + out.set(w); + return out; +} + +/// A place's first number: a kind's line (a PDF's page). +/// A kind's place `L:F S` as where it is (L + F, in lines) and its +/// window's height (S lines); null for one without both. +fn spanOf(text: []const u8) ?[2]f64 { + const sp = std.mem.lastIndexOfScalar(u8, text, ' ') orelse return null; + const colon = std.mem.indexOfScalar(u8, text[0..sp], ':') orelse return null; + const line = std.fmt.parseFloat(f64, text[0..colon]) catch return null; + const frac = std.fmt.parseFloat(f64, text[colon + 1 .. sp]) catch return null; + return .{ line + frac, std.fmt.parseFloat(f64, text[sp + 1 ..]) catch return null }; +} + +pub fn firstNumber(text: []const u8) u32 { + var n: u32 = 0; + for (text) |ch| { + if (ch < '0' or ch > '9') break; + n = n *| 10 +| (ch - '0'); + } + return n; +} /// A session for the side-button jump test: four panes of 100 lines in one /// column, A (pane 0) and B each on a file of its own, C on A's file, and O @@ -128,22 +161,22 @@ const JumpsTest = struct { } }; -/// The file a jump in `pane` is in: a text's, a PDF's. +/// The file a jump in `pane` is in: a text's, a kind's (a PDF's). fn jumpPath(pane: *const Pane) ?[]const u8 { if (Pardes.recentDot(pane)) |d| return d.path; - return pane.pdfPath(); + if (pane.addon) |k| if (k.path.len > 0) return k.path; + return null; } fn samePlace(p: *const Pardes, a: Loc, b: Loc) bool { if (a.pane != b.pane or a.serial != b.serial) return false; - // A PDF's places by where they stand on its strip, as a text's by - // lines: within a body of each other, one visit. - if (a.pdf and b.pdf) if (p.panes[b.pane]) |pane| { - const view = panes.Pdf.paneViewport(p, pane) orelse return a.line == b.line; - const ya = panes.Pdf.placeY(pane, .{ .page = a.line - 1, .at = a.col }) orelse return a.line == b.line; - const yb = panes.Pdf.placeY(pane, .{ .page = b.line - 1, .at = b.col }) orelse return a.line == b.line; - return @abs(ya - yb) <= @as(f64, @floatFromInt(view.pixel_h)); - }; + // A kind's places within a window of each other (`where`'s `L:F S`: + // the window S lines), else by their first numbers (a page or the + // next), one visit. + if (a.place.len > 0 and b.place.len > 0) { + if (spanOf(a.place.slice())) |x| if (spanOf(b.place.slice())) |y| return @abs(x[0] - y[0]) <= @max(x[1], y[1]); + return @max(a.line, b.line) - @min(a.line, b.line) <= 1; + } if (a.line == 0 or b.line == 0) return true; const body = @max(1, p.view().rects[b.pane].h -| BOX_H); return @max(a.line, b.line) - @min(a.line, b.line) <= body; @@ -191,14 +224,14 @@ pub fn trackJump(p: *Pardes) void { if (pane.query) |q| if (!q.frozen) return; const force = v.jumps.force; v.jumps.force = false; - const pdf_place = panes.Pdf.place(pane); + const place = kindPlace(pane); const now: Loc = .{ .pane = @intCast(v.active), .serial = pane.serial, - .line = if (pdf_place) |at| @intCast(at.page + 1) else if (pane.body.cur_pinned) @intCast(@max(0, pane.body.cur_row) + 1) else 0, - .col = if (pdf_place) |at| at.at else if (pane.body.cur_pinned) @intCast(@max(0, pane.body.cur_col) + 1) else 0, + .line = if (place) |at| firstNumber(at.slice()) else if (pane.body.cur_pinned) @intCast(@max(0, pane.body.cur_row) + 1) else 0, + .col = if (place != null) 0 else if (pane.body.cur_pinned) @intCast(@max(0, pane.body.cur_col) + 1) else 0, .path_hash = if (jumpPath(pane)) |path| std.hash.Wyhash.hash(0, path) else 0, - .pdf = pdf_place != null, + .place = place orelse .{}, }; if (!force and v.jumps.n > 0 and samePlace(p, v.jumps.list[v.jumps.cur], now)) { v.jumps.list[v.jumps.cur] = now; // same visit; the entry IS where you are @@ -289,11 +322,12 @@ pub fn jumpBy(p: *Pardes, delta: i32) void { } const e = found.?; const from = v.active; - look.reopenAt(p, from, e.path, .{ .line = @max(1, j.line), .col = if (j.pdf) 0 else @max(1, j.col) }); + look.reopenAt(p, from, e.path, .{ .line = @max(1, j.line), .col = if (j.place.len > 0) 0 else @max(1, j.col) }); const opened = p.panes[v.active] orelse return; const opened_path = jumpPath(opened) orelse return; if (!std.mem.eql(u8, opened_path, e.path)) return; // it did not open - if (j.pdf) panes.Pdf.landAt(p, opened, .{ .page = j.line -| 1, .at = j.col }); + var said: Kind.Buf(160) = .{}; + if (j.place.len > 0) _ = Kind.address(p, v.active, j.place.slice(), &said); // Every entry of that file is the reopened pane from here on, so // a step onto another of them moves in it rather than reopening. for (v.jumps.list[0..p.view().jumps.n]) |*k| if (k.serial == 0 and k.path_hash == j.path_hash) { @@ -308,9 +342,10 @@ pub fn jumpBy(p: *Pardes, delta: i32) void { if (p.panes[v.active]) |source| look.clearNavigationSelection(p, source); if (v.active != j.pane) look.clearNavigationSelection(p, pane); v.jumps.cur = next; - if (pane.pdfPath() != null) { + if (pane.addon != null) { look.focusPaneLine(p, j.pane, .{ .line = 0, .col = 0 }, .keep); - panes.Pdf.landAt(p, pane, .{ .page = j.line -| 1, .at = if (j.pdf) j.col else 0 }); + var said: Kind.Buf(160) = .{}; + if (j.place.len > 0) _ = Kind.address(p, j.pane, j.place.slice(), &said); return; } look.focusPaneLine(p, j.pane, .{ .line = j.line, .col = j.col }, .center); |
