Persist user's spell/grammar toggle across caret movement#36
Merged
luca-chen198 merged 1 commit intoMay 19, 2026
Conversation
Closes #34. `updateAutocorrectSettings` ran on every selection change and unconditionally restored the three spell-related flags to `true` when the caret left a code/LaTeX/link suppress zone, overwriting a manual "off" set via the context menu. `makeNSView` also hardcoded the initial state to `true` with no way for embedders to seed it or observe changes. - Add `SpellCheckingPolicy` to `MarkdownEditorConfiguration` so the initial state of the three toggles can be configured. - Track the user's preference on `NativeTextViewCoordinator` and update it from new `toggleContinuousSpellChecking` / `toggleGrammarChecking` / `toggleAutomaticSpellingCorrection` overrides on `NativeTextView`. - In the restore branch of `updateAutocorrectSettings`, use the tracked preference instead of hardcoded `true`. Suppress-zone path unchanged. - Expose `onSpellCheckingPolicyChanged` on `NativeTextViewWrapper` so embedders can persist the policy and feed it back via configuration on the next launch. Default `MarkdownEditorConfiguration.spellChecking` keeps the previous all-on behavior, so existing callers see no change. Quote substitution has the same caret-movement bug pattern and is deliberately left for a follow-up issue.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #34.
Summary
updateAutocorrectSettingsno longer overwrites the user's manual "off" when the caret leaves a code/LaTeX/link suppress zone. The restore branch reads a per-coordinator preference instead of hardcodedtrue.SpellCheckingPolicyonMarkdownEditorConfigurationlets embedders seed initial state. NewonSpellCheckingPolicyChangedcallback onNativeTextViewWrapperlets them persist user toggles (e.g. toUserDefaults) and feed the value back on next launch.NativeTextViewoverridestoggleContinuousSpellChecking(_:),toggleGrammarChecking(_:), andtoggleAutomaticSpellingCorrection(_:)to capture context-menu toggles into the coordinator state.Defaults match prior behavior —
SpellCheckingPolicy.defaultis all-on, so existing callers see no change.Files
Configuration/MarkdownEditorConfiguration.swift—SpellCheckingPolicystruct +spellCheckingfield.TextView/Coordinator/NativeTextViewCoordinator.swift—userPrefers*mirror,onSpellCheckingPolicyChangedcallback,didToggleSpellCheckingPolicy(textView:)handler.TextView/Coordinator/NativeTextViewCoordinator+Autocorrect.swift— restore branch honorsuserPrefers*. Suppress-zone path unchanged.TextView/NativeTextView/NativeTextView+SpellingToggles.swift— new file, AppKit toggle action overrides.TextView/NativeTextViewWrapper.swift—makeNSViewreads fromconfiguration.spellChecking; new init param threads the callback throughmakeCoordinator.Embedder usage
Test plan
spellCheckingoverride) behaves identically tomain— all three toggles on at launch.swift buildandswift testclean.Out of scope
Smart Quotes (
isAutomaticQuoteSubstitutionEnabled) has the same caret-movement bug pattern. Tracked separately.