diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-21 18:47:01 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-21 21:34:04 -0300 |
| commit | 0d7879195a05b450877d2bf6bd625c01fbfbef8a (patch) | |
| tree | 78ee67251d7919335c2a7ac5e06afe2bbf158f24 /core/File.zig | |
| parent | b7e843256982f5a22954d103bb40264daf2bb758 (diff) | |
| download | pardes-0d7879195a05b450877d2bf6bd625c01fbfbef8a.tar.gz pardes-0d7879195a05b450877d2bf6bd625c01fbfbef8a.zip | |
layers: ghost rows (slice 5): with `Changes` shown, what the file no longer has is drawn where it stood, rows of their own with no number and dimmer ink (`jj.Ghost`, kept with jj's answers, `Changes.ghosts` in `at` order, their text in `Changes.ghost_text` beside the hunks' removed lines): a line a pinned change took away whole, red across, in the line numbers' grey, placed by carrying the place it was taken from through the later pins' hunks into the shown text (`jj.carried`), and each pin's description after its last line (`id title author age`, the id's first four letters, the author's first name, the age short with no "ago", in its lane's colour, the author and age grey; the age is of the wall clock jj's answer carries, read where jj runs, an input as jj's answer is), the descriptions of blocks that close just above a place first and newest first, then the lines taken away there, then the descriptions of pins that have only those; a ghost row carries its own pin's lane and those of the line above that run on below it or close at or after it (`jj.ghostLanes`); the view's geometry takes the rows (`File.fillBody`'s ghosted instance, only while this view shows the changes and there are some: a ghost row's `wrap_col` is `-1 - ` its index, its `wrap_line` the line it stands before; `Pane.ghosts`/`ghost_text`, derived, set by `jj.showGhosts` each step while shown and as an answer lands), so the rows below move down in this view alone (another view with the lanes hidden is unmoved: tested); `wrapAt` says `ghost` and answers the line below at its start, so the cursor steps over them (`j` from the line above lands on the line below), selection, search hits, places and tables do not paint them, the line numbers skip them, a page ends before one; a Look (B3) on one opens its line in the revision it came from (`path@id-:line` for a line taken away, `path@id:line` for a description: `jj.lookGhost`); `]g` and `[g` (helix's, free in pardes's map: `goto_change`) go to the next and the previous change's first line (`jj.nextChange`); edits carry them as the lines' values (`jj.splice`: a ghost row stands before the line it stood before; one before a line taken out stands before the line after what took its place); in a terminal and in a window (tested both); round 3's lanes test reads each line's row through the view's map; tests: what the rows show (text, numbers, lanes by pin, grounds, inks) in both frontends and the other view unmoved; the cursor, the selection, `]g`/`[g` and a Look; the rows riding through two deletions with a client replaying them equal
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/File.zig')
| -rw-r--r-- | core/File.zig | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/core/File.zig b/core/File.zig index 8749417f..a94353d5 100644 --- a/core/File.zig +++ b/core/File.zig @@ -1234,6 +1234,7 @@ fn pageEnd(tab: u16, pane: *Pane) usize { if (pane.wrap_n == 0) return f.scroll + pane.rows; const last = (if (pane.body_visible_rows > 0) @min(pane.wrap_n, pane.body_visible_rows) else pane.wrap_n) - 1; const line: usize = @intCast(pane.wrap_line[last]); + if (pane.wrap_col[last] < 0) return @max(line, f.scroll + 1); if (!pane.body_wrapped or line >= nlines(pane.gpa, f)) return line + 1; const text = sourceLine(pane, @intCast(line)); const width = wrapWidth(pane, pane.view.wrap) -| pane.wrap_pad[last]; @@ -1705,7 +1706,8 @@ pub fn visualRow(tab: u16, line: []const u8, col: usize, width: usize) VisualRow pub fn bodyText(tab: u16, arena: std.mem.Allocator, pane: *Pane, f: *State) ![]const u8 { geometry(tab, pane); const out = try arena.alloc(u8, pane.geometry_len); - const filled = fillBody(tab, out, pane, f, wrapWidth(pane, pane.view.wrap), false); + const width = wrapWidth(pane, pane.view.wrap); + const filled = if (hasGhosts(pane)) fillBody(true, tab, out, pane, f, width, false) else fillBody(false, tab, out, pane, f, width, false); std.debug.assert(filled == out.len); return out; } @@ -1749,7 +1751,13 @@ fn mapRows(tab: u16, pane: *Pane, f: *State) usize { pane.body_wrapped = width > 0; f.tables.ensure(tab, pane.gpa, f); prepareContextRows(pane, f); - return fillBody(tab, null, pane, f, width, true); + return if (hasGhosts(pane)) fillBody(true, tab, null, pane, f, width, true) else fillBody(false, tab, null, pane, f, width, true); +} + +/// Whether this view of the pane shows ghost rows (jj.zig): its pinned +/// changes shown, and some. +fn hasGhosts(pane: *const Pane) bool { + return pane.layers.lanes > 0 and pane.ghosts.len > 0; } /// Everything the geometry is made of, hashed: the text (its revision and @@ -1776,7 +1784,10 @@ fn geometryKey(pane: *const Pane, f: *const State) u64 { /// Run the file-body row walk. With no destination it is the exact sizing /// pass; with one it fills that allocation and records the wrapping map. -fn fillBody(tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) usize { +/// `ghosted`: the view shows ghost rows (`Pane.ghosts`), each a row of its +/// own before the line it stands at, no number, its text cut to the row; a +/// body with none walks without them. +fn fillBody(comptime ghosted: bool, tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_wrap: bool) usize { if (record_wrap) pane.wrap_n = 0; const prefix_width = gutterWidth(pane); // Where a number ends: a blank, then the lanes (laneCells), after it. @@ -1788,12 +1799,35 @@ fn fillBody(tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_w var body_line: usize = f.scroll; var body_at: usize = 0; var written: usize = 0; + // The first ghost row at or below the top line. + var ghost: usize = 0; + if (ghosted) while (ghost < pane.ghosts.len and pane.ghosts[ghost].at < f.scroll) { + ghost += 1; + }; for (0..if (pane.body_rows > 0) pane.body_rows else pane.rows) |i| { if (i > 0) { if (dst) |out| out[written] = '\n'; written += 1; } const context = i < pane.context_rows; + if (ghosted and !context and body_at == 0 and ghost < pane.ghosts.len and pane.ghosts[ghost].at == body_line) { + const g = pane.ghosts[ghost]; + const said = pane.ghost_text[g.text..][0..g.len]; + const shown = if (width > 0) said[0..fitEnd(tab, said, 0, width)] else said[modal.graphemeStart(said, @min(@as(usize, @intCast(@max(0, pane.hscroll))), said.len))..]; + if (record_wrap) { + pane.wrap_line[i] = @intCast(body_line); + pane.wrap_col[i] = -1 - @as(i32, @intCast(ghost)); + pane.wrap_pad[i] = 0; + pane.wrap_n = @intCast(i + 1); + } + if (dst) |out| { + @memset(out[written..][0..prefix_width], ' '); + @memcpy(out[written + prefix_width ..][0..shown.len], shown); + } + written += prefix_width + shown.len; + ghost += 1; + continue; + } const row = if (context) @as(usize, @intCast(pane.wrap_line[i])) else body_line; const at = if (context) 0 else body_at; const text = if (row < total) sourceLine(pane, @intCast(row)) else ""; @@ -1811,7 +1845,7 @@ fn fillBody(tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_w modal.graphemeStart(text, @min(@as(usize, @intCast(pane.hscroll)), text.len)) else at; - if ((width > 0 or pane.context_rows > 0) and record_wrap) { + if ((width > 0 or pane.context_rows > 0 or ghosted) and record_wrap) { pane.wrap_line[i] = @intCast(row); pane.wrap_col[i] = @intCast(cut); pane.wrap_pad[i] = @intCast(pad); @@ -1957,6 +1991,7 @@ pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes. limit = line.len; } else { if (vr >= pane.wrap_n) break; + if (pane.wrap_col[vr] < 0) continue; const lrow: usize = @intCast(@max(0, pane.wrap_line[vr])); if (lrow >= total) break; base = lineStart(p.gpa, f, lrow); @@ -2104,7 +2139,7 @@ pub fn paintWordSelection( var vr: i32 = 0; while (vr + @as(i32, pane.tag_rows) < @as(i32, r.h)) : (vr += 1) { const here = pane.wrapAt(p.settings.tab, vr); - if (here.line != row) continue; + if (here.line != row or here.ghost) continue; var hi = word_hi; const next = pane.wrapAt(p.settings.tab, vr + 1); if (next.line == row) hi = @min(hi, next.at); |
