diff options
| author | Gabriel Schneider <[email protected]> | 2026-08-03 01:07:22 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-08-10 09:17:07 -0300 |
| commit | b50005359c9fa33beef9a2ea7496268a246b296e (patch) | |
| tree | fb5b5df938f130dc108bd35f57e510447b029fd8 /src/modal.zig | |
| parent | 6a43880a7ef6899f0d66c1b0a63a7e7b5610236a (diff) | |
| download | pardes-b50005359c9fa33beef9a2ea7496268a246b296e.tar.gz pardes-b50005359c9fa33beef9a2ea7496268a246b296e.zip | |
separate modal parsing and reuse actions for PDF navigation
Diffstat (limited to 'src/modal.zig')
| -rw-r--r-- | src/modal.zig | 44 |
1 files changed, 11 insertions, 33 deletions
diff --git a/src/modal.zig b/src/modal.zig index cdc49142..8e36d1ae 100644 --- a/src/modal.zig +++ b/src/modal.zig @@ -1279,13 +1279,10 @@ test "hx increment" { try std.testing.expectEqual(@as(?[]u8, null), try hxIncrement(a, "", 1)); } -// ---- file-pane modal step ---- -// One keypress on an editable FILE pane. This is the single source of truth for -// file-modal behavior: main.zig delegates file panes here, and the tutor-driven -// unit tests (below) exercise it directly. Pure (no vaxis/ghostty/term.zig) — -// only std + the modal primitives above. Returns the new content (caller frees -// the old), or null if the key only moved the cursor / was a no-op (caller keeps -// the old content, no realloc). +// ---- retired standalone file-pane modal prototype ---- +// This old pure-std model has no production or harness callers. It remains +// only as context for the primitive algorithms around it; normal_input.zig is +// the sole BODY-NORMAL recognizer and Pardes owns Action execution. pub const Key = union(enum) { ch: u21, // a printable codepoint (insert inserts its UTF-8 bytes) @@ -1535,9 +1532,11 @@ fn stepInsertFile(alloc: std.mem.Allocator, content: []const u8, st: *FileState, } } -// The full NORMAL-mode file step (motions + insert entry + select/edit). See -// handleNormal in main.zig for the terminal counterpart (which differs in its -// edit ops: terminals can't delete shell output, only pasted runs). +// RETIRED LEGACY REFERENCE INTERPRETER. Nothing in production or the test +// harness calls this mini-parser; BODY-NORMAL recognition lives exclusively +// in normal_input.zig and Pardes executes its semantic Actions for text/PDF. +// Keep this frozen only as old modal-algorithm context; do not add bindings or +// infer current behavior from it. pub fn stepFile(alloc: std.mem.Allocator, content: []const u8, st: *FileState, view: View, key: Key, yank: *?[]u8) !?[]u8 { const lines = try splitLines(alloc, content); defer alloc.free(lines); @@ -1550,11 +1549,7 @@ pub fn stepFile(alloc: std.mem.Allocator, content: []const u8, st: *FileState, v const p = st.pending; st.pending = 0; if (p == 'g') { - if (chEq(key, 'g')) cur = gotoFirst() - else if (chEq(key, 'e')) cur = gotoLast(lines) - else if (chEq(key, 'h')) cur = lineStart(cur) - else if (chEq(key, 'l')) cur = lineEnd(lines, cur) - else return null; // unknown continuation: consume, no-op + if (chEq(key, 'g')) cur = gotoFirst() else if (chEq(key, 'e')) cur = gotoLast(lines) else if (chEq(key, 'h')) cur = lineStart(cur) else if (chEq(key, 'l')) cur = lineEnd(lines, cur) else return null; // unknown continuation: consume, no-op st.cur = cur; st.msel_active = false; return null; @@ -1582,24 +1577,7 @@ pub fn stepFile(alloc: std.mem.Allocator, content: []const u8, st: *FileState, v // motions -> move cursor, collapse selection, keep visible var moved: ?Cursor = null; - if (chEq(key, 'h') or tagOf(key) == .left) moved = charLeft(cur) - else if (chEq(key, 'l') or tagOf(key) == .right) moved = charRight(lines, cur) - else if (chEq(key, 'j') or tagOf(key) == .down) moved = lineDown(lines, cur) - else if (chEq(key, 'k') or tagOf(key) == .up) moved = lineUp(lines, cur) - else if (chEq(key, 'w')) moved = nextWordStart(lines, cur, false) - else if (chEq(key, 'W')) moved = nextWordStart(lines, cur, true) - else if (chEq(key, 'b')) moved = prevWordStart(lines, cur, false) - else if (chEq(key, 'B')) moved = prevWordStart(lines, cur, true) - else if (chEq(key, 'e')) moved = nextWordEnd(lines, cur, false) - else if (chEq(key, 'E')) moved = nextWordEnd(lines, cur, true) - else if (chEq(key, '0') or tagOf(key) == .home) moved = lineStart(cur) - else if (chEq(key, '$') or tagOf(key) == .end) moved = lineEnd(lines, cur) - else if (chEq(key, '^')) moved = firstNonWsOf(lines, cur) - else if (chEq(key, 'G')) moved = gotoLast(lines) - else if (tagOf(key) == .half_down) moved = clampToChar(lines, pageDown(cur, @max(1, view.rows / 2))) - else if (tagOf(key) == .half_up) moved = clampToChar(lines, pageUp(cur, @max(1, view.rows / 2))) - else if (tagOf(key) == .page_down) moved = clampToChar(lines, pageDown(cur, view.rows)) - else if (tagOf(key) == .page_up) moved = clampToChar(lines, pageUp(cur, view.rows)); + if (chEq(key, 'h') or tagOf(key) == .left) moved = charLeft(cur) else if (chEq(key, 'l') or tagOf(key) == .right) moved = charRight(lines, cur) else if (chEq(key, 'j') or tagOf(key) == .down) moved = lineDown(lines, cur) else if (chEq(key, 'k') or tagOf(key) == .up) moved = lineUp(lines, cur) else if (chEq(key, 'w')) moved = nextWordStart(lines, cur, false) else if (chEq(key, 'W')) moved = nextWordStart(lines, cur, true) else if (chEq(key, 'b')) moved = prevWordStart(lines, cur, false) else if (chEq(key, 'B')) moved = prevWordStart(lines, cur, true) else if (chEq(key, 'e')) moved = nextWordEnd(lines, cur, false) else if (chEq(key, 'E')) moved = nextWordEnd(lines, cur, true) else if (chEq(key, '0') or tagOf(key) == .home) moved = lineStart(cur) else if (chEq(key, '$') or tagOf(key) == .end) moved = lineEnd(lines, cur) else if (chEq(key, '^')) moved = firstNonWsOf(lines, cur) else if (chEq(key, 'G')) moved = gotoLast(lines) else if (tagOf(key) == .half_down) moved = clampToChar(lines, pageDown(cur, @max(1, view.rows / 2))) else if (tagOf(key) == .half_up) moved = clampToChar(lines, pageUp(cur, @max(1, view.rows / 2))) else if (tagOf(key) == .page_down) moved = clampToChar(lines, pageDown(cur, view.rows)) else if (tagOf(key) == .page_up) moved = clampToChar(lines, pageUp(cur, view.rows)); if (moved) |m| { st.cur = m; st.msel_active = false; |
