Skip to content

Commit 76bae91

Browse files
committed
fix: revert groupsByEvent=false — use default auto-grouping to avoid registration failures
1 parent 46a64a5 commit 76bae91

1 file changed

Lines changed: 11 additions & 18 deletions

File tree

TablePro/Core/ChangeTracking/DataChangeManager.swift

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,9 @@ final class DataChangeManager {
101101
private let undoManager: UndoManager = {
102102
let manager = UndoManager()
103103
manager.levelsOfUndo = 100
104-
manager.groupsByEvent = false
105104
return manager
106105
}()
107106

108-
private func registerUndoAction(_ handler: @escaping (DataChangeManager) -> Void) {
109-
undoManager.beginUndoGrouping()
110-
undoManager.registerUndo(withTarget: self, handler: handler)
111-
undoManager.endUndoGrouping()
112-
}
113-
114107
private var lastUndoResult: UndoResult?
115108

116109
// MARK: - Undo/Redo Properties
@@ -236,7 +229,7 @@ final class DataChangeManager {
236229
newValue: newValue
237230
))
238231
}
239-
registerUndoAction { target in
232+
undoManager.registerUndo(withTarget: self) { target in
240233
target.applyDataUndo(.cellEdit(
241234
rowIndex: rowIndex, columnIndex: columnIndex, columnName: columnName,
242235
previousValue: oldValue, newValue: newValue
@@ -291,7 +284,7 @@ final class DataChangeManager {
291284
changedRowIndices.insert(rowIndex)
292285
}
293286

294-
registerUndoAction { target in
287+
undoManager.registerUndo(withTarget: self) { target in
295288
target.applyDataUndo(.cellEdit(
296289
rowIndex: rowIndex, columnIndex: columnIndex, columnName: columnName,
297290
previousValue: oldValue, newValue: newValue
@@ -311,7 +304,7 @@ final class DataChangeManager {
311304
changeIndex[RowChangeKey(rowIndex: rowIndex, type: .delete)] = changes.count - 1
312305
deletedRowIndices.insert(rowIndex)
313306
changedRowIndices.insert(rowIndex)
314-
registerUndoAction { target in
307+
undoManager.registerUndo(withTarget: self) { target in
315308
target.applyDataUndo(.rowDeletion(rowIndex: rowIndex, originalRow: originalRow))
316309
}
317310
undoManager.setActionName(String(localized: "Delete Row"))
@@ -340,7 +333,7 @@ final class DataChangeManager {
340333
changedRowIndices.insert(rowIndex)
341334
batchData.append((rowIndex: rowIndex, originalRow: originalRow))
342335
}
343-
registerUndoAction { target in
336+
undoManager.registerUndo(withTarget: self) { target in
344337
target.applyDataUndo(.batchRowDeletion(rows: batchData))
345338
}
346339
undoManager.setActionName(String(localized: "Delete Rows"))
@@ -355,7 +348,7 @@ final class DataChangeManager {
355348
changeIndex[RowChangeKey(rowIndex: rowIndex, type: .insert)] = changes.count - 1
356349
insertedRowIndices.insert(rowIndex)
357350
changedRowIndices.insert(rowIndex)
358-
registerUndoAction { target in
351+
undoManager.registerUndo(withTarget: self) { target in
359352
target.applyDataUndo(.rowInsertion(rowIndex: rowIndex))
360353
}
361354
undoManager.setActionName(String(localized: "Insert Row"))
@@ -480,7 +473,7 @@ final class DataChangeManager {
480473
insertedRowData.removeValue(forKey: rowIndex)
481474
}
482475

483-
registerUndoAction { target in
476+
undoManager.registerUndo(withTarget: self) { target in
484477
target.applyDataUndo(.batchRowInsertion(rowIndices: validRows, rowValues: rowValues))
485478
}
486479
undoManager.setActionName(String(localized: "Insert Rows"))
@@ -510,7 +503,7 @@ final class DataChangeManager {
510503
private func applyDataUndo(_ action: UndoAction) {
511504
switch action {
512505
case .cellEdit(let rowIndex, let columnIndex, let columnName, let previousValue, let newValue):
513-
registerUndoAction { target in
506+
undoManager.registerUndo(withTarget: self) { target in
514507
target.applyDataUndo(.cellEdit(
515508
rowIndex: rowIndex, columnIndex: columnIndex, columnName: columnName,
516509
previousValue: newValue, newValue: previousValue
@@ -571,7 +564,7 @@ final class DataChangeManager {
571564

572565
case .rowInsertion(let rowIndex):
573566
let savedValues = insertedRowData[rowIndex]
574-
registerUndoAction { [savedValues] target in
567+
undoManager.registerUndo(withTarget: self) { [savedValues] target in
575568
if let savedValues {
576569
target.insertedRowData[rowIndex] = savedValues
577570
}
@@ -610,7 +603,7 @@ final class DataChangeManager {
610603
}
611604

612605
case .rowDeletion(let rowIndex, let originalRow):
613-
registerUndoAction { target in
606+
undoManager.registerUndo(withTarget: self) { target in
614607
target.applyDataUndo(.rowDeletion(rowIndex: rowIndex, originalRow: originalRow))
615608
}
616609
undoManager.setActionName(String(localized: "Delete Row"))
@@ -630,7 +623,7 @@ final class DataChangeManager {
630623
}
631624

632625
case .batchRowDeletion(let rows):
633-
registerUndoAction { target in
626+
undoManager.registerUndo(withTarget: self) { target in
634627
target.applyDataUndo(.batchRowDeletion(rows: rows))
635628
}
636629
undoManager.setActionName(String(localized: "Delete Rows"))
@@ -655,7 +648,7 @@ final class DataChangeManager {
655648
}
656649

657650
case .batchRowInsertion(let rowIndices, let rowValues):
658-
registerUndoAction { target in
651+
undoManager.registerUndo(withTarget: self) { target in
659652
target.applyDataUndo(.batchRowInsertion(rowIndices: rowIndices, rowValues: rowValues))
660653
}
661654
undoManager.setActionName(String(localized: "Insert Rows"))

0 commit comments

Comments
 (0)