summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-21 20:12:01 -0300
committerGabriel Schneider <[email protected]>2026-11-21 21:34:04 -0300
commit98ff1e611e2fd4cd7f1f3db855a6d52f53ab4b71 (patch)
tree881d8d03277fc29af181ba77c0879368ad47fb1f
parent0d7879195a05b450877d2bf6bd625c01fbfbef8a (diff)
downloadpardes-98ff1e611e2fd4cd7f1f3db855a6d52f53ab4b71.tar.gz
pardes-98ff1e611e2fd4cd7f1f3db855a6d52f53ab4b71.zip
layers: a changed line's words (slice 6): in a run of lines a pinned change took away and wrote, which are one line changed and which words each changed is the patch view's alignment, read off `hunks.format`'s rows of the pin's diff (the library's, called as it is: a paired line's marker has no `ground_line`, its words `ground_emph`; the alignment pairs in order, so the k-th paired line taken away is the k-th paired one written, `jj.pairRun`), where round 3's stand-in made the first as many written as were taken away changed ones: a changed line's old text is a ghost row right above the line (`Ghost.Kind.changed`, its words that went red on no ground, its text grey), the line has the words that came green (`Line.marks`/`nmarks`, `jj.inkCame`, through the row's own columns when it wraps), and neither has the whole-line ground; a line taken away that nothing paired is a ghost row red across above the next changed one's, or after the run; the words are byte ranges kept with jj's answers (`Changes.marks`) and ride with their line; tests: the ghost-rows tests now show `b();` above `b2();` with `b` red and `b2` green and nothing else tinted, and the places and the replay with it; round 3's `two` test reads the words `one`, `1` that went and `two`, `2` that came; core-test 904/1064 (160 skipped), shell-test 1106/1109 (3 skipped)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
-rw-r--r--core/jj.zig242
-rw-r--r--docs/typ/guide.typ5
2 files changed, 197 insertions, 50 deletions
diff --git a/core/jj.zig b/core/jj.zig
index f23d4454..96d9abad 100644
--- a/core/jj.zig
+++ b/core/jj.zig
@@ -226,6 +226,9 @@ pub const Changes = struct {
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);
@@ -233,6 +236,7 @@ pub const Changes = struct {
gpa.free(c.hunks);
gpa.free(c.ghost_text);
gpa.free(c.ghosts);
+ gpa.free(c.marks);
c.* = .{ .serial = c.serial };
}
@@ -279,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.
@@ -311,7 +319,9 @@ pub const Hunk = struct {
/// 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`).
+/// 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`).
@@ -324,8 +334,13 @@ pub const Ghost = struct {
/// 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,
- pub const Kind = enum(u8) { deleted, description };
+ /// 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
@@ -708,11 +723,15 @@ fn parse(gpa: std.mem.Allocator, arena: std.mem.Allocator, logged: []const u8, a
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 (0..out.pins.len) |k| try hunksOf(gpa, arena, @intCast(k), logged[diffs.items[k]..diffs.items[k + 1]], text, out.lines, &hunks, &removed, &marks, &taken);
out.hunks = try hunks.toOwnedSlice(gpa);
nest(out.lines, out.pins.len);
- out.ghosts = try ghostsOf(gpa, arena, out.pins, out.lines, out.hunks, &removed, now);
+ out.ghosts = try ghostsOf(gpa, arena, out.pins, out.lines, out.hunks, taken.items, &removed, now);
out.ghost_text = try removed.toOwnedSlice(gpa);
+ out.marks = try marks.toOwnedSlice(gpa);
kept = true;
return .{ .read = out };
}
@@ -801,17 +820,23 @@ 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.
+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), 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);
@@ -819,25 +844,66 @@ fn hunksOf(gpa: std.mem.Allocator, arena: std.mem.Allocator, k: u16, diffed: []c
.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;
},
.removed => {
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 => {},
}
}
+ // 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;
@@ -847,32 +913,71 @@ 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, where it stood (`carried` into the last pin's revision); and each
+/// whole or changed, 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 {
+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) error{OutOfMemory}![]Ghost {
const Made = struct { g: Ghost, rank: u64 };
var made: std.ArrayList(Made) = .empty;
+ var ti: usize = 0;
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);
+ if (h.old_len == 0) 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, lines.len);
+ 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, lines.len);
+ ats[k] = at;
+ }
var from: usize = h.removed;
- for (0..h.old_len) |k| {
+ for (run, 0..) |t, n| {
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) },
+ try made.append(arena, .{
+ .g = .{ .at = ats[n], .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,
});
from = nl + 1;
@@ -983,10 +1088,20 @@ fn ghostLanes(ch: *const Changes, ghosts: []const Ghost, gi: usize) [levels]PinI
/// 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 {
+fn inkGhost(p: *Pardes, s: *pardes.Surface, g: Ghost, text: []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 said = text[g.text..][0..g.len];
+ 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 => {
const said = text[g.text..][0..g.len];
// `id title author age`: the last two words grey.
@@ -999,6 +1114,25 @@ fn inkGhost(p: *Pardes, s: *pardes.Surface, g: Ghost, text: []const u8, colours:
}
}
+/// 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
@@ -1150,13 +1284,14 @@ pub fn paint(p: *Pardes, s: *pardes.Surface, pane: *Pane, r: pardes.Rect, tx: u1
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);
+ inkGhost(p, s, pane.ghosts[gi], pane.ghost_text, 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| {
@@ -1347,11 +1482,14 @@ 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 },
@@ -1631,9 +1769,10 @@ const Ghosts = struct {
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] };
+ /// 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] };
}
};
@@ -1664,7 +1803,7 @@ test "Changes draws what the text has not where it stood, as ghost rows: a line
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", "" };
+ 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));
@@ -1677,9 +1816,9 @@ test "Changes draws what the text has not where it stood, as ghost rows: a line
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 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, .add, .none, .del, .del, .none, .add, .add, .none };
+ 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) {
@@ -1707,16 +1846,21 @@ test "Changes draws what the text has not where it stood, as ghost rows: a line
}
// 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|
+ 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 + 5).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))[4]));
+ try testing.expectEqualStrings(said[2], Ghosts.text(pane, (try Ghosts.rows(p, pane, arena.allocator(), &buf))[5]));
}
}
@@ -1741,7 +1885,7 @@ test "the cursor steps over ghost rows and selection does not see them; ]g and [
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);
+ 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();
@@ -1750,8 +1894,8 @@ test "the cursor steps over ghost rows and selection does not see them; ]g and [
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));
+ 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).
@@ -1768,8 +1912,8 @@ test "the cursor steps over ghost rows and selection does not see them; ]g and [
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 } });
+ 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.?;
@@ -1800,18 +1944,18 @@ test "ghost rows ride with the text: a line deleted above moves them up, a line
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));
+ 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, &.{ 3, 3, 3, 3, 5 }, ats(answered(a.core, serial).?, &got));
+ 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, &.{ 3, 3, 3, 3, 4 }, ats(answered(a.core, serial).?, &got));
+ 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()));
diff --git a/docs/typ/guide.typ b/docs/typ/guide.typ
index 126c38df..0d55c6a6 100644
--- a/docs/typ/guide.typ
+++ b/docs/typ/guide.typ
@@ -309,7 +309,10 @@ 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.
+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>