summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-22 02:37:06 -0300
committerGabriel Schneider <[email protected]>2026-11-22 02:37:06 -0300
commit58180ae7574b5050331797f0ead1a1cec753b2ed (patch)
tree4a866bdfc968afe58f1f954f969b9c0ab00bc449
parent245dd088a5b502c72f94c85bf1cc5bd0ba7ebb56 (diff)
parent2015baa4ccd26a74b51e7b7cda0eb3533a325142 (diff)
downloadpardes-58180ae7574b5050331797f0ead1a1cec753b2ed.tar.gz
pardes-58180ae7574b5050331797f0ead1a1cec753b2ed.zip
integration: the tree to install: every client's terminals by the pty's bytes, and the source view's changes to the whole mock: pardes-flip (`uxzzxrtt`, on pardes-merge54: the one road by default, the old one behind PARDES_TERM_SCREEN until it is deleted; a client takes its road from the session's welcome: the wire at 29; the predicted echo kept on the one road; the user's ruling of 2026-11-22) and pardes-layers-5 (`qurmskql` on `yxupukvr` on `tllltqkq` on `qwvwsoww`, on pardes-layers-4: a terminal's output pays less for the layers with `Changes` off; ghost rows: a line taken away whole red across, each change's description after its last line; a changed line's words by the patch view's alignment; `]g` and `[g`; a description row keeps its author and age, a change's rows come before its own description); no conflict; core-test 911/1075 (164 skipped), shell-test 1117/1120; its gate: .scratch/sketch/reorg/merge55, the numbers in PARDES.md (2026-11-22)
Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
-rw-r--r--core/Core.zig1
-rw-r--r--core/File.zig65
-rw-r--r--core/Places.zig5
-rw-r--r--core/Query.zig5
-rw-r--r--core/Tables.zig1
-rw-r--r--core/body_layer.zig9
-rw-r--r--core/builtins.zig2
-rw-r--r--core/config.zig1
-rw-r--r--core/jj.zig941
-rw-r--r--core/modal.zig1
-rw-r--r--core/mouse.zig8
-rw-r--r--core/normal.zig5
-rw-r--r--core/panes.zig20
-rw-r--r--core/root.zig3
-rw-r--r--docs/typ/builtins-gui.json2
-rw-r--r--docs/typ/builtins-tui.json2
-rw-r--r--docs/typ/guide.typ13
17 files changed, 991 insertions, 93 deletions
diff --git a/core/Core.zig b/core/Core.zig
index a800cb68..72e92212 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -1913,6 +1913,7 @@ pub fn sync(p: *Pardes) void {
// and its context declarations.
if (pane.file) |*f| pardes.panes.File.refreshContext(p, pane, f);
pane.view = .{ .wrap = p.settings.wrap, .body_h = v.row_metrics.body_h, .tagline_h = v.row_metrics.tagline_h, .rect_h = r.h };
+ if (pane.layers.lanes > 0) @import("jj.zig").showGhosts(p, pane);
// The tag takes a row per line, leaving the body one row if it
// had any; a folded pane shows its first line only. Its prefix
// is made once, on the stack: this runs on every event, and not
diff --git a/core/File.zig b/core/File.zig
index 8749417f..347f4809 100644
--- a/core/File.zig
+++ b/core/File.zig
@@ -19,6 +19,7 @@ const locations = @import("locations.zig");
const Colors = @import("colors.zig");
const Tables = @import("Tables.zig");
const Stream = @import("Stream.zig");
+const jj = @import("jj.zig");
const Pane = panes.Pane;
const Output = panes.Output;
const Mini = panes.mini;
@@ -399,7 +400,7 @@ pub fn renderedLineDisplayCol(tab: u16, pane: *const Pane, row: i32, line_text:
return prefix +| rawDisplayCol(tab, line_text[prefix..], byte_col - prefix);
}
-fn fitEnd(tab: u16, text: []const u8, start: usize, width: usize) usize {
+pub fn fitEnd(tab: u16, text: []const u8, start: usize, width: usize) usize {
var end = start;
var used: usize = 0;
while (used < width and end < text.len) {
@@ -757,7 +758,7 @@ fn edit(p: *Pardes, f: *State, off: usize, len: usize, bytes_in: []const u8, who
};
reportEdit(p, f, off, len, bytes);
// A pinned change's per-line values ride with the lines (jj.zig).
- if (p.changes.answers.items.len > 0) @import("jj.zig").edited(p, f, off, len, bytes);
+ if (p.changes.answers.items.len > 0) jj.edited(p, f, off, len, bytes);
if (f.mini) |*mini| mini.deinit(p.gpa);
f.mini = null;
if (f.line_starts.len > 0) shiftIndex(p.gpa, f, off, len, bytes);
@@ -1234,6 +1235,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];
@@ -1658,7 +1660,7 @@ fn paintAhead(p: *Pardes, pane: *Pane, f: *State) void {
/// The path a text's language is known by: a file at a revision's
/// (jj.zig) without its `@rev`.
pub fn langPath(f: *const State) []const u8 {
- return if (@import("jj.zig").of(f)) |r| r.path else f.path;
+ return if (jj.of(f)) |r| r.path else f.path;
}
pub fn supportsContext(pane: *const Pane) bool {
@@ -1685,6 +1687,12 @@ fn prepareContextRows(pane: *Pane, file: *State) void {
pub fn wrapWidth(pane: *const Pane, wrap: bool) usize {
if (!wrap or pane.rows > pane.wrap_line.len) return 0;
+ return bodyWidth(pane);
+}
+
+/// The cells a body row has for text after the gutter (and a cell for a
+/// wrapped line's marker).
+pub fn bodyWidth(pane: *const Pane) usize {
return @max(1, @as(usize, pane.cols -| gutterWidth(pane)) -| 1);
}
@@ -1705,7 +1713,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 +1758,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 +1791,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 +1806,42 @@ 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];
+ var fit: [jj.row_max]u8 = undefined;
+ // A description is one compact row whatever the scroll.
+ const shown = if (g.kind == .description)
+ jj.fitted(tab, said, bodyWidth(pane), &fit)
+ else 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 +1859,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 +2005,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 +2153,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);
diff --git a/core/Places.zig b/core/Places.zig
index 35b79805..c81c7264 100644
--- a/core/Places.zig
+++ b/core/Places.zig
@@ -669,8 +669,9 @@ pub fn paint(set: *Places, p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect,
var last_line: i32 = -1;
var vr: i32 = 0;
while (vr < body_h) : (vr += 1) {
- const line = pane.wrapAt(p.settings.tab, vr).line;
- if (line == last_line or line < 0) continue;
+ const w = pane.wrapAt(p.settings.tab, vr);
+ const line = w.line;
+ if (line == last_line or line < 0 or w.ghost) continue;
if (line >= nlines) break;
last_line = line;
const ls = File.lineStart(p.gpa, f, @intCast(line));
diff --git a/core/Query.zig b/core/Query.zig
index e2f59028..2ffcfd3b 100644
--- a/core/Query.zig
+++ b/core/Query.zig
@@ -2086,8 +2086,9 @@ pub fn paint(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, body_h: u16)
var vr: i32 = 0;
var last: i32 = -1;
while (vr < body_h) : (vr += 1) {
- const row = pane.wrapAt(p.settings.tab, vr).line;
- if (row == last or row < 1) continue;
+ const w = pane.wrapAt(p.settings.tab, vr);
+ const row = w.line;
+ if (row == last or row < 1 or w.ghost) continue;
last = row;
const i: usize = @intCast(row - 1);
if (i >= q.items.items.len or @as(usize, @intCast(row)) >= f.location_rows.len) continue;
diff --git a/core/Tables.zig b/core/Tables.zig
index a0256d8a..61a67bfe 100644
--- a/core/Tables.zig
+++ b/core/Tables.zig
@@ -660,6 +660,7 @@ pub fn paint(p: *Pardes, s: *Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw:
var vr: u16 = 0;
while (vr < body_h) : (vr += 1) {
const w = pane.wrapAt(p.settings.tab, vr);
+ if (w.ghost) continue;
const table = File.rowTable(pane, w.line) orelse continue;
const text = File.sourceLine(pane, w.line);
var buf: [max_pads]Pad = undefined;
diff --git a/core/body_layer.zig b/core/body_layer.zig
index 28b86f78..817176bb 100644
--- a/core/body_layer.zig
+++ b/core/body_layer.zig
@@ -88,6 +88,7 @@ fn paintSourceSelection(p: *Pardes, s: *Surface, pane: *Pane, r: Rect, rows: []c
var visible: i32 = 0;
while (visible < @as(i32, r.h -| pane.tag_rows)) : (visible += 1) {
const source = pane.wrapAt(p.settings.tab, visible);
+ if (source.ghost) continue;
const line = edit.pointerSourceLine(pane, terminal_lines, source.line);
const start = @min(line.len, @as(usize, @intCast(@max(0, source.at))));
const next = pane.wrapAt(p.settings.tab, visible + 1);
@@ -280,7 +281,7 @@ fn drawWrapMarkers(
const marker_fg = p.chromeTheme().lineno;
var row: u16 = 0;
while (row + 1 < pane.wrap_n and row + 1 < body_h) : (row += 1) {
- if (pane.wrap_line[row + 1] != pane.wrap_line[row]) continue;
+ if (pane.wrap_line[row + 1] != pane.wrap_line[row] or pane.wrap_col[row] < 0) continue;
s.set(tx + tw - 1, body_y + row, config.wrap_marker, .{
.fg = .{ .rgb = marker_fg },
.bg = pane_bg,
@@ -338,7 +339,9 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
// File layout is independent of whether its producer requests colors.
if (pane.file) |*f| {
drawGutter(p, s, pane, r, tx, tw, body_h, active);
- if (pane.layers.lanes > 0) @import("jj.zig").paint(p, s, pane, r, tx, tw, body_h);
+ // Never inlined: in renderBody's own frame it cost every body a
+ // frame (a terminal's output about 33,000 instructions a pump).
+ if (pane.layers.lanes > 0) @call(.never_inline, @import("jj.zig").paint, .{ p, s, pane, r, tx, tw, body_h });
panes.Query.paintMark(p, s, pane, r, body_h);
if (pane.colorAlgo() != .none)
panes.File.recolorSyntax(p, s, pane, f, r, tx, tw, body_h);
@@ -404,7 +407,7 @@ pub fn renderBody(p: *Pardes, s: *Surface, arena: std.mem.Allocator, pane: *Pane
var vr: i32 = 0;
while (vr + @as(i32, pane.tag_rows) < @as(i32, body_bottom)) : (vr += 1) {
const w = pane.wrapAt(p.settings.tab, vr);
- if (w.line < bnd.lo_row or w.line > bnd.hi_row) continue;
+ if (w.line < bnd.lo_row or w.line > bnd.hi_row or w.ghost) continue;
const visible_line = modal.lineSlice(body, @intCast(vr));
// Only the visible columns are measured: a selection that
// starts before this row's first column starts at it, and
diff --git a/core/builtins.zig b/core/builtins.zig
index 77fc58ed..7485af81 100644
--- a/core/builtins.zig
+++ b/core/builtins.zig
@@ -1080,7 +1080,7 @@ pub const At = struct {
pub const run = @import("jj.zig").word;
};
-/// Pin the changes `revset` names (jj) on a file's pane and show them in this view: a lane each after the line number, a line one added whole green; bare, shown here or not (none pinned yet: `@`).
+/// Pin the changes `revset` names (jj) on a file's pane and show them in this view: a lane each after the line number, a line one added whole green, what the file no longer has drawn where it stood (ghost rows: a line taken away whole red, each change's description after its last line); bare, shown here or not (none pinned yet: `@`).
pub const Changes = struct {
pub const takes_arg = true;
pub const run = @import("jj.zig").changesWord;
diff --git a/core/config.zig b/core/config.zig
index 6338c5d1..1f5819c9 100644
--- a/core/config.zig
+++ b/core/config.zig
@@ -514,6 +514,7 @@ pub const goto_paragraph: []const Chord = &.{.{ .cp = 'p' }};
pub const add_newline: []const Chord = &.{.{ .cp = ' ' }};
pub const goto_diagnostic: []const Chord = &.{.{ .cp = 'd' }};
pub const goto_diagnostic_end: []const Chord = &.{.{ .cp = 'D' }};
+pub const goto_change: []const Chord = &.{.{ .cp = 'g' }};
pub const goto_function: []const Chord = &.{.{ .cp = 'f' }};
pub const goto_class: []const Chord = &.{.{ .cp = 't' }};
pub const goto_parameter: []const Chord = &.{.{ .cp = 'a' }};
diff --git a/core/jj.zig b/core/jj.zig
index 0cdf94a1..dd54dfc5 100644
--- a/core/jj.zig
+++ b/core/jj.zig
@@ -221,14 +221,22 @@ pub const Changes = struct {
lines: []Line = &.{},
/// Each pin's hunks in the file, a pin's together, each in place order.
hunks: []Hunk = &.{},
- /// The lines the hunks took away, hunk after hunk, each with its `\n`.
- removed: []u8 = &.{},
+ /// The ghost rows' text: the lines the hunks took away, hunk after
+ /// hunk, each with its `\n`; then each pin's description row.
+ ghost_text: []u8 = &.{},
+ /// The rows a view shows that the text has not, in `at` order.
+ ghosts: []Ghost = &.{},
+ /// The words a changed line changed: byte ranges of a line (`Line`), or
+ /// of `ghost_text` (`Ghost`), each `.{ from, to }`.
+ marks: [][2]u32 = &.{},
pub fn deinit(c: *Changes, gpa: std.mem.Allocator) void {
gpa.free(c.pins);
gpa.free(c.lines);
gpa.free(c.hunks);
- gpa.free(c.removed);
+ gpa.free(c.ghost_text);
+ gpa.free(c.ghosts);
+ gpa.free(c.marks);
c.* = .{ .serial = c.serial };
}
@@ -275,6 +283,10 @@ pub const Line = struct {
whole: bool = false,
/// The pins whose lanes run down it, outermost (oldest) first (`nest`).
lanes: [levels]PinIndex = @splat(.none),
+ /// A changed line's words that came (`Changes.marks[marks..][0..nmarks]`,
+ /// byte ranges of the line).
+ marks: u32 = 0,
+ nmarks: u16 = 0,
};
/// The lanes a row shows at most: the ruled gutter fits three.
@@ -292,14 +304,49 @@ pub const pins_max = 64;
/// revisions' numbers (from 1; `old_len` 0: it only wrote, after old line
/// `old_start`).
pub const Hunk = struct {
+ /// Its pin, or `carrier`: a change between the pins the revset does
+ /// not pin (its hunks only carry places, `carried`).
pin: u16,
+ /// Its change's place in jj's answer, oldest first.
+ step: u16,
old_start: u32,
old_len: u32,
new_start: u32,
new_len: u32,
- /// Its removed lines' text: `Changes.removed[removed..][0..removed_len]`.
+ /// Its removed lines' text: `Changes.ghost_text[removed..][0..removed_len]`.
removed: u32,
removed_len: u32,
+
+ pub const carrier = std.math.maxInt(u16);
+};
+
+/// A row a view shows that is not a line of the text (PARDES.md "Changes on
+/// the source view": a ghost row): a line a pin took away whole, drawn where
+/// it stood, red across; or a pin's description (`id title author age`),
+/// after its last line, in its lane's colour. No number, the cursor steps
+/// over it, search and selection do not see it; a Look on it goes to its
+/// line in the revision it came from (`lookGhost`). A line a pin CHANGED
+/// is a ghost row too: its old text right above the line, the words that
+/// went in red, the line with the words that came in green.
+pub const Ghost = struct {
+ /// The line of the shown text it stands before (`lines.len`: after the
+ /// last). It rides with the text as the lines' values do (`splice`).
+ at: u32,
+ pin: u16,
+ kind: Kind,
+ /// Its line, from 1: a line taken away, in its pin's parent; a
+ /// description, its pin's first line written, in the pin's revision.
+ line: u32,
+ /// Its text, `Changes.ghost_text[text..][0..len]`, no `\n`.
+ text: u32,
+ len: u32,
+ /// A changed line's: the words that went (`Changes.marks`).
+ marks: u32 = 0,
+ nmarks: u16 = 0,
+
+ /// A line taken away whole; a line's old text, the line that took its
+ /// place right below it; a pin's description.
+ pub const Kind = enum(u8) { deleted, changed, description };
};
/// The `Changes` word (builtins.zig registers it): in a file's pane (or a
@@ -480,16 +527,27 @@ fn answer(p: ?*Pardes, gpa: std.mem.Allocator, a: *const Ask) pardes.Stream.Batc
const set = fileset(gpa, a.path) catch return failed(gpa, a, refusal(gpa, "out of memory").refused);
defer gpa.free(set);
// The changes, oldest first, each with its diff of the file: one run.
- const query = std.fmt.allocPrint(gpa, "({s}) & files({s})", .{ a.revset, set }) catch return failed(gpa, a, refusal(gpa, "out of memory").refused);
+ // With them the changes between the first and the shown revision that
+ // the revset does not pin (marked so), whose hunks move the places of
+ // the lines the older pins took away.
+ const query = std.fmt.allocPrint(gpa, "(({s}) | (roots({s})::({s}))) & files({s})", .{ a.revset, a.revset, a.rev, set }) catch return failed(gpa, a, refusal(gpa, "out of memory").refused);
defer gpa.free(query);
- const log_args = [_][]const u8{ "log", "--no-graph", "--reversed", "-r", query, "-T", log_template, "--git", "--context=0", "--", set };
+ const template = logTemplate(gpa, a.revset) catch return failed(gpa, a, refusal(gpa, "out of memory").refused);
+ defer gpa.free(template);
+ const log_args = [_][]const u8{ "log", "--no-graph", "--reversed", "-r", query, "-T", template, "--git", "--context=0", "--", set };
const logged = switch (runJj(p, gpa, dirOf(a.path), &log_args)) {
.refused => |why| return failed(gpa, a, why),
- .bytes => |bytes| bytes,
+ // The wall clock first, read where jj runs (an input, as jj's
+ // answer is): the descriptions' ages are of it.
+ .bytes => |bytes| stamped: {
+ defer gpa.free(bytes);
+ const now = if (p) |q| q.tape.value(.clock, wallSeconds, .{}) else wallSeconds();
+ break :stamped std.fmt.allocPrint(gpa, "{d}\n{s}", .{ now, bytes }) catch return failed(gpa, a, refusal(gpa, "out of memory").refused);
+ },
};
var it = std.mem.splitScalar(u8, logged, '\n');
const any = while (it.next()) |l| {
- if (pinOf(l) != null) break true;
+ if (if (entryOf(l)) |e| e.pinned else false) break true;
} else false;
if (!any) return .{ .gen = a.gen, .rows = logged, .end = .done };
// Who wrote each line: a path, not a fileset (annotate takes one file
@@ -504,6 +562,14 @@ fn answer(p: ?*Pardes, gpa: std.mem.Allocator, a: *const Ask) pardes.Stream.Batc
};
}
+/// The wall clock, in seconds since the epoch (a `.clock` read as `u32`:
+/// a replica's guess and a stamp answer it so too).
+fn wallSeconds() u32 {
+ var ts: std.c.timespec = undefined;
+ if (std.c.clock_gettime(.REALTIME, &ts) != 0) return 0;
+ return std.math.cast(u32, ts.sec) orelse 0;
+}
+
fn runJj(p: ?*Pardes, gpa: std.mem.Allocator, dir: []const u8, args: []const []const u8) Shown {
return if (p) |q| q.tape.site(.jj, gpa, runHost, .{ gpa, dir, args }) else runHost(gpa, dir, args);
}
@@ -550,6 +616,7 @@ pub fn edited(p: *Pardes, f: *const File.State, off: usize, len: usize, bytes: [
// No room for it: its values would lie, so it goes.
c.deinit(p.gpa);
_ = p.changes.answers.swapRemove(i);
+ showGhosts(p, p.panes[id].?);
};
}
}
@@ -575,6 +642,12 @@ fn splice(gpa: std.mem.Allocator, c: *Changes, text: []const u8, off: usize, len
@memcpy(next[from + put ..], c.lines[from + take ..]);
gpa.free(c.lines);
c.lines = next;
+ // A ghost row stands before the line it stood before; one before a
+ // line taken out, before the line after what took its place.
+ for (c.ghosts) |*g| {
+ if (g.at <= from) continue;
+ g.at = @intCast(if (g.at < from + take) from + put else g.at - take + put);
+ }
}
/// jj's answer `b` for `revset` parsed and pinned on pane `id`, or its
@@ -611,10 +684,24 @@ fn pinAnswer(p: *Pardes, id: usize, b: *const pardes.Stream.Batch, revset: []con
return p.reportFailure(id, "Changes: out of memory");
};
p.setStatus(.at(id), "");
+ showGhosts(p, pane);
},
}
}
+/// The pane's ghost rows as its geometry reads them (`Pane.ghosts`): the
+/// session's answers' (one set a pane), its geometry made again when they
+/// change (each step while a view shows them, and as an answer lands).
+pub fn showGhosts(p: *Pardes, pane: *Pane) void {
+ const ch = answered(p, pane.serial);
+ const ghosts: []const Ghost = if (ch) |c| c.ghosts else &.{};
+ const text: []const u8 = if (ch) |c| c.ghost_text else "";
+ if (ghosts.ptr == pane.ghosts.ptr and ghosts.len == pane.ghosts.len and text.ptr == pane.ghost_text.ptr) return;
+ pane.ghosts = ghosts;
+ pane.ghost_text = text;
+ pane.geometry_key = 0;
+}
+
const Read = union(enum) { refused: []u8, read: Changes };
/// jj's answers parsed: `logged` (the pins, each with its diff of the
@@ -622,49 +709,70 @@ const Read = union(enum) { refused: []u8, read: Changes };
/// shows: a line is matched to the line its change added by its text).
fn parse(gpa: std.mem.Allocator, arena: std.mem.Allocator, logged: []const u8, annotated: []const u8, text: []const u8) error{OutOfMemory}!Read {
var out: Changes = .{ .serial = 0 };
+ const now = std.fmt.parseInt(i64, logged[0 .. std.mem.indexOfScalar(u8, logged, '\n') orelse logged.len], 10) catch 0;
var kept = false;
defer if (!kept) out.deinit(gpa);
var pins: std.ArrayList(Pin) = .empty;
defer pins.deinit(gpa);
- // Where each pin's diff starts in `logged`, and the end.
- var diffs: std.ArrayList(usize) = .empty;
+ // Each change jj answered, oldest first: its pin (or `Hunk.carrier`)
+ // and where its diff starts in `logged`; then the end.
+ const Step = struct { pin: u16, diff: usize };
+ var steps: std.ArrayList(Step) = .empty;
var it = std.mem.splitScalar(u8, logged, '\n');
- while (it.next()) |l| if (pinOf(l)) |pin| {
- if (pins.items.len == pins_max) return .{ .refused = try std.fmt.allocPrint(gpa, "more than {d} changes touch it", .{pins_max}) };
- try pins.append(gpa, pin);
- try diffs.append(arena, it.index orelse logged.len);
+ while (it.next()) |l| if (entryOf(l)) |e| {
+ if (e.pinned and pins.items.len == pins_max) return .{ .refused = try std.fmt.allocPrint(gpa, "more than {d} changes touch it", .{pins_max}) };
+ if (steps.items.len == Hunk.carrier) return .{ .refused = try std.fmt.allocPrint(gpa, "more than {d} changes between them touch it", .{Hunk.carrier}) };
+ if (e.pinned) try pins.append(gpa, e.pin);
+ try steps.append(arena, .{ .pin = if (e.pinned) @intCast(pins.items.len - 1) else Hunk.carrier, .diff = it.index orelse logged.len });
};
- try diffs.append(arena, logged.len);
+ try steps.append(arena, .{ .pin = Hunk.carrier, .diff = logged.len });
out.pins = try pins.toOwnedSlice(gpa);
if (out.pins.len == 0) {
kept = true;
return .{ .read = out };
}
- out.lines = try provenance(gpa, arena, annotated, out.pins, text);
- // Each change's hunks, and which of its lines it added whole.
+ var moved: Moved = undefined;
+ out.lines = try provenance(gpa, arena, annotated, out.pins, text, &moved);
+ // Each change's hunks, and which of its lines a pin added whole.
var hunks: std.ArrayList(Hunk) = .empty;
defer hunks.deinit(gpa);
var removed: std.ArrayList(u8) = .empty;
defer removed.deinit(gpa);
- for (0..out.pins.len) |k| try hunksOf(gpa, arena, @intCast(k), logged[diffs.items[k]..diffs.items[k + 1]], text, out.lines, &hunks, &removed);
+ var marks: std.ArrayList([2]u32) = .empty;
+ defer marks.deinit(gpa);
+ var taken: std.ArrayList(Taken) = .empty;
+ for (steps.items[0 .. steps.items.len - 1], steps.items[1..], 0..) |s, next, i| try hunksOf(gpa, arena, s.pin, @intCast(i), logged[s.diff..next.diff], text, out.lines, &hunks, &removed, &marks, &taken);
out.hunks = try hunks.toOwnedSlice(gpa);
- out.removed = try removed.toOwnedSlice(gpa);
nest(out.lines, out.pins.len);
+ out.ghosts = try ghostsOf(gpa, arena, out.pins, out.lines, out.hunks, taken.items, &removed, now, moved);
+ out.ghost_text = try removed.toOwnedSlice(gpa);
+ out.marks = try marks.toOwnedSlice(gpa);
kept = true;
return .{ .read = out };
}
-/// `jj log`'s line a change, before its diff: its id, its author's time,
-/// its author, its description's first line, a tab between.
-const log_template = "change_id.short(8) ++ \"\\t\" ++ author.timestamp().utc().format(\"%s\") ++ \"\\t\" ++ author.name() ++ \"\\t\" ++ description.first_line() ++ \"\\n\"";
+/// `jj log`'s line a change, before its diff: its id, `p` when `revset`
+/// pins it (else `c`), its author's time, its author, its description's
+/// first line, a tab between.
+fn logTemplate(gpa: std.mem.Allocator, revset: []const u8) error{OutOfMemory}![]u8 {
+ var t: std.ArrayList(u8) = .empty;
+ errdefer t.deinit(gpa);
+ try t.appendSlice(gpa, "change_id.short(8) ++ \"\\t\" ++ if(self.contained_in(\"");
+ for (revset) |c| {
+ if (c == '"' or c == '\\') try t.append(gpa, '\\');
+ try t.append(gpa, c);
+ }
+ try t.appendSlice(gpa, "\"), \"p\", \"c\") ++ \"\\t\" ++ author.timestamp().utc().format(\"%s\") ++ \"\\t\" ++ author.name() ++ \"\\t\" ++ description.first_line() ++ \"\\n\"");
+ return t.toOwnedSlice(gpa);
+}
-/// A `log_template` line, or null for a line of a diff (which starts with
+/// A `logTemplate` line, or null for a line of a diff (which starts with
/// a blank, a sign, `@`, `\\` or a word and a blank: never eight of jj's
/// id letters, k to z, and a tab).
-fn pinOf(l: []const u8) ?Pin {
- if (l.len < 9 or l[8] != '\t') return null;
+fn entryOf(l: []const u8) ?struct { pin: Pin, pinned: bool } {
+ if (l.len < 11 or l[8] != '\t' or l[10] != '\t') return null;
for (l[0..8]) |c| if (c < 'k' or c > 'z') return null;
- var cols = std.mem.splitScalar(u8, l[9..], '\t');
+ var cols = std.mem.splitScalar(u8, l[11..], '\t');
var pin: Pin = .{ .id = l[0..8].*, .time = std.fmt.parseInt(i64, cols.next() orelse "", 10) catch 0 };
const author = cols.next() orelse "";
pin.author_len = @intCast(@min(author.len, pin.author.len));
@@ -672,7 +780,7 @@ fn pinOf(l: []const u8) ?Pin {
const title = cols.rest();
pin.title_len = @intCast(@min(title.len, pin.title.len));
@memcpy(pin.title[0..pin.title_len], title[0..pin.title_len]);
- return pin;
+ return .{ .pin = pin, .pinned = l[9] == 'p' };
}
/// Which pin wrote each line of `text` (what the pane shows: `whole` is the
@@ -681,8 +789,9 @@ fn pinOf(l: []const u8) ?Pin {
/// the revision it annotated, which is jj's last snapshot of a file and
/// not the keys typed since): the two texts lined up by what they agree on
/// at either end (`File.spanOf`, the editor's differ: a line inside both
-/// ends keeps its owner, a line only the pane has is nobody's).
-pub fn provenance(gpa: std.mem.Allocator, arena: std.mem.Allocator, annotated: []const u8, pins: []const Pin, text: []const u8) error{OutOfMemory}![]Line {
+/// ends keeps its owner, a line only the pane has is nobody's); `moved`,
+/// where jj's lines stand in `text`.
+pub fn provenance(gpa: std.mem.Allocator, arena: std.mem.Allocator, annotated: []const u8, pins: []const Pin, text: []const u8, moved: *Moved) error{OutOfMemory}![]Line {
var owners: std.ArrayList(PinIndex) = .empty;
var was: std.ArrayList(u8) = .empty;
var rows = std.mem.splitScalar(u8, annotated, '\n');
@@ -699,8 +808,10 @@ pub fn provenance(gpa: std.mem.Allocator, arena: std.mem.Allocator, annotated: [
if (!std.mem.endsWith(u8, annotated, "\n") and was.items.len > 0) was.items.len -= 1;
const out = try gpa.alloc(Line, lineCount(text));
@memset(out, .{ .pin = .none });
+ const was_n: u32 = @intCast(owners.items.len);
if (std.mem.eql(u8, was.items, text)) {
for (out[0..@min(out.len, owners.items.len)], owners.items[0..@min(out.len, owners.items.len)]) |*l, pin| l.pin = pin;
+ moved.* = .{ .head = was_n, .tail = 0, .was = was_n, .now = was_n };
return out;
}
const span = File.spanOf(was.items, text);
@@ -711,9 +822,29 @@ pub fn provenance(gpa: std.mem.Allocator, arena: std.mem.Allocator, annotated: [
// indent with the line above) is the same line when its bytes are.
if (head + tail < @min(out.len, owners.items.len) and std.mem.eql(u8, lineFromEnd(was.items, tail), lineFromEnd(text, tail))) tail += 1;
for (out[out.len - tail ..], owners.items[owners.items.len - tail ..]) |*l, pin| l.pin = pin;
+ moved.* = .{ .head = @intCast(head), .tail = @intCast(tail), .was = was_n, .now = @intCast(out.len) };
return out;
}
+/// Where jj's lines (the revision it annotated) stand in the pane's text,
+/// which has keys typed since (before the word, never snapshotted, or
+/// while jj ran): its first `head` lines and its last `tail` are the same
+/// lines, those between were rewritten.
+pub const Moved = struct {
+ head: u32,
+ tail: u32,
+ /// jj's lines, and the text's.
+ was: u32,
+ now: u32,
+
+ /// The text's place of jj's place `at` (before its line `at`), or null
+ /// inside lines rewritten since: no place there tells the truth.
+ fn place(m: Moved, at: u32) ?u32 {
+ if (at >= m.was - m.tail) return at - (m.was - m.tail) + (m.now - m.tail);
+ return if (at <= m.head) at else null;
+ }
+};
+
/// `text`'s line `k` from its end (0: its last).
fn lineFromEnd(text: []const u8, k: usize) []const u8 {
var end = text.len - @intFromBool(std.mem.endsWith(u8, text, "\n"));
@@ -738,43 +869,92 @@ fn tailLines(text: []const u8, tail: usize) usize {
return starts + std.mem.count(u8, text[from .. text.len - 1], "\n");
}
+/// A line a pin took away (in hunk order, a pin's after another's): one
+/// line changed (`paired`, with the line it became, by its number in the
+/// pin's revision and, while it is shown, its line of the text) or taken
+/// away whole; the words that went, in `Changes.marks`.
+const Taken = struct { paired: bool, marks: u32, nmarks: u16, new: u32 = 0, shown: ?u32 = null, partner: usize = 0 };
+
/// Pin `k`'s hunks in `diffed` (its diff of the file, `--git --context=0`) onto
-/// `hunks`, their removed lines onto `removed`; and each line of `text`
-/// pin `k` wrote (`lines`) marked `whole` when the line it is, matched in
-/// order by its text, was one the change added whole: in a run of lines
-/// taken away and written, the first as many written as were taken away
-/// are changed, the rest added whole.
-fn hunksOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, k: u16, diffed: []const u8, text: []const u8, lines: []Line, hunks: *std.ArrayList(Hunk), removed: *std.ArrayList(u8)) error{OutOfMemory}!void {
- const Added = struct { text: []const u8, whole: bool };
+/// `hunks`, their removed lines onto `removed`, what became of each onto
+/// `taken`; and each line of `text` pin `k` wrote (`lines`), matched in
+/// order by its text, marked `whole` when the change added it whole, else
+/// with the words that came. Which lines a run of lines taken away and
+/// written changed, and their words, is the patch view's alignment
+/// (hunks.format: its `inferEdits`), read off its rows. A change the
+/// revset does not pin (`k` is `Hunk.carrier`): its hunks alone.
+fn hunksOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, k: u16, step: u16, diffed: []const u8, text: []const u8, lines: []Line, hunks: *std.ArrayList(Hunk), removed: *std.ArrayList(u8), marks: *std.ArrayList([2]u32), taken: *std.ArrayList(Taken)) error{OutOfMemory}!void {
+ const Added = struct { text: []const u8, whole: bool, marks: u32, nmarks: u16, new: u32, shown: ?u32 = null };
var added: std.ArrayList(Added) = .empty;
var walk: diff.Walk = .{};
- var taken: u32 = 0;
var it = std.mem.splitScalar(u8, diffed, '\n');
while (it.next()) |raw| {
const l = walk.step(raw);
switch (l.kind) {
.hunk => {
const h = diff.parseHunk(std.mem.trimEnd(u8, raw, "\r")).?;
- try hunks.append(gpa, .{ .pin = k, .old_start = @intCast(h.old_start), .old_len = @intCast(h.old_count), .new_start = @intCast(h.new_start), .new_len = @intCast(h.new_count), .removed = @intCast(removed.items.len), .removed_len = 0 });
- taken = 0;
+ try hunks.append(gpa, .{ .pin = k, .step = step, .old_start = @intCast(h.old_start), .old_len = @intCast(h.old_count), .new_start = @intCast(h.new_start), .new_len = @intCast(h.new_count), .removed = @intCast(removed.items.len), .removed_len = 0 });
},
- .removed => {
+ .removed => if (k != Hunk.carrier) {
const body = std.mem.trimEnd(u8, raw, "\r")[1..];
try removed.appendSlice(gpa, body);
try removed.append(gpa, '\n');
hunks.items[hunks.items.len - 1].removed_len += @intCast(body.len + 1);
- taken += 1;
- },
- .added => {
- try added.append(arena, .{ .text = std.mem.trimEnd(u8, raw, "\r")[1..], .whole = taken == 0 });
- taken -|= 1;
},
else => {},
}
}
+ if (k == Hunk.carrier) return;
+ // The patch view's rows of the same diff: a line it paired is one
+ // changed (its marker has no `ground_line`), its words `ground_emph`.
+ const patch = format: {
+ const ctx: @import("hunks.zig").Ctx = .{ .arena = arena };
+ break :format @import("hunks.zig").format(&ctx, "", diffed) catch |err| switch (err) {
+ error.OutOfMemory => return error.OutOfMemory,
+ else => return,
+ };
+ };
+ const syntax = @import("syntax.zig");
+ var said = std.mem.splitScalar(u8, patch.text, '\n');
+ var run_from = taken.items.len;
+ var plus_from = added.items.len;
+ for (patch.rows) |row| {
+ const row_text = said.next() orelse break;
+ if (row.kind == .hunk) {
+ pairRun(taken.items[run_from..], added.items[plus_from..], plus_from);
+ run_from = taken.items.len;
+ plus_from = added.items.len;
+ }
+ if (row.kind != .added and row.kind != .removed) continue;
+ const paired = row.styles.len > 0 and row.styles[0] & syntax.ground_line == 0;
+ const from = marks.items.len;
+ var i: usize = 1;
+ while (i < row.styles.len) {
+ if (row.styles[i] & syntax.ground_emph == 0) {
+ i += 1;
+ continue;
+ }
+ const run = i;
+ while (i < row.styles.len and row.styles[i] & syntax.ground_emph != 0) i += 1;
+ try marks.append(gpa, .{ @intCast(run - 1), @intCast(i - 1) });
+ }
+ const nmarks: u16 = @intCast(marks.items.len - from);
+ if (row.kind == .added)
+ try added.append(arena, .{ .text = row_text[@min(1, row_text.len)..], .whole = !paired, .marks = @intCast(from), .nmarks = nmarks, .new = @intCast(row.new orelse 0) })
+ else
+ try taken.append(arena, .{ .paired = paired, .marks = @intCast(from), .nmarks = nmarks });
+ }
+ pairRun(taken.items[run_from..], added.items[plus_from..], plus_from);
var next: usize = 0;
var rows = std.mem.splitScalar(u8, text, '\n');
- for (lines) |*line| {
+ const taken_from = taken.items.len - count: {
+ var n: usize = 0;
+ for (hunks.items) |h| if (h.pin == k) {
+ n += h.old_len;
+ };
+ break :count @min(n, taken.items.len);
+ };
+ for (lines, 0..) |*line, line_index| {
const row = rows.next() orelse break;
if (@intFromEnum(line.pin) != k) continue;
const from = next;
@@ -784,8 +964,293 @@ fn hunksOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, k: u16, diffed: []c
continue;
}
line.whole = added.items[next].whole;
+ if (!line.whole) {
+ line.marks = added.items[next].marks;
+ line.nmarks = added.items[next].nmarks;
+ }
+ added.items[next].shown = @intCast(line_index);
next += 1;
}
+ for (taken.items[taken_from..]) |*t| if (t.paired) {
+ t.new = added.items[t.partner].new;
+ t.shown = added.items[t.partner].shown;
+ };
+}
+
+/// A run's lines taken away paired with the lines written, in order (the
+/// alignment pairs each with a later one than the last it paired): each
+/// paired one's partner, by its place in `plus`'s list (from `base`).
+fn pairRun(minus: []Taken, plus: anytype, base: usize) void {
+ var j: usize = 0;
+ for (minus) |*m| if (m.paired) {
+ while (j < plus.len and plus[j].whole) j += 1;
+ if (j == plus.len) {
+ m.paired = false;
+ continue;
+ }
+ m.partner = base + j;
+ j += 1;
+ };
+}
+
+/// A run longer than this (lines taken away in one hunk) shows none of
+/// them as ghost rows; the patch view's alignment gives up past 256 too.
+const max_run = 1024;
+
+/// The ghost rows (`Ghost`), in `at` order: each line a pin took away
+/// whole or changed, where it stood (`carried` into the text); and each
+/// pin's description after its last line (a pin none of whose lines is
+/// left: after its last ghost row, or where its last hunk wrote). At one
+/// place: the descriptions of pins whose lines end just above it, the
+/// newest first (an inner block closes first), then the lines taken away,
+/// older pins' first, each pin's description right after its own. A place
+/// inside lines rewritten since jj's snapshot (`Moved.place`) has no row.
+/// `text` holds the hunks' removed lines; the descriptions' rows go on
+/// after them.
+fn ghostsOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, pins: []const Pin, lines: []const Line, hunks: []const Hunk, taken: []const Taken, text: *std.ArrayList(u8), now: i64, moved: Moved) error{OutOfMemory}![]Ghost {
+ const Made = struct { g: Ghost, rank: u64 };
+ var made: std.ArrayList(Made) = .empty;
+ var ti: usize = 0;
+ for (hunks) |h| {
+ if (h.old_len == 0 or h.pin == Hunk.carrier) continue;
+ const run = taken[@min(ti, taken.len)..@min(ti + h.old_len, taken.len)];
+ ti += h.old_len;
+ // A changed line's old text right above the line; a line taken
+ // away whole above the next changed one's, or after the run.
+ var at = carried(hunks, h.pin, if (h.new_len > 0) h.new_start - 1 + h.new_len else h.new_start, moved);
+ var ats: [max_run]?u32 = undefined;
+ if (run.len > max_run) continue;
+ var k = run.len;
+ while (k > 0) {
+ k -= 1;
+ if (run[k].paired) at = run[k].shown orelse carried(hunks, h.pin, run[k].new -| 1, moved);
+ ats[k] = at;
+ }
+ var from: usize = h.removed;
+ for (run, 0..) |t, n| {
+ const nl = std.mem.indexOfScalarPos(u8, text.items, from, '\n') orelse text.items.len;
+ defer from = nl + 1;
+ try made.append(arena, .{
+ .g = .{ .at = ats[n] orelse continue, .pin = h.pin, .kind = if (t.paired) .changed else .deleted, .line = h.old_start + @as(u32, @intCast(n)), .text = @intCast(from), .len = @intCast(nl - from), .marks = if (t.paired) t.marks else 0, .nmarks = if (t.paired) t.nmarks else 0 },
+ .rank = 1 << 32 | made.items.len << 1,
+ });
+ }
+ }
+ for (pins, 0..) |pin, k| {
+ var at: ?u32 = null;
+ var rank: u64 = pins.len - k;
+ var i = lines.len;
+ while (i > 0) {
+ i -= 1;
+ if (@intFromEnum(lines[i].pin) == k) {
+ at = @intCast(i + 1);
+ break;
+ }
+ }
+ if (at == null) {
+ rank |= 2 << 32;
+ for (made.items) |m| if (m.g.pin == k) {
+ at = @max(at orelse 0, m.g.at);
+ };
+ }
+ var first: u32 = 0;
+ var end: u32 = 0;
+ for (hunks) |h| if (h.pin == k) {
+ if (first == 0) first = h.new_start;
+ end = if (h.new_len > 0) h.new_start - 1 + h.new_len else h.new_start;
+ };
+ const place = at orelse carried(hunks, @intCast(k), end, moved) orelse continue;
+ // After its own ghost rows at its place.
+ for (made.items) |m| if (m.g.pin == k and m.g.at == place) {
+ rank = m.rank | 1;
+ };
+ const at_text = text.items.len;
+ try describe(gpa, text, pin, now);
+ try made.append(arena, .{
+ .g = .{ .at = place, .pin = @intCast(k), .kind = .description, .line = @max(first, 1), .text = @intCast(at_text), .len = @intCast(text.items.len - at_text) },
+ .rank = rank,
+ });
+ }
+ std.sort.pdq(Made, made.items, {}, struct {
+ fn before(_: void, a: Made, b: Made) bool {
+ return if (a.g.at != b.g.at) a.g.at < b.g.at else a.rank < b.rank;
+ }
+ }.before);
+ const out = try gpa.alloc(Ghost, made.items.len);
+ for (out, made.items) |*o, m| o.* = m.g;
+ return out;
+}
+
+/// Where the place after line `after` of pin `k`'s revision is in the
+/// text: moved by each later change's hunks before it (a pin's, or one
+/// between the pins the revset does not pin), or, inside a run of lines a
+/// later one took away, after what it wrote there; then from jj's lines
+/// to the text's (`moved`).
+fn carried(hunks: []const Hunk, k: u16, after: u32, moved: Moved) ?u32 {
+ const from = for (hunks) |h| {
+ if (h.pin == k) break h.step;
+ } else 0;
+ var pos: i64 = after;
+ var i: usize = 0;
+ while (i < hunks.len) {
+ const j = hunks[i].step;
+ var shift: i64 = 0;
+ var inside: ?i64 = null;
+ while (i < hunks.len and hunks[i].step == j) : (i += 1) {
+ const h = hunks[i];
+ if (j <= from) continue;
+ if (h.old_len == 0) {
+ if (h.old_start < pos) shift += h.new_len;
+ } else if (h.old_start + h.old_len - 1 <= pos) {
+ shift += @as(i64, h.new_len) - h.old_len;
+ } else if (h.old_start <= pos) inside = @as(i64, h.new_start) - 1 + h.new_len;
+ }
+ if (j > from) pos = inside orelse pos + shift;
+ }
+ return moved.place(@intCast(std.math.clamp(pos, 0, @as(i64, moved.was))));
+}
+
+/// A pin's description row (PARDES.md: compact, one blank between): its
+/// id's first four letters, its title, its author's first name, its age
+/// short (`5h`, `2d`, `3w`, `4m`, `1y`; under an hour `now`), no "ago".
+fn describe(gpa: std.mem.Allocator, text: *std.ArrayList(u8), pin: Pin, now: i64) error{OutOfMemory}!void {
+ const author = pin.author[0..pin.author_len];
+ try text.print(gpa, "{s} {s} {s} ", .{ pin.id[0..4], pin.title[0..pin.title_len], author[0 .. std.mem.indexOfScalar(u8, author, ' ') orelse author.len] });
+ const s = @max(0, now - pin.time);
+ const day = 24 * 3600;
+ for ([_]struct { u8, i64 }{ .{ 'y', 365 * day }, .{ 'm', 30 * day }, .{ 'w', 7 * day }, .{ 'd', day }, .{ 'h', 3600 } }) |unit| {
+ if (s >= unit[1]) return text.print(gpa, "{d}{c}", .{ @divFloor(s, unit[1]), unit[0] });
+ }
+ try text.appendSlice(gpa, "now");
+}
+
+/// The bytes a description row has at most, cut (`fitted`).
+pub const row_max = 256;
+
+/// A description row (`describe`: `id title author age`) as a body row of
+/// `room` cells shows it: whole when it fits, else its title cut to the
+/// room left (a `…` where it is cut), so the author and the age stay at
+/// its end (PARDES.md: one compact row, both shown).
+pub fn fitted(tab: u16, said: []const u8, room: usize, buf: *[row_max]u8) []const u8 {
+ if (said.len + 3 > row_max or File.displayWidth(tab, said) <= room) return said;
+ var tail = said.len;
+ for (0..2) |_| tail = std.mem.lastIndexOfScalar(u8, said[0..tail], ' ') orelse return said;
+ const head = @min(5, tail);
+ const keep = room -| File.displayWidth(tab, said[0..head]) -| File.displayWidth(tab, said[tail..]) -| 1;
+ const title = if (keep == 0) "" else std.mem.trimEnd(u8, said[head..tail][0..File.fitEnd(tab, said[head..tail], 0, keep)], " ");
+ var out: std.ArrayList(u8) = .initBuffer(buf);
+ out.appendSliceAssumeCapacity(said[0..head]);
+ out.appendSliceAssumeCapacity(title);
+ out.appendSliceAssumeCapacity("\u{2026}");
+ out.appendSliceAssumeCapacity(said[tail..]);
+ return out.items;
+}
+
+/// The lanes on ghost row `gi` (`ghosts[gi]`): those of the line above it
+/// that run on below it or whose description is this row or one after it
+/// at the same place, then its own pin's.
+fn ghostLanes(ch: *const Changes, ghosts: []const Ghost, gi: usize) [levels]PinIndex {
+ const g = ghosts[gi];
+ var out: [levels]PinIndex = @splat(.none);
+ var n: usize = 0;
+ if (g.at > 0 and g.at - 1 < ch.lines.len) for (ch.lines[g.at - 1].lanes) |lane| {
+ if (lane == .none) break;
+ const below = g.at < ch.lines.len and std.mem.indexOfScalar(PinIndex, &ch.lines[g.at].lanes, lane) != null;
+ const closes = for (ghosts[gi..]) |later| {
+ if (later.at != g.at) break false;
+ if (later.kind == .description and later.pin == @intFromEnum(lane)) break true;
+ } else false;
+ if (!below and !closes) continue;
+ out[n] = lane;
+ n += 1;
+ };
+ if (n < levels and std.mem.indexOfScalar(PinIndex, out[0..n], @enumFromInt(g.pin)) == null) out[n] = @enumFromInt(g.pin);
+ return out;
+}
+
+/// A ghost row's cells: a line taken away whole red across, its text in
+/// the line numbers' grey (dimmer than the text's ink); a description in
+/// its lane's colour, its author and age grey; `said`, the row's text as
+/// the body shows it (a description `fitted`).
+fn inkGhost(p: *Pardes, s: *pardes.Surface, g: Ghost, said: []const u8, marks: []const [2]u32, colours: []const [3]u8, x: u16, y: u16, w: u16) void {
+ const th = p.theme();
+ switch (g.kind) {
+ .deleted => s.tint(x, y, w, pardes.colors.Grounds.of(th).del.row, th.lineno),
+ .changed => {
+ const cells = @min(w, File.displayWidth(p.settings.tab, said));
+ for (0..cells) |c| s.at(x + @as(u16, @intCast(c)), y).style.fg = .{ .rgb = th.lineno };
+ for (marks[g.marks..][0..g.nmarks]) |m| {
+ const from = File.displayWidth(p.settings.tab, said[0..@min(m[0], said.len)]);
+ const to = @min(w, File.displayWidth(p.settings.tab, said[0..@min(m[1], said.len)]));
+ if (from < to) s.tint(x + @as(u16, @intCast(from)), y, @intCast(to - from), pardes.colors.Grounds.of(th).del.emph, null);
+ }
+ },
+ .description => {
+ // `id title author age`: the last two words grey.
+ var grey = said.len;
+ for (0..2) |_| grey = std.mem.lastIndexOfScalar(u8, said[0..grey], ' ') orelse 0;
+ const lane_cells = File.displayWidth(p.settings.tab, said[0..grey]);
+ const cells = @min(w, File.displayWidth(p.settings.tab, said));
+ for (0..cells) |c| s.at(x + @as(u16, @intCast(c)), y).style.fg = .{ .rgb = if (c < lane_cells) colours[g.pin % colours.len] else th.lineno };
+ },
+ }
+}
+
+/// A changed line's words that came (`marks`, byte ranges of line `row`),
+/// green on body row `vr`, as much of them as the row shows.
+fn inkCame(p: *Pardes, s: *pardes.Surface, pane: *Pane, marks: []const [2]u32, row: i32, vr: u16, x: u16, y: u16, w: u16) void {
+ const tab = p.settings.tab;
+ const len: u32 = @intCast(File.sourceLine(pane, row).len);
+ const here = pane.wrapAt(tab, vr);
+ const next = pane.wrapAt(tab, @as(i32, vr) + 1);
+ const first: u32 = @intCast(here.at);
+ const end: u32 = if (next.line == row and !next.ghost) @intCast(next.at) else len;
+ for (marks) |m| {
+ const lo = @max(first, @min(m[0], len));
+ const hi = @min(end, @min(m[1], len));
+ if (lo >= hi) continue;
+ const from = here.pad + File.displayOffset(tab, pane, row, @intCast(first), @intCast(lo));
+ const to = @min(@as(i32, w), here.pad + File.displayOffset(tab, pane, row, @intCast(first), @intCast(hi)));
+ if (from >= 0 and from < to) s.tint(x + @as(u16, @intCast(from)), y, @intCast(to - from), pardes.colors.Grounds.of(p.theme()).add.emph, null);
+ }
+}
+
+/// The line `]g` (`forward`) or `[g` goes to from line `from` of pane's
+/// text: the next or the previous change's first line in this view (a run
+/// of lines one pin wrote, or where lines one took away stood); null with
+/// none shown, or none that way.
+pub fn nextChange(p: *Pardes, pane: *const Pane, from: usize, forward: bool) ?usize {
+ if (pane.layers.lanes == 0) return null;
+ const ch = answered(p, pane.serial) orelse return null;
+ var best: ?usize = null;
+ const Best = struct {
+ fn take(b: *?usize, at: usize, here: usize, fwd: bool) void {
+ if (if (fwd) at <= here else at >= here) return;
+ if (b.*) |was| if (if (fwd) at >= was else at <= was) return;
+ b.* = at;
+ }
+ };
+ for (ch.lines, 0..) |l, i| if (l.pin != .none and (i == 0 or ch.lines[i - 1].pin != l.pin)) Best.take(&best, i, from, forward);
+ for (ch.ghosts) |g| if (g.kind == .deleted) Best.take(&best, @min(g.at, ch.lines.len -| 1), from, forward);
+ return best;
+}
+
+/// A Look on body row `vr` of pane `id` when it is a ghost row (mouse.zig,
+/// a B3 click): the line it shows in the revision it came from, as the
+/// address `path@rev:line` opens it (a line taken away: its pin's parent's;
+/// a description: its pin's first line). False on any other row.
+pub fn lookGhost(p: *Pardes, id: usize, vr: i32) bool {
+ const pane = p.panes[id].?;
+ if (pane.layers.lanes == 0 or !pane.wrapAt(p.settings.tab, vr).ghost) return false;
+ const ch = answered(p, pane.serial) orelse return false;
+ const gi: usize = @intCast(-1 - pane.wrap_col[@intCast(vr)]);
+ if (gi >= pane.ghosts.len) return false;
+ const g = pane.ghosts[gi];
+ const f = &pane.file.?;
+ const path = if (of(f)) |r| r.path else f.path;
+ const rev: [9]u8 = ch.pins[g.pin].id ++ "-".*;
+ _ = open(p, id, path, rev[0 .. if (g.kind == .description) 8 else 9], .{ .line = g.line }, false);
+ return true;
}
/// Each line's lanes: the blocks of the pins that span it, oldest first.
@@ -878,9 +1343,9 @@ fn hueApart(a: [3]u8, b: [3]u8) f32 {
/// File.Layers.lanes is set): in the gutter's lane cells after the number a
/// lane each pin whose block runs down the row, at its level, a glyph in a
/// terminal, a strip of pixels in a window (Surface.lanes); and a line a
-/// pin added whole green across it, as a diff's added line. Not yet: the
-/// ghost rows (what the shown revision has not: removed lines, each pin's
-/// description), a changed line's words.
+/// pin added whole green across it, as a diff's added line; on a ghost row
+/// (`Ghost`) its lanes and its cells (`inkGhost`). Not yet: a changed
+/// line's words.
pub fn paint(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u16, tw: u16, body_h: u16) void {
const ch = answered(p, pane.serial) orelse return;
if (ch.lines.len == 0) return;
@@ -897,12 +1362,24 @@ pub fn paint(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u1
const scroll = pane.scroll();
var vr: u16 = pane.context_rows;
while (vr < body_h) : (vr += 1) {
- const row: i32 = if (pane.wrap_n == 0) scroll + @as(i32, vr) else if (vr < pane.wrap_n) pane.wrap_line[vr] else break;
- if (row < 0 or row >= ch.lines.len) continue;
- const line = ch.lines[@intCast(row)];
const y = body_y + vr;
- if (line.whole and line.pin != .none) s.tint(tx + gutter, y, tw - gutter, ground, null);
- for (line.lanes, 0..) |lane, level| {
+ const lanes: [levels]PinIndex = if (vr < pane.wrap_n and pane.wrap_col[vr] < 0) ghost: {
+ const gi: usize = @intCast(-1 - pane.wrap_col[vr]);
+ if (gi >= pane.ghosts.len) continue;
+ const g = pane.ghosts[gi];
+ const said = pane.ghost_text[g.text..][0..g.len];
+ var fit: [row_max]u8 = undefined;
+ inkGhost(p, s, g, if (g.kind == .description) fitted(p.settings.tab, said, File.bodyWidth(pane), &fit) else said, ch.marks, colours, tx + gutter, y, tw - gutter);
+ break :ghost ghostLanes(ch, pane.ghosts, gi);
+ } else line: {
+ const row: i32 = if (pane.wrap_n == 0) scroll + @as(i32, vr) else if (vr < pane.wrap_n) pane.wrap_line[vr] else break;
+ if (row < 0 or row >= ch.lines.len) continue;
+ const line = ch.lines[@intCast(row)];
+ if (line.whole and line.pin != .none) s.tint(tx + gutter, y, tw - gutter, ground, null);
+ if (!line.whole and line.nmarks > 0) inkCame(p, s, pane, ch.marks[line.marks..][0..line.nmarks], row, vr, tx + gutter, y, tw - gutter);
+ break :line line.lanes;
+ };
+ for (lanes, 0..) |lane, level| {
if (lane == .none) break;
const rgb = colours[@intFromEnum(lane) % colours.len];
if (windowed) {
@@ -1090,18 +1567,21 @@ test "Changes pins a revset's changes on the pane, shown in this view: who wrote
const one: PinIndex = @enumFromInt(0);
const two: PinIndex = @enumFromInt(1);
const want = [_]Line{
- .{ .pin = two, .whole = false, .lanes = .{ two, .none, .none } },
+ .{ .pin = two, .whole = false, .lanes = .{ two, .none, .none }, .marks = 2, .nmarks = 2 },
.{ .pin = one, .whole = true, .lanes = .{ one, .none, .none } },
.{ .pin = two, .whole = true, .lanes = .{ two, .none, .none } },
};
try testing.expectEqualSlices(Line, &want, ch.lines);
+ // The patch view's alignment: the words that went (`one`, `1`), then
+ // those that came (`two`, `2`), byte ranges of each line.
+ try testing.expectEqualSlices([2]u32, &.{ .{ 6, 9 }, .{ 12, 13 }, .{ 6, 9 }, .{ 12, 13 } }, ch.marks);
const hunks = [_]Hunk{
- .{ .pin = 0, .old_start = 0, .old_len = 0, .new_start = 1, .new_len = 2, .removed = 0, .removed_len = 0 },
- .{ .pin = 1, .old_start = 1, .old_len = 1, .new_start = 1, .new_len = 1, .removed = 0, .removed_len = 15 },
- .{ .pin = 1, .old_start = 2, .old_len = 0, .new_start = 3, .new_len = 1, .removed = 15, .removed_len = 0 },
+ .{ .pin = 0, .step = 0, .old_start = 0, .old_len = 0, .new_start = 1, .new_len = 2, .removed = 0, .removed_len = 0 },
+ .{ .pin = 1, .step = 1, .old_start = 1, .old_len = 1, .new_start = 1, .new_len = 1, .removed = 0, .removed_len = 15 },
+ .{ .pin = 1, .step = 1, .old_start = 2, .old_len = 0, .new_start = 3, .new_len = 1, .removed = 15, .removed_len = 0 },
};
try testing.expectEqualSlices(Hunk, &hunks, ch.hunks);
- try testing.expectEqualStrings("const one = 1;\n", ch.removed);
+ try testing.expectStringStartsWith(ch.ghost_text, "const one = 1;\n");
// Bare: not shown in this view; what jj said is kept on the pane.
p.update(.{ .command = "Changes" });
try testing.expectEqual(0, pane.layers.lanes);
@@ -1183,7 +1663,7 @@ const WorkerJj = struct {
shell: *Shell,
a: *R.Authority,
r: *R.Replica,
- /// The revision `@-` of the repository's `a.zig`, open.
+ /// The repository's `a.zig` open (`at`: `@@-`, its revision `@-`).
id: usize,
serial: u32,
@@ -1193,7 +1673,7 @@ const WorkerJj = struct {
}
const vtable: pardes.Host.VTable = .{ .search = search };
- fn init(repo: *const Repo) !WorkerJj {
+ fn init(repo: *const Repo, at: []const u8) !WorkerJj {
const shell = try testing.allocator.create(Shell);
shell.* = .{ .q = .{ .gpa = testing.allocator, .lsp_allocator = testing.allocator, .io = testing.io } };
const a = try R.Authority.init(testing.allocator, .{ .cols = 80, .rows = 24 }, .{ .vtable = &vtable, .ctx = shell }, false);
@@ -1201,7 +1681,7 @@ const WorkerJj = struct {
shell.core = a.core;
const r = try R.Replica.init(testing.allocator, 1, try a.unit(0, 0), false);
var line: [4200]u8 = undefined;
- r.confirm(try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}@@-", .{repo.file}) }));
+ r.confirm(try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}{s}", .{ repo.file, at }) }));
const id = a.core.view().active;
return .{ .shell = shell, .a = a, .r = r, .id = id, .serial = a.core.panes[id].?.serial };
}
@@ -1244,7 +1724,7 @@ const WorkerJj = struct {
test "Changes asks jj on a worker: the word says so and returns, its answer lands as one input and pins; a client replays that input and ends equal" {
var repo = try Repo.init(testing.allocator) orelse return error.SkipZigTest;
defer repo.deinit(testing.allocator);
- var w = try WorkerJj.init(&repo);
+ var w = try WorkerJj.init(&repo, "@@-");
defer w.deinit();
try w.word("Changes @--::@-");
// Asked, not answered: the word did not wait for jj.
@@ -1258,7 +1738,7 @@ test "Changes asks jj on a worker: the word says so and returns, its answer land
test "a second Changes before the first's answer: only the second's pins" {
var repo = try Repo.init(testing.allocator) orelse return error.SkipZigTest;
defer repo.deinit(testing.allocator);
- var w = try WorkerJj.init(&repo);
+ var w = try WorkerJj.init(&repo, "@@-");
defer w.deinit();
try w.word("Changes @--::@-");
try w.word("Changes @-");
@@ -1271,7 +1751,7 @@ test "a second Changes before the first's answer: only the second's pins" {
test "the pane closed before its Changes answer: nothing pinned, nothing kept" {
var repo = try Repo.init(testing.allocator) orelse return error.SkipZigTest;
defer repo.deinit(testing.allocator);
- var w = try WorkerJj.init(&repo);
+ var w = try WorkerJj.init(&repo, "@@-");
defer w.deinit();
try w.word("Changes @--::@-");
try w.word("Del");
@@ -1311,10 +1791,11 @@ test "Changes draws a lane a pinned change after the line number, nested ones a
const colours = laneColours(p.theme(), &buf);
try testing.expect(colours.len >= 3);
const ground = pardes.colors.Grounds.of(p.theme()).add.row;
- // Rows 1-10: `fn`'s spine on all; `mid` on 3-6; `shift` on 4.
+ // Lines 1-10, each on the row the view draws it at (ghost rows
+ // stand between): `fn`'s spine on all; `mid` on 3-6; `shift` on 4.
const want = [_][]const u8{ "0", "0", "01", "012", "01", "01", "0", "0", "0", "0" };
for (want, 0..) |lanes, row| {
- const y = body.y + @as(u16, @intCast(row));
+ const y = body.y + @as(u16, @intCast(pane.wrapRow(p.settings.tab, @intCast(row), 0).row));
if (windowed) {
var n: usize = 0;
for (s.lanes.items) |lane| if (lane.y == y) {
@@ -1346,6 +1827,332 @@ test "Changes draws a lane a pinned change after the line number, nested ones a
}
}
+/// A function `fn` wrote, two of its lines `cut` took away whole, and one
+/// `mid` rewrote as two (one changed, one added whole).
+const Ghosts = struct {
+ const fn_text = "fn f() void {\n a();\n b();\n c();\n d();\n e();\n}\n";
+ const cut_text = "fn f() void {\n a();\n b();\n e();\n}\n";
+ const mid_text = "fn f() void {\n a();\n b2();\n x();\n e();\n}\n";
+
+ fn repo() !?Repo {
+ return Repo.with(testing.allocator, &.{ .{ fn_text, "fn" }, .{ cut_text, "cut" }, .{ mid_text, "mid" } }, null);
+ }
+
+ /// The body's rows as this view shows them, whole.
+ fn rows(p: *Pardes, pane: *Pane, arena: std.mem.Allocator, out: [][]const u8) ![]const []const u8 {
+ var it = std.mem.splitScalar(u8, try File.bodyText(p.settings.tab, arena, pane, &pane.file.?), '\n');
+ var n: usize = 0;
+ while (it.next()) |row| : (n += 1) out[n] = row;
+ return out[0..n];
+ }
+
+ /// Each row's text after the gutter, and its number (blank: none).
+ fn text(pane: *const Pane, row: []const u8) []const u8 {
+ return row[@min(row.len, File.gutterWidth(pane))..];
+ }
+ fn number(pane: *const Pane, row: []const u8) []const u8 {
+ return std.mem.trim(u8, row[0..@min(row.len, File.gutterWidth(pane))], " ");
+ }
+
+ /// The rows a `Changes ::@` shows: `said` each pin's description;
+ /// `b();` the old text of the line `mid` changed, right above it.
+ fn want(said: [3][]const u8) [12][]const u8 {
+ return .{ "fn f() void {", " a();", " b();", " b2();", " x();", said[2], " c();", " d();", said[1], " e();", "}", said[0] };
+ }
+};
+
+fn saidOf(arena: std.mem.Allocator, ch: *const Changes) ![3][]const u8 {
+ var said: [3][]const u8 = undefined;
+ for (&said, ch.pins, [_][]const u8{ "fn", "cut", "mid" }) |*d, pin, title| d.* = try std.fmt.allocPrint(arena, "{s} {s} t now", .{ pin.id[0..4], title });
+ return said;
+}
+
+test "Changes draws what the text has not where it stood, as ghost rows: a line a change took away whole red across, each change's description after its last line in its lane's colour; no number, their lanes, the rows below moved down in this view alone" {
+ const gpa = testing.allocator;
+ var repo = try Ghosts.repo() orelse return error.SkipZigTest;
+ defer repo.deinit(gpa);
+ for ([_]bool{ false, true }) |windowed| {
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 24, .windowed = windowed });
+ defer p.deinit();
+ var line: [4200]u8 = undefined;
+ p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) });
+ const id = p.view().active;
+ const pane = p.panes[id].?;
+ const other = p.openView().?;
+ p.update(.{ .command = "Changes ::@" });
+ const ch = answered(p, pane.serial).?;
+ try testing.expectEqual(@as(usize, 3), ch.pins.len);
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ const said = try saidOf(arena.allocator(), ch);
+ var buf: [64][]const u8 = undefined;
+ const got = try Ghosts.rows(p, pane, arena.allocator(), &buf);
+ const want = Ghosts.want(said);
+ const numbers = [_][]const u8{ "1", "2", "", "3", "4", "", "", "", "", "5", "6", "" };
+ for (want, numbers, got[0..want.len]) |w, n, row| {
+ try testing.expectEqualStrings(w, Ghosts.text(pane, row));
+ try testing.expectEqualStrings(n, Ghosts.number(pane, row));
+ }
+ // Drawn: each row's lanes (pins by level), its ground, a ghost's ink.
+ p.sync();
+ const s = try p.render(arena.allocator());
+ const body = s.region(.body, id).?.rect;
+ const first = body.x + File.gutterWidth(pane) - File.laneCells(pane);
+ var cbuf: [8][3]u8 = undefined;
+ const colours = laneColours(p.theme(), &cbuf);
+ const grounds = pardes.colors.Grounds.of(p.theme());
+ const lanes = [_][]const u8{ "0", "0", "02", "02", "02", "02", "01", "01", "01", "0", "0", "0" };
+ const Ground = enum { none, add, del };
+ const ground = [_]Ground{ .add, .add, .none, .none, .add, .none, .del, .del, .none, .add, .add, .none };
+ for (lanes, ground, 0..) |pins, gr, row| {
+ const y = body.y + @as(u16, @intCast(row));
+ if (windowed) {
+ var n: usize = 0;
+ for (s.lanes.items) |lane| if (lane.y == y) {
+ try testing.expectEqual(colours[pins[lane.level] - '0'], lane.rgb);
+ n += 1;
+ };
+ try testing.expectEqual(pins.len, n);
+ } else for (pins, 0..) |pin, level| {
+ const cell = s.at(first + @as(u16, @intCast(level)), y);
+ try testing.expectEqualStrings("\u{258e}", cell.grapheme());
+ try testing.expectEqual(pardes.Color{ .rgb = colours[pin - '0'] }, cell.style.fg);
+ }
+ const cell = s.at(body.x + File.gutterWidth(pane) + 1, y);
+ const bg: ?[3]u8 = switch (gr) {
+ .none => null,
+ .add => grounds.add.row,
+ .del => grounds.del.row,
+ };
+ if (bg) |rgb| try testing.expectEqual(pardes.Color{ .rgb = rgb }, cell.style.bg) else {
+ try testing.expect(!std.meta.eql(cell.style.bg, pardes.Color{ .rgb = grounds.add.row }));
+ try testing.expect(!std.meta.eql(cell.style.bg, pardes.Color{ .rgb = grounds.del.row }));
+ }
+ }
+ // A description's id and title in its lane's colour; a line taken
+ // away in the numbers' grey.
+ for ([_]u16{ 5, 8, 11 }, [_]usize{ 2, 1, 0 }) |row, pin|
+ try testing.expectEqual(pardes.Color{ .rgb = colours[pin] }, s.at(body.x + File.gutterWidth(pane), body.y + row).style.fg);
+ try testing.expectEqual(pardes.Color{ .rgb = p.theme().lineno }, s.at(body.x + File.gutterWidth(pane) + 4, body.y + 6).style.fg);
+ // The changed line: on its old text the word that went (`b`) red,
+ // on it the word that came (`b2`) green; the rest of each neither.
+ const text_x = body.x + File.gutterWidth(pane);
+ for ([_]u16{ 4, 5 }, [_]bool{ true, false }) |col, went| try testing.expectEqual(went, std.meta.eql(s.at(text_x + col, body.y + 2).style.bg, pardes.Color{ .rgb = grounds.del.emph }));
+ for ([_]u16{ 4, 5, 6 }, [_]bool{ true, true, false }) |col, came| try testing.expectEqual(came, std.meta.eql(s.at(text_x + col, body.y + 3).style.bg, pardes.Color{ .rgb = grounds.add.emph }));
+ // The other view shows no lanes: its rows are the text's, unmoved.
+ p.toView(other);
+ const plain = try Ghosts.rows(p, pane, arena.allocator(), &buf);
+ var lines = std.mem.splitScalar(u8, Ghosts.mid_text, '\n');
+ for (plain[0..6]) |row| try testing.expectEqualStrings(lines.next().?, Ghosts.text(pane, row));
+ p.toView(.at(0));
+ try testing.expectEqualStrings(said[2], Ghosts.text(pane, (try Ghosts.rows(p, pane, arena.allocator(), &buf))[5]));
+ }
+}
+
+test "the cursor steps over ghost rows and selection does not see them; ]g and [g go from change to change; a Look on one opens its line in the revision it came from" {
+ const gpa = testing.allocator;
+ var repo = try Ghosts.repo() orelse return error.SkipZigTest;
+ defer repo.deinit(gpa);
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 24, .windowed = false });
+ defer p.deinit();
+ var line: [4200]u8 = undefined;
+ p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) });
+ const id = p.view().active;
+ const pane = p.panes[id].?;
+ p.update(.{ .command = "Changes ::@" });
+ const key = struct {
+ fn send(q: *Pardes, keys: []const u8) void {
+ for (keys) |k| q.update(.{ .key = .{ .cp = k, .text = &[_]u8{k} } });
+ }
+ }.send;
+ // From `x();` (line 4) a `j` is on `e();` (line 5), three ghost rows below.
+ p.update(.{ .command = "Look a.zig:4" });
+ try testing.expectEqual(@as(i32, 3), pane.body.cur_row);
+ key(p, "j");
+ try testing.expectEqual(@as(i32, 4), pane.body.cur_row);
+ try testing.expectEqual(@as(i32, 9), pane.wrapRow(p.settings.tab, 4, 0).row);
+ // All selected: a ghost row keeps its own ground.
+ key(p, "%");
+ p.sync();
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ var s = try p.render(arena.allocator());
+ var body = s.region(.body, id).?.rect;
+ const x = body.x + File.gutterWidth(pane) + 4;
+ try testing.expectEqual(pardes.Color{ .rgb = pardes.colors.Grounds.of(p.theme()).del.row }, s.at(x, body.y + 6).style.bg);
+ try testing.expect(!std.meta.eql(s.at(x, body.y + 6).style.bg, s.at(x, body.y + 4).style.bg));
+ key(p, ";");
+ // ]g, [g: the changes start on lines 1 (fn), 3 (mid) and 5 (fn again,
+ // after the lines cut took away).
+ p.update(.{ .command = "Look a.zig:1" });
+ for ([_]i32{ 2, 4, 4 }) |want| {
+ key(p, "]g");
+ try testing.expectEqual(want, pane.body.cur_row);
+ }
+ for ([_]i32{ 2, 0 }) |want| {
+ key(p, "[g");
+ try testing.expectEqual(want, pane.body.cur_row);
+ }
+ // A Look (B3) on `c();`'s ghost row: fn's revision (cut's parent) at its line 4.
+ p.sync();
+ s = try p.render(arena.allocator());
+ body = s.region(.body, id).?.rect;
+ p.update(.{ .mouse = .{ .button = .right, .kind = .press, .col = x, .row = body.y + 6 } });
+ p.update(.{ .mouse = .{ .button = .right, .kind = .release, .col = x, .row = body.y + 6 } });
+ const shown = p.view().active;
+ try testing.expect(shown != id);
+ const f = &p.panes[shown].?.file.?;
+ try testing.expect(of(f) != null);
+ try testing.expectEqualStrings(Ghosts.fn_text, f.content);
+ try testing.expectEqual(@as(i32, 3), p.panes[shown].?.body.cur_row);
+}
+
+test "ghost rows ride with the text: a line deleted above moves them up, a line they stood before deleted puts them before the next; a client replays it equal" {
+ var repo = try Ghosts.repo() orelse return error.SkipZigTest;
+ defer repo.deinit(testing.allocator);
+ const R = pardes.replica;
+ const a = try R.Authority.init(testing.allocator, .{ .cols = 80, .rows = 24 }, .{}, false);
+ defer a.deinit();
+ const r = try R.Replica.init(testing.allocator, 1, try a.unit(0, 0), false);
+ defer r.deinit();
+ var line: [4200]u8 = undefined;
+ r.confirm(try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) }));
+ r.confirm(try a.local(.{ .command = "Changes ::@" }));
+ r.settle();
+ const serial = a.core.panes[a.core.view().active].?.serial;
+ const ats = struct {
+ fn of(ch: *const Changes, out: []u32) []u32 {
+ for (ch.ghosts, out[0..ch.ghosts.len]) |g, *o| o.* = g.at;
+ return out[0..ch.ghosts.len];
+ }
+ }.of;
+ var got: [8]u32 = undefined;
+ // mid's description, cut's two lines and its description before `e();`
+ // (line 5), fn's after the last.
+ try testing.expectEqualSlices(u32, &.{ 2, 4, 4, 4, 4, 6 }, ats(answered(a.core, serial).?, &got));
+ // `a();` deleted: each one a line up.
+ r.confirm(try a.local(.{ .command = "Look a.zig:2" }));
+ for (";xd") |k| r.confirm(try a.local(.{ .key = .{ .cp = k, .text = &[_]u8{k} } }));
+ r.settle();
+ try testing.expectEqualSlices(u32, &.{ 1, 3, 3, 3, 3, 5 }, ats(answered(a.core, serial).?, &got));
+ // `e();`, the line they stood before, deleted: they stand before `}`.
+ r.confirm(try a.local(.{ .command = "Look a.zig:4" }));
+ for (";xd") |k| r.confirm(try a.local(.{ .key = .{ .cp = k, .text = &[_]u8{k} } }));
+ r.settle();
+ try testing.expectEqualStrings("fn f() void {\n b2();\n x();\n}\n", a.core.panes[a.core.view().active].?.file.?.content);
+ try testing.expectEqualSlices(u32, &.{ 1, 3, 3, 3, 3, 4 }, ats(answered(a.core, serial).?, &got));
+ try testing.expect(r.diverged == null);
+ try testing.expectEqualSlices(Ghost, answered(a.core, serial).?.ghosts, answered(r.core(), serial).?.ghosts);
+ try testing.expectEqual(pardes.tape.digestOf(a.core), pardes.tape.digestOf(r.core()));
+}
+
+test "a description's ghost row keeps its author and age: in a pane narrower than the row its title gives way, cut to the room" {
+ const gpa = testing.allocator;
+ const title = "a title long enough that no narrow pane holds the whole of it beside its author and its age";
+ var repo = try Repo.with(gpa, &.{.{ "fn f() void {\n a();\n}\n", title }}, null) orelse return error.SkipZigTest;
+ defer repo.deinit(gpa);
+ for ([_]bool{ false, true }) |windowed| {
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 50, .rows = 20, .windowed = windowed });
+ defer p.deinit();
+ var line: [4200]u8 = undefined;
+ p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) });
+ const id = p.view().active;
+ const pane = p.panes[id].?;
+ p.update(.{ .command = "Changes ::@" });
+ const ch = answered(p, pane.serial).?;
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ var buf: [64][]const u8 = undefined;
+ const got = try Ghosts.rows(p, pane, arena.allocator(), &buf);
+ const row = Ghosts.text(pane, got[3]);
+ const room = pane.cols - File.gutterWidth(pane) - 1;
+ try testing.expect(File.displayWidth(p.settings.tab, row) <= room);
+ try testing.expectStringStartsWith(row, try std.fmt.allocPrint(arena.allocator(), "{s} a title long", .{ch.pins[0].id[0..4]}));
+ try testing.expectStringEndsWith(row, "\u{2026} t now");
+ // Drawn: the id and the title in its lane's colour, the author and
+ // the age grey, at the row's end.
+ p.sync();
+ const s = try p.render(arena.allocator());
+ const body = s.region(.body, id).?.rect;
+ const x = body.x + File.gutterWidth(pane);
+ var cbuf: [8][3]u8 = undefined;
+ try testing.expectEqual(pardes.Color{ .rgb = laneColours(p.theme(), &cbuf)[0] }, s.at(x, body.y + 3).style.fg);
+ const age_x = x + @as(u16, @intCast(File.displayWidth(p.settings.tab, row))) - 1;
+ try testing.expectEqualStrings("w", s.at(age_x, body.y + 3).grapheme());
+ try testing.expectEqual(pardes.Color{ .rgb = p.theme().lineno }, s.at(age_x, body.y + 3).style.fg);
+ try testing.expectEqual(pardes.Color{ .rgb = p.theme().lineno }, s.at(age_x - 4, body.y + 3).style.fg);
+ }
+}
+
+test "at one place a change's ghost rows come before its description: a line it changed and the next it took away, then its description" {
+ const gpa = testing.allocator;
+ const fn_text = "fn f() void {\n a();\n b();\n c();\n d();\n}\n";
+ const chg_text = "fn f() void {\n a();\n b2();\n d();\n}\n";
+ var repo = try Repo.with(gpa, &.{ .{ fn_text, "fn" }, .{ chg_text, "chg" } }, null) orelse return error.SkipZigTest;
+ defer repo.deinit(gpa);
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 24, .windowed = false });
+ defer p.deinit();
+ var line: [4200]u8 = undefined;
+ p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) });
+ const pane = p.panes[p.view().active].?;
+ p.update(.{ .command = "Changes ::@" });
+ const ch = answered(p, pane.serial).?;
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ const said = [2][]const u8{ try std.fmt.allocPrint(arena.allocator(), "{s} fn t now", .{ch.pins[0].id[0..4]}), try std.fmt.allocPrint(arena.allocator(), "{s} chg t now", .{ch.pins[1].id[0..4]}) };
+ var buf: [64][]const u8 = undefined;
+ const got = try Ghosts.rows(p, pane, arena.allocator(), &buf);
+ const want = [_][]const u8{ "fn f() void {", " a();", " b();", " b2();", " c();", said[1], " d();", "}", said[0] };
+ for (want, got[0..want.len]) |w, row| try testing.expectEqualStrings(w, Ghosts.text(pane, row));
+}
+
+test "a change the revset does not pin, between two it does, moves the older one's ghost rows to where they stand: jj's answer has its hunks" {
+ const gpa = testing.allocator;
+ const fn_text = "fn f() void {\n a();\n b();\n c();\n d();\n}\n";
+ // `old` takes `c();` away; `mid` (not pinned) writes two lines above
+ // it; `last` changes `d();`.
+ const old_text = "fn f() void {\n a();\n b();\n d();\n}\n";
+ const mid_text = "fn f() void {\n a();\n x();\n y();\n b();\n d();\n}\n";
+ const last_text = "fn f() void {\n a();\n x();\n y();\n b();\n d2();\n}\n";
+ var repo = try Repo.with(gpa, &.{ .{ fn_text, "fn" }, .{ old_text, "old" }, .{ mid_text, "mid" }, .{ last_text, "last" } }, null) orelse return error.SkipZigTest;
+ defer repo.deinit(gpa);
+ const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 24, .windowed = false });
+ defer p.deinit();
+ var line: [4200]u8 = undefined;
+ p.update(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) });
+ const pane = p.panes[p.view().active].?;
+ p.update(.{ .command = "Changes @--- | @-" });
+ const ch = answered(p, pane.serial).?;
+ try testing.expectEqual(@as(usize, 2), ch.pins.len);
+ var arena: std.heap.ArenaAllocator = .init(gpa);
+ defer arena.deinit();
+ const said = [2][]const u8{ try std.fmt.allocPrint(arena.allocator(), "{s} old t now", .{ch.pins[0].id[0..4]}), try std.fmt.allocPrint(arena.allocator(), "{s} last t now", .{ch.pins[1].id[0..4]}) };
+ var buf: [64][]const u8 = undefined;
+ const got = try Ghosts.rows(p, pane, arena.allocator(), &buf);
+ const want = [_][]const u8{ "fn f() void {", " a();", " x();", " y();", " b();", " c();", said[0], " d();", " d2();", said[1], "}" };
+ for (want, got[0..want.len]) |w, row| try testing.expectEqualStrings(w, Ghosts.text(pane, row));
+}
+
+test "lines typed between the word and jj's answer: the ghost rows stand where they stood, carried across them" {
+ var repo = try Ghosts.repo() orelse return error.SkipZigTest;
+ defer repo.deinit(testing.allocator);
+ var w = try WorkerJj.init(&repo, "");
+ defer w.deinit();
+ try w.word("Changes ::@");
+ try testing.expect(answered(w.a.core, w.serial) == null);
+ // A line opened above `a();` before the answer lands.
+ try w.word("Look a.zig:2");
+ for ("Oz();") |k| w.r.confirm(try w.a.local(.{ .key = .{ .cp = k, .text = &[_]u8{k} } }));
+ w.r.confirm(try w.a.local(.{ .key = .{ .cp = pardes.Key.escape } }));
+ try w.land();
+ try testing.expectStringStartsWith(w.a.core.panes[w.id].?.file.?.content, "fn f() void {\n z();\n a();\n");
+ var got: [8]u32 = undefined;
+ const ch = answered(w.a.core, w.serial).?;
+ for (ch.ghosts, got[0..ch.ghosts.len]) |g, *o| o.* = g.at;
+ try testing.expectEqualSlices(u32, &.{ 3, 5, 5, 5, 5, 7 }, got[0..ch.ghosts.len]);
+ try testing.expectEqualSlices(Ghost, ch.ghosts, answered(w.r.core(), w.serial).?.ghosts);
+}
+
/// A function three changes wrote: `fn` all of it, `mid` its lines 3-6
/// (rewriting two, adding two), `shift` line 4 again.
const Stack = struct {
diff --git a/core/modal.zig b/core/modal.zig
index f540b1a7..fda948a2 100644
--- a/core/modal.zig
+++ b/core/modal.zig
@@ -58,6 +58,7 @@ pub const Normal = struct {
add_newline,
goto_diagnostic,
goto_diagnostic_end,
+ goto_change,
goto_function,
goto_class,
goto_parameter,
diff --git a/core/mouse.zig b/core/mouse.zig
index 465d8a01..e41f8910 100644
--- a/core/mouse.zig
+++ b/core/mouse.zig
@@ -1250,6 +1250,14 @@ fn dragRelease(p: *Pardes, button: Mouse.Button) void {
}
} else {
const clk = pane.sel[b];
+ // A right-click on a ghost row (jj.zig) looks at its line
+ // in the revision it came from.
+ if (s.button == config.look_button and clk.r0 >= pane.tag_rows and clk.r0 == clk.r1 and clk.c0 == clk.c1 and
+ pane.layers.lanes > 0 and @import("jj.zig").lookGhost(p, s.id, clk.r0 - pane.tag_rows))
+ {
+ pane.sel[b].state = .none;
+ return;
+ }
// A right-click on a line NUMBER looks at that line of
// this file -- a sticky context header's number included,
// since the row map holds each header's own source line.
diff --git a/core/normal.zig b/core/normal.zig
index 982ab656..bb7824b2 100644
--- a/core/normal.zig
+++ b/core/normal.zig
@@ -1024,7 +1024,7 @@ fn shrinkSelToLineBounds(tab: u16, t: *Text, text: []const u8, range: modal.Sele
pub fn textRole(role: modal.Normal.Role, tree: bool) bool {
return switch (role) {
.all_children, .all_siblings, .expand_node, .goto_class, .goto_comment, .goto_entry, .goto_function, .goto_parameter, .goto_test, .goto_xml_element, .next_sibling, .parent_node_end, .parent_node_start, .prev_sibling, .shrink_node => tree,
- .append_output, .command_line, .format, .goto_callstack, .goto_declaration, .goto_definition, .goto_diagnostic, .goto_diagnostic_end, .goto_implementation, .goto_references, .goto_type_definition, .goto_view_bottom, .goto_view_top, .goto_word, .half_page_down, .half_page_up, .insert_output, .keep_pipe, .keep_regex, .leader, .macro_record, .macro_replay, .page_down, .page_up, .pipe_selection, .pipe_selection_to, .remove_regex, .repeat_insert, .search, .search_next, .search_prev, .select_regex, .split_regex, .view_bottom, .view_center, .view_middle, .view_scroll_down, .view_scroll_up, .view_top => false,
+ .append_output, .command_line, .format, .goto_callstack, .goto_change, .goto_declaration, .goto_definition, .goto_diagnostic, .goto_diagnostic_end, .goto_implementation, .goto_references, .goto_type_definition, .goto_view_bottom, .goto_view_top, .goto_word, .half_page_down, .half_page_up, .insert_output, .keep_pipe, .keep_regex, .leader, .macro_record, .macro_replay, .page_down, .page_up, .pipe_selection, .pipe_selection_to, .remove_regex, .repeat_insert, .search, .search_next, .search_prev, .select_regex, .split_regex, .view_bottom, .view_center, .view_middle, .view_scroll_down, .view_scroll_up, .view_top => false,
else => true,
};
}
@@ -1250,6 +1250,9 @@ fn executeNormalAction(p: *Pardes, t: *Text, a: modal.Normal.Action) edit.Error!
},
.view_scroll_down => if (t.what == .body) return t.scrollViewMove(p.settings.tab, text, range, 1),
.view_scroll_up => if (t.what == .body) return t.scrollViewMove(p.settings.tab, text, range, -1),
+ // The next and the previous of the changes this view shows (jj.zig).
+ .goto_change => if (@import("jj.zig").nextChange(p, pane, @intCast(@max(0, t.cur_row)), a.forward)) |line|
+ return pointMove(p.settings.tab, t, text, range, modal.lineStartOffset(text, line)),
.goto_diagnostic, .goto_diagnostic_end => {
// Once a Diagnostics query fed them, the diagnostics are this
// text's places: ]d and [d step them as n and N do, ]D and [D
diff --git a/core/panes.zig b/core/panes.zig
index 2f561d05..289de70f 100644
--- a/core/panes.zig
+++ b/core/panes.zig
@@ -31,7 +31,7 @@ pub const Pane = struct {
/// it (views.zig). (The 9P server's part of `fs` says so in its type.)
pub const replica = .{
.local = .{ "pv", "pv_known" },
- .derived = .{ "wrap_line", "wrap_col", "wrap_pad", "wrap_n", "body_wrapped", "context_rows", "body_rows", "body_visible_rows", "context_row_limit", "geometry_key", "geometry_len", "notices", "pan" },
+ .derived = .{ "wrap_line", "wrap_col", "wrap_pad", "wrap_n", "body_wrapped", "context_rows", "body_rows", "body_visible_rows", "context_row_limit", "geometry_key", "geometry_len", "notices", "pan", "ghosts", "ghost_text" },
.len = .{ .{ "msg", "msg_len" }, .{ "msg_older", "msg_older_len" }, .{ "question", "question_len" }, .{ "shell_tail", "shell_tail_len" }, .{ "sel_snap", "nsel_snap" } },
// A picture's memory is its own allocator's (a dump loaded makes
// it there).
@@ -308,6 +308,14 @@ pub const Pane = struct {
wrap_col: [limits.wrap_rows]i32 = undefined,
wrap_pad: [limits.wrap_rows]u16 = @splat(0),
wrap_n: u16 = 0,
+ /// The ghost rows of its pinned changes (jj.zig, `Ghost`: lines a
+ /// change took away, a change's description), the session's answers'
+ /// (`Pardes.changes`) as its geometry reads them while a view shows
+ /// them (`layers.lanes`): set by jj.showGhosts. A ghost row's `wrap_col` is
+ /// negative, `-1 - ` its index here, and its `wrap_line` the line it
+ /// stands before.
+ ghosts: []const @import("jj.zig").Ghost = &.{},
+ ghost_text: []const u8 = "",
/// A row map also exists for sticky headers when soft wrapping is off.
body_wrapped: bool = false,
context_rows: u16 = 0,
@@ -596,10 +604,14 @@ pub const Pane = struct {
return pane.surfRow(@as(i32, @intCast(Term.grid(pane.terminal).offset)) + pane.pan);
}
- pub fn wrapAt(pane: *Pane, tab: u16, vr: i32) struct { line: i32, at: i32, pad: i32 = 0 } {
+ /// The line and byte a body row shows from; a ghost row (jj.zig) is no
+ /// line's: `ghost`, the line below it at its start.
+ pub fn wrapAt(pane: *Pane, tab: u16, vr: i32) struct { line: i32, at: i32, pad: i32 = 0, ghost: bool = false } {
File.geometry(tab, pane);
- if (pane.wrap_n > 0 and vr >= 0 and vr < @as(i32, pane.wrap_n))
- return .{ .line = pane.wrap_line[@intCast(vr)], .at = pane.wrap_col[@intCast(vr)], .pad = pane.wrap_pad[@intCast(vr)] };
+ if (pane.wrap_n > 0 and vr >= 0 and vr < @as(i32, pane.wrap_n)) {
+ const at = pane.wrap_col[@intCast(vr)];
+ return .{ .line = pane.wrap_line[@intCast(vr)], .at = @max(at, 0), .pad = pane.wrap_pad[@intCast(vr)], .ghost = at < 0 };
+ }
// unwrapped: rows ARE lines, and the byte column a row starts at is the
// horizontal scroll (always 0 on a terminal, which never has one)
return .{ .line = pane.scroll() + vr, .at = pane.hscroll };
diff --git a/core/root.zig b/core/root.zig
index 782c0040..e29e70d8 100644
--- a/core/root.zig
+++ b/core/root.zig
@@ -629,7 +629,7 @@ const machine_lines = [_]struct { []const u8, usize, []const u8 }{
.{ "exec.zig", 3, "kindOf's stat (tape.site(.kind), its io the tape's) and Shell's check (tape.site(.shell))" },
.{ "fs.zig", 38, "the file system behind the tape's sites (open, read, write, stat, mkdir, access; their io the tape's), the process's home (read once at the start, taped), the 9P transport" },
.{ "hunks.zig", 1, "a test helper's file read" },
- .{ "jj.zig", 9, "jj run under tape.site(.jj) on an io of its own (the tape's spawns nothing) with this process's environment, the signal mask cleared as Stream's children's: the session's, a replica replays its answer; or on a worker for `Changes`, its answer an input; a test's shell inbox (dev)" },
+ .{ "jj.zig", 11, "jj run under tape.site(.jj) on an io of its own (the tape's spawns nothing) with this process's environment, the signal mask cleared as Stream's children's: the session's, a replica replays its answer; or on a worker for `Changes`, its answer an input, with the wall clock it was made at (tape.value(.clock) on the loop) for its descriptions' ages; a test's shell inbox (dev)" },
.{ "look.zig", 6, "openLink's fork (the host's: a view's frontend opens a link) and a remote's error name" },
.{ "memory.zig", 7, "the memory regions themselves (mmap, madvise, their locks)" },
.{ "replica.zig", 76, "the client and session engines: sockets, threads, clocks, the blob cache, traces" },
@@ -745,6 +745,7 @@ const kept_out = [_]struct { []const u8, []const u8, []const u8 }{
.{ "Event.zig", "native_image_patches", "what this process's shell can take" },
.{ "panes.zig", "pv pv_known", "the views' shares as this process parks them (views.zig)" },
.{ "panes.zig", "wrap_line wrap_col wrap_pad wrap_n body_wrapped context_rows body_rows body_visible_rows context_row_limit geometry_key geometry_len", "File.geometry's, made by whoever asks first (a frame or a step) from everything its key hashes of the step's state; a tab change resets the key" },
+ .{ "panes.zig", "ghosts ghost_text", "the session's `Changes` answers' ghost rows (Pardes.changes, in the digest) as the geometry reads them: set by jj.showGhosts in each step while a view shows them and as an answer lands, which resets the geometry's key" },
.{ "panes.zig views.zig", "notices", "made again from the step's state at the top of update and presented, and at sync (Messages.collectNotices); a frame's are its own" },
.{ "panes.zig views.zig", "pan", "written by steps only (sync, a view unparked) from the pane and its terminal" },
.{ "File.zig", "cap line_starts line_cap", "the text's line index, of its bytes" },
diff --git a/docs/typ/builtins-gui.json b/docs/typ/builtins-gui.json
index af6f98ae..ad1f98df 100644
--- a/docs/typ/builtins-gui.json
+++ b/docs/typ/builtins-gui.json
@@ -10,7 +10,7 @@
{"name": "Callstack", "leader": "SPC l b", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Show outermost callers first, with signatures and call sites (gc)."},
{"name": "CallstackDepth", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "Caller levels collected by Callstack, 1 through 64; default 8. Bare, it says the current limit."},
{"name": "Changelog", "leader": "SPC h c", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "This build's version and what changed to reach it, printed into an output buffer the same way Config prints the live settings."},
- {"name": "Changes", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Pin the changes `revset` names (jj) on a file's pane and show them in this view: a lane each after the line number, a line one added whole green; bare, shown here or not (none pinned yet: `@`)."},
+ {"name": "Changes", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Pin the changes `revset` names (jj) on a file's pane and show them in this view: a lane each after the line number, a line one added whole green, what the file no longer has drawn where it stood (ghost rows: a line taken away whole red, each change's description after its last line); bare, shown here or not (none pinned yet: `@`)."},
{"name": "ClipPaste", "leader": "SPC p", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Paste the system clipboard after the selection."},
{"name": "ClipPasteBefore", "leader": "SPC P", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Paste the system clipboard before the selection."},
{"name": "ClipReplace", "leader": "SPC R", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Replace the selection with the system clipboard."},
diff --git a/docs/typ/builtins-tui.json b/docs/typ/builtins-tui.json
index 90dbf091..3ec4ea07 100644
--- a/docs/typ/builtins-tui.json
+++ b/docs/typ/builtins-tui.json
@@ -10,7 +10,7 @@
{"name": "Callstack", "leader": "SPC l b", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Show outermost callers first, with signatures and call sites (gc)."},
{"name": "CallstackDepth", "leader": null, "also": [], "arg": true, "scope": "root", "setting": true, "choices": null, "doc": "Caller levels collected by Callstack, 1 through 64; default 8. Bare, it says the current limit."},
{"name": "Changelog", "leader": "SPC h c", "also": ["topbar"], "arg": false, "scope": "root", "setting": false, "choices": null, "doc": "This build's version and what changed to reach it, printed into an output buffer the same way Config prints the live settings."},
- {"name": "Changes", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Pin the changes `revset` names (jj) on a file's pane and show them in this view: a lane each after the line number, a line one added whole green; bare, shown here or not (none pinned yet: `@`)."},
+ {"name": "Changes", "leader": null, "also": [], "arg": true, "scope": "pane", "setting": false, "choices": null, "doc": "Pin the changes `revset` names (jj) on a file's pane and show them in this view: a lane each after the line number, a line one added whole green, what the file no longer has drawn where it stood (ghost rows: a line taken away whole red, each change's description after its last line); bare, shown here or not (none pinned yet: `@`)."},
{"name": "ClipPaste", "leader": "SPC p", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Paste the system clipboard after the selection."},
{"name": "ClipPasteBefore", "leader": "SPC P", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Paste the system clipboard before the selection."},
{"name": "ClipReplace", "leader": "SPC R", "also": [], "arg": false, "scope": "pane", "setting": false, "choices": null, "doc": "Replace the selection with the system clipboard."},
diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ
index 6216b364..0d55c6a6 100644
--- a/docs/typ/guide.typ
+++ b/docs/typ/guide.typ
@@ -302,8 +302,17 @@ again, and with none pinned yet it is `@`, the change against its parent. Each c
line number, from its first line to its last, in the theme's accents in
hue order, oldest first; a change that rewrote lines inside another's
steps a lane to the right on those rows; a line one added whole is green
-across the line. jj answers once, when the word is run: the lanes stay
-where they were drawn through edits made since.
+across the line. What the file no longer has is drawn where it stood, a
+ghost row with no number: a line a change took away whole, red across;
+each change's description (`id title author age`) after its last line, in
+its lane's colour. The cursor steps over ghost rows, search and selection
+do not see them, and a Look on one opens its line in the revision it came
+from. `]g` and `[g` go to the next and the previous change. jj answers
+once, when the word is run: the lanes and the ghost rows ride with the
+lines through edits made since. A line a change changed is not green across: its
+old text stands right above it as a ghost row, the words that went red,
+and on the line the words that came are green (the patch view's
+alignment says which lines are one line changed).
= Call hierarchy <callstack>