How to enable Tab key to indent bulleted lists?

General TRichView support forum. Please post your questions here
Post Reply
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

How to enable Tab key to indent bulleted lists?

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17291
Joined: Sat Aug 27, 2005 10:28 am
Contact:

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

Post 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;
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

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

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17291
Joined: Sat Aug 27, 2005 10:28 am
Contact:

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

Post 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;
edwinyzh
Posts: 104
Joined: Sun Jun 05, 2022 2:22 pm

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

Post by edwinyzh »

Thanks, now it works!
Post Reply