Browse Source

feat: undo/redo for view reorder

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/5332/head
mertmit 1 year ago
parent
commit
1e87d877b5
  1. 36
      packages/nc-gui/components/smartsheet/sidebar/MenuTop.vue

36
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]

Loading…
Cancel
Save