From 29fbf912470ff03b8f50454248591c2c0cbcdc39 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Tue, 10 May 2016 18:18:48 +0300 Subject: [PATCH] IDEA-128057 editor: consume shortcut for "next occurence" action even if there are nothing found These are local actions and we don't want their shortcuts to trigger some other action while search field is in focus (even if they have nothing to do). We still want `update()` to mark actions as disabled on toolbar. Issue: * open "Commit Changes" dialog * type "some commit message in a commit message editor" * invoke search * search for "comm", iterate over occurrences using "Enter" * search for "comment", try to iterate over occurrences using "Enter" * Bug: Dialog is closed, changes are committed (action is disabled and "Enter" is passed to the outer dialog, invoking `doOkAction()`) --- .../find/editorHeaderActions/NextOccurrenceAction.java | 3 ++- .../find/editorHeaderActions/PrevNextOccurrenceAction.java | 3 ++- .../find/editorHeaderActions/PrevOccurrenceAction.java | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/find/editorHeaderActions/NextOccurrenceAction.java b/platform/lang-impl/src/com/intellij/find/editorHeaderActions/NextOccurrenceAction.java index aa38ce2f5b1d..2128a0408def 100644 --- a/platform/lang-impl/src/com/intellij/find/editorHeaderActions/NextOccurrenceAction.java +++ b/platform/lang-impl/src/com/intellij/find/editorHeaderActions/NextOccurrenceAction.java @@ -36,7 +36,8 @@ public final class NextOccurrenceAction extends PrevNextOccurrenceAction { @Override public void actionPerformed(AnActionEvent e) { - e.getRequiredData(SearchSession.KEY).searchForward(); + SearchSession session = e.getRequiredData(SearchSession.KEY); + if (session.hasMatches()) session.searchForward(); } @NotNull diff --git a/platform/lang-impl/src/com/intellij/find/editorHeaderActions/PrevNextOccurrenceAction.java b/platform/lang-impl/src/com/intellij/find/editorHeaderActions/PrevNextOccurrenceAction.java index 0e1e694faec5..891df512f8d0 100644 --- a/platform/lang-impl/src/com/intellij/find/editorHeaderActions/PrevNextOccurrenceAction.java +++ b/platform/lang-impl/src/com/intellij/find/editorHeaderActions/PrevNextOccurrenceAction.java @@ -35,7 +35,8 @@ public abstract class PrevNextOccurrenceAction extends DumbAwareAction implement @Override public final void update(AnActionEvent e) { SearchSession search = e.getData(SearchSession.KEY); - e.getPresentation().setEnabled(search != null && search.hasMatches()); + boolean invokedByShortcut = !ActionPlaces.isToolbarPlace(e.getPlace()); + e.getPresentation().setEnabled(search != null && (invokedByShortcut || search.hasMatches())); } @Nullable diff --git a/platform/lang-impl/src/com/intellij/find/editorHeaderActions/PrevOccurrenceAction.java b/platform/lang-impl/src/com/intellij/find/editorHeaderActions/PrevOccurrenceAction.java index d39f9d5224bb..eb902ae3f9b1 100644 --- a/platform/lang-impl/src/com/intellij/find/editorHeaderActions/PrevOccurrenceAction.java +++ b/platform/lang-impl/src/com/intellij/find/editorHeaderActions/PrevOccurrenceAction.java @@ -39,7 +39,8 @@ public final class PrevOccurrenceAction extends PrevNextOccurrenceAction { @Override public void actionPerformed(AnActionEvent e) { - e.getRequiredData(SearchSession.KEY).searchBackward(); + SearchSession session = e.getRequiredData(SearchSession.KEY); + if (session.hasMatches()) session.searchBackward(); } @NotNull