-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix backticks not removed when entering diacritics using option key commands on iOS #182
Changes from all commits
5382e29
105b607
31cbdb2
dbaed87
642651c
f755217
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
#import "react_native_assert.h" | ||
#import <React/RCTAssert.h> | ||
#import <React/RCTFont.h> | ||
#import <React/RCTTextAttributes.h> | ||
#import <JavaScriptCore/JavaScriptCore.h> | ||
|
||
@implementation RCTMarkdownUtils { | ||
|
@@ -47,13 +48,17 @@ - (NSAttributedString *)parseMarkdown:(nullable NSAttributedString *)input | |
JSValue *result = [function callWithArguments:@[inputString]]; | ||
NSArray *ranges = [result toArray]; | ||
|
||
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:inputString attributes:_backedTextInputView.defaultTextAttributes]; | ||
NSMutableAttributedString *attributedString = [input mutableCopy]; | ||
[attributedString beginEditing]; | ||
|
||
NSMutableDictionary<NSAttributedStringKey, id> *attributes = [_backedTextInputView.defaultTextAttributes mutableCopy]; | ||
[attributes removeObjectForKey:RCTTextAttributesTagAttributeName]; | ||
[attributedString addAttributes:attributes range:NSMakeRange(0, attributedString.length)]; | ||
Comment on lines
+54
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because of the above change, now the attributed string also contains previous styling so I need to apply default text attributes in order to reset it. For some reason, restoring This attribute is also removed by React Native itself: https://github.com/facebook/react-native/blob/f9a5b30e5a805061416123d037351e5c03860756/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm#L175-L179 |
||
|
||
// If the attributed string ends with underlined text, blurring the single-line input imprints the underline style across the whole string. | ||
// It looks like a bug in iOS, as there is no underline style to be found in the attributed string, especially after formatting. | ||
// This is a workaround that applies the NSUnderlineStyleNone to the string before iterating over ranges which resolves this problem. | ||
[attributedString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleNone] range:NSMakeRange(0, attributedString.length)]; | ||
// The workaround is to remove NSUnderlineStyleAttributeName attribute for whole string before iterating over ranges. | ||
[attributedString removeAttribute:NSUnderlineStyleAttributeName range:NSMakeRange(0, attributedString.length)]; | ||
Comment on lines
+60
to
+61
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This previous version of this workaround breaks the diacritics context: Screen.Recording.2024-02-13.at.15.20.11.movIf we remove the workaround, the diacritics context works correctly but the link underline persists: Screen.Recording.2024-02-13.at.15.18.25.movIf we modify the workaround so it uses Screen.Recording.2024-02-13.at.15.22.56.movThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you check on the single line input as well? I'm testing on it, and the current version of the underline workaroud doesn't work for me when Reproduction steps
Screen.Recording.2024-02-13.at.19.01.46.movThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, thanks, didn't notice this comment. I confirm this is reproducible on my end as well. Will investigate that! Screen.Recording.2024-02-14.at.10.54.36.mov |
||
|
||
_blockquoteRanges = [NSMutableArray new]; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to use
mutableCopy
here because creatingNSMutableAttributedString
fromNSString
loses the information about diacritics context.