Skip to content

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

Open
Saadnajmi wants to merge 4 commits intomicrosoft:mainfrom
Saadnajmi:t3code/fabric-textinput-refs
Open

fix(macos): TextInput Fabric commands - setGhostText, blur, and selection fixes#2912
Saadnajmi wants to merge 4 commits intomicrosoft:mainfrom
Saadnajmi:t3code/fabric-textinput-refs

Conversation

@Saadnajmi
Copy link
Copy Markdown
Collaborator

@Saadnajmi Saadnajmi commented Apr 10, 2026

Summary

TextInput commands (setGhostText, blur, setSelection) don't work correctly under Fabric on macOS. This PR fixes three issues:

  • 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

- 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>
@Saadnajmi Saadnajmi changed the title fix(fabric): implement missing TextInput commands for macOS fix(macos): TextInput Fabric commands - setGhostText, blur, and selection fixes Apr 18, 2026
- 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>
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 t3code/fabric-textinput-refs branch from 47ee03f to c5a26be Compare April 18, 2026 20:42
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>
@nakambo
Copy link
Copy Markdown
Collaborator

nakambo commented Apr 20, 2026

Try undo\redo -- e.g.

  • with ghost text showing (and valid undo record), perform undo -- check that ghost text goes away, and undo works as expected. Try redo.
  • with ghost text showing do something to remove it (e.g. move IP), perform undo -- check ghost text doesn't come back. Try redo.
  • try multiple undo\redo's, even when no valid record (check for ObjC exceptions being thrown\RN asserts firing)

@Saadnajmi Saadnajmi marked this pull request as ready for review April 21, 2026 19:11
@Saadnajmi Saadnajmi requested a review from a team as a code owner April 21, 2026 19:11
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