diff --git a/packages/nc-gui/components/smartsheet/sidebar/MenuTop.vue b/packages/nc-gui/components/smartsheet/sidebar/MenuTop.vue index af114f3cf2..971d7dbadf 100644 --- a/packages/nc-gui/components/smartsheet/sidebar/MenuTop.vue +++ b/packages/nc-gui/components/smartsheet/sidebar/MenuTop.vue @@ -95,10 +95,12 @@ function onSortStart(evt: SortableEvent) { dragging = true } -async function onSortEnd(evt: SortableEvent) { - evt.stopImmediatePropagation() - evt.preventDefault() - dragging = false +async function onSortEnd(evt: SortableEvent, undo = false) { + if (!undo) { + evt.stopImmediatePropagation() + evt.preventDefault() + dragging = false + } if (views.length < 2) return @@ -106,6 +108,32 @@ async function onSortEnd(evt: SortableEvent) { if (newIndex === oldIndex) return + if (!undo) { + addUndo({ + redo: { + fn: async () => { + const ord = sortable.toArray() + const temp = ord.splice(oldIndex, 1) + ord.splice(newIndex, 0, temp[0]) + sortable.sort(ord) + await onSortEnd(evt, true) + }, + args: [], + }, + undo: { + fn: async () => { + const ord = sortable.toArray() + const temp = ord.splice(newIndex, 1) + ord.splice(oldIndex, 0, temp[0]) + sortable.sort(ord) + await onSortEnd({ ...evt, oldIndex: newIndex, newIndex: oldIndex }, true) + }, + args: [], + }, + scope: defineModelScope({ view: activeView.value }), + }) + } + const children = evt.to.children as unknown as HTMLLIElement[] const previousEl = children[newIndex - 1]