# editor: Defer the effects of \`change_selections\` to end of \`transact\` \(\#31731\) · gitcafe/zed

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

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

Visibility: public

Requested revision: d7f0241d7b3745f32ca3d5e0c10a2ff70bf031a2

Requested commit: d7f0241d7b3745f32ca3d5e0c10a2ff70bf031a2

Commit: d7f0241d7b3745f32ca3d5e0c10a2ff70bf031a2

Tree: 51525ab2025175c6c4f903505f69d97ca528a878

Author: Michael Sloan

Committer: GitHub

## Message

```
editor: Defer the effects of `change_selections` to end of `transact` (#31731)

In quite a few places the selection is changed multiple times in a
transaction. For example, `backspace` might do it 3 times:

* `select_autoclose_pair`
* selection of the ranges to delete
* `insert` of empty string also updates selection

Before this change, each of these selection changes appended to
selection history and did a bunch of work that's only relevant to
selections the user actually sees. So for each backspace,
`editor::UndoSelection` would need to be invoked 3-4 times before the
cursor actually moves. It still needs to be run twice after this change,
but that is a separate issue.

Signature help even had a `backspace_pressed: bool` as an incomplete
workaround, to avoid it flickering due to the selection switching
between being a range and being cursor-like.

The original motivation for this change is work I'm doing on not
re-querying completions when the language server provides a response
that has `is_incomplete: false`. Whether the menu is still visible is
determined by the cursor position, and this was complicated by it seeing
`backspace` temporarily moving the head of the selection 1 character to
the left.

This change also removes some redundant uses of
`push_to_selection_history`.

Not super stoked with the name `DeferredSelectionEffectsState`. Naming
is hard.

Release Notes:

- N/A
```

## Parents

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

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