Skip to content

fix: keep prior selection when shift-clicking after ctrl-click#679

Open
spike-rabbit wants to merge 1 commit intomainfrom
fix/shift-selection-anchor
Open

fix: keep prior selection when shift-clicking after ctrl-click#679
spike-rabbit wants to merge 1 commit intomainfrom
fix/shift-selection-anchor

Conversation

@spike-rabbit
Copy link
Copy Markdown
Member

What kind of change does this PR introduce? (check one with "x")

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior? (You can also link to an open issue here)

Closes #582. Shift-clicking after a Ctrl-click discards previously selected rows because the range selection replaces the selection with [].

What is the new behavior?

Shift-click extends the existing selection with the range from the last clicked row, preserving prior Ctrl-selections. Duplicates are skipped.

Does this PR introduce a breaking change? (check one with "x")

  • Yes
  • No

Other information:

Added a unit test in body.component.spec.ts covering the issue's repro steps.

@spike-rabbit spike-rabbit requested a review from a team as a code owner April 28, 2026 14:04
@spike-rabbit spike-rabbit force-pushed the fix/shift-selection-anchor branch from 07e1c77 to aec6650 Compare April 28, 2026 14:06
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request fixes a regression where shift-clicking to select a range would clear previously selected rows. The changes ensure that the current selection is preserved when calculating the new range and add a guard for the previous selection index. A performance optimization was suggested for the selection utility to use a Set for membership checks instead of Array.includes() to avoid quadratic time complexity during large selections.

Comment thread projects/ngx-datatable/src/lib/utils/selection.ts Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes multi-row selection behavior so that shift-click range selection preserves any prior ctrl/meta selections (issue #582), and adds coverage for the regression.

Changes:

  • Update shift-click selection to extend the current selection instead of replacing it with an empty selection.
  • Add de-duplication when adding a shift-click range to the selection.
  • Add unit tests reproducing ctrl-click + shift-click behavior and a “first click is shift” edge case.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
projects/ngx-datatable/src/lib/utils/selection.ts Adds de-dupe logic when selecting ranges.
projects/ngx-datatable/src/lib/components/body/body.component.ts Preserves existing selection when shift-selecting, guarded by prevIndex.
projects/ngx-datatable/src/lib/components/body/body.component.spec.ts Adds regression tests for ctrl+shift multi-selection behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread projects/ngx-datatable/src/lib/utils/selection.ts Outdated
Comment thread projects/ngx-datatable/src/lib/components/body/body.component.ts Outdated
@spike-rabbit spike-rabbit force-pushed the fix/shift-selection-anchor branch from dc44ba0 to 17e4802 Compare May 4, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: selection by shift should use last selected member as refrence

2 participants