Skip to content

Commit 44b8356

Browse files
Merge pull request #27 from RtlZeroMemory/feat/divider-codepoint
Divider: support surrogate-pair glyphs in char
2 parents b818419 + 8a935df commit 44b8356

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
@@ -314,6 +314,19 @@ describe("renderer - widget tree to deterministic ZRDL bytes", () => {
314314
assertBytesEqual(actual, expected, "divider_with_label.bin");
315315
});
316316

317+
test("divider preserves surrogate-pair glyph char", () => {
318+
// U+1D306 TETRAGRAM FOR CENTRE (surrogate pair in UTF-16)
319+
const glyph = "𝌆";
320+
const vnode: VNode = { kind: "divider", props: { char: glyph } };
321+
const actual = renderBytes(vnode, Object.freeze({ focusedId: null }));
322+
const strings = parseInternedStrings(actual);
323+
assert.equal(
324+
strings.includes(glyph.repeat(80)),
325+
true,
326+
"expected glyph line in interned strings",
327+
);
328+
});
329+
317330
test("modal_backdrop_dim.bin", async () => {
318331
const expected = await load("modal_backdrop_dim.bin");
319332
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)