Skip to main content

diff_edit

Function diff_edit 

Source
pub fn diff_edit(old: &str, new: &str) -> (usize, usize, usize)
Expand description

Recover a single contiguous edit from the old and new text: (offset, removed, inserted) in bytes.

The whole reason a keystroke does not need the backend’s cooperation. A common prefix and a common suffix bracket exactly what changed, which for one keystroke, one deletion, one paste or one autocorrect is the edit. An edit that touched two separate places (a multi-cursor change) comes back as one span covering both: coarser, never wrong, and it costs only the styling between them.

Both ends are pulled back to character boundaries, so a multi-byte character that changed mid-sequence never produces a range that would split one.