JBR-5953 If hieroglyph typing isn't finalised, focusing another component inserts the composed text there

(cherry picked from commit 5dedf0e367)
This commit is contained in:
Dmitry Batrak
2023-08-18 13:27:47 +03:00
committed by jbrbot
parent a4135ba50b
commit a24d5c01d4
5 changed files with 34 additions and 28 deletions

View File

@@ -62,6 +62,7 @@ public class AquaCaret extends DefaultCaret
public void deinstall(final JTextComponent c) {
c.removePropertyChangeListener(this);
super.deinstall(c);
mFocused = false;
}
@Override

View File

@@ -269,7 +269,7 @@ public class CInputMethod extends InputMethodAdapter {
public void removeNotify() {
if (fAwtFocussedComponentPeer != null) {
long modelPtr = getNativeViewPtr(fAwtFocussedComponentPeer);
nativeEndComposition(modelPtr);
nativeEndComposition(modelPtr, fAwtFocussedComponent);
nativeNotifyPeer(modelPtr, null);
}
@@ -355,7 +355,7 @@ public class CInputMethod extends InputMethodAdapter {
*/
public void endComposition() {
if (fAwtFocussedComponentPeer != null)
nativeEndComposition(getNativeViewPtr(fAwtFocussedComponentPeer));
nativeEndComposition(getNativeViewPtr(fAwtFocussedComponentPeer), fAwtFocussedComponent);
}
/**
@@ -563,18 +563,21 @@ public class CInputMethod extends InputMethodAdapter {
/**
* Frequent callbacks from NSTextInput. I think we're supposed to commit it here?
*/
private synchronized void unmarkText() {
if (fCurrentText == null || fAwtFocussedComponent == null) return;
private synchronized void unmarkText(Component component) {
if (component == null) {
component = fAwtFocussedComponent;
}
if (fCurrentText == null || component == null) return;
TextHitInfo theCaret = TextHitInfo.afterOffset(fCurrentTextLength);
TextHitInfo visiblePosition = theCaret;
InputMethodEvent event = new InputMethodEvent(fAwtFocussedComponent,
InputMethodEvent event = new InputMethodEvent(component,
InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
fCurrentText.getIterator(),
fCurrentTextLength,
theCaret,
visiblePosition);
LWCToolkit.postEvent(LWCToolkit.targetToAppContext(fAwtFocussedComponent), event);
LWCToolkit.postEvent(LWCToolkit.targetToAppContext(component), event);
fCurrentText = null;
fCurrentTextAsString = null;
fCurrentTextLength = 0;
@@ -807,7 +810,7 @@ public class CInputMethod extends InputMethodAdapter {
// Note that if nativePeer isn't something that normally accepts keystrokes (i.e., a CPanel)
// these calls will be ignored.
private native void nativeNotifyPeer(long nativePeer, CInputMethod imInstance);
private native void nativeEndComposition(long nativePeer);
private native void nativeEndComposition(long nativePeer, Component component);
private native void nativeHandleEvent(LWComponentPeer<?, ?> peer, AWTEvent event);
// Returns the locale of the active input method.

View File

@@ -66,6 +66,6 @@
// Input method-related events
- (void)setInputMethod:(jobject)inputMethod;
- (void)abandonInput;
- (void)abandonInput:(jobject) component;
@end

View File

@@ -338,7 +338,7 @@ extern bool isSystemShortcut_NextWindowInApplication(NSUInteger modifiersMask, N
case kVK_End:
// Abandon input to reset IM and unblock input after
// canceling input accented symbols
[self abandonInput];
[self abandonInput:nil];
break;
}
}
@@ -1146,7 +1146,7 @@ static jclass jc_CInputMethod = NULL;
// Abandon input to reset IM and unblock input after entering accented
// symbols
[self abandonInput];
[self abandonInput:nil];
}
+ (void)keyboardInputSourceChanged:(NSNotification *)notification
@@ -1240,7 +1240,11 @@ static jclass jc_CInputMethod = NULL;
}
}
- (void) unmarkText
- (void) unmarkText {
[self unmarkText:nil];
}
- (void) unmarkText:(jobject) component
{
#ifdef IM_DEBUG
fprintf(stderr, "AWTView InputMethod Selector Called : [unmarkText]\n");
@@ -1253,8 +1257,8 @@ static jclass jc_CInputMethod = NULL;
// unmarkText cancels any input in progress and commits it to the text field.
JNIEnv *env = [ThreadUtilities getJNIEnv];
GET_CIM_CLASS();
DECLARE_METHOD(jm_unmarkText, jc_CInputMethod, "unmarkText", "()V");
(*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_unmarkText);
DECLARE_METHOD(jm_unmarkText, jc_CInputMethod, "unmarkText", "(Ljava/awt/Component;)V");
(*env)->CallVoidMethod(env, fInputMethodLOCKABLE, jm_unmarkText, component);
CHECK_EXCEPTION();
}
@@ -1515,14 +1519,14 @@ static jclass jc_CInputMethod = NULL;
object:nil];
}
- (void)abandonInput
- (void)abandonInput:(jobject) component
{
#ifdef IM_DEBUG
fprintf(stderr, "AWTView InputMethod Selector Called : [abandonInput]\n");
#endif // IM_DEBUG
[ThreadUtilities performOnMainThread:@selector(markedTextAbandoned:) on:[NSInputManager currentInputManager] withObject:self waitUntilDone:YES];
[self unmarkText];
[self unmarkText:component];
}
/******************************** END NSTextInputClient Protocol ********************************/

View File

@@ -118,13 +118,6 @@ static void initializeInputMethodController() {
[view setInputMethod:inputMethod]; // inputMethod is a GlobalRef or null to disable.
}
+ (void) _nativeEndComposition:(AWTView *)view {
if (view == nil) return;
[view abandonInput];
}
@end
/*
@@ -186,16 +179,21 @@ JNI_COCOA_EXIT(env);
/*
* Class: sun_lwawt_macosx_CInputMethod
* Method: nativeEndComposition
* Signature: (J)V
* Signature: (JLjava/awt/Component;)V
*/
JNIEXPORT void JNICALL Java_sun_lwawt_macosx_CInputMethod_nativeEndComposition
(JNIEnv *env, jobject this, jlong nativePeer)
(JNIEnv *env, jobject this, jlong nativePeer, jobject component)
{
JNI_COCOA_ENTER(env);
AWTView *view = (AWTView *)jlong_to_ptr(nativePeer);
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
[CInputMethod _nativeEndComposition:view];
AWTView *view = (AWTView *)jlong_to_ptr(nativePeer);
if (!view) return;
jobject componentRef = (*env)->NewGlobalRef(env, component);
[ThreadUtilities performOnMainThreadWaiting:NO block:^(){
[view abandonInput:componentRef];
if (componentRef) {
JNIEnv *env = [ThreadUtilities getJNIEnv];
(*env)->DeleteGlobalRef(env, componentRef);
}
}];
JNI_COCOA_EXIT(env);