Repository navigation
Drop the autocorrection underline on a document switch - #198
Merged
Merged
Conversation
AppKit's blue underline under an autocorrected word belongs to the text view: an NSCorrectionIndicatorUnderlineView over it, and a range the text view's NSTextCheckingController tracks. The editor shows every note in one view and swaps the text, so the outgoing note's underline stood over the incoming one for about half a second, and its range moved into the new text and drew a line across it that was still there after 4 s (device log). The switch now asks the text checking controller to remove its underlines, next to the wide-table overlays it already drops. Both the controller and the call are private, so each step is guarded by responds(to:). The public NSSpellChecker.dismissCorrectionIndicator(for:) and toggling autocorrection leave the underline up; removing it through NSSpellChecker leaves the range. The test puts an underline up the way a correction does, swaps the text and expects neither the view nor the range to remain. 585 tests pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Type a word that autocorrects (the blue underline appears), then switch to another document: the underline stays over the incoming document for about half a second. Sometimes it then reappears as a line across the new text and stays there (still up after 4 s in the device log).
Root cause
The underline belongs to the text view, not to the document. AppKit draws an
NSCorrectionIndicatorUnderlineViewinto the text view, and the text view'sNSTextCheckingControllertracks the corrected range. The editor shows every document in oneNativeTextViewand swaps the text on a switch. Nothing told AppKit the corrected word was gone, so the view stayed and the tracked range moved into the new text.Fix
The switch branch of
updateNSViewnow callsNativeTextView.removeCorrectionUnderlines(), next toremoveAllWideTableOverlays(). It asks the text checking controller toremoveCorrectionIndicatorUnderlines. Both the controller (textCheckingControlleronNSTextView) and the call are private, so each step is guarded byresponds(to:). If a future macOS drops either, nothing happens.Measured before choosing this call:
NSSpellChecker.dismissCorrectionIndicator(for:)(public) and togglingisAutomaticSpellingCorrectionEnabledleave the underline up.NSSpellChecker'sremoveCorrectionIndicatorUnderlinesForView:removes the view but the controller keeps the range.removeCorrectionIndicatorUnderlinesremoves both.Typing is untouched: the call runs only on a document switch.
Tests
CorrectionUnderlineTests: puts an underline up the way a correction does (through the controller), swaps the text, and expects neither the view nor the tracked range to remain. It fails with an emptyremoveCorrectionUnderlines().🤖 Generated with Claude Code