Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(glyphgrid): a double-width character draws BOTH its cells, not just the first

enes139eecd0f2a2
diff --git a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
index 06358a7e8..cda32b3d3 100644
--- a/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
+++ b/docs/superpowers/plans/2026-08-03-phase1b-device-checklist.md
@@ -299,7 +299,22 @@ Auto after you switched builds, that is why: re-select Shared and carry on.
leaves nothing behind. Repeat with **Cursor style = underline** (the rule runs the full width
of the character, not half of it) and with the terminal **blurred** (the outline boxes the
whole character). `bar` is the deliberate exception: it stays ONE hairline on the left edge,
- because it marks the insertion point rather than the cell.
+ because it marks the insertion point rather than the cell. Since 2026-08-05 the right half
+ carries INK as well as background, so check that the inversion covers the **glyph**, not just
+ the block behind it — an un-inverted right half of 日 now means the follower's slot was keyed
+ on the wrong colours.
+
+- [ ] **2.16 A double-width character is WHOLE.** The 2026-08-05 report: ⭐ arrived as a fragment,
+ because a slot's ink box is one cell and the follower cell was written blank. Print a row of
+ wide characters — `printf '⭐ 👍 😄 日本語 中文\n'` — and compare against **GPU per terminal**
+ on the same line. Each character is complete, and its two halves **meet without a step**: no
+ seam of background down the middle, no visible offset between the halves, no doubled left
+ half. Then repeat with **bold** on (`printf '\033[1m⭐ 日本語\033[0m\n'`) — the two halves must
+ come off the same face, so a bold left half beside a regular right half is the failure.
+ Expected residual: the seam may show a hairline difference in antialiasing, because the two
+ halves are rasterized at different sub-texel phases (see `inkX` in `raster.ts`). A hairline is
+ the accepted cost; a visible break or a colour seam is not. Characters wider than two cells
+ are still cut — that is L16, unchanged.
## 3. Interactions
@@ -687,13 +702,22 @@ Auto after you switched builds, that is why: re-select Shared and carry on.
through. (The node's OWN flyout/pill is fine — selection elevation lifts them with it, which is
what 3.9c tests.) Fixing this means feeding real chrome geometry into the rule — Phase 2, and
the same question the "chrome on the canvas" answer settles for free.
-- **L16 — A font-drawn glyph whose INK EXCEEDS ITS CELL is clipped; the overflow is lost.** The
- rasterizer clips every `fillText` to the slot's own cell (`raster.ts` step 2), because a glyph
- that reached into the gutter would land in a neighbour's mip neighbourhood. xterm's own
+- **L16 — A font-drawn SINGLE-WIDTH glyph whose INK EXCEEDS ITS CELL is clipped; the overflow is
+ lost.** The rasterizer clips every `fillText` to the slot's own cell (`raster.ts` step 2), because
+ a glyph that reached into the gutter would land in a neighbour's mip neighbourhood. xterm's own
`TextureAtlas` has no such limit — it MEASURES each glyph's real bounding box, sizes the slot to
the ink and renders a quad of that size, so ink may overhang into the neighbouring cells. That is
why GPU mode can show shapes shared mode truncates.
+ **DOUBLE-WIDTH characters left this limitation on 2026-08-05** (emoji, CJK). Their overflow was
+ never really overflow: the terminal has already reserved a second cell for them, and the feed was
+ writing it BLANK — so ⭐ arrived as a fragment (the 2026-08-05 device report). They need no
+ ink-sized slot, only a second cell-sized one holding the character's right half: `glyphFor(…,
+ half)` keys a second slot, `raster.ts` draws it with the glyph's origin one cell left, and the
+ feed writes it into the follower's lane instead of a blank. Nothing this limitation defends moved
+ — each half is still clipped to its own cell box, still 2*GUTTER_PX from its neighbour's ink, and
+ the shader is untouched. Verify by item **2.16**. A glyph wider than TWO cells is still cut.
+
The 2026-08-04 device round measured one instance: **U+23BF ⎿**, Claude Code's tool-result
connector, kept about a third of its horizontal foot (8 px against GPU mode's 28). The **escape
hatch used so far** is the geometric table — a glyph we DRAW is full-cell by construction, so the
diff --git a/src/renderer/canvas/SharedGlyphLayer.tsx b/src/renderer/canvas/SharedGlyphLayer.tsx
index aa7949589..c00dff6f3 100644
--- a/src/renderer/canvas/SharedGlyphLayer.tsx
+++ b/src/renderer/canvas/SharedGlyphLayer.tsx
@@ -724,13 +724,16 @@ function glyphDebugOn(): boolean {
function glyphDebugTap(): ((info: GlyphSlotAllocation) => void) | undefined {
if (!glyphDebugOn()) return undefined
- return ({ slot, code, bold, italic, x, y, fg, bg }): void => {
+ return ({ slot, code, bold, italic, x, y, fg, bg, half }): void => {
console.warn(
`[glyphgrid] slot ${slot} code 0x${code.toString(16)} ${JSON.stringify(
String.fromCodePoint(code)
- )}${bold ? ' bold' : ''}${italic ? ' italic' : ''} at ${x},${y} fg=${fg.toString(
- 16
- )} bg=${bg.toString(16)}`
+ )}${bold ? ' bold' : ''}${italic ? ' italic' : ''}${
+ // Only the RIGHT half is called out. Every ordinary glyph is a left half, so printing that
+ // on every line would be noise on the one log a device round reads line by line — and a
+ // wide character not showing its pair here is exactly the failure worth spotting.
+ half === 1 ? ' right-half' : ''
+ } at ${x},${y} fg=${fg.toString(16)} bg=${bg.toString(16)}`
)
}
}
diff --git a/src/renderer/glyphgrid/atlas.test.ts b/src/renderer/glyphgrid/atlas.test.ts
index 9f916935c..549f4243c 100644
--- a/src/renderer/glyphgrid/atlas.test.ts
+++ b/src/renderer/glyphgrid/atlas.test.ts
@@ -6,15 +6,24 @@ import { GUTTER_PX, GlyphAtlas, type GlyphRasterizer, type GlyphSlotAllocation }
const FG = 11
const BG = 22
-function fakeRasterizer(cellW = 10, cellH = 20): GlyphRasterizer & { calls: string[] } {
+function fakeRasterizer(
+ cellW = 10,
+ cellH = 20
+): GlyphRasterizer & { calls: string[]; halves: number[] } {
const calls: string[] = []
+ // Which half of a double-width character each draw was for, at the same index as `calls` (the
+ // CLEAR entries aside). Its own array so the recorded call STRING — read verbatim by a dozen
+ // layout assertions below — keeps its shape.
+ const halves: number[] = []
return {
cellW,
cellH,
calls,
+ halves,
source: null,
- draw(code, bold, italic, x, y, fg, bg) {
+ draw(code, bold, italic, x, y, fg, bg, half = 0) {
calls.push(`${code}|${bold ? 'b' : ''}${italic ? 'i' : ''}|${fg}|${bg}@${x},${y}`)
+ halves.push(half)
},
// Logged into the SAME array as the draws, so "the page was blanked BEFORE the triggering
// glyph was drawn into it" is one ordering assertion rather than two independent counters.
@@ -66,7 +75,7 @@ describe('GlyphAtlas', () => {
expect(atlas.glyphFor(0x41, false, false, FG, BG + 1)).not.toBe(a)
})
- it('every lane of the key participates — no two of the five collide', () => {
+ it('every lane of the key participates — no two of the six collide', () => {
const atlas = new GlyphAtlas(fakeRasterizer(), 100)
const slots = [
atlas.glyphFor(0x41, false, false, FG, BG),
@@ -74,11 +83,43 @@ describe('GlyphAtlas', () => {
atlas.glyphFor(0x41, true, false, FG, BG), // bold
atlas.glyphFor(0x41, false, true, FG, BG), // italic
atlas.glyphFor(0x41, false, false, FG + 1, BG), // fg
- atlas.glyphFor(0x41, false, false, FG, BG + 1) // bg
+ atlas.glyphFor(0x41, false, false, FG, BG + 1), // bg
+ atlas.glyphFor(0x41, false, false, FG, BG, 1) // half
]
expect(new Set(slots).size).toBe(slots.length)
})
+ describe('the two halves of a double-width character', () => {
+ // A slot's ink box is exactly one cell and raster.ts cuts the overflow, so an emoji or a CJK
+ // ideograph — which the terminal has already given TWO cells — lost its right half entirely.
+ // It gets a second slot instead: same character, same style, same colours, other half.
+ it('are separate slots, and the second is drawn shifted one cell left', () => {
+ const r = fakeRasterizer()
+ const atlas = new GlyphAtlas(r, 100)
+ const left = atlas.glyphFor(0x4e2d, false, false, FG, BG, 0)
+ const right = atlas.glyphFor(0x4e2d, false, false, FG, BG, 1)
+ expect(right).not.toBe(left)
+ // The atlas does NOT shift anything itself — it hands the rasterizer this slot's own ink
+ // origin and the half, and the shift is raster.ts's (see its `inkX`). Pinned here because
+ // a half that never reached the rasterizer would key two slots and paint them identically.
+ expect(r.halves).toEqual([0, 1])
+ })
+
+ it('cache independently — asking for one never returns the other', () => {
+ const atlas = new GlyphAtlas(fakeRasterizer(), 100)
+ const left = atlas.glyphFor(0x4e2d, false, false, FG, BG, 0)
+ const right = atlas.glyphFor(0x4e2d, false, false, FG, BG, 1)
+ expect(atlas.glyphFor(0x4e2d, false, false, FG, BG, 0)).toBe(left)
+ expect(atlas.glyphFor(0x4e2d, false, false, FG, BG, 1)).toBe(right)
+ })
+
+ it('default to the LEFT half, so every existing caller is unchanged', () => {
+ const atlas = new GlyphAtlas(fakeRasterizer(), 100)
+ const implicit = atlas.glyphFor(0x41, false, false, FG, BG)
+ expect(atlas.glyphFor(0x41, false, false, FG, BG, 0)).toBe(implicit)
+ })
+ })
+
// packColor's own `>>> 0` note applies one layer up: `0xff << 24` is NEGATIVE in JS, so the
// same colour reaches this file as -16777216 from an arithmetic path and as 4278190080 from a
// `readCell` lane. Two spellings of one colour would mean two slots holding identical pixels —
@@ -487,10 +528,12 @@ describe('GlyphAtlas', () => {
atlas.glyphFor(0x78, true, false, FG, BG) // a different style IS a different slot
atlas.glyphFor(0x78, false, false, FG + 1, BG) // …and so is a different colour
atlas.glyphFor(0x20, false, false, FG, BG) // the blank slot is never an allocation
+ atlas.glyphFor(0x78, false, false, FG, BG, 1) // …and so is the other half
expect(seen).toEqual([
- { slot: 1, code: 0x78, bold: false, italic: false, x: 16, y: 2, fg: FG, bg: BG },
- { slot: 2, code: 0x78, bold: true, italic: false, x: 30, y: 2, fg: FG, bg: BG },
- { slot: 3, code: 0x78, bold: false, italic: false, x: 44, y: 2, fg: FG + 1, bg: BG }
+ { slot: 1, code: 0x78, bold: false, italic: false, x: 16, y: 2, fg: FG, bg: BG, half: 0 },
+ { slot: 2, code: 0x78, bold: true, italic: false, x: 30, y: 2, fg: FG, bg: BG, half: 0 },
+ { slot: 3, code: 0x78, bold: false, italic: false, x: 44, y: 2, fg: FG + 1, bg: BG, half: 0 },
+ { slot: 4, code: 0x78, bold: false, italic: false, x: 58, y: 2, fg: FG, bg: BG, half: 1 }
])
})
diff --git a/src/renderer/glyphgrid/atlas.ts b/src/renderer/glyphgrid/atlas.ts
index 9fb7cd683..98e4e6128 100644
--- a/src/renderer/glyphgrid/atlas.ts
+++ b/src/renderer/glyphgrid/atlas.ts
@@ -18,7 +18,10 @@ export interface GlyphRasterizer {
cellH: number
/** Paint one slot. `x, y` is the INK origin in page pixels (already one gutter inside the pitch
* cell — see GUTTER_PX); `fg`/`bg` are packColor lanes, the FINAL per-cell colours with
- * selection/cursor already applied by the caller. */
+ * selection/cursor already applied by the caller.
+ *
+ * `half` selects WHICH cell-wide window of a DOUBLE-WIDTH character this slot holds: 0 the left
+ * (every ordinary glyph, and a wide glyph's lead), 1 the right. See `glyphFor`. */
draw(
code: number,
bold: boolean,
@@ -26,7 +29,8 @@ export interface GlyphRasterizer {
x: number,
y: number,
fg: number,
- bg: number
+ bg: number,
+ half?: 0 | 1
): void
/** Blank the whole page. Called by `GlyphAtlas.reset()` and by nothing else: the bookkeeping and
* the pixels have to be emptied in the same breath or a stale slot keeps its old ink. */
@@ -119,6 +123,9 @@ export interface GlyphSlotAllocation {
/** The packed colour lanes the slot was rasterized in — part of its key. */
fg: number
bg: number
+ /** Which half of a double-width character this slot holds (see `GlyphRasterizer.draw`). 0 for
+ * every ordinary glyph, so a dump that never shows a 1 means nothing wide was drawn. */
+ half: 0 | 1
}
/** What `onReset` hands back. A plain disposable rather than an unsubscribe function so the call
@@ -303,13 +310,47 @@ export class GlyphAtlas {
}
}
- glyphFor(code: number, bold: boolean, italic: boolean, fg: number, bg: number): number {
+ /**
+ * The slot holding this glyph in this style and these colours, allocating and rasterizing it on
+ * first sight.
+ *
+ * `half` is what makes a DOUBLE-WIDTH character (an emoji, a CJK ideograph) whole. Such a
+ * character occupies two terminal cells, but a slot's ink box is exactly ONE cell and raster.ts
+ * CUTS whatever overflows it — so before this parameter existed the lead cell showed the left
+ * portion of the glyph and the follower showed nothing at all. The 2026-08-05 device round is
+ * that loss: ⭐ arriving as a fragment.
+ *
+ * The fix is to let the follower ask for the SAME character's other half. `half: 1` returns a
+ * SECOND slot, rasterized with the glyph shifted one cell left so the window this slot's clip
+ * keeps is the character's right half; the feed then writes that slot into the follower's lane
+ * instead of the blank it used to write. The two halves land in the two cells the terminal has
+ * already reserved for this character, so the composed result is the whole glyph.
+ *
+ * Note what this deliberately is NOT: the ink-sized-slot escalation raster.ts's header describes.
+ * That one is for glyphs whose ink exceeds the cell WITHOUT the terminal knowing (an ornate
+ * script face, real side bearings), and it reaches into the allocator, the slot-rect derivation
+ * and the shader's uv maths at once. This reaches none of them — every slot is still exactly one
+ * cell, still clipped to its own cell box, still 2*GUTTER_PX from its neighbour's ink, and the
+ * shader is untouched. It only spends a second slot on a character the BUFFER already says is
+ * two cells wide. A glyph wider than two cells is still cut, as before.
+ */
+ glyphFor(
+ code: number,
+ bold: boolean,
+ italic: boolean,
+ fg: number,
+ bg: number,
+ half: 0 | 1 = 0
+ ): number {
if (code === 0x20 || code === 0) return 0
// `>>> 0` on both lanes: `0xff << 24` is NEGATIVE in JS (packColor carries the same note), so
// one colour can arrive as -16777216 from an arithmetic path and as 4278190080 off a cell
// lane. Keying the two spellings separately would put identical pixels in two slots — wasted
// page, and resets arriving twice as fast.
- const key = `${code}|${bold ? 1 : 0}${italic ? 1 : 0}|${fg >>> 0}|${bg >>> 0}`
+ //
+ // `half` is IN the key: the two halves of one character are different pixels, and keying them
+ // together would hand the follower the lead's slot and paint the left half twice.
+ const key = `${code}|${bold ? 1 : 0}${italic ? 1 : 0}|${fg >>> 0}|${bg >>> 0}|${half}`
const hit = this.slots.get(key)
if (hit !== undefined) return hit
if (this.nextSlot >= this.capacity) {
@@ -330,14 +371,14 @@ export class GlyphAtlas {
}
const slot = this.nextSlot++
const { x, y } = this.cellXY(slot)
- this.rasterizer.draw(code, bold, italic, x, y, fg, bg)
+ this.rasterizer.draw(code, bold, italic, x, y, fg, bg, half)
this.slots.set(key, slot)
this.dirtyFlag = true
// LAST, and guarded: the tap is a debug aid, so a throwing callback must cost a log line, not
// the glyph — everything above is already committed by the time it runs.
if (this.onAllocate) {
try {
- this.onAllocate({ slot, code, bold, italic, x, y, fg, bg })
+ this.onAllocate({ slot, code, bold, italic, x, y, fg, bg, half })
} catch {
/* a debug tap never breaks a frame */
}
diff --git a/src/renderer/glyphgrid/feed.test.ts b/src/renderer/glyphgrid/feed.test.ts
index 4f0264b20..cb8431e77 100644
--- a/src/renderer/glyphgrid/feed.test.ts
+++ b/src/renderer/glyphgrid/feed.test.ts
@@ -26,15 +26,30 @@ const THEME: ThemeLanes = {
function fakeAtlas(): Pick<GlyphAtlas, 'glyphFor'> & {
calls: Array<[number, boolean, boolean]>
colors: Array<[number, number]>
+ halves: number[]
} {
const calls: Array<[number, boolean, boolean]> = []
const colors: Array<[number, number]> = []
+ // A THIRD parallel record, for the same reason as `colors`: which HALF of a double-width
+ // character a cell asks for is part of the key, and it is the difference between an emoji
+ // rendering whole and rendering as its left fragment. Kept out of `calls` so the many
+ // assertions that pin `calls` verbatim stay about what they were written for.
+ const halves: number[] = []
return {
calls,
colors,
- glyphFor(code: number, bold: boolean, italic: boolean, fg: number, bg: number): number {
+ halves,
+ glyphFor(
+ code: number,
+ bold: boolean,
+ italic: boolean,
+ fg: number,
+ bg: number,
+ half: 0 | 1 = 0
+ ): number {
calls.push([code, bold, italic])
colors.push([fg, bg])
+ halves.push(half)
return 900 + calls.length
}
}
@@ -203,7 +218,7 @@ describe('packViewportRow — attributes', () => {
})
describe('packViewportRow — wide and zero-width cells', () => {
- it('a wide char paints its glyph in the lead cell and a blank, bg-continuous continuation', () => {
+ it('a wide char paints its two halves into its two cells, on one unbroken background', () => {
const wide = makeCell({ code: 0x4e2d, width: 2, bg: ['rgb', 0x223344] })
const cont = makeCell({ code: 0, width: 0, bg: ['rgb', 0x223344] })
const { out, atlas } = pack([wide, cont])
@@ -211,10 +226,30 @@ describe('packViewportRow — wide and zero-width cells', () => {
const tail = readCell(out, 1)
expect(lead.glyph).toBe(901)
expect(lead.flags & FLAG_WIDE).toBe(FLAG_WIDE)
- expect(tail.glyph).toBe(0) // blank slot — the lead's ink covers both columns
+ // A slot's ink box is ONE cell and the overflow is cut, so a blank follower here threw the
+ // character's right half away — the 2026-08-05 ⭐ report. It asks for that half instead, from
+ // its OWN slot: same character and style, `half: 1`.
+ expect(tail.glyph).toBe(902)
+ expect(tail.glyph).not.toBe(lead.glyph)
expect(tail.bg).toBe(lead.bg) // unbroken background run under the glyph
expect(tail.fg).toBe(lead.fg)
- expect(atlas.calls).toEqual([[0x4e2d, false, false]]) // the continuation asks for no glyph
+ expect(atlas.calls).toEqual([
+ [0x4e2d, false, false],
+ [0x4e2d, false, false]
+ ])
+ expect(atlas.halves).toEqual([0, 1])
+ })
+
+ it('the follower inherits the LEAD’s style, not its own empty cell’s', () => {
+ // The two halves come off the same face or they meet at a step. The follower cell carries no
+ // attributes of its own, so reading them off it would draw a bold emoji's right half regular.
+ const lead = makeCell({ code: 0x4e2d, width: 2, bold: true, italic: true })
+ const cont = makeCell({ code: 0, width: 0 })
+ const { atlas } = pack([lead, cont])
+ expect(atlas.calls).toEqual([
+ [0x4e2d, true, true],
+ [0x4e2d, true, true]
+ ])
})
it('a zero-width cell with no wide lead before it still writes a blank cell (never stale)', () => {
@@ -369,8 +404,9 @@ describe('packViewportRow — cursor and selection', () => {
expect(c.fg).toBe(THEME.cursorFg)
expect(c.flags & FLAG_CURSOR).toBe(FLAG_CURSOR)
}
- // The follower still owns no glyph — the lead's ink covers both columns (Phase 1c contract).
- expect(readCell(out, 1).glyph).toBe(0)
+ // …and the inversion reaches the right half's INK, not just its background: the follower's
+ // slot is keyed on the colours it ends up with, so it is rasterized in the cursor pair too.
+ expect(readCell(out, 1).glyph).not.toBe(0)
})
it('carries the cursor no further than the follower of the covered lead', () => {
@@ -628,16 +664,19 @@ describe('packViewportRow — the colours the atlas is asked for', () => {
])
})
- it('a wide lead under the cursor asks for the cursor pair, and its follower asks for nothing', () => {
+ it('BOTH halves of a wide glyph under the cursor ask for the cursor pair', () => {
const wide = makeCell({ code: 0x4e2d, width: 2, bg: ['rgb', 0x223344] })
const cont = makeCell({ code: 0, width: 0, bg: ['rgb', 0x223344] })
const { out, atlas } = pack([wide, cont], { cursorCol: 0 })
- expect(atlas.colors).toEqual([[THEME.cursorFg, THEME.cursorBg]])
- // The follower asks for no slot of its own — it never has — but it now PAINTS in the cursor
- // pair rather than in the lead's own colours: the block covers the whole character, which is
- // what closes L13. Its glyph lane stays 0, so the shader paints exactly this bg lane.
+ // The block covers the whole character (L13), and now that the follower owns a real slot the
+ // override has to reach the request as well as the lane — a right half rasterized in the
+ // cell's ORIGINAL colours would sit un-inverted inside an inverted block.
+ expect(atlas.colors).toEqual([
+ [THEME.cursorFg, THEME.cursorBg],
+ [THEME.cursorFg, THEME.cursorBg]
+ ])
+ expect(atlas.halves).toEqual([0, 1])
expect(readCell(out, 1).bg).toBe(THEME.cursorBg)
- expect(readCell(out, 1).glyph).toBe(0)
})
})
diff --git a/src/renderer/glyphgrid/feed.ts b/src/renderer/glyphgrid/feed.ts
index fcf022a53..3a1149024 100644
--- a/src/renderer/glyphgrid/feed.ts
+++ b/src/renderer/glyphgrid/feed.ts
@@ -98,10 +98,11 @@ export interface BlankCellReport {
/** Debug-only tap, off unless something installs it.
*
- * This exists because a blank cell has THREE possible authors — a wide glyph's follower, a column
- * past the end of the line, and a code the crash guard refuses — and a screenshot cannot tell them
- * apart. It fires only when the cell HAS content and we still drew nothing, which is the exact
- * shape of the 2026-08-05 "a letter goes missing mid-word" report.
+ * This exists because a blank cell has several possible authors — a column past the end of the
+ * line, a code the crash guard refuses, a stray width-0 cell with no lead to be the second half of
+ * — and a screenshot cannot tell them apart. It fires only when the cell HAS content and we still
+ * drew nothing, which is the exact shape of the 2026-08-05 "a letter goes missing mid-word"
+ * report.
*
* Its SILENCE is a result too: if a cell renders blank on screen and this never fires, the feed
* asked for the right glyph and the loss happened downstream (lane upload or draw), which is a
@@ -222,18 +223,28 @@ function resolveBg(cell: CellView, theme: ThemeLanes): number {
*
* WIDE / ZERO-WIDTH cells are one mechanism seen from two sides. A double-width glyph occupies
* two buffer cells: the lead reports width 2, and the cell right after it reports width 0. The
- * lead carries the glyph (plus FLAG_WIDE); the follower is written as a BLANK cell carrying the
- * LEAD's colors, so the background under a wide glyph — a selection, the cursor, a colored
- * block — is one unbroken run instead of two halves that can disagree. The follower is never
- * skipped: this row buffer is REUSED across frames, so "write nothing" would leave the previous
- * frame's lanes standing at that column. Every column in [0, cols) is always written.
+ * lead carries the glyph's LEFT half (plus FLAG_WIDE) and the follower its RIGHT half — the same
+ * character, same style, same colors, asked of the atlas as `half: 1` (see `GlyphAtlas.glyphFor`).
+ * Carrying the LEAD's colors into the follower is what keeps the background under a wide glyph —
+ * a selection, the cursor, a colored block — one unbroken run instead of two halves that can
+ * disagree. The follower is never skipped: this row buffer is REUSED across frames, so "write
+ * nothing" would leave the previous frame's lanes standing at that column. Every column in
+ * [0, cols) is always written.
+ *
+ * THE FOLLOWER USED TO BE BLANK, and that was a real loss, not a simplification: a slot's ink box
+ * is one cell and raster.ts cuts the overflow, so a character the terminal had already reserved
+ * two cells for was rendered as its first cell only. The 2026-08-05 device round is that defect —
+ * ⭐ arriving as a fragment. A stray width-0 cell with NO lead still writes a blank, because there
+ * is no character for it to be the second half of.
*
* THE BLOCK CURSOR REACHES THE FOLLOWER, and that is the fix for limitation L13. The cursor is one
* COLUMN and a wide glyph is two, so applying the override to the cursor's column alone painted the
* left half of 日 and left the right half un-inverted. A cursor sitting on a wide LEAD therefore
* carries into its follower (and nowhere else — not past it, and not into a stray zero-width cell
- * that follows a narrow one). The follower's glyph lane stays 0, per the Phase 1c contract, so the
- * shader paints its bg lane — which is now the cursor colour.
+ * that follows a narrow one). The follower's slot is keyed on the colours it ends up with, so the
+ * cursor colours reach the right half's PIXELS too — the whole character inverts, ink included.
+ * (When the follower's lane was blank this only reached its background; the right half showed no
+ * ink at all, because there was none anywhere.)
*
* DECORATIONS (a search hit's highlight is one) sit between the cell's own colours and the
* selection: they OVERRIDE base/inverse/dim — a hit on coloured output has to be visible — and
@@ -287,6 +298,12 @@ export function packViewportRow(
let carryPending = false
let carryFg = 0
let carryBg = 0
+ /** The lead's CHARACTER, carried so the follower can ask the atlas for its right half. Styling
+ * rides along because the half is rasterized from the same face as the lead — a bold emoji's two
+ * halves must come off the same glyph or they meet at a step. */
+ let carryCode = 0
+ let carryBold = false
+ let carryItalic = false
/** Was the wide lead we are carrying from the one the BLOCK cursor covers? Separate from the
* colour carry because the colours are captured PRE-override and the cursor is applied post — the
* follower has to re-apply it, not inherit an already-overridden pair. */
@@ -301,11 +318,13 @@ export function packViewportRow(
let bg = theme.bg
let flags = 0
// What this cell will ask the atlas for, decided here and REQUESTED after the overrides below.
- // 0 is "nothing to draw" — it fails `isRenderableCode`, which is the same answer a blank cell,
- // a control code and a wide glyph's follower all give.
+ // 0 is "nothing to draw" — it fails `isRenderableCode`, which is the answer a blank cell and a
+ // control code give. A wide glyph's follower does NOT: it adopts the lead's character below.
let code = 0
let bold = false
let italic = false
+ /** Which cell-wide window of `code` this cell draws — 1 only on a wide glyph's follower. */
+ let half: 0 | 1 = 0
// Debug-only witnesses, read at the bottom of the loop. -1 distinguishes "no cell" from a cell
// that reported width 0; `getChars()` is only called when the probe is installed, because it
// allocates a string per cell and this loop runs for every cell of every packed row.
@@ -328,15 +347,22 @@ export function packViewportRow(
probeChars = cell.getChars()
}
if (width === 0) {
- // Second half of the preceding wide glyph: no glyph of its own, and the lead's colors
- // when we have them (a stray width-0 cell with no lead keeps its own — still never
- // stale). Glyph-styling flags mean nothing on a blank; underline continuity across a
- // wide glyph is Phase 2, since nothing renders underline yet.
+ // Second half of the preceding wide glyph: it draws the LEAD's character, right half, in
+ // the lead's colors (a stray width-0 cell with no lead has neither — it stays blank on its
+ // own colors, which is still never stale). Underline continuity across a wide glyph is
+ // Phase 2, since nothing renders underline yet.
if (carryPending) {
fg = carryFg
bg = carryBg
// The other half of the character the cursor is on — see the doc comment's L13 note.
if (carryCursor) cursorHere = true
+ // The lane that used to be 0 here. A double-width character's ink is cut at one cell
+ // (raster.ts), so leaving this blank threw its right half away — the 2026-08-05 ⭐
+ // report. The two cells the terminal reserved for this character now hold its two halves.
+ code = carryCode
+ bold = carryBold
+ italic = carryItalic
+ half = 1
}
carryPending = false
carryCursor = false
@@ -359,6 +385,9 @@ export function packViewportRow(
carryFg = fg
carryBg = bg
carryCursor = cursorHere
+ carryCode = code
+ carryBold = bold
+ carryItalic = italic
} else {
carryPending = false
carryCursor = false
@@ -390,7 +419,7 @@ export function packViewportRow(
}
// fg/bg are FINAL here — this is the only place the atlas may be asked, see the doc comment.
- const glyph = isRenderableCode(code) ? atlas.glyphFor(code, bold, italic, fg, bg) : 0
+ const glyph = isRenderableCode(code) ? atlas.glyphFor(code, bold, italic, fg, bg, half) : 0
// A cell that HOLDS something and still draws nothing is the defect under investigation. A
// space is excluded because that is the correct answer for it, not a loss.
if (blankProbe && glyph === 0 && probeChars !== '' && probeChars !== ' ') {
diff --git a/src/renderer/glyphgrid/raster.test.ts b/src/renderer/glyphgrid/raster.test.ts
index cfeb1c7bb..5d2655ef8 100644
--- a/src/renderer/glyphgrid/raster.test.ts
+++ b/src/renderer/glyphgrid/raster.test.ts
@@ -252,6 +252,64 @@ describe('createCanvasRasterizer', () => {
expect(Number.isInteger(ink.args[1])).toBe(true)
})
+ describe('the right half of a double-width character (`half: 1`)', () => {
+ // A slot's ink box is one cell and step 2 CUTS the overflow, so a character the terminal gave
+ // two cells to was rendered as its first cell alone — the 2026-08-05 ⭐ report. The follower
+ // cell asks for the same character's other half, which is the same draw with the glyph's
+ // origin moved one cell left: the window this slot's clip keeps is then the second cell.
+ it('draws the glyph one cell LEFT of the ink origin', () => {
+ const stub = stubCanvas()
+ active = stub
+ const r = createCanvasRasterizer(FONT, 256)!
+ stub.ops.length = 0
+ r.draw(0x4e2d, false, false, INK_X, INK_Y, FG, BG, 1)
+ const ink = stub.ops.find((o) => o.kind === 'fillText')!
+ expect(ink.args[0]).toBe(INK_X - FONT.cellW)
+ // The baseline does not move: only the horizontal window changes.
+ expect(ink.args[1]).toBe(INK_Y + 16)
+ })
+
+ it('leaves the CLIP on this slot’s own cell box', () => {
+ // This is the whole reason the fix costs nothing structurally. The clip is what holds the
+ // 2*GUTTER_PX separation MAX_SAFE_LOD is derived from; if it moved with the ink, the right
+ // half would spill into the neighbouring slot and show up as a ghost in its mip.
+ const stub = stubCanvas()
+ active = stub
+ const r = createCanvasRasterizer(FONT, 256)!
+ stub.ops.length = 0
+ r.draw(0x4e2d, false, false, INK_X, INK_Y, FG, BG, 1)
+ expect(stub.ops.find((o) => o.kind === 'clip')).toEqual({
+ kind: 'clip',
+ args: [INK_X, INK_Y, FONT.cellW, FONT.cellH]
+ })
+ })
+
+ it('fills this slot’s own pitch rect with bg, exactly as the left half does', () => {
+ // The follower's background is what makes a selection or a block cursor one unbroken run
+ // across a wide glyph. The shift must not reach it.
+ const stub = stubCanvas()
+ active = stub
+ const r = createCanvasRasterizer(FONT, 256)!
+ stub.ops.length = 0
+ r.draw(0x4e2d, false, false, INK_X, INK_Y, FG, BG, 1)
+ expect(stub.ops[0]).toEqual({
+ kind: 'fillRect',
+ fill: BG_CSS,
+ args: [INK_X - GUTTER_PX, INK_Y - GUTTER_PX, PITCH_W, PITCH_H]
+ })
+ })
+
+ it('defaults to the left half, so every existing call is unchanged', () => {
+ const withDefault = stubCanvas()
+ active = withDefault
+ createCanvasRasterizer(FONT, 256)!.draw(0x41, false, false, INK_X, INK_Y, FG, BG)
+ const explicit = stubCanvas()
+ active = explicit
+ createCanvasRasterizer(FONT, 256)!.draw(0x41, false, false, INK_X, INK_Y, FG, BG, 0)
+ expect(withDefault.ops).toEqual(explicit.ops)
+ })
+ })
+
// The claim is about GEOMETRY, not about pixels: no glyph may generate NEW ink outside the slot's
// own WHOLE-TEXEL CELL BOX, because the MAX_SAFE_LOD derivation counts on 2*GUTTER_PX texels
// between two slots' inks. The gutter is not required to be BACKGROUND — the edge-extension
diff --git a/src/renderer/glyphgrid/raster.ts b/src/renderer/glyphgrid/raster.ts
index 73acb7deb..f4f0cfd66 100644
--- a/src/renderer/glyphgrid/raster.ts
+++ b/src/renderer/glyphgrid/raster.ts
@@ -204,13 +204,21 @@ function baselineIn(ctx: OffscreenCanvasRenderingContext2D, font: RasterFont): n
* 2026-08-04 device round measured one: U+23BF ⎿, Claude Code's tool-result connector, kept
* about a third of its horizontal foot (8 px against GPU mode's 28).
*
+ * ONE MEMBER OF THE CLASS IS NOW OUT OF IT: a DOUBLE-WIDTH character (emoji, CJK). Its overflow
+ * was never really overflow — the terminal has already reserved a second cell for it — so it
+ * needs no ink-sized slot, only a second cell-sized one holding the character's right half
+ * (`half` above, and `GlyphAtlas.glyphFor`). Before that, ⭐ rendered as a fragment: the
+ * 2026-08-05 device round. Everything this clip defends is untouched by it, because each half
+ * is still clipped to its own cell box.
+ *
* THE ESCAPE HATCH USED SO FAR is `box-glyphs.ts`: a glyph we DRAW is full-cell by construction,
* so the clip has nothing to cut. That covers line art — the box-drawing and block ranges, plus
* the handful of Misc-Technical aliases the ⎿ finding added — and it is the right answer for
* that class, since those characters are DEFINED as fractions of the cell.
*
- * THE REAL ESCALATION, if a NON-line-art glyph ever needs the overflow (an ornate script face, a
- * symbol font with genuine side bearings), is to do what xterm does: measure a per-glyph
+ * THE REAL ESCALATION, if a NON-line-art, SINGLE-WIDTH glyph ever needs the overflow (an ornate
+ * script face, a symbol font with genuine side bearings), is to do what xterm does: measure a
+ * per-glyph
* bounding box, allocate slots sized to the INK rather than to the cell, and emit quads sized to
* the glyph rather than to the cell. That reaches into the atlas allocator, the slot-rect
* derivation and the shader's uv maths all at once, and it changes what the LOD/gutter argument
@@ -280,7 +288,20 @@ export function createCanvasRasterizer(
/** `x, y` is the INK origin the atlas hands us — already one gutter inside the pitch cell on
* each axis (`GlyphAtlas.cellXY`) — and `fg`/`bg` are the FINAL packed colour lanes for this
* slot. Two DIFFERENT rects are involved; see the header's invariants 3 and 4. */
- draw(code, bold, italic, x, y, fg, bg) {
+ draw(code, bold, italic, x, y, fg, bg, half = 0) {
+ // The glyph's own origin inside this slot. `half: 1` is the RIGHT half of a double-width
+ // character (see `GlyphAtlas.glyphFor`): the character is drawn one cell FURTHER LEFT, so the
+ // window this slot's clip keeps is its second cell instead of its first. Everything else
+ // below is untouched — same clip, same pitch fill, same edge extension — because the fix is
+ // about WHICH part of the glyph a cell-sized slot holds, not about the slot's size.
+ //
+ // The shift is the FRACTIONAL cell, not a whole texel, so the two halves meet exactly where
+ // the two on-screen cells meet (cells are laid out on the fractional cell pitch too). The
+ // cost is that the right half is rasterized at a different sub-texel PHASE than the left —
+ // its antialiasing can differ by a fraction of a pixel along the seam. That is the honest
+ // trade: a phase difference is a hairline, a whole-texel shift would be a visible break in
+ // the character.
+ const inkX = half === 1 ? x - font.cellW : x
// 1. THE BACKGROUND, over the whole PITCH rect — gutters included. The atlas passes the INK
// origin, so the pitch cell's corner is one gutter back on each axis; its extent is the
// pitch, which is `ceil(cell) + 2*GUTTER_PX`. Both are whole texels and consecutive pitch
@@ -368,11 +389,15 @@ export function createCanvasRasterizer(
// and there is no partial texel to complete.
const w = op.x + op.w >= font.cellW - FAR_EDGE_EPS ? colsW - op.x : op.w
const h = op.y + op.h >= font.cellH - FAR_EDGE_EPS ? colsH - op.y : op.h
- ctx.fillRect(x + op.x, y + op.y, w, h)
+ // `inkX`, not `x`: a geometric glyph is defined as a fraction of ONE cell, so on `half: 1`
+ // every op lands entirely left of the clip and the slot comes out blank — which is the
+ // right answer, since a cell-defined glyph has no second cell. (No wide character is
+ // claimed by box-glyphs.ts today, so this is a floor rather than a live path.)
+ ctx.fillRect(inkX + op.x, y + op.y, w, h)
}
} else {
ctx.font = `${italic ? 'italic ' : ''}${bold ? 'bold ' : ''}${font.sizePx}px ${font.family}`
- ctx.fillText(String.fromCodePoint(code), x, y + baseline)
+ ctx.fillText(String.fromCodePoint(code), inkX, y + baseline)
}
ctx.restore()
// 3. THE EDGE EXTENSION — clamp-to-edge padding, the standard atlas technique. Replicate the