Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mouse event listener with selection box feature #290

Closed
wants to merge 17 commits into from

Conversation

cristiancreteanu
Copy link

@cristiancreteanu cristiancreteanu commented Mar 30, 2023

Checklist

  • I added multiple screenshots/screencasts of my UI changes

Motivation and Context

This PR provides the implementation of a selection box using the cursor in order to select multiple elements without the use of the keyboard.

Description

Every time the user clicks OUTSIDE an element, the selection box is created. In order for it to become visible, the user needs to drag the cursor. An element needs to be contained FULLY within the selection box for it to be selected when the selection box is released (i.e. the click/drag action is over). This feature also works when pressing the SHIFT key without deselecting the already selected items.

If the user's cursor goes outside the scope of the canvas while the selection box is active, the selection box will "freeze", but it will continue when the cursor comes back to the canvas. If the user releases the click while the cursor is outside the canvas and they return to the canvas, the selection box will remain active; clicking again will "resume" the selection box and the user can continue to drag the cursor in order to change the already active selection box before releasing it.

Adjustments:

  • hovering is disabled when the selection box is active
  • the cursor shape normally changes to sizeall (pointer: 'move') when hovering over the inside of an element - disabled while selection box is active
  • the cursor shape normally changes to sizenesw/sizenwse when hovering over the edges of an element - disabled while selection box is active

Steps for Testing

  1. Open Apollon in Chrome
  2. Add a few UML Elements to the canvas
  3. Click somewhere on the canvas where there are no elements and drag the mouse to see the selection box
  4. Drag the mouse to include the elements that you want to select
  5. Release the click and all the elements in the selection box should be selected while the others should remain deselected

Screenshots

grafik

grafik

We needed to change SelectableState to keep track of when the
selection box is active in order to make this information available
for other components.
The props contained in some cases the selectionBoxActive attribute.
When passing the props object to svg, an error was shown in the
console saying that selectionBoxActive is not an svg attribute.
@cristiancreteanu cristiancreteanu force-pushed the feature/add-selection-box branch from 0d92471 to fc21f21 Compare April 12, 2023 06:47
@cristiancreteanu cristiancreteanu force-pushed the feature/add-selection-box branch from 8b0995a to 311c0b9 Compare April 12, 2023 08:03
@cristiancreteanu cristiancreteanu self-assigned this Apr 12, 2023
@cristiancreteanu cristiancreteanu added the enhancement New feature or request label Apr 12, 2023
@cristiancreteanu cristiancreteanu force-pushed the feature/add-selection-box branch from 5e9b02f to f439946 Compare April 12, 2023 16:56
Before we were checking whether we are clicking inside an element
by verifying the bounds. But the easier and more correct approach
was to check whether an element is being hovered.
@cristiancreteanu cristiancreteanu marked this pull request as ready for review April 13, 2023 20:54
Copy link
Contributor

@mertyldrr mertyldrr left a comment

Choose a reason for hiding this comment

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

The selection box feature looks very cool. Nice work! We need to make sure modeling tests in Artemis are not affected by the updated selected state. If so, we need to fix them as well.

Copy link
Contributor

@AlexanderG2207 AlexanderG2207 left a comment

Choose a reason for hiding this comment

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

Excellent feature, well done! I tested it locally, and everything works as expected, including some edge cases I tried.

The only thing I would add is more tests for the new feature, as the test coverage could be higher. Also, if applicable, the modeling tests in Artemis should be adjusted, as mentioned by @mertyldrr.

File % Stmts % Branch % Funcs % Lines Uncovered Line #s
mouse-eventlistener.tsx 50 66.66 44.44 50 90-104,114-155,162-179,187-203,213-239,246-256

@krusche
Copy link
Member

krusche commented Oct 15, 2023

@AlexanderG2207 @matthiaslehnertum unfortunately, the author is not part of the team anymore.
Can someone of you take over this PR and finish it after fixing the merge conflicts? Thank you!

@matthiaslehnertum
Copy link
Collaborator

Closing in favor of #332

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants