Home Download Buy Blog Forum Support

Cursor position

Cursor position

Postby ostinelli on Sun Sep 30, 2012 1:55 am

Is it possible to position a cursor at a specific line?

I've checked out docs but I don't seem to understand how to do this.

Thank you,

r.
ostinelli
 
Posts: 15
Joined: Thu Apr 12, 2012 4:50 am

Re: Cursor position

Postby quarnster on Sun Sep 30, 2012 6:40 am

Menu item: Goto->Line.
Key binding: ctrl+g
quarnster
 
Posts: 389
Joined: Tue Nov 29, 2011 11:34 am

Re: Cursor position

Postby ostinelli on Sun Sep 30, 2012 5:35 pm

quarnster wrote:Menu item: Goto->Line.
Key binding: ctrl+g

this being a forum on 'plugin development' I would have believed that it was clear I was looking for a programmatic solution :)

you did give me a pointer though, and in case anyone wonders here's the relative piece of code out of sublime plugin default's folder:

Code: Select all
class GotoLineCommand(sublime_plugin.TextCommand):

    def run(self, edit, line):
        # Convert from 1 based to a 0 based line number
        line = int(line) - 1

        # Negative line numbers count from the end of the buffer
        if line < 0:
            lines, _ = self.view.rowcol(self.view.size())
            line = lines + line + 1

        pt = self.view.text_point(line, 0)

        self.view.sel().clear()
        self.view.sel().add(sublime.Region(pt))

        self.view.show(pt)


r.
ostinelli
 
Posts: 15
Joined: Thu Apr 12, 2012 4:50 am


Return to Plugin Development

Who is online

Users browsing this forum: MarcusF and 5 guests