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/Core.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/Core.zig')
| -rw-r--r-- | src/Core.zig | 96 |
1 files changed, 35 insertions, 61 deletions
diff --git a/src/Core.zig b/src/Core.zig index b1195ac2..cd7b4ec5 100644 --- a/src/Core.zig +++ b/src/Core.zig @@ -74,7 +74,6 @@ const modal = pardes.modal; const mouse = pardes.mouse; const newer_build_words = pardes.newer_build_words; const pager = pardes.pager; -const pdf_enabled = pardes.pdf_enabled; const platform = pardes.platform; const recent_files = @import("recent.zig"); const sel_slot = pardes.sel_slot; @@ -164,6 +163,11 @@ pub const View = struct { header_drag: bool = false, /// A middle or right sweep held over a column's or the workspace's tag. header_sweep: ?mouse.HeaderSweep = null, + /// The kind's pane a press went to, which has its drag and release + /// wherever the pointer goes; and the one the pointer is over, told + /// when it leaves (mouse.kindMouse). + kind_grab: ?u8 = null, + kind_hover: ?u8 = null, header_scroll: usize = 0, /// The focused header's first line on screen, which follows its caret /// when it has more lines than rows. @@ -180,7 +184,6 @@ image_gpa: std.mem.Allocator, /// Its kinds of pane (Kind.zig): the compiled-in ones, then what addons /// brought; the data both cores hold, the code only the authority. kinds: pardes.Kind.Registry = .{}, -pdf_gpa: std.mem.Allocator, tree_sitter_gpa: std.mem.Allocator, opts: Options, resize_count: usize = 0, @@ -271,7 +274,6 @@ look_hover_wait: ?look.LookHoverWait = null, /// resting there does not ask again every frame (look.noteLookHover). look_hover_refused: ?look.LookHoverWait = null, look_hover_preview: ?look.LookHoverPreview = null, -pdf_hover_preview: if (pdf_enabled) ?look.PdfWordPreview else void = if (pdf_enabled) null else {}, /// While a key is replayed across the ranges (normal.replaySels): which /// range this pass is, in document order, how many there are, and /// whether this is the first pass; outside a replay, the one range and @@ -472,7 +474,6 @@ pub fn create(gpa: std.mem.Allocator, opts: Options) !*Pardes { .gpa = gpa, .image_gpa = opts.image_allocator orelse gpa, .kinds = .started(opts.addons), - .pdf_gpa = opts.pdf_allocator orelse gpa, .tree_sitter_gpa = opts.tree_sitter_allocator orelse gpa, .opts = opts, .tty_toggle = opts.tty_toggle, @@ -520,10 +521,18 @@ fn initSession(gpa: std.mem.Allocator, opts: Options) !*Pardes { .document => { const path = opts.file.?; const opened = initial_doc: { - if (comptime pdf_enabled) if (look.isPdfPath(path)) - break :initial_doc pardes.panes.Pdf.openPane(p, 0, path, opts.file_line, .last); - if (p.kinds.forPath(path)) |kind| - break :initial_doc pardes.Kind.openFile(p, 0, kind, path); + if (p.kinds.forPath(path)) |kind| { + const made = pardes.Kind.openFile(p, 0, kind, path); + // `pardes book.pdf:12`'s place, the kind's to take. + if (made) |_| { + if (opts.file_line > 0) { + var said: pardes.Kind.Buf(160) = .{}; + var place: [16]u8 = undefined; + _ = pardes.Kind.address(p, 0, std.fmt.bufPrint(&place, "{d}", .{opts.file_line}) catch "", &said); + } + } else |_| {} + break :initial_doc made; + } break :initial_doc pardes.panes.File.open(p, 0, path, opts.file_line); }; if (opened) |_| {} else |err| { @@ -661,7 +670,7 @@ pub fn recentKeeps(path: []const u8) bool { return exec.kindOf(local) == .file; } -/// A file, PDF or image pane closing: its place noted in Recent, when +/// A file pane or a kind's (a PDF, a picture) closing: its place noted in Recent, when /// Recent keeps it. pub fn noteClosed(p: *Pardes, pane: *const Pane) void { const d = recentPlace(pane) orelse return; @@ -674,12 +683,16 @@ pub fn noteClosed(p: *Pardes, pane: *const Pane) void { pub const RecentPlace = struct { path: []const u8, line: u32, col: u32, aline: u32 = 0, acol: u32 = 0 }; -/// Where a pane is, as Recent keeps it: a file's dot, a PDF's page -/// (`:page:1`), a kind's pane's path alone (line 0). Null for any other. +/// Where a pane is, as Recent keeps it: a file's dot, a kind's pane's +/// path and the first number of its `where` (a PDF's page), 0 for none. +/// Null for any other. pub fn recentPlace(pane: *const Pane) ?RecentPlace { if (recentDot(pane)) |d| return .{ .path = d.path, .line = d.line, .col = d.col, .aline = d.aline, .acol = d.acol }; - if (pane.pdfPath()) |path| return .{ .path = path, .line = @intCast(pane.pdfPage().? + 1), .col = 1 }; - if (pane.addon) |k| if (k.path.len > 0) return .{ .path = k.path, .line = 0, .col = 0 }; + if (pane.addon) |k| if (k.path.len > 0) { + var buf: [32]u8 = undefined; + const line = Jump.firstNumber(pardes.Kind.placeOf(@constCast(k), &buf)); + return .{ .path = k.path, .line = line, .col = @intFromBool(line > 0) }; + }; return null; } @@ -1038,13 +1051,7 @@ pub fn rejectFont(p: *Pardes) void { fn applyWatchedFileChanged(p: *Pardes, id: u8, bytes: []const u8) bool { if (id >= MAX_PANES) return false; const pane = p.panes[id] orelse return false; - if (comptime pdf_enabled) if (pane.pdf != null) { - pardes.panes.Pdf.reloadWatched(p, pane) catch |err| { - p.reportError(id, "PDF reload", err); - return false; - }; - return true; - }; + if (pane.addon != null) return pardes.Kind.fileChanged(p, id, bytes); if (pane.file == null) return false; pardes.panes.File.changed(p, id, bytes); return if (p.panes[id]) |current| @@ -1536,7 +1543,6 @@ pub fn update(p: *Pardes, ev: Event) void { .mouse => |m| m.button == .none and m.kind == .motion, .output => |o| look.lookHoverPane(p) != o.pane, .file_changed => |changed| look.lookHoverPane(p) != changed.pane, - .pdf_scroll => |scroll| look.lookHoverPane(p) != scroll.pane, else => false, }; if (!hover_stays) { @@ -1566,31 +1572,11 @@ pub fn update(p: *Pardes, ev: Event) void { switch (ev) { .resize => |sz| { if (sz.row_metrics) |metrics| v.row_metrics = metrics; - if (comptime pdf_enabled) { - var before: [MAX_PANES]?pardes.panes.Pdf.Viewport = @splat(null); - for (p.panes, 0..) |slot, id| { - const pane = slot orelse continue; - if (pane.pdf != null) before[id] = pardes.panes.Pdf.paneViewport(p, pane); - } - v.screen_w = sz.cols; - v.screen_h = sz.rows; - v.cell_pixels.w = @max(1, sz.cell_pixels.w); - v.cell_pixels.h = @max(1, sz.cell_pixels.h); - layout.compute(p); - for (p.panes, 0..) |slot, id| { - const pane = slot orelse continue; - if (pane.pdf) |pv| { - if (!std.meta.eql(before[id], pardes.panes.Pdf.paneViewport(p, pane))) { - pardes.panes.Pdf.captureLayoutAnchor(pv); - pv.layout_valid = false; - pv.search_reveal_pending = pv.search_query.len > 0; - } - } - } - } else { - v.screen_w = sz.cols; - v.screen_h = sz.rows; - } + v.screen_w = sz.cols; + v.screen_h = sz.rows; + v.cell_pixels.w = @max(1, sz.cell_pixels.w); + v.cell_pixels.h = @max(1, sz.cell_pixels.h); + layout.compute(p); p.resize_count += 1; }, .output => |o| { @@ -1625,16 +1611,6 @@ pub fn update(p: *Pardes, ev: Event) void { @import("keys.zig").handleKey(p, key); }, .mouse => |m| mouse.handleMouse(p, m), - .pdf_scroll => |scroll| { - if (comptime pdf_enabled) { - if (scroll.pane < MAX_PANES) { - if (p.panes[scroll.pane]) |pane| { - if (pane.hasPdf() and v.frontend.native_images) - _ = pardes.panes.Pdf.scrollPane(p, pane, @floatCast(scroll.delta_pixels), scroll.glide); - } - } - } - }, .paste => |bytes| { p.typedInto(); edit.applyPaste(p, bytes); @@ -1651,6 +1627,7 @@ pub fn update(p: *Pardes, ev: Event) void { v.frontend = f; }, .pointer_leave => { + mouse.kindLeave(p); v.pointer_inside = false; v.pointer_body_hit = null; v.pointer_tag_hit = null; @@ -1955,8 +1932,6 @@ pub fn nextWake(p: *const Pardes) ?u64 { for (p.panes) |slot| if (slot) |pane| if (pane.places.busy(pane)) return next; const kinds = pardes.Kind.wake(p); if (kinds) |due| if (due <= next) return next; - // A PDF page being rendered on a lane lands on the frame after it is done. - if (comptime pdf_enabled) for (p.panes) |slot| if (slot) |pane| if (pane.pdf) |st| if (pardes.panes.Pdf.rendering(st)) return next; // A markdown text's tables still being read from the top (Tables.zig). for (p.panes) |slot| if (slot) |pane| if (pane.file) |f| if (f.tables.busy()) return next; if (pardes.panes.Query.busy(p)) return next; @@ -2193,7 +2168,6 @@ pub const Options = struct { image_allocator: ?std.mem.Allocator = null, /// What the host's scan of the addon directories found (Addon.scan). addons: []const pardes.Kind.Loaded = &.{}, - pdf_allocator: ?std.mem.Allocator = null, tree_sitter_allocator: ?std.mem.Allocator = null, /// Where each frame's Surface text is built. Hosts pass a purpose-built /// stack-fallback arena; null means the general allocator. @@ -2204,7 +2178,7 @@ pub const Options = struct { pub const Haptic = enum { none, exec, look }; -/// Zero-sized off macOS, the way PdfSlot is off -Dmupdf: no other shell reads +/// Zero-sized off macOS: no other shell reads /// the field, so no other shell carries it. const HapticSlot = if (platform == .macos) Haptic else void; @@ -2241,7 +2215,7 @@ const FakeTtyQuery = struct { }; fn bootAndTearDown(gpa: std.mem.Allocator) !void { - const p = try Pardes.init(gpa, .{ .cols = 56, .rows = 14, .tty_only = true, .frame_allocator = gpa, .image_allocator = gpa, .pdf_allocator = gpa, .tree_sitter_allocator = gpa }); + const p = try Pardes.init(gpa, .{ .cols = 56, .rows = 14, .tty_only = true, .frame_allocator = gpa, .image_allocator = gpa, .tree_sitter_allocator = gpa }); p.deinit(); } |
