Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
lexical
@lexical/a11y
@lexical/clipboard
@lexical/code
@lexical/code-core
@lexical/code-prism
@lexical/code-shiki
@lexical/compiler
@lexical/devtools-core
@lexical/dragon
@lexical/eslint-plugin
@lexical/extension
@lexical/fast-check
@lexical/file
@lexical/hashtag
@lexical/headless
@lexical/history
@lexical/html
@lexical/internal
@lexical/link
@lexical/list
@lexical/mark
@lexical/markdown
@lexical/mdast
@lexical/offset
@lexical/overflow
@lexical/plain-text
@lexical/react
@lexical/rich-text
@lexical/selection
@lexical/table
@lexical/tailwind
@lexical/text
@lexical/utils
@lexical/y
@lexical/yjs
commit: |
There was a problem hiding this comment.
Thanks for the fix, @Vedthakar, this looks good. I reproduced #9389 on main in Chromium and WebKit: dragging from the end of paragraph 3 onto the + button or the handle puts the focus at the start of paragraph 1. On this branch the focus stays at the start of paragraph 3 in Chromium, WebKit and Firefox, block dragging still works, and the new e2e test fails on main and passes here in Chromium.
A few optional, non-blocking suggestions:
- Custom menus whose buttons set
pointer-eventsthemselves (packages/lexical-react/src/LexicalDraggableBlockPlugin.tsxL383-384).pointer-events: noneon themenuRefelement is inherited, so a child that declarespointer-events: autostays hit-testable. That's a common pattern when the menu container is a pass-through overlay. With.draggable-block-menu > * { pointer-events: auto; }added to the playground, this branch still jumps to paragraph 1 over the+button in Chromium and WebKit. SettingmenuElem.inert = truefor the press (and restoring the previous value) takes the whole subtree out of hit testing and fixed that case in both engines when I tried it. If you'd rather keeppointer-events, consider noting the limitation in theDraggableBlockPlugin_EXPERIMENTALJSDoc, since the description says custommenuComponents get the fix too. - Capture the release listeners (L387-390). Lexical core registers its own drag-release listeners on the document with capture, so a listener that stops
pointerupcan't hide the release (packages/lexical/src/LexicalEvents.tsL2537-2539 and L2626-2633). Passingtrueas the third argument toregisterEventListenershere would do the same. The windowblurlistener (L392-400) could also go throughregisterEventListener, as the core does at L2636. - Test target and assertion (
packages/lexical-playground/__tests__/e2e/DraggableBlock.spec.mjsL246-257). In the playground menu,menu.x + menu.width / 2lands in the 2px gap between the+button and the handle, so neither button is actually hovered. Aiming at each button's centre, and assertingfocusOffset === 0(orselection.toString() === 'Paragraph 3'), would cover the two buttons the issue names and would fail if the selection merely collapsed. - Test plan. AGENTS.md (Commits and Pull Requests) asks for the real output of the command under
### After, and for an explicit note of any browser that wasn't exercised. WebKit, where the issue also reproduces, isn't mentioned.
| const pointerEvents = menuElem.style.pointerEvents; | ||
| menuElem.style.pointerEvents = 'none'; |
There was a problem hiding this comment.
Optional: pointer-events is inherited, so a custom menu whose buttons declare pointer-events: auto (a common pattern when the container is a pass-through overlay) keeps them hit-testable, and the selection still jumps to paragraph 1 in Chromium and WebKit. Setting menuElem.inert = true for the press (and restoring the previous value) takes the whole subtree out of hit testing and fixed that case in both engines when I tried it. Alternatively, note the limitation in the JSDoc.
| const removeListeners = registerEventListeners(doc, { | ||
| pointercancel: onPointerUp, | ||
| pointerup: onPointerUp, | ||
| }); |
There was a problem hiding this comment.
Optional: the core registers its drag-release listeners on the document with capture so a listener that stops pointerup can't hide the release (packages/lexical/src/LexicalEvents.ts L2626-2633). Passing true as the third argument here would do the same; otherwise a stopped release leaves the menu non-interactive until the next one reaches the document.
| steps: 5, | ||
| }, | ||
| ); | ||
| await page.mouse.move(menu.x + menu.width / 2, menu.y + menu.height / 2, { |
There was a problem hiding this comment.
Optional: in the playground menu this point is the 2px gap between the + button and the handle, so neither button is hovered. Aiming at each button's centre (for example .draggable-block-menu > :nth-child(1) and (2)) would cover the two targets the issue names.
| }); | ||
| await page.mouse.up(); | ||
|
|
||
| expect(focus).toBe('Paragraph 3'); |
There was a problem hiding this comment.
Optional: this also passes if the selection collapsed at the anchor. Asserting the focus offset (0) or selection.toString() === 'Paragraph 3' would pin the expected result.
…ag-selecting over the DraggableBlock menu While text is drag-selected, Chrome and Safari resolve a pointer over the draggable block menu to a position inside the menu, outside the editor, and extend the selection to the start of the document. Let the pointer pass through the menu while the primary button is held after a press in the editor, so the selection follows the text beneath it. Fixes meta#9389 Signed-off-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Ved Thakar <111605341+Vedthakar@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
5da535a to
8680743
Compare
|
Thanks for the review. I rebased onto — Ved Thakar |
Description
This solves issue #9389: while drag-selecting text, the selection jumps when the pointer passes over the DraggableBlockPlugin menu (
+button or drag handle) in Chrome and Safari.Current behavior. During a drag-select the browser extends the selection to the position under the pointer. Over the menu, that position is inside the menu's own elements, outside the
contenteditable. Chrome and Safari then extend the selection to the start of the editor: drag right-to-left from the end of paragraph 3 onto the menu, and the focus lands at the start of paragraph 1. Firefox doesn't do this. The issue's measurements showcaretPositionFromPoint()resolves into the editor once the menu haspointer-events: none.What this changes.
DraggableBlockPlugin_EXPERIMENTALsetspointer-events: noneon the menu (menuRef). Onpointeruporpointercancelanywhere in the document, or onblurof the window (where the release can be lost), it restores the menu's previous inline value, so the selection follows the text under the pointer.+itself isn't affected, and block dragging works as before.menuComponents get the fix too.Closes #9389
Test plan
New e2e test in
packages/lexical-playground/__tests__/e2e/DraggableBlock.spec.mjs, "Drag-selecting text over the block menu does not extend the selection past the pointer (#9389)". It types 3 paragraphs, presses at the end of paragraph 3, drags right-to-left onto the menu, and checks that the selection's focus is still in paragraph 3. It also runs in Firefox, which doesn't have the bug, as a control: it would catch the fix breaking selection over the menu there.Before
On
mainwith the test applied (chromium):After
On current
main(tested together with my other open fixes):DraggableBlock.spec.mjs(the new test fails onmain, with the focus in "Paragraph 1") andTextDragDrop.spec.mjspass.pnpm run test-unit: all 10,080 tests passtsc,pnpm run flow(0 errors), and eslint/prettier on the changed files: cleanAuthor: Ved Thakar (@Vedthakar)
🤖 Generated with Claude Code