// Copyright 2000-2021 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.ui;

import com.intellij.openapi.actionSystem.ActionPromoter;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.actionSystem.EditorAction;
import com.intellij.openapi.editor.actions.TextComponentEditorAction;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

import static java.util.Comparator.comparingInt;

/**
 * @author Konstantin Bulenkov
 */
public class EditorTextFieldActionPromoter implements ActionPromoter {
  /**
   * Encapsulates sorting rule that defines what editor actions have precedence to non-editor actions. Current approach is that
   * we want to process text processing-oriented editor actions with higher priority than non-editor actions and all
   * other editor actions with lower priority.
   * <p/>
   * Rationale: there is at least one commit-specific action that is mapped to the editor action by default
   * ({@code 'show commit messages history'} vs {@code 'scroll to center'}). We want to process the former on target
   * short key triggering. Another example is that {@code 'Ctrl+Shift+Right/Left Arrow'} shortcut is bound to
   * {@code 'expand/reduce selection by word'} editor action and {@code 'change dialog width'} non-editor action
   * and we want to use the first one.
   */
  private static final Comparator<AnAction> ACTIONS_COMPARATOR = comparingInt(action -> {
    if (action instanceof TextComponentEditorAction) return -1;
    if (action instanceof EditorAction) return 1;
    return 0;
  });

  @Override
  public List<AnAction> promote(@NotNull List<AnAction> actions, @NotNull DataContext context) {
    ArrayList<AnAction> result = new ArrayList<>(actions);
    result.sort(ACTIONS_COMPARATOR);
    return result;
  }
}

@@ -326,70 +326,8 @@
 xt;%0A
-import com.intellij.openapi.editor.actionSystem.EditorAction;%0A
 impo
@@ -456,240 +456,95 @@
 til.
-Array
 List;%0A
+%0A
 import 
-java.util.Comparator;%0Aimport java.util.List;%0A%0Aimport static java.util.Comparator.comparingInt;%0A%0A/**%0A * @author K
+static com.intellij.util.containers.C
 on
-s
 ta
-ntin Bulenkov%0A */%0Apublic class EditorTextFieldActionPromoter implements ActionPromoter %7B%0A  
+inerUtil.filterIsInstance;%0A%0A
 /**%0A
-  
  * E
@@ -639,16 +639,19 @@
 actions.
+%0A *
  Current
@@ -667,21 +667,16 @@
  is that
-%0A   *
  we want
@@ -751,98 +751,18 @@
 rity
- than non-editor actions and all%0A   * other editor actions with lower priority.%0A  
+.%0A
  * %3Cp/%3E%0A
    *
@@ -757,18 +757,16 @@
  * %3Cp/%3E%0A
-  
  * Ratio
@@ -774,268 +774,8 @@
 ale:
- there is at least one commit-specific action that is mapped to the editor action by default%0A   * (%7B@code 'show commit messages history'%7D vs %7B@code 'scroll to center'%7D). We want to process the former on target%0A   * short key triggering. Another example is that
  %7B@c
@@ -830,18 +830,16 @@
 ound to%0A
-  
  * %7B@cod
@@ -941,18 +941,16 @@
  action%0A
-  
  * and w
@@ -983,237 +983,115 @@
 e.%0A 
-  */%0A  private static final Comparator%3CAnAction%3E ACTIONS_COMPARATOR = comparingInt(action -%3E %7B%0A    if (action instanceof TextComponentEditorAction) return -1;%0A    if (action instanceof EditorAction) return 1;%0A    return 0;%0A  %7D);%0A
+*%0A * @author Konstantin Bulenkov%0A */%0Apublic class EditorTextFieldActionPromoter implements ActionPromoter %7B
 %0A  @
@@ -1204,117 +1204,73 @@
     
-ArrayList%3CAnAction%3E result = new ArrayList%3C%3E(actions);%0A    result.sort(ACTIONS_COMPARATOR);%0A    return result
+return filterIsInstance(actions, TextComponentEditorAction.class)
 ;%0A  

Fix "EditorTextFieldActionPromoter" - only promote "text processing"-oriented editor actions (IDEA-259561)