-
Notifications
You must be signed in to change notification settings - Fork 30
fix(iOS): setting single attributed string to text view #323
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
Draft
IvanIhnatsiuk
wants to merge
8
commits into
software-mansion:main
Choose a base branch
from
IvanIhnatsiuk:fix/set-single-attributed-string-to-textView
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,050
−1,638
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0e0c3fb
fix: set single attributed string to text view
IvanIhnatsiuk ee68135
fix: unordered list styling persist
IvanIhnatsiuk c5bbffe
fix: properly handle text change notification
IvanIhnatsiuk c31d6de
fix: properly set default attributed string
IvanIhnatsiuk 0305136
fix: empty defaultValue applying
IvanIhnatsiuk c007def
fix: compiler warnings
IvanIhnatsiuk a8ae3f2
fix: remove huge html generation
IvanIhnatsiuk a59d5a8
fix: cleanup
IvanIhnatsiuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #import <Foundation/Foundation.h> | ||
| #import <UIKit/UIKit.h> | ||
|
|
||
| @interface AttributedStringBuilder : NSObject | ||
|
|
||
| @property(nonatomic, weak) NSDictionary *stylesDict; | ||
|
|
||
| - (void)apply:(NSArray *)processedStyles | ||
| toAttributedString:(NSMutableAttributedString *)attributedString | ||
| offsetFromBeginning:(NSInteger)offset | ||
| conflictingStyles: | ||
| (NSDictionary<NSNumber *, NSArray<NSNumber *> *> *)conflictingStyles; | ||
|
|
||
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #import "AttributedStringBuilder.h" | ||
| #import "StyleHeaders.h" | ||
| #import "StylePair.h" | ||
|
|
||
| @implementation AttributedStringBuilder | ||
|
|
||
| - (void)apply:(NSArray *)processedStyles | ||
| toAttributedString:(NSMutableAttributedString *)attributedString | ||
| offsetFromBeginning:(NSInteger)offset | ||
| conflictingStyles: | ||
| (NSDictionary<NSNumber *, NSArray<NSNumber *> *> *)conflictingStyles { | ||
| [attributedString beginEditing]; | ||
|
|
||
| for (NSArray *processedStylePair in processedStyles) { | ||
| NSNumber *type = processedStylePair[0]; | ||
| StylePair *pair = processedStylePair[1]; | ||
|
|
||
| NSRange pairRange = [pair.rangeValue rangeValue]; | ||
| NSRange range = NSMakeRange(offset + pairRange.location, pairRange.length); | ||
| if (![self canApplyStyle:type | ||
| range:range | ||
| attributedString:attributedString | ||
| conflictingMap:conflictingStyles | ||
| stylesDict:self.stylesDict]) { | ||
| continue; | ||
| } | ||
|
|
||
| id<BaseStyleProtocol> style = self.stylesDict[type]; | ||
|
|
||
| if ([type isEqualToNumber:@([LinkStyle getStyleType])]) { | ||
| NSString *text = [attributedString.string substringWithRange:range]; | ||
| NSString *url = pair.styleValue; | ||
| BOOL isManual = [text isEqualToString:url]; | ||
| [(LinkStyle *)style addLinkInAttributedString:attributedString | ||
| range:range | ||
| text:text | ||
| url:url | ||
| manual:isManual]; | ||
|
|
||
| } else if ([type isEqualToNumber:@([MentionStyle getStyleType])]) { | ||
| [(MentionStyle *)style addMentionInAttributedString:attributedString | ||
| range:range | ||
| params:pair.styleValue]; | ||
|
|
||
| } else if ([type isEqualToNumber:@([ImageStyle getStyleType])]) { | ||
| [(ImageStyle *)style addImageInAttributedString:attributedString | ||
| range:range | ||
| imageData:pair.styleValue]; | ||
| } else { | ||
| [style addAttributesInAttributedString:attributedString range:range]; | ||
| } | ||
| } | ||
|
|
||
| [attributedString endEditing]; | ||
| } | ||
|
|
||
| - (BOOL)canApplyStyle:(NSNumber *)type | ||
| range:(NSRange)range | ||
| attributedString:(NSAttributedString *)string | ||
| conflictingMap:(NSDictionary<NSNumber *, NSArray<NSNumber *> *> *)confMap | ||
| stylesDict: | ||
| (NSDictionary<NSNumber *, id<BaseStyleProtocol>> *)stylesDict { | ||
| NSArray<NSNumber *> *conflicts = confMap[type]; | ||
| if (!conflicts || conflicts.count == 0) | ||
| return YES; | ||
|
|
||
| for (NSNumber *conflictType in conflicts) { | ||
| id<BaseStyleProtocol> conflictStyle = stylesDict[conflictType]; | ||
| if (!conflictStyle) | ||
| continue; | ||
|
|
||
| NSArray<StylePair *> *occurrences = | ||
| [conflictStyle findAllOccurencesInAttributedString:string range:range]; | ||
|
|
||
| if (occurrences.count > 0) { | ||
| return NO; | ||
| } | ||
| } | ||
|
|
||
| return YES; | ||
| } | ||
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #import <Foundation/Foundation.h> | ||
|
|
||
| @interface ConvertHtmlToPlainTextAndStylesResult : NSObject | ||
| @property(nonatomic, strong) NSString *text; | ||
| @property(nonatomic, strong) NSArray *styles; | ||
| - (instancetype)initWithData:(NSString *)text styles:(NSArray *)styles; | ||
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| #import "ConvertHtmlToPlainTextAndStylesResult.h" | ||
|
|
||
| @implementation ConvertHtmlToPlainTextAndStylesResult | ||
| - (instancetype)initWithData:(NSString *)text styles:(NSArray *)styles { | ||
| self = [super init]; | ||
| _text = text; | ||
| _styles = styles; | ||
| return self; | ||
| } | ||
| @end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #import "EnrichedTextInputView.h" | ||
| #import <Foundation/Foundation.h> | ||
| #import <UIKit/UIKit.h> | ||
|
|
||
| @interface HtmlBuilder : NSObject | ||
|
|
||
| @property(nonatomic, weak) NSDictionary *stylesDict; | ||
| @property(nonatomic, weak) EnrichedTextInputView *input; | ||
|
|
||
| - (NSString *)htmlFromRange:(NSRange)range; | ||
|
|
||
| @end |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 will remove this one when #318 will be merged