Skip to content

Commit 8a935df

Browse files
committed
divider: use first Unicode codepoint for char
Fixes surrogate-pair glyph handling (avoid raw UTF-16 code unit slicing)
1 parent 1e93e80 commit 8a935df

File tree

3 files changed

+25
-10
lines changed

3 files changed

+25
-10
lines changed

packages/core/src/renderer/__tests__/render.golden.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,19 @@ describe("renderer - widget tree to deterministic ZRDL bytes", () => {
307307
assertBytesEqual(actual, expected, "divider_with_label.bin");
308308
});
309309

310+
test("divider preserves surrogate-pair glyph char", () => {
311+
// U+1D306 TETRAGRAM FOR CENTRE (surrogate pair in UTF-16)
312+
const glyph = "𝌆";
313+
const vnode: VNode = { kind: "divider", props: { char: glyph } };
314+
const actual = renderBytes(vnode, Object.freeze({ focusedId: null }));
315+
const strings = parseInternedStrings(actual);
316+
assert.equal(
317+
strings.includes(glyph.repeat(80)),
318+
true,
319+
"expected glyph line in interned strings",
320+
);
321+
});
322+
310323
test("modal_backdrop_dim.bin", async () => {
311324
const expected = await load("modal_backdrop_dim.bin");
312325
const modal: VNode = {

packages/core/src/renderer/renderToDrawlist/simpleVNode.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -728,11 +728,12 @@ export function renderVNodeSimple(
728728
const direction = props.direction === "vertical" ? "vertical" : "horizontal";
729729
const rawChar =
730730
typeof props.char === "string" && props.char.length > 0 ? props.char : undefined;
731-
const glyph = rawChar
732-
? (rawChar[0] ?? (direction === "horizontal" ? "─" : "│"))
733-
: direction === "horizontal"
734-
? "─"
735-
: "│";
731+
const glyph = (() => {
732+
const fallback = direction === "horizontal" ? "─" : "│";
733+
if (!rawChar) return fallback;
734+
const cp = rawChar.codePointAt(0);
735+
return cp === undefined ? fallback : String.fromCodePoint(cp);
736+
})();
736737
const label = typeof props.label === "string" ? props.label : undefined;
737738
const color = typeof props.color === "string" ? props.color : undefined;
738739
const style = color

packages/core/src/renderer/renderToDrawlist/widgets/basic.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,12 @@ export function renderBasicWidget(
442442
const direction = props.direction === "vertical" ? "vertical" : "horizontal";
443443
const rawChar =
444444
typeof props.char === "string" && props.char.length > 0 ? props.char : undefined;
445-
const glyph = rawChar
446-
? (rawChar[0] ?? (direction === "horizontal" ? "─" : "│"))
447-
: direction === "horizontal"
448-
? "─"
449-
: "│";
445+
const glyph = (() => {
446+
const fallback = direction === "horizontal" ? "─" : "│";
447+
if (!rawChar) return fallback;
448+
const cp = rawChar.codePointAt(0);
449+
return cp === undefined ? fallback : String.fromCodePoint(cp);
450+
})();
450451
const label = typeof props.label === "string" ? props.label : undefined;
451452
const color = typeof props.color === "string" ? props.color : undefined;
452453
const style = color

0 commit comments

Comments
 (0)