sublime_text
sublime_text copied to clipboard
Goto Definition does not reuse tabs in other groups
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:
- Set up a 2-group (pane) session in ST.
- Open a file with the function definition in one of the groups (Group 1).
- Open a file with code calling the function in the other group (Group 2).
- 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)
This issue was moved to SublimeTextIssues/DefaultPackages#121
@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.
@jimlawton commented on 20 Apr 2015:
Which package controls this behaviour?
@FichteFoll commented on 20 Apr 2015:
The Default package. Refer to Default/symbol.py
.
@nathikazad commented on 3 Jul 2015:
Would really appreciate this feature. For instance referencing the same file multiple times opens too many tabs.
@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.
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).
It does not work for me :-(
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
:-)
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
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!
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.
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 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.