Skip to content

Commit

Permalink
Prevent unnecessary deselect/select when an already selected item is …
Browse files Browse the repository at this point in the history
…selected

Fixes #1011
  • Loading branch information
msssk committed Apr 18, 2020
1 parent 07ae37b commit 1ecdf07
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,12 @@ define([
// except that clicks/keystrokes without modifier keys will clear
// the previous selection.

// If the target is already selected, and is the sole selection, ignore a user action
// that would simply select the target (causing unnecessary deselect/select).
if (!event[ctrlEquiv] && this.isSelected(target) && this.getSelectedCount() === 1) {
return;
}

// Clear selection first for right-clicks outside selection and non-ctrl-clicks;
// otherwise, extended mode logic is identical to multiple mode
if (event.button === 2 ? !this.isSelected(target) :
Expand Down Expand Up @@ -641,6 +647,18 @@ define([
this._fireSelectionEvents();
},

getSelectedCount: function () {
var count = 0;

for (var id in this.selection) {
if (id) {
count += 1;
}
}

return count;
},

isSelected: function (object) {
// summary:
// Returns true if the indicated row is selected.
Expand Down
1 change: 1 addition & 0 deletions doc/components/mixins/Selection.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Method | Description
`selectAll()`| Programmatically selects all rows in the component. Note that only rows that have actually been loaded will be represented in the `selection` object.
`clearSelection()`| Programmatically deselects all rows in the component.
`isSelected(row)`| Returns `true` if the given row is selected.
`getSelectedCount()` | Returns the number of selected rows/cells.

**Note:** The `select`, `deselect`, and `isSelected` methods can be passed any
type of argument acceptable to List's `row` method; see the [List](../core-components/List.md) APIs for
Expand Down

0 comments on commit 1ecdf07

Please sign in to comment.