feat: add spacebar hold to temporarily activate Hand (pan) tool

Hold Spacebar to temporarily switch to the Hand tool for panning,
release to return to the previously active tool. This matches the
standard Figma UX pattern.

- Uses separate keydown/keyup event listeners for reliable handling
- Guards against text editing mode and key repeat
- References state.activeTool for correct tool state

Fixes #147
This commit is contained in:
TKman 2026-03-20 23:36:07 +09:00 committed by Danila Poyarkov
parent 2e723caba0
commit c52f88e34c
3 changed files with 24 additions and 12 deletions

View file

@ -301,7 +301,7 @@ export function collectFontKeys(graph: SceneGraph, nodeIds: string[]): Array<[st
return [...fontKeys].map((k) => k.split('\0') as [string, string])
}
let cjkFallbackFamilies: string[] = []
const cjkFallbackFamilies: string[] = []
let cjkFallbackPromise: Promise<string[]> | null = null
function getCJKCandidates(): string[] {

View file

@ -2,23 +2,13 @@ export const FIG_KIWI_VERSION = 106
import { deflateSync, inflateSync } from 'fflate'
<<<<<<< HEAD:packages/core/src/kiwi/kiwi-serialize.ts
import { getLoadedFontData, normalizeFontFamily, weightToStyle } from '../fonts'
import { encodeVectorNetworkBlob } from '../vector'
import { stringToGuid, VARIABLE_BINDING_FIELDS } from './kiwi-convert'
import type { SceneGraph, SceneNode, CharacterStyleOverride } from '../scene-graph'
import type { Color, GUID } from '../types'
import type { Color, GUID, Matrix } from '../types'
import type { NodeChange, Paint, VariableConsumptionEntry } from './codec'
=======
import { weightToStyle, getLoadedFontData, normalizeFontFamily } from './fonts'
import { encodeVectorNetworkBlob } from './vector'
import { stringToGuid, VARIABLE_BINDING_FIELDS } from './kiwi/kiwi-convert'
import type { NodeChange, Paint, VariableConsumptionEntry } from './kiwi/codec'
import type { SceneGraph, SceneNode, CharacterStyleOverride } from './scene-graph'
import type { Color, GUID, Matrix } from './types'
>>>>>>> 4df3671 (fix: kiwi serialization bugs causing broken auto-layout in Figma import):packages/core/src/kiwi-serialize.ts
const fontDigestCache = new Map<string, Uint8Array>()

View file

@ -94,6 +94,28 @@ export function useKeyboard() {
if (html) store.pasteFromHTML(html, cursorPos)
})
// Spacebar hold → temporary Hand tool (Figma-style canvas pan)
let toolBeforeSpace: (typeof store.state.activeTool) | null = null
useEventListener(window, 'keydown', (e: KeyboardEvent) => {
if (isEditing(e)) return
if (e.code === 'Space' && !e.metaKey && !e.ctrlKey && !e.altKey && !e.repeat) {
if (store.state.activeTool !== 'HAND') {
toolBeforeSpace = store.state.activeTool
store.setTool('HAND')
}
e.preventDefault()
}
})
useEventListener(window, 'keyup', (e: KeyboardEvent) => {
if (e.code === 'Space' && toolBeforeSpace) {
store.setTool(toolBeforeSpace)
toolBeforeSpace = null
e.preventDefault()
}
})
const keys = useMagicKeys({
passive: false,
onEventFired(e) {