diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-23 12:11:43 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-23 14:57:18 -0300 |
| commit | 3728b4704962672688f0b4461d20481263378165 (patch) | |
| tree | d5be8ea4c729ac54a60d02412cd218b57940fde8 /core/ninep | |
| parent | 62c6caf414fd5a2be556f76eb21d1d6d8d3beadb (diff) | |
| download | pardes-3728b4704962672688f0b4461d20481263378165.tar.gz pardes-3728b4704962672688f0b4461d20481263378165.zip | |
the Changes layer's lines are the pane's text, read-only, and nothing is cut (the user's rulings of 2026-11-23: "all text is regular text", "the ghost line should be regular text too ... but I cant edit them", "don't cut them ... break them following the regular softwrap"; the coordinator's model P71): while a pane's layer is shown, a line a change took away, a changed line's old text and each change's description (`id title author age`, its whole title and its whole author) are lines of the pane's buffer, and the buffer carries their places (`File.State.read_only`, `File.ReadOnly`, whose layer `File.State.layer`), so every motion, selection, search, text object, count, yank, B2 and B3 works on them because they are text, and they wrap by the pane's soft wrap; ONE check where every edit passes (`File.edit`'s `readOnly`: a file at a revision is its whole text, the layer's lines each one; an edit that changes a byte of one, puts any in at its start or inside it, or leaves one on the end of the line above is refused whole, in words on the notice line), edit.zig's second revision check deleted; THE FILE'S TEXT by one function (`File.fileText`, `FileParts`, `fileHash`, `fileEql`, `fileLen`: the buffer itself with no layer, a file with none pays nothing) and two maps (`fileOffset`/`bufferOffset`, `fileRow`/`bufferRow`: a place in one of the layer's lines is after the file line above it), read by every sink: Save and Save-as (Effect.zig), `body`, `addr`, `data`, `xdata`, `sel` and `dot` over 9P (ninep/pane.zig `bodyOf` is the file's text, `fileDot`/`setFileDot`, a 9P write is `File.replaceFile`, a read of a pane with the layer a copy, never a region of the buffer), the dirty checks, Get and a disk reread (`File.load`: the layer out and back), Edit (sam over the file's text, its result a load, its `w` the file's), the language server (its source, the offset asked at, its edits, its places), the syntax parse (`highlightLayered`: the file's text parsed, its colours laid around the layer's lines; context declarations; a worker's parse; query rows' colours and line numbers), jj's own provenance and churn, `Look :N` and `path:N` (the file's line N), the undo journal (an edit journaled in the file's offsets, an undo taken with the layer out; `Journal.record` takes the removed bytes); the layer in and out by `jj.showLayer`/`jj.hideLayer` through `File.relayer` (an edit of kind `.layer` that nothing reading the file hears of, every view's cursor, selection and top line kept by the file's offsets); the layer is the pane's: shown in every view of it and of its twins (`jj.setLanes`); when the editor's whole new text's shortest splice runs into a read-only line where an equal splice does not, that one is taken (`File.clearOfReadOnly`, never back across a read-only line); deleted: `File.fillBody`'s ghost branch, `File.hasGhosts`, `File.bodyWidth`, `jj.fitted`, `jj.row_max`, `jj.showGhosts`, `jj.wordAt`, `Pane.ghosts`/`ghost_text` and `wrapAt`'s `ghost`, Core's per-step sync; the gutter numbers the file's lines; `]g`/`[g` land on a layer's line as on any; the arrow keeps the user's bend (`╰─→`, as nmwnvrow); WIRE 34 (a file pane's `read_only` and `layer`, a description ghost's `author` in the dump and the digest; a clean file's text is dumped while the layer's lines are in its buffer; a dump of 31 loads, a pane whose view showed the layer showing it again: `jj.loaded`); tests (core/jj.zig): the layer's lines as text, read-only (terminal and window), THE FILE'S TEXT (every sink with the layer off and on, byte for byte), the undo across hide and show, 9P in the file's offsets, a client replaying them and a join loading them, a wire-31 dump, a description whole and wrapped in 50 columns, and the old tests of the per-view rows made the pane's; its gate (.scratch/sketch/reorg/pardes-layers-8/g8a, loads 3-7): core-test 942/1108 (166 skipped; the base 936/1102) and shell-test 1150/1153 (3 skipped; the base 1144/1147) in Debug and in ReleaseSafe, behaviour-test 276/276 and --replay, pane-test 182/183, the soak --clients 5 (diverged 0, unequal 0, unlisted 0 at 30/80/207 ms, the corpus 22 of 22, no leak), the gui unit-test 1747/1751 (the known BaselineHarnessMismatch alone), the frame gate 77/77 frames, 0 differ; the perf counts against tree6 40 of 121 over 0.1% where the base's own gate (merge63-g) has 33: against the base this adds body-appends +0.42%, client-key-down +0.18%, terminal on all +0.155%, client-delete-undo +0.14%, deep-sel +0.12%, client-edit-char +0.11% (cause not found yet)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/ninep')
| -rw-r--r-- | core/ninep/ctl.zig | 24 | ||||
| -rw-r--r-- | core/ninep/events.zig | 4 | ||||
| -rw-r--r-- | core/ninep/pane.zig | 137 |
3 files changed, 110 insertions, 55 deletions
diff --git a/core/ninep/ctl.zig b/core/ninep/ctl.zig index 7b4e2754..2090f17e 100644 --- a/core/ninep/ctl.zig +++ b/core/ninep/ctl.zig @@ -426,7 +426,7 @@ pub fn paneText(p: *Pardes, pane: *Pane, buf: *[pane_text_cap]u8) []const u8 { pane.serial, if (pane_files.tagOf(p, pane)) |tag| tag.len else |_| 0, // a length, as a stat's: none when the tag cannot be made // A terminal's body is its history, read whole on an open's first read. - if (pane.isTerminal()) pardes.Term.scrollbackLen(pane.terminal) else pane_files.bodyOf(pane).len, + if (pane.isTerminal()) pardes.Term.scrollbackLen(pane.terminal) else pane_files.bodyOf(p, pane).len, // A directory pane is one, as acme's isdir says. @intFromBool(if (pane.file) |f| f.listing != null else false), @intFromBool(pane_files.dirtyOf(pane)), @@ -1202,10 +1202,10 @@ fn acmeCtl(p: *Pardes, req: Req, serial: u32, line: []const u8, apply: bool) Acm .delete => return .{ .builtin = "Delete" }, .@"dot=addr", .@"addr=dot", .@"limit=addr", .show, .cleartag => { if (apply) switch (w) { - .@"dot=addr" => pane_files.setDot(p.settings.tab, pane, pf.addr), - .@"addr=dot" => pf.addr = pane_files.dotOf(pane), + .@"dot=addr" => pane_files.setFileDot(p.settings.tab, pane, pf.addr), + .@"addr=dot" => pf.addr = pane_files.fileDot(pane), .@"limit=addr" => pf.limit = pf.addr, - .show => pane_files.showOffset(p.settings.tab, pane, pane_files.dotOf(pane).q0), + .show => pane_files.showFileOffset(p.settings.tab, pane, pane_files.fileDot(pane).q0), else => _ = pane_files.truncate(p, pane, .tag), }; return .done; @@ -1240,7 +1240,7 @@ pub fn getRefused(p: *Pardes, pane: *Pane, word: []const u8) ?[]const u8 { if (f.output != null and f.content.len < 100) return null; // Dirty by a rename alone is no text to lose: only edits are asked about. const saved = f.saved_hash orelse return null; - if (std.hash.Wyhash.hash(0, f.content) == saved) return null; + if (panes.File.fileHash(f) == saved) return null; if (pane.discard_warned) |w| if (w.revision == f.revision and w.by == .get) return null; pane.discard_warned = .{ .revision = f.revision, .by = .get }; const id = p.paneBySerial(pane.serial).?; @@ -1274,10 +1274,11 @@ pub fn getFile(p: *Pardes, pane: *Pane, path: []const u8) GetError!void { p.gpa.free(bytes); return if (err == error.OutOfMemory) error.OutOfMemory else error.InvalidName; }; - panes.File.setContent(p, f, bytes); + // The file's new text: the layer's lines out and back (File.load). + panes.File.load(p, f, bytes); f.saved_revision = f.revision; - f.saved_hash = std.hash.Wyhash.hash(0, f.content); - f.saved_len = f.content.len; + f.saved_hash = panes.File.fileHash(f); + f.saved_len = panes.File.fileLen(f); f.disk_newer = null; f.disk_newer_warned = false; f.disk_gone = false; @@ -1307,10 +1308,11 @@ pub fn get(p: *Pardes, pane: *Pane) GetError!void { p.gpa.free(bytes); return err; }; - panes.File.setContent(p, f, bytes); + // The file's new text: the layer's lines out and back (File.load). + panes.File.load(p, f, bytes); f.saved_revision = f.revision; - f.saved_hash = std.hash.Wyhash.hash(0, f.content); - f.saved_len = f.content.len; + f.saved_hash = panes.File.fileHash(f); + f.saved_len = panes.File.fileLen(f); f.disk_newer = null; f.disk_gone = false; f.on_disk = fs.localPath(f.path) != null; diff --git a/core/ninep/events.zig b/core/ninep/events.zig index 1fd05b54..f1e17324 100644 --- a/core/ninep/events.zig +++ b/core/ninep/events.zig @@ -722,7 +722,7 @@ pub fn writeEvent(p: *Pardes, asked: Req, id: usize) Reply { } const serial = pane0.serial; { - const body = pane_files.bodyOf(pane0); + const body = pane_files.bodyOf(p, pane0); const tag = pane_files.tagOf(p, pane0) catch return Reply.fail(req.tag, E.NOMEM); var check: EventReader = .{ .data = req.data }; while (check.next()) |r| { @@ -749,7 +749,7 @@ pub fn writeEvent(p: *Pardes, asked: Req, id: usize) Reply { while (run.next()) |r| { const live = p.paneBySerial(serial) orelse break; const pane = p.panes[live].?; - const whole = if (r.action.onTag()) pane_files.tagOf(p, pane) catch return Reply.fail(req.tag, E.NOMEM) else pane_files.bodyOf(pane); + const whole = if (r.action.onTag()) pane_files.tagOf(p, pane) catch return Reply.fail(req.tag, E.NOMEM) else pane_files.bodyOf(p, pane); const lo = @min(@as(usize, r.q0), whole.len); const hi = @max(lo, @min(@as(usize, r.q1), whole.len)); // An empty range with no text is a click at that point: expanded as diff --git a/core/ninep/pane.zig b/core/ninep/pane.zig index d47b637b..2616c735 100644 --- a/core/ninep/pane.zig +++ b/core/ninep/pane.zig @@ -146,11 +146,28 @@ pub const State = struct { // ---- what a pane is ---- -pub fn bodyOf(pane: *const Pane) []const u8 { +/// A pane's text as 9P serves it: a file's text (File.fileText: the +/// buffer less its read-only lines, the `Changes` layer's, which are no +/// text of the file's). Every address, `dot` and range over 9P is of this +/// text (`fileDot`); a write to it is the file's (`spliceBody`). +pub fn bodyOf(p: *Pardes, pane: *const Pane) []const u8 { + if (pane.file) |*f| return panes.File.fileText(f, p.scratch.allocator()) catch ""; + return ""; +} + +/// The buffer the editor edits (with the layer's lines): what the +/// editor's own dot is of (`dotOf`, `setDot`). +fn bufferOf(pane: *const Pane) []const u8 { if (pane.file) |*f| return f.content; return ""; } +/// Whether 9P reads of the pane are a copy of its file's text, not a +/// region of its buffer (`fsPayload` reads the buffer). +fn layered(pane: *const Pane) bool { + return if (pane.file) |*f| f.read_only.len > 0 else false; +} + pub fn fileOf(pane: *Pane) ?*panes.File.State { return if (pane.file) |*f| f else null; } @@ -240,7 +257,7 @@ fn positionAt(pane: *const Pane, text: []const u8, off: usize) modal.Cursor { } pub fn dotOf(pane: *Pane) State.Range { - const text = bodyOf(pane); + const text = bufferOf(pane); // In runes, as every address is (modal.runeStart). const head = runeOffsetAt(pane, text, .{ .row = @intCast(@max(0, pane.body.cur_row)), .col = @intCast(@max(0, pane.body.cur_col)) }); if (!pane.body.vsel.active) return .{ .q0 = clip(head), .q1 = clip(head) }; @@ -251,7 +268,7 @@ pub fn dotOf(pane: *Pane) State.Range { } pub fn setDot(tab: u16, pane: *Pane, r: State.Range) void { - const text = bodyOf(pane); + const text = bufferOf(pane); const q0 = @min(@as(usize, r.q0), text.len); const q1 = @max(q0, @min(@as(usize, r.q1), text.len)); const a = runePositionAt(pane, text, q0); @@ -268,7 +285,7 @@ pub fn setDot(tab: u16, pane: *Pane, r: State.Range) void { /// a write shown is not a write that moves dot (acme's textinsert leaves /// dot where its rule puts it; only the view follows the text). pub fn showOffset(tab: u16, pane: *Pane, off: usize) void { - const text = bodyOf(pane); + const text = bufferOf(pane); const c = positionAt(pane, text, @min(off, text.len)); // Where dot is now, kept: pinned, so the view moving under it does not // move it to the view's top (pinCursor). @@ -282,6 +299,26 @@ pub fn showOffset(tab: u16, pane: *Pane, off: usize) void { pane.body.cur_col = col; } +/// `dotOf` in the file's text's offsets, as 9P serves it (`bodyOf`): a dot +/// in a read-only line is after the file line above it. +pub fn fileDot(pane: *Pane) State.Range { + const d = dotOf(pane); + const f = if (pane.file) |*file| file else return d; + return .{ .q0 = clip(panes.File.fileOffset(f, d.q0)), .q1 = clip(panes.File.fileOffset(f, d.q1)) }; +} + +/// `setDot` from the file's text's offsets (`fileDot`). +pub fn setFileDot(tab: u16, pane: *Pane, r: State.Range) void { + const f = if (pane.file) |*file| file else return setDot(tab, pane, r); + setDot(tab, pane, .{ .q0 = clip(panes.File.bufferOffset(f, r.q0, false)), .q1 = clip(panes.File.bufferOffset(f, r.q1, r.q1 > r.q0)) }); +} + +/// `showOffset` of a file's text's offset. +pub fn showFileOffset(tab: u16, pane: *Pane, off: usize) void { + const f = if (pane.file) |*file| file else return showOffset(tab, pane, off); + showOffset(tab, pane, panes.File.bufferOffset(f, off, false)); +} + pub fn clampAddr(pf: *State, len: usize) void { const n = clip(len); pf.addr.q0 = @min(pf.addr.q0, n); @@ -314,18 +351,21 @@ pub fn wholeUtf8(data: []const u8) usize { return data.len; } +/// `bytes` over `q0`..`q1` of the file's text (`bodyOf`'s offsets): the +/// file's edit (File.replaceFile), never refused for the layer's lines. pub fn spliceBody(p: *Pardes, pane: *Pane, q0: usize, q1: usize, bytes: []const u8) ?usize { const f = fileOf(pane) orelse return null; const take = if (bytes.len == 0) 0 else wholeUtf8(bytes); - const lo = @min(q0, f.content.len); - const hi = @max(lo, @min(q1, f.content.len)); + const text = bodyOf(p, pane); + const lo = @min(q0, text.len); + const hi = @max(lo, @min(q1, text.len)); // An empty range deleted, or a range replaced by what it holds: no // edit, so no undo step and no new revision. - if (std.mem.eql(u8, f.content[lo..hi], bytes[0..take])) return take; + if (std.mem.eql(u8, text[lo..hi], bytes[0..take])) return take; const join = pane.fs.joined == f.revision; pane.fs.joined = null; if (!pane.fs.nomark and !join) panes.File.pushUndo(p, pane) catch return null; - if (!panes.File.replace(p, f, lo, hi - lo, bytes[0..take])) return null; + if (!panes.File.replaceFile(p, f, lo, hi - lo, bytes[0..take])) return null; return take; } @@ -340,7 +380,7 @@ pub fn fileSize(p: *Pardes, id: usize, f: PaneFile) u64 { const pf = &pane.fs; return switch (f) { // A terminal's body reads its screen and history, as text. - .body => if (pane.file == null and pane.isTerminal()) pardes.Term.scrollbackLen(pane.terminal) else if (kindText(p, pane)) |t| t.len else bodyOf(pane).len, + .body => if (pane.file == null and pane.isTerminal()) pardes.Term.scrollbackLen(pane.terminal) else if (kindText(p, pane)) |t| t.len else bodyOf(p, pane).len, // What addr selects, generated by each read: no length, as acme's // data and xdata have none; and rows, made by each read. .data, .xdata, .rows => 0, @@ -351,7 +391,7 @@ pub fn fileSize(p: *Pardes, id: usize, f: PaneFile) u64 { break :ctl ctl.paneText(p, pane, &buf).len; }, .sel => sel: { - const d = dotOf(pane); + const d = fileDot(pane); break :sel @max(d.q0, d.q1) - d.q0; }, .addr => if (pf.addr_failed) 0 else range_len, @@ -407,14 +447,14 @@ pub fn read(p: *Pardes, req: Req, id: usize, pane: *Pane, file: PaneFile) Reply // A failed address reads empty, as an unset limit does: there is // none. data and xdata are what refuse. .addr => readRange(p, req, if (pf.addr_failed) null else addr: { - clampAddr(pf, bodyOf(pane).len); + clampAddr(pf, bodyOf(p, pane).len); break :addr pf.addr; }), - .dot => readRange(p, req, dotOf(pane)), + .dot => readRange(p, req, fileDot(pane)), .limit => readRange(p, req, pf.limit), - .data => readData(req, id, pane, pf, false), - .xdata => readData(req, id, pane, pf, true), - .sel => readSel(req, id, pane), + .data => readData(p, req, id, pane, pf, false), + .xdata => readData(p, req, id, pane, pf, true), + .sel => readSel(p, req, id, pane), .dirty => readFlag(p, req, dirtyOf(pane)), .mark => readFlag(p, req, !pf.nomark), .scroll => readFlag(p, req, !pf.noscroll), @@ -457,7 +497,9 @@ fn kindText(p: *Pardes, pane: *Pane) ?[]const u8 { fn readBody(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply { if (pane.file != null) { - const text = bodyOf(pane); + const text = bodyOf(p, pane); + // The layer's lines in the buffer: a copy of the file's text. + if (layered(pane)) return tree.window(p, req, text); const off = @min(req.off, text.len); const n = @min(text.len - off, req.size); return .{ .tag = req.tag, .payload = .{ .region = .{ @@ -476,9 +518,9 @@ fn readBody(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply { return tree.window(p, req, text); } -fn readData(req: Req, id: usize, pane: *Pane, pf: *State, stop_at_end: bool) Reply { +fn readData(p: *Pardes, req: Req, id: usize, pane: *Pane, pf: *State, stop_at_end: bool) Reply { if (pf.addr_failed) return tree.failText(req.tag, E.INVAL, e_addr_failed); - const text = bodyOf(pane); + const text = bodyOf(p, pane); clampAddr(pf, text.len); const q0: usize = pf.addr.q0; const hi: usize = if (stop_at_end) @max(q0, @as(usize, pf.addr.q1)) else text.len; @@ -487,6 +529,11 @@ fn readData(req: Req, id: usize, pane: *Pane, pf: *State, stop_at_end: bool) Rep pf.addr.q0 = clip(end); if (!stop_at_end) pf.addr.q1 = clip(end); if (pane.file == null) return .{ .tag = req.tag }; + if (layered(pane)) { + var whole = req; + whole.off = 0; + return tree.window(p, whole, text[q0..end]); + } return .{ .tag = req.tag, .payload = .{ .region = .{ .pane = @intCast(id), .serial = pane.serial, @@ -495,14 +542,19 @@ fn readData(req: Req, id: usize, pane: *Pane, pf: *State, stop_at_end: bool) Rep } } }; } -fn readSel(req: Req, id: usize, pane: *Pane) Reply { +fn readSel(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply { if (pane.file == null) return .{ .tag = req.tag }; - const text = bodyOf(pane); - const d = dotOf(pane); + const text = bodyOf(p, pane); + const d = fileDot(pane); const lo = @min(@as(usize, d.q0), text.len); const hi = @max(lo, @min(@as(usize, d.q1), text.len)); const off = @min(req.off, hi - lo); const n = @min(hi - lo - off, req.size); + if (layered(pane)) { + var whole = req; + whole.off = 0; + return tree.window(p, whole, text[lo + off ..][0..n]); + } return .{ .tag = req.tag, .payload = .{ .region = .{ .pane = @intCast(id), .serial = pane.serial, @@ -519,7 +571,7 @@ pub fn write(p: *Pardes, req: Req, id: usize, pane: *Pane, file: PaneFile) Reply .body => writeBody(p, req, id, pane), .tag => writeTag(p, req, pane), .ctl => ctl.writePane(p, req, pane), - .addr, .dot, .limit => writeRange(p.settings.tab, req, pane, file), + .addr, .dot, .limit => writeRange(p, req, pane, file), .data, .xdata => writeData(p, req, pane), .sel => writeSel(p, req, pane), .dirty, .mark, .scroll => writeFlag(p, req, pane, file), @@ -603,13 +655,13 @@ pub fn flushBatch(p: *Pardes) void { const id = p.paneBySerial(b.serial) orelse return; const pane = p.panes[id].?; if (fileOf(pane) == null) return; - const before = dotOf(pane); + const before = fileDot(pane); const take = spliceJoined(p, pane, b.at, b.at, b.bytes.items, b.handle) orelse return; - setDot(p.settings.tab, pane, .{ + setFileDot(p.settings.tab, pane, .{ .q0 = shiftOne(before.q0, clip(b.at), 0, clip(take)), .q1 = shiftOne(before.q1, clip(b.at), 0, clip(take)), }); - if (!pane.fs.noscroll) showOffset(p.settings.tab, pane, b.at + take); + if (!pane.fs.noscroll) showFileOffset(p.settings.tab, pane, b.at + take); } /// How many bytes this open's write holds back (`fs.batch`) for its pane. @@ -645,11 +697,11 @@ fn writeBody(p: *Pardes, req: Req, id: usize, pane: *Pane) Reply { p.emitWrite(id, req.data[0..take]); return .{ .tag = req.tag, .written = @intCast(take) }; } - const at = bodyOf(pane).len + heldBytes(p, req, pane); + const at = bodyOf(p, pane).len + heldBytes(p, req, pane); if (holdWrite(p, req, pane, at) catch return Reply.fail(req.tag, E.NOMEM)) |take| return .{ .tag = req.tag, .written = @intCast(take) }; const take = spliceJoined(p, pane, at, at, req.data, req.handle) orelse return Reply.fail(req.tag, E.NOMEM); - if (!pane.fs.noscroll) showOffset(p.settings.tab, pane, at + take); + if (!pane.fs.noscroll) showFileOffset(p.settings.tab, pane, at + take); return .{ .tag = req.tag, .written = @intCast(take) }; } @@ -738,7 +790,7 @@ fn writeData(p: *Pardes, req: Req, pane: *Pane) Reply { if (fileOf(pane) == null) return tree.failText(req.tag, E.INVAL, e_no_text); const pf = &pane.fs; if (pf.addr_failed) return tree.failText(req.tag, E.INVAL, e_addr_failed); - clampAddr(pf, bodyOf(pane).len + heldBytes(p, req, pane)); + clampAddr(pf, bodyOf(p, pane).len + heldBytes(p, req, pane)); const q0: usize = pf.addr.q0; const q1: usize = @max(q0, @as(usize, pf.addr.q1)); // An insert (an empty address) goes on from the open's held bytes. @@ -747,15 +799,15 @@ fn writeData(p: *Pardes, req: Req, pane: *Pane) Reply { return .{ .tag = req.tag, .written = @intCast(take) }; }; flushBatch(p); - const before = dotOf(pane); + const before = fileDot(pane); const take = spliceJoined(p, pane, q0, q1, req.data, req.handle) orelse return Reply.fail(req.tag, E.NOMEM); - setDot(p.settings.tab, pane, .{ + setFileDot(p.settings.tab, pane, .{ .q0 = shiftOne(before.q0, clip(q0), clip(q1 - q0), clip(take)), .q1 = shiftOne(before.q1, clip(q0), clip(q1 - q0), clip(take)), }); pf.addr = .{ .q0 = clip(q0 + take), .q1 = clip(q0 + take) }; - if (!pf.noscroll) showOffset(p.settings.tab, pane, q0 + take); + if (!pf.noscroll) showFileOffset(p.settings.tab, pane, q0 + take); return .{ .tag = req.tag, .written = @intCast(take) }; } @@ -764,7 +816,7 @@ fn writeSel(p: *Pardes, req: Req, pane: *Pane) Reply { const pf = &pane.fs; // The same open's next write follows its last; any other replaces dot. const going_on = req.handle != 0 and pf.wrsel_by == req.handle; - const d = if (going_on) State.Range{ .q0 = pf.wrsel.q1, .q1 = pf.wrsel.q1 } else dotOf(pane); + const d = if (going_on) State.Range{ .q0 = pf.wrsel.q1, .q1 = pf.wrsel.q1 } else fileDot(pane); const q0: usize = d.q0; const q1: usize = @max(q0, @as(usize, d.q1)); const take = spliceBody(p, pane, q0, q1, req.data) orelse @@ -774,7 +826,7 @@ fn writeSel(p: *Pardes, req: Req, pane: *Pane) Reply { const start = if (going_on) pf.wrsel.q0 else clip(q0); pf.wrsel = .{ .q0 = start, .q1 = clip(q0 + take) }; pf.wrsel_by = req.handle; - setDot(p.settings.tab, pane, pf.wrsel); + setFileDot(p.settings.tab, pane, pf.wrsel); return .{ .tag = req.tag, .written = @intCast(take) }; } @@ -796,12 +848,13 @@ pub const e_addr_failed = "no address: the last one written to addr failed"; /// that does not evaluate says why: `bad address syntax`, `no match for /// regexp`, `address out of range`, `bad regular expression`, `addresses /// out of order`. -fn writeRange(tab: u16, req: Req, pane: *Pane, file: PaneFile) Reply { +fn writeRange(p: *Pardes, req: Req, pane: *Pane, file: PaneFile) Reply { + const tab = p.settings.tab; // A terminal, an image or a PDF has no text an address names: refused // alike for addr, dot and limit, before the expression is read. if (fileOf(pane) == null) return tree.failText(req.tag, E.INVAL, e_no_text_address); const pf = &pane.fs; - const text = bodyOf(pane); + const text = bodyOf(p, pane); clampAddr(pf, text.len); const expr = std.mem.trimEnd(u8, req.data, "\n"); // One that goes from the address (`.`, `+`, `-`) has none to go from @@ -842,7 +895,7 @@ fn writeRange(tab: u16, req: Req, pane: *Pane, file: PaneFile) Reply { }, .limit => pf.limit = range, // Setting dot scrolls to it, which is the whole of acme's `show`. - .dot => setDot(tab, pane, range), + .dot => setFileDot(tab, pane, range), else => unreachable, } return .{ .tag = req.tag, .written = @intCast(req.data.len) }; @@ -1011,25 +1064,25 @@ pub fn truncate(p: *Pardes, pane: *Pane, file: PaneFile) tree.Status { .body => if (fileOf(pane) != null) { pf.joined = null; const was = fileOf(pane).?.revision; - _ = spliceBody(p, pane, 0, bodyOf(pane).len, "") orelse return .err; + _ = spliceBody(p, pane, 0, bodyOf(p, pane).len, "") orelse return .err; // An empty body truncated is no edit: the write after it makes // the step, rather than join one that was never pushed. pf.joined = if (fileOf(pane).?.revision != was) fileOf(pane).?.revision else null; pf.joined_by = 0; pf.addr = .{}; - setDot(p.settings.tab, pane, .{}); + setFileDot(p.settings.tab, pane, .{}); }, .data, .xdata => if (fileOf(pane) != null) { - clampAddr(pf, bodyOf(pane).len); + clampAddr(pf, bodyOf(p, pane).len); const q0 = pf.addr.q0; const q1 = @max(q0, pf.addr.q1); - const before = dotOf(pane); + const before = fileDot(pane); pf.joined = null; const was = fileOf(pane).?.revision; _ = spliceBody(p, pane, q0, q1, "") orelse return .err; pf.joined = if (fileOf(pane).?.revision != was) fileOf(pane).?.revision else null; pf.joined_by = 0; - setDot(p.settings.tab, pane, .{ .q0 = shiftOne(before.q0, q0, q1 - q0, 0), .q1 = shiftOne(before.q1, q0, q1 - q0, 0) }); + setFileDot(p.settings.tab, pane, .{ .q0 = shiftOne(before.q0, q0, q1 - q0, 0), .q1 = shiftOne(before.q1, q0, q1 - q0, 0) }); pf.addr = .{ .q0 = q0, .q1 = q0 }; }, // Done with the write after it, which may yet be refused. @@ -1067,7 +1120,7 @@ test "rows through the line index are the ones counting newlines gives, at every const pane = p.panes[0].?; const f = &pane.file.?; _ = try panes.File.lineIndex(p.gpa, f); - const text = bodyOf(pane); + const text = bufferOf(pane); try testing.expect(lineIndex(pane, text) != null); for (0..text.len + 2) |off| { try testing.expectEqual(modal.positionAt(text, off), positionAt(pane, text, off)); |
