Forum > SynEdit

Compare two text lines and highlight difference

<< < (2/7) > >>

Martin_fr:
SynEdit doesn't have that....

The closest you currently get is the "same word highlight", which applies to current selection too.
- if you start selecting one line from the start,
- select a few chars only
- wait about half a second, so the "same word highlight" will be activated
  (this can be set under Tools > Options: Editor > Display > Markup and Matches > top section "Highlight all occurrences of word under caret"
- Now the start of the other line should be highlighted.
- Extend the selection, until the other line looses the highlight => you are at the first diff in the line.

It's not what you want/need. Not even close....

It is a different feature, but it can be used for simple comparison ....


If you want to extend SynEdit....
1) Well you need your own code to find the diffs between the lines.

Once you have a list of sections that you want to highlight ( record Line, StartX, EndX: integer end; ):
2) You can write your on SynEditMarkup.
a) If you don't use any Highlighter (no Pascal or other HL) then you can use the "SynPos...Highlighter).
b) Otherwise, look at markups. Something like SynMarkupHighlightAll should be easy to modify. It already has a list....

Awkward:
... looks like this feature
https://github.com/rickard67/TextDiff

totya:

--- Quote from: Awkward on February 08, 2023, 05:37:40 pm ---... looks like this feature
https://github.com/rickard67/TextDiff

--- End quote ---

Thanks for the tip, but the basicdemo2 completely freeze my machine, when I click "open". Possible Dwarf/debug error, I must press reset (data loss).

But basicdemo1 works, but paintbox isn't really good for me, but for starting point is good.

Thank you!

Edit 1.: UTF8 characters loss with Demo1, fore example: "öüó"

totya:

--- Quote from: Martin_fr on February 08, 2023, 03:35:37 pm ---SynEdit doesn't have that....
--- End quote ---

I mean Synedit components (group name). Thank you for the many tips!

avk:
I don't know how it's done in TextDiff, but in LGenerics it's very easy:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---...uses  ..., lgSeqUtils; ...procedure TForm1.Button1Click(Sender: TObject);type  TUtil = specialize TGSeqUtil<string, string>;var  s1, s2: string;  a1, a2: TStringArray;  LDiff: TUtil.TDiff;begin  s1 := 'This is a nice day, the sky is blue and wind blowing sun is rising.';  s2 := 'This is a nice day with many kills, the sky is red and wind blowing sun is somewhere, because all dark here.';  a1 := s1.Split([' ', '.', ','], TStringSplitOptions.ExcludeEmpty);  a2 := s2.Split([' ', '.', ','], TStringSplitOptions.ExcludeEmpty);  LDiff := TUtil.Diff(a1, a2);  Memo1.Append('Deleted from s1(i.e. not present in s2):');  for I := 0 to High(LDiff.SourceChanges) do    if LDiff.SourceChanges[I] then      Memo1.Append(a1[I]);  Memo1.Append('');  Memo1.Append('Inserted into s2(i.e. not present in s1):');  for I := 0 to High(LDiff.TargetChanges) do    if LDiff.TargetChanges[I] then      Memo1.Append(a2[I]);  end; 
it prints:

--- Code: Text  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Deleted from s1(i.e. not present in s2):bluerising Inserted into s2(i.e. not present in s1):withmanykillsredsomewherebecausealldarkhere 

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version