Skip to content

Instantly share code, notes, and snippets.

@chendesheng
Created January 9, 2023 14:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chendesheng/99e673571c8dd19ddf9557a5ff6d2bcc to your computer and use it in GitHub Desktop.
Save chendesheng/99e673571c8dd19ddf9557a5ff6d2bcc to your computer and use it in GitHub Desktop.
Sublime Text jump to file from Find Results using keyboard
import sublime
import sublime_plugin
class DoubleClickAtCaretCommand(sublime_plugin.TextCommand):
def run(self, edit, **kwargs):
view = self.view
cursor = view.sel()[0]
(rg, scope) = view.extract_tokens_with_scopes(view.line(cursor))[1]
if 'line-number.match.find-in-files' in scope:
linenum = view.substr(rg)
colnum = cursor.a - rg.b - 1
# print(linenum)
regions = view.symbol_regions()
regions.sort(key=lambda s: s.region.a, reverse=True)
for symbol_region in regions:
if symbol_region.region.b < cursor.a:
file_path = symbol_region.name
view.window().open_file(
"{}:{}:{}".format(file_path, linenum, colnum),
sublime.ENCODED_POSITION)
# print(file_path)
break
@joshuapinter
Copy link

WORKS BRILLIANTLY! THANK YOU FOR UPDATING THIS!

After upgrading my Sublime Text to the latest build, this critical feature/script stopped working. This did the trick and got my workflow back up and running. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment