Sublime Forum

Custom action on mouse double click

#1

Hi ST users,

I have bound mouse double click to a custom function as below.
> [
> {
> “button”: “button1”, “count”: 2,
> “command”: “custom_mouseclick”,
> },
> ]

My custom_mouseclick.py is as below.

class CustomMouseclickCommand(sublime_plugin.TextCommand):
    def run_(self, view, args):
        if self.view.name().startswith("name1"):
            self.view.run_command('cmd1')
            return

        if self.view.name().startswith("name2"):
            self.view.run_command('cmd2)
            return
       self.view.run_command('drag_select', {'by' : 'words'})

The custom mouse actions get called when I am in the appropriate views, however, the default action (drag_select) is not working in other views. What am I missing?

Thanks,
Rajah

0 Likes

#2

The drag_select command is a special command that is seemlingly only available in mouse maps. I do not know of a way to invoke it manually.

Besides, there should be a colon between 'by' and 'words'.

In this case, you can just use the expand_selection command however:

view.run_command("expand_selection", {"to": "word"})
0 Likes

#4

Works like a charm, thanks.

0 Likes