fix(macos): TextInput Fabric commands - setGhostText, blur, and selection fixes#2912
Merged
Saadnajmi merged 8 commits intomicrosoft:mainfrom Apr 22, 2026
Merged
Conversation
- Add setGhostText command to Fabric TextInput native handler (was declared in JS but missing from native dispatch) - Port ghost text implementation from Paper to Fabric with proper Fabric API adaptations (NSRange selection, direct _backedTextInputView access) - Fix setTextAndSelection using notifyDelegate:YES instead of NO, matching Paper behavior to prevent spurious delegate callbacks - Add ghost text cleanup in textInputDidChange delegate - Add RNTesterPlayground test case for verifying TextInput ref and commands (focus, blur, clear, setSelection, setGhostText) - Add debug logging in setLocalRef to diagnose ref null issue - Add test assertions for setSelection and setGhostText methods Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Fix blur on Fabric: use currentEditor to detect focused NSTextField (field editor mismatch made blur a silent no-op) - Prevent ghost text from being selectable on Fabric by clearing it in textInputDidChangeSelection, matching Paper behavior - Remove TARGET_OS_OSX guard from setGhostText command dispatch (was causing compilation issues with preprocessor) - Remove temporary debug logging from TextInput.js setLocalRef - Add commented-out Paper blur fix for future testing Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
5 tasks
Removes the RNTesterPlayground interactive test and the commented-out Paper blur fix to keep the PR focused on Fabric TextInput command fixes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
47ee03f to
c5a26be
Compare
The command dispatch was calling [componentView setGhostText:] unconditionally, but the protocol method is only declared under #if TARGET_OS_OSX. This caused iOS and visionOS builds to fail with "no known instance method for selector". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
|
Try undo\redo -- e.g.
|
Ghost text insertion/removal was going through the undo manager, causing undo/redo to restore or remove ghost text unexpectedly. Wrap ghost text attributedText mutations in disableUndoRegistration/enableUndoRegistration to keep ghost text changes off the undo stack, matching Paper's behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Two ghost text bugs: 1. Undo would restore ghost text as real text because the undo manager's pre-edit snapshot contained ghost text. Fix: clear ghost text in textInputShouldChangeText BEFORE the edit, so the snapshot never includes ghost text. This matches Paper's approach. 2. Ghost text persisted after blur. Fix: clear ghost text in textInputDidEndEditing, matching Paper's behavior. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Remove disableUndoRegistration/enableUndoRegistration from ghost text handling — these were corrupting the undo manager state and breaking normal undo/redo. The real undo protection is clearing ghost text in textInputShouldChangeText (before the edit), so the undo manager's pre-edit snapshot never contains ghost text. Also skip breakUndoCoalescing in RCTUITextView when ghostTextChanging, so ghost text insertions/removals don't create undo coalescing breaks. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ghost text insertions/removals via setAttributedString: on the text storage were getting on the undo stack, causing Cmd+Z to undo the invisible ghost text change instead of the user's actual typing. Wrap the text storage mutation in disableUndoRegistration/ enableUndoRegistration specifically when ghostTextChanging, keeping it tightly scoped to avoid corrupting the undo manager state. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Collaborator
Author
As is, it blocks undos while ghost text is active. I think I'll leave it till we get further integration downstream. |
vmoroz
approved these changes
Apr 22, 2026
Saadnajmi
added a commit
that referenced
this pull request
Apr 22, 2026
…ion fixes (#2937) ## Summary Backport of #2912 to 0.81-stable. - **Add missing `setGhostText` command to Fabric**: Ghost text was implemented for Paper in #1890 / #1897 (with undo fixes in #2105 / #2106), but the Fabric command dispatcher and component view never got the implementation. This ports the ghost text logic (insertion, removal, attributes, delegate cleanup) from `RCTBaseTextInputView` to `RCTTextInputComponentView`. - **Fix `blur` command on macOS Fabric**: `blur` was a silent no-op because it compared `[window firstResponder]` against the NSTextField, but on macOS the firstResponder during editing is the field editor (NSTextView), not the text field itself. Fixed by checking `currentEditor` on NSTextField. - **Fix ghost text being selectable on Fabric**: Ghost text could be selected by the user on Fabric (but not Paper). Added cleanup in `textInputDidChangeSelection` to clear ghost text when the user changes selection, matching Paper behavior. - **Fix `setTextAndSelection` delegate notification**: Changed `notifyDelegate:YES` to `notifyDelegate:NO` to match Paper's `setSelectionStart:selectionEnd:` behavior and prevent spurious delegate callbacks during programmatic selection changes. ## Test plan - [x] Verified `setGhostText` command works via RNTester on macOS Fabric - [x] Verified `blur` command works on macOS Fabric - [x] Verified ghost text is not selectable on Fabric - [x] Verified `focus`, `clear`, `setSelection` commands still work - [x] JS TextInput tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 <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.
Summary
TextInput commands (
setGhostText,blur,setSelection) don't work correctly under Fabric on macOS. This PR fixes three issues:setGhostTextcommand to Fabric: Ghost text was implemented for Paper in [iOS/macOS] [TextInput] Implement ghost text #1890 / [iOS/macOS] [TextInput] Implement ghost text #1897 (with undo fixes in Ensure ghost text doesn't appear when performing undos #2105 / [0.73-stable] Ensure ghost text doesn't appear when performing undos #2106), but the Fabric command dispatcher and component view never got the implementation. This ports the ghost text logic (insertion, removal, attributes, delegate cleanup) fromRCTBaseTextInputViewtoRCTTextInputComponentView.blurcommand on macOS Fabric:blurwas a silent no-op because it compared[window firstResponder]against the NSTextField, but on macOS the firstResponder during editing is the field editor (NSTextView), not the text field itself. Fixed by checkingcurrentEditoron NSTextField.textInputDidChangeSelectionto clear ghost text when the user changes selection, matching Paper behavior.setTextAndSelectiondelegate notification: ChangednotifyDelegate:YEStonotifyDelegate:NOto match Paper'ssetSelectionStart:selectionEnd:behavior and prevent spurious delegate callbacks during programmatic selection changes.Test plan
setGhostTextcommand works via RNTester on macOS Fabricblurcommand works on macOS Fabricfocus,clear,setSelectioncommands still work🤖 Generated with Claude Code