Page 1 of 1

Ctrl+A

Posted: Tue Mar 14, 2017 3:09 am
by larshgf
Is it possible in TRichViewEdit programmatically (by code) to select all text by Ctrl+A ?

Re: Ctrl+A

Posted: Tue Mar 14, 2017 9:28 am
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.