Recent

Author Topic: How to highlight and mark multiple strings in a SynEdit?  (Read 9279 times)

carlejt

  • New Member
  • *
  • Posts: 39
How to highlight and mark multiple strings in a SynEdit?
« on: June 03, 2012, 06:08:28 am »
Hello

How to highlight, mark or select multiple strings within a component TSynEdit?
Note: strings can be defined by the line number and the two positions Y (column) into the line. Or also by two positions X (line) Y (column).

What also puzzles me is (which prompted me to ask the above):
How do you call or are called the marks that the Lazarus editor does when it finds matches in the string indicated by the text cursor?

Capture:

http://i45.tinypic.com/ksp4i.png

How i can do that a SynEdit component has this feature?
Note: My version of Lazarus is 0.9.30

Thanks

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: How to highlight and mark multiple strings in a SynEdit?
« Reply #1 on: June 03, 2012, 11:54:20 am »
The picture you took is "highlight all occurrences of word under caret". In the IDE Alt-M can be used to keep it at the current word, even if you move the caret.

http://wiki.lazarus.freepascal.org/IDE_Window:_Editor_Options_Markup#Current_Word

It is done by TSynEditMarkupHighlightAllCaret, which is part of SynEdit. It is included in every SynEdit. (Currently exactly one is included in every SynEdit). In future it may be an option.

You can configure it via

Code: [Select]
x := TSynEditMarkupHighlightAllCaret(SynEdit.MarkupByClass[TSynEditMarkupHighlightAllCaret]);

x.WaitTime
x.Trim
x.FullWord
x.FullWordMaxLen
Ix.gnoreKeywords


If you want to Highlight a word of your choice: TSynEditMarkupHighlightAll. It has also one instance in SynEdit already.
Code: [Select]
SearchString
SearchOptions


See unit components\synedit\syneditmarkuphighall.pp for more

If you need more than one, you must inherit your own class from SynEdit. And (in the constructor) create additional instances of the desired module.
Code: [Select]
  fMarkupHighAll   := TSynEditMarkupHighlightAll.Create(self);
  fMarkupManager.AddMarkUp(fMarkupHighAll);

They will be freed automatically when SynEdit is destroyed.

carlejt

  • New Member
  • *
  • Posts: 39
Re: How to highlight and mark multiple strings in a SynEdit?
« Reply #2 on: June 03, 2012, 05:47:16 pm »
Thanks for your reply

Another question:

How i do that the SyEdit1 component has the characteristic "highlight all occurrences of word under caret."?

Note: My code is small, only a form1 with a synedit1. An example would help me. 

Martin fr. thank you very much.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: How to highlight and mark multiple strings in a SynEdit?
« Reply #3 on: June 03, 2012, 06:10:12 pm »
You need to add SynEditMarkupHighAll to the "uses" clause of your unit.
Code: [Select]
uses SynEditMarkupHighAll;
If you use Lazvarus 0.9.31 fixes, there is something called an "Identifier Dictionary", where you can enter the class (or any identifier) and it will add the unit for you.

Then add a "OnCreate" event to your form (the one with the synedit)

Code: [Select]
procedure TForm1.FormCreate(Sender: TObject);
var
  SynMarkup: TSynEditMarkupHighlightAllCaret;
begin
  SynMarkup := TSynEditMarkupHighlightAllCaret(SynEdit1.MarkupByClass[TSynEditMarkupHighlightAllCaret]);

  SynMarkup.MarkupInfo.FrameColor := clSilver;
  SynMarkup.MarkupInfo.Background := clGray;

  SynMarkup.WaitTime := 100; // millisec
  SynMarkup.Trim := True;     // no spaces, if using selection
  SynMarkup.FullWord := True; // only full words If "Foo" is under caret, do not mark it in "FooBar"
  SynMarkup.IgnoreKeywords := False;
end;

You can set whatever color, or bold or ...

--
One day that will be added to the visual designer. But for now

carlejt

  • New Member
  • *
  • Posts: 39
Re: How to highlight and mark multiple strings in a SynEdit?
« Reply #4 on: June 03, 2012, 07:23:40 pm »
Hello Martin fr.

The code works, Martin fr. Thank you very much. I am very grateful. Now I can continue with my project...

Thanks Martin fr.



 

TinyPortal © 2005-2018