From f5002ec244eec48c26be78ccbc6cbb1058581d50 Mon Sep 17 00:00:00 2001 From: Denis Fokin Date: Mon, 19 Mar 2018 17:59:49 +0300 Subject: [PATCH] IDEA-188519 Actions that do not show popup because of dumb mode fail typeahead --- .../src/com/intellij/ide/IdeEventQueue.java | 4 +++- .../keymap/impl/DumbModeWarningListener.java | 6 ++++++ .../openapi/keymap/impl/IdeKeyEventDispatcher.java | 13 +++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 platform/platform-impl/src/com/intellij/openapi/keymap/impl/DumbModeWarningListener.java diff --git a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java index 63357020c2be..2054442ea4b2 100644 --- a/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java +++ b/platform/platform-impl/src/com/intellij/ide/IdeEventQueue.java @@ -229,6 +229,8 @@ public class IdeEventQueue extends EventQueue { addDispatcher(new EditingCanceller(), null); abracadabraDaberBoreh(); + + IdeKeyEventDispatcher.addDumbModeWarningListener(() -> flushDelayedKeyEvents()); } private void abracadabraDaberBoreh() { @@ -1386,7 +1388,7 @@ public class IdeEventQueue extends EventQueue { return true; } - private void flushDelayedKeyEvents() { + public void flushDelayedKeyEvents() { delayKeyEvents.set(false); int size = myDelayedKeyEvents.size(); for (int keyEventIndex = 0; keyEventIndex < size; keyEventIndex++) { diff --git a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/DumbModeWarningListener.java b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/DumbModeWarningListener.java new file mode 100644 index 000000000000..a105b4bde248 --- /dev/null +++ b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/DumbModeWarningListener.java @@ -0,0 +1,6 @@ +// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.openapi.keymap.impl; + +public interface DumbModeWarningListener { + void actionCanceledBecauseOfDumbMode(); +} diff --git a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeKeyEventDispatcher.java b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeKeyEventDispatcher.java index c7060aed3298..d2a7678edc0b 100644 --- a/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeKeyEventDispatcher.java +++ b/platform/platform-impl/src/com/intellij/openapi/keymap/impl/IdeKeyEventDispatcher.java @@ -628,6 +628,13 @@ public final class IdeKeyEventDispatcher implements Disposable { } if (!nonDumbAwareAction.isEmpty()) { + + if (dumbModeWarningListener != null) { + dumbModeWarningListener.actionCanceledBecauseOfDumbMode(); + } + + IdeEventQueue.getInstance().flushDelayedKeyEvents(); + showDumbModeWarningLaterIfNobodyConsumesEvent(e, nonDumbAwareAction.toArray(new AnActionEvent[0])); } @@ -644,6 +651,12 @@ public final class IdeKeyEventDispatcher implements Disposable { } } + private static DumbModeWarningListener dumbModeWarningListener = null; + + public static void addDumbModeWarningListener (DumbModeWarningListener listener) { + dumbModeWarningListener = listener; + } + /** * This method fills {@code myActions} list. * @return true if there is a shortcut with second stroke found.