Sublime Forum

Double click and Find-in-Files

#1

Hello all,

I have written numerous plugins that launch their own result views from which you can double to navigate to a file in the project. Each results view has different logic for jumping to the file, so I ended up writing yet another plugin to handle all mouse double clicks. For example, my custom double click plugin looks like this:

class CustomMouseclickCommand(sublime.plugin.TextCommand): def run_(self, view, args): if self.view.name().startswith ("View1): self.view.run_command("my_command1) return if self.view.name().startswith ("View2): self.view.run_command("my_command2") return if self.view.name().startswith ("View3): self.view.run_command("my_command3") return if self.view.name().startswith ("Find Results): self.view.run_command("????") <--------- return else: self.view.run_command('expand_selection', {'to': 'word'})

I also have the following mouse click command:
[ { "button": "button1", "count": 2, "press_command": "custom_mouseclick", "press_args": {"key": "selector", "operand": {"by": "words"}}, } ]

I want to know the command and args that the find-in-files results view calls to jump to the file so that I can insert that command into my code above with the arrow. I tried the default mouse double click command (drag_select, by:words), and that is not working. Any help in this direction is most appreciated.

Thanks,
Rajah

0 Likes

#2

Turning on command logging with sublime.log_commands(True) in the console seems to indicate that it’s using drag_select the way you thought it might be.

The command gets an extra event argument that tells it where the event happened, so perhaps the reason it’s not working for you is that without the event, it doesn’t know where you double clicked…

1 Like

#3

further to OdatNurd’s helpful advice, as per the documentation, you probably want to add a want_event() method to your class that returns True, and that pass that event to the drag_select command.

0 Likes

#4

Thanks @OdatNurd, worked like a charm. The sublime.log_commands() tip is very useful, I did not know about that.

0 Likes

#5

Hi @kingkeith, I overrode the want_event() method in my class, but it not seem to make any difference. Not sure what I was missing. In any case, this is my final statement that makes everything work.

self.view.run_command('drag_select', {"by":"words", "event": args['event']})

Thank you very much for your time and tips.

0 Likes