Recent

Author Topic: [SOLVED] TSynCompletion filtering question  (Read 806 times)

Wesbat

  • New Member
  • *
  • Posts: 33
    • engrams.dev
[SOLVED] TSynCompletion filtering question
« on: December 14, 2024, 11:09:26 am »
Hi all.

Let me first say I've been enjoying working with Lazarus. It is a great tool.

For my question, I did try forum and internet searches, played with the component's events, and checked the Sourceforge bug tracker (admittedly a bit harder to trawl it).

I want to use the TSynCompletion component to provide a means to insert user-generated content. The challenge is the list of items are note searchable - i.e. I want to enter a partial word to match at an arbitrary location in the list, for example typing "hover" should match the entry "Display link target on hover".

I understand the component was built for code editors, and my use-case likely oversteps it's intended use. But I want to ask just in case - is there a way to achieve this filter behaviour with TSynCompletion?
« Last Edit: December 15, 2024, 01:17:08 am by Wesbat »

LV

  • Full Member
  • ***
  • Posts: 188
Re: TSynCompletion filtering question
« Reply #1 on: December 14, 2024, 11:15:47 am »
Maybe: c:\lazarus\examples\SynEdit\SearchAndReplace\

Wesbat

  • New Member
  • *
  • Posts: 33
    • engrams.dev
Re: TSynCompletion filtering question
« Reply #2 on: December 14, 2024, 11:41:38 am »
hmm, not quite the functionality I need. I need to insert a text that does not yet exist via a completion-like list. Thanks for the suggestion either way LV.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10652
  • Debugger - SynEdit - and more
    • wiki
Re: TSynCompletion filtering question
« Reply #3 on: December 14, 2024, 12:08:45 pm »
There is a "completion" example in the example folder. It shows how to use different completion tools. It also shows how to fill and filter the list.

Wesbat

  • New Member
  • *
  • Posts: 33
    • engrams.dev
Re: TSynCompletion filtering question
« Reply #4 on: December 14, 2024, 10:18:05 pm »
Thanks for the good suggestion Martin_fr,

Apologies for not be clearer in my original post. That example was the first place I looked and it works well for single-word completions. In my case I am trying to complete multiple words.

To demonstrate per the example: To complete the phrase "Personal Computer" (a word within the example's Itemlist) I cannot type "computer" and see the phrase in the popup list (screenshot attached). I have to type "personal" instead (it matches from the start of the ItemList entry)

Is it possible to match any word in the ItemList, not just the first word?

The ItemList from lazarus\examples\SynCompletion:
Code: Pascal  [Select][+][-]
  1.     SynCompletion1.ItemList.Add('Personal Computer');  { <-- not shown in completion list if "computer" is entered }
  2.     SynCompletion1.ItemList.Add('Personal');
  3.     SynCompletion1.ItemList.Add('Computer');
  4.     SynCompletion1.ItemList.Add('Police Constable');
  5.     SynCompletion1.ItemList.Add('Police');
  6.     SynCompletion1.ItemList.Add('Constable');

In comparison, when I enter "que" within the Lazarus code editor it matches "Query" and "Request" - I'd like to mimic this behaviour :)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10652
  • Debugger - SynEdit - and more
    • wiki
Re: TSynCompletion filtering question
« Reply #5 on: December 14, 2024, 10:36:35 pm »
Have you looked at the source?

- TForm1.DoExecute
- TForm1.DoSearchPosition

Both have comments when they get executed. You can debug them to see what they do.

In both of them, in the nested procedure ADD, change the condition to:
Code: Pascal  [Select][+][-]
  1.     if pos(UpperCase(SynCompletion1.CurrentString),UpperCase(s)) > 0 then
  2.       SynCompletion1.ItemList.Add(s);

In DoSearchPosition you can play with APosition if you want a different item selected => mind then you reset whatever the user did by up/down keys.

You can leave position unchanged. Or you can check which word is at that position, and then set APosition to the position to which that word moved.

Wesbat

  • New Member
  • *
  • Posts: 33
    • engrams.dev
Re: TSynCompletion filtering question
« Reply #6 on: December 14, 2024, 10:44:41 pm »
Have you looked at the source?

- TForm1.DoExecute
- TForm1.DoSearchPosition

Okay now I feel rather really silly. I should have known better, thank you for the perfect answer Martin_fr  :)

 

TinyPortal © 2005-2018