Skip to content

fix(0.81, macos): TextInput Fabric commands - setGhostText, blur, and selection fixes#2937

Merged
Saadnajmi merged 8 commits intomicrosoft:0.81-stablefrom
Saadnajmi:0.81/fabric-textinput-refs
Apr 22, 2026
Merged

fix(0.81, macos): TextInput Fabric commands - setGhostText, blur, and selection fixes#2937
Saadnajmi merged 8 commits intomicrosoft:0.81-stablefrom
Saadnajmi:0.81/fabric-textinput-refs

Conversation

@Saadnajmi
Copy link
Copy Markdown
Collaborator

@Saadnajmi Saadnajmi commented Apr 18, 2026

Summary

Backport of #2912 to 0.81-stable.

  • Add missing setGhostText command 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) 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

  • Verified setGhostText command works via RNTester on macOS Fabric
  • Verified blur command works on macOS Fabric
  • Verified ghost text is not selectable on Fabric
  • Verified focus, clear, setSelection commands still work
  • JS TextInput tests pass

🤖 Generated with Claude Code

Saadnajmi and others added 2 commits April 18, 2026 13:26
- 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>
@Saadnajmi Saadnajmi requested a review from a team as a code owner April 18, 2026 20:26
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>
@Saadnajmi Saadnajmi force-pushed the 0.81/fabric-textinput-refs branch from bc6be17 to 9da4c7d Compare April 18, 2026 20:42
Saadnajmi and others added 5 commits April 18, 2026 14:20
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>
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>
@Saadnajmi Saadnajmi merged commit c424c38 into microsoft:0.81-stable Apr 22, 2026
24 checks passed
@Saadnajmi Saadnajmi deleted the 0.81/fabric-textinput-refs branch April 22, 2026 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants