From 88c77f257f39bcd2333f87239a7e22a936236497 Mon Sep 17 00:00:00 2001 From: "Maxim.Mossienko" Date: Wed, 23 Nov 2016 15:12:48 +0100 Subject: [PATCH] same policy for choosing selected text editor suitable for navigation --- .../intellij/ide/actions/GotoActionBase.java | 20 ++++++++++++------- .../ide/actions/SearchEverywhereAction.java | 7 ++----- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/actions/GotoActionBase.java b/platform/lang-impl/src/com/intellij/ide/actions/GotoActionBase.java index ecce07af15e0..049c91b8ae36 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/GotoActionBase.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/GotoActionBase.java @@ -128,13 +128,8 @@ public abstract class GotoActionBase extends AnAction { return Pair.create(predefined, 0); } if (useEditorSelection) { - final Editor editor = e.getData(CommonDataKeys.EDITOR); - if (editor != null) { - final String selectedText = editor.getSelectionModel().getSelectedText(); - if (selectedText != null && !selectedText.contains("\n")) { - return Pair.create(selectedText, 0); - } - } + String selectedText = getInitialTextForNavigation(e.getData(CommonDataKeys.EDITOR)); + if (selectedText != null) return new Pair<>(selectedText, 0); } final String query = e.getData(SpeedSearchSupply.SPEED_SEARCH_CURRENT_QUERY); @@ -160,6 +155,17 @@ public abstract class GotoActionBase extends AnAction { return Pair.create("", 0); } + @Nullable + public static String getInitialTextForNavigation(@Nullable Editor editor) { + if (editor != null) { + final String selectedText = editor.getSelectionModel().getSelectedText(); + if (selectedText != null && !selectedText.contains("\n")) { + return selectedText; + } + } + return null; + } + protected void showNavigationPopup(AnActionEvent e, ChooseByNameModel model, final GotoActionCallback callback) { showNavigationPopup(e, model, callback, true); } diff --git a/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java b/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java index fd8b7230f93e..a0ae7100d254 100644 --- a/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java +++ b/platform/lang-impl/src/com/intellij/ide/actions/SearchEverywhereAction.java @@ -372,11 +372,8 @@ public class SearchEverywhereAction extends AnAction implements CustomComponentA mySkipFocusGain = false; return; } - String text = ""; - if (myEditor != null) { - text = myEditor.getSelectionModel().getSelectedText(); - text = text == null ? "" : text.trim(); - } + String text = GotoActionBase.getInitialTextForNavigation(myEditor); + text = text != null ? text.trim() : ""; search.setText(text); search.getTextEditor().setForeground(UIUtil.getLabelForeground());