Home Download Buy Blog Forum Support

Goto position

Goto position

Postby DigitallyBorn on Tue Jul 02, 2013 4:08 pm

I'm rather surprised that this feature does already exist (or maybe it does, I just can't find documentation for it).

I'd like to move the cursor to a position in the file by byte offset. Anybody who has worked with text-based data files knows that this can be invaluable for debugging code (I'm knee deep in it now).
DigitallyBorn
 
Posts: 1
Joined: Tue Jul 02, 2013 4:07 pm

Re: Goto position

Postby skuroda on Wed Jul 03, 2013 12:59 am

Not built in but you can get that behavior with a plugin.

Code: Select all
import sublime
import sublime_plugin


class GotoPositionCommand(sublime_plugin.WindowCommand):
    def run(self):
        window = self.window
        view = window.active_view()
        self.original_cursors = []
        for cursor in view.sel():
            self.original_cursors.append(cursor)
        window.show_input_panel("Byte Position", "", self.location_update, self.location_update, self.on_cancel)


    def location_update(self, input_text):
        print(input_text)
        window = self.window
        view = window.active_view()
        try:
            location = int(input_text)
        except:
            return

        cursors = view.sel()
        cursors.clear()
        cursors.add(sublime.Region(location, location))
        view.show_at_center(location)

    def on_cancel(self):
        window = self.window
        view = window.active_view()
        view.sel().clear()
        view.sel().add_all(self.original_cursors)
        view.show(view.sel())


Though with multibyte character this will likely have issues.
skuroda
 
Posts: 685
Joined: Fri Oct 05, 2012 8:11 am

Re: Goto position

Postby jfcherng on Tue Jul 01, 2014 8:34 pm

jfcherng
 
Posts: 6
Joined: Thu Jun 05, 2014 2:24 am


Return to Ideas and Feature Requests

Who is online

Users browsing this forum: No registered users and 8 guests