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
|
@@ -2,171 +2,192 @@
|
|
|
2
2
|
|
|
3
3
|
@implementation OccurenceUtils
|
|
4
4
|
|
|
5
|
-
+ (BOOL)detect
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
{
|
|
5
|
+
+ (BOOL)detect:(NSAttributedStringKey _Nonnull)key
|
|
6
|
+
withInput:(EnrichedTextInputView *_Nonnull)input
|
|
7
|
+
inRange:(NSRange)range
|
|
8
|
+
withCondition:(BOOL(NS_NOESCAPE ^ _Nonnull)(id _Nullable value,
|
|
9
|
+
NSRange range))condition {
|
|
11
10
|
__block NSInteger totalLength = 0;
|
|
12
|
-
[input->textView.textStorage
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
11
|
+
[input->textView.textStorage
|
|
12
|
+
enumerateAttribute:key
|
|
13
|
+
inRange:range
|
|
14
|
+
options:0
|
|
15
|
+
usingBlock:^(id _Nullable value, NSRange range,
|
|
16
|
+
BOOL *_Nonnull stop) {
|
|
17
|
+
if (condition(value, range)) {
|
|
18
|
+
totalLength += range.length;
|
|
19
|
+
}
|
|
20
|
+
}];
|
|
19
21
|
return totalLength == range.length;
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
// checkPrevious flag is used for styles like lists or blockquotes
|
|
23
|
-
// it means that first character of paragraph will be checked instead if the
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
{
|
|
25
|
+
// it means that first character of paragraph will be checked instead if the
|
|
26
|
+
// detection is not in input's selected range and at the end of the input
|
|
27
|
+
+ (BOOL)detect:(NSAttributedStringKey _Nonnull)key
|
|
28
|
+
withInput:(EnrichedTextInputView *_Nonnull)input
|
|
29
|
+
atIndex:(NSUInteger)index
|
|
30
|
+
checkPrevious:(BOOL)checkPrev
|
|
31
|
+
withCondition:(BOOL(NS_NOESCAPE ^ _Nonnull)(id _Nullable value,
|
|
32
|
+
NSRange range))condition {
|
|
31
33
|
NSRange detectionRange = NSMakeRange(index, 0);
|
|
32
34
|
id attrValue;
|
|
33
|
-
if(NSEqualRanges(input->textView.selectedRange, detectionRange)) {
|
|
35
|
+
if (NSEqualRanges(input->textView.selectedRange, detectionRange)) {
|
|
34
36
|
attrValue = input->textView.typingAttributes[key];
|
|
35
|
-
} else if(index == input->textView.textStorage.string.length) {
|
|
36
|
-
if(checkPrev) {
|
|
37
|
-
NSRange paragraphRange = [input->textView.textStorage.string
|
|
38
|
-
|
|
37
|
+
} else if (index == input->textView.textStorage.string.length) {
|
|
38
|
+
if (checkPrev) {
|
|
39
|
+
NSRange paragraphRange = [input->textView.textStorage.string
|
|
40
|
+
paragraphRangeForRange:detectionRange];
|
|
41
|
+
if (paragraphRange.location == detectionRange.location) {
|
|
39
42
|
return NO;
|
|
40
43
|
} else {
|
|
41
|
-
return [self detect:key
|
|
44
|
+
return [self detect:key
|
|
45
|
+
withInput:input
|
|
46
|
+
inRange:NSMakeRange(paragraphRange.location, 1)
|
|
47
|
+
withCondition:condition];
|
|
42
48
|
}
|
|
43
49
|
} else {
|
|
44
50
|
return NO;
|
|
45
51
|
}
|
|
46
52
|
} else {
|
|
47
53
|
NSRange attrRange = NSMakeRange(0, 0);
|
|
48
|
-
attrValue = [input->textView.textStorage attribute:key
|
|
54
|
+
attrValue = [input->textView.textStorage attribute:key
|
|
55
|
+
atIndex:index
|
|
56
|
+
effectiveRange:&attrRange];
|
|
49
57
|
}
|
|
50
58
|
return condition(attrValue, detectionRange);
|
|
51
59
|
}
|
|
52
60
|
|
|
53
|
-
+ (BOOL)detectMultiple
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
{
|
|
61
|
+
+ (BOOL)detectMultiple:(NSArray<NSAttributedStringKey> *_Nonnull)keys
|
|
62
|
+
withInput:(EnrichedTextInputView *_Nonnull)input
|
|
63
|
+
inRange:(NSRange)range
|
|
64
|
+
withCondition:(BOOL(NS_NOESCAPE ^ _Nonnull)(id _Nullable value,
|
|
65
|
+
NSRange range))condition {
|
|
59
66
|
__block NSInteger totalLength = 0;
|
|
60
|
-
for(NSString*
|
|
61
|
-
[input->textView.textStorage
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
for (NSString *key in keys) {
|
|
68
|
+
[input->textView.textStorage
|
|
69
|
+
enumerateAttribute:key
|
|
70
|
+
inRange:range
|
|
71
|
+
options:0
|
|
72
|
+
usingBlock:^(id _Nullable value, NSRange range,
|
|
73
|
+
BOOL *_Nonnull stop) {
|
|
74
|
+
if (condition(value, range)) {
|
|
75
|
+
totalLength += range.length;
|
|
76
|
+
}
|
|
77
|
+
}];
|
|
68
78
|
}
|
|
69
79
|
return totalLength == range.length;
|
|
70
80
|
}
|
|
71
81
|
|
|
72
|
-
+ (BOOL)any
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
{
|
|
82
|
+
+ (BOOL)any:(NSAttributedStringKey _Nonnull)key
|
|
83
|
+
withInput:(EnrichedTextInputView *_Nonnull)input
|
|
84
|
+
inRange:(NSRange)range
|
|
85
|
+
withCondition:(BOOL(NS_NOESCAPE ^ _Nonnull)(id _Nullable value,
|
|
86
|
+
NSRange range))condition {
|
|
78
87
|
__block BOOL found = NO;
|
|
79
|
-
[input->textView.textStorage
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
[input->textView.textStorage
|
|
89
|
+
enumerateAttribute:key
|
|
90
|
+
inRange:range
|
|
91
|
+
options:0
|
|
92
|
+
usingBlock:^(id _Nullable value, NSRange range,
|
|
93
|
+
BOOL *_Nonnull stop) {
|
|
94
|
+
if (condition(value, range)) {
|
|
95
|
+
found = YES;
|
|
96
|
+
*stop = YES;
|
|
97
|
+
}
|
|
98
|
+
}];
|
|
87
99
|
return found;
|
|
88
100
|
}
|
|
89
101
|
|
|
90
|
-
+ (BOOL)anyMultiple
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
{
|
|
102
|
+
+ (BOOL)anyMultiple:(NSArray<NSAttributedStringKey> *_Nonnull)keys
|
|
103
|
+
withInput:(EnrichedTextInputView *_Nonnull)input
|
|
104
|
+
inRange:(NSRange)range
|
|
105
|
+
withCondition:(BOOL(NS_NOESCAPE ^ _Nonnull)(id _Nullable value,
|
|
106
|
+
NSRange range))condition {
|
|
96
107
|
__block BOOL found = NO;
|
|
97
|
-
for(NSString *key in keys) {
|
|
98
|
-
[input->textView.textStorage
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
108
|
+
for (NSString *key in keys) {
|
|
109
|
+
[input->textView.textStorage
|
|
110
|
+
enumerateAttribute:key
|
|
111
|
+
inRange:range
|
|
112
|
+
options:0
|
|
113
|
+
usingBlock:^(id _Nullable value, NSRange range,
|
|
114
|
+
BOOL *_Nonnull stop) {
|
|
115
|
+
if (condition(value, range)) {
|
|
116
|
+
found = YES;
|
|
117
|
+
*stop = YES;
|
|
118
|
+
}
|
|
119
|
+
}];
|
|
120
|
+
if (found) {
|
|
107
121
|
return YES;
|
|
108
122
|
}
|
|
109
123
|
}
|
|
110
124
|
return NO;
|
|
111
125
|
}
|
|
112
126
|
|
|
113
|
-
+ (NSArray<StylePair *> *_Nullable)all
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
127
|
+
+ (NSArray<StylePair *> *_Nullable)all:(NSAttributedStringKey _Nonnull)key
|
|
128
|
+
withInput:(EnrichedTextInputView *_Nonnull)input
|
|
129
|
+
inRange:(NSRange)range
|
|
130
|
+
withCondition:
|
|
131
|
+
(BOOL(NS_NOESCAPE ^ _Nonnull)(id _Nullable value,
|
|
132
|
+
NSRange range))
|
|
133
|
+
condition {
|
|
134
|
+
__block NSMutableArray<StylePair *> *occurences =
|
|
135
|
+
[[NSMutableArray<StylePair *> alloc] init];
|
|
136
|
+
[input->textView.textStorage
|
|
137
|
+
enumerateAttribute:key
|
|
138
|
+
inRange:range
|
|
139
|
+
options:0
|
|
140
|
+
usingBlock:^(id _Nullable value, NSRange range,
|
|
141
|
+
BOOL *_Nonnull stop) {
|
|
142
|
+
if (condition(value, range)) {
|
|
143
|
+
StylePair *pair = [[StylePair alloc] init];
|
|
144
|
+
pair.rangeValue = [NSValue valueWithRange:range];
|
|
145
|
+
pair.styleValue = value;
|
|
146
|
+
[occurences addObject:pair];
|
|
147
|
+
}
|
|
148
|
+
}];
|
|
130
149
|
return occurences;
|
|
131
150
|
}
|
|
132
151
|
|
|
133
|
-
+ (NSArray<StylePair *> *_Nullable)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
{
|
|
139
|
-
__block NSMutableArray<StylePair *> *occurences =
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
152
|
+
+ (NSArray<StylePair *> *_Nullable)
|
|
153
|
+
allMultiple:(NSArray<NSAttributedStringKey> *_Nonnull)keys
|
|
154
|
+
withInput:(EnrichedTextInputView *_Nonnull)input
|
|
155
|
+
inRange:(NSRange)range
|
|
156
|
+
withCondition:(BOOL(NS_NOESCAPE ^ _Nonnull)(id _Nullable value,
|
|
157
|
+
NSRange range))condition {
|
|
158
|
+
__block NSMutableArray<StylePair *> *occurences =
|
|
159
|
+
[[NSMutableArray<StylePair *> alloc] init];
|
|
160
|
+
for (NSString *key in keys) {
|
|
161
|
+
[input->textView.textStorage
|
|
162
|
+
enumerateAttribute:key
|
|
163
|
+
inRange:range
|
|
164
|
+
options:0
|
|
165
|
+
usingBlock:^(id _Nullable value, NSRange range,
|
|
166
|
+
BOOL *_Nonnull stop) {
|
|
167
|
+
if (condition(value, range)) {
|
|
168
|
+
StylePair *pair = [[StylePair alloc] init];
|
|
169
|
+
pair.rangeValue = [NSValue valueWithRange:range];
|
|
170
|
+
pair.styleValue = value;
|
|
171
|
+
[occurences addObject:pair];
|
|
172
|
+
}
|
|
173
|
+
}];
|
|
151
174
|
}
|
|
152
175
|
return occurences;
|
|
153
176
|
}
|
|
154
177
|
|
|
155
|
-
+ (NSArray *_Nonnull)getRangesWithout
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
inRange:(NSRange)range
|
|
159
|
-
{
|
|
178
|
+
+ (NSArray *_Nonnull)getRangesWithout:(NSArray<NSNumber *> *_Nonnull)types
|
|
179
|
+
withInput:(EnrichedTextInputView *_Nonnull)input
|
|
180
|
+
inRange:(NSRange)range {
|
|
160
181
|
NSMutableArray<id> *activeStyleObjects = [[NSMutableArray alloc] init];
|
|
161
|
-
for(NSNumber *type in types) {
|
|
182
|
+
for (NSNumber *type in types) {
|
|
162
183
|
id<BaseStyleProtocol> styleClass = input->stylesDict[type];
|
|
163
184
|
[activeStyleObjects addObject:styleClass];
|
|
164
185
|
}
|
|
165
|
-
|
|
186
|
+
|
|
166
187
|
if (activeStyleObjects.count == 0) {
|
|
167
|
-
return @[[NSValue valueWithRange:range]];
|
|
188
|
+
return @[ [NSValue valueWithRange:range] ];
|
|
168
189
|
}
|
|
169
|
-
|
|
190
|
+
|
|
170
191
|
NSMutableArray<NSValue *> *newRanges = [[NSMutableArray alloc] init];
|
|
171
192
|
NSUInteger lastRangeLocation = range.location;
|
|
172
193
|
NSUInteger endLocation = range.location + range.length;
|
|
@@ -184,15 +205,17 @@
|
|
|
184
205
|
|
|
185
206
|
if (forbiddenStyleFound) {
|
|
186
207
|
if (i > lastRangeLocation) {
|
|
187
|
-
|
|
188
|
-
|
|
208
|
+
NSRange cleanRange =
|
|
209
|
+
NSMakeRange(lastRangeLocation, i - lastRangeLocation);
|
|
210
|
+
[newRanges addObject:[NSValue valueWithRange:cleanRange]];
|
|
189
211
|
}
|
|
190
212
|
lastRangeLocation = i + 1;
|
|
191
213
|
}
|
|
192
214
|
}
|
|
193
215
|
|
|
194
216
|
if (lastRangeLocation < endLocation) {
|
|
195
|
-
NSRange remainingRange =
|
|
217
|
+
NSRange remainingRange =
|
|
218
|
+
NSMakeRange(lastRangeLocation, endLocation - lastRangeLocation);
|
|
196
219
|
[newRanges addObject:[NSValue valueWithRange:remainingRange]];
|
|
197
220
|
}
|
|
198
221
|
|
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
#pragma once
|
|
3
3
|
|
|
4
4
|
@interface ParagraphAttributesUtils : NSObject
|
|
5
|
-
+ (BOOL)handleBackspaceInRange:(NSRange)range
|
|
6
|
-
|
|
5
|
+
+ (BOOL)handleBackspaceInRange:(NSRange)range
|
|
6
|
+
replacementText:(NSString *)text
|
|
7
|
+
input:(id)input;
|
|
8
|
+
+ (BOOL)handleParagraphStylesMergeOnBackspace:(NSRange)range
|
|
9
|
+
replacementText:(NSString *)text
|
|
10
|
+
input:(id)input;
|
|
11
|
+
+ (BOOL)handleResetTypingAttributesOnBackspace:(NSRange)range
|
|
12
|
+
replacementText:(NSString *)text
|
|
13
|
+
input:(id)input;
|
|
14
|
+
+ (BOOL)isParagraphEmpty:(NSRange)range inString:(NSString *)string;
|
|
7
15
|
@end
|