[AHK v2] Compare Texts and Highlight Differences

Post your working scripts, libraries and tools
oif2003
Posts: 213
Joined: 17 Oct 2018, 11:43
GitHub: oif2003

[AHK v2] Compare Texts and Highlight Differences

12 Nov 2018, 23:24

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.
Attachments
textComparisonSS2.png
textComparisonSS2.png (78.55 KiB) Viewed 1354 times
Last edited by oif2003 on 14 Nov 2018, 20:15, edited 2 times in total.
burque505
Posts: 1018
Joined: 22 Jan 2017, 19:37

Re: [AHK v2] Text Comparison With Difference Highlighting

13 Nov 2018, 12:12

@oif2003, that's very nice, and I like what you've done with Class_RichEdit for v2. Thanks for sharing it.
Regards,
burque505
carno
Posts: 204
Joined: 20 Jun 2014, 16:48

Re: [AHK v2] Compare Texts and Highlight Differences

10 Feb 2019, 00:11

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.
burque505
Posts: 1018
Joined: 22 Jan 2017, 19:37

Re: [AHK v2] Compare Texts and Highlight Differences

10 Feb 2019, 14:57

@carno, I bet you're trying to run it with AHK v1. This script needs AHK v2.
Regards,
burque505
carno
Posts: 204
Joined: 20 Jun 2014, 16:48

Re: [AHK v2] Compare Texts and Highlight Differences

10 Feb 2019, 19:14

@burque505: Righto, your bet is on the money! :D Can I adapt/modify this script for v1 or I must install v2?
User avatar
Delta Pythagorean
Posts: 474
Joined: 13 Feb 2017, 13:44
GitHub: DelPyth
Location: Somewhere in the US

Re: [AHK v2] Compare Texts and Highlight Differences

11 Feb 2019, 07:47

Oh wow!

This is quite useful, especially for version comparison!
Thank you very much!
ahklearner
Posts: 309
Joined: 23 Jan 2015, 01:49

Re: [AHK v2] Compare Texts and Highlight Differences

13 Feb 2019, 08:58

was looking for something of this kind very lately, Thank You

Return to “Scripts and Functions”

Who is online

Users browsing this forum: 0x00 and 47 guests