react-native-enriched 0.1.6 → 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.
Files changed (123) hide show
  1. package/README.md +4 -14
  2. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerDelegate.java +4 -1
  3. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerInterface.java +2 -1
  4. package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.cpp +10 -0
  5. package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.h +7 -0
  6. package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/Props.h +0 -45
  7. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt +111 -2
  8. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt +9 -3
  9. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewPackage.kt +2 -0
  10. package/android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt +1 -1
  11. package/android/src/main/java/com/swmansion/enriched/events/OnRequestHtmlResultEvent.kt +33 -0
  12. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBlockQuoteSpan.kt +6 -0
  13. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt +6 -0
  14. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedCodeBlockSpan.kt +42 -1
  15. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt +6 -0
  16. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt +6 -0
  17. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt +6 -0
  18. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedImageSpan.kt +135 -9
  19. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedInlineCodeSpan.kt +6 -0
  20. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt +5 -0
  21. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedLinkSpan.kt +6 -0
  22. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedMentionSpan.kt +6 -0
  23. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedOrderedListSpan.kt +6 -0
  24. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedSpans.kt +13 -3
  25. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt +5 -0
  26. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt +5 -0
  27. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnorderedListSpan.kt +6 -0
  28. package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt +4 -0
  29. package/android/src/main/java/com/swmansion/enriched/spans/utils/ForceRedrawSpan.kt +13 -0
  30. package/android/src/main/java/com/swmansion/enriched/styles/HtmlStyle.kt +80 -9
  31. package/android/src/main/java/com/swmansion/enriched/styles/InlineStyles.kt +1 -0
  32. package/android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt +188 -5
  33. package/android/src/main/java/com/swmansion/enriched/styles/ParametrizedStyles.kt +57 -30
  34. package/android/src/main/java/com/swmansion/enriched/utils/AsyncDrawable.kt +91 -0
  35. package/android/src/main/java/com/swmansion/enriched/utils/EnrichedParser.java +24 -13
  36. package/android/src/main/java/com/swmansion/enriched/utils/ResourceManager.kt +26 -0
  37. package/android/src/main/java/com/swmansion/enriched/watchers/EnrichedSpanWatcher.kt +3 -0
  38. package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.cpp +6 -6
  39. package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.h +6 -6
  40. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputComponentDescriptor.h +19 -19
  41. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.cpp +40 -51
  42. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.h +13 -15
  43. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.cpp +23 -21
  44. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.h +35 -36
  45. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.cpp +4 -4
  46. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.h +13 -14
  47. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/conversions.h +12 -13
  48. package/android/src/main/res/drawable/broken_image.xml +10 -0
  49. package/ios/EnrichedTextInputView.h +27 -12
  50. package/ios/EnrichedTextInputView.mm +906 -547
  51. package/ios/attachments/ImageAttachment.h +10 -0
  52. package/ios/attachments/ImageAttachment.mm +34 -0
  53. package/ios/attachments/MediaAttachment.h +23 -0
  54. package/ios/attachments/MediaAttachment.mm +31 -0
  55. package/ios/config/InputConfig.h +12 -6
  56. package/ios/config/InputConfig.mm +71 -33
  57. package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.cpp +10 -0
  58. package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.h +7 -0
  59. package/ios/generated/RNEnrichedTextInputViewSpec/Props.h +0 -45
  60. package/ios/generated/RNEnrichedTextInputViewSpec/RCTComponentViewHelpers.h +41 -4
  61. package/ios/inputParser/InputParser.h +5 -5
  62. package/ios/inputParser/InputParser.mm +867 -333
  63. package/ios/inputTextView/InputTextView.h +1 -1
  64. package/ios/inputTextView/InputTextView.mm +100 -59
  65. package/ios/internals/EnrichedTextInputViewComponentDescriptor.h +11 -9
  66. package/ios/internals/EnrichedTextInputViewShadowNode.h +28 -24
  67. package/ios/internals/EnrichedTextInputViewShadowNode.mm +64 -47
  68. package/ios/internals/EnrichedTextInputViewState.h +3 -1
  69. package/ios/styles/BlockQuoteStyle.mm +192 -142
  70. package/ios/styles/BoldStyle.mm +96 -62
  71. package/ios/styles/CodeBlockStyle.mm +304 -0
  72. package/ios/styles/H1Style.mm +10 -3
  73. package/ios/styles/H2Style.mm +10 -3
  74. package/ios/styles/H3Style.mm +10 -3
  75. package/ios/styles/HeadingStyleBase.mm +129 -84
  76. package/ios/styles/ImageStyle.mm +160 -0
  77. package/ios/styles/InlineCodeStyle.mm +149 -84
  78. package/ios/styles/ItalicStyle.mm +77 -51
  79. package/ios/styles/LinkStyle.mm +353 -224
  80. package/ios/styles/MentionStyle.mm +434 -220
  81. package/ios/styles/OrderedListStyle.mm +172 -105
  82. package/ios/styles/StrikethroughStyle.mm +53 -34
  83. package/ios/styles/UnderlineStyle.mm +69 -45
  84. package/ios/styles/UnorderedListStyle.mm +170 -105
  85. package/ios/utils/BaseStyleProtocol.h +3 -2
  86. package/ios/utils/ColorExtension.mm +7 -5
  87. package/ios/utils/FontExtension.mm +42 -27
  88. package/ios/utils/ImageData.h +10 -0
  89. package/ios/utils/ImageData.mm +4 -0
  90. package/ios/utils/LayoutManagerExtension.h +1 -1
  91. package/ios/utils/LayoutManagerExtension.mm +334 -109
  92. package/ios/utils/MentionParams.h +0 -1
  93. package/ios/utils/MentionStyleProps.h +1 -1
  94. package/ios/utils/MentionStyleProps.mm +27 -20
  95. package/ios/utils/OccurenceUtils.h +42 -38
  96. package/ios/utils/OccurenceUtils.mm +177 -107
  97. package/ios/utils/ParagraphAttributesUtils.h +6 -1
  98. package/ios/utils/ParagraphAttributesUtils.mm +152 -41
  99. package/ios/utils/ParagraphsUtils.h +2 -1
  100. package/ios/utils/ParagraphsUtils.mm +40 -26
  101. package/ios/utils/StringExtension.h +1 -1
  102. package/ios/utils/StringExtension.mm +19 -16
  103. package/ios/utils/StyleHeaders.h +35 -11
  104. package/ios/utils/TextInsertionUtils.h +13 -2
  105. package/ios/utils/TextInsertionUtils.mm +38 -20
  106. package/ios/utils/WordsUtils.h +2 -1
  107. package/ios/utils/WordsUtils.mm +32 -22
  108. package/ios/utils/ZeroWidthSpaceUtils.h +3 -1
  109. package/ios/utils/ZeroWidthSpaceUtils.mm +153 -75
  110. package/lib/module/EnrichedTextInput.js +41 -3
  111. package/lib/module/EnrichedTextInput.js.map +1 -1
  112. package/lib/module/EnrichedTextInputNativeComponent.ts +17 -5
  113. package/lib/module/normalizeHtmlStyle.js +0 -4
  114. package/lib/module/normalizeHtmlStyle.js.map +1 -1
  115. package/lib/typescript/src/EnrichedTextInput.d.ts +2 -5
  116. package/lib/typescript/src/EnrichedTextInput.d.ts.map +1 -1
  117. package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts +7 -5
  118. package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts.map +1 -1
  119. package/lib/typescript/src/normalizeHtmlStyle.d.ts.map +1 -1
  120. package/package.json +8 -1
  121. package/src/EnrichedTextInput.tsx +48 -7
  122. package/src/EnrichedTextInputNativeComponent.ts +17 -5
  123. package/src/normalizeHtmlStyle.ts +0 -4
