Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 302
Gary Avatar asked Feb 18 '14 19:02

Gary


People also ask

How do I navigate code in IntelliJ?

To navigate backwards, press Ctrl+Alt+Left . To navigate forward, press Ctrl+Alt+Right . To navigate to the last edited location, press Ctrl+Shift+Backspace . To find the current caret location in the editor, press Ctrl+M .

How do I enable editing in IntelliJ?

Code Editing Use the Code Editing page of the Settings/Preferences dialog to configure the general code editing options. Select this checkbox to have IntelliJ IDEA highlight pairs of opening/closing braces when you position the caret right before the opening or right after the closing one.

How do I switch between files in IntelliJ?

The file being edited right now is highlighted. Invoke switcher with hotkey Ctrl+Tab or Ctrl+Shift+Tab. Here's an even more convenient way to jump to any recently opened file: bring up the Recent Files window with Ctrl+E / Cmd E and just type the name of the file you want to navigate to.


1 Answers

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).

like image 183
Justin Avatar answered Oct 12 '22 23:10

Justin