Skip to content

fix: detect delete areas using pointer coordinates#10078

Open
mikeharv wants to merge 2 commits into
RaspberryPiFoundation:mainfrom
mikeharv:drag-origin
Open

fix: detect delete areas using pointer coordinates#10078
mikeharv wants to merge 2 commits into
RaspberryPiFoundation:mainfrom
mikeharv:drag-origin

Conversation

@mikeharv

@mikeharv mikeharv commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

The basics

The details

Resolves

Fixes #10077

Proposed Changes

  • Dragger: Delete-area detection during pointer drags now uses the cursor position (PointerEvent.clientX / clientY) instead of the block’s workspace origin (getRelativeToSurfaceXY()). Block movement is unchanged; only hit testing for delete styling, drag-target hooks, and drop/delete on onDragEnd follow the pointer.
  • WorkspaceSvg.getDragTarget: Accepts only PointerEvent once again.
  • Keyboard drags: onDrag skips delete-area logic when the event is not a PointerEvent; onDragEnd commits without delete-area checks.

This effectively reverts one particular change introduced by #9593

Reason for Changes

Previously, deletion could trigger when the block origin overlapped a delete area even if the cursor was elsewhere, for example, dragging a block over the workspace while its top-left corner still intersected the toolbox column. Now, deletion depends on where the user is pointing, not where the block’s origin happens to be.

This conveniently seems to resolve #10076 as well, likely due to getRelativeToWorkspaceXY() returning the wrong sort of coordinates for zoomed workspaces. (I did not bother to root cause this, but did confirm it's no longer happening.)

Test Coverage

New mocha suite simulating realistic drags with delete areas.

  • Drag to trashcan center - delete styling applied; block disposed on drop.
  • Drag to toolbox center - same behavior for toolbox delete area.
  • Origin overlaps toolbox, cursor outside - block origin moved slightly into toolbox delete rect; cursor stays outside; no delete styling; block survives onDragEnd.

@mikeharv mikeharv requested a review from a team as a code owner June 26, 2026 19:09
@mikeharv mikeharv requested a review from gonfunko June 26, 2026 19:09
@github-actions github-actions Bot added the PR: fix Fixes a bug label Jun 26, 2026
@github-actions github-actions Bot added PR: fix Fixes a bug and removed PR: fix Fixes a bug labels Jun 26, 2026
* @returns Null if not over a drag target, or the drag target the event is
* over.
*/
getDragTarget(e: PointerEvent | Coordinate): IDragTarget | null {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Here especially, and kinda throughout, I think this really should have always taken a coordinate; I'd suggest leaving it as-is. Also this is technically breaking. In general I think only the actual event listener should handle events, and any methods called by it or its callees should take specific/abstracted arguments, rather than handing events around all over the place and picking one or two properties out of them.

return;
}

let wouldDelete = false;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why was this moved back here and made a let? It seems like it's still only assigned in one place and read right after that down below?

Comment on lines +25 to +26
x: (bounds.left + bounds.right) / 2,
y: (bounds.top + bounds.bottom) / 2,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This only maths if it's at (0,0) right? and same for rectCenterClient below

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR: fix Fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blocks move using top left corner as origin instead of pointer coordinates Bad delete area detection when zoomed

2 participants