mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-128907 Goto declaration in code fragment opens new editor
This commit is contained in:
+12
-10
@@ -94,7 +94,7 @@ public class GotoDeclarationAction extends BaseCodeInsightAction implements Code
|
||||
return;
|
||||
}
|
||||
}
|
||||
chooseAmbiguousTarget(editor, offset, elements);
|
||||
chooseAmbiguousTarget(editor, offset, elements, file);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -102,7 +102,7 @@ public class GotoDeclarationAction extends BaseCodeInsightAction implements Code
|
||||
PsiElement navElement = element.getNavigationElement();
|
||||
navElement = TargetElementUtil.getInstance().getGotoDeclarationTarget(element, navElement);
|
||||
if (navElement != null) {
|
||||
gotoTargetElement(navElement);
|
||||
gotoTargetElement(navElement, editor, file);
|
||||
}
|
||||
}
|
||||
catch (IndexNotReadyException e) {
|
||||
@@ -121,13 +121,10 @@ public class GotoDeclarationAction extends BaseCodeInsightAction implements Code
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void chooseAmbiguousTarget(final Editor editor, int offset, PsiElement[] elements) {
|
||||
PsiElementProcessor<PsiElement> navigateProcessor = new PsiElementProcessor<PsiElement>() {
|
||||
@Override
|
||||
public boolean execute(@NotNull final PsiElement element) {
|
||||
gotoTargetElement(element);
|
||||
return true;
|
||||
}
|
||||
private static void chooseAmbiguousTarget(final Editor editor, int offset, PsiElement[] elements, PsiFile currentFile) {
|
||||
PsiElementProcessor<PsiElement> navigateProcessor = element -> {
|
||||
gotoTargetElement(element, editor, currentFile);
|
||||
return true;
|
||||
};
|
||||
boolean found =
|
||||
chooseAmbiguousTarget(editor, offset, navigateProcessor, CodeInsightBundle.message("declaration.navigation.title"), elements);
|
||||
@@ -136,7 +133,12 @@ public class GotoDeclarationAction extends BaseCodeInsightAction implements Code
|
||||
}
|
||||
}
|
||||
|
||||
private static void gotoTargetElement(PsiElement element) {
|
||||
private static void gotoTargetElement(@NotNull PsiElement element, @NotNull Editor currentEditor, @NotNull PsiFile currentFile) {
|
||||
if (element.getContainingFile() == currentFile) {
|
||||
currentEditor.getCaretModel().moveToOffset(element.getTextOffset());
|
||||
return;
|
||||
}
|
||||
|
||||
Navigatable navigatable = element instanceof Navigatable ? (Navigatable)element : EditSourceUtil.getDescriptor(element);
|
||||
if (navigatable != null && navigatable.canNavigate()) {
|
||||
navigatable.navigate(true);
|
||||
|
||||
Reference in New Issue
Block a user