Recent

Author Topic: TSynEdit: Highlighter fold and color at the same time  (Read 760 times)

Dzandaa

  • Hero Member
  • *****
  • Posts: 557
  • From C# to Lazarus
TSynEdit: Highlighter fold and color at the same time
« on: March 27, 2026, 12:41:01 pm »
Hi, everybody,

New to TSynedit creation:

I want to write a custom TSynEdit for personal data editing.

I use a TSynEdit in my form and I want to have a color Highlighter and a fold Highlighter at the same time when writing.

For example: when I tape a Keyword for folding, I also want then the text color change.

Any Idea, thank you.

B->
Regards,
Dzandaa

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12518
  • Debugger - SynEdit - and more
    • wiki
Re: TSynEdit: Highlighter fold and color at the same time
« Reply #1 on: March 27, 2026, 02:42:42 pm »
https://wiki.freepascal.org/SynEdit_Highlighter
And there are demo sources for a new highlighter in the examples folder.

Mind you, for 5.0 there are quite some changes. They will require a few updates (but mostly simple to make, like renaming).

Also in 5.0 some docs have been added:
https://gitlab.com/freepascal.org/lazarus/lazarus/-/tree/main/components/lazedit/docs?ref_type=heads

And the above examples have been updated (and maybe a bit improved)
https://gitlab.com/freepascal.org/lazarus/lazarus/-/tree/main/examples/SynEdit/NewHighlighterTutorial?ref_type=heads

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12518
  • Debugger - SynEdit - and more
    • wiki
Re: TSynEdit: Highlighter fold and color at the same time
« Reply #2 on: March 27, 2026, 02:48:00 pm »
Quote
For example: when I tape a Keyword for folding, I also want then the text color change.

Not a problem....

Well, once you got through the tutorial, and have your own highlighter.

In "GetTokenAttribute" you can check for the "TopCodeFoldBlockType" and return a different attribute. You just need to have as many attributes as you need colors.

(You can search the sql highlighter for TopCodeFoldBlockType)

Edson

  • Hero Member
  • *****
  • Posts: 1329
Re: TSynEdit: Highlighter fold and color at the same time
« Reply #3 on: March 28, 2026, 01:49:19 am »
I use a TSynEdit in my form and I want to have a color Highlighter and a fold Highlighter at the same time when writing.

For example: when I tape a Keyword for folding, I also want then the text color change.

Any Idea, thank you.

SynFacilSyn (https://github.com/t-edson/SynFacilSyn) is a configurable SynEdit highlighter and can do syntax highlighting and folding too. There are some samples in the Github.

I haven't tested in the last Lazarus versions  :-[ but I think it is OK.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

 

TinyPortal © 2005-2018