Skip to content

Studio: drag sidebar rows in the desktop app, and drop the drag hint - #11561

Merged
shimmyshimmer merged 3 commits into
mainfrom
studio-sidebar-drag-desktop
Sep 22, 2026
Merged

shimmyshimmer merged 3 commits into
mainfrom
studio-sidebar-drag-desktop

Conversation

@shimmyshimmer

Copy link
Copy Markdown
Member

The bug

#11373 gave every sidebar row a drag gesture built on the HTML5 drag API: draggable, dragstart, dragover, drop. That works in a browser. In the desktop app no row can be dragged anywhere, and since the same PR took Move up and Move down out of the row menus for everything but touch screens, there is no way left to reorder a chat there short of alt and an arrow key.

The webview owns every OS drag. wry answers draggingEntered, draggingUpdated and performDragOperation itself, and only calls through to the webview when the listener declines the event:

if !listener(DragDropEvent::Enter { paths, position }) {
  unsafe { objc2::msg_send![super(this), draggingEntered: drag_info] }
} else {
  NSDragOperation::Copy
}

Tauri's listener always returns true, so nothing in the page hears the drag and dragover and drop never fire.

Windows gets to the same place by another route. wry walks the child HWNDs and calls RevokeDragDrop on each one before registering its own target, throwing away the target WebView2 implements HTML5 drag and drop on. The replacement returns early unless the payload carries CF_HDROP, so a dragged row is ignored and the original target is gone. Linux looks unaffected: those handlers return false and revoke nothing, so WebKit keeps its own drag and drop.

None of this is new to us. shared-composer.tsx already skips its own drop handlers under isTauri, and files arrive through features/native-intents on Tauri's own DragDrop window event. That path carries OS file paths and has nothing to say about a chat row.

Turning dragDropEnabled off is not the fix. It would take the native file drop with it.

The fix

hooks/use-sidebar-drag.ts is rebuilt on pointer events. lib/sidebar-drag.ts is untouched, so every drop rule and every cue stands as it was.

  • A press becomes a drag after 5px of travel, so a click still opens the chat and a double click still renames it.
  • Each zone carries itself in a data-sidebar-drop attribute, and elementsFromPoint hit tests innermost first. Same nesting the old dragover bubbling gave: row, then folder block, then section.
  • Put back by hand what the native drag gave free: autoscroll at the ends of the list, Escape to cancel, no text selection while dragging, and the click after the release swallowed.
  • The pointer is captured on the body, so a release outside the window still ends the gesture. The body and not the row, because opening a folder under the pointer redraws the rows around it.
  • Touch is unchanged. It still scrolls, and its row menus keep Move up and Move down.

The drag hint goes

The label that followed the cursor reading Pin, Unpin, Reorder or Move to a folder is gone, along with shell.drag.* in all 12 locales. The line on the landing edge and the ring around a folder already say where the row will land.

Tests

npm run test passes 8466. sidebar-row-drag.test.ts keeps its planner coverage and gains the guard that would have caught this: the suite fails if draggable, onDragOver or dataTransfer comes back to the sidebar. npm run i18n:check passes across all 12 locales. Lint is unchanged from the baseline on every file touched.

Sidebar rows were wired to the HTML5 drag API, which the desktop
webview never forwards to the page, so no row could be dragged there.
Rebuild the gesture on pointer events, and take out the label that
followed the cursor.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-22T17:23:23.434216Z 6e02cae Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@shimmyshimmer

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 85b9e50037

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

pre-commit-ci Bot and others added 2 commits September 22, 2026 17:10
Edge scrolling ran off pointermove alone, so a pointer resting on the
edge took one step and stalled, and the cue stayed on the row that had
slid away. A frame loop drives it now and re-aims as the list moves.

The window handlers also answered every pointer, so a finger could drive
and drop a drag the mouse started, which is what touch is kept out of.
Each one now answers only the pointer that pressed the row.
@shimmyshimmer

Copy link
Copy Markdown
Member Author

Both findings were right, and both are fixed in 6e02cae.

