diff options
Diffstat (limited to 'src/pardes.zig')
| -rw-r--r-- | src/pardes.zig | 43 |
1 files changed, 34 insertions, 9 deletions
diff --git a/src/pardes.zig b/src/pardes.zig index 26b167d5..a23039ef 100644 --- a/src/pardes.zig +++ b/src/pardes.zig @@ -462,6 +462,9 @@ 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, }; test { @@ -4924,6 +4927,12 @@ pub const Pardes = struct { return null; } + /// The file a jump in `pane` is in: a text's, a PDF's. + fn jumpPath(pane: *const Pane) ?[]const u8 { + if (recentDot(pane)) |d| return d.path; + return pane.pdfPath(); + } + fn recentDot(pane: *const Pane) ?struct { path: []const u8, line: u32, col: u32, aline: u32 = 0, acol: u32 = 0 } { const f = pane.file orelse return null; if (f.output != null) return null; @@ -7355,6 +7364,14 @@ pub const Pardes = struct { 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)); + }; if (a.line == 0 or b.line == 0) return true; const body = @max(1, p.rects[b.pane].h -| BOX_H); return @max(a.line, b.line) - @min(a.line, b.line) <= body; @@ -7374,8 +7391,8 @@ pub const Pardes = struct { kept.serial = 0; // Open again in some pane (a look, Recent): the entry is that // pane's, and closed only while no pane has the file. - for (p.panes, 0..) |slot, id| if (slot) |pane| if (recentDot(pane)) |d| { - if (std.hash.Wyhash.hash(0, d.path) != j.path_hash) continue; + for (p.panes, 0..) |slot, id| if (slot) |pane| if (jumpPath(pane)) |path| { + if (std.hash.Wyhash.hash(0, path) != j.path_hash) continue; kept.pane = @intCast(id); kept.serial = pane.serial; break; @@ -7399,12 +7416,14 @@ pub const Pardes = struct { if (pane.query) |q| if (!q.frozen) return; const force = p.jump_force; p.jump_force = false; + const pdf_place = panes.Pdf.place(pane); const now: Loc = .{ .pane = @intCast(p.active), .serial = pane.serial, - .line = if (pane.pdfPage()) |page| @intCast(page + 1) else if (pane.body.cur_pinned) @intCast(@max(0, pane.body.cur_row) + 1) else 0, - .col = if (pane.pdfPage() != null) 0 else if (pane.body.cur_pinned) @intCast(@max(0, pane.body.cur_col) + 1) else 0, - .path_hash = if (recentDot(pane)) |d| std.hash.Wyhash.hash(0, d.path) else 0, + .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, + .path_hash = if (jumpPath(pane)) |path| std.hash.Wyhash.hash(0, path) else 0, + .pdf = pdf_place != null, }; if (!force and p.njumps > 0 and p.samePlace(p.jumps[p.jcur], now)) { p.jumps[p.jcur] = now; // same visit; the entry IS where you are @@ -7447,7 +7466,7 @@ pub const Pardes = struct { var next = if (older) p.jcur - 1 else p.jcur + 1; // A terminal or a scratch has no file to keep to: the step is global. if (p.settings.jump_scope == .file) if (p.panes[p.active]) |here| if (recentPlace(here)) |place| if (place.path.len > 0) { - const hash = if (recentDot(here)) |d| std.hash.Wyhash.hash(0, d.path) else 0; + const hash = if (jumpPath(here)) |path| std.hash.Wyhash.hash(0, path) else 0; // The nearest of this pane's own wins over a nearer one of this // file in another pane: the step does not move the keyboard. var pick: ?usize = null; @@ -7492,10 +7511,11 @@ pub const Pardes = struct { return p.jumpBy(delta); } const from = p.active; - look.reopenAt(p, from, e.path, .{ .line = @max(1, j.line), .col = @max(1, j.col) }); + look.reopenAt(p, from, e.path, .{ .line = @max(1, j.line), .col = if (j.pdf) 0 else @max(1, j.col) }); const opened = p.panes[p.active] orelse return; - const f = opened.file orelse return; - if (!std.mem.eql(u8, f.path, e.path)) return; // it did not open + 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 }); // 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 (p.jumps[0..p.njumps]) |*k| if (k.serial == 0 and k.path_hash == j.path_hash) { @@ -7510,6 +7530,11 @@ pub const Pardes = struct { if (p.panes[p.active]) |source| look.clearNavigationSelection(p, source); if (p.active != j.pane) look.clearNavigationSelection(p, pane); p.jcur = next; + if (pane.pdfPath() != 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 }); + return; + } look.focusPaneLine(p, j.pane, .{ .line = j.line, .col = j.col }, .center); } |
