react-native-enriched 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -5
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerDelegate.java +3 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerInterface.java +1 -0
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.cpp +10 -0
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.h +7 -0
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt +92 -0
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/events/OnRequestHtmlResultEvent.kt +33 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBlockQuoteSpan.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedCodeBlockSpan.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedImageSpan.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedInlineCodeSpan.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedLinkSpan.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedMentionSpan.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedOrderedListSpan.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedSpans.kt +9 -3
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnorderedListSpan.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt +4 -0
- package/android/src/main/java/com/swmansion/enriched/styles/HtmlStyle.kt +78 -0
- package/android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt +80 -4
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedParser.java +8 -0
- package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.cpp +6 -6
- package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.h +6 -6
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputComponentDescriptor.h +19 -19
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.cpp +40 -51
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.h +13 -15
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.cpp +23 -21
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.h +35 -36
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.cpp +4 -4
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.h +13 -14
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/conversions.h +12 -13
- package/ios/EnrichedTextInputView.h +25 -13
- package/ios/EnrichedTextInputView.mm +872 -581
- package/ios/attachments/ImageAttachment.h +10 -0
- package/ios/attachments/ImageAttachment.mm +34 -0
- package/ios/attachments/MediaAttachment.h +23 -0
- package/ios/attachments/MediaAttachment.mm +31 -0
- package/ios/config/InputConfig.h +6 -6
- package/ios/config/InputConfig.mm +39 -33
- package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.cpp +10 -0
- package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.h +7 -0
- package/ios/generated/RNEnrichedTextInputViewSpec/RCTComponentViewHelpers.h +21 -0
- package/ios/inputParser/InputParser.h +5 -5
- package/ios/inputParser/InputParser.mm +789 -378
- package/ios/inputTextView/InputTextView.h +1 -1
- package/ios/inputTextView/InputTextView.mm +100 -59
- package/ios/internals/EnrichedTextInputViewComponentDescriptor.h +11 -9
- package/ios/internals/EnrichedTextInputViewShadowNode.h +28 -25
- package/ios/internals/EnrichedTextInputViewShadowNode.mm +45 -40
- package/ios/internals/EnrichedTextInputViewState.h +3 -1
- package/ios/styles/BlockQuoteStyle.mm +189 -118
- package/ios/styles/BoldStyle.mm +95 -63
- package/ios/styles/CodeBlockStyle.mm +204 -128
- package/ios/styles/H1Style.mm +10 -4
- package/ios/styles/H2Style.mm +10 -4
- package/ios/styles/H3Style.mm +10 -4
- package/ios/styles/HeadingStyleBase.mm +129 -84
- package/ios/styles/ImageStyle.mm +75 -73
- package/ios/styles/InlineCodeStyle.mm +148 -85
- package/ios/styles/ItalicStyle.mm +76 -52
- package/ios/styles/LinkStyle.mm +348 -227
- package/ios/styles/MentionStyle.mm +363 -246
- package/ios/styles/OrderedListStyle.mm +171 -106
- package/ios/styles/StrikethroughStyle.mm +52 -35
- package/ios/styles/UnderlineStyle.mm +68 -46
- package/ios/styles/UnorderedListStyle.mm +169 -106
- package/ios/utils/BaseStyleProtocol.h +2 -2
- package/ios/utils/ColorExtension.mm +7 -5
- package/ios/utils/FontExtension.mm +42 -27
- package/ios/utils/LayoutManagerExtension.h +1 -1
- package/ios/utils/LayoutManagerExtension.mm +280 -170
- package/ios/utils/MentionParams.h +0 -1
- package/ios/utils/MentionStyleProps.h +1 -1
- package/ios/utils/MentionStyleProps.mm +27 -20
- package/ios/utils/OccurenceUtils.h +42 -42
- package/ios/utils/OccurenceUtils.mm +142 -119
- package/ios/utils/ParagraphAttributesUtils.h +6 -2
- package/ios/utils/ParagraphAttributesUtils.mm +115 -71
- package/ios/utils/ParagraphsUtils.h +2 -1
- package/ios/utils/ParagraphsUtils.mm +40 -26
- package/ios/utils/StringExtension.h +1 -1
- package/ios/utils/StringExtension.mm +19 -16
- package/ios/utils/StyleHeaders.h +27 -15
- package/ios/utils/TextInsertionUtils.h +13 -2
- package/ios/utils/TextInsertionUtils.mm +38 -20
- package/ios/utils/WordsUtils.h +2 -1
- package/ios/utils/WordsUtils.mm +32 -22
- package/ios/utils/ZeroWidthSpaceUtils.h +3 -1
- package/ios/utils/ZeroWidthSpaceUtils.mm +145 -79
- package/lib/module/EnrichedTextInput.js +39 -1
- package/lib/module/EnrichedTextInput.js.map +1 -1
- package/lib/module/EnrichedTextInputNativeComponent.ts +11 -0
- package/lib/typescript/src/EnrichedTextInput.d.ts +1 -0
- package/lib/typescript/src/EnrichedTextInput.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts +6 -0
- package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts.map +1 -1
- package/package.json +8 -1
- package/src/EnrichedTextInput.tsx +45 -0
- package/src/EnrichedTextInputNativeComponent.ts +11 -0
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
#import "
|
|
1
|
+
#import "ColorExtension.h"
|
|
2
2
|
#import "EnrichedTextInputView.h"
|
|
3
3
|
#import "FontExtension.h"
|
|
4
4
|
#import "OccurenceUtils.h"
|
|
5
5
|
#import "ParagraphsUtils.h"
|
|
6
|
+
#import "StyleHeaders.h"
|
|
6
7
|
#import "TextInsertionUtils.h"
|
|
7
|
-
#import "ColorExtension.h"
|
|
8
8
|
|
|
9
9
|
@implementation CodeBlockStyle {
|
|
10
10
|
EnrichedTextInputView *_input;
|
|
11
11
|
NSArray *_stylesToExclude;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
+ (StyleType)getStyleType {
|
|
14
|
+
+ (StyleType)getStyleType {
|
|
15
|
+
return CodeBlock;
|
|
16
|
+
}
|
|
15
17
|
|
|
16
|
-
+ (BOOL)isParagraphStyle {
|
|
18
|
+
+ (BOOL)isParagraphStyle {
|
|
19
|
+
return YES;
|
|
20
|
+
}
|
|
17
21
|
|
|
18
22
|
- (instancetype)initWithInput:(id)input {
|
|
19
23
|
self = [super init];
|
|
@@ -24,94 +28,130 @@
|
|
|
24
28
|
|
|
25
29
|
- (void)applyStyle:(NSRange)range {
|
|
26
30
|
BOOL isStylePresent = [self detectStyle:range];
|
|
27
|
-
if(range.length >= 1) {
|
|
28
|
-
isStylePresent ? [self removeAttributes:range]
|
|
31
|
+
if (range.length >= 1) {
|
|
32
|
+
isStylePresent ? [self removeAttributes:range]
|
|
33
|
+
: [self addAttributes:range withTypingAttr:YES];
|
|
29
34
|
} else {
|
|
30
35
|
isStylePresent ? [self removeTypingAttributes] : [self addTypingAttributes];
|
|
31
36
|
}
|
|
32
37
|
}
|
|
33
38
|
|
|
34
|
-
- (void)addAttributes:(NSRange)range {
|
|
35
|
-
NSTextList *codeBlockList =
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
- (void)addAttributes:(NSRange)range withTypingAttr:(BOOL)withTypingAttr {
|
|
40
|
+
NSTextList *codeBlockList =
|
|
41
|
+
[[NSTextList alloc] initWithMarkerFormat:@"codeblock" options:0];
|
|
42
|
+
NSArray *paragraphs =
|
|
43
|
+
[ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView
|
|
44
|
+
range:range];
|
|
45
|
+
// if we fill empty lines with zero width spaces, we need to offset later
|
|
46
|
+
// ranges
|
|
38
47
|
NSInteger offset = 0;
|
|
39
48
|
NSRange preModificationRange = _input->textView.selectedRange;
|
|
40
|
-
|
|
49
|
+
|
|
41
50
|
// to not emit any space filling selection/text changes
|
|
42
51
|
_input->blockEmitting = YES;
|
|
43
52
|
|
|
44
53
|
for (NSValue *value in paragraphs) {
|
|
45
|
-
NSRange pRange = NSMakeRange([value rangeValue].location + offset,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
NSRange pRange = NSMakeRange([value rangeValue].location + offset,
|
|
55
|
+
[value rangeValue].length);
|
|
56
|
+
// length 0 with first line, length 1 and newline with some empty lines in
|
|
57
|
+
// the middle
|
|
58
|
+
if (pRange.length == 0 ||
|
|
59
|
+
(pRange.length == 1 &&
|
|
60
|
+
[[NSCharacterSet newlineCharacterSet]
|
|
61
|
+
characterIsMember:[_input->textView.textStorage.string
|
|
62
|
+
characterAtIndex:pRange.location]])) {
|
|
63
|
+
[TextInsertionUtils insertText:@"\u200B"
|
|
64
|
+
at:pRange.location
|
|
65
|
+
additionalAttributes:nullptr
|
|
66
|
+
input:_input
|
|
67
|
+
withSelection:NO];
|
|
52
68
|
pRange = NSMakeRange(pRange.location, pRange.length + 1);
|
|
53
69
|
offset += 1;
|
|
54
70
|
}
|
|
55
|
-
|
|
56
|
-
[_input->textView.textStorage
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
71
|
+
|
|
72
|
+
[_input->textView.textStorage
|
|
73
|
+
enumerateAttribute:NSParagraphStyleAttributeName
|
|
74
|
+
inRange:pRange
|
|
75
|
+
options:0
|
|
76
|
+
usingBlock:^(id _Nullable value, NSRange range,
|
|
77
|
+
BOOL *_Nonnull stop) {
|
|
78
|
+
NSMutableParagraphStyle *pStyle =
|
|
79
|
+
[(NSParagraphStyle *)value mutableCopy];
|
|
80
|
+
pStyle.textLists = @[ codeBlockList ];
|
|
81
|
+
[_input->textView.textStorage
|
|
82
|
+
addAttribute:NSParagraphStyleAttributeName
|
|
83
|
+
value:pStyle
|
|
84
|
+
range:range];
|
|
85
|
+
}];
|
|
63
86
|
}
|
|
64
|
-
|
|
87
|
+
|
|
65
88
|
// back to emitting
|
|
66
89
|
_input->blockEmitting = NO;
|
|
67
|
-
|
|
68
|
-
if(preModificationRange.length == 0) {
|
|
69
|
-
// fix selection if only one line was possibly made a list and filled with a
|
|
90
|
+
|
|
91
|
+
if (preModificationRange.length == 0) {
|
|
92
|
+
// fix selection if only one line was possibly made a list and filled with a
|
|
93
|
+
// space
|
|
70
94
|
_input->textView.selectedRange = preModificationRange;
|
|
71
95
|
} else {
|
|
72
96
|
// in other cases, fix the selection with newly made offsets
|
|
73
|
-
_input->textView.selectedRange = NSMakeRange(
|
|
97
|
+
_input->textView.selectedRange = NSMakeRange(
|
|
98
|
+
preModificationRange.location, preModificationRange.length + offset);
|
|
74
99
|
}
|
|
75
|
-
|
|
100
|
+
|
|
76
101
|
// also add typing attributes
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
102
|
+
if (withTypingAttr) {
|
|
103
|
+
NSMutableDictionary *typingAttrs =
|
|
104
|
+
[_input->textView.typingAttributes mutableCopy];
|
|
105
|
+
NSMutableParagraphStyle *pStyle =
|
|
106
|
+
[typingAttrs[NSParagraphStyleAttributeName] mutableCopy];
|
|
107
|
+
pStyle.textLists = @[ codeBlockList ];
|
|
108
|
+
typingAttrs[NSParagraphStyleAttributeName] = pStyle;
|
|
109
|
+
|
|
110
|
+
_input->textView.typingAttributes = typingAttrs;
|
|
111
|
+
}
|
|
83
112
|
}
|
|
84
113
|
|
|
85
114
|
- (void)addTypingAttributes {
|
|
86
|
-
[self addAttributes:_input->textView.selectedRange];
|
|
115
|
+
[self addAttributes:_input->textView.selectedRange withTypingAttr:YES];
|
|
87
116
|
}
|
|
88
117
|
|
|
89
118
|
- (void)removeAttributes:(NSRange)range {
|
|
90
|
-
NSArray *paragraphs =
|
|
91
|
-
|
|
119
|
+
NSArray *paragraphs =
|
|
120
|
+
[ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView
|
|
121
|
+
range:range];
|
|
122
|
+
|
|
92
123
|
[_input->textView.textStorage beginEditing];
|
|
93
|
-
|
|
94
|
-
for(NSValue *value in paragraphs) {
|
|
124
|
+
|
|
125
|
+
for (NSValue *value in paragraphs) {
|
|
95
126
|
NSRange pRange = [value rangeValue];
|
|
96
|
-
|
|
97
|
-
[_input->textView.textStorage
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
127
|
+
|
|
128
|
+
[_input->textView.textStorage
|
|
129
|
+
enumerateAttribute:NSParagraphStyleAttributeName
|
|
130
|
+
inRange:pRange
|
|
131
|
+
options:0
|
|
132
|
+
usingBlock:^(id _Nullable value, NSRange range,
|
|
133
|
+
BOOL *_Nonnull stop) {
|
|
134
|
+
NSMutableParagraphStyle *pStyle =
|
|
135
|
+
[(NSParagraphStyle *)value mutableCopy];
|
|
136
|
+
pStyle.textLists = @[];
|
|
137
|
+
[_input->textView.textStorage
|
|
138
|
+
addAttribute:NSParagraphStyleAttributeName
|
|
139
|
+
value:pStyle
|
|
140
|
+
range:range];
|
|
141
|
+
}];
|
|
104
142
|
}
|
|
105
|
-
|
|
143
|
+
|
|
106
144
|
[_input->textView.textStorage endEditing];
|
|
107
|
-
|
|
145
|
+
|
|
108
146
|
// also remove typing attributes
|
|
109
|
-
NSMutableDictionary *typingAttrs =
|
|
110
|
-
|
|
147
|
+
NSMutableDictionary *typingAttrs =
|
|
148
|
+
[_input->textView.typingAttributes mutableCopy];
|
|
149
|
+
NSMutableParagraphStyle *pStyle =
|
|
150
|
+
[typingAttrs[NSParagraphStyleAttributeName] mutableCopy];
|
|
111
151
|
pStyle.textLists = @[];
|
|
112
|
-
|
|
152
|
+
|
|
113
153
|
typingAttrs[NSParagraphStyleAttributeName] = pStyle;
|
|
114
|
-
|
|
154
|
+
|
|
115
155
|
_input->textView.typingAttributes = typingAttrs;
|
|
116
156
|
}
|
|
117
157
|
|
|
@@ -120,14 +160,16 @@
|
|
|
120
160
|
}
|
|
121
161
|
|
|
122
162
|
- (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text {
|
|
123
|
-
if([self detectStyle:_input->textView.selectedRange] && text.length == 0) {
|
|
163
|
+
if ([self detectStyle:_input->textView.selectedRange] && text.length == 0) {
|
|
124
164
|
// backspace while the style is active
|
|
125
|
-
|
|
126
|
-
NSRange paragraphRange = [_input->textView.textStorage.string
|
|
127
|
-
|
|
128
|
-
|
|
165
|
+
|
|
166
|
+
NSRange paragraphRange = [_input->textView.textStorage.string
|
|
167
|
+
paragraphRangeForRange:_input->textView.selectedRange];
|
|
168
|
+
|
|
169
|
+
if (NSEqualRanges(_input->textView.selectedRange, NSMakeRange(0, 0))) {
|
|
129
170
|
// a backspace on the very first input's line quote
|
|
130
|
-
// it doesn't run textVieDidChange so we need to manually remove
|
|
171
|
+
// it doesn't run textVieDidChange so we need to manually remove
|
|
172
|
+
// attributes
|
|
131
173
|
[self removeAttributes:paragraphRange];
|
|
132
174
|
return YES;
|
|
133
175
|
}
|
|
@@ -135,92 +177,126 @@
|
|
|
135
177
|
return NO;
|
|
136
178
|
}
|
|
137
179
|
|
|
138
|
-
- (BOOL)styleCondition:(id _Nullable)value
|
|
180
|
+
- (BOOL)styleCondition:(id _Nullable)value:(NSRange)range {
|
|
139
181
|
NSParagraphStyle *paragraph = (NSParagraphStyle *)value;
|
|
140
|
-
return paragraph != nullptr && paragraph.textLists.count == 1 &&
|
|
182
|
+
return paragraph != nullptr && paragraph.textLists.count == 1 &&
|
|
183
|
+
[paragraph.textLists.firstObject.markerFormat
|
|
184
|
+
isEqualToString:@"codeblock"];
|
|
141
185
|
}
|
|
142
186
|
|
|
143
187
|
- (BOOL)detectStyle:(NSRange)range {
|
|
144
|
-
if(range.length >= 1) {
|
|
145
|
-
return [OccurenceUtils detect:NSParagraphStyleAttributeName
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
188
|
+
if (range.length >= 1) {
|
|
189
|
+
return [OccurenceUtils detect:NSParagraphStyleAttributeName
|
|
190
|
+
withInput:_input
|
|
191
|
+
inRange:range
|
|
192
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
193
|
+
return [self styleCondition:value:range];
|
|
194
|
+
}];
|
|
150
195
|
} else {
|
|
151
|
-
return [OccurenceUtils detect:NSParagraphStyleAttributeName
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
196
|
+
return [OccurenceUtils detect:NSParagraphStyleAttributeName
|
|
197
|
+
withInput:_input
|
|
198
|
+
atIndex:range.location
|
|
199
|
+
checkPrevious:YES
|
|
200
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
201
|
+
return [self styleCondition:value:range];
|
|
202
|
+
}];
|
|
156
203
|
}
|
|
157
204
|
}
|
|
158
205
|
|
|
159
206
|
- (BOOL)anyOccurence:(NSRange)range {
|
|
160
|
-
return [OccurenceUtils any:NSParagraphStyleAttributeName
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
207
|
+
return [OccurenceUtils any:NSParagraphStyleAttributeName
|
|
208
|
+
withInput:_input
|
|
209
|
+
inRange:range
|
|
210
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
211
|
+
return [self styleCondition:value:range];
|
|
212
|
+
}];
|
|
165
213
|
}
|
|
166
214
|
|
|
167
215
|
- (NSArray<StylePair *> *_Nullable)findAllOccurences:(NSRange)range {
|
|
168
|
-
return [OccurenceUtils all:NSParagraphStyleAttributeName
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
216
|
+
return [OccurenceUtils all:NSParagraphStyleAttributeName
|
|
217
|
+
withInput:_input
|
|
218
|
+
inRange:range
|
|
219
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
220
|
+
return [self styleCondition:value:range];
|
|
221
|
+
}];
|
|
173
222
|
}
|
|
174
223
|
|
|
175
224
|
- (void)manageCodeBlockFontAndColor {
|
|
176
|
-
if([[_input->config codeBlockFgColor]
|
|
225
|
+
if ([[_input->config codeBlockFgColor]
|
|
226
|
+
isEqualToColor:[_input->config primaryColor]]) {
|
|
177
227
|
return;
|
|
178
228
|
}
|
|
179
229
|
|
|
180
|
-
NSRange wholeRange =
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
230
|
+
NSRange wholeRange =
|
|
231
|
+
NSMakeRange(0, _input->textView.textStorage.string.length);
|
|
232
|
+
NSArray *paragraphs =
|
|
233
|
+
[ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView
|
|
234
|
+
range:wholeRange];
|
|
235
|
+
|
|
236
|
+
for (NSValue *pValue in paragraphs) {
|
|
184
237
|
NSRange paragraphRange = [pValue rangeValue];
|
|
185
|
-
NSArray *properRanges = [OccurenceUtils getRangesWithout:_stylesToExclude
|
|
186
|
-
|
|
187
|
-
|
|
238
|
+
NSArray *properRanges = [OccurenceUtils getRangesWithout:_stylesToExclude
|
|
239
|
+
withInput:_input
|
|
240
|
+
inRange:paragraphRange];
|
|
241
|
+
|
|
242
|
+
for (NSValue *value in properRanges) {
|
|
188
243
|
NSRange currRange = [value rangeValue];
|
|
189
244
|
BOOL selfDetected = [self detectStyle:currRange];
|
|
190
|
-
|
|
191
|
-
[_input->textView.textStorage
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
245
|
+
|
|
246
|
+
[_input->textView.textStorage
|
|
247
|
+
enumerateAttribute:NSFontAttributeName
|
|
248
|
+
inRange:currRange
|
|
249
|
+
options:0
|
|
250
|
+
usingBlock:^(id _Nullable value, NSRange range,
|
|
251
|
+
BOOL *_Nonnull stop) {
|
|
252
|
+
UIFont *currentFont = (UIFont *)value;
|
|
253
|
+
UIFont *newFont = nullptr;
|
|
254
|
+
|
|
255
|
+
BOOL isCodeFont = [[currentFont familyName]
|
|
256
|
+
isEqualToString:[[_input->config monospacedFont]
|
|
257
|
+
familyName]];
|
|
258
|
+
|
|
259
|
+
if (isCodeFont && !selfDetected) {
|
|
260
|
+
newFont = [[[_input->config primaryFont]
|
|
261
|
+
withFontTraits:currentFont]
|
|
262
|
+
setSize:currentFont.pointSize];
|
|
263
|
+
} else if (!isCodeFont && selfDetected) {
|
|
264
|
+
newFont = [[[_input->config monospacedFont]
|
|
265
|
+
withFontTraits:currentFont]
|
|
266
|
+
setSize:currentFont.pointSize];
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (newFont != nullptr) {
|
|
270
|
+
[_input->textView.textStorage
|
|
271
|
+
addAttribute:NSFontAttributeName
|
|
272
|
+
value:newFont
|
|
273
|
+
range:range];
|
|
274
|
+
}
|
|
275
|
+
}];
|
|
276
|
+
|
|
277
|
+
[_input->textView.textStorage
|
|
278
|
+
enumerateAttribute:NSForegroundColorAttributeName
|
|
279
|
+
inRange:currRange
|
|
280
|
+
options:0
|
|
281
|
+
usingBlock:^(id _Nullable value, NSRange range,
|
|
282
|
+
BOOL *_Nonnull stop) {
|
|
283
|
+
UIColor *newColor = nullptr;
|
|
284
|
+
BOOL colorApplied = [(UIColor *)value
|
|
285
|
+
isEqualToColor:[_input->config codeBlockFgColor]];
|
|
286
|
+
|
|
287
|
+
if (colorApplied && !selfDetected) {
|
|
288
|
+
newColor = [_input->config primaryColor];
|
|
289
|
+
} else if (!colorApplied && selfDetected) {
|
|
290
|
+
newColor = [_input->config codeBlockFgColor];
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
if (newColor != nullptr) {
|
|
294
|
+
[_input->textView.textStorage
|
|
295
|
+
addAttribute:NSForegroundColorAttributeName
|
|
296
|
+
value:newColor
|
|
297
|
+
range:range];
|
|
298
|
+
}
|
|
299
|
+
}];
|
|
224
300
|
}
|
|
225
301
|
}
|
|
226
302
|
}
|
package/ios/styles/H1Style.mm
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
#import "StyleHeaders.h"
|
|
2
1
|
#import "EnrichedTextInputView.h"
|
|
2
|
+
#import "StyleHeaders.h"
|
|
3
3
|
|
|
4
4
|
@implementation H1Style
|
|
5
|
-
+ (StyleType)getStyleType {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
+ (StyleType)getStyleType {
|
|
6
|
+
return H1;
|
|
7
|
+
}
|
|
8
|
+
+ (BOOL)isParagraphStyle {
|
|
9
|
+
return YES;
|
|
10
|
+
}
|
|
11
|
+
- (CGFloat)getHeadingFontSize {
|
|
12
|
+
return [((EnrichedTextInputView *)input)->config h1FontSize];
|
|
13
|
+
}
|
|
8
14
|
- (BOOL)isHeadingBold {
|
|
9
15
|
return [((EnrichedTextInputView *)input)->config h1Bold];
|
|
10
16
|
}
|
package/ios/styles/H2Style.mm
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
#import "StyleHeaders.h"
|
|
2
1
|
#import "EnrichedTextInputView.h"
|
|
2
|
+
#import "StyleHeaders.h"
|
|
3
3
|
|
|
4
4
|
@implementation H2Style
|
|
5
|
-
+ (StyleType)getStyleType {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
+ (StyleType)getStyleType {
|
|
6
|
+
return H2;
|
|
7
|
+
}
|
|
8
|
+
+ (BOOL)isParagraphStyle {
|
|
9
|
+
return YES;
|
|
10
|
+
}
|
|
11
|
+
- (CGFloat)getHeadingFontSize {
|
|
12
|
+
return [((EnrichedTextInputView *)input)->config h2FontSize];
|
|
13
|
+
}
|
|
8
14
|
- (BOOL)isHeadingBold {
|
|
9
15
|
return [((EnrichedTextInputView *)input)->config h2Bold];
|
|
10
16
|
}
|
package/ios/styles/H3Style.mm
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
#import "StyleHeaders.h"
|
|
2
1
|
#import "EnrichedTextInputView.h"
|
|
2
|
+
#import "StyleHeaders.h"
|
|
3
3
|
|
|
4
4
|
@implementation H3Style
|
|
5
|
-
+ (StyleType)getStyleType {
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
+ (StyleType)getStyleType {
|
|
6
|
+
return H3;
|
|
7
|
+
}
|
|
8
|
+
+ (BOOL)isParagraphStyle {
|
|
9
|
+
return YES;
|
|
10
|
+
}
|
|
11
|
+
- (CGFloat)getHeadingFontSize {
|
|
12
|
+
return [((EnrichedTextInputView *)input)->config h3FontSize];
|
|
13
|
+
}
|
|
8
14
|
- (BOOL)isHeadingBold {
|
|
9
15
|
return [((EnrichedTextInputView *)input)->config h3Bold];
|
|
10
16
|
}
|