From 0b7eba47fbcb853bedc557a61ea1f81902a652e4 Mon Sep 17 00:00:00 2001 From: "David W. Keith" Date: Fri, 17 Jul 2026 08:44:35 -0700 Subject: [PATCH 1/2] feat(config): make automatic quote substitution configurable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds SpellCheckingPolicy.automaticQuoteSubstitution (default true — behavior unchanged for existing embedders). Markdown-source embedders can now keep straight quotes; previously isAutomaticQuoteSubstitutionEnabled was hard-coded on in NativeTextViewWrapper and the autocorrect suppress-zone restore path. --- .../Configuration/MarkdownEditorConfiguration.swift | 8 +++++++- .../NativeTextViewCoordinator+Autocorrect.swift | 4 +++- .../MarkdownEngine/TextView/NativeTextViewWrapper.swift | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) 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 From f114653155693f5c54b18fb4c629a7cb81e83809 Mon Sep 17 00:00:00 2001 From: "David W. Keith" Date: Thu, 3 Sep 2026 10:49:01 -0700 Subject: [PATCH 2/2] test: cover SpellCheckingPolicy.automaticQuoteSubstitution Add default-value and custom-init coverage, and a CHANGELOG entry, for the automaticQuoteSubstitution toggle. --- CHANGELOG.md | 6 +++++ .../SpellCheckingPolicyTests.swift | 26 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 Tests/MarkdownEngineTests/SpellCheckingPolicyTests.swift 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/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) + } +}