Skip to content

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

feat(canvas): draw pen, comment, and hand cursors; Figma's Section and Frame keys (#1198)

Danila Poyarkovaa7b3c7ea9dc
diff --git a/changes/1198/changed.md b/changes/1198/changed.md
new file mode 100644
index 000000000..87832acc8
--- /dev/null
+++ b/changes/1198/changed.md
@@ -0,0 +1,2 @@
+- Pen, comment, and hand tools show their own cursors on the canvas, and the hand closes while panning.
+- Section moves to Shift+S and Frame also answers to A, as in Figma.
diff --git a/packages/core/src/editor/tool-registry.ts b/packages/core/src/editor/tool-registry.ts
index f12d05168..4b81cccbb 100644
--- a/packages/core/src/editor/tool-registry.ts
+++ b/packages/core/src/editor/tool-registry.ts
@@ -25,7 +25,8 @@ export const EDITOR_TOOLS: EditorToolDef[] = [
export const TOOL_SHORTCUTS: Partial<Record<string, Tool>> = {
KeyV: 'SELECT',
KeyF: 'FRAME',
- KeyS: 'SECTION',
+ KeyA: 'FRAME',
+ 'Shift+KeyS': 'SECTION',
KeyR: 'RECTANGLE',
KeyO: 'ELLIPSE',
KeyL: 'LINE',
diff --git a/packages/docs/de/user-guide/drawing-shapes.md b/packages/docs/de/user-guide/drawing-shapes.md
index 3e9d78400..015835555 100644
--- a/packages/docs/de/user-guide/drawing-shapes.md
+++ b/packages/docs/de/user-guide/drawing-shapes.md
@@ -15,7 +15,7 @@ Die untere Werkzeugleiste enthält Werkzeuge für Formen, Rahmen und Sektionen.
| Ellipse | <kbd>O</kbd> | Ellipse |
| Linie | <kbd>L</kbd> | Linie |
| Rahmen | <kbd>F</kbd> | Container für andere Objekte |
-| Sektion | <kbd>S</kbd> | Container der obersten Ebene |
+| Sektion | <kbd>Shift</kbd> + <kbd>S</kbd> | Container der obersten Ebene |
Polygon und Stern befinden sich im Formenmenü.
diff --git a/packages/docs/es/user-guide/drawing-shapes.md b/packages/docs/es/user-guide/drawing-shapes.md
index a78c18963..729312b87 100644
--- a/packages/docs/es/user-guide/drawing-shapes.md
+++ b/packages/docs/es/user-guide/drawing-shapes.md
@@ -15,7 +15,7 @@ La barra inferior contiene herramientas para crear formas, marcos y secciones. S
| Elipse | <kbd>O</kbd> | Elipse |
| Línea | <kbd>L</kbd> | Línea |
| Marco | <kbd>F</kbd> | Contenedor de otros objetos |
-| Sección | <kbd>S</kbd> | Contenedor de nivel superior |
+| Sección | <kbd>Shift</kbd> + <kbd>S</kbd> | Contenedor de nivel superior |
Polígono y Estrella están disponibles en el menú de formas.
diff --git a/packages/docs/fr/user-guide/drawing-shapes.md b/packages/docs/fr/user-guide/drawing-shapes.md
index 1fb7a9b1a..9f9200ea9 100644
--- a/packages/docs/fr/user-guide/drawing-shapes.md
+++ b/packages/docs/fr/user-guide/drawing-shapes.md
@@ -15,7 +15,7 @@ La barre inférieure contient les outils de création de formes, cadres et secti
| Ellipse | <kbd>O</kbd> | Ellipse |
| Ligne | <kbd>L</kbd> | Ligne |
| Cadre | <kbd>F</kbd> | Conteneur d’autres objets |
-| Section | <kbd>S</kbd> | Conteneur de premier niveau |
+| Section | <kbd>Shift</kbd> + <kbd>S</kbd> | Conteneur de premier niveau |
Polygone et Étoile sont disponibles dans le menu des formes.
diff --git a/packages/docs/it/user-guide/drawing-shapes.md b/packages/docs/it/user-guide/drawing-shapes.md
index 87b7ad69a..b05f76e6c 100644
--- a/packages/docs/it/user-guide/drawing-shapes.md
+++ b/packages/docs/it/user-guide/drawing-shapes.md
@@ -15,7 +15,7 @@ La barra inferiore contiene gli strumenti per creare forme, frame e sezioni. Sel
| Ellisse | <kbd>O</kbd> | Ellisse |
| Linea | <kbd>L</kbd> | Linea |
| Frame | <kbd>F</kbd> | Contenitore di altri oggetti |
-| Sezione | <kbd>S</kbd> | Contenitore di primo livello |
+| Sezione | <kbd>Shift</kbd> + <kbd>S</kbd> | Contenitore di primo livello |
Poligono e Stella sono disponibili nel menu delle forme.
diff --git a/packages/docs/pl/user-guide/drawing-shapes.md b/packages/docs/pl/user-guide/drawing-shapes.md
index e3dc89f25..783bc7300 100644
--- a/packages/docs/pl/user-guide/drawing-shapes.md
+++ b/packages/docs/pl/user-guide/drawing-shapes.md
@@ -15,7 +15,7 @@ Dolny pasek narzędzi zawiera narzędzia do tworzenia kształtów, ramek i sekcj
| Elipsa | <kbd>O</kbd> | Elipsa |
| Linia | <kbd>L</kbd> | Linia |
| Ramka | <kbd>F</kbd> | Kontener na inne obiekty |
-| Sekcja | <kbd>S</kbd> | Kontener najwyższego poziomu przejmujący przecinające się obiekty |
+| Sekcja | <kbd>Shift</kbd> + <kbd>S</kbd> | Kontener najwyższego poziomu przejmujący przecinające się obiekty |
## Dodatkowe kształty
@@ -74,5 +74,5 @@ Po wybraniu narzędzia Ramka panel Projekt pokazuje grupy gotowych rozmiarów dl
| Elipsa | <kbd>O</kbd> | <kbd>O</kbd> |
| Linia | <kbd>L</kbd> | <kbd>L</kbd> |
| Ramka | <kbd>F</kbd> | <kbd>F</kbd> |
-| Sekcja | <kbd>S</kbd> | <kbd>S</kbd> |
+| Sekcja | <kbd>⇧</kbd><kbd>S</kbd> | <kbd>Shift</kbd> + <kbd>S</kbd> |
| Kwadrat lub koło | <kbd>Shift</kbd> + przeciąganie | <kbd>Shift</kbd> + przeciąganie |
diff --git a/packages/docs/reference/keyboard-shortcuts.md b/packages/docs/reference/keyboard-shortcuts.md
index fc6c7eb7a..93b5b382c 100644
--- a/packages/docs/reference/keyboard-shortcuts.md
+++ b/packages/docs/reference/keyboard-shortcuts.md
@@ -18,8 +18,8 @@ Full Figma-compatible shortcut map. ✅ = implemented.
| <kbd>V</kbd> | Move/Select | ✅ |
| <kbd>K</kbd> | Scale | 🔲 |
| <kbd>H</kbd> | Hand | ✅ |
-| <kbd>F</kbd> | Frame | ✅ |
-| <kbd>S</kbd> | Section | ✅ |
+| <kbd>F</kbd> or <kbd>A</kbd> | Frame | ✅ |
+| <kbd>⇧</kbd><kbd>S</kbd> | Section | ✅ |
| <kbd>R</kbd> | Rectangle | ✅ |
| <kbd>O</kbd> | Ellipse | ✅ |
| <kbd>L</kbd> | Line | ✅ |
diff --git a/packages/docs/ru/user-guide/drawing-shapes.md b/packages/docs/ru/user-guide/drawing-shapes.md
index 4578c6baa..70af016a6 100644
--- a/packages/docs/ru/user-guide/drawing-shapes.md
+++ b/packages/docs/ru/user-guide/drawing-shapes.md
@@ -15,7 +15,7 @@ description: Создание прямоугольников, эллипсов,
| Эллипс | <kbd>O</kbd> | Эллипс |
| Линия | <kbd>L</kbd> | Линия |
| Фрейм | <kbd>F</kbd> | Контейнер для других объектов |
-| Секция | <kbd>S</kbd> | Контейнер верхнего уровня, принимающий пересекающиеся соседние объекты |
+| Секция | <kbd>Shift</kbd> + <kbd>S</kbd> | Контейнер верхнего уровня, принимающий пересекающиеся соседние объекты |
## Дополнительные фигуры
@@ -83,7 +83,7 @@ description: Создание прямоугольников, эллипсов,
| Эллипс | <kbd>O</kbd> | <kbd>O</kbd> |
| Линия | <kbd>L</kbd> | <kbd>L</kbd> |
| Фрейм | <kbd>F</kbd> | <kbd>F</kbd> |
-| Секция | <kbd>S</kbd> | <kbd>S</kbd> |
+| Секция | <kbd>⇧</kbd><kbd>S</kbd> | <kbd>Shift</kbd> + <kbd>S</kbd> |
| Квадрат или круг | <kbd>Shift</kbd> + перетаскивание | <kbd>Shift</kbd> + перетаскивание |
## Советы
diff --git a/packages/docs/user-guide/drawing-shapes.md b/packages/docs/user-guide/drawing-shapes.md
index 2ac62b3b9..eb3ee6959 100644
--- a/packages/docs/user-guide/drawing-shapes.md
+++ b/packages/docs/user-guide/drawing-shapes.md
@@ -13,8 +13,8 @@ The bottom toolbar provides tools for creating shapes, frames, and sections. Sel
| Rectangle | <kbd>R</kbd> | Draws a rectangle |
| Ellipse | <kbd>O</kbd> | Draws an ellipse |
| Line | <kbd>L</kbd> | Draws a line |
-| Frame | <kbd>F</kbd> | Draws a frame (container for other nodes) |
-| Section | <kbd>S</kbd> | Draws a section (takes in the siblings it fully covers) |
+| Frame | <kbd>F</kbd> or <kbd>A</kbd> | Draws a frame (container for other nodes) |
+| Section | <kbd>Shift</kbd> + <kbd>S</kbd> | Draws a section (takes in the siblings it fully covers) |
## Shapes Flyout
@@ -100,8 +100,8 @@ Select the Frame tool to browse collapsible presets for phones, tablets, desktop
| Rectangle tool | <kbd>R</kbd> | <kbd>R</kbd> |
| Ellipse tool | <kbd>O</kbd> | <kbd>O</kbd> |
| Line tool | <kbd>L</kbd> | <kbd>L</kbd> |
-| Frame tool | <kbd>F</kbd> | <kbd>F</kbd> |
-| Section tool | <kbd>S</kbd> | <kbd>S</kbd> |
+| Frame tool | <kbd>F</kbd> or <kbd>A</kbd> | <kbd>F</kbd> or <kbd>A</kbd> |
+| Section tool | <kbd>⇧</kbd><kbd>S</kbd> | <kbd>Shift</kbd> + <kbd>S</kbd> |
| Constrain to square/circle | <kbd>Shift</kbd> + drag | <kbd>Shift</kbd> + drag |
## Tips
diff --git a/packages/vue/src/canvas/pen/input.ts b/packages/vue/src/canvas/pen/input.ts
index 079ac9a2a..6fd2f1db4 100644
--- a/packages/vue/src/canvas/pen/input.ts
+++ b/packages/vue/src/canvas/pen/input.ts
@@ -5,6 +5,7 @@ import type { Editor } from '@open-pencil/core/editor'
import type { Vector } from '@open-pencil/scene-graph/primitives'
import { createPenDrag, handlePenDragMove } from '#vue/canvas/pen/drag'
+import { PEN_CURSOR } from '#vue/editor/tool-cursor'
import type { DragState } from '#vue/shared/input/types'
import { handlePenNodeEditDown } from '#vue/shared/input/vector'
@@ -40,7 +41,7 @@ export function startPenInput(
editor.penSetPendingClose(true)
editor.penSetClosingToFirst(true)
setDrag(createPenDrag(first.x, first.y))
- cursorOverride.value = 'crosshair'
+ cursorOverride.value = PEN_CURSOR
return true
}
}
@@ -48,7 +49,7 @@ export function startPenInput(
editor.penSetPendingClose(false)
editor.penAddVertex(cx, cy)
setDrag(createPenDrag(cx, cy))
- cursorOverride.value = 'crosshair'
+ cursorOverride.value = PEN_CURSOR
return true
}
diff --git a/packages/vue/src/canvas/tools/input.ts b/packages/vue/src/canvas/tools/input.ts
index e7351d01a..e1855c1c8 100644
--- a/packages/vue/src/canvas/tools/input.ts
+++ b/packages/vue/src/canvas/tools/input.ts
@@ -3,6 +3,7 @@ import type { Ref } from 'vue'
import type { Editor } from '@open-pencil/core/editor'
import { startPenInput } from '#vue/canvas/pen/input'
+import { HAND_GRAB_CURSOR } from '#vue/editor/tool-cursor'
import { startShapeDraw, startTextDraw } from '#vue/shared/input/draw'
import { startPanDrag } from '#vue/shared/input/pan'
import { handleSelectDown } from '#vue/shared/input/select'
@@ -42,6 +43,7 @@ export function handleToolMouseDown({
if (event.button === 1 || tool === 'HAND') {
startPanDrag(event, setDrag, editor)
+ cursorOverride.value = HAND_GRAB_CURSOR
return
}
diff --git a/packages/vue/src/editor/tool-cursor/index.ts b/packages/vue/src/editor/tool-cursor/index.ts
index 915efff53..a496701d2 100644
--- a/packages/vue/src/editor/tool-cursor/index.ts
+++ b/packages/vue/src/editor/tool-cursor/index.ts
@@ -1,5 +1,23 @@
import type { Tool } from '@open-pencil/core/editor'
+import commentCursorSVG from '#vue/shared/assets/cursors/comment.svg?raw'
+import handGrabCursorSVG from '#vue/shared/assets/cursors/hand-grab.svg?raw'
+import handCursorSVG from '#vue/shared/assets/cursors/hand.svg?raw'
+import penCursorSVG from '#vue/shared/assets/cursors/pen.svg?raw'
+
+function svgCursor(svg: string, x: number, y: number, fallback: string): string {
+ return `url("data:image/svg+xml,${encodeURIComponent(svg)}") ${x} ${y}, ${fallback}`
+}
+
+/** The pen nib, pointing at its tip. */
+export const PEN_CURSOR = svgCursor(penCursorSVG, 4, 4, 'crosshair')
+/** A speech bubble whose tail tip places the comment pin. */
+const COMMENT_CURSOR = svgCursor(commentCursorSVG, 5, 24, 'crosshair')
+/** The open hand of the hand tool. */
+const HAND_CURSOR = svgCursor(handCursorSVG, 16, 16, 'grab')
+/** The closed hand while a pan drag is held. */
+export const HAND_GRAB_CURSOR = svgCursor(handGrabCursorSVG, 16, 16, 'grabbing')
+
const TOOL_CURSORS: Record<Tool, string> = {
SELECT: 'default',
FRAME: 'crosshair',
@@ -10,9 +28,9 @@ const TOOL_CURSORS: Record<Tool, string> = {
POLYGON: 'crosshair',
STAR: 'crosshair',
TEXT: 'text',
- PEN: 'crosshair',
- HAND: 'grab',
- COMMENT: 'crosshair'
+ PEN: PEN_CURSOR,
+ HAND: HAND_CURSOR,
+ COMMENT: COMMENT_CURSOR
}
export function toolCursor(tool: Tool, override?: string | null): string {
diff --git a/packages/vue/src/shared/assets/cursors/comment.svg b/packages/vue/src/shared/assets/cursors/comment.svg
new file mode 100644
index 000000000..31d13559d
--- /dev/null
+++ b/packages/vue/src/shared/assets/cursors/comment.svg
@@ -0,0 +1,18 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
+ <filter id="shadow" x="-50%" y="-50%" width="200%" height="200%">
+ <feDropShadow dx="0" dy="1.25" stdDeviation="1" flood-opacity="0.5"/>
+ </filter>
+ <g filter="url(#shadow)" stroke-linecap="round" stroke-linejoin="round">
+ <g transform="translate(3.16 6.64) scale(0.8)">
+ <g fill="#fff" stroke="#fff" stroke-width="3.75">
+ <path d="M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092a10 10 0 1 0-4.777-4.719Z"/>
+ </g>
+ <g fill="#fff">
+ <path d="M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092a10 10 0 1 0-4.777-4.719Z"/>
+ </g>
+ <g fill="none" stroke="#000" stroke-width="1.25">
+ <path d="M2.992 16.342a2 2 0 0 1 .094 1.167l-1.065 3.29a1 1 0 0 0 1.236 1.168l3.413-.998a2 2 0 0 1 1.099.092a10 10 0 1 0-4.777-4.719"/>
+ </g>
+ </g>
+ </g>
+</svg>
diff --git a/packages/vue/src/shared/assets/cursors/hand-grab.svg b/packages/vue/src/shared/assets/cursors/hand-grab.svg
new file mode 100644
index 000000000..0fb9046ac
--- /dev/null
+++ b/packages/vue/src/shared/assets/cursors/hand-grab.svg
@@ -0,0 +1,21 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
+ <filter id="shadow" x="-50%" y="-50%" width="200%" height="200%">
+ <feDropShadow dx="0" dy="1.25" stdDeviation="1" flood-opacity="0.5"/>
+ </filter>
+ <g filter="url(#shadow)" stroke-linecap="round" stroke-linejoin="round">
+ <g transform="translate(6.4 4.8) scale(0.8)">
+ <g fill="#fff" stroke="#fff" stroke-width="3.75">
+ <path d="M6 14V9a2 2 0 0 1 4 0V8a2 2 0 0 1 4 0v1a2 2 0 0 1 4 0v2a2 2 0 0 1 4 0v3a8 8 0 0 1-8 8h-4a8 8 0 0 1-8-8a2 2 0 0 1 4 0Z"/>
+ <path d="M18 11.5V9a2 2 0 0 0-2-2a2 2 0 0 0-2 2v1.4m0-.4V8a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2m0-.1V9a2 2 0 0 0-2-2a2 2 0 0 0-2 2v5m0 0a2 2 0 0 0-2-2a2 2 0 0 0-2 2"/>
+ <path d="M18 11a2 2 0 1 1 4 0v3a8 8 0 0 1-8 8h-4a8 8 0 0 1-8-8a2 2 0 1 1 4 0"/>
+ </g>
+ <g fill="#fff">
+ <path d="M6 14V9a2 2 0 0 1 4 0V8a2 2 0 0 1 4 0v1a2 2 0 0 1 4 0v2a2 2 0 0 1 4 0v3a8 8 0 0 1-8 8h-4a8 8 0 0 1-8-8a2 2 0 0 1 4 0Z"/>
+ </g>
+ <g fill="none" stroke="#000" stroke-width="1.25">
+ <path d="M18 11.5V9a2 2 0 0 0-2-2a2 2 0 0 0-2 2v1.4m0-.4V8a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2m0-.1V9a2 2 0 0 0-2-2a2 2 0 0 0-2 2v5m0 0a2 2 0 0 0-2-2a2 2 0 0 0-2 2"/>
+ <path d="M18 11a2 2 0 1 1 4 0v3a8 8 0 0 1-8 8h-4a8 8 0 0 1-8-8a2 2 0 1 1 4 0"/>
+ </g>
+ </g>
+ </g>
+</svg>
diff --git a/packages/vue/src/shared/assets/cursors/hand.svg b/packages/vue/src/shared/assets/cursors/hand.svg
new file mode 100644
index 000000000..b1f6eb08e
--- /dev/null
+++ b/packages/vue/src/shared/assets/cursors/hand.svg
@@ -0,0 +1,21 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
+ <filter id="shadow" x="-50%" y="-50%" width="200%" height="200%">
+ <feDropShadow dx="0" dy="1.25" stdDeviation="1" flood-opacity="0.5"/>
+ </filter>
+ <g filter="url(#shadow)" stroke-linecap="round" stroke-linejoin="round">
+ <g transform="translate(6.4 6.4) scale(0.8)">
+ <g fill="#fff" stroke="#fff" stroke-width="3.75">
+ <path d="M6 14V6a2 2 0 0 1 4 0V4a2 2 0 0 1 4 0v2a2 2 0 0 1 4 0v2a2 2 0 0 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15Z"/>
+ <path d="M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2m0 4V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2m0 4.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8"/>
+ <path d="M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15"/>
+ </g>
+ <g fill="#fff">
+ <path d="M6 14V6a2 2 0 0 1 4 0V4a2 2 0 0 1 4 0v2a2 2 0 0 1 4 0v2a2 2 0 0 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15Z"/>
+ </g>
+ <g fill="none" stroke="#000" stroke-width="1.25">
+ <path d="M18 11V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2m0 4V4a2 2 0 0 0-2-2a2 2 0 0 0-2 2v2m0 4.5V6a2 2 0 0 0-2-2a2 2 0 0 0-2 2v8"/>
+ <path d="M18 8a2 2 0 1 1 4 0v6a8 8 0 0 1-8 8h-2c-2.8 0-4.5-.86-5.99-2.34l-3.6-3.6a2 2 0 0 1 2.83-2.82L7 15"/>
+ </g>
+ </g>
+ </g>
+</svg>
diff --git a/packages/vue/src/shared/assets/cursors/pen.svg b/packages/vue/src/shared/assets/cursors/pen.svg
new file mode 100644
index 000000000..e45b1f0bf
--- /dev/null
+++ b/packages/vue/src/shared/assets/cursors/pen.svg
@@ -0,0 +1,24 @@
+<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 32 32">
+ <filter id="shadow" x="-50%" y="-50%" width="200%" height="200%">
+ <feDropShadow dx="0" dy="1.25" stdDeviation="1" flood-opacity="0.5"/>
+ </filter>
+ <g filter="url(#shadow)" stroke-linecap="round" stroke-linejoin="round">
+ <g transform="translate(2.16 2.16) scale(0.8)">
+ <g fill="#fff" stroke="#fff" stroke-width="3.75">
+ <path d="M18 13l-1.375-6.874a1 1 0 0 0-.746-.776L3.235 2.028a1 1 0 0 0-1.207 1.207L5.35 15.879a1 1 0 0 0 .776.746L13 18Z"/>
+ <path d="M15.707 21.293a1 1 0 0 1-1.414 0l-1.586-1.586a1 1 0 0 1 0-1.414l5.586-5.586a1 1 0 0 1 1.414 0l1.586 1.586a1 1 0 0 1 0 1.414z"/>
+ <path d="M18 13l-1.375-6.874a1 1 0 0 0-.746-.776L3.235 2.028a1 1 0 0 0-1.207 1.207L5.35 15.879a1 1 0 0 0 .776.746L13 18M2.3 2.3l7.286 7.286"/>
+ <path d="M13 11a2 2 0 1 1-4 0a2 2 0 1 1 4 0"/>
+ </g>
+ <g fill="#fff">
+ <path d="M18 13l-1.375-6.874a1 1 0 0 0-.746-.776L3.235 2.028a1 1 0 0 0-1.207 1.207L5.35 15.879a1 1 0 0 0 .776.746L13 18Z"/>
+ <path d="M15.707 21.293a1 1 0 0 1-1.414 0l-1.586-1.586a1 1 0 0 1 0-1.414l5.586-5.586a1 1 0 0 1 1.414 0l1.586 1.586a1 1 0 0 1 0 1.414z"/>
+ </g>
+ <g fill="none" stroke="#000" stroke-width="1.25">
+ <path d="M15.707 21.293a1 1 0 0 1-1.414 0l-1.586-1.586a1 1 0 0 1 0-1.414l5.586-5.586a1 1 0 0 1 1.414 0l1.586 1.586a1 1 0 0 1 0 1.414z"/>
+ <path d="M18 13l-1.375-6.874a1 1 0 0 0-.746-.776L3.235 2.028a1 1 0 0 0-1.207 1.207L5.35 15.879a1 1 0 0 0 .776.746L13 18M2.3 2.3l7.286 7.286"/>
+ <path d="M13 11a2 2 0 1 1-4 0a2 2 0 1 1 4 0"/>
+ </g>
+ </g>
+ </g>
+</svg>
diff --git a/packages/vue/src/shared/assets/resize-cursor.svg b/packages/vue/src/shared/assets/cursors/resize.svg
similarity index 100%
rename from packages/vue/src/shared/assets/resize-cursor.svg
rename to packages/vue/src/shared/assets/cursors/resize.svg
diff --git a/packages/vue/src/shared/assets/rotate-cursor.svg b/packages/vue/src/shared/assets/cursors/rotate.svg
similarity index 100%
rename from packages/vue/src/shared/assets/rotate-cursor.svg
rename to packages/vue/src/shared/assets/cursors/rotate.svg
diff --git a/packages/vue/src/shared/input/geometry.ts b/packages/vue/src/shared/input/geometry.ts
index 5887bb367..b1817a731 100644
--- a/packages/vue/src/shared/input/geometry.ts
+++ b/packages/vue/src/shared/input/geometry.ts
@@ -15,8 +15,8 @@ import {
import type { SceneGraph, SceneNode } from '@open-pencil/scene-graph'
import type { Vector } from '@open-pencil/scene-graph/primitives'
-import resizeCursorSVG from '#vue/shared/assets/resize-cursor.svg?raw'
-import rotateCursorSVG from '#vue/shared/assets/rotate-cursor.svg?raw'
+import resizeCursorSVG from '#vue/shared/assets/cursors/resize.svg?raw'
+import rotateCursorSVG from '#vue/shared/assets/cursors/rotate.svg?raw'
export function getPointerCoords(e: MouseEvent, canvas: HTMLCanvasElement | null, editor: Editor) {
if (!canvas) return { sx: 0, sy: 0, cx: 0, cy: 0 }
diff --git a/packages/vue/tests/editor/tool-cursor/index.test.ts b/packages/vue/tests/editor/tool-cursor/index.test.ts
new file mode 100644
index 000000000..9408ad4ca
--- /dev/null
+++ b/packages/vue/tests/editor/tool-cursor/index.test.ts
@@ -0,0 +1,26 @@
+import { describe, expect, test } from 'bun:test'
+
+import { HAND_GRAB_CURSOR, toolCursor } from '#vue/editor/tool-cursor'
+
+/** The hotspot and fallback that follow a CSS cursor's image. */
+function cursorTail(cursor: string) {
+ return cursor.slice(cursor.lastIndexOf(')') + 1).trim()
+}
+
+describe('toolCursor', () => {
+ test('pen, comment, and hand draw their own cursors with a fallback', () => {
+ expect(cursorTail(toolCursor('PEN'))).toBe('4 4, crosshair')
+ expect(cursorTail(toolCursor('COMMENT'))).toBe('5 24, crosshair')
+ expect(cursorTail(toolCursor('HAND'))).toBe('16 16, grab')
+ expect(cursorTail(HAND_GRAB_CURSOR)).toBe('16 16, grabbing')
+ for (const cursor of [toolCursor('PEN'), toolCursor('COMMENT'), toolCursor('HAND')]) {
+ expect(cursor.startsWith('url("data:image/svg+xml,%3Csvg')).toBe(true)
+ }
+ })
+
+ test('drawing tools keep the system crosshair and an override wins', () => {
+ expect(toolCursor('RECTANGLE')).toBe('crosshair')
+ expect(toolCursor('SELECT')).toBe('default')
+ expect(toolCursor('HAND', 'move')).toBe('move')
+ })
+})
diff --git a/src/app/editor/toolbar/shortcuts.ts b/src/app/editor/toolbar/shortcuts.ts
index cf3d49865..bf2229bb5 100644
--- a/src/app/editor/toolbar/shortcuts.ts
+++ b/src/app/editor/toolbar/shortcuts.ts
@@ -1,10 +1,13 @@
+import { mapValues } from 'es-toolkit/object'
+
import type { Tool } from '@open-pencil/core/editor'
+import { formatShortcut, type ShortcutPlatform } from '@open-pencil/vue'
-/** Each tool's key as the toolbar and Settings print it; empty for tools without one. */
-export const TOOL_SHORTCUT_LABELS: Readonly<Record<Tool, string>> = {
+/** Each tool's key in the command registry's notation; empty for tools without one. */
+const TOOL_SHORTCUT_KEYS: Readonly<Record<Tool, string>> = {
SELECT: 'V',
FRAME: 'F',
- SECTION: 'S',
+ SECTION: 'SHIFT+S',
RECTANGLE: 'R',
ELLIPSE: 'O',
LINE: 'L',
@@ -16,6 +19,11 @@ export const TOOL_SHORTCUT_LABELS: Readonly<Record<Tool, string>> = {
COMMENT: 'C'
}
+/** Each tool's key as the toolbar and Settings print it on this platform. */
+export function toolShortcutLabels(platform?: ShortcutPlatform): Readonly<Record<Tool, string>> {
+ return mapValues(TOOL_SHORTCUT_KEYS, (keys) => formatShortcut(keys, platform) ?? '')
+}
+
/** A tool's tooltip: its name, then its key when it has one. */
export function toolTip(label: string, shortcut: string): string {
return shortcut ? `${label} (${shortcut})` : label
diff --git a/src/components/comments/CommentsLayer.vue b/src/components/comments/CommentsLayer.vue
index c44cf2820..89f2849a3 100644
--- a/src/components/comments/CommentsLayer.vue
+++ b/src/components/comments/CommentsLayer.vue
@@ -12,7 +12,7 @@ import { computed, ref, useTemplateRef, watch } from 'vue'
import type { ViewportTransform } from '@open-pencil/core/geometry'
import type { Vector } from '@open-pencil/scene-graph/primitives'
-import { useCommentMessages } from '@open-pencil/vue'
+import { toolCursor, useCommentMessages } from '@open-pencil/vue'
import { useComments } from '@/app/comments/use'
import { useEditorStore } from '@/app/editor/active-store'
@@ -175,6 +175,7 @@ function closeCard() {
<div
v-if="commenting"
:class="ui.capture()"
+ :style="{ cursor: toolCursor('COMMENT') }"
data-slot="comments-capture"
@pointerdown.prevent="placeDraft"
@contextmenu.prevent
diff --git a/src/components/settings/toolbar/ToolbarLayoutEditor.vue b/src/components/settings/toolbar/ToolbarLayoutEditor.vue
index 61edb0646..18e4714f0 100644
--- a/src/components/settings/toolbar/ToolbarLayoutEditor.vue
+++ b/src/components/settings/toolbar/ToolbarLayoutEditor.vue
@@ -19,7 +19,7 @@ import {
type ToolbarLayout,
type ToolbarRow
} from '@/app/editor/toolbar/layout'
-import { TOOL_SHORTCUT_LABELS } from '@/app/editor/toolbar/shortcuts'
+import { toolShortcutLabels } from '@/app/editor/toolbar/shortcuts'
import ToolbarLayoutJoint from '@/components/settings/toolbar/ToolbarLayoutJoint.vue'
import ToolbarLayoutRow, {
type ToolbarRowControl
@@ -34,6 +34,7 @@ import { toolbarEntryIcons, useToolbarEntryLabels } from '@/components/toolbar/l
*/
const layout = defineModel<ToolbarLayout>({ required: true })
const labels = useToolbarEntryLabels()
+const toolShortcuts = toolShortcutLabels()
/** A row and its place in the whole list, which is also the joint above it. */
interface PlacedRow {
@@ -130,7 +131,7 @@ function setShown(entry: ToolbarEntry, shown: boolean) {
<ToolbarLayoutRow
:label="labels[row.entry]"
:icon="toolbarEntryIcons[row.entry]"
- :shortcut="isToolbarAction(row.entry) ? '' : TOOL_SHORTCUT_LABELS[row.entry]"
+ :shortcut="isToolbarAction(row.entry) ? '' : toolShortcuts[row.entry]"
:hidden="row.hidden"
:pinned="row.entry === PINNED_TOOLBAR_ENTRY"
:can-move-up="row.canMoveUp"
diff --git a/src/components/toolbar/Toolbar.vue b/src/components/toolbar/Toolbar.vue
index 85d9f0909..80846ef72 100644
--- a/src/components/toolbar/Toolbar.vue
+++ b/src/components/toolbar/Toolbar.vue
@@ -12,7 +12,7 @@ import {
import { useEditorStore } from '@/app/editor/active-store'
import { toolIcons } from '@/app/editor/icons'
import { toolbarItems } from '@/app/editor/toolbar/layout'
-import { TOOL_SHORTCUT_LABELS } from '@/app/editor/toolbar/shortcuts'
+import { toolShortcutLabels } from '@/app/editor/toolbar/shortcuts'
import { appPreferences } from '@/app/settings/preferences/store'
import { useActionToast } from '@/app/shell/toast/action'
import InsertIconButton from '@/components/icon-picker/InsertIconButton.vue'
@@ -32,8 +32,9 @@ const { menu } = useI18n()
const toolLabels = useToolLabels()
+const toolShortcuts = toolShortcutLabels()
const items = computed(() =>
- toolbarItems(appPreferences.value.toolbar, toolLabels.value, TOOL_SHORTCUT_LABELS)
+ toolbarItems(appPreferences.value.toolbar, toolLabels.value, toolShortcuts)
)
const tools = computed(() =>
items.value.flatMap((item) => (item.kind === 'tool' ? [item.tool] : []))
@@ -64,7 +65,7 @@ function onActionTap(item: ToolbarActionItem) {
:flyout-selections="flyoutSelections"
:tool-icons="toolIcons"
:tool-labels="toolLabels"
- :tool-shortcuts="TOOL_SHORTCUT_LABELS"
+ :tool-shortcuts="toolShortcuts"
:ui="toolbarUI"
@set-tool="actions.setTool"
>
@@ -80,7 +81,7 @@ function onActionTap(item: ToolbarActionItem) {
:flyout-selections="flyoutSelections"
:tool-icons="toolIcons"
:tool-labels="toolLabels"
- :tool-shortcuts="TOOL_SHORTCUT_LABELS"
+ :tool-shortcuts="toolShortcuts"
:ui="toolbarUI"
:mobile-category="mobileCategory"
:slide-direction="slideDirection"
diff --git a/src/theme/comments.ts b/src/theme/comments.ts
index 05f1cd486..e159a174c 100644
--- a/src/theme/comments.ts
+++ b/src/theme/comments.ts
@@ -8,7 +8,7 @@ export const comments = tv({
slots: {
// Below the toolbar and other floating UI, above the canvas.
layer: 'pointer-events-none absolute inset-0 z-0',
- capture: 'pointer-events-auto absolute inset-0 cursor-crosshair',
+ capture: 'pointer-events-auto absolute inset-0',
// Pins sit at their zoomed canvas positions in here; panning only moves this layer.
pins: 'absolute top-0 left-0',
// A 32px speech bubble whose square corner points at the commented spot, as Figma draws it;
diff --git a/tests/app/editor/toolbar/layout.test.ts b/tests/app/editor/toolbar/layout.test.ts
index 14d0736dd..fcbdc446b 100644
--- a/tests/app/editor/toolbar/layout.test.ts
+++ b/tests/app/editor/toolbar/layout.test.ts
@@ -15,10 +15,11 @@ import {
type ToolbarEntry,
type ToolbarLayout
} from '@/app/editor/toolbar/layout'
-import { TOOL_SHORTCUT_LABELS } from '@/app/editor/toolbar/shortcuts'
+import { toolShortcutLabels } from '@/app/editor/toolbar/shortcuts'
const SHAPES: ToolbarEntry[] = ['RECTANGLE', 'LINE', 'ELLIPSE', 'POLYGON', 'STAR']
-const LABELS = { ...TOOL_SHORTCUT_LABELS }
+const SHORTCUTS = toolShortcutLabels('mac')
+const LABELS = { ...SHORTCUTS }
function layout(groups: ToolbarEntry[][], hidden: ToolbarEntry[] = []): ToolbarLayout {
return normalizeToolbarLayout(groups, hidden)
@@ -71,7 +72,7 @@ describe('toolbarItems', () => {
const items = toolbarItems(
layout(DEFAULT_TOOLBAR_LAYOUT.groups, ['SECTION', 'RECTANGLE']),
LABELS,
- TOOL_SHORTCUT_LABELS
+ SHORTCUTS
)
expect(items[1]).toEqual({
kind: 'tool',
@@ -93,7 +94,7 @@ describe('toolbarItems', () => {
const items = toolbarItems(
layout(DEFAULT_TOOLBAR_LAYOUT.groups, ['FRAME', 'SECTION']),
LABELS,
- TOOL_SHORTCUT_LABELS
+ SHORTCUTS
)
expect(items.map((item) => (item.kind === 'tool' ? item.tool.key : item.action))).not.toContain(
'FRAME'
diff --git a/tests/e2e/canvas/tool-cursors.spec.ts b/tests/e2e/canvas/tool-cursors.spec.ts
new file mode 100644
index 000000000..2640e8389
--- /dev/null
+++ b/tests/e2e/canvas/tool-cursors.spec.ts
@@ -0,0 +1,45 @@
+import { expect, test, useEditorSetupWithClear } from '#tests/e2e/fixtures'
+import { expectDefined } from '#tests/helpers/assert'
+
+const editor = useEditorSetupWithClear('/?test&no-chrome&no-rulers')
+
+const canvasElement = () => editor.page.getByTestId('canvas-element')
+const commentsCapture = () => editor.page.locator('[data-slot="comments-capture"]')
+
+/** The hotspot and fallback after a cursor's image, e.g. `16 16, grab`. */
+async function cursorTail(cursor: Promise<string>) {
+ const value = await cursor
+ return value.slice(value.lastIndexOf(')') + 1).trim()
+}
+
+const canvasCursor = () => cursorTail(canvasElement().evaluate((el) => el.style.cursor))
+
+test('the hand closes while it pans and opens again on release', async () => {
+ await editor.page.keyboard.press('h')
+ expect(await canvasCursor()).toBe('16 16, grab')
+
+ const box = expectDefined(await editor.canvas.canvas.boundingBox(), 'canvas bounds')
+ await editor.page.mouse.move(box.x + 300, box.y + 300)
+ await editor.page.mouse.down()
+ await editor.page.mouse.move(box.x + 340, box.y + 320, { steps: 4 })
+ expect(await canvasCursor()).toBe('16 16, grabbing')
+
+ await editor.page.mouse.up()
+ expect(await canvasCursor()).toBe('16 16, grab')
+ editor.canvas.assertNoErrors()
+})
+
+test('the pen keeps its nib cursor while placing points', async () => {
+ await editor.page.keyboard.press('p')
+ expect(await canvasCursor()).toBe('4 4, crosshair')
+ await editor.canvas.click(200, 200)
+ expect(await canvasCursor()).toBe('4 4, crosshair')
+ await editor.page.keyboard.press('Escape')
+})
+
+test('the comment tool shows a speech bubble pointing with its tail', async () => {
+ await editor.page.keyboard.press('c')
+ const cursor = commentsCapture().evaluate((el) => (el as HTMLElement).style.cursor)
+ expect(await cursorTail(cursor)).toBe('5 24, crosshair')
+ await editor.page.keyboard.press('v')
+})
diff --git a/tests/e2e/keyboard/shortcuts.spec.ts b/tests/e2e/keyboard/shortcuts.spec.ts
index 015227a65..94c218236 100644
--- a/tests/e2e/keyboard/shortcuts.spec.ts
+++ b/tests/e2e/keyboard/shortcuts.spec.ts
@@ -106,10 +106,22 @@ test.describe('tool switching', () => {
expect(await getActiveTool()).toBe('HAND')
})
- test('S → SECTION', async () => {
- await editor.page.keyboard.press('s')
+ test('A → FRAME', async () => {
+ await editor.page.keyboard.press('v')
+ await editor.page.keyboard.press('a')
+ expect(await getActiveTool()).toBe('FRAME')
+ })
+
+ test('⇧S → SECTION', async () => {
+ await editor.page.keyboard.press('Shift+KeyS')
expect(await getActiveTool()).toBe('SECTION')
})
+
+ test('S alone leaves the tool unchanged', async () => {
+ await editor.page.keyboard.press('v')
+ await editor.page.keyboard.press('s')
+ expect(await getActiveTool()).toBe('SELECT')
+ })
})
test.describe('selection shortcuts', () => {
diff --git a/tests/helpers/canvas.ts b/tests/helpers/canvas.ts
index 22cccd9f2..3adab3d72 100644
--- a/tests/helpers/canvas.ts
+++ b/tests/helpers/canvas.ts
@@ -124,7 +124,7 @@ export class CanvasHelper {
}
async drawSection(x: number, y: number, width: number, height: number) {
- await this.pressKey('s')
+ await this.pressKey('Shift+KeyS')
await this.drag(x, y, x + width, y + height)
await this.waitForRender()
}
@@ -135,7 +135,7 @@ export class CanvasHelper {
const keys: Record<string, string> = {
select: 'v',
frame: 'f',
- section: 's',
+ section: 'Shift+KeyS',
rectangle: 'r',
ellipse: 'o',
text: 't',