react-complex-tree icon indicating copy to clipboard operation
react-complex-tree copied to clipboard

Indirectly selecting the starting item in a `shift` multiselect action results in an incorrect multiselection

Open tonyketcham opened this issue 4 months ago • 2 comments

Describe the bug When selecting the first item in a shift key held selection of multiple items, if the first item is selected via a ref or by changing the selectedItems view state on a ControlledTree, the starting state does not get overridden. Therefore, the previous item which was directly selected in the tree is incorrectly used as the start of the range.

To Reproduce

  1. Go to https://rct.lukasbach.com/docs/guides/refs
  2. Select "Banana" in the tree
  3. Click the ref button "Select items Apple and Orange"
  4. Hold down the shift key
  5. Select "Desserts" in the tree

Expected selection is: [Apple, Orange, Lemon, Berries, Banana, Meals, Desserts]

Actual selection is: [Banana, Meals, Desserts]

Expected behavior Changes to the tree's selection state which originate outside of the tree component itself should overwrite the starting item in a multiselection range

Screenshots

https://github.com/lukasbach/react-complex-tree/assets/43280336/7ecad96a-cfc3-4284-b184-2b1cce2324e5

https://github.com/lukasbach/react-complex-tree/assets/43280336/20d85ef9-cef2-473b-8025-72a12bc42762

Real-world case

When clicking on a layer in the visual canvas space, the selectedItems view state of the RCT layer tree is updated. Holding down shift to select the end item of a selection range in the tree then results in an incorrect multiselection:

https://github.com/lukasbach/react-complex-tree/assets/43280336/84e6efc7-cbea-4693-b126-3317d487617e

tonyketcham avatar Feb 15 '24 01:02 tonyketcham