Skip to content

Commit

Permalink
Improve transformed annotation removal
Browse files Browse the repository at this point in the history
  • Loading branch information
mvasilak committed Jun 27, 2024
1 parent 94cbde2 commit b60b184
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1408,8 +1408,13 @@ final class PDFReaderActionHandler: ViewModelActionHandler, BackgroundDbProcessi
}
undoManager.enableUndoRegistration()
undoController.recordCommand(named: nil, adding: finalAnnotations) {
// Remove may be superfluous, if those annotations are already removed by the undo, but it doesn't cause any issue.
document.remove(annotations: toRemove, options: [.suppressNotifications: true])
// Remove may be superfluous, if those annotations are already removed by the undo.
// Annotations are filtered, so only those that still need to are removed, to avoid an edge case where undocumented PSPDFKit expection
// "The removed annotation does not belong to the current document" is thrown.
let needRemove = toRemove.compactMap { document.annotation(on: Int($0.pageIndex), with: $0.key ?? $0.uuid) }
if !needRemove.isEmpty {
document.remove(annotations: needRemove, options: [.suppressNotifications: true])
}
// Transformed annotations need to be added, before they are converted, otherwise their document property is nil.
document.add(annotations: finalAnnotations, options: [.suppressNotifications: true])
}
Expand Down

0 comments on commit b60b184

Please sign in to comment.