Much simpler undo/redo handling, bugs fixed and less code.
This commit is contained in:
@@ -314,7 +314,46 @@ function startLocalDrag(init, evt) {
|
||||
realizedId: null,
|
||||
}
|
||||
|
||||
store.$history?.beginCompound()
|
||||
// If history is empty (no baseline), create a baseline snapshot BEFORE any movement mutations
|
||||
try {
|
||||
const isResize = init.mode === 'resize-left' || init.mode === 'resize-right'
|
||||
// Move: only baseline if history empty. Resize: force baseline (so undo returns to pre-resize) but only once.
|
||||
store.$history?._baselineIfNeeded?.(isResize)
|
||||
const evs = []
|
||||
if (store.events instanceof Map) {
|
||||
for (const [id, ev] of store.events) {
|
||||
evs.push({
|
||||
id,
|
||||
start: ev.startDate,
|
||||
days: ev.days,
|
||||
title: ev.title,
|
||||
color: ev.colorId,
|
||||
recur: ev.recur
|
||||
? {
|
||||
f: ev.recur.freq,
|
||||
i: ev.recur.interval,
|
||||
c: ev.recur.count,
|
||||
w: Array.isArray(ev.recur.weekdays) ? ev.recur.weekdays.join('') : null,
|
||||
}
|
||||
: null,
|
||||
})
|
||||
}
|
||||
}
|
||||
console.debug(
|
||||
isResize ? '[history] pre-resize baseline snapshot' : '[history] pre-drag baseline snapshot',
|
||||
{
|
||||
mode: init.mode,
|
||||
events: evs,
|
||||
weekend: store.weekend,
|
||||
firstDay: store.config?.first_day,
|
||||
},
|
||||
)
|
||||
} catch {}
|
||||
|
||||
// Enter drag suppression (prevent intermediate pushes)
|
||||
try {
|
||||
store.$history?._beginDrag?.()
|
||||
} catch {}
|
||||
|
||||
if (evt.currentTarget && evt.pointerId !== undefined) {
|
||||
try {
|
||||
@@ -453,7 +492,10 @@ function onDragPointerUp(e) {
|
||||
justDragged.value = false
|
||||
}, 120)
|
||||
}
|
||||
store.$history?.endCompound()
|
||||
// End drag suppression regardless; no post snapshot (pre-only model)
|
||||
try {
|
||||
store.$history?._endDrag?.()
|
||||
} catch {}
|
||||
}
|
||||
|
||||
const min = (a, b) => (a < b ? a : b)
|
||||
|
||||
Reference in New Issue
Block a user