WPCubed Product Support

How to add changes made by code to the undo stack?

Thank you very much! We are using 9.4 Premium.

I enabled the option, but I can't see any difference. The behavior is still the same. I can undo the changes made by code, but redo isn't working.

Also, aside from that, I noticed when entering some random text and line breaks manually in the WP edit field like ...

flkasdjfasdf
ioeruoiewrewr
fasdfsadf

... and then use the Undo / Redo function, it doesn't work properly. The undo seems to work, but redo doesn't work.

Also when manually creating a table via the WPToolbar "Create Table" icon, let's say 1 row and 5 columns and then use undo, it doesn't seem to work either. When I click undo until the button stays disabled, I end up with a table with 1 column and 5 rows. This also happens in the WPToolsDemo.exe that is shipped with the installation: Insert a table at the bottom of the text, 1 row, 5 columns, press Ctrl + Z to undo.

#3 ♥ 0
1.7k Views 2 users 1 ♥ read 2 min
wpsupport

With the latest version 9.4 you can use this

WPRichText1.ClipboardOptionsEx :=
WPRichText1.ClipboardOptionsEx + [ wpcoUndoModeIsSaveAsStream ];

I recommend to use that if you deal with tables.

Which version do you use?

#2 ♥ 1

I'm inserting content into the WPRichText control via code. For instance a table with one row and two columns and each column contains some text.

This does not trigger the undo functions. But I want that the user is able to undo / redo the changes made by the code.

I've been playing around with StartUndolevel / EndUndoLevel aswell as UndoSaveState / UndoRestoreState but it is not really working 100%.

In the WPCTRMemo code you write:

{:: Starts a new undo level.
    Before extensive changes to the text you should better use
    UndoSaveState. Call UndoRestoreState when you done with the changes, }
procedure StartUndolevel;

So this is what I did:

procedure TForm1.InsertContent;
begin
  WP.StartUndoLevel;
  WP.UndoSaveState;
  try
    // ... Insert table, append row, append cells, set text for each cell.
  finally
    WP.UndoRestoreState;
    WP.EndUndoLevel;
  end;
end;

In the WPToolbar I can see that after calling InsertContent the Undo icon becomes active. When I click Undo the changes are indeed undone and the Redo icon becomes active. But when I click Redo nothing happens, except that the Undo icon becomes active again. But the undone changes are not restored.

What am I doing wrong? Could you please give me advice on how to do that correctly?

#1 ♥ 0