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()`)
This commit is contained in:
Aleksey Pivovarov
2016-05-12 12:22:24 +03:00
committed by Aleksey Pivovarov
parent 89c6a1b5b5
commit 29fbf91247
3 changed files with 6 additions and 3 deletions
@@ -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
@@ -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
@@ -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