# Use line-based and word-based diff when reloading and formatting buffers \(\#25129\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/0fdad0c0d6216618b59e269a04fbe81e5b758bfa)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 0fdad0c0d6216618b59e269a04fbe81e5b758bfa

Requested commit: 0fdad0c0d6216618b59e269a04fbe81e5b758bfa

Commit: 0fdad0c0d6216618b59e269a04fbe81e5b758bfa

Tree: a5bd6d6e971af01f64094fcd3e551bc1932d44e0

Author: Max Brunsfeld

Committer: GitHub

## Message

```
Use line-based and word-based diff when reloading and formatting buffers (#25129)

Closes https://github.com/zed-industries/zed/issues/10122
Closes https://github.com/zed-industries/zed/issues/25034

When formatting buffers or reloading them after they change on disk, we
performed a diff between the buffer's current contents and the new
content. We need this diff in order preserve the positions of cursors
and other decorations when updating the buffer's text.

In order to handle changes within lines, we would previously compute a
*character-wise* diff. This was extremely expensive for large files.

This PR gets rid of the character-wise diff, and instead performs a
normal line-wise diff. Then, for certain replace hunks, we compute a
secondary word-based diff. Also, I've switched to the
[`imara-diff`](https://github.com/pascalkuthe/imara-diff) crate, instead
of `similar`.

Release Notes:

- Fixed a hang that could occur when large files were changed on disk or
formatted.
```

## Parents

- [1087e05da49bc788f1df81e0aa26ac66c3c73789](https://git.cafe/gitcafe/zed/commit/1087e05da49bc788f1df81e0aa26ac66c3c73789?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/0fdad0c0d6216618b59e269a04fbe81e5b758bfa?format=markdown)
