Skip to content

Commit 7df0db1

Browse files
fix: conflicts in styles
1 parent 17cf35e commit 7df0db1

20 files changed

Lines changed: 102 additions & 12 deletions

ios/EnrichedTextInputView.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ NS_ASSUME_NONNULL_BEGIN
1818
@public InputParser *parser;
1919
@public NSMutableDictionary<NSAttributedStringKey, id> *defaultTypingAttributes;
2020
@public NSDictionary<NSNumber *, id<BaseStyleProtocol>> *stylesDict;
21+
NSDictionary<NSNumber *, NSArray<NSNumber *> *> *conflictingStyles;
22+
NSDictionary<NSNumber *, NSArray<NSNumber *> *> *blockingStyles;
2123
@public BOOL blockEmitting;
2224
@public BOOL emitHtml;
2325
}
@@ -26,6 +28,7 @@ NS_ASSUME_NONNULL_BEGIN
2628
- (void)emitOnMentionEvent:(NSString *)indicator text:(nullable NSString *)text;
2729
- (void)anyTextMayHaveBeenModified;
2830
- (BOOL)handleStyleBlocksAndConflicts:(StyleType)type range:(NSRange)range;
31+
- (NSArray<NSNumber *> *)getPresentStyleTypesFrom:(NSArray<NSNumber *> *)types range:(NSRange)range;
2932
@end
3033

3134
NS_ASSUME_NONNULL_END

