From ea323c33f02dd69dce17122b2f25493481ec0741 Mon Sep 17 00:00:00 2001 From: Danila Poyarkov Date: Sat, 16 May 2026 18:38:58 +0300 Subject: [PATCH] fix(clipboard): match shaped glyphs by character index, not array position --- packages/core/src/text/derived-text/clipboard.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/core/src/text/derived-text/clipboard.ts b/packages/core/src/text/derived-text/clipboard.ts index 9232ae2db..649867ce3 100644 --- a/packages/core/src/text/derived-text/clipboard.ts +++ b/packages/core/src/text/derived-text/clipboard.ts @@ -103,6 +103,11 @@ export async function buildDerivedTextDataV4( : computeWordWrapBreaks(node.text, glyphMetrics, fallbackAdvance, node.width, node.fontSize, node.fontFamily) const lineBreakSet = new Set(lineBreaks) + const shapedByChar = new Map)['glyphs'][number]>() + if (shaped) { + for (const g of shaped.glyphs) shapedByChar.set(g.firstCharacter, g) + } + const fallbackBaselines: NonNullable['baselines'] = [] const fallbackOffsets = Array.from({ length: node.text.length + 1 }, () => 0) let fallbackX = 0 @@ -110,7 +115,7 @@ export async function buildDerivedTextDataV4( let lineStart = 0 const glyphs = glyphMetrics.map((glyph, index) => { - const shapedGlyph = shaped?.glyphs[index] + const shapedGlyph = shapedByChar.get(index) const fallbackGlyphAdvance = glyph.advance || fallbackAdvance if (!shapedGlyph && lineBreakSet.has(index)) { fallbackBaselines.push({