From 8584df61f91cc2af34d06cdcaff8f57230787ed8 Mon Sep 17 00:00:00 2001 From: Sergey Simonchik Date: Tue, 24 Jul 2018 16:15:28 +0300 Subject: [PATCH] support Tab character in console via registerActionHandler for IdeActions.ACTION_EDITOR_TAB (IDEA-195938) (IDEA-CR-35309) No need to disable focus traversal keys in this case, also the fix looks more consistent with other editor actions in console. --- .../execution/impl/ConsoleViewImpl.java | 32 +++++++------------ 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java index bda25beb7a50..3a286c565847 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/impl/ConsoleViewImpl.java @@ -74,7 +74,9 @@ import org.jetbrains.annotations.TestOnly; import javax.swing.*; import java.awt.*; import java.awt.datatransfer.DataFlavor; -import java.awt.event.*; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseWheelEvent; import java.io.IOException; import java.util.*; import java.util.List; @@ -399,18 +401,6 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo ); } - @Override - protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { - // Run Tab typed action, as EditorImpl.processKeyTyped(java.awt.event.KeyEvent) doesn't handle Tab characters. - if (!myIsViewer && e.getID() == KeyEvent.KEY_TYPED && e.getModifiers() == 0 && e.getKeyChar() == '\t') { - EditorEx editor = (EditorEx)getEditor(); - TypedAction action = EditorActionManager.getInstance().getTypedAction(); - action.actionPerformed(editor, e.getKeyChar(), editor.getDataContext()); - return true; - } - return super.processKeyBinding(ks, e, condition, pressed); - } - @Override @NotNull public JComponent getComponent() { @@ -425,18 +415,10 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo initConsoleEditor(); requestFlushImmediately(); myMainPanel.add(createCenterComponent(), BorderLayout.CENTER); - disableFocusTraversalKeys(myEditor); } return this; } - private static void disableFocusTraversalKeys(@NotNull Editor editor) { - // Tab key should be handled as a typed character, not as a focus traversal key. - JComponent component = editor.getContentComponent(); - component.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, new HashSet<>()); - component.setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, new HashSet<>()); - } - /** * Adds transparent (actually, non-opaque) component over console. * It will be as big as console. Use it to draw on console because it does not prevent user from console usage. @@ -913,6 +895,7 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo registerActionHandler(myEditor, IdeActions.ACTION_EDITOR_PASTE, new PasteHandler()); registerActionHandler(myEditor, IdeActions.ACTION_EDITOR_BACKSPACE, new BackSpaceHandler()); registerActionHandler(myEditor, IdeActions.ACTION_EDITOR_DELETE, new DeleteHandler()); + registerActionHandler(myEditor, IdeActions.ACTION_EDITOR_TAB, new TabHandler()); registerActionHandler(myEditor, EOFAction.ACTION_ID); } @@ -1327,6 +1310,13 @@ public class ConsoleViewImpl extends JPanel implements ConsoleView, ObservableCo } } + private static class TabHandler extends ConsoleAction { + @Override + protected void execute(@NotNull ConsoleViewImpl console, @NotNull DataContext context) { + console.type(console.myEditor, "\t"); + } + } + @Override public JComponent getPreferredFocusableComponent() { //ensure editor created