# Use stable path keys for the project diff \(\#59984\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 2c346f60a76fe3f0367ef924927f50a6efdf5718

Requested commit: 2c346f60a76fe3f0367ef924927f50a6efdf5718

Commit: 2c346f60a76fe3f0367ef924927f50a6efdf5718

Tree: e17f0f2c900b56dd5ddeeb1ea77c96cb69f913c7

Author: Cole Miller

Committer: GitHub

## Message

```
Use stable path keys for the project diff (#59984)

#59043 updated the project diff and git panel to improve the sorting
options and make the order of files always match across the two.
However, the approach relied on sorting the list of buffers first and
then using an incrementing `PathKey.sort_prefix` to insert them into the
multibuffer. This is a problem because path keys are intended to be
stable, and any addition of removal of a buffer from the multibuffer
would cause the path keys for all subsequent buffers to change, so
`update_path_excerpts` would do unnecessary work.

This PR fixes that by computing stable path keys for the buffers based
on the ordering settings:
- `PathKey.sort_prefix` is based on the git status if that setting is
enabled, or a constant otherwise (the same way it worked before #59043)
- when the tree view is disabled, `PathKey.path` is either the raw
`RepoPath` (if sorting by path) or `{name}/{repo_path}` (if sorting by
name). When the tree view is enabled, we get the path by inserting `\0`
just before every directory component of the `RepoPath`, so that all
directories sort before all files.

Release Notes:

- N/A
```

## Parents

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

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