Skip to content

fix: detect delete areas using pointer coordinates#10078

Merged
mikeharv merged 4 commits into
RaspberryPiFoundation:mainfrom
mikeharv:drag-origin
Jun 29, 2026
Merged

fix: detect delete areas using pointer coordinates#10078
mikeharv merged 4 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
Comment thread packages/blockly/core/workspace_svg.ts
Comment thread packages/blockly/core/dragging/dragger.ts Outdated
Comment thread packages/blockly/tests/mocha/dragger_test.js Outdated
@mikeharv mikeharv requested a review from gonfunko June 29, 2026 15:14
@mikeharv mikeharv merged commit d438210 into RaspberryPiFoundation:main Jun 29, 2026
5 checks passed
@mikeharv mikeharv deleted the drag-origin branch June 29, 2026 20:34
@gonfunko gonfunko mentioned this pull request Jun 29, 2026
1 task
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