lol I initially wrote this for a non-programming related project, but it’s turned out so useful, I always reach for it. I find that if I need to navigate to some place, I can almost always remember/reconstruct what the line roughly is like, so this procedure actually comes quite natural to me.
This is the code, some chunk of which is lifted out of symbol.py (seriously, if someone better versed with python and/or sublime plugin development should write a better version, preferably allowing searching all lines in all open files)
import sublime
import sublime_plugin
class NavigateToLineViaQuickPanel(sublime_plugin.WindowCommand):
def run(self):
v = self.window.active_view()
osp(v)
def osp(view):
def highlight_entry(x):
jojo = sublime.active_window().active_view().file_name()
window = sublime.active_window()
window.open_file(
jojo + ":" + str(x+1),
group=window.active_group(),
flags=sublime.TRANSIENT | sublime.ENCODED_POSITION | sublime.FORCE_GROUP)
def select_entry(index, orig_view, orig_sel):
if (index==-1):
if orig_view:
orig_view.sel().clear()
orig_view.sel().add_all(orig_sel)
orig_view.window().focus_view(orig_view)
orig_view.show(orig_sel[0])
else:
view.run_command("goto_line", {"line": index+1})
orig_sel = None
if view:
orig_sel = [r for r in view.sel()]
j = view.lines(sublime.Region(0, view.size()))
sublime.active_window().show_quick_panel(
# [[view.substr(y),str(ind)] for ind, y in enumerate(j)],
[view.substr(i) for i in j],
on_select=lambda x: select_entry(x, view, orig_sel),
on_highlight=lambda x: highlight_entry(x),
flags=sublime.KEEP_OPEN_ON_FOCUS_LOST | sublime.MONOSPACE_FONT)