Skip to content

editor: Fix Shift-click selection after cursor movement - #61045

Merged
SomeoneToIgnore merged 2 commits into
zed-industries:mainfrom
saberoueslati:editor/59913-shift-click-selection
Jul 18, 2026
Merged

editor: Fix Shift-click selection after cursor movement#61045
SomeoneToIgnore merged 2 commits into
zed-industries:mainfrom
saberoueslati:editor/59913-shift-click-selection

Conversation

@saberoueslati

Copy link
Copy Markdown
Contributor

Context

Shift-click sometimes extended a selection from an earlier word boundary after double-clicking a word and moving the cursor with the arrow keys. Cursor movement changed the selection but left the word or line selection mode active, so the next Shift-click reused stale selection bounds. Selection movement now resets the mode to character mode whenever it changes the selection, while preserving valid empty line selections that have not been moved.

Closes #59913.

Behavior before the fix :

Screencast.from.2026-07-15.13-21-51.webm

Behavior after the fix :

Screencast.from.2026-07-15.13-19-38.webm

How to Review

crates/editor/src/selections_collection.rs: MutableSelectionsCollection::move_with now resets the selection mode to character mode when movement changes a selection.

crates/editor/src/editor_tests.rs: Regression tests cover Shift-click after collapsing a word selection and confirm that a valid empty line selection retains line-wise extension behavior.

Self-Review Checklist

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content is consistent with the UI/UX checklist
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Fixed Shift-click sometimes extending selections from a previous word or line boundary.

@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jul 15, 2026
@SomeoneToIgnore SomeoneToIgnore added the area:editor Feedback for code editing, formatting, editor iterations, etc label Jul 16, 2026
@SomeoneToIgnore SomeoneToIgnore self-assigned this Jul 16, 2026

@SomeoneToIgnore SomeoneToIgnore left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the nice find.

The fix though, is rather confusing as move_offsets_with just below the change did not get change too, despite being identical?

The other large question is that before, the select mode was changed only at the end of each selection in the editor:

self.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
s.select(selections);
s.clear_pending();
if s.is_extending() {
s.set_is_extending(false);
} else {
s.set_select_mode(pending_mode);
}
});

This all signals that we need to fix things elsewhere, not paper things over.

@saberoueslati

saberoueslati commented Jul 18, 2026

Copy link
Copy Markdown
Contributor Author

@SomeoneToIgnore I’ve reworked the fix so MutableSelectionsCollection::select resets the selection mode to Character. Both move_with and move_offsets_with already funnel changed selections through select, so they now behave consistently without duplicating the reset in individual movement methods.

Since end_selection also calls select, it now captures the appropriate mode beforehand and restores it afterward. This preserves word/line granularity for active selection gestures while preventing stale modes from surviving later selection replacements.

I also added a regression test covering the move_offsets_with path. The focused tests pass, as does the full editor library suite: 850 passed and 1 ignored.

@SomeoneToIgnore SomeoneToIgnore left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes much more sense, thank you a lot for the investigation!

@SomeoneToIgnore
SomeoneToIgnore added this pull request to the merge queue Jul 18, 2026
Merged via the queue into zed-industries:main with commit 2118a7c Jul 18, 2026
35 checks passed
jolutz pushed a commit to jolutz/zed that referenced this pull request Aug 8, 2026
…es#61045)

## Context

Shift-click sometimes extended a selection from an earlier word boundary
after double-clicking a word and moving the cursor with the arrow keys.
Cursor movement changed the selection but left the word or line
selection mode active, so the next Shift-click reused stale selection
bounds. Selection movement now resets the mode to character mode
whenever it changes the selection, while preserving valid empty line
selections that have not been moved.

Closes zed-industries#59913.

Behavior before the fix :

[Screencast from 2026-07-15
13-21-51.webm](https://github.com/user-attachments/assets/c126adfe-f9db-4a04-91c2-6db6e8070182)

Behavior after the fix :

[Screencast from 2026-07-15
13-19-38.webm](https://github.com/user-attachments/assets/19c9f5b6-aaf8-4e8b-b4c5-70327411d1b9)


## How to Review

**`crates/editor/src/selections_collection.rs`**:
`MutableSelectionsCollection::move_with` now resets the selection mode
to character mode when movement changes a selection.

**`crates/editor/src/editor_tests.rs`**: Regression tests cover
Shift-click after collapsing a word selection and confirm that a valid
empty line selection retains line-wise extension behavior.

## Self-Review Checklist

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the UI/UX checklist
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed Shift-click sometimes extending selections from a previous word
or line boundary.
playdohface pushed a commit to playdohface/zed that referenced this pull request Aug 29, 2026
…es#61045)

## Context

Shift-click sometimes extended a selection from an earlier word boundary
after double-clicking a word and moving the cursor with the arrow keys.
Cursor movement changed the selection but left the word or line
selection mode active, so the next Shift-click reused stale selection
bounds. Selection movement now resets the mode to character mode
whenever it changes the selection, while preserving valid empty line
selections that have not been moved.

Closes zed-industries#59913.

Behavior before the fix :

[Screencast from 2026-07-15
13-21-51.webm](https://github.com/user-attachments/assets/c126adfe-f9db-4a04-91c2-6db6e8070182)

Behavior after the fix :

[Screencast from 2026-07-15
13-19-38.webm](https://github.com/user-attachments/assets/19c9f5b6-aaf8-4e8b-b4c5-70327411d1b9)


## How to Review

**`crates/editor/src/selections_collection.rs`**:
`MutableSelectionsCollection::move_with` now resets the selection mode
to character mode when movement changes a selection.

**`crates/editor/src/editor_tests.rs`**: Regression tests cover
Shift-click after collapsing a word selection and confirm that a valid
empty line selection retains line-wise extension behavior.

## Self-Review Checklist

- [x] I've reviewed my own diff for quality, security, and reliability
- [ ] Unsafe blocks (if any) have justifying comments
- [x] The content is consistent with the UI/UX checklist
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable

Release Notes:

- Fixed Shift-click sometimes extending selections from a previous word
or line boundary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:editor Feedback for code editing, formatting, editor iterations, etc cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shift+click sometimes starts selection earlier

2 participants