Skip to content

Line or Word Diffs

jhgbrt edited this page Oct 4, 2020 · 3 revisions

The difference algorithm in this library operates in character mode. This produces the most detailed diff possible. However, for some applications one may wish to take a coarser approach.

Line Mode

Computing a line-mode diff is really easy.

  var diffs = Diff.ComputeLineDiff(text1, text2);

Word Mode

Computing a word-mode diff is exactly the same as the line-mode diff, except you will have to make a copy of diff_linesToChars and call it diff_linesToWords. Look for the line that identifies the next line boundary:

lineEnd = text.indexOf('\n', lineStart);

Change this line to look for any runs of whitespace, not just end of lines.

Despite the name, the diff_charsToLines function will continue to work fine in word-mode.

Clone this wiki locally