Skip to content

#512 unselect a node in multi selection when holding shift key#527

Merged
langonginc merged 6 commits intomainfrom
#512-unselect-multi-selection
Dec 9, 2023
Merged

#512 unselect a node in multi selection when holding shift key#527
langonginc merged 6 commits intomainfrom
#512-unselect-multi-selection

Conversation

@langonginc
Copy link
Copy Markdown
Member

After #525

@langonginc langonginc linked an issue Dec 3, 2023 that may be closed by this pull request
@langonginc langonginc marked this pull request as draft December 3, 2023 11:22
@langonginc langonginc marked this pull request as ready for review December 3, 2023 12:22
@langonginc
Copy link
Copy Markdown
Member Author

Lines will be added in #528.

// details panel only, remove all if this is not a multiple selection
if (!e.shiftKey && selected.length <= 1) dispatch(clearSelected());
dispatch(addSelected(node)); // details panel only
if (!e.shiftKey) dispatch(clearSelected());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe it's a bit hard to find out the relation here. Need some time to think about different situations and what the operation should be. How about writing it to

if (!e.shiftKey) dispatch(clearSelected()); // remove all if this is not a multiple selection
else {
  if (selected.includes(node)) dispatch(removeSelected(node)); // remove current if it is already in the multiple selection
  else dispatch(addSelected(node)); // add current in the multiple selection
}

So basically we have 3 possible operations and none of them could overlap each other. The current code makes me wonder if if could be fired one by one :(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

L3 may be put in the if.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not quite sure what to put in the if. Any code suggestion?

Copy link
Copy Markdown
Member Author

@langonginc langonginc Dec 5, 2023

Choose a reason for hiding this comment

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

Oh, I'm sorry, L4 may be copy to the if like this:

        if (!e.shiftKey) {
            dispatch(clearSelected()); // remove all if this is not a multiple selection
            dispatch(addSelected(node)); // show current details
        } else {
            if (selected.includes(node))
                dispatch(removeSelected(node)); // remove current if it is already in the multiple selection
            else dispatch(addSelected(node)); // add current in the multiple selection
        }

Or, we won't be able to click to show one object's details.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hmm, there may be a problem with clearing the selected. We cannot move nodes that are selected if is more than one. We can delete the clear operation to avoid this.

Copy link
Copy Markdown
Member

@thekingofcity thekingofcity Dec 9, 2023

Choose a reason for hiding this comment

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

Also it looks like we can always setSelected([node]) in non multiple selection case 🤔 In that way, we can have one less include check. But it’s okay to merge without this change.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh, we can not setSelected([node]) when the user clicks a previously selected one without holding shift. Previous selected is used to move multiple selected nodes. This should be left in the comment :(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, we can not setSelected([node]) when the user clicks a previously selected one without holding shift. Previous selected is used to move multiple selected nodes. This should be left in the comment :(

A, B, C are selected and I just click A again without press the shift key. We should clear selection and add A only? Is that?

Copy link
Copy Markdown
Member

@thekingofcity thekingofcity Dec 9, 2023

Choose a reason for hiding this comment

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

A, B, C are selected and I just click A again without pressing the shift key. -> Then we should not clear the multiple selections as users may drag before releasing the click and the selected nodes should be moved according to the drag.

So no-op is correct but a better comment should be left as // no-op as users may drag the previously selected node(s) in handlePointerMove.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Oh, I got it.

Copy link
Copy Markdown
Member

@thekingofcity thekingofcity left a comment

Choose a reason for hiding this comment

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

LGTM

@langonginc langonginc merged commit d5b830e into main Dec 9, 2023
@langonginc langonginc deleted the #512-unselect-multi-selection branch December 9, 2023 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Unselect a node in a multiple selection holding shift

2 participants