Skip to content

Bug: @lexical/offset makes invalid selection if offset points to inline node #7580

@wataru-chocola

Description

@wataru-chocola

Lexical version: 0.31.2

Steps To Reproduce

  1. Clone repository.
  2. Run pnpm install & pnpm dev.
  3. Visit dev site.
  4. Input aaaaa\naa.
  5. Input offset=6 and click "Set Offset".

Link to code example:

https://github.com/wataru-chocola/lexical-offset-bug

The current behavior

Image

You will see the following error in devtools console.

client:789 [vite] connecting...
client:912 [vite] connected.
hook.js:608 IndexSizeError: Failed to execute 'setBaseAndExtent' on 'Selection': There is no child at offset 6.
    at setDOMSelectionBaseAndExtent (Lexical.dev.mjs:7321:18)
    at updateDOMSelection (Lexical.dev.mjs:7407:3)
    at $commitPendingUpdates (Lexical.dev.mjs:8078:9)
    at Lexical.dev.mjs:8347:9
overrideMethod @ hook.js:608
setDOMSelectionBaseAndExtent @ Lexical.dev.mjs:7327
updateDOMSelection @ Lexical.dev.mjs:7407
$commitPendingUpdates @ Lexical.dev.mjs:8078
(anonymous) @ Lexical.dev.mjs:8347
localhost/:1 Uncaught (in promise) Error: A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received

offsetView.createSelectionFromOffsets makes invalid selection if specified offset points to inline node.

  • anchor / focus node will be its parent element (correct).
  • anchor / focus offset will be the offset of the inline node, but should be the index of the inline node in the parent.

The expected behavior

No error occurs.

Impact of fix

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions