AI-native design editor. Open-source Figma alternative.
fix(snapping): hide pixel rounding alignment guides
Danila Poyarkov510b95377777
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2c734ea67..bdbb35306 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -36,6 +36,7 @@### Changed+- Keep pixel-grid rounding invisible while showing alignment guides only for real geometry, objects, and canvas/layout guides.- Copy selections as Figma-compatible clipboard data while preserving typed geometry, text sizing, images, components, variables, modes, and shared styles for lossless in-app paste.- Choose whether interface animations follow the system motion preference or stay off, with live updates and a persistent override.- Put unbound fill and stroke style pickers in section headers, preserve applied and missing style rows, and remove the redundant Dimensions heading for text layers.diff --git a/packages/vue/src/shared/input/snap.ts b/packages/vue/src/shared/input/snap.tsindex 7b65c71e0..33c1e7d82 100644--- a/packages/vue/src/shared/input/snap.ts+++ b/packages/vue/src/shared/input/snap.ts@@ -17,29 +17,13 @@ export function computePixelGridSnap(bounds: Rect, threshold: number): PixelSnapconst roundedY = Math.round(bounds.y)const dx = roundedX - bounds.xconst dy = roundedY - bounds.y- const guides: SnapGuide[] = []- if (Math.abs(dx) < threshold) {- guides.push({- axis: 'x',- position: roundedX,- from: bounds.y,- to: bounds.y + bounds.height- })- }- if (Math.abs(dy) < threshold) {- guides.push({- axis: 'y',- position: roundedY,- from: bounds.x,- to: bounds.x + bounds.width- })- }return {delta: {x: Math.abs(dx) < threshold ? dx : 0,y: Math.abs(dy) < threshold ? dy : 0},- guides+ // Pixel rounding is not alignment with another object or an explicit guide.+ guides: []}}diff --git a/tests/engine/vue/input/snap-guides.test.ts b/tests/engine/vue/input/snap-guides.test.tsnew file mode 100644index 000000000..e29b7d547--- /dev/null+++ b/tests/engine/vue/input/snap-guides.test.ts@@ -0,0 +1,58 @@+import { describe, expect, test } from 'bun:test'++import { createEditor } from '@open-pencil/core/editor'+import { computeSnap } from '@open-pencil/scene-graph'++import { computePixelGridSnap, resolveObjectPixelSnap } from '#vue/shared/input/snap'++describe('move snap guide presentation', () => {+ test('pixel rounding adjusts a lone frame without drawing self-alignment guides', () => {+ const pixel = computePixelGridSnap({ x: 10.25, y: 20.4, width: 100, height: 80 }, 5)+ expect(pixel.delta).toEqual({ x: -0.25, y: -0.3999999999999986 })+ expect(pixel.guides).toEqual([])+ const editor = createEditor()+ editor.state.snappingPreferences = { geometry: false, objects: true, pixelGrid: true }+ const result = resolveObjectPixelSnap(+ new Set(['frame']),+ { x: 10.25, y: 20.4, width: 100, height: 80 },+ [],+ editor+ )+ expect(result.correction).toEqual(pixel.delta)+ expect(result.guides).toEqual([])+ })++ test('object alignment still emits a real guide', () => {+ const editor = createEditor()+ editor.state.snappingPreferences = { geometry: false, objects: true, pixelGrid: true }+ const target = editor.graph.createNode('FRAME', editor.state.currentPageId, {+ x: 200,+ y: 20,+ width: 100,+ height: 80+ })+ const result = resolveObjectPixelSnap(+ new Set(['moving']),+ { x: 99, y: 20, width: 100, height: 80 },+ [target],+ editor+ )+ expect(result.correction.x).toBe(1)+ expect(result.guides.some((guide) => guide.axis === 'x' && guide.position === 200)).toBe(true)+ })++ test('multiple moving nodes are excluded from object targets', () => {+ const nodes = [+ { id: 'first', x: 0, y: 0, width: 50, height: 50, rotation: 0 },+ { id: 'second', x: 50, y: 0, width: 50, height: 50, rotation: 0 }+ ]+ expect(+ computeSnap(+ new Set(['first', 'second']),+ { x: 0.2, y: 0.2, width: 100, height: 50 },+ nodes,+ 5+ ).guides+ ).toEqual([])+ })+})