diff --git a/CHANGELOG.md b/CHANGELOG.md index 58fbc83f..bd0f2572 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added +- **`SpellCheckingPolicy.automaticQuoteSubstitution`**: makes + `NSTextView.isAutomaticQuoteSubstitutionEnabled` configurable instead of + hard-coded on. Some Markdown sources need straight quotes throughout + (frontmatter, code-adjacent prose) where automatic curly-quote substitution + would corrupt the source. Defaults to `true`, preserving the prior + always-on behavior. - **Directive seam (parsing)**: opt-in named inline commands with typed arguments, for constructs that need a name and parameters rather than delimiters. A `MarkdownDirective` declares a name, a form — self-contained diff --git a/Sources/MarkdownEngine/Configuration/MarkdownEditorConfiguration.swift b/Sources/MarkdownEngine/Configuration/MarkdownEditorConfiguration.swift index 2f90699d..2b2a10ec 100644 --- a/Sources/MarkdownEngine/Configuration/MarkdownEditorConfiguration.swift +++ b/Sources/MarkdownEngine/Configuration/MarkdownEditorConfiguration.swift @@ -167,15 +167,21 @@ public struct SpellCheckingPolicy: Sendable { public var grammarChecking: Bool /// Mirrors `NSTextView.isAutomaticSpellingCorrectionEnabled`. public var automaticSpellingCorrection: Bool + /// Mirrors `NSTextView.isAutomaticQuoteSubstitutionEnabled`. Markdown sources + /// sometimes need straight quotes throughout (frontmatter, code-adjacent prose); + /// `true` preserves the historical always-on behavior. + public var automaticQuoteSubstitution: Bool public init( continuousSpellChecking: Bool = true, grammarChecking: Bool = true, - automaticSpellingCorrection: Bool = true + automaticSpellingCorrection: Bool = true, + automaticQuoteSubstitution: Bool = true ) { self.continuousSpellChecking = continuousSpellChecking self.grammarChecking = grammarChecking self.automaticSpellingCorrection = automaticSpellingCorrection + self.automaticQuoteSubstitution = automaticQuoteSubstitution } public static let `default` = SpellCheckingPolicy() diff --git a/Sources/MarkdownEngine/TextView/Coordinator/NativeTextViewCoordinator+Autocorrect.swift b/Sources/MarkdownEngine/TextView/Coordinator/NativeTextViewCoordinator+Autocorrect.swift index 389ad527..a89a40f7 100644 --- a/Sources/MarkdownEngine/TextView/Coordinator/NativeTextViewCoordinator+Autocorrect.swift +++ b/Sources/MarkdownEngine/TextView/Coordinator/NativeTextViewCoordinator+Autocorrect.swift @@ -62,7 +62,9 @@ extension NativeTextViewCoordinator { textView.isGrammarCheckingEnabled = shouldDisableSpelling ? false : userPrefersGrammarChecking - textView.isAutomaticQuoteSubstitutionEnabled = !shouldDisableSpelling + textView.isAutomaticQuoteSubstitutionEnabled = shouldDisableSpelling + ? false + : configuration.spellChecking.automaticQuoteSubstitution textView.isAutomaticDashSubstitutionEnabled = false } diff --git a/Sources/MarkdownEngine/TextView/NativeTextViewWrapper.swift b/Sources/MarkdownEngine/TextView/NativeTextViewWrapper.swift index e081003e..0c8fd329 100644 --- a/Sources/MarkdownEngine/TextView/NativeTextViewWrapper.swift +++ b/Sources/MarkdownEngine/TextView/NativeTextViewWrapper.swift @@ -286,7 +286,7 @@ public struct NativeTextViewWrapper: NSViewRepresentable { textView.isAutomaticSpellingCorrectionEnabled = configuration.spellChecking.automaticSpellingCorrection textView.isContinuousSpellCheckingEnabled = configuration.spellChecking.continuousSpellChecking textView.isGrammarCheckingEnabled = configuration.spellChecking.grammarChecking - textView.isAutomaticQuoteSubstitutionEnabled = true + textView.isAutomaticQuoteSubstitutionEnabled = configuration.spellChecking.automaticQuoteSubstitution textView.isAutomaticDataDetectionEnabled = true textView.isAutomaticDashSubstitutionEnabled = false textView.onPasteImage = onPasteImage diff --git a/Tests/MarkdownEngineTests/SpellCheckingPolicyTests.swift b/Tests/MarkdownEngineTests/SpellCheckingPolicyTests.swift new file mode 100644 index 00000000..45ee73dc --- /dev/null +++ b/Tests/MarkdownEngineTests/SpellCheckingPolicyTests.swift @@ -0,0 +1,26 @@ +// +// SpellCheckingPolicyTests.swift +// MarkdownEngineTests +// + +import Testing +@testable import MarkdownEngine + +@Suite("SpellCheckingPolicy") +struct SpellCheckingPolicyTests { + @Test("automaticQuoteSubstitution defaults to true, preserving prior always-on behavior") + func defaultsToEnabled() { + let policy = SpellCheckingPolicy() + #expect(policy.automaticQuoteSubstitution == true) + #expect(SpellCheckingPolicy.default.automaticQuoteSubstitution == true) + } + + @Test("automaticQuoteSubstitution can be disabled independently of the other toggles") + func canBeDisabled() { + let policy = SpellCheckingPolicy(automaticQuoteSubstitution: false) + #expect(policy.automaticQuoteSubstitution == false) + #expect(policy.continuousSpellChecking == true) + #expect(policy.grammarChecking == true) + #expect(policy.automaticSpellingCorrection == true) + } +}