sublime_text icon indicating copy to clipboard operation
sublime_text copied to clipboard

Goto Definition does not reuse tabs in other groups

Open jimlawton opened this issue 9 years ago • 13 comments

I use a 2-group setup, generally with library code in the right-hand group. Previously, "Goto Definition" would jump to the implementation in the other group if I already had a tab for the module there, or otherwise open a new tab in the current group.

Now, however, (and for the last month or more), "Goto Definition" always opens the destination in a new tab in the current group.

Steps to reproduce:

  1. Set up a 2-group (pane) session in ST.
  2. Open a file with the function definition in one of the groups (Group 1).
  3. Open a file with code calling the function in the other group (Group 2).
  4. In the latter file, right-click on the function name, and "Goto Definition".

Expected result: the cursor jumps to the function definition in Group 1. Actual result: the cursor jumps to the function definition in a new tab in Group 2.

Details:

  • Build: 3084
  • Channel: dev
  • OS: Linux (Ubuntu 14.04, x64)

jimlawton avatar Apr 20 '15 13:04 jimlawton

This issue was moved to SublimeTextIssues/DefaultPackages#121

FichteFoll avatar Apr 20 '15 21:04 FichteFoll

@FichteFoll commented on 20 Apr 2015:

This issue is a bit tricky. I also noticed this, but I thought about whether I would normally want to open the definition in an open view or in its own view. Usually it would be the 'own view'.

However, currently ST does neither because it will focus and scroll existing views iff they are in the same group as the quick panel.

Imo it could be done that shift+enter would always open the definition in a new view while normal enter would focus and scroll the existing view, regardless of group position. It would look weird with the preview however. That could be either in the same group as the panel, which is direct feedback to the user but has the weird jumping in case you use "enter", or it could be focusing the views in a different group if they exist, which will then jump around during preview.

FichteFoll avatar Apr 28 '16 13:04 FichteFoll

@jimlawton commented on 20 Apr 2015:

Which package controls this behaviour?

FichteFoll avatar Apr 28 '16 13:04 FichteFoll

@FichteFoll commented on 20 Apr 2015:

The Default package. Refer to Default/symbol.py.

FichteFoll avatar Apr 28 '16 13:04 FichteFoll

@nathikazad commented on 3 Jul 2015:

Would really appreciate this feature. For instance referencing the same file multiple times opens too many tabs.

FichteFoll avatar Apr 28 '16 13:04 FichteFoll

@SCdF commented on 2 Oct 2015:

I know we're not big fans of "me too" style comments, but I would appreciate a feature that disabled the current way this works and reuses open editors already. My standard workflow is 1/3rd terminal, 2/3 ST3 with two panes, prod code in the first and test code in the second. It's frustrating to goto defintion in a test and have it not jump to the already open code editor in the prod code pane.

FichteFoll avatar Apr 28 '16 13:04 FichteFoll

As @keith-hall suggested on the forum, the fix is the following: just remove the | sublime.FORCE_GROUP (from Default/symbol.py, line 57 in ST3b3126).

VipSaran avatar Oct 06 '16 14:10 VipSaran

It does not work for me :-(

Starli0n avatar Mar 21 '17 14:03 Starli0n

Actually, it was not enough.

I replace from Default/symbol.py, line 57 in ST3b3126.

def open_location(window, l):
    fname, display_fname, rowcol = l
    row, col = rowcol

    window.open_file(
        fname + ":" + str(row) + ":" + str(col),
        sublime.ENCODED_POSITION | sublime.FORCE_GROUP)

by

def open_location(window, l):
    fname, display_fname, rowcol = l
    row, col = rowcol

    view = window.find_open_file(fname)
    if view:
        if view.is_primary():
            window.focus_view(view)
        else:
            view.close() # Preview related to the QuickPanel

    window.open_file(
        fname + ":" + str(row) + ":" + str(col),
        sublime.ENCODED_POSITION)

Some explanations:

  • window.find_open_file(fname) seems to always return a valid view which comes from either:
    • a view already opened
    • OR the preview of the QuickPanel
  • if this view is NOT a primary one, it means that the view is already opened in another group
    • So close it

After it is a bit tricky

  • if the view is a primary one it means that
    • the view is within the current group
    • OR the view is already opened in a prior group
    • so set the focus on it

Finally, open the file accordingly to the col and row and do not force the group with sublime.FORCE_GROUP :-)

Starli0n avatar Mar 21 '17 15:03 Starli0n

And if you want to remove the current file from the QuickPanel Selection, add those lines:

https://github.com/Starli0n/F_SublimeDefault/blob/master/symbol.py#L48-L51

Starli0n avatar Mar 22 '17 10:03 Starli0n

Now, however, (and for the last month or more), "Goto Definition" always opens the destination in a new tab in the current group.

I like this new behavior. Please, do not change it. If so, add a setting so I can have it back!

evandrocoan avatar Aug 14 '19 01:08 evandrocoan

For my purposes https://github.com/SublimeTextIssues/Core/issues/813#issuecomment-251981350 by @VipSaran was enough to restore the behavior to how it formerly worked for me.

Thank you! This was driving me nuts.

rpbaptist avatar Aug 15 '19 11:08 rpbaptist

Hmmm ... it isn't clear to me what the fixes here are suggesting and how to edit Default/symbol.py.

I’m on ST4 (4136) BTW … does this change things?

I can extract the file with PackageResource but as for actually altering the code that gets run by Sublime … that escapes me as it’s not clear where the file is actually coming from and where to save it to.

maegul avatar Oct 06 '22 06:10 maegul

@maegul without knowing if you are still looking for a way to fix this, here is what I did on my Windows machine: go to your sublime text installation folder, there is a Default.sublime-package file under the Packages folder there. It's a zip archive, I've opened it with 7-zip. Inside you'll find symbol.py. Take it out of the archive, open it in ST, comment out all the FORCE_GROUP flags (there are 3 I think), save it, put it back in the Default.sublime-package overwriting the default version. Restart ST.

If you are using LSP and it's lsp_symbol_definition keybinding, that command also has a force_group argument, set that to false in your keybinding settings.

ssoher avatar Dec 23 '22 18:12 ssoher