Skip to content

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

fix: enter from the layers panel as a canvas click does, and draw no entered outline (#1700)

Danila Poyarkovfdef19d12c85
diff --git a/changes/1700/fixed.md b/changes/1700/fixed.md
new file mode 100644
index 000000000..6c07fb785
--- /dev/null
+++ b/changes/1700/fixed.md
@@ -0,0 +1 @@
+- Picking a layer in the layers panel leaves canvas clicks as clicking it on the canvas would, and the canvas no longer outlines the container a layer was reached through, as in Figma (#1700).
diff --git a/packages/core/src/canvas/overlays/index.ts b/packages/core/src/canvas/overlays/index.ts
index 6b4d7ea4f..744a1fd34 100644
--- a/packages/core/src/canvas/overlays/index.ts
+++ b/packages/core/src/canvas/overlays/index.ts
@@ -1,5 +1,4 @@
export {
- drawEnteredContainer,
drawGroupBounds,
drawHandle,
drawHoverHighlight,
diff --git a/packages/core/src/canvas/overlays/selection.ts b/packages/core/src/canvas/overlays/selection.ts
index 15f882491..1186e29c9 100644
--- a/packages/core/src/canvas/overlays/selection.ts
+++ b/packages/core/src/canvas/overlays/selection.ts
@@ -78,17 +78,6 @@ export function drawCodeFocus(
})
}
-export function drawEnteredContainer(
- r: SkiaRenderer,
- canvas: Canvas,
- graph: SceneGraph,
- enteredContainerId?: string | null,
- preview?: RotationPreview | null
-): void {
- const stroke = { color: r.selColor(SELECTION_DASH_ALPHA), dash: SELECTION_DASH }
- outlineNode(r, canvas, graph, enteredContainerId, stroke, preview)
-}
-
/** Single-node selection overlay: path-text curve/band for imported TEXT_PATH,
* the standard rect+handles otherwise. */
function drawSingleSelection(
diff --git a/packages/core/src/canvas/renderer/overlay-pass.ts b/packages/core/src/canvas/renderer/overlay-pass.ts
index 447704f0e..0a814e4bf 100644
--- a/packages/core/src/canvas/renderer/overlay-pass.ts
+++ b/packages/core/src/canvas/renderer/overlay-pass.ts
@@ -10,7 +10,6 @@ import { cachedGlyphWidth } from '#core/canvas/labels/paragraph-cache'
import { drawNodeEditOverlay } from '#core/canvas/node-edit-overlay'
import {
drawAutoLayoutHover,
- drawEnteredContainer,
drawFlashes,
drawHoverHighlight,
drawLayoutInsertIndicator,
@@ -142,7 +141,6 @@ export function drawOverlayPass(
if (!measuring) drawLayoutOutlines(r, canvas, graph, selectedIds, hoveredNodeId, overlays)
drawHoverHighlight(r, canvas, graph, hoveredNodeId, overlays.rotationPreview)
drawIssueHighlight(r, canvas, graph, overlays.designIssues?.highlight, overlays.rotationPreview)
- drawEnteredContainer(r, canvas, graph, overlays.enteredContainerId, overlays.rotationPreview)
drawDropTarget(r, canvas, graph, overlays.dropTargetId, overlays.rotationPreview)
drawConnectorTarget(r, canvas, graph, overlays.connectorTarget, overlays.rotationPreview)
drawEditingText(r, canvas, graph, overlays)
diff --git a/packages/core/src/canvas/renderer/pipeline.ts b/packages/core/src/canvas/renderer/pipeline.ts
index fe8b1fe9f..44b7e93c6 100644
--- a/packages/core/src/canvas/renderer/pipeline.ts
+++ b/packages/core/src/canvas/renderer/pipeline.ts
@@ -119,7 +119,6 @@ export function renderFromEditorState(
gradientEdit: state.gradientEdit,
transforming: state.transforming,
measurementMode: state.measurementMode,
- enteredContainerId: state.enteredContainerId,
editingTextId: state.editingTextId,
renamingLabelId: state.renamingLabelId,
textEditor: textEditor as RenderOverlays['textEditor'],
diff --git a/packages/core/src/canvas/renderer/types.ts b/packages/core/src/canvas/renderer/types.ts
index 99eccbbcb..5d6e6293a 100644
--- a/packages/core/src/canvas/renderer/types.ts
+++ b/packages/core/src/canvas/renderer/types.ts
@@ -51,7 +51,6 @@ export interface RenderOverlays {
gradientEdit?: GradientEdit | null
transforming?: boolean
measurementMode?: MeasurementMode
- enteredContainerId?: string | null
editingTextId?: string | null
/** The layer whose name a field over the canvas renames, whose title the canvas leaves out. */
renamingLabelId?: string | null
diff --git a/packages/vue/src/primitives/LayerTree/LayerTreeRoot.vue b/packages/vue/src/primitives/LayerTree/LayerTreeRoot.vue
index 8649a6832..e1ae98ca5 100644
--- a/packages/vue/src/primitives/LayerTree/LayerTreeRoot.vue
+++ b/packages/vue/src/primitives/LayerTree/LayerTreeRoot.vue
@@ -161,21 +161,6 @@ onScopeDispose(() => {
for (const stop of unsubscribe) stop()
})
-function syncCanvasScope(nodeId: string) {
- const node = editor.graph.getNode(nodeId)
- if (!node) return
- let parentId = node.parentId
- while (parentId && parentId !== editor.state.currentPageId) {
- if (editor.graph.isContainer(parentId)) {
- editor.enterContainer(parentId)
- return
- }
- const parent = editor.graph.getNode(parentId)
- parentId = parent?.parentId ?? null
- }
- editor.state.enteredContainerId = null
-}
-
function select(id: string, selection: boolean | LayerSelectionMode) {
const mode = typeof selection === 'boolean' ? { additive: selection, range: false } : selection
emit('select', id, mode.additive)
@@ -196,7 +181,8 @@ function select(id: string, selection: boolean | LayerSelectionMode) {
} finally {
applyingSelection = false
}
- if (!mode.additive && !mode.range) syncCanvasScope(id)
+ // A layer picked here leaves canvas clicks as a click on it there would, as in Figma.
+ if (!mode.additive && !mode.range) editor.enterContainerOf(id)
scrollToNode(id)
}
diff --git a/tests/e2e/layers/canvas-scope.spec.ts b/tests/e2e/layers/canvas-scope.spec.ts
new file mode 100644
index 000000000..899925e9f
--- /dev/null
+++ b/tests/e2e/layers/canvas-scope.spec.ts
@@ -0,0 +1,24 @@
+import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'
+import { clickDepthDriver } from '#tests/helpers/canvas/click-depth/driver'
+
+// Figma has no entered container: a layer picked in the layers panel leaves canvas clicks just as
+// selecting it on the canvas does (scratch/pr-oracle/scope-outline.ts), so the panel enters what
+// a canvas click on the layer would, and never a container that is open by itself.
+
+const editor = useEditorSetupWithClear('/?test&no-rulers')
+
+const scene = clickDepthDriver(() => editor.page)
+
+test('a layer picked in the layers panel enters only what a canvas click on it would', async () => {
+ const ids = await scene.scopeTree()
+ await editor.canvas.waitForRender()
+
+ // C sits in a top-level frame, which a click looks into by itself: nothing is entered.
+ await editor.page.locator(`[data-node-id="${ids.c}"]`).click()
+ await expect.poll(async () => (await scene.state()).entered).toBeNull()
+
+ // A sits in a nested frame: that frame is entered, as a double-click on the canvas would.
+ await editor.page.locator(`[data-node-id="${ids.a}"]`).click()
+ await expect.poll(async () => (await scene.state()).entered).toBe(ids.inner)
+ editor.canvas.assertNoErrors()
+})
diff --git a/tests/helpers/canvas/click-depth/driver.ts b/tests/helpers/canvas/click-depth/driver.ts
index 1c509eb1d..4ae4bb57e 100644
--- a/tests/helpers/canvas/click-depth/driver.ts
+++ b/tests/helpers/canvas/click-depth/driver.ts
@@ -2,7 +2,11 @@ import type { Page } from '@playwright/test'
import type * as ClickDepthScenes from '#tests/helpers/canvas/click-depth/scene'
-type SceneName = 'createClickDepthCards' | 'createNestedBoard' | 'createComponentChart'
+type SceneName =
+ | 'createClickDepthCards'
+ | 'createNestedBoard'
+ | 'createComponentChart'
+ | 'createScopeTree'
/** Builds click-depth scenes and reads back what pointer input selected, hovered, or moved. */
/** `page` is read on each call, so a spec can create the driver before its page exists. */
@@ -25,6 +29,21 @@ export function clickDepthDriver(page: () => Page) {
nestedBoard: () => build('createNestedBoard'),
componentChart: () => build('createComponentChart'),
+ /** Builds the scope tree and opens the layer rows of its two leaves. */
+ async scopeTree() {
+ const ids = await build('createScopeTree')
+ await page().evaluate(
+ (leaves) => {
+ const store = window.openPencil?.getStore?.()
+ if (!store) throw new Error('OpenPencil store not initialized')
+ store.select(leaves)
+ store.clearSelection()
+ },
+ [ids.a, ids.c]
+ )
+ return ids
+ },
+
/** Shows the page at `zoom` with the canvas origin at the top left. */
zoomTo(zoom: number) {
return page().evaluate((level) => {
diff --git a/tests/helpers/canvas/click-depth/scene.ts b/tests/helpers/canvas/click-depth/scene.ts
index 1f1aba42c..acedba487 100644
--- a/tests/helpers/canvas/click-depth/scene.ts
+++ b/tests/helpers/canvas/click-depth/scene.ts
@@ -125,3 +125,50 @@ export function createComponentChart(graph: SceneGraph, pageId: string) {
})
return { component: component.id, group: group.id, curve: curve.id }
}
+
+/**
+ * A section holding a top-level frame with a nested frame: `a` sits in the nested frame, `c`
+ * directly in the top-level frame. Both are selected and cleared, so their layer rows are open.
+ */
+export function createScopeTree(graph: SceneGraph, pageId: string) {
+ const grey = fill(0.9, 0.9, 0.9)
+ const section = graph.createNode('SECTION', pageId, {
+ name: 'Section',
+ width: 500,
+ height: 400,
+ fills: grey
+ })
+ const top = graph.createNode('FRAME', section.id, {
+ name: 'Top',
+ x: 40,
+ y: 40,
+ width: 400,
+ height: 300,
+ fills: grey
+ })
+ const inner = graph.createNode('FRAME', top.id, {
+ name: 'Inner',
+ x: 40,
+ y: 40,
+ width: 300,
+ height: 200,
+ fills: grey
+ })
+ const a = graph.createNode('RECTANGLE', inner.id, {
+ name: 'A',
+ x: 40,
+ y: 40,
+ width: 60,
+ height: 60,
+ fills: grey
+ })
+ const c = graph.createNode('RECTANGLE', top.id, {
+ name: 'C',
+ x: 20,
+ y: 260,
+ width: 30,
+ height: 30,
+ fills: grey
+ })
+ return { inner: inner.id, a: a.id, c: c.id }
+}