Skip to content
Source
Sign inSign up
pingdotgg/t3code

Fix native composer spellcheck #4254

Closedbadcuban(GitHub profile, opens in a new tab)wants to merge 2 commits intomain fromrefs/pull/4254/headopened View on GitHub

Closes #4253

What Changed

  • Let trusted insertReplacementText edits run through the browser's native editing path so accepted spelling corrections remain synchronized with Lexical.
  • Patch Lexical 0.41's development and production bundles to reconcile text with minimal DOM mutations, preserving Blink spelling markers on untouched text.
  • Enable spellcheck explicitly on the composer.
  • On macOS desktop, fall back to NSSpellChecker when Electron reports a misspelled word with no dictionary suggestions. Existing Electron suggestions remain the first choice on every platform.
  • Refocus the editor after accepting a desktop spelling suggestion.

Why

Lexical normally converts spelling corrections into controlled replacements and can rewrite the complete text node during reconciliation. Blink treats those script mutations differently from native editing: existing spelling markers can disappear, and the remaining text is not rechecked until another real keystroke.

Electron can also emit a context-menu event with a misspelledWord but an empty dictionarySuggestions array on macOS, even when the system spellchecker has useful candidates. For example, NSSpellChecker suggests texting, testing, toting, teeing, and tenting for teting.

This keeps native spelling state attached to the composer and recovers the operating system's suggestions when Chromium omits them.

UI Changes

There is no layout or styling change. The interaction changes are:

  • Before: accepting one correction could clear the other spelling underlines until the next keystroke.
  • After: remaining underlines stay active and the edited text is rechecked immediately.
  • Before: the macOS desktop context menu could show No suggestions for a word the system checker can correct.
  • After: the menu uses the system suggestions as a fallback.

TODO before marking ready for review: attach a short before/after recording of the native context-menu interaction.

Validation

  • vp fmt --check on all changed source/config files
  • vp lint on all changed TypeScript/TSX files
  • vp run --filter @t3tools/web --filter @t3tools/desktop typecheck
  • vp test run src/components/ComposerPromptEditor.test.ts in apps/web
  • vp test run src/electron/ElectronSpelling.test.ts src/window/DesktopWindow.test.ts in apps/desktop (27 tests)
  • Production web build
  • Isolated web composer verification for spellcheck attributes, native replacement synchronization, and editor stability
  • Electron desktop development build and startup on macOS
  • Direct macOS NSSpellChecker verification for the teting suggestion case

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Note

Fix native spellcheck in the composer by recovering macOS suggestions and intercepting replacement events

  • Adds a ComposerNativeSpellcheckReplacementPlugin in ComposerPromptEditor.tsx that intercepts beforeinput events of type insertReplacementText at capture phase and stops propagation, letting Blink handle replacements natively so spelling underlines are maintained.
  • Introduces an ElectronSpelling service in ElectronSpelling.ts that spawns osascript (JXA) to query NSSpellChecker on macOS, with a 250ms timeout and a cap of 10 unique suggestions.
  • Reworks the context-menu handler in DesktopWindow.ts to fetch platform suggestions asynchronously when Chromium provides none, shows only the most recent menu when requests overlap, and focuses webContents after accepting a suggestion.
  • Patches lexical@0.41.0 to always use diffComposedText in setTextContent, fixing spelling underline rescheduling in Blink.
  • Risk: the osascript subprocess adds up to 250ms latency to context-menu display on macOS when Chromium has no suggestions.
Macroscope summarized ada34a4.

Note

Medium Risk Changes composer input event handling and desktop context-menu async behavior; macOS spawns short-lived osascript processes for spell lookups.

Overview Fixes native spellcheck in the composer and on macOS desktop when Chromium omits suggestions.

Web composer: Adds ComposerNativeSpellcheckReplacementPlugin, which captures trusted insertReplacementText on the editor host so spelling corrections use the browser’s native editing path instead of Lexical’s controlled beforeinput handling—keeping Blink spell markers and immediate re-check. Enables spellCheck on the composer ContentEditable.

macOS desktop: Introduces ElectronSpelling, which queries NSSpellChecker via osascript (250ms timeout, capped suggestions) when Electron reports a misspelled word with empty dictionarySuggestions. The context menu is built asynchronously with request versioning so only the latest spelling menu opens; accepting a suggestion calls replaceMisspelling and refocuses the editor.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit ada34a4df96d30bac576cebb7421f33b58501b32. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro

      Run ID: 959a856e-1dfc-40ac-93bf-a37338f2155d

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched

    3. Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

      Fix All in Cursor ❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the [Cursor dashboard](https://www.cursor.com/dashboard/bugbot).

      Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 180ac82318de234d8213925a62ed914693f65627. Configure [here](https://www.cursor.com/dashboard/bugbot).
    4. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Needs human review

      Diff is too large for automated approval analysis. A human reviewer should evaluate this PR.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    5. Note

      🤖 GPT-5.6 Sol responding on behalf of Theo

      We're closing this PR as we clean up the T3 Code backlog. Thank you for taking the time to put this together.

      This branch enables native spellcheck, but #7745 includes that editor work plus saved language selection and Electron spelling setup. We are keeping the complete implementation instead of this partial path.

      If you believe we closed this in error, please reopen the PR and leave a comment explaining what we missed.

Sign in to join this conversation.