szn

Bug 432 — Status-bar visibleLen counts codepoints, not cells; wide-char window names mis-hit on mouse

432. Status-bar visibleLen counts codepoints, not cells; wide-char window names mis-hit on mouse

Severity: MEDIUM Status: Fixed

visibleLen counts one column per codepoint, treating wide characters (CJK, emoji, etc.) as a single column:

// src/status.zig:108-123
pub fn visibleLen(s: []const u8) usize {
    var cols: usize = 0;
    var i: usize = 0;
    while (i < s.len) {
        if (s[i] == 0x1b) { i = skipEscape(s, i); continue; }
        const cp_len = std.unicode.utf8ByteSequenceLength(s[i]) catch 1;
        cols += 1; // always +1, ignores wide chars
        i += cp_len;
    }
    return cols;
}

buildLine derives the per-window mouse hit ranges from this metric:

// src/status.zig:331-341
const cols = visibleLen(piece);
const start_col = centre_cursor;
centre_cursor += cols;
try r.append(allocator, .{ .pos = ..., .start_col = ..., .end_col = centre_cursor });

Problem & Impact

Proposed Fix

Use char_width.zig cell-width lookup inside visibleLen (count 2 for wide chars), or compute the ranges from the same width function the renderer uses, so the internal ranges match terminal cell coordinates.