Edge scrolling. autoScroll only ever ran from track, and track only ran from pointermove, so a pointer that reached the edge and stopped took one 12px step and stalled. A frame loop drives it now, started with the drag and cancelled with it, and it re-aims on any frame that actually scrolled, since the rows move under a pointer that has not. track no longer scrolls at all, so there is one driver rather than two. The loop stops itself if the drag source is gone, so an unmount mid-drag cannot leave it running.

Pointer identity. The window handlers answered every pointer. onMove, onUp and onCancel now each return unless the event carries the pointer that pressed the row, and a non-primary press never starts one. A gesture already in flight is abandoned rather than refused: refusing would let a release the window never saw strand one and block every drag after it.

Both are covered by tests in sidebar-row-drag.test.ts.

Note that 3badef5 on this branch is a pre-commit.ci autofix touching backend Python formatting. It is not mine and is unrelated to the sidebar.

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e02caec80

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@oobabooga

oobabooga commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Rebuilding use-sidebar-drag.ts on pointer events fixes sidebar drag in the desktop app without touching the drop rules in lib/sidebar-drag.ts, and it keeps native file drop working, which turning off dragDropEnabled would not.

Live test (the real hook on a 60-row scrolling list, driven by Playwright in Chromium, at 6e02caec80):

Gesture Result
Plain click on a row ✅ Opens the chat
Press, move 2px, release ✅ Still opens the chat
Drag c0 onto c5 ✅ reorder drop, no stray click on release
Escape mid-drag ✅ Drag cancelled, no drop
Pointer resting at the bottom edge ✅ List keeps scrolling (12 → 228 → 456 px over 600 ms) and stops once the pointer leaves the edge
Pointer resting at the top edge ✅ List keeps scrolling up (576 → 276 px over 400 ms)
Drop after an edge scroll ✅ Cue and drop follow the row now under the pointer (c2 lands between c21 and c22)
pointerup / pointercancel from a second pointer mid-drag ✅ Ignored; the drag continues and drops normally
After the drop ✅ Frame loop stops, no further scrolling

Checks:

  • tsc clean
  • sidebar-row-drag.test.ts 28/28
  • Full frontend suite: same 7 failures as the merge base, none new

Desktop: I tested in Chromium, not in a Tauri build. The macOS and Windows fix follows from the wry drag handling in the description, the same reason shared-composer.tsx already skips its drop handlers under isTauri.

LGTM.

@shimmyshimmer
shimmyshimmer merged commit 92e1485 into main Sep 22, 2026
6 of 52 checks passed
@shimmyshimmer
shimmyshimmer deleted the studio-sidebar-drag-desktop branch September 22, 2026 17:30
@shimmyshimmer

Copy link
Copy Markdown
Member Author

Right, and confirmed in the code: swallowClick removes its listener on a zero-delay timer, while escape is usually pressed with the button still down, so the guard was gone before the release ever produced a click. Releasing over the source row opened the chat the drag had just been cancelled out of.

This PR was already merged when the review landed, so the fix is #11568 against main.

Escape no longer ends the gesture there. It marks it escaped, clears the drag and leaves the pointer listeners in place, so the release is what detaches, swallows the click and returns without a drop. A move after escape is ignored, so a cancelled drag cannot come back to life under a pointer that keeps travelling. Escape before the threshold still abandons the press outright, since nothing was lifted and a click after it belongs to the row.

shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…nslothai#11561)

* Studio: drag sidebar rows in the desktop app, and drop the drag hint

Sidebar rows were wired to the HTML5 drag API, which the desktop
webview never forwards to the page, so no row could be dragged there.
Rebuild the gesture on pointer events, and take out the label that
followed the cursor.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Keep the edge scroll going, and let one pointer own the drag

Edge scrolling ran off pointermove alone, so a pointer resting on the
edge took one step and stalled, and the cue stayed on the row that had
slid away. A frame loop drives it now and re-aims as the list moves.

The window handlers also answered every pointer, so a finger could drive
and drop a drag the mouse started, which is what touch is kept out of.
Each one now answers only the pointer that pressed the row.

---------

Co-authored-by: Unsloth <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants