summaryrefslogtreecommitdiff
path: root/src/body_layer.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-15 15:33:30 -0300
committerGabriel Schneider <[email protected]>2026-09-15 17:24:42 -0300
commit8ac4a48a2e8e66a9e72bcbc61c114be8db9215fd (patch)
tree4c48ecd42a800b12daed0712a4620639d1631f7e /src/body_layer.zig
parentc1787ff868ee723629c1d500098d36dc419f77c3 (diff)
downloadpardes-8ac4a48a2e8e66a9e72bcbc61c114be8db9215fd.tar.gz
pardes-8ac4a48a2e8e66a9e72bcbc61c114be8db9215fd.zip
Separate discontinuous pinned source context with thin borders
Diffstat (limited to 'src/body_layer.zig')
-rw-r--r--src/body_layer.zig29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/body_layer.zig b/src/body_layer.zig
index 3b5ee795..14fb91ec 100644
--- a/src/body_layer.zig
+++ b/src/body_layer.zig
@@ -3,6 +3,7 @@
const std = @import("std");
const pardes = @import("pardes.zig");
const config = @import("config.zig");
+const limits = @import("memory.zig").limits;
pub const Metrics = struct {
body_w: u16 = 1,
@@ -18,9 +19,24 @@ pub const Layer = struct {
cols: u16 = 0,
rows: u16 = 0,
context_rows: u16 = 0,
+ context_separators: std.bit_set.StaticBitSet(limits.wrap_rows) = .initEmpty(),
cells: []pardes.Cell = &.{},
cursor: ?struct { x: u16, y: u16, bar: bool = false } = null,
+ pub fn setContextLines(layer: *Layer, lines: []const i32) void {
+ layer.context_separators = .initEmpty();
+ const count = @min(lines.len, layer.context_rows);
+ var row: usize = 0;
+ while (row + 1 < count and row < limits.wrap_rows) : (row += 1) {
+ if (lines[row + 1] != lines[row] +| 1) layer.context_separators.set(row);
+ }
+ }
+
+ pub fn hasContextBorderAfter(layer: *const Layer, row: usize) bool {
+ if (row >= layer.context_rows or row >= limits.wrap_rows) return false;
+ return row + 1 == layer.context_rows or layer.context_separators.isSet(row);
+ }
+
pub fn rowTop(layer: *const Layer, row: u16, body_h: f32, tagline_h: f32) f32 {
const body = @max(1, body_h);
const tag = std.math.clamp(tagline_h, 1, body);
@@ -78,3 +94,16 @@ test "compact body layer rows fill reclaimed height and invert exact boundaries"
try std.testing.expect(layer.hitAt(39.99, 80, 10, 20, 6, 12) == null);
try std.testing.expect(layer.hitAt(std.math.nan(f32), 80, 10, 20, 6, 12) == null);
}
+
+test "compact context borders separate source gaps and preserve multiline headers" {
+ var layer: Layer = .{ .context_rows = 6 };
+ layer.setContextLines(&.{ 3, 4, 8, 9, 10, 17 });
+ const expected = [_]bool{ false, true, false, false, true, true, false };
+ for (expected, 0..) |border, row| try std.testing.expectEqual(border, layer.hasContextBorderAfter(row));
+ layer.context_rows = 2;
+ layer.setContextLines(&.{ 9, 10 });
+ try std.testing.expect(!layer.hasContextBorderAfter(0));
+ try std.testing.expect(layer.hasContextBorderAfter(1));
+ try std.testing.expect(!layer.hasContextBorderAfter(4));
+ try std.testing.expect(!layer.context_separators.isSet(4));
+}