diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-17 07:44:55 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-17 12:15:01 -0300 |
| commit | 0db7861d9da09e059fa1b9e40fff5cd52add27f2 (patch) | |
| tree | 6e95dfa36e07b3234b1d5cdb990b11f95c184a3f /src/Editor.zig | |
| parent | d3742ddf2b3a85eb3935cb35e958fa27f1293a6b (diff) | |
| parent | dee94c740bdaea61ff35b4e0a7f1d2815c9ee441 (diff) | |
| download | pardes-0db7861d9da09e059fa1b9e40fff5cd52add27f2.tar.gz pardes-0db7861d9da09e059fa1b9e40fff5cd52add27f2.zip | |
integration: the text pane a library (pardes-editor), with the GPU move, the terminal, the plumber and the diff work
A merge of pardes-next (wmrtztwl) and editor-lib (rlumrxuq), no conflicts. Gated against the baseline of the integration line (.scratch/sketch/gpu/mbase): the merge with the library before its follow-up, in full: frame corpus 77/77 identical in Debug and in ReleaseFast, the gated window -0.019% instructions (threshold 0.5%), unit-test on gui 1584/1592 with no failure the baseline has not; this merge: corpus 77/77 in Debug, unit-test on gui 1584/1592, on tui core-test 811/950 (139 skipped), shell-test 990/993, lib-test, hxdiff 658, parity 738, hxgolf 124, hxlib 538 and its parity 618, all 0 mismatches, replicas pass.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'src/Editor.zig')
| -rw-r--r-- | src/Editor.zig | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/Editor.zig b/src/Editor.zig new file mode 100644 index 00000000..b7c7057d --- /dev/null +++ b/src/Editor.zig @@ -0,0 +1,80 @@ +//! What an edit of a text runs with (normal.zig, edit.zig): the allocators, +//! the registers, the register the running command names, the replay of a +//! key across the ranges, the text an edit made that nothing kept, and the +//! core the text's pane is in. Gathered for each call from where pardes +//! keeps them (`Pardes.editor`); the library gathers it from the value a +//! sketch stores (src/lib_editor.zig). Nothing here is kept between calls. +const std = @import("std"); +const Registers = @import("Registers.zig"); + +/// The library's build (build.zig `library`): a text with no pane and no +/// core, its characters its own. Where an edit reaches a pane it branches +/// on this at compile time, so the library never compiles the core. +pub const lib = @import("pardes_config").lib; +const Pardes = if (lib) void else @import("Core.zig"); +const Syntax = if (lib) @import("lib_editor.zig").Syntax else void; +const modal = @import("modal.zig"); + +const Editor = @This(); + +/// A text's parse as the tree-sitter walks read it (normal.nodeTree): the +/// tree, a path its grammar's queries are found by, and helix's +/// object_selections, what Alt-o grew from for Alt-i to go back to, its +/// ranges in `gpa`. Dropped with the tree when the text changes. +pub const Tree = struct { root: *anyopaque, path: []const u8, history: *std.ArrayList(NodeStep), gpa: std.mem.Allocator }; +pub const NodeStep = struct { ranges: []modal.Selection, primary: usize }; + +gpa: std.mem.Allocator, +/// What an edit makes and drops: the update's scratch. +scratch: std.mem.Allocator, +registers: *Registers, +/// The register the running normal command names (`"<reg>`); 0 for the +/// default one. +register: *u21, +/// While a key is replayed across the ranges (normal.replaySels): whether +/// this is the first pass, whether a pass stopped the replay, which range +/// this pass is, in document order, and how many there are; outside a +/// replay, the one range and its first pass. A register value belongs to +/// its range by `multi_index`. +multi_first: *bool, +multi_stop: *bool, +multi_index: *usize, +multi_count: *usize, +/// An edited text nothing kept (a tag's shown text): see +/// edit.retireEditText. +retired_edit: *?[]u8, +/// The core the text's pane is in: what an edit reaches past its text with. +p: if (lib) void else *Pardes, +/// The library's: an edit failed (its allocator ran out) and the key is +/// refused. +failed: if (lib) *bool else void, +/// The library's: the parse its caller handed in, which the tree-sitter +/// walks read; null, and they are the caller's (`textRole`). +syntax: if (lib) ?*Syntax else void, + +pub fn of(p: *Pardes) Editor { + return .{ + .gpa = p.gpa, + .scratch = p.scratch.allocator(), + .registers = &p.registers, + .register = &p.view().register, + .multi_first = &p.multi_first, + .multi_stop = &p.multi_stop, + .multi_index = &p.multi_index, + .multi_count = &p.multi_count, + .retired_edit = &p.retired_edit, + .p = p, + .failed = {}, + .syntax = {}, + }; +} + +/// An edit that failed, said on the message row of the pane the keyboard +/// is in. +pub fn reportError(e: Editor, err: anyerror) void { + if (comptime lib) { + e.failed.* = true; + return; + } + e.p.reportError(e.p.view().active, "edit", err); +} |
