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,17 +1,21 @@
|
|
|
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 "
|
|
6
|
+
#import "StyleHeaders.h"
|
|
7
7
|
|
|
8
8
|
@implementation InlineCodeStyle {
|
|
9
9
|
EnrichedTextInputView *_input;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
+ (StyleType)getStyleType {
|
|
12
|
+
+ (StyleType)getStyleType {
|
|
13
|
+
return InlineCode;
|
|
14
|
+
}
|
|
13
15
|
|
|
14
|
-
+ (BOOL)isParagraphStyle {
|
|
16
|
+
+ (BOOL)isParagraphStyle {
|
|
17
|
+
return NO;
|
|
18
|
+
}
|
|
15
19
|
|
|
16
20
|
- (instancetype)initWithInput:(id)input {
|
|
17
21
|
self = [super init];
|
|
@@ -21,48 +25,76 @@
|
|
|
21
25
|
|
|
22
26
|
- (void)applyStyle:(NSRange)range {
|
|
23
27
|
BOOL isStylePresent = [self detectStyle:range];
|
|
24
|
-
if(range.length >= 1) {
|
|
25
|
-
isStylePresent ? [self removeAttributes:range]
|
|
28
|
+
if (range.length >= 1) {
|
|
29
|
+
isStylePresent ? [self removeAttributes:range]
|
|
30
|
+
: [self addAttributes:range withTypingAttr:YES];
|
|
26
31
|
} else {
|
|
27
32
|
isStylePresent ? [self removeTypingAttributes] : [self addTypingAttributes];
|
|
28
33
|
}
|
|
29
34
|
}
|
|
30
35
|
|
|
31
|
-
- (void)addAttributes:(NSRange)range {
|
|
36
|
+
- (void)addAttributes:(NSRange)range withTypingAttr:(BOOL)withTypingAttr {
|
|
32
37
|
// we don't want to apply inline code to newline characters, it looks bad
|
|
33
|
-
NSArray *nonNewlineRanges =
|
|
34
|
-
|
|
35
|
-
|
|
38
|
+
NSArray *nonNewlineRanges =
|
|
39
|
+
[ParagraphsUtils getNonNewlineRangesIn:_input->textView range:range];
|
|
40
|
+
|
|
41
|
+
for (NSValue *value in nonNewlineRanges) {
|
|
36
42
|
NSRange currentRange = [value rangeValue];
|
|
37
43
|
[_input->textView.textStorage beginEditing];
|
|
38
44
|
|
|
39
|
-
[_input->textView.textStorage
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
45
|
+
[_input->textView.textStorage
|
|
46
|
+
addAttribute:NSBackgroundColorAttributeName
|
|
47
|
+
value:[[_input->config inlineCodeBgColor]
|
|
48
|
+
colorWithAlphaIfNotTransparent:0.4]
|
|
49
|
+
range:currentRange];
|
|
50
|
+
[_input->textView.textStorage
|
|
51
|
+
addAttribute:NSForegroundColorAttributeName
|
|
52
|
+
value:[_input->config inlineCodeFgColor]
|
|
53
|
+
range:currentRange];
|
|
54
|
+
[_input->textView.textStorage
|
|
55
|
+
addAttribute:NSUnderlineColorAttributeName
|
|
56
|
+
value:[_input->config inlineCodeFgColor]
|
|
57
|
+
range:currentRange];
|
|
58
|
+
[_input->textView.textStorage
|
|
59
|
+
addAttribute:NSStrikethroughColorAttributeName
|
|
60
|
+
value:[_input->config inlineCodeFgColor]
|
|
61
|
+
range:currentRange];
|
|
62
|
+
[_input->textView.textStorage
|
|
63
|
+
enumerateAttribute:NSFontAttributeName
|
|
64
|
+
inRange:currentRange
|
|
65
|
+
options:0
|
|
66
|
+
usingBlock:^(id _Nullable value, NSRange range,
|
|
67
|
+
BOOL *_Nonnull stop) {
|
|
68
|
+
UIFont *font = (UIFont *)value;
|
|
69
|
+
if (font != nullptr) {
|
|
70
|
+
UIFont *newFont = [[[_input->config monospacedFont]
|
|
71
|
+
withFontTraits:font] setSize:font.pointSize];
|
|
72
|
+
[_input->textView.textStorage
|
|
73
|
+
addAttribute:NSFontAttributeName
|
|
74
|
+
value:newFont
|
|
75
|
+
range:range];
|
|
76
|
+
}
|
|
77
|
+
}];
|
|
78
|
+
|
|
53
79
|
[_input->textView.textStorage endEditing];
|
|
54
80
|
}
|
|
55
81
|
}
|
|
56
82
|
|
|
57
83
|
- (void)addTypingAttributes {
|
|
58
|
-
NSMutableDictionary *newTypingAttrs =
|
|
59
|
-
|
|
60
|
-
newTypingAttrs[
|
|
61
|
-
|
|
62
|
-
newTypingAttrs[
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
84
|
+
NSMutableDictionary *newTypingAttrs =
|
|
85
|
+
[_input->textView.typingAttributes mutableCopy];
|
|
86
|
+
newTypingAttrs[NSBackgroundColorAttributeName] =
|
|
87
|
+
[[_input->config inlineCodeBgColor] colorWithAlphaIfNotTransparent:0.4];
|
|
88
|
+
newTypingAttrs[NSForegroundColorAttributeName] =
|
|
89
|
+
[_input->config inlineCodeFgColor];
|
|
90
|
+
newTypingAttrs[NSUnderlineColorAttributeName] =
|
|
91
|
+
[_input->config inlineCodeFgColor];
|
|
92
|
+
newTypingAttrs[NSStrikethroughColorAttributeName] =
|
|
93
|
+
[_input->config inlineCodeFgColor];
|
|
94
|
+
UIFont *currentFont = (UIFont *)newTypingAttrs[NSFontAttributeName];
|
|
95
|
+
if (currentFont != nullptr) {
|
|
96
|
+
newTypingAttrs[NSFontAttributeName] = [[[_input->config monospacedFont]
|
|
97
|
+
withFontTraits:currentFont] setSize:currentFont.pointSize];
|
|
66
98
|
}
|
|
67
99
|
_input->textView.typingAttributes = newTypingAttrs;
|
|
68
100
|
}
|
|
@@ -70,100 +102,131 @@
|
|
|
70
102
|
- (void)removeAttributes:(NSRange)range {
|
|
71
103
|
[_input->textView.textStorage beginEditing];
|
|
72
104
|
|
|
73
|
-
[_input->textView.textStorage removeAttribute:NSBackgroundColorAttributeName
|
|
74
|
-
|
|
75
|
-
[_input->textView.textStorage addAttribute:
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
105
|
+
[_input->textView.textStorage removeAttribute:NSBackgroundColorAttributeName
|
|
106
|
+
range:range];
|
|
107
|
+
[_input->textView.textStorage addAttribute:NSForegroundColorAttributeName
|
|
108
|
+
value:[_input->config primaryColor]
|
|
109
|
+
range:range];
|
|
110
|
+
[_input->textView.textStorage addAttribute:NSUnderlineColorAttributeName
|
|
111
|
+
value:[_input->config primaryColor]
|
|
112
|
+
range:range];
|
|
113
|
+
[_input->textView.textStorage addAttribute:NSStrikethroughColorAttributeName
|
|
114
|
+
value:[_input->config primaryColor]
|
|
115
|
+
range:range];
|
|
116
|
+
[_input->textView.textStorage
|
|
117
|
+
enumerateAttribute:NSFontAttributeName
|
|
118
|
+
inRange:range
|
|
119
|
+
options:0
|
|
120
|
+
usingBlock:^(id _Nullable value, NSRange range,
|
|
121
|
+
BOOL *_Nonnull stop) {
|
|
122
|
+
UIFont *font = (UIFont *)value;
|
|
123
|
+
if (font != nullptr) {
|
|
124
|
+
UIFont *newFont = [[[_input->config primaryFont]
|
|
125
|
+
withFontTraits:font] setSize:font.pointSize];
|
|
126
|
+
[_input->textView.textStorage addAttribute:NSFontAttributeName
|
|
127
|
+
value:newFont
|
|
128
|
+
range:range];
|
|
129
|
+
}
|
|
130
|
+
}];
|
|
131
|
+
|
|
87
132
|
[_input->textView.textStorage endEditing];
|
|
88
133
|
}
|
|
89
134
|
|
|
90
135
|
- (void)removeTypingAttributes {
|
|
91
|
-
NSMutableDictionary *newTypingAttrs =
|
|
136
|
+
NSMutableDictionary *newTypingAttrs =
|
|
137
|
+
[_input->textView.typingAttributes mutableCopy];
|
|
92
138
|
[newTypingAttrs removeObjectForKey:NSBackgroundColorAttributeName];
|
|
93
|
-
newTypingAttrs[NSForegroundColorAttributeName] =
|
|
139
|
+
newTypingAttrs[NSForegroundColorAttributeName] =
|
|
140
|
+
[_input->config primaryColor];
|
|
94
141
|
newTypingAttrs[NSUnderlineColorAttributeName] = [_input->config primaryColor];
|
|
95
|
-
newTypingAttrs[NSStrikethroughColorAttributeName] =
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
142
|
+
newTypingAttrs[NSStrikethroughColorAttributeName] =
|
|
143
|
+
[_input->config primaryColor];
|
|
144
|
+
UIFont *currentFont = (UIFont *)newTypingAttrs[NSFontAttributeName];
|
|
145
|
+
if (currentFont != nullptr) {
|
|
146
|
+
newTypingAttrs[NSFontAttributeName] = [[[_input->config primaryFont]
|
|
147
|
+
withFontTraits:currentFont] setSize:currentFont.pointSize];
|
|
99
148
|
}
|
|
100
149
|
_input->textView.typingAttributes = newTypingAttrs;
|
|
101
150
|
}
|
|
102
151
|
|
|
103
152
|
// making sure no newlines get inline code style, it looks bad
|
|
104
153
|
- (void)handleNewlines {
|
|
105
|
-
for(int i = 0; i < _input->textView.textStorage.string.length; i++) {
|
|
106
|
-
if([[NSCharacterSet newlineCharacterSet]
|
|
154
|
+
for (int i = 0; i < _input->textView.textStorage.string.length; i++) {
|
|
155
|
+
if ([[NSCharacterSet newlineCharacterSet]
|
|
156
|
+
characterIsMember:[_input->textView.textStorage.string
|
|
157
|
+
characterAtIndex:i]]) {
|
|
107
158
|
NSRange mockRange = NSMakeRange(0, 0);
|
|
108
|
-
// can't use detect style because it intentionally doesn't take newlines
|
|
109
|
-
|
|
110
|
-
|
|
159
|
+
// can't use detect style because it intentionally doesn't take newlines
|
|
160
|
+
// into consideration
|
|
161
|
+
UIColor *bgColor =
|
|
162
|
+
[_input->textView.textStorage attribute:NSBackgroundColorAttributeName
|
|
163
|
+
atIndex:i
|
|
164
|
+
effectiveRange:&mockRange];
|
|
165
|
+
if ([self styleCondition:bgColor:NSMakeRange(i, 1)]) {
|
|
111
166
|
[self removeAttributes:NSMakeRange(i, 1)];
|
|
112
167
|
}
|
|
113
168
|
}
|
|
114
169
|
}
|
|
115
170
|
}
|
|
116
171
|
|
|
117
|
-
// emojis don't retain monospace font attribute so we check for the background
|
|
118
|
-
|
|
172
|
+
// emojis don't retain monospace font attribute so we check for the background
|
|
173
|
+
// color if there is no mention
|
|
174
|
+
- (BOOL)styleCondition:(id _Nullable)value:(NSRange)range {
|
|
119
175
|
UIColor *bgColor = (UIColor *)value;
|
|
120
176
|
MentionStyle *mStyle = _input->stylesDict[@([MentionStyle getStyleType])];
|
|
121
177
|
return bgColor != nullptr && mStyle != nullptr && ![mStyle detectStyle:range];
|
|
122
178
|
}
|
|
123
179
|
|
|
124
180
|
- (BOOL)detectStyle:(NSRange)range {
|
|
125
|
-
if(range.length >= 1) {
|
|
181
|
+
if (range.length >= 1) {
|
|
126
182
|
// detect only in non-newline characters
|
|
127
|
-
NSArray *nonNewlineRanges =
|
|
128
|
-
|
|
183
|
+
NSArray *nonNewlineRanges =
|
|
184
|
+
[ParagraphsUtils getNonNewlineRangesIn:_input->textView range:range];
|
|
185
|
+
if (nonNewlineRanges.count == 0) {
|
|
129
186
|
return NO;
|
|
130
187
|
}
|
|
131
|
-
|
|
188
|
+
|
|
132
189
|
BOOL detected = YES;
|
|
133
|
-
for(NSValue *value in nonNewlineRanges) {
|
|
190
|
+
for (NSValue *value in nonNewlineRanges) {
|
|
134
191
|
NSRange currentRange = [value rangeValue];
|
|
135
|
-
BOOL currentDetected =
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
192
|
+
BOOL currentDetected =
|
|
193
|
+
[OccurenceUtils detect:NSBackgroundColorAttributeName
|
|
194
|
+
withInput:_input
|
|
195
|
+
inRange:currentRange
|
|
196
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
197
|
+
return [self styleCondition:value:range];
|
|
198
|
+
}];
|
|
140
199
|
detected = detected && currentDetected;
|
|
141
200
|
}
|
|
142
|
-
|
|
201
|
+
|
|
143
202
|
return detected;
|
|
144
203
|
} else {
|
|
145
|
-
return [OccurenceUtils detect:NSBackgroundColorAttributeName
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
204
|
+
return [OccurenceUtils detect:NSBackgroundColorAttributeName
|
|
205
|
+
withInput:_input
|
|
206
|
+
atIndex:range.location
|
|
207
|
+
checkPrevious:NO
|
|
208
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
209
|
+
return [self styleCondition:value:range];
|
|
210
|
+
}];
|
|
150
211
|
}
|
|
151
212
|
}
|
|
152
213
|
|
|
153
214
|
- (BOOL)anyOccurence:(NSRange)range {
|
|
154
|
-
return [OccurenceUtils any:NSBackgroundColorAttributeName
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
215
|
+
return [OccurenceUtils any:NSBackgroundColorAttributeName
|
|
216
|
+
withInput:_input
|
|
217
|
+
inRange:range
|
|
218
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
219
|
+
return [self styleCondition:value:range];
|
|
220
|
+
}];
|
|
159
221
|
}
|
|
160
222
|
|
|
161
223
|
- (NSArray<StylePair *> *_Nullable)findAllOccurences:(NSRange)range {
|
|
162
|
-
return [OccurenceUtils all:NSBackgroundColorAttributeName
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
224
|
+
return [OccurenceUtils all:NSBackgroundColorAttributeName
|
|
225
|
+
withInput:_input
|
|
226
|
+
inRange:range
|
|
227
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
228
|
+
return [self styleCondition:value:range];
|
|
229
|
+
}];
|
|
167
230
|
}
|
|
168
231
|
|
|
169
232
|
@end
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
#import "StyleHeaders.h"
|
|
2
1
|
#import "EnrichedTextInputView.h"
|
|
3
2
|
#import "FontExtension.h"
|
|
4
3
|
#import "OccurenceUtils.h"
|
|
4
|
+
#import "StyleHeaders.h"
|
|
5
5
|
|
|
6
6
|
@implementation ItalicStyle {
|
|
7
7
|
EnrichedTextInputView *_input;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
+ (StyleType)getStyleType {
|
|
10
|
+
+ (StyleType)getStyleType {
|
|
11
|
+
return Italic;
|
|
12
|
+
}
|
|
11
13
|
|
|
12
|
-
+ (BOOL)isParagraphStyle {
|
|
14
|
+
+ (BOOL)isParagraphStyle {
|
|
15
|
+
return NO;
|
|
16
|
+
}
|
|
13
17
|
|
|
14
18
|
- (instancetype)initWithInput:(id)input {
|
|
15
19
|
self = [super init];
|
|
@@ -19,31 +23,39 @@
|
|
|
19
23
|
|
|
20
24
|
- (void)applyStyle:(NSRange)range {
|
|
21
25
|
BOOL isStylePresent = [self detectStyle:range];
|
|
22
|
-
if(range.length >= 1) {
|
|
23
|
-
isStylePresent ? [self removeAttributes:range]
|
|
26
|
+
if (range.length >= 1) {
|
|
27
|
+
isStylePresent ? [self removeAttributes:range]
|
|
28
|
+
: [self addAttributes:range withTypingAttr:YES];
|
|
24
29
|
} else {
|
|
25
30
|
isStylePresent ? [self removeTypingAttributes] : [self addTypingAttributes];
|
|
26
31
|
}
|
|
27
32
|
}
|
|
28
33
|
|
|
29
|
-
- (void)addAttributes:(NSRange)range {
|
|
34
|
+
- (void)addAttributes:(NSRange)range withTypingAttr:(BOOL)withTypingAttr {
|
|
30
35
|
[_input->textView.textStorage beginEditing];
|
|
31
|
-
[_input->textView.textStorage
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
[_input->textView.textStorage
|
|
37
|
+
enumerateAttribute:NSFontAttributeName
|
|
38
|
+
inRange:range
|
|
39
|
+
options:0
|
|
40
|
+
usingBlock:^(id _Nullable value, NSRange range,
|
|
41
|
+
BOOL *_Nonnull stop) {
|
|
42
|
+
UIFont *font = (UIFont *)value;
|
|
43
|
+
if (font != nullptr) {
|
|
44
|
+
UIFont *newFont = [font setItalic];
|
|
45
|
+
[_input->textView.textStorage addAttribute:NSFontAttributeName
|
|
46
|
+
value:newFont
|
|
47
|
+
range:range];
|
|
48
|
+
}
|
|
49
|
+
}];
|
|
40
50
|
[_input->textView.textStorage endEditing];
|
|
41
51
|
}
|
|
42
52
|
|
|
43
53
|
- (void)addTypingAttributes {
|
|
44
|
-
UIFont *currentFontAttr =
|
|
45
|
-
|
|
46
|
-
|
|
54
|
+
UIFont *currentFontAttr =
|
|
55
|
+
(UIFont *)_input->textView.typingAttributes[NSFontAttributeName];
|
|
56
|
+
if (currentFontAttr != nullptr) {
|
|
57
|
+
NSMutableDictionary *newTypingAttrs =
|
|
58
|
+
[_input->textView.typingAttributes mutableCopy];
|
|
47
59
|
newTypingAttrs[NSFontAttributeName] = [currentFontAttr setItalic];
|
|
48
60
|
_input->textView.typingAttributes = newTypingAttrs;
|
|
49
61
|
}
|
|
@@ -51,62 +63,74 @@
|
|
|
51
63
|
|
|
52
64
|
- (void)removeAttributes:(NSRange)range {
|
|
53
65
|
[_input->textView.textStorage beginEditing];
|
|
54
|
-
[_input->textView.textStorage
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
66
|
+
[_input->textView.textStorage
|
|
67
|
+
enumerateAttribute:NSFontAttributeName
|
|
68
|
+
inRange:range
|
|
69
|
+
options:0
|
|
70
|
+
usingBlock:^(id _Nullable value, NSRange range,
|
|
71
|
+
BOOL *_Nonnull stop) {
|
|
72
|
+
UIFont *font = (UIFont *)value;
|
|
73
|
+
if (font != nullptr) {
|
|
74
|
+
UIFont *newFont = [font removeItalic];
|
|
75
|
+
[_input->textView.textStorage addAttribute:NSFontAttributeName
|
|
76
|
+
value:newFont
|
|
77
|
+
range:range];
|
|
78
|
+
}
|
|
79
|
+
}];
|
|
63
80
|
[_input->textView.textStorage endEditing];
|
|
64
81
|
}
|
|
65
82
|
|
|
66
83
|
- (void)removeTypingAttributes {
|
|
67
|
-
UIFont *currentFontAttr =
|
|
68
|
-
|
|
69
|
-
|
|
84
|
+
UIFont *currentFontAttr =
|
|
85
|
+
(UIFont *)_input->textView.typingAttributes[NSFontAttributeName];
|
|
86
|
+
if (currentFontAttr != nullptr) {
|
|
87
|
+
NSMutableDictionary *newTypingAttrs =
|
|
88
|
+
[_input->textView.typingAttributes mutableCopy];
|
|
70
89
|
newTypingAttrs[NSFontAttributeName] = [currentFontAttr removeItalic];
|
|
71
90
|
_input->textView.typingAttributes = newTypingAttrs;
|
|
72
91
|
}
|
|
73
92
|
}
|
|
74
93
|
|
|
75
|
-
- (BOOL)styleCondition:(id _Nullable)value
|
|
94
|
+
- (BOOL)styleCondition:(id _Nullable)value:(NSRange)range {
|
|
76
95
|
UIFont *font = (UIFont *)value;
|
|
77
96
|
return font != nullptr && [font isItalic];
|
|
78
97
|
}
|
|
79
98
|
|
|
80
99
|
- (BOOL)detectStyle:(NSRange)range {
|
|
81
|
-
if(range.length >= 1) {
|
|
82
|
-
return [OccurenceUtils detect:NSFontAttributeName
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
100
|
+
if (range.length >= 1) {
|
|
101
|
+
return [OccurenceUtils detect:NSFontAttributeName
|
|
102
|
+
withInput:_input
|
|
103
|
+
inRange:range
|
|
104
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
105
|
+
return [self styleCondition:value:range];
|
|
106
|
+
}];
|
|
87
107
|
} else {
|
|
88
|
-
return [OccurenceUtils detect:NSFontAttributeName
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
108
|
+
return [OccurenceUtils detect:NSFontAttributeName
|
|
109
|
+
withInput:_input
|
|
110
|
+
atIndex:range.location
|
|
111
|
+
checkPrevious:NO
|
|
112
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
113
|
+
return [self styleCondition:value:range];
|
|
114
|
+
}];
|
|
93
115
|
}
|
|
94
116
|
}
|
|
95
117
|
|
|
96
118
|
- (BOOL)anyOccurence:(NSRange)range {
|
|
97
|
-
return [OccurenceUtils any:NSFontAttributeName
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
119
|
+
return [OccurenceUtils any:NSFontAttributeName
|
|
120
|
+
withInput:_input
|
|
121
|
+
inRange:range
|
|
122
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
123
|
+
return [self styleCondition:value:range];
|
|
124
|
+
}];
|
|
102
125
|
}
|
|
103
126
|
|
|
104
127
|
- (NSArray<StylePair *> *_Nullable)findAllOccurences:(NSRange)range {
|
|
105
|
-
return [OccurenceUtils all:NSFontAttributeName
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
128
|
+
return [OccurenceUtils all:NSFontAttributeName
|
|
129
|
+
withInput:_input
|
|
130
|
+
inRange:range
|
|
131
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
132
|
+
return [self styleCondition:value:range];
|
|
133
|
+
}];
|
|
110
134
|
}
|
|
111
135
|
|
|
112
136
|
@end
|