Skip to content

AI-native design editor. Open-source Figma alternative.

Fix text not rendering + undo for Figma clipboard paste

Danila Poyarkov8850625a6fa1
diff --git a/packages/core/src/clipboard.ts b/packages/core/src/clipboard.ts
index 0b74ed951..368601f84 100644
--- a/packages/core/src/clipboard.ts
+++ b/packages/core/src/clipboard.ts
@@ -265,11 +265,14 @@ export function importClipboardNodes(
? ('STRETCH' as const)
: ('AUTO' as const),
clipsContent: nc.frameMaskDisabled === false,
- textAutoResize: mapTextAutoResize(nc.textAutoResize as string),
+ textAutoResize: 'NONE' as const,
fontWeight: nc.fontWeight ?? styleToWeight(nc.fontName?.style ?? ''),
italic: nc.fontName?.style?.toLowerCase().includes('italic') ?? false,
lineHeight: mapLineHeight(nc.lineHeight as { value: number; units: string } | undefined),
- letterSpacing: nc.letterSpacing ?? 0,
+ letterSpacing: mapLetterSpacing(
+ nc.letterSpacing as { value: number; units: string } | undefined,
+ nc.fontSize as number | undefined
+ ),
vectorNetwork: decodeVectorData(nc, blobs)
})
@@ -326,11 +329,14 @@ function mapCounterAlign(align?: string): LayoutCounterAlign {
return 'MIN'
}
-function mapTextAutoResize(resize?: string): 'NONE' | 'HEIGHT' | 'WIDTH_AND_HEIGHT' | 'TRUNCATE' {
- if (resize === 'HEIGHT') return 'HEIGHT'
- if (resize === 'WIDTH_AND_HEIGHT') return 'WIDTH_AND_HEIGHT'
- if (resize === 'TRUNCATE') return 'TRUNCATE'
- return 'NONE'
+function mapLetterSpacing(
+ ls?: { value: number; units: string },
+ fontSize?: number
+): number {
+ if (!ls) return 0
+ if (ls.units === 'PIXELS') return ls.value
+ if (ls.units === 'PERCENT') return (ls.value / 100) * (fontSize ?? 14)
+ return 0
}
function mapLineHeight(lh?: { value: number; units: string }): number | undefined {
diff --git a/packages/core/src/kiwi/codec.ts b/packages/core/src/kiwi/codec.ts
index 63b2188b9..631efe65d 100644
--- a/packages/core/src/kiwi/codec.ts
+++ b/packages/core/src/kiwi/codec.ts
@@ -247,6 +247,7 @@ export interface NodeChange {
stackWrap?: string
stackPositioning?: string
stackChildPrimaryGrow?: number
+ stackChildAlignSelf?: string
stackCounterSpacing?: number
// Frame
clipsContent?: boolean
@@ -255,6 +256,7 @@ export interface NodeChange {
vectorData?: unknown
// Text
fontSize?: number
+ fontWeight?: number
fontName?: { family: string; style: string; postscript?: string }
textAlignHorizontal?: string
textAlignVertical?: string
diff --git a/src/stores/editor.ts b/src/stores/editor.ts
index 484ff7050..b6bf6ef78 100644
--- a/src/stores/editor.ts
+++ b/src/stores/editor.ts
@@ -1573,6 +1573,18 @@ export function createEditorStore() {
clipboardData.setData('text/plain', names)
}
+ function collectSubtrees(g: SceneGraph, rootIds: string[]): SceneNode[] {
+ const result: SceneNode[] = []
+ function walk(id: string) {
+ const node = g.getNode(id)
+ if (!node) return
+ result.push({ ...node })
+ for (const childId of node.childIds) walk(childId)
+ }
+ for (const id of rootIds) walk(id)
+ return result
+ }
+
function pasteFromHTML(html: string) {
const ownNodes = parseOpenPencilClipboard(html)
if (ownNodes) {
@@ -1588,6 +1600,7 @@ export function createEditorStore() {
const offsetX = bounds ? viewCenterX - (bounds.x + bounds.w / 2) : 0
const offsetY = bounds ? viewCenterY - (bounds.y + bounds.h / 2) : 0
+ const prevSelection = new Set(state.selectedIds)
const created = importClipboardNodes(
figma.nodes,
graph,
@@ -1599,6 +1612,26 @@ export function createEditorStore() {
if (created.length > 0) {
computeAllLayouts(graph)
state.selectedIds = new Set(created)
+
+ const allNodes = collectSubtrees(graph, created)
+ const pageId = state.currentPageId
+ undo.push({
+ label: 'Paste',
+ forward: () => {
+ for (const snapshot of allNodes) {
+ graph.createNode(snapshot.type, snapshot.parentId ?? pageId, snapshot)
+ }
+ computeAllLayouts(graph)
+ state.selectedIds = new Set(created)
+ requestRender()
+ },
+ inverse: () => {
+ for (const id of [...created].reverse()) graph.deleteNode(id)
+ computeAllLayouts(graph)
+ state.selectedIds = prevSelection
+ requestRender()
+ }
+ })
requestRender()
}
}