Skip to content

Commit c4830db

Browse files
lyahdavchristophpurrer
authored andcommitted
Fix TextInput interfering with Japanese conversion
The bug happened anywhere we set a onChangeText event handler on TextInput, and rewrite the inflight text such as shown in https://github.com/microsoft/react-native-macos/blob/main/packages/rn-tester/js/examples/TextInput/TextInputSharedExamples.js#L137 To fix we have to ignore changes to text if we have incomplete conversions.
1 parent 6b42baf commit c4830db

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ NS_ASSUME_NONNULL_BEGIN
7676
#endif // ]TODO(macOS GH#774)
7777

7878
#if TARGET_OS_OSX // [TODO(macOS GH#774)
79+
- (BOOL)hasMarkedText;
7980
// UITextInput method for OSX
8081
- (CGSize)sizeThatFits:(CGSize)size;
8182
#endif // ]TODO(macOS GH#774)

Libraries/Text/TextInput/RCTBaseTextInputView.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ - (void)setAttributedText:(NSAttributedString *)attributedText
153153
range:NSMakeRange(0, attributedTextCopy.length)];
154154

155155
textNeedsUpdate = ([self textOf:attributedTextCopy equals:backedTextInputViewTextCopy] == NO);
156+
#if TARGET_OS_OSX // [TODO(macOS GH#774)
157+
// If we are in a language that uses conversion (e.g. Japanese), ignore updates if we have unconverted text.
158+
if ([self.backedTextInputView hasMarkedText]) {
159+
textNeedsUpdate = NO;
160+
}
161+
#endif // ]TODO(macOS GH#774)
156162

157163
if (eventLag == 0 && textNeedsUpdate) {
158164
#if !TARGET_OS_OSX // TODO(macOS GH#774)

Libraries/Text/TextInput/Singleline/RCTUITextField.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,13 @@ - (void)_textDidChange
127127
#endif // ]TODO(macOS GH#774)
128128
}
129129

130+
#if TARGET_OS_OSX // [TODO(macOS GH#774)
131+
- (BOOL)hasMarkedText
132+
{
133+
return ((NSTextView *)self.currentEditor).hasMarkedText;
134+
}
135+
#endif // ]TODO(macOS GH#774)
136+
130137
#pragma mark - Accessibility
131138

132139
#if !TARGET_OS_OSX // [TODO(macOS GH#774)

0 commit comments

Comments
 (0)