summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-21 18:47:01 -0300
committerGabriel Schneider <[email protected]>2026-11-21 21:34:04 -0300
commit0d7879195a05b450877d2bf6bd625c01fbfbef8a (patch)
tree78ee67251d7919335c2a7ac5e06afe2bbf158f24 /core
parentb7e843256982f5a22954d103bb40264daf2bb758 (diff)
downloadpardes-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')
-rw-r--r--core/Core.zig1
-rw-r--r--core/File.zig45
-rw-r--r--core/Places.zig5
-rw-r--r--core/Query.zig5
-rw-r--r--core/Tables.zig1
-rw-r--r--core/body_layer.zig5
-rw-r--r--core/builtins.zig2
-rw-r--r--core/config.zig1
-rw-r--r--core/jj.zig505
-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
14 files changed, 572 insertions, 35 deletions
diff --git a/core/Core.zig b/core/Core.zig
index efa2ac3d..2f93209e 100644
--- a/core/Core.zig
+++ b/core/Core.zig
@@ -1912,6 +1912,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..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);
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 78b8e0b9..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,
@@ -406,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..f23d4454 100644
--- a/core/jj.zig
+++ b/core/jj.zig
@@ -221,14 +221,18 @@ 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 = &.{},
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);
c.* = .{ .serial = c.serial };
}
@@ -297,11 +301,33 @@ pub const Hunk = struct {
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,
};
+/// 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`).
+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,
+
+ pub const Kind = enum(u8) { deleted, description };
+};
+
/// The `Changes` word (builtins.zig registers it): in a file's pane (or a
/// revision's), the changes `revset` names pinned on the pane and shown in
/// this view; another revset replaces them (in every view that shows
@@ -485,7 +511,13 @@ fn answer(p: ?*Pardes, gpa: std.mem.Allocator, a: *const Ask) pardes.Stream.Batc
const log_args = [_][]const u8{ "log", "--no-graph", "--reversed", "-r", query, "-T", log_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| {
@@ -504,6 +536,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 +590,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 +616,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 +658,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,6 +683,7 @@ 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;
@@ -648,8 +710,9 @@ fn parse(gpa: std.mem.Allocator, arena: std.mem.Allocator, logged: []const u8, a
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);
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, &removed, now);
+ out.ghost_text = try removed.toOwnedSlice(gpa);
kept = true;
return .{ .read = out };
}
@@ -788,6 +851,192 @@ fn hunksOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, k: u16, diffed: []c
}
}
+/// The ghost rows (`Ghost`), in `at` order: each line a pin took away
+/// whole, where it stood (`carried` into the last pin's revision); 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,
+/// then the descriptions of pins that have only those. `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, text: *std.ArrayList(u8), now: i64) error{OutOfMemory}![]Ghost {
+ const Made = struct { g: Ghost, rank: u64 };
+ var made: std.ArrayList(Made) = .empty;
+ for (hunks) |h| {
+ // Round 3's stand-in until slice 6: as many lines taken away as
+ // were written are changed ones, the rest taken away whole.
+ const changed = @min(h.old_len, h.new_len);
+ if (changed == h.old_len) continue;
+ const at = carried(hunks, h.pin, if (h.new_len > 0) h.new_start - 1 + h.new_len else h.new_start, lines.len);
+ var from: usize = h.removed;
+ for (0..h.old_len) |k| {
+ const nl = std.mem.indexOfScalarPos(u8, text.items, from, '\n') orelse text.items.len;
+ if (k >= changed) try made.append(arena, .{
+ .g = .{ .at = at, .pin = h.pin, .kind = .deleted, .line = h.old_start + @as(u32, @intCast(k)), .text = @intCast(from), .len = @intCast(nl - from) },
+ .rank = 1 << 32 | made.items.len,
+ });
+ from = nl + 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 at_text = text.items.len;
+ try describe(gpa, text, pin, now);
+ try made.append(arena, .{
+ .g = .{ .at = at orelse carried(hunks, @intCast(k), end, lines.len), .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 last
+/// pin's: moved by each later pin's hunks before it, or, inside a run of
+/// lines a later pin took away, after what it wrote there. (A change the
+/// revset does not pin, between two it does, is not seen: its lines move
+/// the places below it by as many.)
+fn carried(hunks: []const Hunk, k: u16, after: u32, lines: usize) u32 {
+ var pos: i64 = after;
+ var i: usize = 0;
+ while (i < hunks.len) {
+ const j = hunks[i].pin;
+ var shift: i64 = 0;
+ var inside: ?i64 = null;
+ while (i < hunks.len and hunks[i].pin == j) : (i += 1) {
+ const h = hunks[i];
+ if (j <= k) 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 > k) pos = inside orelse pos + shift;
+ }
+ return @intCast(std.math.clamp(pos, 0, @as(i64, @intCast(lines))));
+}
+
+/// 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 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.
+fn inkGhost(p: *Pardes, s: *pardes.Surface, g: Ghost, text: []const u8, 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),
+ .description => {
+ const said = text[g.text..][0..g.len];
+ // `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 };
+ },
+ }
+}
+
+/// 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.
/// A pin's block runs from a line it wrote on to each next line it wrote
/// while every line between was written by a newer pin: its lane unbroken
@@ -878,9 +1127,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 +1146,20 @@ 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;
+ inkGhost(p, s, pane.ghosts[gi], pane.ghost_text, 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);
+ break :line line.lanes;
+ };
+ for (lanes, 0..) |lane, level| {
if (lane == .none) break;
const rgb = colours[@intFromEnum(lane) % colours.len];
if (windowed) {
@@ -1101,7 +1358,7 @@ test "Changes pins a revset's changes on the pane, shown in this view: who wrote
.{ .pin = 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);
@@ -1311,10 +1568,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 +1604,219 @@ 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.
+ fn want(said: [3][]const u8) [11][]const u8 {
+ return .{ "fn f() void {", " a();", " 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", "01", "01", "01", "0", "0", "0" };
+ const Ground = enum { none, add, del };
+ const ground = [_]Ground{ .add, .add, .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{ 4, 7, 10 }, [_]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 + 5).style.fg);
+ // 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))[4]));
+ }
+}
+
+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, 8), 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 + 5).style.bg);
+ try testing.expect(!std.meta.eql(s.at(x, body.y + 5).style.bg, s.at(x, body.y + 3).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 + 5 } });
+ p.update(.{ .mouse = .{ .button = .right, .kind = .release, .col = x, .row = body.y + 5 } });
+ 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, &.{ 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, &.{ 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, &.{ 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()));
+}
+
/// 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 8b152132..df85a508 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).
@@ -303,6 +303,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,
@@ -591,10 +599,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 5c91afd1..166c8c16 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", 75, "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" },