-
Notifications
You must be signed in to change notification settings - Fork 0
SpellCheckAdorner
The SpellCheckAdorner draws red squiggles under the misspelled words of the
MarkdownRichEditor's Visual Document. It replaces WPF's built-in spell
check, which cannot segment code-like identifiers and so flags the whole of
this.ShouldBe().Invld() instead of only the genuinely misspelled part.
-
Class:
UI.Controls.SpellCheckAdorner(derives fromSystem.Windows.Documents.Adorner) -
Attached by:
MarkdownRichEditoronLoaded, into the editor'sAdornerLayer.
WPF's SpellCheck.IsEnabled is control-level and offers no per-run opt-out and no control over word
segmentation. Two things follow that it cannot do:
-
Exclude code. Handled at projection time — code runs carry the language tag
zxx(no linguistic content); this adorner skips any run so tagged. -
Segment identifiers.
this.ShouldBe().Invld()must break intothis/Should/Be/Invldso each is judged on its own and onlyInvldis flagged. That segmentation is the camelCase- and punctuation-awareWordTokenizer; the dictionary lookups come fromSpellCheckScannerover anISpellDictionary(the OS speller, viaWindowsSpellDictionary).
-
Scan (debounced). On
TextChangedthe adorner clears its ranges, then — once edits settle — walks the document's prose runs (into sections, lists, tables, and spans), runs the scanner over each, and stores aTextRangeper misspelling. The dictionary pass runs only here. -
Paint (cheap).
OnRenderdraws a squiggle under each stored range that is on-screen. Scrolling and resizing only repaint from the existing ranges — they never re-run the dictionary, so scrolling stays cheap. -
Graceful degradation. If the OS speller is unavailable,
WindowsSpellDictionaryreports every word as correct, so no squiggles appear and nothing fails.
The adorner does not paint the squiggles interactively (IsHitTestVisible = false), but it does own
the authoritative list of Misspelling ranges, so it answers one query for the editor:
MisspellingAt(TextPointer) returns the Misspelling under a point, or null. On a right-click the
MarkdownRichEditor uses it to decide whether to head the Editor Context Menu
with Spelling Suggestions — SpellingSuggestions.For(word, dictionary) over the same
ISpellDictionary, gathered into the menu by EditorContextMenu.Fill. Choosing a suggestion replaces
the Misspelling's span, which Captures back into the Markdown source like any other edit. Painting
itself never changes the source.
The editor must own a ContextMenu object from construction for any of this to be reachable: WPF's
built-in text-editor context menu is a class handler on ContextMenuOpening, so it runs before the
editor's own handler, and finding no menu it opens its own and marks the event handled — leaving the
Spelling Suggestions permanently unseen. The menu is therefore created once and only ever refilled
(INV-057).
LiveMarkDownEditor
User guide
- Getting Started
- Writing and Formatting
- Tables
- Diagrams
- Files, Folders and Tabs
- Finding and Navigating
- Panels and Layout
- Live Updates and Conflicts
- Pages, Printing and Export
- Spell Check
- Keyboard Shortcuts
Controls
- MarkdownRichEditor
- PageView
- DocumentSheetBackdrop
- PrintPreviewPages
- EditorGutter
- SourceGutter
- OutlinePanel
- FolderPanel
- PanelHeader
- PanelColumn
- CommandBarPanel
- CommandTip
- FindHighlightAdorner
- SpellCheckAdorner
- CodeShadingAdorner
- ChangeHighlightAdorner
- MermaidPreview
- MermaidDiagramView
- DiagramCanvas
- VideoPlayerView