Skip to content

Instantly share code, notes, and snippets.

@krzyzanowskim
Created June 19, 2025 23:11
Show Gist options
  • Save krzyzanowskim/4b1557a29bdd37b9dfc13215d561dc07 to your computer and use it in GitHub Desktop.
Save krzyzanowskim/4b1557a29bdd37b9dfc13215d561dc07 to your computer and use it in GitHub Desktop.
DummyTextCheckingClient
import Foundation
import Cocoa
class DummyTextCheckingClient: NSObject, NSTextCheckingClient, NSTextInputClient {
func handle(_ textCheckingResult: NSTextCheckingResult, for string: String, in range: NSRange, types checkingTypes: NSTextCheckingTypes, options: [NSSpellChecker.OptionKey : Any] = [:], orthography: NSOrthography?, wordCount: Int) {}
func string(at index: Int, effectiveRange: NSRangePointer?) -> String? { return nil }
func conversationIdentifier() -> Any? { return nil }
func documentURL() -> URL? { return nil }
func documentRange() -> NSRange { return NSRange(location: 0, length: 0) }
func isEditable() -> Bool { return false }
func firstSelectedRange() -> NSRange { return NSRange(location: 0, length: 0) }
func selectedRange() -> NSRange { return NSRange(location: 0, length: 0) }
func shouldChangeText(in affectedCharRange: NSRange, replacementString: String?) -> Bool { return false }
func didChangeText(in affectedCharRange: NSRange, replacementString: String?) {}
func supportsTextChecking() -> Bool { return false }
func attributedString() -> NSAttributedString { return NSAttributedString(string: "") }
func setMarkedText(_ markedText: Any, selectedRange: NSRange, replacementRange: NSRange) {}
func unmarkText() {}
func hasMarkedText() -> Bool { return false }
func markedRange() -> NSRange { return NSRange(location: NSNotFound, length: 0) }
func validAttributesForMarkedText() -> [NSAttributedString.Key] { return [] }
func layoutManager() -> NSLayoutManager? { return nil }
func insertText(_ string: Any, replacementRange: NSRange) {}
func doCommand(by selector: Selector) {}
func annotatedSubstring(forProposedRange range: NSRange, actualRange: NSRangePointer?) -> NSAttributedString? { return nil }
func setAnnotations(_ annotations: [NSAttributedString.Key : String], range: NSRange) {}
func addAnnotations(_ annotations: [NSAttributedString.Key : String], range: NSRange) {}
func removeAnnotation(_ annotationName: NSAttributedString.Key, range: NSRange) {}
func replaceCharacters(in range: NSRange, withAnnotatedString annotatedString: NSAttributedString) {}
func selectAndShow(_ range: NSRange) {}
func view(for range: NSRange, firstRect: NSRectPointer?, actualRange: NSRangePointer?) -> NSView? { return nil }
func candidateListTouchBarItem() -> NSCandidateListTouchBarItem<AnyObject>? { return nil }
func attributedSubstring(forProposedRange range: NSRange, actualRange: NSRangePointer?) -> NSAttributedString? { return nil }
func firstRect(forCharacterRange range: NSRange, actualRange: NSRangePointer?) -> NSRect { return NSRect.zero }
func characterIndex(for point: NSPoint) -> Int { return 0 }
}
let controller = NSTextCheckingController(client: DummyTextCheckingClient())
for attribute in controller.validAnnotations() {
print(attribute.rawValue)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment