Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
appId: swmansion.enriched.example
---
# Verifies that typing attributes are properly preserved on selection changes
- launchApp

- tapOn:
id: 'toggle-screen-button'

- tapOn:
id: "editor-input"

- tapOn:
id: "toolbar-bold"

- inputText: 'bold text'
- pressKey: Enter
- pressKey: Enter
- pressKey: Enter
- inputText: 'another line'

- doubleTapOn:
id: 'editor-input'
point: '20%, 75%'

- tapOn:
id: 'editor-input'
point: '50%, 15%'

- inputText: 'new'

- runFlow:
file: '../subflows/capture_or_assert_screenshot.yaml'
env:
SCREENSHOT_NAME: 'preserve_typing_attributes_on_selection_changes'
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions ios/EnrichedTextInputView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -2000,6 +2000,14 @@ - (bool)textView:(UITextView *)textView
return NO;
}

// To be sure, we re-run typingAttributes management right before the
// character actually lands. Sometimes, between a selection change and the
// next keystroke, typing attributes might get removed - this seems like a
// native TextKit issue.
if (textView.markedTextRange == nil && text.length > 0) {
[attributesManager repeatRecentTypingAttributesManagement];
}

return YES;
}

Expand Down
1 change: 1 addition & 0 deletions ios/inputAttributesManager/InputAttributesManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- (void)didRemoveTypingAttribute:(NSString *)key;
- (void)clearRemovedTypingAttributes;
- (void)manageTypingAttributesWithOnlySelection:(BOOL)onlySelectionChanged;
- (void)repeatRecentTypingAttributesManagement;
- (void)handleDirtyRangesStyling;
- (NSSet<NSString *> *)customAttributesKeys;
@end
7 changes: 7 additions & 0 deletions ios/inputAttributesManager/InputAttributesManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ @implementation InputAttributesManager {
NSMutableArray<NSValue *> *_dirtyRanges;
NSSet *_customAttributesKeys;
NSMutableSet *_removedTypingAttributes;
BOOL _recentOnlySelectionStatus;
}

- (instancetype)initWithInput:(EnrichedTextInputView *)input {
self = [super init];
_input = input;
_dirtyRanges = [[NSMutableArray alloc] init];
_removedTypingAttributes = [[NSMutableSet alloc] init];
_recentOnlySelectionStatus = NO;

// setup customAttributes
NSMutableSet *_customAttrsSet = [[NSMutableSet alloc] init];
Expand Down Expand Up @@ -129,6 +131,7 @@ - (void)handleDirtyRangesStyling {
}

- (void)manageTypingAttributesWithOnlySelection:(BOOL)onlySelectionChanged {
_recentOnlySelectionStatus = onlySelectionChanged;
EnrichedInputTextView *textView = _input->textView;
NSRange selectedRange = textView.selectedRange;

Expand Down Expand Up @@ -219,4 +222,8 @@ - (void)manageTypingAttributesWithOnlySelection:(BOOL)onlySelectionChanged {
textView.typingAttributes = newAttrs;
}

- (void)repeatRecentTypingAttributesManagement {
[self manageTypingAttributesWithOnlySelection:_recentOnlySelectionStatus];
}

@end
Loading