ios/EnrichedTextInputView.mm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ @implementation EnrichedTextInputView {
2626
EnrichedTextInputViewShadowNode::ConcreteState::Shared _state;
2727
int _componentViewHeightUpdateCounter;
2828
NSMutableSet<NSNumber *> *_activeStyles;
29-
NSDictionary<NSNumber *, NSArray<NSNumber *> *> *_conflictingStyles;
30-
NSDictionary<NSNumber *, NSArray<NSNumber *> *> *_blockingStyles;
3129
LinkData *_recentlyActiveLinkData;
3230
NSRange _recentlyActiveLinkRange;
3331
NSString *_recentlyEmittedString;
@@ -98,7 +96,7 @@ - (void)setDefaults {
9896
@([CodeBlockStyle getStyleType]): [[CodeBlockStyle alloc] initWithInput:self]
9997
};
10098

101-
_conflictingStyles = @{
99+
conflictingStyles = @{
102100
@([BoldStyle getStyleType]) : @[],
103101
@([ItalicStyle getStyleType]) : @[],
104102
@([UnderlineStyle getStyleType]) : @[],
@@ -116,7 +114,7 @@ - (void)setDefaults {
116114
@([BoldStyle getStyleType]), @([ItalicStyle getStyleType]), @([UnderlineStyle getStyleType]), @([StrikethroughStyle getStyleType]), @([UnorderedListStyle getStyleType]), @([OrderedListStyle getStyleType]), @([BlockQuoteStyle getStyleType]), @([InlineCodeStyle getStyleType]), @([MentionStyle getStyleType]), @([LinkStyle getStyleType])]
117115
};
118116

119-
_blockingStyles = @{
117+
blockingStyles = @{
120118
@([BoldStyle getStyleType]) : @[@([CodeBlockStyle getStyleType])],
121119
@([ItalicStyle getStyleType]) : @[@([CodeBlockStyle getStyleType])],
122120
@([UnderlineStyle getStyleType]) : @[@([CodeBlockStyle getStyleType])],
@@ -945,13 +943,13 @@ - (void)startMentionWithIndicator:(NSString *)indicator {
945943
// returns false when style shouldn't be applied and true when it can be
946944
- (BOOL)handleStyleBlocksAndConflicts:(StyleType)type range:(NSRange)range {
947945
// handle blocking styles: if any is present we do not apply the toggled style
948-
NSArray<NSNumber *> *blocking = [self getPresentStyleTypesFrom: _blockingStyles[@(type)] range:range];
946+
NSArray<NSNumber *> *blocking = [self getPresentStyleTypesFrom: blockingStyles[@(type)] range:range];
949947
if(blocking.count != 0) {
950948
return NO;
951949
}
952950

953951
// handle conflicting styles: all of their occurences have to be removed
954-
NSArray<NSNumber *> *conflicting = [self getPresentStyleTypesFrom: _conflictingStyles[@(type)] range:range];
952+
NSArray<NSNumber *> *conflicting = [self getPresentStyleTypesFrom: conflictingStyles[@(type)] range:range];
955953
if(conflicting.count != 0) {
956954
for(NSNumber *style in conflicting) {
957955
id<BaseStyleProtocol> styleClass = stylesDict[style];
@@ -1212,7 +1210,9 @@ - (bool)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range r
12121210
[h2Style handleNewlinesInRange:range replacementText:text] ||
12131211
[h3Style handleNewlinesInRange:range replacementText:text] ||
12141212
[ZeroWidthSpaceUtils handleBackspaceInRange:range replacementText:text input:self] ||
1215-
[ParagraphAttributesUtils handleBackspaceInRange:range replacementText:text input:self]
1213+
[ParagraphAttributesUtils handleBackspaceInRange:range replacementText:text input:self] ||
1214+
// this callback HAS TO be always evaluated last
1215+
[ParagraphAttributesUtils handleNewlineBackspaceInRange:range replacementText:text input:self]
12161216
) {
12171217
[self anyTextMayHaveBeenModified];
12181218
return NO;

ios/styles/BlockQuoteStyle.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ @implementation BlockQuoteStyle {
1111

1212
+ (StyleType)getStyleType { return BlockQuote; }
1313

14+
+ (BOOL)isParagraphStyle { return YES; }
15+
1416
- (instancetype)initWithInput:(id)input {
1517
self = [super init];
1618
_input = (EnrichedTextInputView *)input;

ios/styles/BoldStyle.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ @implementation BoldStyle {
99

1010
+ (StyleType)getStyleType { return Bold; }
1111

12+
+ (BOOL)isParagraphStyle { return NO; }
13+
1214
- (instancetype)initWithInput:(id)input {
1315
self = [super init];
1416
_input = (EnrichedTextInputView *)input;

ios/styles/CodeBlockStyle.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ @implementation CodeBlockStyle {
1212

1313
+ (StyleType)getStyleType { return CodeBlock; }
1414

15+
+ (BOOL)isParagraphStyle { return YES; }
16+
1517
- (instancetype)initWithInput:(id)input {
1618
self = [super init];
1719
_input = (EnrichedTextInputView *)input;

ios/styles/H1Style.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
@implementation H1Style
55
+ (StyleType)getStyleType { return H1; }
6+
+ (BOOL)isParagraphStyle { return NO; }
67
- (CGFloat)getHeadingFontSize { return [((EnrichedTextInputView *)input)->config h1FontSize]; }
78
- (BOOL)isHeadingBold {
89
return [((EnrichedTextInputView *)input)->config h1Bold];

ios/styles/H2Style.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
@implementation H2Style
55
+ (StyleType)getStyleType { return H2; }
6+
+ (BOOL)isParagraphStyle { return NO; }
67
- (CGFloat)getHeadingFontSize { return [((EnrichedTextInputView *)input)->config h2FontSize]; }
78
- (BOOL)isHeadingBold {
89
return [((EnrichedTextInputView *)input)->config h2Bold];

ios/styles/H3Style.mm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
@implementation H3Style
55
+ (StyleType)getStyleType { return H3; }
6+
+ (BOOL)isParagraphStyle { return NO; }
67
- (CGFloat)getHeadingFontSize { return [((EnrichedTextInputView *)input)->config h3FontSize]; }
78
- (BOOL)isHeadingBold {
89
return [((EnrichedTextInputView *)input)->config h3Bold];

ios/styles/InlineCodeStyle.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ @implementation InlineCodeStyle {
1111

1212
+ (StyleType)getStyleType { return InlineCode; }
1313

14+
+ (BOOL)isParagraphStyle { return NO; }
15+
1416
- (instancetype)initWithInput:(id)input {
1517
self = [super init];
1618
_input = (EnrichedTextInputView *)input;

ios/styles/ItalicStyle.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ @implementation ItalicStyle {
99

1010
+ (StyleType)getStyleType { return Italic; }
1111

12+
+ (BOOL)isParagraphStyle { return NO; }
13+
1214
- (instancetype)initWithInput:(id)input {
1315
self = [super init];
1416
_input = (EnrichedTextInputView *)input;

0 commit comments

Comments
 (0)