fix behaviour of Ctrl+Up/Down when parameter info is shown

... and lookup is not shown
This commit is contained in:
Dmitry Batrak
2017-08-17 19:16:13 +03:00
parent 812c1c5413
commit 2a7e9af405
4 changed files with 71 additions and 60 deletions
@@ -20,11 +20,14 @@ import com.intellij.codeInsight.completion.CompletionMemory;
import com.intellij.codeInsight.completion.JavaMethodCallElement;
import com.intellij.codeInsight.hint.ParameterInfoController;
import com.intellij.codeInsight.hints.ParameterHintsPass;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.editor.actionSystem.EditorActionManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Key;
@@ -181,47 +184,53 @@ abstract class JavaMethodOverloadSwitchHandler extends EditorActionHandler {
}
public static class UpInEditor extends UpDownInEditor {
public UpInEditor() {
super(true);
public UpInEditor(EditorActionHandler originalHandler) {
super(originalHandler, true);
}
}
public static class DownInEditor extends UpDownInEditor {
public DownInEditor() {
super(false);
public DownInEditor(EditorActionHandler originalHandler) {
super(originalHandler, false);
}
}
private static abstract class UpDownInEditor extends AnAction {
private static abstract class UpDownInEditor extends EditorActionHandler {
private final EditorActionHandler myOriginalHandler;
private final boolean myUp;
private UpDownInEditor(boolean up) {
private UpDownInEditor(EditorActionHandler originalHandler, boolean up) {
myOriginalHandler = originalHandler;
myUp = up;
}
@Override
public void update(AnActionEvent e) {
Editor editor = e.getData(CommonDataKeys.EDITOR);
e.getPresentation().setEnabled(CodeInsightSettings.getInstance().SHOW_PARAMETER_NAME_HINTS_ON_COMPLETION && editor != null &&
ParameterInfoController.existsWithVisibleHintForEditor(editor, false));
protected boolean isEnabledForCaret(@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) {
return myOriginalHandler.isEnabled(editor, caret, dataContext) ||
isEnabled(editor);
}
private static boolean isEnabled(@NotNull Editor editor) {
return CodeInsightSettings.getInstance().SHOW_PARAMETER_NAME_HINTS_ON_COMPLETION &&
ParameterInfoController.existsWithVisibleHintForEditor(editor, false);
}
@Override
public void actionPerformed(AnActionEvent e) {
Editor editor = e.getData(CommonDataKeys.EDITOR);
assert editor != null;
ParameterInfoController.hideAllHints(editor);
protected void doExecute(@NotNull Editor editor, @Nullable Caret caret, DataContext dataContext) {
if (isEnabled(editor)) {
ParameterInfoController.hideAllHints(editor);
}
// hints can be hidden asynchronously (with animation), so we disable switching explicitly here
editor.putUserData(SWITCH_DISABLED, Boolean.TRUE);
try {
ActionManager actionManager = ActionManager.getInstance();
AnAction action = actionManager.getAction(myUp ? IdeActions.ACTION_LOOKUP_UP
: IdeActions.ACTION_LOOKUP_DOWN);
if (action == null) {
action = actionManager.getAction(myUp ? IdeActions.ACTION_EDITOR_MOVE_CARET_UP
: IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN);
if (myOriginalHandler.isEnabled(editor, caret, dataContext)) {
myOriginalHandler.execute(editor, caret, dataContext);
}
else {
EditorActionManager.getInstance().getActionHandler(myUp ? IdeActions.ACTION_EDITOR_MOVE_CARET_UP
: IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN)
.execute(editor, caret, dataContext);
}
action.actionPerformed(e);
}
finally {
editor.putUserData(SWITCH_DISABLED, null);
@@ -565,7 +565,7 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
waitForAllAsyncStuff();
checkHintContents("<html><b>@NotNull String key</b></html>\n" +
"<html><b>@NotNull String key</b>, String def</html>");
myFixture.performEditorAction("EditorOverloadUp");
myFixture.performEditorAction(IdeActions.ACTION_LOOKUP_UP);
waitForAllAsyncStuff();
checkResultWithInlays("<caret>class C { void m() { System.getProperty(<hint text=\"key:\"/>, <hint text=\"def:\"/>) } }");
checkHintContents(null);
@@ -580,7 +580,7 @@ public class CompletionHintsTest extends LightFixtureCompletionTestCase {
waitForAllAsyncStuff();
checkHintContents("<html><b>@NotNull String key</b></html>\n" +
"<html><b>@NotNull String key</b>, String def</html>");
myFixture.performEditorAction("EditorOverloadDown");
myFixture.performEditorAction(IdeActions.ACTION_LOOKUP_DOWN);
waitForAllAsyncStuff();
checkResultWithInlays("class C { void m() { System.getProperty(<hint text=\"key:\"/>, <hint text=\"def:\"/>) } }<caret>");
checkHintContents(null);
@@ -20,16 +20,18 @@ import com.intellij.codeInsight.completion.CodeCompletionFeatures;
import com.intellij.codeInsight.completion.CompletionProgressIndicator;
import com.intellij.codeInsight.completion.impl.CompletionServiceImpl;
import com.intellij.codeInsight.lookup.CharFilter;
import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.codeInsight.lookup.LookupManager;
import com.intellij.featureStatistics.FeatureUsageTracker;
import com.intellij.ide.ui.UISettings;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.IdeActions;
import com.intellij.openapi.editor.Caret;
import com.intellij.openapi.editor.CaretAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorAction;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.editor.actionSystem.EditorActionManager;
import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.ui.ScrollingUtil;
import org.jetbrains.annotations.NotNull;
@@ -105,39 +107,44 @@ public abstract class LookupActionHandler extends EditorActionHandler {
}
public static class UpAction extends DumbAwareAction {
@Override
public void actionPerformed(AnActionEvent e) {
FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_CONTROL_ARROWS);
LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(CommonDataKeys.EDITOR.getData(e.getDataContext()));
assert lookup != null : LookupImpl.getLastLookupDisposeTrace();
lookup.hideLookup(true);
ActionManager.getInstance().getAction(IdeActions.ACTION_EDITOR_MOVE_CARET_UP).actionPerformed(e);
}
@Override
public void update(AnActionEvent e) {
Lookup lookup = LookupManager.getActiveLookup(CommonDataKeys.EDITOR.getData(e.getDataContext()));
e.getPresentation().setEnabled(lookup != null);
public static class UpAction extends EditorAction implements DumbAware {
public UpAction() {
super(new UpDownInEditorHandler(true));
}
}
public static class DownAction extends DumbAwareAction {
public static class DownAction extends EditorAction implements DumbAware {
public DownAction() {
super(new UpDownInEditorHandler(false));
}
}
@Override
public void actionPerformed(AnActionEvent e) {
FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_CONTROL_ARROWS);
LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(CommonDataKeys.EDITOR.getData(e.getDataContext()));
assert lookup != null : LookupImpl.getLastLookupDisposeTrace();
lookup.hideLookup(true);
ActionManager.getInstance().getAction(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN).actionPerformed(e);
private static class UpDownInEditorHandler extends EditorActionHandler {
private final boolean myUp;
private UpDownInEditorHandler(boolean up) {
myUp = up;
}
@Override
public void update(AnActionEvent e) {
Lookup lookup = LookupManager.getActiveLookup(CommonDataKeys.EDITOR.getData(e.getDataContext()));
e.getPresentation().setEnabled(lookup != null);
public boolean executeInCommand(@NotNull Editor editor, DataContext dataContext) {
return false;
}
@Override
protected boolean isEnabledForCaret(@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) {
return LookupManager.getActiveLookup(editor) != null;
}
@Override
protected void doExecute(@NotNull Editor editor, @Nullable Caret caret, DataContext dataContext) {
FeatureUsageTracker.getInstance().triggerFeatureUsed(CodeCompletionFeatures.EDITING_COMPLETION_CONTROL_ARROWS);
LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor);
assert lookup != null : LookupImpl.getLastLookupDisposeTrace();
lookup.hideLookup(true);
EditorActionManager.getInstance().getActionHandler(myUp ? IdeActions.ACTION_EDITOR_MOVE_CARET_UP
: IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN)
.execute(editor, caret, dataContext);
}
}
+2 -7
View File
@@ -17,13 +17,6 @@
<id>com.intellij</id>
<name>IDEA CORE</name>
<actions>
<action id="EditorOverloadUp" class="com.intellij.codeInsight.editorActions.JavaMethodOverloadSwitchHandler$UpInEditor"
use-shortcut-of="EditorLookupUp"/>
<action id="EditorOverloadDown" class="com.intellij.codeInsight.editorActions.JavaMethodOverloadSwitchHandler$DownInEditor"
use-shortcut-of="EditorLookupDown"/>
</actions>
<xi:include href="/META-INF/IdeTipsAndTricks.xml" xpointer="xpointer(/idea-plugin/*)"/>
<xi:include href="/idea/RichPlatformPlugin.xml" xpointer="xpointer(/idea-plugin/*)"/>
<module value="com.intellij.modules.java"/>
@@ -1431,6 +1424,8 @@
<editorActionHandler action="PrevParameter" implementationClass="com.intellij.codeInsight.editorActions.JavaVarArgPrevParameterHandler"/>
<editorActionHandler action="EditorUp" implementationClass="com.intellij.codeInsight.editorActions.JavaMethodOverloadSwitchHandler$Up"/>
<editorActionHandler action="EditorDown" implementationClass="com.intellij.codeInsight.editorActions.JavaMethodOverloadSwitchHandler$Down"/>
<editorActionHandler action="EditorLookupUp" implementationClass="com.intellij.codeInsight.editorActions.JavaMethodOverloadSwitchHandler$UpInEditor"/>
<editorActionHandler action="EditorLookupDown" implementationClass="com.intellij.codeInsight.editorActions.JavaMethodOverloadSwitchHandler$DownInEditor"/>
<editorSmartKeysConfigurable instance="com.intellij.application.options.JavadocOptionsProvider"
id="editor.preferences.javadocOptions"