From b22d3db879fa9c4a7ed260a1162f9f6549c2fdca Mon Sep 17 00:00:00 2001 From: Tagir Valeev Date: Wed, 22 Sep 2021 13:27:55 +0700 Subject: [PATCH] [java-completion] Specific actions to move through lookup options Fixes IDEA-274076 Provide a way to change default keys used to navigate code completion list GitOrigin-RevId: ff5cb8d36c3b0f1315b7a1c708501134c15e8e67 --- .../lookup/impl/LookupActionHandler.java | 30 +++++++++++++++++-- .../src/messages/ActionsBundle.properties | 2 ++ .../src/idea/PlatformLangActionManager.xml | 2 ++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupActionHandler.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupActionHandler.java index 360ce6fda045..8b2f31661aaf 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupActionHandler.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupActionHandler.java @@ -44,7 +44,9 @@ public abstract class LookupActionHandler extends EditorActionHandler { if (project != null && lookup != null) { LookupManager.getInstance(project).hideActiveLookup(); } - myOriginalHandler.execute(editor, caret, dataContext); + if (myOriginalHandler != null) { + myOriginalHandler.execute(editor, caret, dataContext); + } return; } @@ -103,6 +105,28 @@ public abstract class LookupActionHandler extends EditorActionHandler { } } + public static class UpInLookupAction extends EditorAction { + public UpInLookupAction() { + super(new UpHandler(null) { + @Override + public boolean isEnabledForCaret(@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) { + return LookupManager.getActiveLookup(editor) != null; + } + }); + } + } + + public static class DownInLookupAction extends EditorAction { + public DownInLookupAction() { + super(new DownHandler(null) { + @Override + public boolean isEnabledForCaret(@NotNull Editor editor, @NotNull Caret caret, DataContext dataContext) { + return LookupManager.getActiveLookup(editor) != null; + } + }); + } + } + private static final class UpDownInEditorHandler extends EditorActionHandler { private final boolean myUp; @@ -140,7 +164,9 @@ public abstract class LookupActionHandler extends EditorActionHandler { @Override protected void executeInLookup(final LookupImpl lookup, DataContext context, Caret caret) { if (!UISettings.getInstance().getCycleScrolling() && !lookup.isFocused() && lookup.getList().getSelectedIndex() == 0) { - myOriginalHandler.execute(lookup.getEditor(), caret, context); + if (myOriginalHandler != null) { + myOriginalHandler.execute(lookup.getEditor(), caret, context); + } return; } executeUpOrDown(lookup, true); diff --git a/platform/platform-resources-en/src/messages/ActionsBundle.properties b/platform/platform-resources-en/src/messages/ActionsBundle.properties index 569f49b0ff03..7790a7b6b855 100644 --- a/platform/platform-resources-en/src/messages/ActionsBundle.properties +++ b/platform/platform-resources-en/src/messages/ActionsBundle.properties @@ -82,6 +82,8 @@ action.EditorLeftWithSelection.text=Left with Selection action.EditorRightWithSelection.text=Right with Selection action.EditorLookupUp.text=Lookup Up action.EditorLookupDown.text=Lookup Down +action.EditorLookupSelectionUp.text=Select Previous Completion Option +action.EditorLookupSelectionDown.text=Select Next Completion Option action.EditorIndentSelection.text=Indent Selection action.EditorUnindentSelection.text=Unindent Line or Selection action.EditorIndentLineOrSelection.text=Indent Line or Selection diff --git a/platform/platform-resources/src/idea/PlatformLangActionManager.xml b/platform/platform-resources/src/idea/PlatformLangActionManager.xml index 512cfe1ec210..d395ca38c9af 100644 --- a/platform/platform-resources/src/idea/PlatformLangActionManager.xml +++ b/platform/platform-resources/src/idea/PlatformLangActionManager.xml @@ -23,6 +23,8 @@ + +