Ensure ghost text doesn't appear when performing undos #2105
+57
−24
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:
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 tonil
. SincesetAttributedText:
already gets rid of the ghost text when we ask it to, the subsequent call tosetGhostText:
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: