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