diff options
Diffstat (limited to 'src/look.zig')
| -rw-r--r-- | src/look.zig | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/look.zig b/src/look.zig index 3cd1faa5..4d23582b 100644 --- a/src/look.zig +++ b/src/look.zig @@ -1413,9 +1413,13 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void { } const pane = p.panes[target] orelse return; const f = pane.file orelse { + if (comptime pdf_enabled) if (pane.pdf) |*pv| return lookPdfPage(p, id, target, pv, expr); if (by_serial and pane.isTerminal()) return lookTerminalAddress(p, id, target, expr); + // Named as the pane is, the bare `:addr` (path empty) included. + var serial_name: [32]u8 = undefined; + const subject = if (pane.image) |iv| iv.path else if (path.len > 0) path else std.fmt.bufPrint(&serial_name, config.pane_addr ++ "{d}", .{pane.serial}) catch "the pane"; var cut: [miss_path_cap + "…".len]u8 = undefined; - return missed(p, id, "{s} is no text to address", .{missText(path, &cut)}); + return missed(p, id, "{s} is no text to address", .{missText(subject, &cut)}); }; if (!by_serial and path.len > 0 and (f.output != null or !std.mem.endsWith(u8, f.path, std.fs.path.basename(path)))) return; var a: Addr = .{ .text = f.content, .lim = null, .expr = expr }; @@ -1433,6 +1437,20 @@ fn lookAddress(p: *Pardes, id: usize, path: []const u8, expr: []const u8) void { p.active = target; } +/// A PDF's address is its page: `:N` turns to page N, one past its last a +/// miss. It has no text to hold a byte offset (`#N`) or a pattern: any +/// other address is refused with what it takes. +fn lookPdfPage(p: *Pardes, id: usize, target: usize, pv: anytype, expr: []const u8) void { + var cut: [miss_path_cap + "…".len]u8 = undefined; + const page = std.fmt.parseInt(usize, std.mem.trim(u8, expr, " \t"), 10) catch 0; + if (page == 0) return missed(p, id, "{s}: a PDF has no text to address; its address is a page, :N", .{missText(pv.path, &cut)}); + if (page > pv.page_count) return missedPage(p, id, pv.path, page); + const pane = p.panes[target].?; + clearNavigationSelection(p, pane); + if (pv.focusLocation(p.pdf_gpa, page, 0)) panes.Pdf.resetPageChrome(pane); + p.active = target; +} + /// `@p<terminal>:<address>`: any address over the terminal's body as its /// logical lines read (the lines a +Search lists as `@p<serial>:<line>`), /// from its cursor; the match is selected there, as a +Search row's is. @@ -1599,6 +1617,9 @@ pub fn lookAt(p: *Pardes, id: usize, operand_raw: []const u8) void { // acme's `file:addr` and `:addr` (look.c:450-543): an address after // the colon, evaluated in that file from its dot (openfile, look.c:675). if (addressed(trimmed)) |ad| return lookAddress(p, id, ad.path, ad.expr); + // `:N` on a PDF is its page N, never a search for the text. + if (comptime pdf_enabled) if (pane.hasPdf() and trimmed.len > 1 and trimmed[0] == ':') + return lookAddress(p, id, "", trimmed[1..]); const pl = parsePathLine(trimmed); // `file:3:0`: columns count from 1, as addr's do, and a zero is refused // in addr's words rather than taken as no column. |
