ui: stabilize action position in Keymap tree

This fix affects actions without default text/description
set in a plugin.xml or ActionsBundle.

Text/description might be initialised in AnAction constructor,
and thus be empty in StubAction.
Some ActionGroup might contain stub action, even if it was already loaded.

While collecting actions for "Other" group we will load non-stub version
of an action, and it will pass the filter.

Thus, prior to this fix, AnAction might change its place in a tree
depending on whether text filter was used or not.
And, in some cases, depending on the filter itself - as it could've match
internal action id.
This commit is contained in:
Aleksey Pivovarov
2017-02-16 17:49:21 +03:00
parent 4fdc027fa5
commit 6779b93ce8
@@ -507,6 +507,8 @@ public class ActionsTreeUtil {
return action -> {
if (filter == null) return true;
if (action == null) return false;
action = tryUnstubAction(action);
final String insensitiveFilter = filter.toLowerCase();
ArrayList<String> options = new ArrayList<>();
options.add(action.getTemplatePresentation().getText());
@@ -597,4 +599,13 @@ public class ActionsTreeUtil {
? ((DefaultActionGroup)group).getChildActionsOrStubs()
: group.getChildren(null);
}
@NotNull
private static AnAction tryUnstubAction(@NotNull AnAction action) {
if (action instanceof ActionStub) {
AnAction newAction = ActionManager.getInstance().getActionOrStub(((ActionStub)action).getId());
if (newAction != null) return newAction;
}
return action;
}
}