summaryrefslogtreecommitdiff
path: root/src/normal.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-06 02:56:53 -0300
committerGabriel Schneider <[email protected]>2026-11-06 04:13:33 -0300
commitd1d5d3cfb18841604bba2057eeb3598f729b4475 (patch)
tree298c29ab8767852bf74eb86ad4d15acc4348f109 /src/normal.zig
parent33037ece5af9ae1c7048819bbbae3fc5e6fc4ade (diff)
downloadpardes-d1d5d3cfb18841604bba2057eeb3598f729b4475.tar.gz
pardes-d1d5d3cfb18841604bba2057eeb3598f729b4475.zip
client #1, the views indexed: a view's share of the session is Pardes.View (the ~42 fields views.fields named: size, cell metrics, columns, rects, focus, jumps, pointer, gestures, prefixes, frontend), one of Pardes.views[4] (null when closed), the live one views[live] through Pardes.view() (index field `view` renamed `live`); going into another view is the index plus the panes' shares, which stay swapped (park and unpark now move only Pane.pv); views.zig loses fields, Part over Pardes, Parked, kept, emptied and the session half of every copy, and a pane closing leaves every view's layout at once (views.gone, at the two places a slot is freed) instead of the serials each parked view kept; drawOne and within put the drawn view's own share back whole; the views are in the digest now (tape's per-field parts name views[k].field), so a fresh view's col_x/col_w default to zeros, not undefined; the dump keeps every open view in the core and the panes' shares of the others under `shares`; an image from before (live view as the core's own fields, the rest under `views`) loads them into views[] once; the ~2,400 references rewritten mechanically from the compiler's errors (p.active is p.view().active, `const v = p.view()` hoisted in 823 places), Kind.zig (4 lines) and addon_test.zig (3) among them, macos.zig by pattern (not compiled here); tape's watched host writes read the live view's frontend and active; perf.zig's accessor lines change its harness hash, the debug baselines re-keyed to it (their numbers the base's); no golden changes; gates: core-test 956/956 both, unit-test 1487/1488 tui and 1530/1531 gui, behaviour-test 248/248 both, pane-test 171/172, snap all 105 ok, process-test 0 of 37 failed tui, replicas ok
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'src/normal.zig')
-rw-r--r--src/normal.zig56
1 files changed, 29 insertions, 27 deletions
diff --git a/src/normal.zig b/src/normal.zig
index 96c61fba..d5ce5f4a 100644
--- a/src/normal.zig
+++ b/src/normal.zig
@@ -149,10 +149,11 @@ pub fn applySelRegex(p: *Pardes, pane: *Pane, t: *Text, pat: []const u8, mode: m
/// Search only the primary range, as Helix does. Select mode adds a new
/// match and makes it primary; normal mode replaces only the primary.
fn searchStep(p: *Pardes, t: *Text, text: []const u8, forward: bool, count: u32) void {
- const name = if (p.register != 0) p.register else p.registers.last_search;
+ const v = p.view();
+ const name = if (v.register != 0) v.register else p.registers.last_search;
const pat = p.registers.value(name, 0) orelse return;
var re = SearchRegex.compile(p.scratch.allocator(), pat) catch {
- p.setMessage(p.active, "invalid search pattern");
+ p.setMessage(v.active, "invalid search pattern");
return;
};
var hay = text;
@@ -175,7 +176,7 @@ fn searchStep(p: *Pardes, t: *Text, text: []const u8, forward: bool, count: u32)
wrapped = true;
break :blk lastMatch(&re, hay, from, hay.len);
}) orelse {
- p.setMessage(p.active, "no more matches");
+ p.setMessage(v.active, "no more matches");
return;
};
if (found.end == 0) return;
@@ -190,7 +191,7 @@ fn searchStep(p: *Pardes, t: *Text, text: []const u8, forward: bool, count: u32)
ranges[got.pri] = next;
t.setRanges(text, ranges[0..got.n], &.{}, got.pri, true);
}
- if (wrapped) p.setMessage(p.active, "wrapped around document");
+ if (wrapped) p.setMessage(v.active, "wrapped around document");
}
t.show();
}
@@ -220,7 +221,7 @@ pub fn searchSelection(p: *Pardes, t: *Text, text: []const u8, boundary: bool) v
appendSearchLiteral(&pattern, arena, text[from..to]) catch return;
if (boundary and to < text.len and modal.searchWordBefore(text, to) and !modal.searchWordAt(text, to)) pattern.appendSlice(arena, "\\b") catch return;
}
- const name = if (p.register != 0) p.register else '/';
+ const name = if (p.view().register != 0) p.view().register else '/';
p.registers.put(p.gpa, name, pattern.items, 0, 1, true);
p.registers.last_search = name;
}
@@ -485,7 +486,7 @@ const Replay = union(enum) {
};
pub fn replaySels(p: *Pardes, t: *Text, what: Replay) void {
- const id = p.active;
+ const id = p.view().active;
// a header belongs to no pane and cannot go away under the replay
const owner = t.pane();
const serial = if (owner) |pane| pane.serial else 0;
@@ -600,17 +601,18 @@ pub fn handleNormal(p: *Pardes, t: *Text, key: Key) void {
.action => |value| value,
};
t.normal.register = 0;
- p.register = named;
- defer p.register = 0;
+ p.view().register = named;
+ defer p.view().register = 0;
if (t.nsel == 0 or action.once())
return executeNormalAction(p, t, action);
replaySels(p, t, .{ .normal = action });
}
fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void {
+ const v = p.view();
// What reaches past the text -- a builtin, a search, a language query --
// acts for the pane the text belongs to; a header's is the active one.
- const pane = t.pane() orelse p.panes[p.active] orelse return;
+ const pane = t.pane() orelse p.panes[v.active] orelse return;
const raw_selection = t.what == .body and pane.rawPointerText(pane.sel[sel_slot]) != null;
const before = .{ t.cur_row, t.cur_col, t.vsel, t.select, t.nsel, t.mode };
defer if (raw_selection and !std.meta.eql(before, .{ t.cur_row, t.cur_col, t.vsel, t.select, t.nsel, t.mode })) {
@@ -629,7 +631,7 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void {
// typed again by a macro, Esc is only helix's
if (p.macro.replaying > 0) return;
tagline.exitHeader(p); // out of a header too, as Shift-Esc
- return exec.runBuiltin(p, .Last, p.active, "", null);
+ return exec.runBuiltin(p, .Last, v.active, "", null);
},
// gg and G: a count names the line; bare G is no move (helix)
.goto_file_start, .goto_line => {
@@ -719,7 +721,7 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void {
(if (p.panes[qid].?.query) |q| q.source == .diagnostics else false)
else
false;
- if (!fed) return p.lspRequest(p.active, .diagnostics, "");
+ if (!fed) return p.lspRequest(v.active, .diagnostics, "");
if (a.role == .goto_diagnostic) return set.step(p, pane, a.forward, 1, false);
if (set.hits.items.len == 0) return;
set.goTo(pane, if (a.forward) set.hits.items.len - 1 else 0, false);
@@ -817,18 +819,18 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void {
.undo => return edit.undoStep(p, t, true),
.redo => return edit.undoStep(p, t, false),
// Language shortcuts run the same builtins as tags and leader commands.
- .goto_definition => return exec.runBuiltin(p, .Def, p.active, "", null),
- .goto_references => return exec.runBuiltin(p, .Refs, p.active, "", null),
- .goto_callstack => return exec.runBuiltin(p, .Callstack, p.active, "", null),
- .goto_declaration => return p.lspRequest(p.active, .declaration, ""),
- .goto_type_definition => return p.lspRequest(p.active, .type_definition, ""),
- .goto_implementation => return p.lspRequest(p.active, .implementation, ""),
- .format => return p.lspRequest(p.active, .format, ""),
+ .goto_definition => return exec.runBuiltin(p, .Def, v.active, "", null),
+ .goto_references => return exec.runBuiltin(p, .Refs, v.active, "", null),
+ .goto_callstack => return exec.runBuiltin(p, .Callstack, v.active, "", null),
+ .goto_declaration => return p.lspRequest(v.active, .declaration, ""),
+ .goto_type_definition => return p.lspRequest(v.active, .type_definition, ""),
+ .goto_implementation => return p.lspRequest(v.active, .implementation, ""),
+ .format => return p.lspRequest(v.active, .format, ""),
.increment => return edit.normalAdjustNumber(p, t, @intCast(a.count)),
.decrement => return edit.normalAdjustNumber(p, t, -@as(i64, @intCast(a.count))),
.leader => if (p.macro.replaying == 0) {
- p.prefix = .leader;
- p.leader_n = 0;
+ v.prefix = .leader;
+ v.leader_n = 0;
},
// `:` is the one key a tag and a body do not share: it moves the
// keyboard between them.
@@ -845,7 +847,7 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void {
// `/` in a text is its query pane's line 1 (Query.zig); a
// terminal's still asks on the notice band.
.search => if (pane.file != null and t.what == .body)
- panes.Query.open(p, p.active, .text, "", true)
+ panes.Query.open(p, v.active, .text, "", true)
else
return panes.startPrompt(p, pane, &pane.body, .{ .search = config.search_marker }),
// In a file's text, n and N step its places while they answer for
@@ -859,9 +861,9 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void {
// The pattern is line 1 of this text's query pane, made or
// reused, the keyboard staying here: n and N step its places.
if (t.what == .body and pane.file != null and !pane.hasPdf() and pane.query == null) {
- const name = if (p.register != 0) p.register else '/';
+ const name = if (v.register != 0) v.register else '/';
const pat = p.registers.value(name, 0) orelse return;
- panes.Query.open(p, p.active, .text, pat, false);
+ panes.Query.open(p, v.active, .text, pat, false);
pane.places.provenance = .search;
}
},
@@ -869,7 +871,7 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void {
.macro_record => {
const m = &p.macro;
if (m.recording == 0) {
- m.recording = if (p.register != 0) p.register else '@';
+ m.recording = if (v.register != 0) v.register else '@';
m.recorded.clearRetainingCapacity();
return;
}
@@ -882,10 +884,10 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) void {
m.recording = 0;
},
.macro_replay => {
- const name: u21 = if (p.register != 0) p.register else '@';
+ const name: u21 = if (v.register != 0) v.register else '@';
const notation = p.registers.value(name, 0) orelse return;
const keys = Macro.decode(p.scratch.allocator(), notation) catch return;
- p.register = 0;
+ v.register = 0;
for (0..a.count) |_| keyboard.replayKeys(p, keys);
},
.repeat_insert => {
@@ -913,7 +915,7 @@ pub fn handlePdfNormal(p: *Pardes, pane: *Pane, key: Key) void {
if (pane.pdf == null) return;
if (pane.body.normal.prefix == null and isPrefix(key, 'f')) {
pane.body.normal.clear();
- return exec.runBuiltin(p, .PdfSections, p.active, "", null);
+ return exec.runBuiltin(p, .PdfSections, p.view().active, "", null);
}
switch (modal.Normal.parse(&pane.body.normal, normalInput(key))) {
.pending, .ignored, .unbound => {},