Skip to content

Commit aa2d350

Browse files
authored
iOS headings improvements (#177)
- added a check that makes sure headings attributes are removed after entering - added a check that fixes attributes of text artificially incorporated into headings (by backspacing it from a following line) - remade the logic of the checks made before the text change is committed. Previous approach could result in crashes because checks that actually changed something influenced the following checks. Since no two of them can go off at the same time, now they are mutually exclusive - if one goes off, others don't
1 parent 9dcf5f7 commit aa2d350

5 files changed

Lines changed: 84 additions & 65 deletions

File tree

example/ios/EnrichedTextInputExample.xcodeproj/project.pbxproj

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
31EE7B79626043278451F7C2 /* Nunito-MediumItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 56DFDD6005684613BABE1A5B /* Nunito-MediumItalic.ttf */; };
1717
44F3116C228D441D96648511 /* Nunito-Bold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = DA817F04F35B4BA1A6C0BB7A /* Nunito-Bold.ttf */; };
1818
475EC9D8C2514408931549DD /* Nunito-Black.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 012D53DFD8C6464DBF6E19E4 /* Nunito-Black.ttf */; };
19+
4B4950F65A47714993F53BB4 /* libPods-EnrichedTextInputExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 95CD629A5570EDEE67260A64 /* libPods-EnrichedTextInputExample.a */; };
1920
4FEAEB180FF94632ADFA7D7D /* Nunito-SemiBoldItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 78A78FF825C747578571B76F /* Nunito-SemiBoldItalic.ttf */; };
2021
56EDC86733EA478B9DA01878 /* CascadiaCode-Medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 87375222174145AD85B4DE62 /* CascadiaCode-Medium.ttf */; };
2122
5B86D220CCF04C2A850EB7E8 /* CascadiaCode-MediumItalic.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 78D6C09519344432B162E948 /* CascadiaCode-MediumItalic.ttf */; };
@@ -36,7 +37,6 @@
3637
95A487B0B0A94AFDA7B10C06 /* FontAwesome.ttf in Resources */ = {isa = PBXBuildFile; fileRef = D133E950DA6A4BC0A97DDFFE /* FontAwesome.ttf */; };
3738
95CD2D9394AA4FD8B184FC56 /* Nunito-Light.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 153B340F016F497BA045811A /* Nunito-Light.ttf */; };
3839
970142F6180042E5964006A6 /* CascadiaCode-Light.ttf in Resources */ = {isa = PBXBuildFile; fileRef = DA76D9192FE24EC28C84DE79 /* CascadiaCode-Light.ttf */; };
39-
9CCBAA226FD195143DDD2884 /* libPods-EnrichedTextInputExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D370084B15B932DA6ABD7D8 /* libPods-EnrichedTextInputExample.a */; };
4040
A2B3511833CC42D2B563A6C8 /* Nunito-Medium.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 974D908628154101A0445B89 /* Nunito-Medium.ttf */; };
4141
A9294579BC314C709C083877 /* Nunito-SemiBold.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 375DF342F26841F6BF549CAB /* Nunito-SemiBold.ttf */; };
4242
B17531A20CBB4D92B0AF89A3 /* Nunito-Italic-VariableFont_wght.ttf in Resources */ = {isa = PBXBuildFile; fileRef = ABF6C071A9704D7F84EAC642 /* Nunito-Italic-VariableFont_wght.ttf */; };
@@ -58,6 +58,7 @@
5858
13B07FB81A68108700A75B9A /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = PrivacyInfo.xcprivacy; path = EnrichedTextInputExample/PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
5959
153B340F016F497BA045811A /* Nunito-Light.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "Nunito-Light.ttf"; path = "../assets/fonts/Nunito/static/Nunito-Light.ttf"; sourceTree = "<group>"; };
6060
1872D96B58594795BDF6C766 /* Nunito-ExtraLight.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "Nunito-ExtraLight.ttf"; path = "../assets/fonts/Nunito/static/Nunito-ExtraLight.ttf"; sourceTree = "<group>"; };
61+
371B368B6AB82CCE5511A1CA /* Pods-EnrichedTextInputExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-EnrichedTextInputExample.debug.xcconfig"; path = "Target Support Files/Pods-EnrichedTextInputExample/Pods-EnrichedTextInputExample.debug.xcconfig"; sourceTree = "<group>"; };
6162
375DF342F26841F6BF549CAB /* Nunito-SemiBold.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "Nunito-SemiBold.ttf"; path = "../assets/fonts/Nunito/static/Nunito-SemiBold.ttf"; sourceTree = "<group>"; };
6263
3A18DEB91C24449AA3ECE59A /* CascadiaCode-Italic-VariableFont_wght.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-Italic-VariableFont_wght.ttf"; path = "../assets/fonts/Cascadia_Code/CascadiaCode-Italic-VariableFont_wght.ttf"; sourceTree = "<group>"; };
6364
3FD646A3FF0F4F33AC65021F /* CascadiaCode-SemiBold.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-SemiBold.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-SemiBold.ttf"; sourceTree = "<group>"; };
@@ -71,7 +72,7 @@
7172
5D3228FB7E494D31805D6C01 /* Nunito-Regular.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "Nunito-Regular.ttf"; path = "../assets/fonts/Nunito/static/Nunito-Regular.ttf"; sourceTree = "<group>"; };
7273
6352E13F84F841D5A2BA25B4 /* CascadiaCode-Italic.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-Italic.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-Italic.ttf"; sourceTree = "<group>"; };
7374
674C8E7598D647768ECEC0E1 /* OFL.txt */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = OFL.txt; path = ../assets/fonts/Cascadia_Code/OFL.txt; sourceTree = "<group>"; };
74-
6D370084B15B932DA6ABD7D8 /* libPods-EnrichedTextInputExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-EnrichedTextInputExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
75+
6918616D8394A3A8000BFE5C /* Pods-EnrichedTextInputExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-EnrichedTextInputExample.release.xcconfig"; path = "Target Support Files/Pods-EnrichedTextInputExample/Pods-EnrichedTextInputExample.release.xcconfig"; sourceTree = "<group>"; };
7576
761780EC2CA45674006654EE /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = AppDelegate.swift; path = EnrichedTextInputExample/AppDelegate.swift; sourceTree = "<group>"; };
7677
78A78FF825C747578571B76F /* Nunito-SemiBoldItalic.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "Nunito-SemiBoldItalic.ttf"; path = "../assets/fonts/Nunito/static/Nunito-SemiBoldItalic.ttf"; sourceTree = "<group>"; };
7778
78D6C09519344432B162E948 /* CascadiaCode-MediumItalic.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-MediumItalic.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-MediumItalic.ttf"; sourceTree = "<group>"; };
@@ -82,10 +83,9 @@
8283
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = EnrichedTextInputExample/LaunchScreen.storyboard; sourceTree = "<group>"; };
8384
87375222174145AD85B4DE62 /* CascadiaCode-Medium.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "CascadiaCode-Medium.ttf"; path = "../assets/fonts/Cascadia_Code/static/CascadiaCode-Medium.ttf"; sourceTree = "<group>"; };
8485
8A425B9B75B9488EA0FDF624 /* README.txt */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = README.txt; path = ../assets/fonts/Cascadia_Code/README.txt; sourceTree = "<group>"; };
85-
8D30641E04B3C92750094BD1 /* Pods-EnrichedTextInputExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-EnrichedTextInputExample.release.xcconfig"; path = "Target Support Files/Pods-EnrichedTextInputExample/Pods-EnrichedTextInputExample.release.xcconfig"; sourceTree = "<group>"; };
8686
8DDAE8E93F2D4651A22D1882 /* Nunito-LightItalic.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "Nunito-LightItalic.ttf"; path = "../assets/fonts/Nunito/static/Nunito-LightItalic.ttf"; sourceTree = "<group>"; };
87+
95CD629A5570EDEE67260A64 /* libPods-EnrichedTextInputExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-EnrichedTextInputExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
8788
974D908628154101A0445B89 /* Nunito-Medium.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "Nunito-Medium.ttf"; path = "../assets/fonts/Nunito/static/Nunito-Medium.ttf"; sourceTree = "<group>"; };
88-
ABB962282C7DB4F364360154 /* Pods-EnrichedTextInputExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-EnrichedTextInputExample.debug.xcconfig"; path = "Target Support Files/Pods-EnrichedTextInputExample/Pods-EnrichedTextInputExample.debug.xcconfig"; sourceTree = "<group>"; };
8989
ABF6C071A9704D7F84EAC642 /* Nunito-Italic-VariableFont_wght.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "Nunito-Italic-VariableFont_wght.ttf"; path = "../assets/fonts/Nunito/Nunito-Italic-VariableFont_wght.ttf"; sourceTree = "<group>"; };
9090
AFECE93D073F484A93612569 /* Nunito-ExtraLightItalic.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "Nunito-ExtraLightItalic.ttf"; path = "../assets/fonts/Nunito/static/Nunito-ExtraLightItalic.ttf"; sourceTree = "<group>"; };
9191
B6CB34AFACC240079497790D /* Nunito-Italic.ttf */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = undefined; includeInIndex = 0; lastKnownFileType = unknown; name = "Nunito-Italic.ttf"; path = "../assets/fonts/Nunito/static/Nunito-Italic.ttf"; sourceTree = "<group>"; };
@@ -104,7 +104,7 @@
104104
isa = PBXFrameworksBuildPhase;
105105
buildActionMask = 2147483647;
106106
files = (
107-
9CCBAA226FD195143DDD2884 /* libPods-EnrichedTextInputExample.a in Frameworks */,
107+
4B4950F65A47714993F53BB4 /* libPods-EnrichedTextInputExample.a in Frameworks */,
108108
);
109109
runOnlyForDeploymentPostprocessing = 0;
110110
};
@@ -127,7 +127,7 @@
127127
isa = PBXGroup;
128128
children = (
129129
ED297162215061F000B7C4FE /* JavaScriptCore.framework */,
130-
6D370084B15B932DA6ABD7D8 /* libPods-EnrichedTextInputExample.a */,
130+
95CD629A5570EDEE67260A64 /* libPods-EnrichedTextInputExample.a */,
131131
);
132132
name = Frameworks;
133133
sourceTree = "<group>";
@@ -165,8 +165,8 @@
165165
BBD78D7AC51CEA395F1C20DB /* Pods */ = {
166166
isa = PBXGroup;
167167
children = (
168-
ABB962282C7DB4F364360154 /* Pods-EnrichedTextInputExample.debug.xcconfig */,
169-
8D30641E04B3C92750094BD1 /* Pods-EnrichedTextInputExample.release.xcconfig */,
168+
371B368B6AB82CCE5511A1CA /* Pods-EnrichedTextInputExample.debug.xcconfig */,
169+
6918616D8394A3A8000BFE5C /* Pods-EnrichedTextInputExample.release.xcconfig */,
170170
);
171171
path = Pods;
172172
sourceTree = "<group>";
@@ -222,13 +222,13 @@
222222
isa = PBXNativeTarget;
223223
buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "EnrichedTextInputExample" */;
224224
buildPhases = (
225-
4981A167C0063A82876DD1AB /* [CP] Check Pods Manifest.lock */,
225+
78C433C49BA99727B8F82093 /* [CP] Check Pods Manifest.lock */,
226226
13B07F871A680F5B00A75B9A /* Sources */,
227227
13B07F8C1A680F5B00A75B9A /* Frameworks */,
228228
13B07F8E1A680F5B00A75B9A /* Resources */,
229229
00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */,
230-
75C9505AFC16ED96EE5E9ED4 /* [CP] Embed Pods Frameworks */,
231-
B600D4E6CF246F817102A773 /* [CP] Copy Pods Resources */,
230+
EDDF48CF048F8E3AEC92FBE1 /* [CP] Embed Pods Frameworks */,
231+
F803EE48F3DE8A3C8C2D3B60 /* [CP] Copy Pods Resources */,
232232
);
233233
buildRules = (
234234
);
@@ -336,7 +336,7 @@
336336
shellPath = /bin/sh;
337337
shellScript = "set -e\n\nWITH_ENVIRONMENT=\"$REACT_NATIVE_PATH/scripts/xcode/with-environment.sh\"\nREACT_NATIVE_XCODE=\"$REACT_NATIVE_PATH/scripts/react-native-xcode.sh\"\n\n/bin/sh -c \"$WITH_ENVIRONMENT $REACT_NATIVE_XCODE\"\n";
338338
};
339-
4981A167C0063A82876DD1AB /* [CP] Check Pods Manifest.lock */ = {
339+
78C433C49BA99727B8F82093 /* [CP] Check Pods Manifest.lock */ = {
340340
isa = PBXShellScriptBuildPhase;
341341
buildActionMask = 2147483647;
342342
files = (
@@ -358,7 +358,7 @@
358358
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
359359
showEnvVarsInLog = 0;
360360
};
361-
75C9505AFC16ED96EE5E9ED4 /* [CP] Embed Pods Frameworks */ = {
361+
EDDF48CF048F8E3AEC92FBE1 /* [CP] Embed Pods Frameworks */ = {
362362
isa = PBXShellScriptBuildPhase;
363363
buildActionMask = 2147483647;
364364
files = (
@@ -375,7 +375,7 @@
375375
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-EnrichedTextInputExample/Pods-EnrichedTextInputExample-frameworks.sh\"\n";
376376
showEnvVarsInLog = 0;
377377
};
378-
B600D4E6CF246F817102A773 /* [CP] Copy Pods Resources */ = {
378+
F803EE48F3DE8A3C8C2D3B60 /* [CP] Copy Pods Resources */ = {
379379
isa = PBXShellScriptBuildPhase;
380380
buildActionMask = 2147483647;
381381
files = (
@@ -408,7 +408,7 @@
408408
/* Begin XCBuildConfiguration section */
409409
13B07F941A680F5B00A75B9A /* Debug */ = {
410410
isa = XCBuildConfiguration;
411-
baseConfigurationReference = ABB962282C7DB4F364360154 /* Pods-EnrichedTextInputExample.debug.xcconfig */;
411+
baseConfigurationReference = 371B368B6AB82CCE5511A1CA /* Pods-EnrichedTextInputExample.debug.xcconfig */;
412412
buildSettings = {
413413
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
414414
CLANG_ENABLE_MODULES = YES;
@@ -436,7 +436,7 @@
436436
};
437437
13B07F951A680F5B00A75B9A /* Release */ = {
438438
isa = XCBuildConfiguration;
439-
baseConfigurationReference = 8D30641E04B3C92750094BD1 /* Pods-EnrichedTextInputExample.release.xcconfig */;
439+
baseConfigurationReference = 6918616D8394A3A8000BFE5C /* Pods-EnrichedTextInputExample.release.xcconfig */;
440440
buildSettings = {
441441
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
442442
CLANG_ENABLE_MODULES = YES;

example/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2692,7 +2692,7 @@ SPEC CHECKSUMS:
26922692
ReactCommon: d07170f92e0e853091a70b2741b7c43f5dfdea73
26932693
ReactNativeEnriched: b11d66700889cd36c9938a825736de1929349b24
26942694
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
2695-
Yoga: 47264cc34431da6b66b3687348be283084924f46
2695+
Yoga: 6af5d1e0290903c82b3e0cb6836a5f898c1c4634
26962696

26972697
PODFILE CHECKSUM: 1b876ae6d1ea0597d954f2089c1213dd3ade28bc
26982698

ios/EnrichedTextInputView.mm

Lines changed: 33 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,16 @@ - (void)anyTextMayHaveBeenModified {
10161016
[bqStyle manageBlockquoteColor];
10171017
}
10181018

1019+
// improper headings fix
1020+
H1Style *h1Style = stylesDict[@([H1Style getStyleType])];
1021+
H2Style *h2Style = stylesDict[@([H2Style getStyleType])];
1022+
H3Style *h3Style = stylesDict[@([H3Style getStyleType])];
1023+
if(h1Style != nullptr && h2Style != nullptr && h3Style != nullptr) {
1024+
[h1Style handleImproperHeadings];
1025+
[h2Style handleImproperHeadings];
1026+
[h3Style handleImproperHeadings];
1027+
}
1028+
10191029
// placholder management
10201030
if(!_placeholderLabel.hidden && textView.textStorage.string.length > 0) {
10211031
[self setPlaceholderLabelShown:NO];
@@ -1102,61 +1112,36 @@ - (void)textViewDidEndEditing:(UITextView *)textView {
11021112
- (bool)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
11031113
recentlyChangedRange = NSMakeRange(range.location, text.length);
11041114

1105-
BOOL rejectTextChanges = NO;
1106-
11071115
UnorderedListStyle *uStyle = stylesDict[@([UnorderedListStyle getStyleType])];
1108-
if(uStyle != nullptr) {
1109-
// removing first line list fix
1110-
BOOL removedFirstLineList = [uStyle handleBackspaceInRange:range replacementText:text];
1111-
1112-
// creating unordered list from "- "
1113-
BOOL addedShortcutList = [uStyle tryHandlingListShorcutInRange:range replacementText:text];
1114-
1115-
// any of these changes make us reject text changes
1116-
rejectTextChanges = rejectTextChanges || removedFirstLineList || addedShortcutList;
1117-
}
1118-
11191116
OrderedListStyle *oStyle = stylesDict[@([OrderedListStyle getStyleType])];
1120-
if(oStyle != nullptr) {
1121-
// removing first line list fix
1122-
BOOL removedFirstLineList = [oStyle handleBackspaceInRange:range replacementText:text];
1123-
1124-
// creating ordered list from "1."
1125-
BOOL addedShortcutList = [oStyle tryHandlingListShorcutInRange:range replacementText:text];
1126-
1127-
// any of these changes make us reject text changes
1128-
rejectTextChanges = rejectTextChanges || removedFirstLineList || addedShortcutList;
1129-
}
1130-
11311117
BlockQuoteStyle *bqStyle = stylesDict[@([BlockQuoteStyle getStyleType])];
1132-
if(bqStyle != nullptr) {
1133-
// removing first line quote fix
1134-
BOOL removedFirstLineQuote = [bqStyle handleBackspaceInRange:range replacementText:text];
1135-
rejectTextChanges = rejectTextChanges || removedFirstLineQuote;
1136-
}
1137-
11381118
LinkStyle *linkStyle = stylesDict[@([LinkStyle getStyleType])];
1139-
if(linkStyle != nullptr) {
1140-
// persisting link attributes fix
1141-
BOOL fixedLeadingAttributes = [linkStyle handleLeadingLinkReplacement:range replacementText:text];
1142-
rejectTextChanges = rejectTextChanges || fixedLeadingAttributes;
1143-
}
1144-
11451119
MentionStyle *mentionStyle = stylesDict[@([MentionStyle getStyleType])];
1146-
if(mentionStyle != nullptr) {
1147-
// persisting mention attributes fix
1148-
BOOL fixedLeadingAttributes = [mentionStyle handleLeadingMentionReplacement:range replacementText:text];
1149-
rejectTextChanges = rejectTextChanges || fixedLeadingAttributes;
1150-
}
1151-
1152-
// zero width space removal fix
1153-
rejectTextChanges = rejectTextChanges || [ZeroWidthSpaceUtils handleBackspaceInRange:range replacementText:text input:self];
1154-
1155-
if(rejectTextChanges) {
1120+
H1Style *h1Style = stylesDict[@([H1Style getStyleType])];
1121+
H2Style *h2Style = stylesDict[@([H2Style getStyleType])];
1122+
H3Style *h3Style = stylesDict[@([H3Style getStyleType])];
1123+
1124+
// some of the changes these checks do could interfere with later checks and cause a crash
1125+
// so here I rely on short circuiting evaluation of the logical expression
1126+
// either way it's not possible to have two of them come off at the same time
1127+
if(
1128+
[uStyle handleBackspaceInRange:range replacementText:text] ||
1129+
[uStyle tryHandlingListShorcutInRange:range replacementText:text] ||
1130+
[oStyle handleBackspaceInRange:range replacementText:text] ||
1131+
[oStyle tryHandlingListShorcutInRange:range replacementText:text] ||
1132+
[bqStyle handleBackspaceInRange:range replacementText:text] ||
1133+
[linkStyle handleLeadingLinkReplacement:range replacementText:text] ||
1134+
[mentionStyle handleLeadingMentionReplacement:range replacementText:text] ||
1135+
[h1Style handleNewlinesInRange:range replacementText:text] ||
1136+
[h2Style handleNewlinesInRange:range replacementText:text] ||
1137+
[h3Style handleNewlinesInRange:range replacementText:text] ||
1138+
[ZeroWidthSpaceUtils handleBackspaceInRange:range replacementText:text input:self]
1139+
) {
11561140
[self anyTextMayHaveBeenModified];
1141+
return NO;
11571142
}
1158-
1159-
return !rejectTextChanges;
1143+
1144+
return YES;
11601145
}
11611146

11621147
- (void)textViewDidChangeSelection:(UITextView *)textView {

0 commit comments

Comments
 (0)