react-native-enriched 0.2.0 → 0.3.0
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 +16 -17
- package/android/build.gradle +77 -72
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerDelegate.java +21 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerInterface.java +7 -0
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.cpp +156 -0
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.h +147 -0
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/Props.cpp +10 -0
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/Props.h +194 -0
- package/android/lint.gradle +70 -0
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputConnectionWrapper.kt +140 -0
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt +304 -83
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewLayoutManager.kt +3 -1
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt +166 -51
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewPackage.kt +1 -3
- package/android/src/main/java/com/swmansion/enriched/MeasurementStore.kt +70 -21
- package/android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt +21 -11
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeHtmlEvent.kt +8 -9
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeSelectionEvent.kt +10 -9
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeStateDeprecatedEvent.kt +21 -0
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeStateEvent.kt +9 -12
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeTextEvent.kt +10 -10
- package/android/src/main/java/com/swmansion/enriched/events/OnInputBlurEvent.kt +7 -9
- package/android/src/main/java/com/swmansion/enriched/events/OnInputFocusEvent.kt +7 -9
- package/android/src/main/java/com/swmansion/enriched/events/OnInputKeyPressEvent.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/events/OnLinkDetectedEvent.kt +13 -11
- package/android/src/main/java/com/swmansion/enriched/events/OnMentionDetectedEvent.kt +10 -9
- package/android/src/main/java/com/swmansion/enriched/events/OnMentionEvent.kt +9 -8
- package/android/src/main/java/com/swmansion/enriched/events/OnRequestHtmlResultEvent.kt +32 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBlockQuoteSpan.kt +24 -5
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedCodeBlockSpan.kt +10 -2
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH4Span.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH5Span.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH6Span.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedImageSpan.kt +34 -17
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedInlineCodeSpan.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt +7 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedLinkSpan.kt +10 -4
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedMentionSpan.kt +14 -11
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedOrderedListSpan.kt +18 -11
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedSpans.kt +174 -72
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt +7 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt +7 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnorderedListSpan.kt +11 -5
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedBlockSpan.kt +3 -2
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedHeadingSpan.kt +1 -2
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedInlineSpan.kt +1 -2
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedParagraphSpan.kt +3 -2
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedZeroWidthSpaceSpan.kt +1 -2
- package/android/src/main/java/com/swmansion/enriched/spans/utils/ForceRedrawSpan.kt +2 -1
- package/android/src/main/java/com/swmansion/enriched/styles/HtmlStyle.kt +155 -20
- package/android/src/main/java/com/swmansion/enriched/styles/InlineStyles.kt +25 -8
- package/android/src/main/java/com/swmansion/enriched/styles/ListStyles.kt +60 -20
- package/android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt +161 -25
- package/android/src/main/java/com/swmansion/enriched/styles/ParametrizedStyles.kt +128 -52
- package/android/src/main/java/com/swmansion/enriched/utils/AsyncDrawable.kt +10 -7
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedConstants.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedEditableFactory.kt +17 -0
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedParser.java +136 -87
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSelection.kt +71 -42
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSpanState.kt +183 -48
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSpannable.kt +82 -0
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSpannableStringBuilder.kt +15 -0
- package/android/src/main/java/com/swmansion/enriched/utils/Utils.kt +0 -70
- package/android/src/main/java/com/swmansion/enriched/watchers/EnrichedSpanWatcher.kt +46 -14
- package/android/src/main/java/com/swmansion/enriched/watchers/EnrichedTextWatcher.kt +34 -11
- package/android/src/main/new_arch/CMakeLists.txt +6 -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 +33 -14
- package/ios/EnrichedTextInputView.h +26 -14
- package/ios/EnrichedTextInputView.mm +1209 -586
- package/ios/config/InputConfig.h +24 -6
- package/ios/config/InputConfig.mm +154 -38
- package/ios/{utils → extensions}/ColorExtension.mm +7 -5
- package/ios/extensions/FontExtension.mm +106 -0
- package/ios/{utils → extensions}/LayoutManagerExtension.h +1 -1
- package/ios/extensions/LayoutManagerExtension.mm +396 -0
- package/ios/{utils → extensions}/StringExtension.mm +19 -16
- package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.cpp +156 -0
- package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.h +147 -0
- package/ios/generated/RNEnrichedTextInputViewSpec/Props.cpp +10 -0
- package/ios/generated/RNEnrichedTextInputViewSpec/Props.h +194 -0
- package/ios/generated/RNEnrichedTextInputViewSpec/RCTComponentViewHelpers.h +95 -0
- package/ios/inputParser/InputParser.h +5 -5
- package/ios/inputParser/InputParser.mm +864 -380
- package/ios/inputTextView/InputTextView.h +1 -1
- package/ios/inputTextView/InputTextView.mm +100 -59
- package/ios/{utils → interfaces}/BaseStyleProtocol.h +2 -2
- package/ios/interfaces/ImageAttachment.h +10 -0
- package/ios/interfaces/ImageAttachment.mm +36 -0
- package/ios/interfaces/LinkRegexConfig.h +19 -0
- package/ios/interfaces/LinkRegexConfig.mm +37 -0
- package/ios/interfaces/MediaAttachment.h +23 -0
- package/ios/interfaces/MediaAttachment.mm +31 -0
- package/ios/{utils → interfaces}/MentionParams.h +0 -1
- package/ios/{utils → interfaces}/MentionStyleProps.mm +27 -20
- package/ios/{utils → interfaces}/StyleHeaders.h +37 -15
- package/ios/{utils → interfaces}/StyleTypeEnum.h +3 -0
- 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 +110 -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/H4Style.mm +17 -0
- package/ios/styles/H5Style.mm +17 -0
- package/ios/styles/H6Style.mm +17 -0
- package/ios/styles/HeadingStyleBase.mm +148 -86
- package/ios/styles/ImageStyle.mm +75 -73
- package/ios/styles/InlineCodeStyle.mm +162 -88
- package/ios/styles/ItalicStyle.mm +76 -52
- package/ios/styles/LinkStyle.mm +411 -232
- 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/OccurenceUtils.h +42 -42
- package/ios/utils/OccurenceUtils.mm +142 -119
- package/ios/utils/ParagraphAttributesUtils.h +10 -2
- package/ios/utils/ParagraphAttributesUtils.mm +182 -71
- package/ios/utils/ParagraphsUtils.h +2 -1
- package/ios/utils/ParagraphsUtils.mm +41 -27
- 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 +61 -2
- package/lib/module/EnrichedTextInput.js.map +1 -1
- package/lib/module/EnrichedTextInputNativeComponent.ts +149 -12
- package/lib/module/{normalizeHtmlStyle.js → utils/normalizeHtmlStyle.js} +12 -0
- package/lib/module/utils/normalizeHtmlStyle.js.map +1 -0
- package/lib/module/utils/regexParser.js +46 -0
- package/lib/module/utils/regexParser.js.map +1 -0
- package/lib/typescript/src/EnrichedTextInput.d.ts +24 -14
- package/lib/typescript/src/EnrichedTextInput.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts +129 -12
- package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts +4 -0
- package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts.map +1 -0
- package/lib/typescript/src/utils/regexParser.d.ts +3 -0
- package/lib/typescript/src/utils/regexParser.d.ts.map +1 -0
- package/package.json +17 -6
- package/src/EnrichedTextInput.tsx +96 -13
- package/src/EnrichedTextInputNativeComponent.ts +149 -12
- package/src/index.tsx +2 -0
- package/src/{normalizeHtmlStyle.ts → utils/normalizeHtmlStyle.ts} +14 -2
- package/src/utils/regexParser.ts +56 -0
- package/ios/utils/FontExtension.mm +0 -91
- package/ios/utils/LayoutManagerExtension.mm +0 -286
- package/lib/module/normalizeHtmlStyle.js.map +0 -1
- package/lib/typescript/src/normalizeHtmlStyle.d.ts +0 -4
- package/lib/typescript/src/normalizeHtmlStyle.d.ts.map +0 -1
- package/ios/{utils → extensions}/ColorExtension.h +0 -0
- package/ios/{utils → extensions}/FontExtension.h +0 -0
- package/ios/{utils → extensions}/StringExtension.h +1 -1
- package/ios/{utils → interfaces}/ImageData.h +0 -0
- package/ios/{utils → interfaces}/ImageData.mm +0 -0
- package/ios/{utils → interfaces}/LinkData.h +0 -0
- package/ios/{utils → interfaces}/LinkData.mm +0 -0
- package/ios/{utils → interfaces}/MentionParams.mm +0 -0
- package/ios/{utils → interfaces}/MentionStyleProps.h +1 -1
- /package/ios/{utils → interfaces}/StylePair.h +0 -0
- /package/ios/{utils → interfaces}/StylePair.mm +0 -0
- /package/ios/{utils → interfaces}/TextDecorationLineEnum.h +0 -0
- /package/ios/{utils → interfaces}/TextDecorationLineEnum.mm +0 -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,142 @@
|
|
|
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
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
154
|
+
NSTextStorage *storage = _input->textView.textStorage;
|
|
155
|
+
NSString *string = storage.string;
|
|
156
|
+
NSUInteger length = string.length;
|
|
157
|
+
|
|
158
|
+
if (length == 0)
|
|
159
|
+
return;
|
|
160
|
+
|
|
161
|
+
CFStringInlineBuffer buffer;
|
|
162
|
+
CFStringInitInlineBuffer((CFStringRef)string, &buffer,
|
|
163
|
+
CFRangeMake(0, length));
|
|
164
|
+
|
|
165
|
+
for (NSUInteger index = 0; index < length; index++) {
|
|
166
|
+
unichar ch = CFStringGetCharacterFromInlineBuffer(&buffer, index);
|
|
167
|
+
// check new lines only
|
|
168
|
+
if (![[NSCharacterSet newlineCharacterSet] characterIsMember:ch])
|
|
169
|
+
continue;
|
|
170
|
+
|
|
171
|
+
NSRange newlineRange = NSMakeRange(index, 1);
|
|
172
|
+
|
|
173
|
+
UIColor *bgColor = [storage attribute:NSBackgroundColorAttributeName
|
|
174
|
+
atIndex:index
|
|
175
|
+
effectiveRange:nil];
|
|
176
|
+
|
|
177
|
+
if (bgColor != nil && [self styleCondition:bgColor range:newlineRange]) {
|
|
178
|
+
[self removeAttributes:newlineRange];
|
|
113
179
|
}
|
|
114
180
|
}
|
|
115
181
|
}
|
|
116
182
|
|
|
117
|
-
// emojis don't retain monospace font attribute so we check for the background
|
|
118
|
-
|
|
183
|
+
// emojis don't retain monospace font attribute so we check for the background
|
|
184
|
+
// color if there is no mention
|
|
185
|
+
- (BOOL)styleCondition:(id _Nullable)value range:(NSRange)range {
|
|
119
186
|
UIColor *bgColor = (UIColor *)value;
|
|
120
187
|
MentionStyle *mStyle = _input->stylesDict[@([MentionStyle getStyleType])];
|
|
121
188
|
return bgColor != nullptr && mStyle != nullptr && ![mStyle detectStyle:range];
|
|
122
189
|
}
|
|
123
190
|
|
|
124
191
|
- (BOOL)detectStyle:(NSRange)range {
|
|
125
|
-
if(range.length >= 1) {
|
|
192
|
+
if (range.length >= 1) {
|
|
126
193
|
// detect only in non-newline characters
|
|
127
|
-
NSArray *nonNewlineRanges =
|
|
128
|
-
|
|
194
|
+
NSArray *nonNewlineRanges =
|
|
195
|
+
[ParagraphsUtils getNonNewlineRangesIn:_input->textView range:range];
|
|
196
|
+
if (nonNewlineRanges.count == 0) {
|
|
129
197
|
return NO;
|
|
130
198
|
}
|
|
131
|
-
|
|
199
|
+
|
|
132
200
|
BOOL detected = YES;
|
|
133
|
-
for(NSValue *value in nonNewlineRanges) {
|
|
201
|
+
for (NSValue *value in nonNewlineRanges) {
|
|
134
202
|
NSRange currentRange = [value rangeValue];
|
|
135
|
-
BOOL currentDetected =
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
203
|
+
BOOL currentDetected =
|
|
204
|
+
[OccurenceUtils detect:NSBackgroundColorAttributeName
|
|
205
|
+
withInput:_input
|
|
206
|
+
inRange:currentRange
|
|
207
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
208
|
+
return [self styleCondition:value range:range];
|
|
209
|
+
}];
|
|
140
210
|
detected = detected && currentDetected;
|
|
141
211
|
}
|
|
142
|
-
|
|
212
|
+
|
|
143
213
|
return detected;
|
|
144
214
|
} else {
|
|
145
|
-
return [OccurenceUtils detect:NSBackgroundColorAttributeName
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
215
|
+
return [OccurenceUtils detect:NSBackgroundColorAttributeName
|
|
216
|
+
withInput:_input
|
|
217
|
+
atIndex:range.location
|
|
218
|
+
checkPrevious:NO
|
|
219
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
220
|
+
return [self styleCondition:value range:range];
|
|
221
|
+
}];
|
|
150
222
|
}
|
|
151
223
|
}
|
|
152
224
|
|
|
153
225
|
- (BOOL)anyOccurence:(NSRange)range {
|
|
154
|
-
return [OccurenceUtils any:NSBackgroundColorAttributeName
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
226
|
+
return [OccurenceUtils any:NSBackgroundColorAttributeName
|
|
227
|
+
withInput:_input
|
|
228
|
+
inRange:range
|
|
229
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
230
|
+
return [self styleCondition:value range:range];
|
|
231
|
+
}];
|
|
159
232
|
}
|
|
160
233
|
|
|
161
234
|
- (NSArray<StylePair *> *_Nullable)findAllOccurences:(NSRange)range {
|
|
162
|
-
return [OccurenceUtils all:NSBackgroundColorAttributeName
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
235
|
+
return [OccurenceUtils all:NSBackgroundColorAttributeName
|
|
236
|
+
withInput:_input
|
|
237
|
+
inRange:range
|
|
238
|
+
withCondition:^BOOL(id _Nullable value, NSRange range) {
|
|
239
|
+
return [self styleCondition:value range:range];
|
|
240
|
+
}];
|
|
167
241
|
}
|
|
168
242
|
|
|
169
243
|
@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 :(NSRange)range {
|
|
94
|
+
- (BOOL)styleCondition:(id _Nullable)value range:(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: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: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: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:range];
|
|
133
|
+
}];
|
|
110
134
|
}
|
|
111
135
|
|
|
112
136
|
@end
|