feat: enable macOS autocorrect on the editor#150
Conversation
Adds autocorrect="on", autocapitalize="sentences", and spellcheck="true" to the ProseMirror contenteditable so WKWebView applies the user's system-level spelling correction and auto-capitalization, matching the behavior of Apple Notes. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdded native input attributes to the editor root element and registered macOS WebKit text-substitution / autocorrect defaults at app startup so the system-level WebView preferences are set before creating the webview. ChangesEditor Native Input Attributes
macOS WebView Defaults Registration
sequenceDiagram
participant App as Tauri App
participant Defaults as NSUserDefaults
participant WebView as WebKit WebView
App->>Defaults: register_webview_defaults() (build NSDictionary)
Defaults-->>App: defaults registered
App->>WebView: create webview (Tauri builder)
WebView->>Defaults: read registered defaults for text/autocorrect
WebView-->>App: webview initialized with macOS text prefs
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
WKWebView reads per-app NSUserDefaults to decide whether to render the spelling underline and apply auto-correct / smart-substitution inside contenteditable. These keys default to off for new bundle IDs, so the HTML spellcheck/autocorrect attributes alone produced no visible behavior. Register the WebKit defaults from Rust before the Tauri builder runs (setting them inside .setup() is too late). Uses registerDefaults so user toggles via the WebKit context menu still win. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src-tauri/src/lib.rs`:
- Around line 3649-3657: The registered defaults array named keys includes
substitution settings beyond spellcheck/autocorrect scope; trim it to only the
spelling/correction-related entries by removing
"WebAutomaticQuoteSubstitutionEnabled", "WebAutomaticDashSubstitutionEnabled",
"WebAutomaticTextReplacementEnabled", and "WebAutomaticLinkDetectionEnabled" so
keys contains only "WebContinuousSpellCheckingEnabled",
"WebGrammarCheckingEnabled", and "WebAutomaticSpellingCorrectionEnabled" (update
the keys array in lib.rs accordingly).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: dd08f2b7-50af-4f93-a67e-0c1ea56bcc4b
⛔ Files ignored due to path filters (1)
src-tauri/Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (2)
src-tauri/Cargo.tomlsrc-tauri/src/lib.rs
| let keys = [ | ||
| "WebContinuousSpellCheckingEnabled", | ||
| "WebGrammarCheckingEnabled", | ||
| "WebAutomaticSpellingCorrectionEnabled", | ||
| "WebAutomaticQuoteSubstitutionEnabled", | ||
| "WebAutomaticDashSubstitutionEnabled", | ||
| "WebAutomaticTextReplacementEnabled", | ||
| "WebAutomaticLinkDetectionEnabled", | ||
| ]; |
There was a problem hiding this comment.
Trim the registered defaults to the behaviors this PR is actually shipping.
Lines 3653-3656 also enable smart quotes, dash substitution, text replacement, and link detection. That is a broader behavior change than the spellcheck/autocorrect/autocapitalize scope in this PR, and in a markdown editor it can silently rewrite literal text or code-like content. I’d keep this list to the spelling/correction keys unless product explicitly wants the extra substitutions too.
Suggested diff
let keys = [
"WebContinuousSpellCheckingEnabled",
"WebGrammarCheckingEnabled",
"WebAutomaticSpellingCorrectionEnabled",
- "WebAutomaticQuoteSubstitutionEnabled",
- "WebAutomaticDashSubstitutionEnabled",
- "WebAutomaticTextReplacementEnabled",
- "WebAutomaticLinkDetectionEnabled",
];📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| let keys = [ | |
| "WebContinuousSpellCheckingEnabled", | |
| "WebGrammarCheckingEnabled", | |
| "WebAutomaticSpellingCorrectionEnabled", | |
| "WebAutomaticQuoteSubstitutionEnabled", | |
| "WebAutomaticDashSubstitutionEnabled", | |
| "WebAutomaticTextReplacementEnabled", | |
| "WebAutomaticLinkDetectionEnabled", | |
| ]; | |
| let keys = [ | |
| "WebContinuousSpellCheckingEnabled", | |
| "WebGrammarCheckingEnabled", | |
| "WebAutomaticSpellingCorrectionEnabled", | |
| ]; |
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src-tauri/src/lib.rs` around lines 3649 - 3657, The registered defaults array
named keys includes substitution settings beyond spellcheck/autocorrect scope;
trim it to only the spelling/correction-related entries by removing
"WebAutomaticQuoteSubstitutionEnabled", "WebAutomaticDashSubstitutionEnabled",
"WebAutomaticTextReplacementEnabled", and "WebAutomaticLinkDetectionEnabled" so
keys contains only "WebContinuousSpellCheckingEnabled",
"WebGrammarCheckingEnabled", and "WebAutomaticSpellingCorrectionEnabled" (update
the keys array in lib.rs accordingly).
Summary
Adds Apple Notes-style spellcheck and autocorrect to the editor. Two layers were needed:
spellcheck="true",autocorrect="on",autocapitalize="sentences"to the ProseMirror contenteditable.WebContinuousSpellCheckingEnabledandWebAutomaticSpellingCorrectionEnabledto decide whether to render the red underline and auto-replace. These keys default to off for new bundle IDs — that's why the HTML attributes alone weren't enough. WeregisterDefaultsfor the relevant WebKit keys at the very top ofrun()(setting them inside.setup()is too late, per tauri#7705).Defaults registered:
WebContinuousSpellCheckingEnabled— red wavy underline + checkWebGrammarCheckingEnabled— grammarWebAutomaticSpellingCorrectionEnabled— auto-replace misspellingsWebAutomaticQuoteSubstitutionEnabled— smart quotesWebAutomaticDashSubstitutionEnabled— em / en dashWebAutomaticTextReplacementEnabled— Text ReplacementWebAutomaticLinkDetectionEnabled— auto-detect URLsSource-mode textarea is intentionally left with
spellCheck={false}since it edits raw markdown.Closes #142
Why
registerDefaultsinstead ofsetBool_forKeyregisterDefaultsonly fills in values when the key isn't already set — so a user who right-clicks in the editor and unchecks "Correct Spelling Automatically" will have their preference persisted across launches. Forcing the value withsetBool_forKeywould override that choice on every startup.Notes
objc2/objc2-foundation(already transitive from Tauri/wry, just promoted to direct deps).com.scratch.app; if you've previously toggled WebKit context-menu items off, those choices win over the new defaults.Test plan
This is a sampl sentance wihh some typos so you can see if auto corret is working currectly.in a note — confirm misspellings get the red underline and that auto-replace fires (matches the Apple Notes GIF in macOS auto correct support like Apple Notes #142).hello.thenworldcapitalizes toWorld).cargo check+cargo clippy+ frontend build).🤖 Generated with Claude Code
Summary by CodeRabbit