IDEA-184989 Navigating from preview should keep the cursor position

This commit is contained in:
Vassiliy.Kudryashov
2018-01-19 23:44:56 +03:00
parent 3ee891791a
commit 4856c80ce9
2 changed files with 29 additions and 7 deletions
@@ -49,6 +49,7 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.openapi.wm.impl.IdeFrameImpl;
import com.intellij.pom.Navigatable;
import com.intellij.psi.PsiElement;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.GlobalSearchScopeUtil;
@@ -66,6 +67,7 @@ import com.intellij.usages.UsageViewPresentation;
import com.intellij.usages.impl.UsagePreviewPanel;
import com.intellij.util.Alarm;
import com.intellij.util.ArrayUtil;
import com.intellij.util.OpenSourceUtil;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.*;
@@ -511,13 +513,13 @@ public class FindPopupPanel extends JBPanel implements FindUI {
myOkActionListener.actionPerformed(null);
}
else {
navigateToSelectedUsage();
navigateToSelectedUsage(null);
}
}
}.registerCustomShortcutSet(new CustomShortcutSet(ENTER), this);
DumbAwareAction.create(e -> {
if (enterAsOK) {
navigateToSelectedUsage();
navigateToSelectedUsage(null);
}
else {
myOkActionListener.actionPerformed(null);
@@ -537,7 +539,7 @@ public class FindPopupPanel extends JBPanel implements FindUI {
new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
navigateToSelectedUsage();
navigateToSelectedUsage(e);
}
}.registerCustomShortcutSet(new CustomShortcutSet(navigationKeyStrokes.toArray(Shortcut.EMPTY_ARRAY)), this);
}
@@ -584,7 +586,7 @@ public class FindPopupPanel extends JBPanel implements FindUI {
@Override
protected boolean onDoubleClick(MouseEvent event) {
if (event.getSource() != myResultsPreviewTable) return false;
navigateToSelectedUsage();
navigateToSelectedUsage(null);
return true;
}
}.installOn(myResultsPreviewTable);
@@ -1245,7 +1247,14 @@ public class FindPopupPanel extends JBPanel implements FindUI {
model.setFileFilter(mask);
}
private void navigateToSelectedUsage() {
private void navigateToSelectedUsage(AnActionEvent e) {
Navigatable[] navigatables = e != null ? e.getData(CommonDataKeys.NAVIGATABLE_ARRAY) : null;
if (navigatables != null) {
myBalloon.cancel();
OpenSourceUtil.navigate(navigatables);
return;
}
Map<Integer, Usage> usages = getSelectedUsages();
if (usages != null) {
myBalloon.cancel();
@@ -20,7 +20,8 @@ import com.intellij.find.FindManager;
import com.intellij.find.FindModel;
import com.intellij.ide.IdeTooltipManager;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.actionSystem.DataProvider;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.*;
@@ -28,8 +29,11 @@ import com.intellij.openapi.editor.colors.EditorColors;
import com.intellij.openapi.editor.colors.EditorColorsManager;
import com.intellij.openapi.editor.event.VisibleAreaEvent;
import com.intellij.openapi.editor.event.VisibleAreaListener;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.openapi.editor.ex.util.EditorUtil;
import com.intellij.openapi.editor.markup.*;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.popup.Balloon;
import com.intellij.openapi.ui.popup.BalloonBuilder;
@@ -38,6 +42,8 @@ import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.pom.Navigatable;
import com.intellij.psi.*;
import com.intellij.ui.Gray;
import com.intellij.ui.JBColor;
@@ -84,9 +90,16 @@ public class UsagePreviewPanel extends UsageContextPanelBase implements DataProv
@Nullable
@Override
public Object getData(@NonNls String dataId) {
if (CommonDataKeys.EDITOR.getName().equals(dataId) && myEditor != null) {
if (CommonDataKeys.EDITOR.is(dataId) && myEditor != null) {
return myEditor;
}
if (CommonDataKeys.NAVIGATABLE_ARRAY.is(dataId) && myEditor instanceof EditorEx) {
LogicalPosition position = myEditor.getCaretModel().getLogicalPosition();
VirtualFile file = FileDocumentManager.getInstance().getFile(myEditor.getDocument());
if (file != null) {
return new Navigatable[] {new OpenFileDescriptor(myProject, file, position.line, position.column)};
}
}
return null;
}