same policy for choosing selected text editor suitable for navigation

This commit is contained in:
Maxim.Mossienko
2016-11-23 16:05:34 +01:00
parent 35445d8587
commit 88c77f257f
2 changed files with 15 additions and 12 deletions
@@ -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 <T> void showNavigationPopup(AnActionEvent e, ChooseByNameModel model, final GotoActionCallback<T> callback) {
showNavigationPopup(e, model, callback, true);
}
@@ -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());