Sublime Forum

[ solved ] Move the cursor on click

#1

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

0 Likes

#2

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.

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)

0 Likes

#3

It’s working, I am impressed!

What’s the underscore for?

0 Likes

#4

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.

0 Likes

#5

Very clever, I’ll remember that!

Thanks!

0 Likes