trichview.com

trichview.support




Re: autocompletion like in OpenOffice


Return to index


Author

Message

Stef Mientki

Posted: 03/24/2005 3:09:08


hello Sergey,


I've realized the base of it, (it seems to work ;-)

but in these construction, I've always my doubts.


Could you please take a look at the code,

and tell me it's acceptable ?


I used one of your previous ideas for autocompletion.

When typing "Ric" this procedure shows "RichViewEdit",

with "hViewEdit" selected/highlighted.

When you now type a "RETURN", the word is substituted, followed by a space.


In OnKeyPress, I detect the string, and also using the just typed character.

When the string matches, I insert the extra text and highlight the extra

text. I also set a global flag "AutoCompletion_Flag".


Then in OnKeyDown, I detect the CR + AutoCompletion_Flag,

then deselect the highlighted text and insert an extra space.


thanks,

Stef Mientki


procedure TForm1.RVE_nameKeyPress(Sender: TObject; var Key: Char);

(*******************************************************************************

Autocompletion

******************************************************************************)

var

   RVE_top: TCustomRichViewEdit;

     ItemNo, WordEnd, WordStart: Integer;

     s: String;

const demo = 'hViewEdit';

begin

   RVE_top :=RVE.TopLevelEditor;

   ItemNo :=RVE_top.CurItemNo;

   WordEnd :=RVE_top.OffsetInCurItem;

   if RVE_top.GetItemStyle(ItemNo)<0 then exit;


   s :=RVE_top.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);


   //Compare the already typed word + the newly entered key

   if lowercase(s+key)='ric' then

   begin

     autocompletion_flag:=true;


     //make sure nothing is selected

     RVE_top.Deselect;


     //here I have to insert the last tuped character myself

     //and make key = 0

     RVE_top.InsertText('c'+demo);

     key:=#0;


     //set the added text as the selection

     RVE_top.SetSelectionBounds(ItemNo, WordEnd+1, ItemNo,

WordEnd+length(demo)+1);

     RVE_top.invalidate;

   end;

end;



procedure TForm1.RVE_nameKeyDown(Sender: TObject; var Key: Word;

   Shift: TShiftState);

(*******************************************************************************

******************************************************************************)

var

   RVE_top :TCustomRichViewEdit;

begin

   if (key=vk_return) and autocompletion_flag then

   begin

     RVE_top :=RVE.TopLevelEditor;

     RVE_top.Deselect;

     RVE_top.InsertText(' ');

     RVE_top.invalidate;

     key:=0;

   end;

   autocompletion_flag:=false;

end;





Powered by ABC Amber Outlook Express Converter