procedure TForm1.xre1KeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if (Key = 90) and (ssCtrl in Shift) then
begin
if MyUndoIdt < 1 then
MyUndoIdt:= MyDim;
if MyUndo[MyUndoIdt] <> nil then
begin
SendMessage(xre1.Handle, WM_SETREDRAW, 0, 0);
xre1.LoadFromStream(MyUndo[MyUndoIdt], rvynaAuto);
xre1.Format;
FreeAndNil(MyUndo[MyUndoIdt]);
xre1.SelStart:= MyUndoPos[MyUndoIdt];
MyUndoPos[MyUndoIdt]:= 0;
SendMessage(xre1.Handle, WM_SETREDRAW, 1, 0);
xre1.Invalidate;
Dec(MyUndoIdt);
end
end;
end;
I need to do that to do a my proper undo because I use MarkString function. With this function Undo (RichView) doesn't work correctly.
May be it would be better to use undoable version of sting marking procedure? (SearchText + ApplyStyleConversion)
It's slower, but can be undone without tricks.
And your code in OnKeyDown is not working? What's wrong with it?
Yes, it does not block the default processing of Ctrl+Z, but the default undo code will be executed after your code. After loading a file, an undo buffer is empty, so the default procedure should do nothing.
There will be a problem inside tables, as I mentioned before, but without tables it should work.
Well, you are right, undo and redo keys are processed without calling OnKeyDown. I agree, it's not good.
The beginning of TCustomRichViewEdit.KeyDown must be changed from
TRVEditRVData(RVData).PrepareForEdit;
if (Key=VK_RETURN) and (rvoDoNotWantReturns in EditorOptions) then
Key := 0;
if IsUndoShortcut(Shift, Key) then begin
Undo;
Key := 0;
end
else if IsRedoShortcut(Shift, Key) then begin
Redo;
Key := 0;
end;
if Key = 0 then
exit;
inherited KeyDown(Key, Shift);
if (Key=VK_RETURN) and (rvoDoNotWantReturns in EditorOptions) then begin
Key := 0;
exit;
end;
inherited KeyDown(Key, Shift);
if Key = 0 then
exit;
if IsUndoShortcut(Shift, Key) then begin
Undo;
Key := 0;
end
else if IsRedoShortcut(Shift, Key) then begin
Redo;
Key := 0;
end;