AI-native design editor. Open-source Figma alternative.
fix(vue): edit text inside components on double click
Danila Poyarkov2b24669949ed
diff --git a/packages/vue/src/Canvas/useCanvasInput.ts b/packages/vue/src/Canvas/useCanvasInput.tsindex 8ecc7e18b..e5f61553c 100644--- a/packages/vue/src/Canvas/useCanvasInput.ts+++ b/packages/vue/src/Canvas/useCanvasInput.ts@@ -737,6 +737,24 @@ export function useCanvasInput(cursorOverride.value = null}+ function startTextEditingAt(hit: SceneNode, cx: number, cy: number) {+ editor.select([hit.id])+ editor.startTextEditing(hit.id)+ const textEd = editor.textEditor+ if (textEd) {+ const abs = editor.graph.getAbsolutePosition(hit.id)+ textEd.selectWordAt(cx - abs.x, cy - abs.y)+ editor.requestRender()+ }+ }++ function getContainerDescendantHit(containerId: string, cx: number, cy: number): SceneNode | null {+ const hit = editor.graph.hitTestDeep(cx, cy, editor.state.currentPageId)+ if (!hit) return null+ if (hit.id === containerId || editor.graph.isDescendant(hit.id, containerId)) return hit+ return null+ }+function onDblClick(e: MouseEvent) {const nodeEditEditor = editor as Editor & NodeEditMethodsif (editor.state.editingTextId) return@@ -750,10 +768,14 @@ export function useCanvasInput(selectedNode && selectedId && editor.graph.isContainer(selectedId) && !selectedNode.lockedif (canEnter) {- editor.enterContainer(selectedId)const useDeep = selectedNode.type === 'COMPONENT' || selectedNode.type === 'INSTANCE'- const hit = hitTestInScope(cx, cy, useDeep)- if (hit) {+ const hit = useDeep+ ? getContainerDescendantHit(selectedId, cx, cy)+ : hitTestInScope(cx, cy, false)+ editor.enterContainer(selectedId)+ if (hit?.type === 'TEXT') {+ startTextEditingAt(hit, cx, cy)+ } else if (hit) {editor.select([hit.id])} else {editor.clearSelection()@@ -766,14 +788,7 @@ export function useCanvasInput(if (!hit) returnif (hit.type === 'TEXT') {- editor.select([hit.id])- editor.startTextEditing(hit.id)- const textEd = editor.textEditor- if (textEd) {- const abs = editor.graph.getAbsolutePosition(hit.id)- textEd.selectWordAt(cx - abs.x, cy - abs.y)- editor.requestRender()- }+ startTextEditingAt(hit, cx, cy)return}