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.
This commit is contained in:
Sergey Simonchik
2018-07-24 16:20:50 +03:00
parent c5e9cc83c2
commit 8584df61f9
@@ -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