• 
      

    Add the CodeMirror Speak-and-Spell plugin code.

    Review Request #14475 — Created June 25, 2025 and submitted

    Information

    codemirror-speak-and-spell
    master

    Reviewers

    This is the full plugin for CodeMirror Speak-and-Spell for CodeMirror 5.
    It allows native browser/OS features such as spell checking,
    speech-to-text, AI-assisted writing/rewriting, and other text
    replacements to work with CodeMirror.

    It does this by intercepting the beforeinput events emitted by the
    browser before any text would be inserted or replaced, canceling the
    change, and then replaying the same change using CodeMirror's API.

    By doing it this way, we avoid the thrashing that occurs with
    CodeMirror's own attempts at supporting these features. Normally,
    CodeMirror will listen for an input change and then wait 40ms before
    relaying changes back into CodeMirror, but in practice this doesn't
    consistently work. It's okay on Firefox, but has a tendency to undo
    replaced changes on Chrome and Safari. Taking the browser's DOM
    manipulations out of the equation removes the source of this problem
    entirely.

    A sample file has been provided to experience the plugin on different
    browsers.

    Tested Chrome, Firefox, and Safari with both the sample page and with
    the plugin used in Review Board.

    My tests involved the following on each:

    1. General typing and text formatting using Review Board's toolbar.
    2. Inline spelling/grammar suggestions with text replaced.
    3. Dialog-based spelling/grammar suggestions with replacements.
    4. Safari's text transformations (Capitalize, Make Upper Case, Make Lower Case).
    5. AI-assisted writing, re-writing, and summarizations.
    6. Speech-to-text.

    These were tested at various places within a test document. I checked
    that this all worked regardless of where the cursor was.

    Unlike with default behavior, I didn't see any document thrashing at any
    point, or any data loss.

    Summary ID
    Add the CodeMirror Speak-and-Spell plugin code.
    This is the full plugin for CodeMirror Speak-and-Spell for CodeMirror 5. It allows native browser/OS features such as spell checking, speech-to-text, AI-assisted writing/rewriting, and other text replacements to work with CodeMirror. It does this by intercepting the `beforeinput` events emitted by the browser before any text would be inserted or replaced, canceling the change, and then replaying the same change using CodeMirror's API. By doing it this way, we avoid the thrashing that occurs with CodeMirror's own attempts at supporting these features. Normally, CodeMirror will listen for an `input` change and then wait 40ms before relaying changes back into CodeMirror, but in practice this doesn't consistently work. It's okay on Firefox, but has a tendency to undo replaced changes on Chrome and Safari. Taking the browser's DOM manipulations out of the equation removes the source of this problem entirely. A sample file has been provided to experience the plugin on different browsers.
    c561bbe98153c5499fee18ef23f03f603c7fceed
    Description From Last Updated

    Do we need the cmOps.ts file? It's just an exact copy of cmUtils.ts

    maubinmaubin
    maubin
    1. 
        
    2. Show all issues

      Do we need the cmOps.ts file? It's just an exact copy of cmUtils.ts

      1. Hmm, I renamed it but must have messed something up.

    3. 
        
    chipx86
    maubin
    1. Ship It!
    2. 
        
    chipx86
    Review request changed
    Status:
    Completed