diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-05 00:20:16 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-05 01:17:28 -0300 |
| commit | 3b31e0484bd06658f10cd9165b76cb1ca3b198bd (patch) | |
| tree | d12169502b6b3a5b38be989ca4f0afd9e78a7ebd /src/pdf_view.zig | |
| parent | 26649273cc253319fdd833923928aa883e3f884c (diff) | |
| download | pardes-3b31e0484bd06658f10cd9165b76cb1ca3b198bd.tar.gz pardes-3b31e0484bd06658f10cd9165b76cb1ca3b198bd.zip | |
modal, normal, pdf_view, Text, syntax, edit: one key layer: an Action is the role the key named and what it was given (a count, a literal, ] or [), not a second union of sixteen sub-enums the roles were mapped onto one if at a time; a context's roles are tried in their enum order, the pending prefix and m sub-key are roles too, the text's executor and the PDF's switch flat on the role, and pdf_view.applyNormal(core, pane, action) does what a page cannot (Last, the leader, the tag, a search) instead of handing a seven-value enum back; no key does anything new; Text.normal's walked shape changes (wire semantics); helix-keys.md says how the keys are read
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/pdf_view.zig')
| -rw-r--r-- | src/pdf_view.zig | 185 |
1 files changed, 47 insertions, 138 deletions
diff --git a/src/pdf_view.zig b/src/pdf_view.zig index 654284f4..7f9c7b55 100644 --- a/src/pdf_view.zig +++ b/src/pdf_view.zig @@ -11,6 +11,7 @@ const filesystem = @import("fs.zig"); const tracy = @import("tracy.zig"); const image = @import("image.zig"); const look = @import("look.zig"); +const tagline = @import("tagline.zig"); const File = panes.File; const Output = panes.Output; @@ -1223,19 +1224,6 @@ pub const PanAxis = enum { horizontal, vertical }; pub const PanResult = enum { moved, edge, unavailable }; pub const ScrollResult = struct { active_page: usize }; pub const CellPixels = struct { w: u16, h: u16 }; -pub const NormalHost = enum { - none, - last, - leader, - command_line, - search, - search_forward, - search_backward, -}; -pub const NormalResult = struct { - host: NormalHost = .none, - page_changed: bool = false, -}; const PlacedGeometry = struct { geometry: image.NativeGeometry, @@ -2394,20 +2382,17 @@ fn movePage( viewport: ?Viewport, cell_pixels: CellPixels, direction: i8, - kind: modal.Normal.Page, + half: bool, count: u32, ) bool { if (!native_images) { const pages: i64 = @intCast(@max(@as(u32, 1), count)); return stepPage(state, gpa, if (direction > 0) pages else -pages); } - const base: u32 = switch (kind) { - .half_down, .half_up => if (viewport) |view| - @max(@as(u32, 1), view.pixel_h / 2) - else - cell_pixels.h, - .down, .up => if (viewport) |view| view.pixel_h else cell_pixels.h, - }; + const base: u32 = if (viewport) |view| + (if (half) @max(@as(u32, 1), view.pixel_h / 2) else view.pixel_h) + else + cell_pixels.h; return scrollNormal( state, gpa, @@ -2416,128 +2401,52 @@ fn movePage( ); } -pub fn applyNormal( - state: *State, - gpa: std.mem.Allocator, - semantic: modal.Normal.Action, - native_images: bool, - cell_pixels: CellPixels, - viewport: ?Viewport, - geometry: ?image.NativeGeometry, -) NormalResult { - if (comptime !enabled) return .{}; - var result: NormalResult = .{}; - switch (semantic) { +/// A normal-mode command in a PDF pane: the page moves, or the session is +/// asked for what a page cannot do (Last, the leader, the tag, a search). +pub fn applyNormal(core: *pardes.Pardes, pane: *pardes.Pane, a: modal.Normal.Action) void { + if (comptime !enabled) return; + const state = if (pane.pdf) |*pv| pv else return; + const gpa = core.pdf_gpa; + const native = core.native_images; + const cells: CellPixels = .{ .w = core.cell_pixels.w, .h = core.cell_pixels.h }; + const viewport = paneViewport(core, pane); + const placed = if (native) paneGeometry(core, pane) else null; + const page_changed = switch (a.role) { // Esc drops a selection or a search the page shows, else goes back - // a pane (text-only, the page shows neither). - .escape => if (!state.cancelChrome(gpa) or !native_images) { - result.host = .last; - }, - .move => |move| switch (move.motion) { - .down => result.page_changed = moveRows( - state, - gpa, - native_images, - viewport, - cell_pixels, - 1, - move.count, - ), - .up => result.page_changed = moveRows( - state, - gpa, - native_images, - viewport, - cell_pixels, - -1, - move.count, - ), - .left => if (native_images) if (geometry) |placed| { - _ = panPixels(state, placed, .horizontal, -1, scaledStep(cell_pixels.w, move.count)); - }, - .right => if (native_images) if (geometry) |placed| { - _ = panPixels(state, placed, .horizontal, 1, scaledStep(cell_pixels.w, move.count)); - }, - else => {}, - }, - .goto => |go| switch (go.target) { - .file_start => result.page_changed = state.activatePage( - gpa, - if (go.explicit_count) go.count -| 1 else 0, - true, - ), - .last_line => result.page_changed = state.activatePage(gpa, state.page_count -| 1, true), - .line_start, .first_nonws => if (native_images) if (geometry) |placed| - setHorizontalEdge(state, placed, false), - .line_end => if (native_images) if (geometry) |placed| - setHorizontalEdge(state, placed, true), - .line_down => result.page_changed = moveRows( - state, - gpa, - native_images, - viewport, - cell_pixels, - 1, - go.count, - ), - .line_up => result.page_changed = moveRows( - state, - gpa, - native_images, - viewport, - cell_pixels, - -1, - go.count, - ), - else => {}, - }, - .line => |line| switch (line) { - .start, .first_nonws => if (native_images) if (geometry) |placed| - setHorizontalEdge(state, placed, false), - .end => if (native_images) if (geometry) |placed| - setHorizontalEdge(state, placed, true), + // a pane (text-only, the page shows neither); typed again by a + // macro, Esc is only the page's. + .escape => { + if ((!state.cancelChrome(gpa) or !native) and core.macro.replaying == 0) exec.runBuiltin(core, .Last, core.active, "", null); + return; }, - .goto_line => |go| { - if (go.explicit) - result.page_changed = state.activatePage(gpa, go.count -| 1, true); + .move_down, .goto_line_down => moveRows(state, gpa, native, viewport, cells, 1, a.count), + .move_up, .goto_line_up => moveRows(state, gpa, native, viewport, cells, -1, a.count), + .view_scroll_down => moveRows(state, gpa, native, viewport, cells, 1, 1), + .view_scroll_up => moveRows(state, gpa, native, viewport, cells, -1, 1), + .move_left, .move_right => { + if (placed) |g| _ = panPixels(state, g, .horizontal, if (a.role == .move_left) -1 else 1, scaledStep(cells.w, a.count)); + return; }, - .page => |page| result.page_changed = switch (page.kind) { - .half_down, .down => movePage( - state, - gpa, - native_images, - viewport, - cell_pixels, - 1, - page.kind, - page.count, - ), - .half_up, .up => movePage( - state, - gpa, - native_images, - viewport, - cell_pixels, - -1, - page.kind, - page.count, - ), + .goto_line_start, .goto_first_nonws, .line_start, .line_first_nonws, .goto_line_end, .line_end => { + if (placed) |g| setHorizontalEdge(state, g, a.role == .goto_line_end or a.role == .line_end); + return; }, - .view => |view| result.page_changed = switch (view) { - .scroll_down => moveRows(state, gpa, native_images, viewport, cell_pixels, 1, 1), - .scroll_up => moveRows(state, gpa, native_images, viewport, cell_pixels, -1, 1), - else => false, + .goto_file_start => state.activatePage(gpa, if (a.explicit) a.count -| 1 else 0, true), + .goto_line => a.explicit and state.activatePage(gpa, a.count -| 1, true), + .goto_last_line => state.activatePage(gpa, state.page_count -| 1, true), + .half_page_down, .page_down => movePage(state, gpa, native, viewport, cells, 1, a.role == .half_page_down, a.count), + .half_page_up, .page_up => movePage(state, gpa, native, viewport, cells, -1, a.role == .half_page_up, a.count), + .leader => { + core.leader_on = true; + core.leader_n = 0; + return; }, - .leader => result.host = .leader, - .command_line => result.host = .command_line, - .search => result.host = .search, - .search_step => |step| result.host = if (step.direction == .forward) - .search_forward - else - .search_backward, - else => {}, - } - return result; + .command_line => return tagline.enterTag(core, pane), + .search => return core.startPrompt(pane, &pane.body, .{ .search = config.search_marker }), + .search_next, .search_prev => return look.lookWalk(core, if (a.role == .search_next) 1 else -1), + else => false, + }; + if (page_changed) resetPageChrome(pane); } pub fn captureLayoutAnchor(state: *State) void { |