@@ -1,20 +1,27 @@
1
- #import "StyleHeaders.h"
2
1
  #import "EnrichedTextInputView.h"
3
2
  #import "FontExtension.h"
4
3
  #import "OccurenceUtils.h"
5
4
  #import "ParagraphsUtils.h"
5
+ #import "StyleHeaders.h"
6
6
  #import "TextInsertionUtils.h"
7
7
 
8
8
  @implementation OrderedListStyle {
9
9
  EnrichedTextInputView *_input;
10
10
  }
11
11
 
12
- + (StyleType)getStyleType { return OrderedList; }
12
+ + (StyleType)getStyleType {
13
+ return OrderedList;
14
+ }
15
+
16
+ + (BOOL)isParagraphStyle {
17
+ return YES;
18
+ }
13
19
 
14
20
  - (CGFloat)getHeadIndent {
15
21
  // lists are drawn manually
16
22
  // margin before marker + gap between marker and paragraph
17
- return [_input->config orderedListMarginLeft] + [_input->config orderedListGapWidth];
23
+ return [_input->config orderedListMarginLeft] +
24
+ [_input->config orderedListGapWidth];
18
25
  }
19
26
 
20
27
  - (instancetype)initWithInput:(id)input {
@@ -25,99 +32,136 @@
25
32
 
26
33
  - (void)applyStyle:(NSRange)range {
27
34
  BOOL isStylePresent = [self detectStyle:range];
28
- if(range.length >= 1) {
29
- isStylePresent ? [self removeAttributes:range] : [self addAttributes:range];
35
+ if (range.length >= 1) {
36
+ isStylePresent ? [self removeAttributes:range]
37
+ : [self addAttributes:range withTypingAttr:YES];
30
38
  } else {
31
39
  isStylePresent ? [self removeTypingAttributes] : [self addTypingAttributes];
32
40
  }
33
41
  }
34
42
 
35
43
  // we assume correct paragraph range is already given
36
- - (void)addAttributes:(NSRange)range {
37
- NSTextList *numberBullet = [[NSTextList alloc] initWithMarkerFormat:NSTextListMarkerDecimal options:0];
38
- NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView range:range];
39
- // if we fill empty lines with zero width spaces, we need to offset later ranges
44
+ - (void)addAttributes:(NSRange)range withTypingAttr:(BOOL)withTypingAttr {
45
+ NSTextList *numberBullet =
46
+ [[NSTextList alloc] initWithMarkerFormat:NSTextListMarkerDecimal
47
+ options:0];
48
+ NSArray *paragraphs =
49
+ [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView
50
+ range:range];
51
+ // if we fill empty lines with zero width spaces, we need to offset later
52
+ // ranges
40
53
  NSInteger offset = 0;
41
54
  // needed for range adjustments
42
55
  NSRange preModificationRange = _input->textView.selectedRange;
43
-
56
+
44
57
  // let's not emit some weird selection changes or text/html changes
45
58
  _input->blockEmitting = YES;
46
-
47
- for(NSValue *value in paragraphs) {
59
+
60
+ for (NSValue *value in paragraphs) {
48
61
  // take previous offsets into consideration
49
- NSRange fixedRange = NSMakeRange([value rangeValue].location + offset, [value rangeValue].length);
50
-
51
- // length 0 with first line, length 1 and newline with some empty lines in the middle
52
- if(fixedRange.length == 0 ||
53
- (fixedRange.length == 1 &&
54
- [[NSCharacterSet newlineCharacterSet] characterIsMember: [_input->textView.textStorage.string characterAtIndex:fixedRange.location]])
55
- ) {
56
- [TextInsertionUtils insertText:@"\u200B" at:fixedRange.location additionalAttributes:nullptr input:_input withSelection:NO];
62
+ NSRange fixedRange = NSMakeRange([value rangeValue].location + offset,
63
+ [value rangeValue].length);
64
+
65
+ // length 0 with first line, length 1 and newline with some empty lines in
66
+ // the middle
67
+ if (fixedRange.length == 0 ||
68
+ (fixedRange.length == 1 &&
69
+ [[NSCharacterSet newlineCharacterSet]
70
+ characterIsMember:[_input->textView.textStorage.string
71
+ characterAtIndex:fixedRange.location]])) {
72
+ [TextInsertionUtils insertText:@"\u200B"
73
+ at:fixedRange.location
74
+ additionalAttributes:nullptr
75
+ input:_input
76
+ withSelection:NO];
57
77
  fixedRange = NSMakeRange(fixedRange.location, fixedRange.length + 1);
58
78
  offset += 1;
59
79
  }
60
-
61
- [_input->textView.textStorage enumerateAttribute:NSParagraphStyleAttributeName inRange:fixedRange options:0
62
- usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
63
- NSMutableParagraphStyle *pStyle = [(NSParagraphStyle *)value mutableCopy];
64
- pStyle.textLists = @[numberBullet];
65
- pStyle.headIndent = [self getHeadIndent];
66
- pStyle.firstLineHeadIndent = [self getHeadIndent];
67
- [_input->textView.textStorage addAttribute:NSParagraphStyleAttributeName value:pStyle range:range];
68
- }
69
- ];
80
+
81
+ [_input->textView.textStorage
82
+ enumerateAttribute:NSParagraphStyleAttributeName
83
+ inRange:fixedRange
84
+ options:0
85
+ usingBlock:^(id _Nullable value, NSRange range,
86
+ BOOL *_Nonnull stop) {
87
+ NSMutableParagraphStyle *pStyle =
88
+ [(NSParagraphStyle *)value mutableCopy];
89
+ pStyle.textLists = @[ numberBullet ];
90
+ pStyle.headIndent = [self getHeadIndent];
91
+ pStyle.firstLineHeadIndent = [self getHeadIndent];
92
+ [_input->textView.textStorage
93
+ addAttribute:NSParagraphStyleAttributeName
94
+ value:pStyle
95
+ range:range];
96
+ }];
70
97
  }
71
-
98
+
72
99
  // back to emitting
73
100
  _input->blockEmitting = NO;
74
-
75
- if(preModificationRange.length == 0) {
76
- // fix selection if only one line was possibly made a list and filled with a space
101
+
102
+ if (preModificationRange.length == 0) {
103
+ // fix selection if only one line was possibly made a list and filled with a
104
+ // space
77
105
  _input->textView.selectedRange = preModificationRange;
78
106
  } else {
79
107
  // in other cases, fix the selection with newly made offsets
80
- _input->textView.selectedRange = NSMakeRange(preModificationRange.location, preModificationRange.length + offset);
108
+ _input->textView.selectedRange = NSMakeRange(
109
+ preModificationRange.location, preModificationRange.length + offset);
81
110
  }
82
-
111
+
83
112
  // also add typing attributes
84
- NSMutableDictionary *typingAttrs = [_input->textView.typingAttributes mutableCopy];
85
- NSMutableParagraphStyle *pStyle = [typingAttrs[NSParagraphStyleAttributeName] mutableCopy];
86
- pStyle.textLists = @[numberBullet];
87
- pStyle.headIndent = [self getHeadIndent];
88
- pStyle.firstLineHeadIndent = [self getHeadIndent];
89
- typingAttrs[NSParagraphStyleAttributeName] = pStyle;
90
- _input->textView.typingAttributes = typingAttrs;
113
+ if (withTypingAttr) {
114
+ NSMutableDictionary *typingAttrs =
115
+ [_input->textView.typingAttributes mutableCopy];
116
+ NSMutableParagraphStyle *pStyle =
117
+ [typingAttrs[NSParagraphStyleAttributeName] mutableCopy];
118
+ pStyle.textLists = @[ numberBullet ];
119
+ pStyle.headIndent = [self getHeadIndent];
120
+ pStyle.firstLineHeadIndent = [self getHeadIndent];
121
+ typingAttrs[NSParagraphStyleAttributeName] = pStyle;
122
+ _input->textView.typingAttributes = typingAttrs;
123
+ }
91
124
  }
92
125
 
93
126
  // does pretty much the same as normal addAttributes, just need to get the range
94
127
  - (void)addTypingAttributes {
95
- [self addAttributes:_input->textView.selectedRange];
128
+ [self addAttributes:_input->textView.selectedRange withTypingAttr:YES];
96
129
  }
97
130
 
98
131
  - (void)removeAttributes:(NSRange)range {
99
- NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView range:range];
100
-
132
+ NSArray *paragraphs =
133
+ [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView
134
+ range:range];
135
+
101
136
  [_input->textView.textStorage beginEditing];
102
-
103
- for(NSValue *value in paragraphs) {
137
+
138
+ for (NSValue *value in paragraphs) {
104
139
  NSRange range = [value rangeValue];
105
- [_input->textView.textStorage enumerateAttribute:NSParagraphStyleAttributeName inRange:range options:0
106
- usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
107
- NSMutableParagraphStyle *pStyle = [(NSParagraphStyle *)value mutableCopy];
108
- pStyle.textLists = @[];
109
- pStyle.headIndent = 0;
110
- pStyle.firstLineHeadIndent = 0;
111
- [_input->textView.textStorage addAttribute:NSParagraphStyleAttributeName value:pStyle range:range];
112
- }
113
- ];
140
+ [_input->textView.textStorage
141
+ enumerateAttribute:NSParagraphStyleAttributeName
142
+ inRange:range
143
+ options:0
144
+ usingBlock:^(id _Nullable value, NSRange range,
145
+ BOOL *_Nonnull stop) {
146
+ NSMutableParagraphStyle *pStyle =
147
+ [(NSParagraphStyle *)value mutableCopy];
148
+ pStyle.textLists = @[];
149
+ pStyle.headIndent = 0;
150
+ pStyle.firstLineHeadIndent = 0;
151
+ [_input->textView.textStorage
152
+ addAttribute:NSParagraphStyleAttributeName
153
+ value:pStyle
154
+ range:range];
155
+ }];
114
156
  }
115
-
157
+
116
158
  [_input->textView.textStorage endEditing];
117
-
159
+
118
160
  // also remove typing attributes
119
- NSMutableDictionary *typingAttrs = [_input->textView.typingAttributes mutableCopy];
120
- NSMutableParagraphStyle *pStyle = [typingAttrs[NSParagraphStyleAttributeName] mutableCopy];
161
+ NSMutableDictionary *typingAttrs =
162
+ [_input->textView.typingAttributes mutableCopy];
163
+ NSMutableParagraphStyle *pStyle =
164
+ [typingAttrs[NSParagraphStyleAttributeName] mutableCopy];
121
165
  pStyle.textLists = @[];
122
166
  pStyle.headIndent = 0;
123
167
  pStyle.firstLineHeadIndent = 0;
@@ -125,24 +169,28 @@
125
169
  _input->textView.typingAttributes = typingAttrs;
126
170
  }
127
171
 
128
- // needed for the sake of style conflicts, needs to do exactly the same as removeAttribtues
172
+ // needed for the sake of style conflicts, needs to do exactly the same as
173
+ // removeAttribtues
129
174
  - (void)removeTypingAttributes {
130
175
  [self removeAttributes:_input->textView.selectedRange];
131
176
  }
132
177
 
133
178
  - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text {
134
- if([self detectStyle:_input->textView.selectedRange] && text.length == 0) {
179
+ if ([self detectStyle:_input->textView.selectedRange] && text.length == 0) {
135
180
  // backspace while the style is active
136
-
137
- NSRange paragraphRange = [_input->textView.textStorage.string paragraphRangeForRange:_input->textView.selectedRange];
138
-
139
- if(NSEqualRanges(_input->textView.selectedRange, NSMakeRange(0, 0))) {
181
+
182
+ NSRange paragraphRange = [_input->textView.textStorage.string
183
+ paragraphRangeForRange:_input->textView.selectedRange];
184
+
185
+ if (NSEqualRanges(_input->textView.selectedRange, NSMakeRange(0, 0))) {
140
186
  // a backspace on the very first input's line list point
141
- // it doesn't run textVieDidChange so we need to manually remove attributes
187
+ // it doesn't run textVieDidChange so we need to manually remove
188
+ // attributes
142
189
  [self removeAttributes:paragraphRange];
143
190
  return YES;
144
- } else if(range.location == paragraphRange.location - 1) {
145
- // same case in other lines; here, the removed range location will be exactly 1 less than paragraph range location
191
+ } else if (range.location == paragraphRange.location - 1) {
192
+ // same case in other lines; here, the removed range location will be
193
+ // exactly 1 less than paragraph range location
146
194
  [self removeAttributes:paragraphRange];
147
195
  return YES;
148
196
  }
@@ -150,24 +198,36 @@
150
198
  return NO;
151
199
  }
152
200
 
153
- - (BOOL)tryHandlingListShorcutInRange:(NSRange)range replacementText:(NSString *)text {
154
- NSRange paragraphRange = [_input->textView.textStorage.string paragraphRangeForRange:range];
155
- // a dot was added - check if we are both at the paragraph beginning + 1 character (which we want to be a dash)
156
- if([text isEqualToString:@"."] && range.location - 1 == paragraphRange.location) {
157
- unichar charBefore = [_input->textView.textStorage.string characterAtIndex:range.location - 1];
158
- if(charBefore == '1') {
201
+ - (BOOL)tryHandlingListShorcutInRange:(NSRange)range
202
+ replacementText:(NSString *)text {
203
+ NSRange paragraphRange =
204
+ [_input->textView.textStorage.string paragraphRangeForRange:range];
205
+ // a dot was added - check if we are both at the paragraph beginning + 1
206
+ // character (which we want to be a dash)
207
+ if ([text isEqualToString:@"."] &&
208
+ range.location - 1 == paragraphRange.location) {
209
+ unichar charBefore = [_input->textView.textStorage.string
210
+ characterAtIndex:range.location - 1];
211
+ if (charBefore == '1') {
159
212
  // we got a match - add a list if possible
160
- if([_input handleStyleBlocksAndConflicts:[[self class] getStyleType] range:paragraphRange]) {
213
+ if ([_input handleStyleBlocksAndConflicts:[[self class] getStyleType]
214
+ range:paragraphRange]) {
161
215
  // don't emit during the replacing
162
216
  _input->blockEmitting = YES;
163
-
217
+
164
218
  // remove the number
165
- [TextInsertionUtils replaceText:@"" at:NSMakeRange(paragraphRange.location, 1) additionalAttributes:nullptr input:_input withSelection:YES];
166
-
219
+ [TextInsertionUtils replaceText:@""
220
+ at:NSMakeRange(paragraphRange.location, 1)
221
+ additionalAttributes:nullptr
222
+ input:_input
223
+ withSelection:YES];
224
+
167
225
  _input->blockEmitting = NO;
168
-
226
+
169
227
  // add attributes on the paragraph
170
- [self addAttributes:NSMakeRange(paragraphRange.location, paragraphRange.length - 1)];
228
+ [self addAttributes:NSMakeRange(paragraphRange.location,
229
+ paragraphRange.length - 1)
230
+ withTypingAttr:YES];
171
231
  return YES;
172
232
  }
173
233
  }
@@ -175,41 +235,48 @@
175
235
  return NO;
176
236
  }
177
237
 
178
- - (BOOL)styleCondition:(id _Nullable)value :(NSRange)range {
238
+ - (BOOL)styleCondition:(id _Nullable)value:(NSRange)range {
179
239
  NSParagraphStyle *paragraph = (NSParagraphStyle *)value;
180
- return paragraph != nullptr && paragraph.textLists.count == 1 && paragraph.textLists.firstObject.markerFormat == NSTextListMarkerDecimal;
240
+ return paragraph != nullptr && paragraph.textLists.count == 1 &&
241
+ paragraph.textLists.firstObject.markerFormat ==
242
+ NSTextListMarkerDecimal;
181
243
  }
182
244
 
183
245
  - (BOOL)detectStyle:(NSRange)range {
184
- if(range.length >= 1) {
185
- return [OccurenceUtils detect:NSParagraphStyleAttributeName withInput:_input inRange:range
186
- withCondition: ^BOOL(id _Nullable value, NSRange range) {
187
- return [self styleCondition:value :range];
188
- }
189
- ];
246
+ if (range.length >= 1) {
247
+ return [OccurenceUtils detect:NSParagraphStyleAttributeName
248
+ withInput:_input
249
+ inRange:range
250
+ withCondition:^BOOL(id _Nullable value, NSRange range) {
251
+ return [self styleCondition:value:range];
252
+ }];
190
253
  } else {
191
- return [OccurenceUtils detect:NSParagraphStyleAttributeName withInput:_input atIndex:range.location checkPrevious:YES
192
- withCondition:^BOOL(id _Nullable value, NSRange range) {
193
- return [self styleCondition:value :range];
194
- }
195
- ];
254
+ return [OccurenceUtils detect:NSParagraphStyleAttributeName
255
+ withInput:_input
256
+ atIndex:range.location
257
+ checkPrevious:YES
258
+ withCondition:^BOOL(id _Nullable value, NSRange range) {
259
+ return [self styleCondition:value:range];
260
+ }];
196
261
  }
197
262
  }
198
263
 
199
264
  - (BOOL)anyOccurence:(NSRange)range {
200
- return [OccurenceUtils any:NSParagraphStyleAttributeName withInput:_input inRange:range
201
- withCondition:^BOOL(id _Nullable value, NSRange range) {
202
- return [self styleCondition:value :range];
203
- }
204
- ];
265
+ return [OccurenceUtils any:NSParagraphStyleAttributeName
266
+ withInput:_input
267
+ inRange:range
268
+ withCondition:^BOOL(id _Nullable value, NSRange range) {
269
+ return [self styleCondition:value:range];
270
+ }];
205
271
  }
206
272
 
207
273
  - (NSArray<StylePair *> *_Nullable)findAllOccurences:(NSRange)range {
208
- return [OccurenceUtils all:NSParagraphStyleAttributeName withInput:_input inRange:range
209
- withCondition:^BOOL(id _Nullable value, NSRange range) {
210
- return [self styleCondition:value :range];
211
- }
212
- ];
274
+ return [OccurenceUtils all:NSParagraphStyleAttributeName
275
+ withInput:_input
276
+ inRange:range
277
+ withCondition:^BOOL(id _Nullable value, NSRange range) {
278
+ return [self styleCondition:value:range];
279
+ }];
213
280
  }
214
281
 
215
282
  @end
@@ -1,12 +1,18 @@
1
- #import "StyleHeaders.h"
2
1
  #import "EnrichedTextInputView.h"
3
2
  #import "OccurenceUtils.h"
3
+ #import "StyleHeaders.h"
4
4
 
5
5
  @implementation StrikethroughStyle {
6
6
  EnrichedTextInputView *_input;
7
7
  }
8
8
 
9
- + (StyleType)getStyleType { return Strikethrough; }
9
+ + (StyleType)getStyleType {
10
+ return Strikethrough;
11
+ }
12
+
13
+ + (BOOL)isParagraphStyle {
14
+ return NO;
15
+ }
10
16
 
11
17
  - (instancetype)initWithInput:(id)input {
12
18
  self = [super init];
@@ -15,69 +21,82 @@
15
21
  }
16
22
 
17
23
  - (void)applyStyle:(NSRange)range {
18
- BOOL isStylePresent = [self detectStyle: range];
19
- if(range.length >= 1) {
20
- isStylePresent ? [self removeAttributes:range] : [self addAttributes:range];
24
+ BOOL isStylePresent = [self detectStyle:range];
25
+ if (range.length >= 1) {
26
+ isStylePresent ? [self removeAttributes:range]
27
+ : [self addAttributes:range withTypingAttr:YES];
21
28
  } else {
22
29
  isStylePresent ? [self removeTypingAttributes] : [self addTypingAttributes];
23
30
  }
24
31
  }
25
32
 
26
- - (void)addAttributes:(NSRange)range {
27
- [_input->textView.textStorage addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlineStyleSingle) range:range];
33
+ - (void)addAttributes:(NSRange)range withTypingAttr:(BOOL)withTypingAttr {
34
+ [_input->textView.textStorage addAttribute:NSStrikethroughStyleAttributeName
35
+ value:@(NSUnderlineStyleSingle)
36
+ range:range];
28
37
  }
29
38
 
30
39
  - (void)addTypingAttributes {
31
- NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy];
40
+ NSMutableDictionary *newTypingAttrs =
41
+ [_input->textView.typingAttributes mutableCopy];
32
42
  newTypingAttrs[NSStrikethroughStyleAttributeName] = @(NSUnderlineStyleSingle);
33
43
  _input->textView.typingAttributes = newTypingAttrs;
34
44
  }
35
45
 
36
46
  - (void)removeAttributes:(NSRange)range {
37
- [_input->textView.textStorage removeAttribute:NSStrikethroughStyleAttributeName range:range];
47
+ [_input->textView.textStorage
48
+ removeAttribute:NSStrikethroughStyleAttributeName
49
+ range:range];
38
50
  }
39
51
 
40
52
  - (void)removeTypingAttributes {
41
- NSMutableDictionary *newTypingAttrs = [_input->textView.typingAttributes mutableCopy];
42
- [newTypingAttrs removeObjectForKey: NSStrikethroughStyleAttributeName];
53
+ NSMutableDictionary *newTypingAttrs =
54
+ [_input->textView.typingAttributes mutableCopy];
55
+ [newTypingAttrs removeObjectForKey:NSStrikethroughStyleAttributeName];
43
56
  _input->textView.typingAttributes = newTypingAttrs;
44
57
  }
45
58
 
46
- - (BOOL)styleCondition:(id _Nullable)value :(NSRange)range {
59
+ - (BOOL)styleCondition:(id _Nullable)value:(NSRange)range {
47
60
  NSNumber *strikethroughStyle = (NSNumber *)value;
48
- return strikethroughStyle != nullptr && [strikethroughStyle intValue] != NSUnderlineStyleNone;
61
+ return strikethroughStyle != nullptr &&
62
+ [strikethroughStyle intValue] != NSUnderlineStyleNone;
49
63
  }
50
64
 
51
65
  - (BOOL)detectStyle:(NSRange)range {
52
- if(range.length >= 1) {
53
- return [OccurenceUtils detect:NSStrikethroughStyleAttributeName withInput:_input inRange:range
54
- withCondition: ^BOOL(id _Nullable value, NSRange range) {
55
- return [self styleCondition:value :range];
56
- }
57
- ];
66
+ if (range.length >= 1) {
67
+ return [OccurenceUtils detect:NSStrikethroughStyleAttributeName
68
+ withInput:_input
69
+ inRange:range
70
+ withCondition:^BOOL(id _Nullable value, NSRange range) {
71
+ return [self styleCondition:value:range];
72
+ }];
58
73
  } else {
59
- return [OccurenceUtils detect:NSStrikethroughStyleAttributeName withInput:_input atIndex:range.location checkPrevious:NO
60
- withCondition:^BOOL(id _Nullable value, NSRange range) {
61
- return [self styleCondition:value :range];
62
- }
63
- ];
74
+ return [OccurenceUtils detect:NSStrikethroughStyleAttributeName
75
+ withInput:_input
76
+ atIndex:range.location
77
+ checkPrevious:NO
78
+ withCondition:^BOOL(id _Nullable value, NSRange range) {
79
+ return [self styleCondition:value:range];
80
+ }];
64
81
  }
65
82
  }
66
83
 
67
84
  - (BOOL)anyOccurence:(NSRange)range {
68
- return [OccurenceUtils any:NSStrikethroughStyleAttributeName withInput:_input inRange:range
69
- withCondition:^BOOL(id _Nullable value, NSRange range) {
70
- return [self styleCondition:value :range];
71
- }
72
- ];
85
+ return [OccurenceUtils any:NSStrikethroughStyleAttributeName
86
+ withInput:_input
87
+ inRange:range
88
+ withCondition:^BOOL(id _Nullable value, NSRange range) {
89
+ return [self styleCondition:value:range];
90
+ }];
73
91
  }
74
92
 
75
93
  - (NSArray<StylePair *> *_Nullable)findAllOccurences:(NSRange)range {
76
- return [OccurenceUtils all:NSStrikethroughStyleAttributeName withInput:_input inRange:range
77
- withCondition:^BOOL(id _Nullable value, NSRange range) {
78
- return [self styleCondition:value :range];
79
- }
80
- ];
94
+ return [OccurenceUtils all:NSStrikethroughStyleAttributeName
95
+ withInput:_input
96
+ inRange:range
97
+ withCondition:^BOOL(id _Nullable value, NSRange range) {
98
+ return [self styleCondition:value:range];
99
+ }];
81
100
  }
82
101
 
83
102
  @end