History

Undo/redo history via JSON Patch (RFC 6902) diffs.

Stores minimal diffs between project states rather than full snapshots, making history memory-efficient even for large projects.

Usage:

project = load_project(path)

with project.track_changes("add intro clip"):
    track.add_clip(...)
    clip.add_drop_shadow()

project.undo()   # reverts the block
project.redo()   # re-applies it
project.history  # list of change descriptions
class camtasia.history.ChangeRecord(description, forward_patch, inverse_patch)[source]

Bases: object

A single recorded change with forward and inverse patches.

description: str
forward_patch: JsonPatch
inverse_patch: JsonPatch
class camtasia.history.ChangeHistory(max_history_depth=100)[source]

Bases: object

Manages an undo/redo stack of JSON Patch diffs.

Each entry stores the minimal diff needed to move between states, not a full copy of the project data.

property max_history_depth: int

Maximum number of undo entries retained.

property can_undo: bool

Whether there are changes available to undo.

property can_redo: bool

Whether there are changes available to redo.

property undo_count: int

Number of changes on the undo stack.

property redo_count: int

Number of changes on the redo stack.

property descriptions: list[str]

Descriptions of all recorded changes (oldest first).

record(description, snapshot_before, snapshot_after)[source]

Record a change by diffing before/after snapshots.

Return type:

None

undo(project_data)[source]

Apply the most recent inverse patch. Returns the description.

Return type:

str

redo(project_data)[source]

Re-apply the most recently undone patch. Returns the description.

Return type:

str

clear()[source]

Discard all history.

Return type:

None

property total_patch_size_bytes: int

Approximate memory usage of stored patches in bytes.

to_json()[source]

Serialize history to JSON string for persistence.

Return type:

str

classmethod from_json(json_string)[source]

Deserialize history from JSON string.

Return type:

ChangeHistory

camtasia.history.with_undo(description)[source]

Decorator that wraps a function call in track_changes.

Return type:

Callable