Gary
Gary

Reputation: 6667

Can IntelliJ "navigate declaration" be configured to honor split editors

I use "Navigate-Declaration" all the time in IntelliJ IDEA. I would like to configure it to behave slightly differently when split editors are used.

The basic use case is simple:

  1. Start using IntelliJ IDEA with only one class open, call it "ClassA". ClassA has a reference to ClassB.
  2. Use "Navigate->Declaration" to navigate to ClassB. IntelliJ will open a new tab for ClassB and show this class in the editor window. ClassA is no longer visible in the editor.
  3. Use "Navigate->Back". ClassA tab is now visible again in the one editor window. With keyboard shorcuts, this can be a very quick way to navigate code.

However, things behave strange when using a split window:

  1. Open several class files in the editor window.
  2. Split the window (Tools->Editor tabs->split vertically).
  3. In the left side tab group, navigate to an interesting code section, i.e. one that we want to refer to for a while.
  4. In the right side tab group, position the cursor on a class being referred to and select Navigate->Declaration.

If this class is already open in the left side tab group, IntelliJ will bring that tab forward in the left editor, replacing the one class I selected for viewing. However, if the class is not already open in any tab group, IntelliJ will open the file on the right side tab group. This is essentially the same as what happens when a split editor is not used.

Even worse, "Navigate->Back" action will now indeed navigate back to the original class in the right side, but does not change anything on the left side, i.e. that one class that I intended to refer to for a while is not visible.

So the behavior of the "Navigate->Open Declaration" action is dependent on the state of IntelliJ itself, and not on my intention. I do not want intelliJ to arbitrarily decide which split window to show a file in. I would rather that it only open the declaration in the tab group where the cursor curently is.

What would be really nice is an action like "Navigate->open declaration in current tab group". Does this exist? Can a plugin be created for this?

Upvotes: 8

Views: 1530

Answers (1)

Justin
Justin

Reputation: 4054

I have the same issue but I have a workaround that works for most of my cases:

In Settings > Editor > General > Editor Tabs, and under Closing Policy, I set the tab limit to 1. This enforces a single tab per split, which prevents a hidden tab in another split from opening when you navigate to a symbol within it. When you go to declaration, if the destination file is in a split, it will go there, and if it doesn't exist, it will replace the tab in your split. This works for most cases, it might get trickier if you don't want intellij to change the part of the file you're looking at in a split, but for most cases it works.

(Also I don't use tabs generally to remember which files, I usually use the Recent Files window to navigate).

Upvotes: 1

Related Questions