diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-21 07:02:01 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-21 07:02:01 -0300 |
| commit | f7de6f49ee3d9ac241575f5244743193c9943841 (patch) | |
| tree | 9f77af1eab8bfba6a4c8cfc75fe5ec646d517ffe /core/File.zig | |
| parent | 78a022adb2a657711f706fcaae7c2abb412dac9c (diff) | |
| download | pardes-f7de6f49ee3d9ac241575f5244743193c9943841.tar.gz pardes-f7de6f49ee3d9ac241575f5244743193c9943841.zip | |
layers: what round 1 left, three places where a revision's pane or a patch's did not do what the design's words say: a B3 click on path@rev[:line] in running text opens the file at that revision there (the click already expanded the whole token, @ being a file character; jj's test now drives it through the mouse); a revision's text is read-only over 9P too: an open of its body, data, xdata or sel to write is refused in words ("a revision is read-only", errno EROFS, as enameErrno reads the words: core/ninep/tree.zig's open, the one road 9P has to the text; the editor's own two are File.edit's splice and edit.zig's whole text), where before the write reached File.edit and was answered "out of memory"; Syntax off in a patch's pane takes the language's ink and leaves the patch: its bytes are made again once a paint without the language's (syntax.highlightDiffPlain), grounds, markers and changed words as they were (round 1 took them too); tests: the click, the four opens, a .zig patch's cells' grounds the same and its ink not; tui core-test 893/1053 (160 skipped)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core/File.zig')
| -rw-r--r-- | core/File.zig | 57 |
1 files changed, 51 insertions, 6 deletions
diff --git a/core/File.zig b/core/File.zig index 01aaeec8..450e4ec9 100644 --- a/core/File.zig +++ b/core/File.zig @@ -1864,8 +1864,8 @@ fn fillBody(tab: u16, dst: ?[]u8, pane: *Pane, f: *State, width: usize, record_w /// highlightFileRange): on until `Syntax` turns it off; /// 2. patch: a diff's or a patch's grounds, a `+`/`-` row's ground and /// marker and the words a changed line changed (syntax.zig's -/// highlightDiff): always, in a diff (its style bytes are the ink's -/// too: `Syntax` off takes both). +/// highlightDiff): always, in a diff (with `Syntax` off its bytes are +/// made without the language's ink: highlightDiffPlain). /// /// Both are painted in recolorSyntax's one walk over the cells, each where /// it says (one walk per painter cost a frame a sixth more). Ruled, not @@ -1886,10 +1886,16 @@ pub fn synStyle(p: *Pardes, sy: syntax.Syn) ?SynStyle { /// syntax colors: recolor each content cell from its tree-sitter style byte; /// content starts after the lineno gutter pub fn recolorSyntax(p: *Pardes, s: *Surface, pane: *Pane, f: *State, r: pardes.Rect, tx: u16, tw: u16, body_h: u16) void { - // The ink off (`Syntax`): no style byte is read, so a cell asks - // nothing of it (a test a cell cost a frame 0.1 to 0.5%). A patch's - // grounds are bytes of the same painter's: they go with it. - const highlights: []const u8 = if (!pane.layers.ink) &.{} else if (f.mini) |mini| mini.colors else f.highlights; + // The ink off (`Syntax`): a file's style bytes are not read, so a cell + // asks nothing of it (a test a cell cost a frame 0.1 to 0.5%); a + // patch's are made again without the language's, once a paint, its + // grounds, markers and changed words kept. + const highlights: []const u8 = if (pane.layers.ink) + (if (f.mini) |mini| mini.colors else f.highlights) + else if (pane.colorAlgo() == .diff and f.highlights.len > 0) + syntax.highlightDiffPlain(p.scratch.allocator(), f.content, f.highlight_start, f.highlight_start + f.highlights.len) catch &.{} + else + &.{}; const highlight_start = if (f.mini != null) 0 else f.highlight_start; const spans = f.pager_spans; if (highlights.len == 0 and f.output == null and spans.len == 0) return; @@ -2614,3 +2620,42 @@ test "Syntax takes a text's ink off in this view and puts it back, and another v try Frame.take(p, &arena, pane, id, &inks); try std.testing.expect(Frame.colored(&inks, plain)); } + +test "Syntax off in a patch's pane takes the language's ink and leaves the patch: every ground as it was" { + if (!syntax.supportsPath("/x.zig")) return error.SkipZigTest; + const gpa = std.testing.allocator; + // A patch's hunks take their language's ink once the parsers run. + syntax.start(gpa); + defer syntax.stop(); + const p = try Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 14 }); + defer p.deinit(); + const pane = try p.setTestFile("diff --git a/x.zig b/x.zig\n--- a/x.zig\n+++ b/x.zig\n@@ -1,2 +1,2 @@\n const a = 1;\n-const b = 2;\n+pub const b = 3;\n"); + gpa.free(pane.file.?.path); + pane.file.?.path = try gpa.dupe(u8, "/change.diff"); + pane.file.?.syntax_dirty = true; + try std.testing.expect(pane.colorAlgo() == .diff); + const id = p.view().active; + var arena: std.heap.ArenaAllocator = .init(gpa); + defer arena.deinit(); + var on: [7][2][24]pardes.Color = undefined; + for (0..2) |pass| { + if (pass == 1) p.update(.{ .command = "Syntax" }); + p.sync(); + _ = arena.reset(.retain_capacity); + const s = try p.render(arena.allocator()); + const body = s.region(.body, id).?.rect; + var differ = false; + for (0..7) |row| for (0..24) |col| { + const cell = s.cells[(body.y + row) * s.cols + body.x + gutterWidth(pane) + col]; + if (pass == 0) { + on[row][0][col] = cell.style.bg; + on[row][1][col] = cell.style.fg; + } else { + // The grounds stay; the ink of the code goes. + try std.testing.expect(std.meta.eql(on[row][0][col], cell.style.bg)); + differ = differ or !std.meta.eql(on[row][1][col], cell.style.fg); + } + }; + if (pass == 1) try std.testing.expect(differ); + } +} |
