Fix splitting of events where repeats are reduced to 1.

This commit is contained in:
Leo Vasanko 2025-08-25 21:23:32 -06:00
parent 467a984955
commit b69a299309
2 changed files with 45 additions and 1 deletions

View File

@ -302,7 +302,9 @@ function onDragPointerMove(e) {
} else if (st.isVirtual && (st.mode === 'resize-left' || st.mode === 'resize-right')) {
// For virtual occurrence resize: convert to real once, then adjust range
if (!st.realizedId) {
const newId = store.splitMoveVirtualOccurrence(st.id, st.startDate, st.startDate, st.endDate)
const initialStart = ns
const initialEnd = ne
const newId = store.splitMoveVirtualOccurrence(st.id, st.startDate, initialStart, initialEnd)
if (newId) {
st.realizedId = newId
st.id = newId

View File

@ -309,6 +309,22 @@ export const useCalendarStore = defineStore('calendar', {
const originalCountRaw = base.repeatCount
const occurrenceDate = fromLocalString(occurrenceDateStr, DEFAULT_TZ)
const baseStart = fromLocalString(base.startDate, DEFAULT_TZ)
// If series effectively has <=1 occurrence, treat as simple move (no split) and flatten
let totalOccurrences = Infinity
if (originalCountRaw !== 'unlimited') {
const parsed = parseInt(originalCountRaw, 10)
if (!isNaN(parsed)) totalOccurrences = parsed
}
if (totalOccurrences <= 1) {
// Flatten to non-repeating if not already
if (base.isRepeating) {
base.repeat = 'none'
base.isRepeating = false
this.events.set(baseId, { ...base })
}
this.setEventRange(baseId, newStartStr, newEndStr, { mode: 'move', rotatePattern: true })
return baseId
}
if (occurrenceDate <= baseStart) {
this.setEventRange(baseId, newStartStr, newEndStr, { mode: 'move' })
return baseId
@ -341,6 +357,11 @@ export const useCalendarStore = defineStore('calendar', {
return
}
this._terminateRepeatSeriesAtIndex(baseId, keptOccurrences)
// After truncation compute base kept count
const truncated = this.events.get(baseId)
if (truncated && truncated.repeatCount && truncated.repeatCount !== 'unlimited') {
// keptOccurrences already reflects number before split; adjust not needed further
}
let remainingCount = 'unlimited'
if (originalCountRaw !== 'unlimited') {
const total = parseInt(originalCountRaw, 10)
@ -369,6 +390,27 @@ export const useCalendarStore = defineStore('calendar', {
repeatCount: remainingCount,
repeatWeekdays,
})
// Flatten base if single occurrence now
if (truncated && truncated.isRepeating) {
const baseCountNum =
truncated.repeatCount === 'unlimited' ? Infinity : parseInt(truncated.repeatCount, 10)
if (baseCountNum <= 1) {
truncated.repeat = 'none'
truncated.isRepeating = false
this.events.set(baseId, { ...truncated })
}
}
// Flatten new if single occurrence only
const newly = this.events.get(newId)
if (newly && newly.isRepeating) {
const newCountNum =
newly.repeatCount === 'unlimited' ? Infinity : parseInt(newly.repeatCount, 10)
if (newCountNum <= 1) {
newly.repeat = 'none'
newly.isRepeating = false
this.events.set(newId, { ...newly })
}
}
this.notifyEventsChanged()
return newId
},