Snap-to-grid for moving/resizing canvas objects, plus a per-sheet grid size

Sheet.gridSize (4-200px, default 24, configurable in Settings -> Blatt)
now doubles as both the visible dot-grid's spacing and the snap
increment while dragging to move any canvas object, or free/viewport-
resizing a chart/text/button/fixed-viewport table. An "Automatisch"
table's resize is left unsnapped on top of this -- it already
discretizes to row/col boundaries by construction.

Also fixes the visible grid not actually lining up with real snap
positions once zoomed: the dot pattern's background-size now scales
with zoom like the objects themselves already did, instead of staying a
fixed screen-pixel size regardless of zoom level.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
wkh
2026-09-09 23:33:39 +02:00
co-authored by Claude Sonnet 5
parent 5f75b9c298
commit d0500fcaf5
8 changed files with 101 additions and 14 deletions
+8 -1
View File
@@ -75,7 +75,7 @@ import type {
TableView,
TextObject,
} from './types';
import { defaultTableView, DEFAULT_ROW_H } from './types';
import { defaultTableView, DEFAULT_ROW_H, MIN_GRID_SIZE, MAX_GRID_SIZE } from './types';
import { createSeedDocument } from '../data/seed';
import { validateDocument } from '../io/json';
@@ -855,6 +855,12 @@ function createStore() {
s.showGrid = show;
markDirty();
}
function setSheetGridSize(sheetId: string, size: number) {
const s = sheetById(sheetId);
if (!s) return;
s.gridSize = Math.round(Math.min(MAX_GRID_SIZE, Math.max(MIN_GRID_SIZE, size)));
markDirty();
}
function setSheetZoom(sheetId: string, z: number) {
const s = sheetById(sheetId);
if (!s) return;
@@ -2874,6 +2880,7 @@ function createStore() {
setSheetBackground,
setSheetForeground,
setSheetShowGrid,
setSheetGridSize,
setSheetZoom,
activeZoom,
setZoom,