Page 1 of 1

How to enable Tab key to indent bulleted lists?

Posted: Sun Jun 26, 2022 11:07 am
by edwinyzh
Take the RichViewActions demo as an example, I expected that pressing TAB will indent the entire list item, but it's not, it indents the texts after the bullet points instead.

How to use [Tab]/[Shift -Tab] to indent/outdent an entire list item line, like that in MS Word?

Thanks.

Re: How to enable Tab key to indent bulleted lists?

Posted: Sun Jun 26, 2022 12:12 pm
by Sergey Tkachenko
More exactly, MS Word increases/decreases list level.
You can do it by including the following code in TRichViewEdit.OnKeyDown:

Code: Select all

procedure TForm3.RichViewEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  rve: TCustomRichViewEdit;
begin
  rve := (Sender as TCustomRichViewEdit).TopLevelEditor;
  if (Key = VK_TAB) and not (ssCtrl in Shift) and
    not rve.SelectionExists and
    (rve.CurItemNo > 0) and
    (rve.OffsetInCurItem = rve.GetOffsBeforeItem(rve.CurItemNo)) and
    (rve.GetItemStyle(rve.CurItemNo - 1) = rvsListMarker)
  then
  begin
    if ssShift in Shift then
      rve.ChangeListLevels(-1)
    else
      rve.ChangeListLevels(1);
    Key := 0;
    Include(rve.RVData.State, rvstIgnoreNextChar);
  end;
end;

Re: How to enable Tab key to indent bulleted lists?

Posted: Sun Jun 26, 2022 3:52 pm
by edwinyzh
Sergey, Thanks!

With the code you provided the TAB/Shift+TAB work, but I can no longer input any character after that, I believe it has something to do with the code:

Code: Select all

Include(rve.RVData.State, rvstIgnoreNextChar)
Any advises? Thanks again.

Re: How to enable Tab key to indent bulleted lists?

Posted: Sun Jun 26, 2022 4:31 pm
by Sergey Tkachenko
You are right, sorry.

Instead, add a variable to the form
IgnoreNextTab: Boolean;

OnKeyDown:

Code: Select all

procedure TForm3.RichViewEdit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var
  rve: TCustomRichViewEdit;
begin
  rve := (Sender as TCustomRichViewEdit).TopLevelEditor;
  if (Key = VK_TAB) and not (ssCtrl in Shift) and
    not rve.SelectionExists and
    (rve.CurItemNo > 0) and
    (rve.OffsetInCurItem = rve.GetOffsBeforeItem(rve.CurItemNo)) and
    (rve.GetItemStyle(rve.CurItemNo - 1) = rvsListMarker)
    then
  begin
    if ssShift in Shift then
      rve.ChangeListLevels(-1)
    else
      rve.ChangeListLevels(1);
    Key := 0;
    IgnoreNextTab := True;
  end;
end;
OnKeyPress:

Code: Select all

procedure TForm3.RichViewEdit1KeyPress(Sender: TObject; var Key: Char);
begin
  if IgnoreNextTab then
  begin
    IgnoreNextTab := False;
    if Key = #9 then
      Key := #0;
    exit;
  end;
end;

Re: How to enable Tab key to indent bulleted lists?

Posted: Mon Jun 27, 2022 2:41 am
by edwinyzh
Thanks, now it works!