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

[improvement] More selection logic #1806

Merged
merged 2 commits into from Aug 13, 2023
Merged

[improvement] More selection logic #1806

merged 2 commits into from Aug 13, 2023

Conversation

steveruizok
Copy link
Collaborator

@steveruizok steveruizok commented Aug 13, 2023

This PR includes further UX improvements to selection.

  • clicking inside of a hollow shape will no longer select it on pointer up
  • clicking a shape's filled label will select it on pointer down
  • clicking a shape's empty label will select it on pointer up
  • clicking and dragging a selected arrow is now better limited to its body, not its bounds
  • arrows will no longer bind to labels

Other important changes here:

  • most function overloads are here removed
  • setSelectedShapeIds is now setSelectedShapes
  • Group2d geometries no longer have an (unimplemented) operation property

Text labels

A big change here relates to text labels. Previously, we had listeners set on the text label elements; I've removed these and we now check the actual label bounds geometry for a hit. For geo shapes, this geometry is now placed correctly based on the alignment / vertical alignment of the label.

  • Clicking on a label with text in it will select the shape on pointer down.
  • Clicking on an empty text label will select the shape on pointer up.

Hollow shapes

Previously, shapes with fill: none were also being selected on pointer up. I've removed that logic because it was producing wrong-feeling selections too often. We now select these shapes only when clicking on the label (as mentioned above) or when clicking on the edges of the shape. This is in line with the original behavior (currently on tldraw.com, prior to the earlier PR that updated selection logic).

Arrows

Arrows still hit the inside of hollow shapes, using the "smallest hovered" logic previously used for pointer-up selection on hollow shapes. They also now correctly do so while ignoring text labels.

Change Type

  • minor — New feature

Test Plan

  1. try selecting geo shapes, nested geo shapes, arrows and shapes with labels or without labels
  • Unit Tests

@huppy-bot huppy-bot bot added the minor Increment the minor version when merged label Aug 13, 2023
@vercel
Copy link

vercel bot commented Aug 13, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
examples ✅ Ready (Inspect) Visit Preview Aug 13, 2023 3:22pm

@steveruizok steveruizok added this pull request to the merge queue Aug 13, 2023
Merged via the queue into main with commit 22329c5 Aug 13, 2023
6 checks passed
@steveruizok steveruizok deleted the selection-3 branch August 13, 2023 15:59
github-merge-queue bot pushed a commit that referenced this pull request Apr 17, 2024
(this is a PR redo of #3424 which
got messed up a bit)

It doesn't quite feel like this is the right fix but it does solve the
issue. I was trying to see if `getShapeAtPoint` needed more work but the
further I went in that rabbit hole it seemed like I shouldn't touch that
code without causing a bunch of disruption at the moment.

Specifically, the code that does `Check labels first` in Editor.ts is a
little obscure (lines 4384-4397). It only checks a couple specifics
shapes (with certain combinations, i.e. a geo with "none" fill) _and_ it
doesn't check `hitLabels` which also maybe feels wrong? I tried
unraveling it but there's a lot of code relying on it at the moment to
mess with it in the stickies work.
(I was looking at #1910 and
#1806 for historical context fwiw)

Before:


https://github.com/tldraw/tldraw/assets/469604/b263a192-2085-4ffb-9e47-6e9c32abe1f9



After:


https://github.com/tldraw/tldraw/assets/469604/5b0b422b-dd5c-4593-9ac5-dec595923ea6



### Change Type

<!-- ❗ Please select a 'Scope' label ❗️ -->

- [x] `sdk` — Changes the tldraw SDK
- [ ] `dotcom` — Changes the tldraw.com web app
- [ ] `docs` — Changes to the documentation, examples, or templates.
- [ ] `vs code` — Changes to the vscode plugin
- [ ] `internal` — Does not affect user-facing stuff

<!-- ❗ Please select a 'Type' label ❗️ -->

- [x] `bugfix` — Bug fix
- [ ] `feature` — New feature
- [ ] `improvement` — Improving existing features
- [ ] `chore` — Updating dependencies, other boring stuff
- [ ] `galaxy brain` — Architectural changes
- [ ] `tests` — Changes to any test code
- [ ] `tools` — Changes to infrastructure, CI, internal scripts,
debugging tools, etc.
- [ ] `dunno` — I don't know
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
minor Increment the minor version when merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant