Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.
This repository was archived by the owner on Apr 15, 2026. It is now read-only.

First-keystroke console error with bracketMatching when using non‑English IME #1687

@jiaopengzi

Description

@jiaopengzi

Describe the issue

Hello,

I found an issue and prepared a minimal HTML demo to reproduce it.

Environment

windows 11

Chrome 146.0.7680.165

@codemirror/state 6.6.0

@codemirror/view 6.40.0

@codemirror/language 6.12.2

Description

When using a non‑English input method (for example, a Chinese IME) with the bracketMatching extension enabled, a runtime error is logged in the browser console on the very first keystroke in the editor.
The error does not occur when using an English input method.
I noticed that issue #1684 reports a similar problem, so this may be related or a duplicate.

Open the provided minimal demo.

Details

<!doctype html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>CodeMirror bracketMatching Demo</title>
        <style>
            #editor {
                height: 320px;
                border: 1px solid #ddd;
                border-radius: 6px;
            }
        </style>
    </head>
    <body>
        <h3>CodeMirror only bracketMatching demo</h3>
        <div id="editor"></div>

        <script type="module">
            import { EditorState } from "https://esm.sh/@codemirror/state@6.6.0"
            import { EditorView } from "https://esm.sh/@codemirror/view@6.40.0"
            import { bracketMatching } from "https://esm.sh/@codemirror/language@6.12.2"

            const doc = "demo"

            const state = EditorState.create({
                doc,
                extensions: [bracketMatching()],
            })

            const view = new EditorView({
                state,
                parent: document.getElementById("editor"),
            })

            window.cmView = view
        </script>
    </body>
</html>

Switch your input method to a non‑English IME (e.g., Chinese).
Focus the editor and type a character (the first keystroke).
Observe the runtime error in the browser console.

index.js:1356 CodeMirror plugin crashed: RangeError: Position 5 is out of range for changeset of length 4
    at s.mapPos (index.js:758:19)
    at s.map (index.js:3101:33)
    at s.map (index.js:3236:45)
    at F.fromClass.decorations.update (index.js:1887:53)
    at jt.update (index.js:1467:32)
    at s.updatePlugins (index.js:8036:29)
    at s.update (index.js:7934:22)
    at s.dispatchTransactions (index.js:7833:28)
    at s.dispatch (index.js:7860:14)
    at as (index.js:4295:14)

Question
Is this a known limitation/expected behavior, or is it a bug? I can attach the exact console error message, stack trace, and/or a short screen recording if that would help.

Thank you.

Browser and platform

No response

Reproduction link

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions