Skip to content

Commit

Permalink
Fix underline blinks while typing after a link
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekzaw committed Dec 11, 2024
1 parent 7977d83 commit a3e9169
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions apple/MarkdownBackedTextInputDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,15 @@ - (void)textInputDidChange
// After adding a newline at the end of the blockquote, the typing attributes in the new line
// still contain NSParagraphStyle with non-zero firstLineHeadIndent and headIntent.
// This causes the cursor to be shifted to the right instead of being located at the beginning of the line.
// The following code removes NSParagraphStyle from typing attributes to fix the position of the cursor.
NSParagraphStyle *paragraphStyle = _textView.typingAttributes[NSParagraphStyleAttributeName];
if (paragraphStyle != nil && paragraphStyle.firstLineHeadIndent != 0) {
NSMutableDictionary *newTypingAttributes = [_textView.typingAttributes mutableCopy];
NSMutableParagraphStyle *newParagraphStyle = [paragraphStyle mutableCopy];
newParagraphStyle.firstLineHeadIndent = 0;
newParagraphStyle.headIndent = 0;
newTypingAttributes[NSParagraphStyleAttributeName] = newParagraphStyle;
_textView.typingAttributes = newTypingAttributes;
}
// Also, if the previous line of the text ends with a link, there will be underline blinks visible while typing.
// The following code resets default text attributes to fix both problems at once.
// It seems like the setter performs deep comparision, so we differentiate the new value using a counter,
// otherwise this trick would work only once.
static NSAttributedStringKey RCTLiveMarkdownForceUpdateAttributeName = @"RCTLiveMarkdownForceUpdate";
static NSUInteger counter = 0;
NSMutableDictionary *defaultTextAttributes = [_textView.defaultTextAttributes mutableCopy];
defaultTextAttributes[RCTLiveMarkdownForceUpdateAttributeName] = @(counter++);
_textView.defaultTextAttributes = defaultTextAttributes;

// Delegate the call to the original text input delegate
[_originalTextInputDelegate textInputDidChange];
Expand Down

0 comments on commit a3e9169

Please sign in to comment.