Compute diffs based on characters rather than lines
Previously, a change on a given line would cause that whole line to be replaced. In turn, this caused anchors on that line to go to the start of that line because they would lie inside of a deleted region after applying the diff. By switching to a character-wise diff, we perform smaller edits to the buffer which stabilizes anchor positions.
This commit is contained in:
parent
f7a3141576
commit
71128d2ee6
2 changed files with 6 additions and 3 deletions
|
@ -1006,7 +1006,7 @@ impl Buffer {
|
|||
let old_text = old_text.to_string();
|
||||
let line_ending = LineEnding::detect(&new_text);
|
||||
LineEnding::normalize(&mut new_text);
|
||||
let changes = TextDiff::from_lines(old_text.as_str(), new_text.as_str())
|
||||
let changes = TextDiff::from_chars(old_text.as_str(), new_text.as_str())
|
||||
.iter_all_changes()
|
||||
.map(|c| (c.tag(), c.value().len()))
|
||||
.collect::<Vec<_>>();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue