7

Using: Delphi XE2, Windows VCL forms application, 32-bit

I'm using the SynEdit control to display text. I'm already using the TSynHTMLSyn syntax highlighter with the control to properly highlight HTML and JS code.

I'm also doing a diff on this text (using Angus Johnson's TDiff) with another version of the text to find: deletions, additions and changes. I need to highlight each of these type of changes with a different color ie RED for deletion, BLUE for additions, and GREEN for changes.

My questions:

  1. Is it possible to implement?
  2. If yes, then how?

TIA.

Steve F
  • 1,527
  • 1
  • 29
  • 55
  • I am not really a SynEdit user but if nothing else helped, I'd try something like `E.SelStart := x; E.SelEnd := y; E.SelectedColor := c;` (looking at the class's member set [here](http://z505.com/synedit/synedit_doc/tsynedit.html) and [here](http://z505.com/synedit/synedit_doc/tcustomsynedit.html)). – Andriy M Oct 31 '13 at 12:34
  • This works but I need: 1) Multiple selections to be highlighted 2) Even if the user clicks in the control to select some other text, the text that was highlighted earlier should remain highlighted. – Steve F Nov 10 '13 at 10:06
  • Have you checked the fork of `TSynEdit` that is used by the Lazarus IDE? I think it can handle multiple highlighted blocks that persists when editing. – LU RD Nov 12 '13 at 22:53
  • See if you can make something out of this: [`SynEdit Highlighter`](http://wiki.freepascal.org/SynEdit_Highlighter). – LU RD Nov 12 '13 at 23:03

1 Answers1

1

Try to use TSynEdit.onSpecialLineColors event, e.g.

procedure TfmRunScript.EditorSpecialLineColors(Sender: TObject;
  Line: Integer; var Special: Boolean; var FG, BG: TColor);
begin
 if Line = ErrorLine then
  begin
   Special := True;
   BG := clMaroon;
   FG := clWhite;
  end;
end;
Pavlo Golub
  • 359
  • 5
  • 13
  • 1
    I need to highlight words in a line based on buffer position (start and stop). I don't see how this event would work for me. – Steve F Nov 15 '13 at 18:03