Home Download Buy Blog Forum Support

[ solved ] Move the cursor on click

[ solved ] Move the cursor on click

Postby greg on Thu Sep 27, 2012 11:40 pm

I've remap a mouse click like this:

{ "button": "button1", "modifiers": ["alt"], "command": "navigate_to_definition" }

So I can alt-click a class name to jump to its definition. However that "alt+click" doesn't move the cursor, so I have to first click (no modifiers) on the word, then alt+click it.

Is there a way (with a macro or something) to have it done with a single alt+click?

TIA
Last edited by greg on Tue Oct 02, 2012 3:52 pm, edited 1 time in total.
greg
 
Posts: 34
Joined: Fri Sep 14, 2012 10:00 am

Re: Move the cursor on click

Postby adzenith on Thu Sep 27, 2012 11:48 pm

You can make a plugin that looks something like this (untested). drag_select is the default mouse behaviour, and this plugin calls that and then navigate_to_definition.

Code: Select all
class navigate(sublime_plugin.TextCommand):
   #note the underscore
   def run_(self, args):
      self.view.run_command("drag_select", args)
      self.view.run_command("navigate_to_definition", args)
adzenith
 
Posts: 1214
Joined: Mon Oct 19, 2009 9:12 pm

Re: Move the cursor on click

Postby greg on Sat Sep 29, 2012 10:28 am

It's working, I am impressed!

What's the underscore for?
greg
 
Posts: 34
Joined: Fri Sep 14, 2012 10:00 am

Re: Move the cursor on click

Postby adzenith on Tue Oct 02, 2012 12:06 am

When you call a TextCommand, it calls the run_ function. This function strips out some of the arguments that drag_select relies on, and then calls run (no underscore). By overloading run_ instead of run we can keep those extra arguments and pass them to drag_select.
adzenith
 
Posts: 1214
Joined: Mon Oct 19, 2009 9:12 pm

Re: Move the cursor on click

Postby greg on Tue Oct 02, 2012 3:51 pm

Very clever, I'll remember that!

Thanks!
greg
 
Posts: 34
Joined: Fri Sep 14, 2012 10:00 am


Return to General Discussion

Who is online

Users browsing this forum: eof, Exabot [Bot], Google [Bot] and 33 guests