mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-297124 diff: prefer code navigation inside active diff editor
Fix "Jump to Source" from diff in "Local Changes" - it should navigate to the main editor. Fix regression after d366a295b5ccd07d2df8f01b9ccba7c1b669d4b3 GitOrigin-RevId: 2902aace9c5ded1ecf0ead81eff3f5359d013544
This commit is contained in:
committed by
intellij-monorepo-bot
parent
65e5db97fa
commit
9ceaf5b931
@@ -10,6 +10,8 @@ import com.intellij.ide.actions.EditSourceAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataKey;
|
||||
import com.intellij.openapi.actionSystem.ex.ActionUtil;
|
||||
import com.intellij.openapi.fileEditor.FileNavigator;
|
||||
import com.intellij.openapi.fileEditor.FileNavigatorImpl;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.pom.Navigatable;
|
||||
@@ -76,12 +78,11 @@ public class OpenInEditorAction extends EditSourceAction implements DumbAware {
|
||||
}
|
||||
|
||||
public void openEditor(@NotNull Project project, Navigatable @NotNull [] navigatables) {
|
||||
FileNavigatorImpl fileNavigator = (FileNavigatorImpl)FileNavigator.getInstance();
|
||||
|
||||
boolean success = false;
|
||||
for (Navigatable navigatable : navigatables) {
|
||||
if (navigatable.canNavigate()) {
|
||||
navigatable.navigate(true);
|
||||
success = true;
|
||||
}
|
||||
success |= fileNavigator.navigateIgnoringContextEditor(navigatable);
|
||||
}
|
||||
if (success) onAfterEditorOpened();
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.Navigatable;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
@@ -21,6 +23,8 @@ import java.util.List;
|
||||
import static com.intellij.openapi.fileEditor.OpenFileDescriptor.unfoldCurrentLine;
|
||||
|
||||
public class FileNavigatorImpl implements FileNavigator {
|
||||
private final ThreadLocal<Boolean> myIgnoreContextEditor = new ThreadLocal<>();
|
||||
|
||||
@Override
|
||||
public boolean canNavigate(@NotNull OpenFileDescriptor descriptor) {
|
||||
VirtualFile file = descriptor.getFile();
|
||||
@@ -79,6 +83,7 @@ public class FileNavigatorImpl implements FileNavigator {
|
||||
}
|
||||
|
||||
private boolean navigateInRequestedEditor(@NotNull OpenFileDescriptor descriptor) {
|
||||
if (myIgnoreContextEditor.get() == Boolean.TRUE) return false;
|
||||
@SuppressWarnings("deprecation") DataContext ctx = DataManager.getInstance().getDataContext();
|
||||
Editor e = OpenFileDescriptor.NAVIGATE_IN_EDITOR.getData(ctx);
|
||||
if (e == null) return false;
|
||||
@@ -103,4 +108,17 @@ public class FileNavigatorImpl implements FileNavigator {
|
||||
}
|
||||
return !editors.isEmpty();
|
||||
}
|
||||
|
||||
@ApiStatus.Experimental
|
||||
public boolean navigateIgnoringContextEditor(@NotNull Navigatable navigatable) {
|
||||
if (!navigatable.canNavigate()) return false;
|
||||
myIgnoreContextEditor.set(Boolean.TRUE);
|
||||
try {
|
||||
navigatable.navigate(true);
|
||||
}
|
||||
finally {
|
||||
myIgnoreContextEditor.set(null);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user