Summary
In GraphSelectionModel (single-selection mode), when the first selectable cell in the incoming list is already the currently selected cell, both addCells and setCells should be a no-op. Currently neither method short-circuits in this case:
addCells – firstSelectable && !this.isSelected(firstSelectable) evaluates to false, so toAdd = [] but toRemove = this.cells is non-empty. changeSelection([], this.cells) fires, clearing the selection instead of doing nothing.
setCells – always passes [firstSelectable] into changeSelection, triggering a remove+re-add cycle even when the cell is already selected. The end state is correct, but a spurious UNDO/CHANGE event pair is emitted.
Any fix must be applied symmetrically to both methods to avoid API inconsistency.
Steps to reproduce
- Enable single-selection mode on a
GraphSelectionModel.
- Select a cell via
addCell or setCell.
- Call
addCell or setCell again with the same cell.
- Observe:
addCells clears the selection; setCells fires unnecessary events.
Expected behaviour
Both calls should be a no-op (selection unchanged, no events fired) when the first selectable candidate is already the selected cell.
Proposed fix sketch
// addCells – single-selection branch
const firstSelectable = this.getFirstSelectableCell(cells);
if (firstSelectable && this.isSelected(firstSelectable)) {
return; // already the selected cell; no-op
}
this.changeSelection(firstSelectable ? [firstSelectable] : [], this.cells);
return;
// setCells – single-selection branch (symmetric guard)
const firstSelectable = this.getFirstSelectableCell(cells);
if (firstSelectable && this.isSelected(firstSelectable) && this.cells.length === 1) {
return; // already the only selected cell; no-op
}
this.changeSelection(firstSelectable ? [firstSelectable] : [], this.cells);
return;
References
/cc @redfish4ktc
Summary
In
GraphSelectionModel(single-selection mode), when the first selectable cell in the incoming list is already the currently selected cell, bothaddCellsandsetCellsshould be a no-op. Currently neither method short-circuits in this case:addCells–firstSelectable && !this.isSelected(firstSelectable)evaluates tofalse, sotoAdd = []buttoRemove = this.cellsis non-empty.changeSelection([], this.cells)fires, clearing the selection instead of doing nothing.setCells– always passes[firstSelectable]intochangeSelection, triggering a remove+re-add cycle even when the cell is already selected. The end state is correct, but a spuriousUNDO/CHANGEevent pair is emitted.Any fix must be applied symmetrically to both methods to avoid API inconsistency.
Steps to reproduce
GraphSelectionModel.addCellorsetCell.addCellorsetCellagain with the same cell.addCellsclears the selection;setCellsfires unnecessary events.Expected behaviour
Both calls should be a no-op (selection unchanged, no events fired) when the first selectable candidate is already the selected cell.
Proposed fix sketch
References
/cc @redfish4ktc