Initial support for input language restoration

This commit is contained in:
Peter Iakovlev
2018-12-20 17:49:29 +04:00
parent 957bf00ddc
commit 73ac7e6a76
2 changed files with 21 additions and 1 deletions

View File

@@ -140,8 +140,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic) BOOL enablesReturnKeyAutomatically; // default is NO (when YES, will automatically disable return key when text widget has zero-length contents, and will automatically enable when text widget has non-zero-length contents)
@property (nonatomic, getter=isSecureTextEntry) BOOL secureTextEntry; // default is NO
- (void)dropAutocorrection;
@property (nonatomic, strong) NSString * _Nullable initialPrimaryLanguage;
- (void)dropAutocorrection;
@end

View File

@@ -83,6 +83,7 @@
@interface ASPanningOverriddenUITextView : ASTextKitComponentsTextView
{
BOOL _shouldBlockPanGesture;
BOOL _initializedPrimaryInputLanguage;
}
@property (nonatomic, copy) bool (^shouldPaste)();
@@ -90,6 +91,8 @@
@property (nonatomic, copy) bool (^shouldReturn)();
@property (nonatomic, copy) void (^backspaceWhileEmpty)();
@property (nonatomic, strong) NSString * _Nullable initialPrimaryLanguage;
@end
@implementation ASPanningOverriddenUITextView
@@ -190,6 +193,21 @@
}
}
- (UITextInputMode *)textInputMode {
if (!_initializedPrimaryInputLanguage) {
_initializedPrimaryInputLanguage = true;
/*if (_initialPrimaryLanguage != nil) {
for (UITextInputMode *inputMode in [UITextInputMode activeInputModes]) {
NSString *primaryLanguage = inputMode.primaryLanguage;
if (primaryLanguage != nil && [primaryLanguage isEqualToString:_initialPrimaryLanguage]) {
return inputMode;
}
}*/
}
}
return [super textInputMode];
}
#endif
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
@@ -316,6 +334,7 @@
// Create and configure our text view.
ASPanningOverriddenUITextView *textView = [[ASPanningOverriddenUITextView alloc] initWithFrame:CGRectZero textContainer:_textKitComponents.textContainer];
textView.initialPrimaryLanguage = _initialPrimaryLanguage;
__weak ASEditableTextNode *weakSelf = self;
textView.shouldPaste = ^bool{
__strong ASEditableTextNode *strongSelf = weakSelf;