Skip to main content

diff_text

Function diff_text 

Source
pub fn diff_text(a: &str, b: &str) -> Vec<TextSegment>
Expand description

Character-level (Unicode-scalar) diff of two strings.

Trims the common prefix/suffix, then runs an LCS over the changed middle to produce minimal segments. For very large changed runs (when the middle’s |a| * |b| exceeds [LCS_GUARD]) it falls back to a single delete + insert to bound cost — correct, but not minimal for those pathological inputs.

use tiptap_rusty_parser::{diff_text, SegKind};
let segs = diff_text("kitten", "sitting");
// The common run "itt" survives as a Keep segment.
assert!(segs.iter().any(|s| s.kind == SegKind::Keep && s.text.contains("itt")));