mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-08-17 12:42:15 +01:00
Use nearest-grid snapping for event resize
This commit is contained in:
@@ -441,6 +441,13 @@ function snapEndToGrid(time: Dayjs, snapMinutes: number): Dayjs {
|
|||||||
return time.startOf('day').add(snapped, 'minute');
|
return time.startOf('day').add(snapped, 'minute');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Snap a dayjs time to the nearest snap boundary (for resize)
|
||||||
|
function snapToNearestGrid(time: Dayjs, snapMinutes: number): Dayjs {
|
||||||
|
const minutes = time.hour() * 60 + time.minute();
|
||||||
|
const snapped = Math.round(minutes / snapMinutes) * snapMinutes;
|
||||||
|
return time.startOf('day').add(snapped, 'minute');
|
||||||
|
}
|
||||||
|
|
||||||
// --- Visual snap (composable) ---
|
// --- Visual snap (composable) ---
|
||||||
const {
|
const {
|
||||||
startDragSnap: startVisualDragSnap,
|
startDragSnap: startVisualDragSnap,
|
||||||
@@ -503,9 +510,11 @@ async function handleEventResize(arg: EventChangeArg) {
|
|||||||
|
|
||||||
const startChanged = !newStartLocal.isSame(origStartLocal, 'minute');
|
const startChanged = !newStartLocal.isSame(origStartLocal, 'minute');
|
||||||
|
|
||||||
// Snap only the changed edge once, reuse for both setDates and API update
|
// Snap only the changed edge once, reuse for both setDates and API update.
|
||||||
const snappedStart = startChanged ? snapStartToGrid(newStartLocal, snap) : null;
|
// Use Math.round (snapToNearestGrid) to match the visual snap during resize.
|
||||||
const snappedEnd = !startChanged && !ext.isRunning ? snapEndToGrid(newEndLocal, snap) : null;
|
const snappedStart = startChanged ? snapToNearestGrid(newStartLocal, snap) : null;
|
||||||
|
const snappedEnd =
|
||||||
|
!startChanged && !ext.isRunning ? snapToNearestGrid(newEndLocal, snap) : null;
|
||||||
|
|
||||||
// Set FC event to snapped position immediately to avoid flash.
|
// Set FC event to snapped position immediately to avoid flash.
|
||||||
// Use the original event date for the edge that wasn't resized.
|
// Use the original event date for the edge that wasn't resized.
|
||||||
|
|||||||
@@ -159,12 +159,12 @@ export function useVisualSnap({
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (resizeEdge === 'bottom') {
|
if (resizeEdge === 'bottom') {
|
||||||
const snappedEnd = Math.ceil(endPos / snapPx) * snapPx;
|
const snappedEnd = Math.round(endPos / snapPx) * snapPx;
|
||||||
const clampedEnd = Math.max(top + snapPx, snappedEnd);
|
const clampedEnd = Math.max(top + snapPx, snappedEnd);
|
||||||
harness.style.bottom = -clampedEnd + 'px';
|
harness.style.bottom = -clampedEnd + 'px';
|
||||||
if (mirror) updateMirrorDurationLabel(mirror, top, clampedEnd, snapPx);
|
if (mirror) updateMirrorDurationLabel(mirror, top, clampedEnd, snapPx);
|
||||||
} else if (resizeEdge === 'top') {
|
} else if (resizeEdge === 'top') {
|
||||||
const snappedTop = Math.floor(top / snapPx) * snapPx;
|
const snappedTop = Math.round(top / snapPx) * snapPx;
|
||||||
const clampedTop = Math.min(endPos - snapPx, snappedTop);
|
const clampedTop = Math.min(endPos - snapPx, snappedTop);
|
||||||
harness.style.top = clampedTop + 'px';
|
harness.style.top = clampedTop + 'px';
|
||||||
if (mirror) updateMirrorDurationLabel(mirror, clampedTop, endPos, snapPx);
|
if (mirror) updateMirrorDurationLabel(mirror, clampedTop, endPos, snapPx);
|
||||||
|
|||||||
Reference in New Issue
Block a user