Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 70 additions & 39 deletions ios/inputParser/InputParser.mm
Original file line number Diff line number Diff line change
Expand Up @@ -592,55 +592,86 @@ - (NSString *)tagContentForStyle:(NSNumber *)style
}

- (void)replaceWholeFromHtml:(NSString *_Nonnull)html {
NSArray *processingResult = [self getTextAndStylesFromHtml:html];
NSString *plainText = (NSString *)processingResult[0];
NSArray *stylesInfo = (NSArray *)processingResult[1];

// reset the text first and reset typing attributes
_input->textView.text = @"";
_input->textView.typingAttributes = _input->defaultTypingAttributes;

// set new text
_input->textView.text = plainText;

// re-apply the styles
[self applyProcessedStyles:stylesInfo
offsetFromBeginning:0
plainTextLength:plainText.length];
@try {
NSArray *processingResult = [self getTextAndStylesFromHtml:html];
NSString *plainText = (NSString *)processingResult[0];
NSArray *stylesInfo = (NSArray *)processingResult[1];

// set new text
_input->textView.text = plainText;

// re-apply the styles
[self applyProcessedStyles:stylesInfo
offsetFromBeginning:0
plainTextLength:plainText.length];
} @catch (NSException *exception) {
RCTLogWarn(@"[EnrichedTextInput]: Failed to parse HTML: (%@), falling back "
@"to raw input.",
exception.reason);

// set new text
_input->textView.text = html;
}
}

- (void)replaceFromHtml:(NSString *_Nonnull)html range:(NSRange)range {
NSArray *processingResult = [self getTextAndStylesFromHtml:html];
NSString *plainText = (NSString *)processingResult[0];
NSArray *stylesInfo = (NSArray *)processingResult[1];

// we can use ready replace util
[TextInsertionUtils replaceText:plainText
at:range
additionalAttributes:nil
input:_input
withSelection:YES];

[self applyProcessedStyles:stylesInfo
offsetFromBeginning:range.location
plainTextLength:plainText.length];
@try {
NSArray *processingResult = [self getTextAndStylesFromHtml:html];
NSString *plainText = (NSString *)processingResult[0];
NSArray *stylesInfo = (NSArray *)processingResult[1];

// we can use ready replace util
[TextInsertionUtils replaceText:plainText
at:range
additionalAttributes:nil
input:_input
withSelection:YES];

[self applyProcessedStyles:stylesInfo
offsetFromBeginning:range.location
plainTextLength:plainText.length];
} @catch (NSException *exception) {
RCTLogWarn(@"[EnrichedTextInput]: Failed to parse HTML: (%@), falling back "
@"to raw input.",
exception.reason);
[TextInsertionUtils replaceText:html
at:range
additionalAttributes:nil
input:_input
withSelection:YES];
}
}

- (void)insertFromHtml:(NSString *_Nonnull)html location:(NSInteger)location {
NSArray *processingResult = [self getTextAndStylesFromHtml:html];
NSString *plainText = (NSString *)processingResult[0];
NSArray *stylesInfo = (NSArray *)processingResult[1];

// same here, insertion utils got our back
[TextInsertionUtils insertText:plainText
at:location
additionalAttributes:nil
input:_input
withSelection:YES];

[self applyProcessedStyles:stylesInfo
offsetFromBeginning:location
plainTextLength:plainText.length];
@try {
NSArray *processingResult = [self getTextAndStylesFromHtml:html];
NSString *plainText = (NSString *)processingResult[0];
NSArray *stylesInfo = (NSArray *)processingResult[1];

// same here, insertion utils got our back
[TextInsertionUtils insertText:plainText
at:location
additionalAttributes:nil
input:_input
withSelection:YES];

[self applyProcessedStyles:stylesInfo
offsetFromBeginning:location
plainTextLength:plainText.length];
} @catch (NSException *exception) {
RCTLogWarn(@"[EnrichedTextInput]: Failed to parse HTML: (%@), falling back "
@"to raw input.",
exception.reason);
[TextInsertionUtils insertText:html
at:location
additionalAttributes:nil
input:_input
withSelection:YES];
}
}

- (void)applyProcessedStyles:(NSArray *)processedStyles
Expand Down
Loading