id == 0 blank trimming, and combining characterschar, comb1, comb2) as text codepointsSeverity: HIGH
Status: ✅ RESOLVED
Files: src/grid.zig:560-576, src/grid.zig:928-960, src/grid.zig:1011-1033, src/screen.zig:803, src/screen.zig:851
When cell.attr.sixel == true, cell.char stores id & 0x1FFFFF and (cell.comb1, cell.comb2) store the cell offsets (dx, dy) from the top-left of the image. Three code paths treat these fields as ordinary text codepoints without checking cell.attr.sixel:
id == 0 cell (0, 0) trimmed as blank (src/grid.zig:562, src/grid.zig:1011, src/grid.zig:1033):
For the first sixel image (id == 0), the top-left marker cell (dx = 0, dy = 0) has char == 0, comb1 == 0, comb2 == 0, is_padding == false, attr.sixel == true.
Grid.lineHasContent (src/grid.zig:562) checks c.char != 0 or c.comb1 != 0 or c.comb2 != 0 without or c.attr.sixel.Grid.reflowCursorInternal’s trailing-blank trimmers (src/grid.zig:1011 and :1033) check c.char == 0 and !c.is_padding and c.comb1 == 0 and c.comb2 == 0 without and !c.attr.sixel. If a row ends at cell (0, 0) of image 0, reflow trims the marker cell.Grid.rewrap interprets cell.char (sixel ID) as a Unicode codepoint (src/grid.zig:928-960):
findClusterEnd (src/grid.zig:951) calls char_width.charWidth(cells[idx].char). When id == 0, charWidth(0) == 0; when id falls in a Thai/Lao range (0x0E01..0x0EFF), findThaiClusterEnd runs on sixel marker cells; when id falls in a wide CJK/emoji range, clusterWidth (src/grid.zig:928) returns width 2 and rewrap inserts a synthetic is_padding cell after the sixel marker, corrupting marker alignment and sixel_refcounts.(comb1, comb2) on sixel markers (src/screen.zig:803, src/screen.zig:851):
In Screen.writeChar, when w == 0 (a combining character), prev_cell is checked with if (prev_cell.char != 0 and !prev_cell.is_padding) without and !prev_cell.attr.sixel. Writing a combining mark after a sixel marker cell overwrites prev_cell.comb1 or prev_cell.comb2, corrupting the sixel dx/dy offset.or c.attr.sixel to Grid.lineHasContent and and !c.attr.sixel to the blank-cell checks in Grid.reflowCursorInternal.Grid.findClusterEnd and Grid.clusterWidth, return idx + 1 and width 1 immediately when cells[idx].attr.sixel is true.Screen.writeChar (lines 803 and 851), require !prev_cell.attr.sixel before attaching combining marks to prev_cell.