@@ -86,16 +86,24 @@ public extension NSTableView {
8686 removeRows ( at: IndexSet ( changeset. elementDeleted. map { $0. element } ) , withAnimation: deleteRowsAnimation ( ) )
8787 }
8888
89- if !changeset. elementInserted . isEmpty {
90- insertRows ( at : IndexSet ( changeset. elementInserted . map { $0. element } ) , withAnimation : insertRowsAnimation ( ) )
89+ if !changeset. elementUpdated . isEmpty {
90+ reloadData ( forRowIndexes : IndexSet ( changeset. elementUpdated . map { $0. element } ) , columnIndexes : IndexSet ( 0 ..< tableColumns . count ) )
9191 }
9292
93- if !changeset. elementUpdated. isEmpty {
94- reloadData ( forRowIndexes: IndexSet ( changeset. elementUpdated. map { $0. element } ) , columnIndexes: IndexSet ( changeset. elementUpdated. map { $0. section } ) )
93+ if !changeset. elementMoved. isEmpty {
94+ let insertionIndices = IndexSet ( changeset. elementInserted. map { $0. element } )
95+ var movedSourceIndices = IndexSet ( )
96+
97+ for (source, target) in changeset. elementMoved {
98+ let sourceElementOffset = movedSourceIndices. count ( in: source. element... )
99+ let targetElementOffset = insertionIndices. count ( in: 0 ..< target. element)
100+ moveRow ( at: source. element + sourceElementOffset, to: target. element - targetElementOffset)
101+ movedSourceIndices. insert ( source. element)
102+ }
95103 }
96104
97- for (source , target ) in changeset. elementMoved {
98- moveRow ( at: source . element, to : target . element )
105+ if ! changeset. elementInserted . isEmpty {
106+ insertRows ( at: IndexSet ( changeset . elementInserted . map { $0 . element } ) , withAnimation : insertRowsAnimation ( ) )
99107 }
100108
101109 endUpdates ( )
0 commit comments