Skip to content

fix(editor): improve block drag-and-drop hit targeting#100

Merged
zacharias-ona merged 1 commit into
mainfrom
fix/block-drag-drop-targeting
Apr 16, 2026
Merged

fix(editor): improve block drag-and-drop hit targeting#100
zacharias-ona merged 1 commit into
mainfrom
fix/block-drag-drop-targeting

Conversation

@zacharias-ona
Copy link
Copy Markdown
Collaborator

Problem

Dragging blocks via the grip handle is finicky — the cursor must be positioned on the exact line of a block for the drop indicator to appear. Moving the cursor into the gap between blocks causes the target to vanish, making reordering unreliable.

Root cause

Two issues in getBlockElement:

  1. Dead zone too small (4px) — Block elements have small margins (mt-0.5), so the gaps between them are larger than 4px. The cursor frequently lands in "no man's land" where no block is matched.
  2. No fallback during drag — When the cursor is between blocks, the function returns null instead of snapping to the nearest block. This causes the drop indicator to disappear and the drop to fail.

Changes

  • Increase HANDLE_DEAD_ZONE from 4px to 16px so the drag handle appears more readily when hovering near a block
  • Add a nearest-block fallback: when no block matches within the dead zone, find the absolute nearest block by edge distance
  • During drag operations (DRAGOVER_COMMAND / DROP_COMMAND), always use unbounded search so the cursor always resolves to a target
  • Extract getTopLevelBlockElements helper to avoid duplicating the element lookup across the two search passes

Closes #99

Increase the dead zone from 4px to 16px so the drag handle appears more
readily when hovering near a block.

Add a nearest-block fallback so the cursor always resolves to a target
during drag operations, even when positioned in the gap between blocks.

Extract element lookup into getTopLevelBlockElements for reuse across
the two search passes.

Closes #99

Co-authored-by: Ona <no-reply@ona.com>
@zacharias-ona zacharias-ona added the ona-user PR created via interactive Ona session — no issue reference required label Apr 16, 2026
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 16, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
memo Ready Ready Preview, Comment Apr 16, 2026 6:40pm

Request Review

@zacharias-ona zacharias-ona merged commit da2c37a into main Apr 16, 2026
6 checks passed
@zacharias-ona zacharias-ona deleted the fix/block-drag-drop-targeting branch April 16, 2026 18:42
@zacharias-ona
Copy link
Copy Markdown
Collaborator Author

✅ UI verification passed — design spec compliance confirmed.

Static analysissrc/components/editor/draggable-block-plugin.tsx:

  • Color tokens: text-muted-foreground, hover:text-foreground, bg-accent — all from the design spec token set
  • Drop indicator: h-0.5 bg-accent matches spec (2px bg-accent line)
  • Drag handle: GripVertical with text-muted-foreground matches spec
  • Transitions: transition-opacity duration-100 — no decorative animations
  • Accessibility: aria-label, role="button", tabIndex={0} present
  • No arbitrary hex/rgb values, no arbitrary spacing

Visual verification (Playwright screenshots of editor page):

  • Desktop dark: layout, spacing, colors, sidebar all correct
  • Mobile (375×812): sidebar hidden, hamburger visible, editor full-width, no horizontal scroll

Changes are logic-only (hit-testing improvements for drag-and-drop targeting) with no visual impact at rest.

@zacharias-ona
Copy link
Copy Markdown
Collaborator Author

✅ Post-merge verification passed.

E2E suite: 27/27 tests passed (auth, editor drag-and-drop, editor links, slash commands, floating toolbar, page CRUD, sidebar drag-and-drop, workspace switcher).

Ad-hoc smoke tests:

  • ✅ Landing page — loaded, has title
  • /sign-in — rendered with email input
  • /api/health — healthy
  • ✅ Authenticated login flow — redirected to workspace
  • ✅ Workspace page — fully loaded
  • ✅ Editor navigation — page opened via sidebar, editor rendered
  • ✅ No console errors (unauthenticated or authenticated)

No routes skipped.

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

Labels

ona-user PR created via interactive Ona session — no issue reference required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Block drag-and-drop requires exact cursor positioning

1 participant