Project: Eclipse_Platform_UI
Bug 294117 [Commands] Ctrl+C, Ctrl+X, Ctrl+V (Cut, Copy, Paste) shortcuts don't work over SWT_AWT Bridge
Reported: 2009-11-03 15:37:08 | Status: verified fixed

User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322; InfoPath.1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.04506.648; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729) Build Identifier: Version: 3.5.0 Build id: I20090611-1540 In Eclipse 3.5, the Ctrl+C, Ctrl+X, Ctrl+V (Cut, Copy, Paste) shortcuts no longer work in all Swing JTextComponents in a SWT_AWT Bridge frame. In summary the problem is due to the fact that since Eclipse 3.5 was introduced, the JTextComponent (hosted via the bridge Frame) no longer receives the normal sequence of KeyEvents dispatched from the AWT EventQueue when a cut/copy/paste key shortcut occurs. More specifically, the KEY_PRESSED KeyEvent that is normally included in the KeyEvent sequence when one of these CTRL+C, CTRL+X, CTRL+V shortcut operations occurs is now !!!MISSING!!!. The the missing KEY_PRESSED event causes the key shortcut action to fail the Swing KeyEvent processing as illustrated below: 1) The JComponent.processKeyEvent(e) receives the KEY_RELEASED event for the CTRL+V without receiving a prior matching KEY_PRESSED event. 2) The method assigns the flag "shouldProcessKey" by calling method KeyboardState.shouldProcess(e). 3) The KeyboardState.shouldProcess(KeyEvent e) method first checks a registry to determine if a matching KEY_PRESSED event for CTRL+V has been encountered. If not, it assigns the "shouldProcessKey" to "false". 4) Since "shouldProcessKey==false", JComponent.processKeyEvent(e) does not call processKeyBindings(...) for the event like it normally would and IGNORES the event. Reproducible: Always Steps to Reproduce: I am attaching eclipse plugin KeyEvents_1.0.0.200911021616.jar to demonstrate this problem. The plugin contains the Sun Swing Sample KeyEventDemo and a simple eclipse view (KeyEventDemoView) to embed the swing KeyEventDemo panel in a Composite via the SWT_AWT bridge. 1) Include the plugin in your target platform. 2) Launch eclipse. 3) Click Window | Show View | Other...; the "Show View" dialog is displayed. 4) Select "Key Events Category" | "KeyEvent Demo View"; the "KeyEvent Demo View" is displayed in the workbench. 5) Within the workbench go to any SWT view and copy (Ctrl-C) some text into your clipboard. 6) Now go to the "KeyEvent Demo View" and click mouse in JTextField at the top of the panel to give keyboard focus; the caret is flashing in the textfield. 7) Type the Ctrl+V key shortcut in the textfield. Expected Behavior: The contents of the clipboard SHOULD be copied to the textfield. The following list of key events SHOULD appear in the list box below it (as they would in a pure Swing app): KEY PRESSED: key code = 17 (Ctrl) modifiers = 128 (Ctrl) KEY PRESSED: key code = 86 (V) modifiers = 128 (Ctrl) KEY TYPED: key character = CHAR_UNDEFINED modifiers = 128 (Ctrl) KEY RELEASED: key code = 86 (V) modifiers = 128 (Ctrl) KEY RELEASED: key code = 17 (Ctrl) modifiers = 0 (no modifiers) Actual Behavior: The contents of the clipboard ARE NOT copied to the textfield. The following list of key events appears in the list box (NOTICE that the KEY_PRESSED for the Ctrl+V event is !!MISSING!!): KEY PRESSED: key code = 17 (Ctrl) modifiers = 128 (Ctrl) KEY RELEASED: key code = 86 (V) modifiers = 128 (Ctrl) KEY RELEASED: key code = 17 (Ctrl) modifiers = 0 (no modifiers) Additional Info: If you extract the KeyEventDemo.java source (remove the package name from the source), then compile and run it (yes, it already has main() method inside) using jre 1.6.0, then you will see the KeyEventDemo appear as a pure swing app. Try to use the Ctrl+v paste shortcut in the text field as before and you will now see it work as it should. Check the list box and see the proper sequence of KeyEvents fired.

Files changed in fix:
bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/handlers/WidgetMethodHandler.java