diff --git a/event-manager.js b/event-manager.js index 6f5a2fe..7fb1c2e 100644 --- a/event-manager.js +++ b/event-manager.js @@ -331,7 +331,7 @@ export class EventManager { @@ -387,7 +387,24 @@ export class EventManager { this.hideEventDialog() }) - this.eventForm.querySelector('[data-action="cancel"]').addEventListener('click', () => { + this.eventForm.querySelector('[data-action="delete"]').addEventListener('click', () => { + if (this._dialogMode === 'edit' && this._editingEventId) { + // Find and remove the event from ALL dates it spans across + const datesToCleanup = [] + for (const [dateStr, eventList] of this.events) { + const eventIndex = eventList.findIndex(event => event.id === this._editingEventId) + if (eventIndex !== -1) { + eventList.splice(eventIndex, 1) + // Mark date for cleanup if empty + if (eventList.length === 0) { + datesToCleanup.push(dateStr) + } + } + } + // Clean up empty date entries + datesToCleanup.forEach(dateStr => this.events.delete(dateStr)) + this.calendar.forceUpdateVisibleWeeks() + } this.hideEventDialog() if (this._dialogMode === 'create') this.clearSelection() })