summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-29 12:22:50 -0300
committerGabriel Schneider <[email protected]>2026-10-29 14:30:01 -0300
commitc4f3749c058121ba086a851188691e7ae40d2018 (patch)
tree670de57e99619809d88828d589ea3af2b7483995
parent3b793d1d349c01bf6046b0f87742f16755069115 (diff)
downloadpardes-c4f3749c058121ba086a851188691e7ae40d2018.tar.gz
pardes-c4f3749c058121ba086a851188691e7ae40d2018.zip
a row's last byte deep in a long line is found walking to its column only: rawAtDisplay no longer measures the rest of the line first
File.rawAtDisplay took the display width of the whole rest of the line before walking to the column, so every byteAtRowDisplay on a row of a 2 MB line measured 2 MB: a selection whose head is deep in such a line, with the line's first rows in view, drew in 20 ms (Debug) instead of 0.1. Only a line that ends before the column is measured whole now, and it is short. Same answers, at the end and past it included (the test). The perf gate's deep-sel cell had never drawn that line: its view, set by ensureCursorVisible from the last frame's wrap map, stopped six lines short of it. With the map made for the view as it is (File.geometry, next commit) the line is in view and the walk showed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
-rw-r--r--src/File.zig9
-rw-r--r--test/panes.zig3
2 files changed, 9 insertions, 3 deletions
diff --git a/src/File.zig b/src/File.zig
index 6df49c98..e4bca000 100644
--- a/src/File.zig
+++ b/src/File.zig
@@ -509,10 +509,13 @@ pub fn rawDisplayCol(line_text: []const u8, raw_col: usize) usize {
return displayWidth(line_text[0..bounded]) +| (raw_col -| line_text.len);
}
+/// Walked only as far as the column: a row's last byte, a million bytes
+/// into a line, is found without measuring the rest of it. Only a line
+/// that ends before the column is measured whole (it is short).
pub fn rawAtDisplay(line_text: []const u8, display_col: usize) usize {
- const width = displayWidth(line_text);
- if (display_col > width) return line_text.len +| (display_col - width);
- return byteAtDisplay(line_text, display_col);
+ const at = byteAtDisplay(line_text, display_col);
+ if (at < line_text.len) return at;
+ return line_text.len +| (display_col -| displayWidth(line_text));
}
pub fn byteAtDisplayFrom(line_text: []const u8, from_raw: usize, display_col: usize) usize {
diff --git a/test/panes.zig b/test/panes.zig
index e2cd85dc..0379a03d 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -2661,6 +2661,9 @@ const FileTests = struct {
try std.testing.expectEqual(text.len, byteAtDisplay(text, 5));
try std.testing.expectEqual(@as(usize, 3), rawDisplayCol(text, 5));
try std.testing.expectEqual(@as(usize, 5), rawAtDisplay(text, 3));
+ // At the line's end and past it (virtual columns, one byte each).
+ try std.testing.expectEqual(text.len, rawAtDisplay(text, 5));
+ try std.testing.expectEqual(text.len + 2, rawAtDisplay(text, 7));
try std.testing.expectEqual(@as(usize, 2), graphemeDisplayWidth("👩\u{200d}🚀"));
}