From 7a62ef7040f4025ef2c16d9da16d6b53e077e27c Mon Sep 17 00:00:00 2001 From: "Janus C. H. Knudsen" Date: Wed, 8 Oct 2025 19:05:09 +0200 Subject: [PATCH] Snaps event resize to grid interval Ensures that when resizing an event, the end time snaps to the defined grid interval, providing a more consistent user experience. --- src/elements/SwpEventElement.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/elements/SwpEventElement.ts b/src/elements/SwpEventElement.ts index 5dc5367..60d27c3 100644 --- a/src/elements/SwpEventElement.ts +++ b/src/elements/SwpEventElement.ts @@ -136,16 +136,19 @@ export class SwpEventElement extends BaseSwpEventElement { // 2. Calculate new end time based on height const gridSettings = calendarConfig.getGridSettings(); - const { hourHeight } = gridSettings; + const { hourHeight, snapInterval } = gridSettings; // Get current start time const start = this.start; // Calculate duration from height - const durationMinutes = (newHeight / hourHeight) * 60; + const rawDurationMinutes = (newHeight / hourHeight) * 60; - // Calculate new end time by adding duration to start (using DateService for timezone safety) - const endDate = this.dateService.addMinutes(start, durationMinutes); + // Snap duration to grid interval (like drag & drop) + const snappedDurationMinutes = Math.round(rawDurationMinutes / snapInterval) * snapInterval; + + // Calculate new end time by adding snapped duration to start (using DateService for timezone safety) + const endDate = this.dateService.addMinutes(start, snappedDurationMinutes); // 3. Update end attribute (triggers attributeChangedCallback → updateDisplay) this.end = endDate;