Skip to content

Commit

Permalink
Add clarifying comments about removingGhostTextFromString:strict: n…
Browse files Browse the repository at this point in the history
…il checks
  • Loading branch information
Adam Gleitman committed Apr 3, 2024
1 parent 5b951f7 commit 3c44bcc
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,8 @@ - (void)setAttributedText:(NSAttributedString *)attributedText

// Ghost text changes should not be part of the undo stack
if (!self.backedTextInputView.ghostTextChanging) {
// If there was ghost text previously, we don't want it showing up if we undo
// If there was ghost text previously, we don't want it showing up if we undo.
// If something goes wrong when trying to remove it, just stick with oldAttributedText.
NSAttributedString *oldAttributedTextWithoutGhostText = [self removingGhostTextFromString:oldAttributedText strict:YES] ?: oldAttributedText;
[self.backedTextInputView.undoManager registerUndoWithTarget:self handler:^(RCTBaseTextInputView *strongSelf) {
strongSelf.attributedText = oldAttributedTextWithoutGhostText;
Expand Down Expand Up @@ -1008,8 +1009,11 @@ - (void)setGhostText:(NSString *)ghostText {

/**
* Attempts to remove the ghost text from a provided string given our current state.
*
* If `strict` mode is enabled, this method assumes the ghost text exists exactly
* where we expect it to be, and we assert if this turns out to not be the case.
* where we expect it to be. We assert and return `nil` if we don't find the expected ghost text.
* It's the responsibility of the caller to make sure the result isn't `nil`.
*
* If disabled, we allow for the possibility that the ghost text has already been removed,
* which can happen if a delegate callback is trying to remove ghost text after invoking `setAttributedText:`.
*/
Expand Down

0 comments on commit 3c44bcc

Please sign in to comment.