fix(mobile): don't open the sidebar drawer while selecting message text#5585
Open
BrunooMoniz wants to merge 1 commit into
Open
fix(mobile): don't open the sidebar drawer while selecting message text#5585BrunooMoniz wants to merge 1 commit into
BrunooMoniz wants to merge 1 commit into
Conversation
On mobile, dragging to extend a text selection inside a chat message opened the left sidebar drawer. The swipe-to-open gesture in _initChatSwipeToOpenSidebar (static/js/sidebar-layout.js) armed for any horizontal drag that started anywhere over the chat content, so growing a selection to copy it was captured as an edge-swipe and popped the drawer open. Arm the gesture only from a narrow 24px strip at the screen's left/right edge, and bail whenever a text selection is active at touchstart or appears/grows during the drag. A drag that starts over a message body is now left entirely to native text selection, while a genuine edge-swipe still opens the drawer on either side and the hamburger and backdrop-close paths are unchanged. Adds tests/test_sidebar_swipe_js.py, which loads the real module under Node, dispatches synthetic touch events, and asserts a mid-content selection drag keeps the drawer closed while a true edge-swipe still opens it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On mobile, dragging to extend a text selection inside a chat message opened the left sidebar drawer. The swipe-to-open gesture in
_initChatSwipeToOpenSidebar(static/js/sidebar-layout.js) armed for any one-finger horizontal drag that started anywhere over#chat-container, so growing a selection to copy a reply was captured as an edge-swipe and popped the drawer open over the text you were selecting. This PR gates the gesture so it arms only from a narrow 24px strip at the screen's left/right edge and bails whenever a text selection is active at touch start or appears/grows during the drag. A drag that starts over a message body is now left entirely to native text selection, while a genuine edge-swipe still opens the drawer on either side and the hamburger button and backdrop-tap close path are unchanged. The gesture is already mobile-only (gated to viewports narrower than 768px), so desktop is unaffected.Target branch
dev, notmain. All PRs land indev;mainis curated by the maintainer at each release. If your PR is onmainby accident, click "Edit" on this PR and change the base.Linked Issue
Fixes #5584
Type of Change
Checklist
devdocker compose uporuvicorn app:app) and verified the change works end-to-end. Type-checks and unit tests are not enough.How to Test
Steps a reviewer can reproduce (full app):
docker compose up -d --build, open the chat on a phone (or in DevTools with mobile/touch emulation and the viewport narrower than 768px).dev: the left sidebar drawer slides open over the message and the selection is interrupted. With this branch: the text selection extends normally and the drawer stays closed. A deliberate swipe from the very left/right screen edge still opens the drawer, and the hamburger button and backdrop tap still open/close it.What was verified for this change:
dev(before, drag-to-select opens the drawer) vs this branch (after, the selection stays and the drawer stays closed). See the screenshots below.node --check static/js/sidebar-layout.js— passes.python -m pytest tests/test_sidebar_swipe_js.py— 5 passed. The test loads the real module under Node and dispatches synthetic touch events: a mid-content selection drag, an edge-start drag with a live selection, and a selection that grows mid-drag all keep the drawer closed; a genuine left-edge and right-edge swipe both still open it. The three selection cases fail on currentdev(the drawer opens) and pass on this branch, so the test pins the fix.pytestsuite is unaffected.Files changed:
static/js/sidebar-layout.js— the swipe-to-open handler now arms only from a narrow edge strip (EDGE_ZONE) and bails on an active or growing text selection (hasTextSelection); no styling, markup, or other behaviour changes.tests/test_sidebar_swipe_js.py— a Node-driven regression test (same subprocess pattern astests/test_markdown_rendering_js.py) that dispatches synthetic touch events against the real module.Visual / UI changes — REQUIRED if you touched anything that renders
Anything that changes what the UI looks like — buttons, icons, padding, colors, fonts, spacing, layout, CSS, HTML, SVG, or any
static/js/module that draws to the DOM — needs all of the following.static/js/sidebar-layout.jsmodule andstatic/style.cssrendered in WebKit at a mobile viewport (390x844) on the default dark theme, showing the drawer-open (before, currentdev) vs drawer-closed with the selection intact (after, this branch). The gesture is mobile-only (gated below 768px), so there is no desktop case to show.--red,--fg,--bg,--card,--border, etc.) — do not introduce new color values, font sizes, or spacing units.static/index.html) or plain text.Fira Code) for primary UI text. Don't override.Screenshots / clips
Mobile — before (current
dev)Mobile — after (this PR)