summaryrefslogtreecommitdiff
path: root/src/edit.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/edit.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/edit.zig')
-rw-r--r--src/edit.zig44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/edit.zig b/src/edit.zig
index 5adb94e3..c6c59604 100644
--- a/src/edit.zig
+++ b/src/edit.zig
@@ -35,7 +35,7 @@ const Registers = pardes.Registers;
/// registers computed from the editor (`#`, `.`, `%`) cannot be written.
/// `+` and `*` are the system clipboard: the value is sent there too.
pub fn setYank(p: *Pardes, text: []const u8) void {
- var name: u21 = if (p.register != 0) p.register else Registers.default;
+ var name: u21 = if (p.view().register != 0) p.view().register else Registers.default;
switch (name) {
'_', '#', '.', '%' => return,
'*' => name = '+',
@@ -75,7 +75,7 @@ fn selText(p: *Pardes, t: *Text) []const u8 {
pub const Paste = enum { after, before, replace };
pub fn pasteRegister(p: *Pardes, t: *Text, how: Paste, count: usize) void {
- const name: u21 = if (p.register != 0) p.register else Registers.default;
+ const name: u21 = if (p.view().register != 0) p.view().register else Registers.default;
if (name == '+' or name == '*') {
if (!normal.multiOnce(p)) return;
const pane = t.pane() orelse return;
@@ -98,7 +98,7 @@ pub const ClipRequest = struct {
pub fn clipRequest(p: *Pardes, id: usize, mode: Paste) void {
const pane = p.panes[id] orelse return;
- p.clip_pending = .{ .pane = id, .serial = pane.serial, .mode = mode };
+ p.view().clip_pending = .{ .pane = id, .serial = pane.serial, .mode = mode };
p.emit(.read_clipboard);
}
@@ -111,27 +111,28 @@ pub fn typeToTty(p: *Pardes, id: usize, pane: *const Pane, text: []const u8) voi
}
pub fn applyPaste(p: *Pardes, whole: []const u8) void {
+ const v = p.view();
// Every shell's paste comes through here, bounded: what is past the
// limit is left out, at a character's start, and said.
const limit = @import("memory.zig").limits.max_paste_bytes;
const bytes = if (whole.len > limit) whole[0..modal.graphemeStart(whole, limit)] else whole;
if (whole.len > limit) {
var said: [96]u8 = undefined;
- p.setMessage(p.active, std.fmt.bufPrint(&said, "paste cut at its limit, {d} KiB: the rest left out", .{limit / 1024}) catch "paste cut at its limit");
+ p.setMessage(v.active, std.fmt.bufPrint(&said, "paste cut at its limit, {d} KiB: the rest left out", .{limit / 1024}) catch "paste cut at its limit");
}
// A prompt answering for a header takes the paste, as it takes keys.
- const asking = if (p.panes[p.active]) |active| active.prompt != .none else false;
+ const asking = if (p.panes[v.active]) |active| active.prompt != .none else false;
if (!asking) if (tagline.focusedHeader(p)) |t| {
- p.clip_pending = null;
+ v.clip_pending = null;
return pasteInto(p, t, bytes);
};
- const req = p.clip_pending;
- p.clip_pending = null;
+ const req = v.clip_pending;
+ v.clip_pending = null;
if (bytes.len == 0) return;
- const id = if (req) |r| r.pane else p.active;
+ const id = if (req) |r| r.pane else v.active;
const pane = p.panes[id] orelse return;
if (req) |r| if (pane.serial != r.serial) return;
- p.active = id;
+ v.active = id;
if (pane.prompt != .none and pane.prompt != .del_side and pane.prompt != .repl_choice) {
// an answer is one line: a newline in it would only be submitting it
const line = p.scratch.allocator().alloc(u8, bytes.len) catch return;
@@ -172,10 +173,11 @@ fn pasteInto(p: *Pardes, t: *Text, bytes: []const u8) void {
}
pub fn clipYank(p: *Pardes, pane: *Pane, main_only: bool) void {
+ const v = p.view();
// helix's `"+y`: the clipboard register, and only it
- const named = p.register;
- p.register = '+';
- defer p.register = named;
+ const named = v.register;
+ v.register = '+';
+ defer v.register = named;
if (comptime pdf_enabled) if (pane.pdf) |pv| {
if (pv.selection_text.len > 0) setYank(p, pv.selection_text);
return;
@@ -350,7 +352,7 @@ pub fn spanHas(r: i32, c: i32, ar: i32, ac: i32, br: i32, bc: i32) bool {
/// the active modal selection as text, if any
pub fn currentSelText(p: *Pardes, pane: *Pane) ?[]const u8 {
- if (comptime pdf_enabled) if (p.frontend.native_images) if (pane.pdf) |pv|
+ if (comptime pdf_enabled) if (p.view().frontend.native_images) if (pane.pdf) |pv|
if (pv.selection != null and pv.selection_text.len > 0) return pv.selection_text;
if (!pane.body.vsel.active) return null;
return vselText(p, &pane.body);
@@ -1027,7 +1029,7 @@ fn insertEdit(p: *Pardes, t: *Text, key: Key) void {
const f = (t.pane() orelse break :dot).file orelse break :dot;
if (f.output != null or !lsp.speaks(f.path)) break :dot;
const seq = p.lsp_ask.seq;
- p.lspRequest(p.active, .completion, "");
+ p.lspRequest(p.view().active, .completion, "");
if (p.lsp_ask.seq != seq) return;
}
// helix smart_tab: after text, Tab leaves the syntax node the
@@ -1845,7 +1847,7 @@ pub fn pushUndo(p: *Pardes, t: *Text) void {
if (!p.multi_first) return;
switch (t.what) {
// A B1 chord took its one undo point when it began (mouse.zig).
- .body => if (p.chord_hold) return,
+ .body => if (p.view().chord_hold) return,
.tag, .column, .workspace => return t.remember(p.gpa, if (t.own) |own| .{ .text = own } else null),
// a prompt's answer is typed once and gone; it keeps no history
.input => return,
@@ -1880,7 +1882,7 @@ const PointerTextSelection = struct {
pub fn pointerTextSelection(p: *const Pardes, id: usize, col: u16, row: u16, body_hit: ?Mouse.BodyHit, tag_hit: ?TagHit) ?PointerTextSelection {
const pane = p.panes[id] orelse return null;
- const r = p.rects[id];
+ const r = p.view().rects[id];
if (col < r.x + config.GUTTER or col >= r.x + r.w or row < r.y or row >= r.y + r.h) return null;
const tag_y = p.tagTop(pane, r);
const body_y = p.bodyTop(pane, r);
@@ -2063,11 +2065,11 @@ test "only the SPC clipboard commands cross to the system clipboard" {
const before = pane.file.?.content.len;
p.update(.{ .key = .{ .cp = ' ' } });
p.update(.{ .key = .{ .cp = 'p' } });
- try std.testing.expect(p.clip_pending != null);
+ try std.testing.expect(p.view().clip_pending != null);
try std.testing.expect(drainedEffect(p, .read_clipboard));
try std.testing.expectEqual(before, pane.file.?.content.len); // nothing yet
p.update(.{ .paste = "PASTED" });
- try std.testing.expect(p.clip_pending == null);
+ try std.testing.expect(p.view().clip_pending == null);
try std.testing.expect(std.mem.indexOf(u8, pane.file.?.content, "PASTED") != null);
// ...and it did NOT land in the register on its way past, nor echo back
// out to the clipboard it came from.
@@ -2084,9 +2086,9 @@ test "only the SPC clipboard commands cross to the system clipboard" {
// than firing late into whatever pane is focused by then.
p.update(.{ .key = .{ .cp = ' ' } });
p.update(.{ .key = .{ .cp = 'P' } });
- try std.testing.expect(p.clip_pending != null);
+ try std.testing.expect(p.view().clip_pending != null);
p.update(.{ .key = .{ .cp = 'l' } });
- try std.testing.expect(p.clip_pending == null);
+ try std.testing.expect(p.view().clip_pending == null);
}
/// acme's double-click (plan9port acme text.c:1407, textdoubleclick): from