File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -73,16 +73,24 @@ public extension NSTableView {
7373 removeRows ( at: IndexSet ( changeset. elementDeleted. map { $0. element } ) , withAnimation: deleteRowsAnimation ( ) )
7474 }
7575
76- if !changeset. elementInserted. isEmpty {
77- insertRows ( at: IndexSet ( changeset. elementInserted. map { $0. element } ) , withAnimation: insertRowsAnimation ( ) )
78- }
79-
8076 if !changeset. elementUpdated. isEmpty {
8177 reloadData ( forRowIndexes: IndexSet ( changeset. elementUpdated. map { $0. element } ) , columnIndexes: IndexSet ( 0 ..< tableColumns. count) )
8278 }
8379
84- for (source, target) in changeset. elementMoved {
85- moveRow ( at: source. element, to: target. element)
80+ if !changeset. elementMoved. isEmpty {
81+ let insertionIndices = IndexSet ( changeset. elementInserted. map { $0. element } )
82+ var movedSourceIndices = IndexSet ( )
83+
84+ for (source, target) in changeset. elementMoved {
85+ let sourceElementOffset = movedSourceIndices. count ( in: source. element... )
86+ let targetElementOffset = insertionIndices. count ( in: 0 ..< target. element)
87+ moveRow ( at: source. element + sourceElementOffset, to: target. element - targetElementOffset)
88+ movedSourceIndices. insert ( source. element)
89+ }
90+ }
91+
92+ if !changeset. elementInserted. isEmpty {
93+ insertRows ( at: IndexSet ( changeset. elementInserted. map { $0. element } ) , withAnimation: insertRowsAnimation ( ) )
8694 }
8795
8896 endUpdates ( )
You can’t perform that action at this time.
0 commit comments