mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
JBR-2847 Always dispatch KEY_TYPED event to the same component as KEY_PRESSED event
also fixes JBR-2834, IDEA-254466, IDEA-254466 squashed with fixes for JBR-3291, JBR-3307, JBR-3598 (cherry picked from commitse94f6057a4,ba6b9c085e,2ccf6b65a7,3b0708af7d,3674766d65) (cherry picked from commitd7383ededb)
This commit is contained in:
@@ -77,6 +77,7 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager {
|
||||
private LinkedList<TypeAheadMarker> typeAheadMarkers = new LinkedList<TypeAheadMarker>();
|
||||
private boolean consumeNextKeyTyped;
|
||||
private Component restoreFocusTo;
|
||||
private WeakReference<Component> lastKeyPressedOrReleasedTarget = NULL_COMPONENT_WR;
|
||||
|
||||
private static boolean fxAppThreadIsDispatchThread;
|
||||
|
||||
@@ -865,7 +866,9 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager {
|
||||
* @see Component#dispatchEvent
|
||||
*/
|
||||
public boolean dispatchKeyEvent(KeyEvent e) {
|
||||
Component focusOwner = (((AWTEvent)e).isPosted) ? getFocusOwner() : e.getComponent();
|
||||
Component focusOwner = (((AWTEvent)e).isPosted &&
|
||||
!(e.getID() == KeyEvent.KEY_TYPED && SunToolkit.isSystemGenerated(e)))
|
||||
? getFocusOwner() : e.getComponent();
|
||||
|
||||
if (focusOwner != null && focusOwner.isShowing() && focusOwner.canBeFocusOwner()) {
|
||||
if (!e.isConsumed()) {
|
||||
@@ -1089,8 +1092,21 @@ public class DefaultKeyboardFocusManager extends KeyboardFocusManager {
|
||||
|
||||
private boolean preDispatchKeyEvent(KeyEvent ke) {
|
||||
if (((AWTEvent) ke).isPosted) {
|
||||
Component focusOwner = getFocusOwner();
|
||||
ke.setSource(((focusOwner != null) ? focusOwner : getFocusedWindow()));
|
||||
boolean typedEvent = ke.getID() == KeyEvent.KEY_TYPED;
|
||||
boolean systemEvent = SunToolkit.isSystemGenerated(ke);
|
||||
Component focusOwner;
|
||||
if (typedEvent && systemEvent) {
|
||||
focusOwner = lastKeyPressedOrReleasedTarget.get();
|
||||
} else {
|
||||
focusOwner = getFocusOwner();
|
||||
if (focusOwner == null) {
|
||||
focusOwner = getFocusedWindow();
|
||||
}
|
||||
}
|
||||
if (!typedEvent && systemEvent) {
|
||||
lastKeyPressedOrReleasedTarget = new WeakReference<>(focusOwner);
|
||||
}
|
||||
ke.setSource(focusOwner);
|
||||
}
|
||||
if (ke.getSource() == null) {
|
||||
return true;
|
||||
|
||||
@@ -5335,7 +5335,6 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
|
||||
// Start editing when a key is typed. UI classes can disable this behavior
|
||||
// by setting the client property JTable.autoStartsEdit to Boolean.FALSE.
|
||||
if (!retValue && condition == WHEN_ANCESTOR_OF_FOCUSED_COMPONENT &&
|
||||
isFocusOwner() &&
|
||||
!Boolean.FALSE.equals(getClientProperty("JTable.autoStartsEdit"))) {
|
||||
// We do not have a binding for the event.
|
||||
Component editorComponent = getEditorComponent();
|
||||
@@ -5364,11 +5363,6 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
|
||||
if (editorComponent == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// If the editorComponent is a JComponent, pass the event to it.
|
||||
if (editorComponent instanceof JComponent) {
|
||||
retValue = ((JComponent)editorComponent).processKeyBinding
|
||||
(ks, e, WHEN_FOCUSED, pressed);
|
||||
// If we have started an editor as a result of the user
|
||||
// pressing a key and the surrendersFocusOnKeystroke property
|
||||
// is true, give the focus to the new editor.
|
||||
@@ -5378,6 +5372,11 @@ public class JTable extends JComponent implements TableModelListener, Scrollable
|
||||
editorComponent.requestFocus();
|
||||
}
|
||||
}
|
||||
// If the editorComponent is a JComponent, pass the event to it.
|
||||
if (editorComponent instanceof JComponent) {
|
||||
retValue = ((JComponent)editorComponent).processKeyBinding
|
||||
(ks, e, WHEN_FOCUSED, pressed);
|
||||
}
|
||||
}
|
||||
return retValue;
|
||||
}
|
||||
|
||||
@@ -884,7 +884,6 @@ javax/swing/JComboBox/6607130/bug6607130.java
|
||||
javax/swing/JComboBox/4199622/bug4199622.java nobug windows-all
|
||||
javax/swing/JComboBox/4515752/DefaultButtonTest.java nobug windows-all
|
||||
|
||||
javax/swing/JComboBox/8032878/bug8032878.java nobug windows-all
|
||||
javax/swing/JComboBox/8057893/bug8057893.java nobug windows-all
|
||||
|
||||
javax/swing/JList/6462008/bug6462008.java nobug windows-all
|
||||
|
||||
Reference in New Issue
Block a user