Escape should work in terminal the same way as for other windows (IDEA-116221)
authorDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Wed, 26 Oct 2016 16:29:31 +0000 (18:29 +0200)
committerDmitry Trofimov <dmitry.trofimov@jetbrains.com>
Wed, 26 Oct 2016 16:29:31 +0000 (18:29 +0200)
plugins/terminal/lib/jediterm-pty-2.2.jar
plugins/terminal/src/org/jetbrains/plugins/terminal/JBTabbedTerminalWidget.java
plugins/terminal/src/org/jetbrains/plugins/terminal/JBTerminalWidget.java

index b8c321c79bf58e74efeaa03eb0ccf5285df5fd16..61b96fd443b592402960587d067c89206fd59bb0 100644 (file)
Binary files a/plugins/terminal/lib/jediterm-pty-2.2.jar and b/plugins/terminal/lib/jediterm-pty-2.2.jar differ
index bab43d35d93c29cdddc2d15cc894b3cf47ccca3f..92aa38c26c9ef4865f213c55e445b405cad41ed4 100644 (file)
@@ -100,6 +100,9 @@ public class JBTabbedTerminalWidget extends TabbedTerminalWidget implements Disp
                                     @NotNull List<TerminalAction> actions,
                                     @Nullable final Predicate<KeyEvent> elseAction) {
     for (final TerminalAction action : actions) {
+      if (action.isHidden()) {
+        continue;
+      }
       AnAction a = new DumbAwareAction() {
         @Override
         public void actionPerformed(AnActionEvent e) {
@@ -117,7 +120,7 @@ public class JBTabbedTerminalWidget extends TabbedTerminalWidget implements Disp
 
   @Override
   protected JediTermWidget createInnerTerminalWidget(TabbedSettingsProvider settingsProvider) {
-    return new JBTerminalWidget(mySettingsProvider, myParent);
+    return new JBTerminalWidget(myProject, mySettingsProvider, myParent);
   }
 
   @Override
index 9485714944c359600710f6477512256910ff88fd..8a935c8c30e08ebd496294a06fab4312f4e1ef7f 100644 (file)
@@ -1,7 +1,10 @@
 package org.jetbrains.plugins.terminal;
 
+import com.google.common.base.Predicate;
 import com.intellij.openapi.Disposable;
+import com.intellij.openapi.project.Project;
 import com.intellij.openapi.util.Disposer;
+import com.intellij.openapi.wm.ToolWindowManager;
 import com.intellij.ui.SearchTextField;
 import com.intellij.ui.components.JBScrollBar;
 import com.intellij.ui.components.JBScrollPane;
@@ -15,18 +18,24 @@ import com.jediterm.terminal.model.JediTerminal;
 import com.jediterm.terminal.model.StyleState;
 import com.jediterm.terminal.model.TerminalTextBuffer;
 import com.jediterm.terminal.ui.JediTermWidget;
+import com.jediterm.terminal.ui.TerminalAction;
 import com.jediterm.terminal.ui.settings.SettingsProvider;
 import org.jetbrains.annotations.NotNull;
 
 import javax.swing.*;
 import javax.swing.event.DocumentListener;
 import java.awt.*;
+import java.awt.event.KeyEvent;
 import java.awt.event.KeyListener;
+import java.util.List;
 
 public class JBTerminalWidget extends JediTermWidget implements Disposable{
 
-  public JBTerminalWidget(JBTerminalSystemSettingsProvider settingsProvider, Disposable parent) {
+  private final Project myProject;
+
+  public JBTerminalWidget(Project project, JBTerminalSystemSettingsProvider settingsProvider, Disposable parent) {
     super(settingsProvider);
+    myProject = project;
     setName("terminal");
     JBTabbedTerminalWidget.convertActions(this, getActions());
 
@@ -76,7 +85,28 @@ public class JBTerminalWidget extends JediTermWidget implements Disposable{
     });
     return bar;
   }
-  
+
+  @Override
+  public List<TerminalAction> getActions() {
+     List<TerminalAction> actions = super.getActions();
+     if (!TerminalOptionsProvider.getInstance().overrideIdeShortcuts()) {
+       actions
+         .add(new TerminalAction("EditorEscape", new KeyStroke[]{KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)}, new Predicate<KeyEvent>() {
+           @Override
+           public boolean apply(KeyEvent input) {
+             if (!myTerminalPanel.getTerminalTextBuffer().isUsingAlternateBuffer()) {
+               ToolWindowManager.getInstance(myProject).activateEditorComponent();
+               return true;
+             }
+             else {
+               return false;
+             }
+           }
+         }).withHidden(true));
+     }
+     return actions;
+  };
+
   @Override
   public void dispose() {
   }