Ctrl+A

General TRichView support forum. Please post your questions here
Post Reply
larshgf
Posts: 20
Joined: Fri Jan 20, 2017 9:35 am

Ctrl+A

Post by larshgf »

Is it possible in TRichViewEdit programmatically (by code) to select all text by Ctrl+A ?
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Ctrl+A

Post by Sergey Tkachenko »

If you use RichViewActions, there is TrvActionSelectAll, it has Ctrl+A shortcut by default.
If you do not use RichViewActions, you can use the standard action TEditSelectAll.

Or you can create a menu item or a toolbar button, assign its ShortCut = Ctrl+A, and call in OnClick:

Code: Select all

rve.SelectAll;
rve.Invalidate;
It's also possible to implement it in OnKeyDown, but it is more difficult.
The simplest code is

Code: Select all

procedure TForm3.RichViewEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (ssCtrl in Shift) and (Key = ord('A')) then
  begin
    (Sender as TCustomRichViewEdit).SelectAll;
    (Sender as TCustomRichViewEdit).Invalidate;
  end;
end;
But when called when the caret is in a table cell, it selects this cell, not the full editor.
It's also possible to select the whole editor from OnKeyDown, but it's more difficult (the problem of destroying cell inplace editor in OnKeyDown). I can explain a workaround, but I recommend using other methods listed above.
Post Reply