Skip to content

Unexpected error: Failed to execute 'setStart' on 'Range': The offset 4294967292 is larger than the node's length (491). #2627

Closed

Description

@nestoris

Description

An unexpected error occurred in the renderer process.

Stack Trace

Error: Failed to execute 'setStart' on 'Range': The offset 4294967292 is larger than the node's length (491).
    at Object.select (file:///usr/lib/marktext/app.asar/dist/electron/webpack:/src/muya/lib/selection/index.js:346:11)
    at Object.setCursorRange (file:///usr/lib/marktext/app.asar/dist/electron/webpack:/src/muya/lib/selection/index.js:491:10)
    at aa.setCursor (file:///usr/lib/marktext/app.asar/dist/electron/webpack:/src/muya/lib/contentState/index.js:205:15)
    at aa.partialRender (file:///usr/lib/marktext/app.asar/dist/electron/webpack:/src/muya/lib/contentState/index.js:257:12)
    at aa.inputHandler (file:///usr/lib/marktext/app.asar/dist/electron/webpack:/src/muya/lib/contentState/inputCtrl.js:324:51)
    at HTMLDivElement.<anonymous> (file:///usr/lib/marktext/app.asar/dist/electron/webpack:/src/muya/lib/eventHandler/keyboard.js:203:22)

Version

Mark Text: v0.16.3 (c1d603f)
Operating system: Linux x64 5.10.59-1-MANJARO (linux)

Activity

  1. Jocs commented on Dec 29, 2021

    @Jocs
    Member

    How to reproduce this issue?

  2. added
    🐤 blocked/need info
    on Dec 29, 2021
  3. fxha commented on Jan 12, 2022

    @fxha
    Contributor

    Description:

    Merging two lines of white-spaces (here spaces) result in an editor crash because the spaces are converted into a code bock. The cursor is invalid after this operation and overflows when setting the cursor in DOM.

    Steps:

    Type in editor mode and set cursor the the given position:

    1. Type a and hit enter
    2. Type two or three spaces and hit enter
    3. Type two or three spaces and hit enter
    4. Type b and position cursor
    5. Press Shift, once ArrorLeft while holding shift and afterwards Backspace
    a
    
    2x <space>
    
    <cursor>2x <space>
    
    b
    

    Cursor before crash:

    {
      "start":{
        "key":"ag-105",
        "offset": -2
      },
      "anchor":{
        "key":"ag-105",
        "offset": -2
      },
      "end":{
        "key":"ag-105",
        "offset": -2
      },
      "focus":{
        "key":"ag-105",
        "offset": -2
      }
    }

    Expected behavior:

    • Either the code block is generated and the correct cursor should be set or
    • all spaces are replaced by one space and the cursor may be adjusted.

    Temporary Workaround:

    Validate cursor before setting and use a fallback.

    Stack Trace:

    index.js?4d53:346 Uncaught DOMException: Failed to execute 'setStart' on 'Range': The offset 4294967293 is invalid.
        at Selection.select (webpack-internal:///./src/muya/lib/selection/index.js:360:11)
        at Selection.setCursorRange (webpack-internal:///./src/muya/lib/selection/index.js:527:10)
        at ContentState.setCursor (webpack-internal:///./src/muya/lib/contentState/index.js:241:56)
        at ContentState.partialRender (webpack-internal:///./src/muya/lib/contentState/index.js:326:12)
        at ContentState.inputHandler (webpack-internal:///./src/muya/lib/contentState/inputCtrl.js:366:51)
        at HTMLDivElement.inputHandler (webpack-internal:///./src/muya/lib/eventHandler/keyboard.js:248:22)
    
  4. added
    🐛 bug
    and removed
    🐤 blocked/need info
    on Jan 12, 2022
  5. Jocs commented on May 23, 2026

    @Jocs
    Member

    Closing this with the regression-guard e2e specs added in #4268.

    The user-action recipe described here (and the same crash signature in ~25 other reports) does not reproduce on the current develop branch (0.18.9). The setCursorRange offset clamp at src/muya/lib/selection/index.js:524-530 plus cumulative refactor fixes appear to have closed the underlying bug.

    The recipes from these reports are now encoded as Playwright tests in test/e2e/crash-range-offset.spec.ts so a regression here will fail CI before it reaches another user.

    If you still hit this crash on a recent build, please reopen with the exact MarkText version and the markdown that triggered it.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    🐛 bug🔭 area/muya

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions