OK
This commit is contained in:
@@ -125,9 +125,56 @@
|
||||
function handleDragOver(e: DragEvent) {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
function handleKeyDown(e: KeyboardEvent) {
|
||||
if (state.editingId || state.editingGlobal) return;
|
||||
if (state.focusedId) return;
|
||||
const tag = (e.target as HTMLElement)?.tagName;
|
||||
if (tag === 'INPUT' || tag === 'TEXTAREA') return;
|
||||
if ((e.target as HTMLElement)?.isContentEditable) return;
|
||||
|
||||
const mod = e.metaKey || e.ctrlKey;
|
||||
const rect = container.getBoundingClientRect();
|
||||
const centerX = (rect.width / 2 - state.viewport.x) / state.viewport.zoom;
|
||||
const centerY = (rect.height / 2 - state.viewport.y) / state.viewport.zoom;
|
||||
|
||||
if (mod && e.key === 'c' && state.selectedId) {
|
||||
e.preventDefault();
|
||||
state.copyItem(state.selectedId);
|
||||
} else if (mod && e.key === 'v') {
|
||||
e.preventDefault();
|
||||
const newId = state.pasteItem(centerX, centerY);
|
||||
if (newId) state.select(newId);
|
||||
} else if (mod && e.key === 'd' && state.selectedId) {
|
||||
e.preventDefault();
|
||||
const newId = state.duplicateItem(state.selectedId, centerX, centerY);
|
||||
if (newId) state.select(newId);
|
||||
} else if (e.key === 'Escape') {
|
||||
state.select(null);
|
||||
state.focus(null);
|
||||
} else if (e.key === '[' && state.selectedId) {
|
||||
e.preventDefault();
|
||||
state.sendBackward(state.selectedId);
|
||||
} else if (e.key === ']' && state.selectedId) {
|
||||
e.preventDefault();
|
||||
state.bringForward(state.selectedId);
|
||||
} else if (e.key.startsWith('Arrow') && state.selectedId) {
|
||||
e.preventDefault();
|
||||
const step = e.shiftKey ? 10 : 1;
|
||||
const item = state.getItem(state.selectedId);
|
||||
if (!item) return;
|
||||
const dx = e.key === 'ArrowLeft' ? -step : e.key === 'ArrowRight' ? step : 0;
|
||||
const dy = e.key === 'ArrowUp' ? -step : e.key === 'ArrowDown' ? step : 0;
|
||||
state.updateItem(state.selectedId, { x: item.x + dx, y: item.y + dy });
|
||||
} else if (e.key === 'e' && state.selectedId && !mod) {
|
||||
e.preventDefault();
|
||||
state.focus(state.selectedId);
|
||||
state.edit(state.selectedId);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:window onmouseup={handleMouseUp} onmousemove={handleMouseMove} />
|
||||
<svelte:window onmouseup={handleMouseUp} onmousemove={handleMouseMove} onkeydown={handleKeyDown} />
|
||||
|
||||
<!-- svelte-ignore a11y_no_static_element_interactions -->
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user