Undo a block of operations

  • Hi,

    i want to modify a couple of aspects in a text (fonts, font sizes, some text modifications) and want to undo them all together with one undo call.

    I have tried:

    WPUndostack.StartUndoLevel;
    [modify the text]
    WPUndostack.EndUndoLevel;

    But when i press "Undo" all operations are undone step by step (they should be undone at once)

    After that i have tried to use:

    WPUndostack.StartUndoLevel;
    strm := WPUndoStack.SaveStream(false, nil, nil, nil, -1, true);
    WPrichText.SaveToStream(strm);
    [modify the text]
    WPUndostack.EndUndoLevel;

    In the Undo event i reload the content from the given stream.

    Now the operations are undone step by step and then when the undostack reaches the stream i saved teh wholöe text is replaced by the previous version (as it should by the first undo)

    The "operations" include: modify the selected text content, replacing some fonts, setting some font sizes and colors. Sometime the text may be replaced completely using "WPRichText.Text := 'some text'". Maybe that causes the problems with the undostack?

    How can i group these operations to one undo step??
    (StartUndoLevel/EndUndoLevel are not working as expected)

    Using V4.25 in Delphi 2005 Enterprise

    Thanks in advance,
    Ralf

    • Offizieller Beitrag

    the checkpoints could help:

    // Save a checkpoint, Makes it possible to undo all opertions until this checkpoint
    function SaveCheckpoint(const Title: string): Integer;

    // undoes all actions until the mentioned checkpoint is found
    function UndoToCheckpoint(CheckpointNr: Integer): Boolean;