Text Diff implements the Myers diff algorithm in pure JavaScript — the same algorithm used by `git diff`, GNU diff, and most code review tools. Myers finds the shortest edit script (the smallest number of insertions and deletions) that transforms the first input into the second. The implementation here runs in O((N+M)D) time where N and M are the input lengths and D is the edit distance, which is fast for typical document edits where most lines are unchanged.
Diffing happens at two levels. Line-level diff splits both inputs on newline characters and runs Myers over the line arrays. Word-level diff splits on whitespace using the regex /(\s+)/ which preserves the whitespace tokens so that re-joined output matches the original. Word-level is used to highlight changes inside a modified line, while line-level decides which lines are unchanged versus modified.
The classic Myers algorithm is O(ND) and uses a V-array indexed by k-line numbers (the diagonal in the edit graph). The implementation walks from start to end finding the furthest reaching point on each diagonal, then back-traces to recover the actual edit script. For typical edits — a few changed lines in a long document — this completes in well under one hundred milliseconds even for thousand-line inputs.
Performance degrades when the two inputs are very different (high D), because Myers explores more diagonals. Pasting two completely unrelated documents and asking for a diff can hit O(NM) in the worst case, which freezes the tab on multi-thousand-line inputs. This is a property of the algorithm, not a bug. For unrelated texts, the result is also not informative.
Whitespace-insensitive and case-insensitive modes do not change the diff algorithm itself; they normalize both inputs before passing them to Myers. Whitespace mode collapses runs of whitespace to a single space and trims; case-insensitive lowercases both inputs. Because the original text is preserved separately, the highlighted output still shows the verbatim characters even when the comparison key was normalized.
Two view modes are available. Unified shows one column with green plus markers for additions and red minus markers for deletions, mimicking the output of git diff. Side-by-side renders two columns with synchronized scrolling. Both views compute against the same edit script — switching modes does not retrigger the diff calculation, only the renderer.
Output is exposed via Copy, Download (as a plain-text patch in the unified format), and a stats panel that counts added, removed, and unchanged lines. Everything runs synchronously in the browser tab. There is no upload — your contracts, source code, and pre-publication drafts stay local even when computing the diff against a server-fetched template would be more convenient.