Skip to content

Commit b396dfe

Browse files
committed
fix: address review issues in NSUndoManager migration
- Fix primaryKeyChange undo closure capturing stale workingPrimaryKey - Fix batch insertion undo leaking insertedRowData entries - Clear undo history in loadSchema to prevent stale actions on table switch - Make undoManager private to prevent bypass of lastUndoResult contract
1 parent 7110b84 commit b396dfe

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

TablePro/Core/ChangeTracking/DataChangeManager.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ final class DataChangeManager {
9898
return lo
9999
}
100100

101-
let undoManager: UndoManager = {
101+
private let undoManager: UndoManager = {
102102
let manager = UndoManager()
103103
manager.levelsOfUndo = 100
104104
manager.groupsByEvent = false
@@ -606,6 +606,7 @@ final class DataChangeManager {
606606
for rowIndex in rowIndices {
607607
removeChangeByKey(rowIndex: rowIndex, type: .insert)
608608
insertedRowIndices.remove(rowIndex)
609+
insertedRowData.removeValue(forKey: rowIndex)
609610
changedRowIndices.insert(rowIndex)
610611
}
611612
lastUndoResult = UndoResult(

TablePro/Core/SchemaTracking/StructureChangeManager.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ final class StructureChangeManager {
9696
// Reset working state
9797
resetWorkingState()
9898

99-
// Clear changes
99+
// Clear changes and undo history
100100
pendingChanges.removeAll()
101101
validationErrors.removeAll()
102+
undoManager.removeAllActions()
102103
hasChanges = false
103104

104105
// Increment reloadVersion to trigger DataGridView column width recalculation
@@ -673,8 +674,9 @@ final class StructureChangeManager {
673674
}
674675

675676
case .primaryKeyChange(let old, _):
677+
let current = workingPrimaryKey
676678
undoManager.registerUndo(withTarget: self) { target in
677-
target.applySchemaUndo(.primaryKeyChange(old: self.workingPrimaryKey, new: old))
679+
target.applySchemaUndo(.primaryKeyChange(old: current, new: old))
678680
}
679681
undoManager.setActionName(String(localized: "Change Primary Key"))
680682
workingPrimaryKey = old

0 commit comments

Comments
 (0)