Files
Outpost/Vendor/swift-markdown-engine/Sources/MarkdownEngine/TextView/NativeTextView/NativeTextView+SpellingPolicy.swift
T
Puranjay Savar Mattas 6e1ffb96fd chore: vendor swift-markdown-engine as plain tracked source
Convert from git submodule to plain vendored copy. No push access to
upstream nodes-app/swift-markdown-engine meant our local fix commit
(05c1720) was stranded and unreachable from any remote on fresh
clones/CI. Vendoring as plain files folds it into normal repo history
instead.
2026-08-20 13:26:13 +01:00

47 lines
1.9 KiB
Swift

//
// NativeTextView+SpellingPolicy.swift
// MarkdownEngine
//
// Created by Luca Chen on 16.03.26.
//
// Spell-check suppression inside code spans, code blocks, LaTeX, and other
// coordinator-flagged tokens — anything that should be exempt from the
// default underline pass.
//
import AppKit
extension NativeTextView {
override func setSpellingState(_ value: Int, range charRange: NSRange) {
// Spell-checker callback — fires from AppKit, potentially several
// times per keystroke, and does full-document contains() scans below;
// accumulate so the cost shows up in the PERF frame.
PerfTrace.accumulate("spellCb") { applySpellingPolicy(value, range: charRange) }
}
private func applySpellingPolicy(_ value: Int, range charRange: NSRange) {
let coordinator = delegate as? NativeTextViewCoordinator
if value != 0 {
if self.string.contains("`") {
let inCode = coordinator?.isInsideCode(range: charRange, in: self.string)
?? MarkdownDetection.isInsideCodeBlock(range: charRange, in: self.string, registry: self.configuration.extensionRegistry)
if inCode {
return
}
}
if self.string.contains("$") {
let inLatex = coordinator?.isInsideLatex(location: charRange.location, in: self.string)
?? MarkdownDetection.isInsideLatex(location: charRange.location, in: self.string, registry: self.configuration.extensionRegistry)
if inLatex {
return
}
}
let inSpellcheckSuppressedToken = coordinator?.isInsideSpellcheckSuppressedToken(range: charRange, in: self.string) ?? false
if inSpellcheckSuppressedToken {
return
}
}
super.setSpellingState(value, range: charRange)
}
}