UndoRecorder

Swift

@objc(PSPDFUndoRecorder)
public protocol UndoRecorder : AnyObject

A type yielded by an undo controller that allows recording multiple undoable actions grouped as one undoable command.

PSPDF_EXPORT(PSPDFUndoRecorder)

  • Record actions of changing multiple properties of the given annotations by observing changes made to them in the scope of the given closure.

    recorder.record(changing: [freeTextAnnotation]) {
        freeTextAnnotation.fontSize = 32
        freeTextAnnotation.sizeToFit()
    }
    

    The above code will record two actions for freeTextAnnotation: one for fontAttributes, which changes as a result of setting fontSize, and one for boundingBox, which changes as result of calling sizeToFit().

    Precondition

    Recording new actions in an already committed recorder is not allowed and will result in an assertion failure.

    Precondition

    Each of the given annotations must already be referenced in a PDF document, otherwise they will be ignored.

    Declaration

    Swift

    @objc(recordChangingAnnotations:inScope:)
    func record(changing annotations: [Annotation], in scope: () -> Void)

    Parameters

    annotations

    Annotations expected to change.

    scope

    Closure in which annotations are changed.

  • Record actions of adding the given annotations to a document.

    recorder.record(adding: [lineAnnotation, circleAnnotation]) {
        document.add(annotations: [lineAnnotation, circleAnnotation])
    }
    

    The above code will record two actions: one for adding lineAnnotation and one for adding circleAnnotation.

    Precondition

    Recording new actions in an already committed recorder is not allowed and will result in an assertion failure.

    Declaration

    Swift

    @objc(recordAddingAnnotations:inScope:)
    func record(adding annotations: [Annotation], in scope: () -> Void)

    Parameters

    annotations

    Annotations expected to be added.

    scope

    Closure in which annotations are added to a document.

  • Record actions of removing the given annotations from a document.

    recorder.record(removing: [noteAnnotation, inkAnnotation]) {
        document.remove(annotations: [noteAnnotation, inkAnnotation])
    }
    

    The above code will record two actions: one for removing noteAnnotation and one for removing inkAnnotation.

    Precondition

    Recording new actions in an already committed recorder is not allowed and will result in an assertion failure.

    Declaration

    Swift

    @objc(recordRemovingAnnotations:inScope:)
    func record(removing annotations: [Annotation], in scope: () -> Void)

    Parameters

    annotations

    Annotations expected to be removed.

    scope

    Closure in which annotations are removed from a document.