-
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 4 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)]; | ||
[attributedString removeAttribute:NSUnderlineStyleAttributeName range:NSMakeRange(0, attributedString.length)]; | ||
|
||
_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.