# editor: Fix jumbled auto-imports when completing with multiple cursors \(\#50320\) · gitcafe/zed

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

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

Visibility: public

Requested revision: 949944acb4b33595f329126060132a2cdaca1de9

Requested commit: 949944acb4b33595f329126060132a2cdaca1de9

Commit: 949944acb4b33595f329126060132a2cdaca1de9

Tree: 39d28400b081a6d6e99d76fdcb57c3df3da5d8da

Author: Atchyut Preetham Pulavarthi

Committer: GitHub

## Message

```
editor: Fix jumbled auto-imports when completing with multiple cursors (#50320)

When accepting an autocomplete suggestion with multiple active cursors
using `CMD+D`, Zed applies the primary completion edit to all cursors.
However, the overlap check for LSP `additionalTextEdits` only verifies
the replace range of the newest cursor.

If user has a cursor inside an existing import statement at the top of
the file and another cursor further down, Zed fails to detect the
overlap at the top of the file. When the user auto-completes the import
statement ends up jumbled.

This fix updates the completion logic to calculate the commit ranges for
all active cursors and passes them to the LSP store. The overlap check
now iterates over all commit ranges to ensure auto-imports are correctly
discarded if they intersect with any of the user's multi-cursor edits.

Closes https://github.com/zed-industries/zed/issues/50314

### Before


https://github.com/user-attachments/assets/8d0f71ec-37ab-4714-a318-897d9ee5e56b

### After


https://github.com/user-attachments/assets/4c978167-3065-48c0-bc3c-547a2dd22ac3

Before you mark this PR as ready for review, make sure that you have:
- [x] Added a solid test coverage and/or screenshots from doing manual
testing
- [x] Done a self-review taking into account security and performance
aspects
- [x] Aligned any UI changes with the [UI
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)

Release Notes:

- Fixed an issue where accepting an autocomplete suggestion with
multiple cursors could result in duplicated or jumbled text in import
statements.
```

## Parents

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

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