Page 1 of 1

[AHK v2] Compare Texts and Highlight Differences

Posted: 12 Nov 2018, 23:24
by oif2003
Hi,

I made a script that compares two texts and highlights the differences (red - deletion, green - insertion). It first computes the longest common subsequence between the two texts in the user chosen mode (line, word, or character), then it outputs the results by highlighting the differences in the RichEdit boxes. Highlighted portions of the results and the LCS (longest common subsequence) can be copied to clipboard with the option of using `r`n as extra delimiters. It gives correct, but annoying results when text is repeated (more prone to happening in character comparison mode). Use at your own risk!

To test it out you will need the following files:
https://github.com/oif2003/RichEditBox/ ... e.ahk?ts=4
https://github.com/oif2003/RichEditBox/ ... t.ahk?ts=4

credit: Just Me, majkinetor, corrupt, jballi, DigiDon, and burque505 for Class_RichEdit

Edit: The script now consolidates changes that are adjacent or can be made adjacent through swapping of matched characters in different positions. This partially fixes the annoying issue of fragmented results on text that has many repeating parts.

Re: [AHK v2] Text Comparison With Difference Highlighting

Posted: 13 Nov 2018, 12:12
by burque505
@oif2003, that's very nice, and I like what you've done with Class_RichEdit for v2. Thanks for sharing it.
Regards,
burque505

Re: [AHK v2] Text Comparison With Difference Highlighting

Posted: 14 Nov 2018, 08:42
by guest3456
awesome

Re: [AHK v2] Compare Texts and Highlight Differences

Posted: 10 Feb 2019, 00:11
by carno
When I double-click on textCompare.ahk I get this error message:
Error in #include file "Class_RichEdit.ahk":
parameter #2 invalid.
Specifically: "Integer"
Line#
}
; -------------------------------------------------------------------------------------------------------------------
SetModified(Modified := False) { ; Sets or clears the modification flag for an edit control.
; EM_SETMODIFY = 0xB9
SendMessage( 0xB9, !!Modified, 0, , "ahk_id " . This.HWND)
Return ErrorLevel
}
; -------------------------------------------------------------------------------------------------------------------
SetEventMask(Events := "") { ; Set the events which shall send notification codes control's owner
; Events : Array containing one or more of the keys defined in 'ENM'.
; For details see http://msdn.microsoft.com/en-us/library/bb774238(v=vs.85).aspx
; EM_SETEVENTMASK = 0x0445
Static ENM := {NONE: 0x00, CHANGE: 0x01, UPDATE: 0x02, SCROLL: 0x04, SCROLLEVENTS: 0x08, DRAGDROPDONE: 0x10
, PARAGRAPHEXPANDED: 0x20, PAGECHANGE: 0x40, KEYEVENTS: 0x010000, MOUSEEVENTS: 0x020000
, REQUESTRESIZE: 0x040000, SELCHANGE: 0x080000, DROPFILES: 0x100000, PROTECTED: 0x200000
, LINK: 0x04000000}

---> if Events is "Integer"

The program will exit.

Re: [AHK v2] Compare Texts and Highlight Differences

Posted: 10 Feb 2019, 14:57
by burque505
@carno, I bet you're trying to run it with AHK v1. This script needs AHK v2.
Regards,
burque505

Re: [AHK v2] Compare Texts and Highlight Differences

Posted: 10 Feb 2019, 19:14
by carno
@burque505: Righto, your bet is on the money! :D Can I adapt/modify this script for v1 or I must install v2?

Re: [AHK v2] Compare Texts and Highlight Differences

Posted: 11 Feb 2019, 07:47
by Delta Pythagorean
Oh wow!

This is quite useful, especially for version comparison!
Thank you very much!

Re: [AHK v2] Compare Texts and Highlight Differences

Posted: 11 Feb 2019, 07:56
by DRocks
Wow.

Re: [AHK v2] Compare Texts and Highlight Differences

Posted: 13 Feb 2019, 08:58
by ahklearner
was looking for something of this kind very lately, Thank You