trichview.com

trichview.support




Re: Autocompletion ?


Return to index


Author

Message

Sergey Tkachenko

Posted: 11/14/2003 18:50:44


Here is the simplest example. It changes 'ms$' to 'one of Bills products'

when you type 'ms$' and press one of characters listed in the Delimiters

property (more exactly, when you press this character to the right of

'ms$').


There is only one problem: wrong order of undo. Autocompletion occurs before

inserting the delimiter character, so this character is undone before the

autocompletion.

Is it acceptable for you?


procedure TForm3.RichViewEdit1KeyPress(Sender: TObject; var Key: Char);

var rve: TCustomRichViewEdit;

    ItemNo, WordEnd, WordStart: Integer;

    s: String;

    {..................................}

    function IsDelimiter(ch: Char): Boolean;

    begin

      Result := Pos(ch, RichViewEdit1.Delimiters)<>0;

    end;

    {..................................}

begin

  if not IsDelimiter(Key) then

    exit;

  rve := RichViewEdit1.TopLevelEditor;

  ItemNo := rve.CurItemNo;

  WordEnd := rve.OffsetInCurItem;

  if rve.GetItemStyle(ItemNo)<0 then

    exit;

  s := rve.GetItemTextA(ItemNo);

  WordStart := WordEnd;

  if WordStart<1 then

    exit;

  while (WordStart-1>0) and not IsDelimiter(s[WordStart-1]) do

    dec(WordStart);

  s := Copy(s, WordStart, WordEnd-WordStart);

  if s='ms$' then begin

    rve.SetSelectionBounds(ItemNo, WordStart, ItemNo, WordEnd);

    rve.InsertText('one of Bills products');

  end;

end;





Powered by ABC Amber Outlook Express Converter