AI-native design editor. Open-source Figma alternative.
fix(clipboard): match shaped glyphs by character index, not array position
Danila Poyarkovea323c33f02d
diff --git a/packages/core/src/text/derived-text/clipboard.ts b/packages/core/src/text/derived-text/clipboard.tsindex 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<number, (typeof shaped extends null | undefined ? never : NonNullable<typeof shaped>)['glyphs'][number]>()+ if (shaped) {+ for (const g of shaped.glyphs) shapedByChar.set(g.firstCharacter, g)+ }+const fallbackBaselines: NonNullable<NodeChange['derivedTextData']>['baselines'] = []const fallbackOffsets = Array.from({ length: node.text.length + 1 }, () => 0)let fallbackX = 0@@ -110,7 +115,7 @@ export async function buildDerivedTextDataV4(let lineStart = 0const glyphs = glyphMetrics.map((glyph, index) => {- const shapedGlyph = shaped?.glyphs[index]+ const shapedGlyph = shapedByChar.get(index)const fallbackGlyphAdvance = glyph.advance || fallbackAdvanceif (!shapedGlyph && lineBreakSet.has(index)) {fallbackBaselines.push({