Recent

Author Topic: How TSynEdit achieves automatic completion  (Read 827 times)

myisjwj

  • Jr. Member
  • **
  • Posts: 92
How TSynEdit achieves automatic completion
« on: August 03, 2023, 05:17:30 am »
For example, using TSynEdit, TSynHTMLSyn, and TSynCompletion requires adding the Html keyword to the itemlist of TSynCompletion to automatically complete. Can keywords be extracted from TSynHTMLSyn and added to the itemlist, or can TSynHTMLSyn be used for automatic completion.

Edson

  • Hero Member
  • *****
  • Posts: 1327
Re: How TSynEdit achieves automatic completion
« Reply #1 on: August 03, 2023, 05:36:09 pm »
Completion and Highlighting are two separated features in SynEdit. They are implemented in separated controls and you have to program them independently.

You could use https://github.com/t-edson/SynFacilCompletion that is a Highlighter and Completion tool where you can reuse Keywords for completion list too. However using SynFacilCompletion means you cannot use other Highlighter like TSynHTMLSyn. You would have to implement the highlighter too in SynFacilCompletion, and I don't know if it can be as successful for HTML like TSynHTMLSyn is.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

myisjwj

  • Jr. Member
  • **
  • Posts: 92
Re: How TSynEdit achieves automatic completion
« Reply #2 on: August 04, 2023, 04:54:39 am »
I have written a program myself that can prompt.
Code: Pascal  [Select][+][-]
  1. Var
  2.  
  3. KWList: TStringList;
  4.  
  5. AllStL: Integer;
  6.  
  7.  
  8. KWList:=TStringList. Create;
  9.  
  10. KWList. LoadFromFile ('htmlKeyWord. txt ');
  11.  
  12.  
  13.  
  14. Procedure TForm1. SynCompletion1BeforeExecute (ASender: TSynBaseCompletion;
  15.  
  16. Var ACurrentString: String; Var APosition: Integer; Var AnX, AnY: Integer;
  17.  
  18. Var AnResult: TOnBeforeExecuteFlags);
  19.  
  20. Var
  21.  
  22. Temp: String;
  23.  
  24. i: Integer;
  25.  
  26. Begin
  27.  
  28. AllStL:=ACurrentString. Length;
  29.  
  30. SynCompletion1. ItemList. Clear;
  31.  
  32. //Generate keyword list
  33.  
  34. For i:=0 to KWList.Count-1 do
  35.  
  36. Begin
  37.  
  38. Temp:=KWList [i];
  39.  
  40. If temp. IndexOf (ACurrentString)>=0 then
  41.  
  42. Begin
  43.  
  44. SynCompletion1. ItemList. Add (temp);
  45.  
  46. End;
  47.  
  48. End;
  49.  
  50. End;
  51.  
  52.  
  53. Procedure TForm1. SynCompletionCodeCompletion (var Value: string;
  54.  
  55. SourceValue: string; Var SourceStart, SourceEnd: TPoint; KeyChar: TUTF8Char;
  56.  
  57. Shift: TShiftState);
  58.  
  59. Var
  60.  
  61. Px: Integer;
  62.  
  63. Begin
  64.  
  65. Px:=AllStL SourceValue. Length;
  66.  
  67. SourceStart. X:=SourceStart. X-Px// Delete multiple characters such as</
  68.  
  69. End;

The content of htmlKeyWord.txt is as follows:
<div>
</div>
<h1>
</h1>
<h2>
</h2>
<h3>
</h3>
.....


Now we just can't find the key word libraries for various languages (HTML, Lazarus, APS, Php, etc.).

 

TinyPortal © 2005-2018