summaryrefslogtreecommitdiff
path: root/src/file_pane.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/file_pane.zig')
-rw-r--r--src/file_pane.zig6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/file_pane.zig b/src/file_pane.zig
index 8fc0fa0d..1c6d5e2f 100644
--- a/src/file_pane.zig
+++ b/src/file_pane.zig
@@ -92,6 +92,12 @@ pub fn dumpPane(
pub fn graphemeDisplayWidth(grapheme: []const u8) usize {
if (std.mem.eql(u8, grapheme, "\t")) return config.tab_width;
+ // A one-byte printable ASCII grapheme is one cell, and saying so here rather than asking
+ // `gwidth` costs a comparison instead of a Unicode table walk. `gwidth` was 6.9% of a profiled
+ // keystroke at the P4's geometry, essentially all of it answering this question about `y`.
+ // Bounded to 0x20..0x7e on purpose: DEL and the C0 controls are not one printable cell, and
+ // `gwidth` is still the authority on them.
+ if (grapheme.len == 1 and grapheme[0] >= 0x20 and grapheme[0] < 0x7f) return 1;
return @max(1, @as(usize, vaxis.gwidth.gwidth(grapheme, .unicode)));
}