Sublime Forum

Can I make double click do normal behaviour + my own

#1

Hi,
Default behavior on double clicking is highlighting the word and it’s other instances in the file (and I use it a lot) and would not want to be without it.
BUT, now I’m creating a plugin where I want the double click behave differently, but only in one special buffer.

So I have a plugin like:

class MySpecialDoubleclickCommand(sublime_plugin.TextCommand):
  def run(self, edit):
    if self.view.name() == "mySpecialBuffer":
      self.doMyStuff()

which runs fine…

But when I assign it to the double click it just calls my code. Is there a way to make it call my plugin and also the default behavior one?

This is how I assign the double click in the Default (Windows).sublime-mousemap :

{ "button": "button1", "count": 2, "command": "my_special_doubleclick" }

I know I can assign modifiers like ctrl+alt, but I rather just have the double click…

thanks in advance
Dean

1 Like

Can we please get context support for mousemap files?
#2

Theoretically (I haven’t checked that yet for double click) by making use of run_ you can get hold of the mouse click event and then pass it to the default handler (drag_select - see the default mousemap for the details).

Here’s an example: [1] custom command that overrides run_, [2] mousemap for subclasses of that command, which specifies the system command that gets overriden and its arguments, so that the custom command can call it.

By the way, please, let me know how it goes. I’m also going to override double-click to navigate the stack trace during debugging. Would be great if this sketch works.

[1] github.com/sublimescala/sublime … me.py#L190
[2] github.com/sublimescala/sublime … e-mousemap

1 Like

#3

Thanks, this worked like a charm! :smile:

The mouse overwrite ended as:

{
  "button": "button1", "count": 2,
  "press_command": "my_special_doubleclick",
  "press_args": {"command": "drag_select", "args": {"by": "words"}}
}

And my plugin is:

class MySpecialDoubleclickCommand(sublime_plugin.TextCommand):
  def run_(self, args):
    if self.view.name() == "mySpecialBuffer":
      self.doMyStuff()
    else:
      system_command = args"command"] if "command" in args else None
      if system_command:
        system_args = dict({"event": args"event"]}.items() + args"args"].items())
        self.view.run_command(system_command, system_args)

thanks again for your quick reply
Dean

0 Likes

#4

Aforementioned code apparently works only in ST2. I would like to get this functionality working in ST3 as well. Python 3.x treats dictionaries differently than 2.x so I changed the addition to union to achieve the same dictionary as a result.

However, my attempts to call the run_command(system_command, system_args) have been unsuccessful. I keep getting the following error:

  File "C:\Program Files\Sublime Text 3\sublime.py", line 607, in run_command
    sublime_api.view_run_command(self.view_id, cmd, args)
TypeError: Value required

Any help would be appreciated.

0 Likes

#5

Scam, I did a little digging on bringing that broken dictionary syntax into Python 3, and here’s what I got:

stackoverflow.com/questions/1336 … dict-items

Turns out we need to replace the + operator with .update()

To put it in context, here’s what it looks like, using the example from earlier in this thread:

class MySpecialDoubleclickCommand(sublime_plugin.TextCommand):
    def run_(self, view, args):
        if self.view.name() == "mySpecialBuffer":
            self.doMyStuff()
        else:
            system_command = args"command"] if "command" in args else None
            if system_command:
                system_args = dict({"event": args"event"]}.items())
                system_args.update(dict(args"args"].items()))
                self.view.run_command(system_command, system_args)

Thanks to everyone in this thread for the springboard - I hope the fix I found works for you too.

0 Likes