microsoft / react-native-macos

A framework for building native macOS apps with React.
https://microsoft.github.io/react-native-windows/
MIT License
3.37k stars 129 forks source link

Ensure ghost text doesn't appear when performing undos #2105

Closed amgleitman closed 3 months ago

amgleitman commented 3 months ago

Summary:

Right now, the ghost text feature is quite incompatible with undo/redo support. Since we weren't filtering out ghost text from a text input's contents when registering undoable actions, we were susceptible to a bunch of weird side effects, such as ghost text becoming editable or even crashes.

The fix here is to make sure any undoable actions ignore ghost text. Ghost text is very transient and is designed to disappear as soon as you make any sort of change, so the easiest way to do this is to just remove it directly before doing anything.

A related issue pops up where a write to setAttributedText: also triggers a call to set the ghost text to nil. Since setAttributedText: already gets rid of the ghost text when we ask it to, the subsequent call to setGhostText: may not need any action. We solve this by being more lenient in this case, assuming that if the ghost text isn't in where our internal state expects it to be, we probably already removed it.

Test Plan:

Validated that ghost text behaves properly against the following scenarios: