Home Download Buy Blog Forum Support

Page-up/down in autocomplete popup and command palette?

Page-up/down in autocomplete popup and command palette?

Postby highend on Fri Aug 16, 2013 11:16 am

Is there a way to use the pageup / pagedown keys to move the scrollbar by "pages" in an autocomplete popup or the command palette?

I've tried to setup a keybinding for it, but instead of the content in the popup, the cursor in the buffer is moved...

Code: Select all
   { "keys": ["pagedown"], "command": "scroll_lines", "args": {"amount": 3.0 }, "context":
      [
         { "key": "auto_complete_visible", "operator": "equal", "operand": true }
      ]
   },


Are there any other working methods or at least a plugin that could help?
highend
 
Posts: 93
Joined: Fri Jan 20, 2012 2:47 pm

Re: Page-up/down in autocomplete popup and command palette?

Postby highend on Sun Aug 18, 2013 11:09 am

Not possible?
highend
 
Posts: 93
Joined: Fri Jan 20, 2012 2:47 pm

Re: Page-up/down in autocomplete popup and command palette?

Postby Veedrac on Sun Aug 18, 2013 5:48 pm

highend wrote:Not possible?


No, it is.

Since I'm too lazy to see if there's a proper way of doing this...

Use

Code: Select all
"""
Based off of http://www.sublimetext.com/forum/viewtopic.php?t=8677,
and I see no license there so AFAIK you need to ask there any time you
even think about doing anything to this source. Or you can just duck
and hope, like I have.

My changes are hereby released completely and irrevocably into the
Public Domain. THE ORIGINAL CODE MAY NOT BE PUBLIC DOMAIN AND THUS
THIS CODE SHOULD NOT BE THOUGHT OF AS PUBLIC DOMAIN.

- Joshua Landau <joshua@landau.ws>
"""

import sublime, sublime_plugin

class RunMultipleCommandsCommand(sublime_plugin.TextCommand):
   """
   "args" for this takes _either_ "command" or "commands", where
   "commands" is a list of what "command" takes. "args" also takes
   an optional "times" parameter, and just runs itself that many
   times.

   "command" takes either a string (such as "store_selections") or
   a dictionary with a "command" attribute, an optional "args"
   attribute and an optional "context" attribute.

   In the above, the "command" and "args" attribute are as expected,
   and the "context" attribute is one of "window", "app" and "text".
   """
   def run(self, edit, commands=None, command=None, times=1):
      if commands is None:
         commands = [command] if command is not None else []

      for _ in range(times):
         for command in commands:
            self.exec_command(command)


   def exec_command(self, command):
      # Shortcut for simple command described by one string
      if not "command" in command:
         if isinstance(command, str):
            command = {"command": command}

         else:
            raise ValueError("No command name provided.")

      args = command.get("args")

      contexts = {"window": self.view.window(), "app": sublime, "text": self.view}
      context = contexts[command.get("context", "text")]

      context.run_command(command["command"], args)


as a plugin and then use this key-binding:

Code: Select all
   {
      "keys": ["pageup"],
      "command": "run_multiple_commands",
      "args": { "command": { "command": "move", "args": {"by": "lines", "forward": false } }, "times": 8 },
      "context": [
         { "key": "auto_complete_visible", "operator": "equal", "operand": true }
      ]
   },
   {
      "keys": ["pagedown"],
      "command": "run_multiple_commands",
      "args": { "command": { "command": "move", "args": {"by": "lines", "forward": true  } }, "times": 8 },
      "context": [
         { "key": "auto_complete_visible", "operator": "equal", "operand": true }
      ]
   },


This has unfortunate characteristics if you "run out" of autocompletes (the cursor just keeps moving when in the real buffer) but I'm not going to solve that right now...
Veedrac
 
Posts: 19
Joined: Sun Aug 18, 2013 4:16 pm

Re: Page-up/down in autocomplete popup and command palette?

Postby highend on Sun Aug 18, 2013 6:54 pm

Thank you Veedrac!

Unfortunately I get an error in the console, after pressing pagedown in an autocomplete popup (with enough entries, that pagedown "makes sense"):

Code: Select all
command: run_multiple_commands {"command": {"args": {"by": "lines", "forward": true}, "command": "move"}, "times": 8}
Traceback (most recent call last):
  File "D:\Tools\Sublime Text\sublime_plugin.py", line 543, in run_
    return self.run(edit, **args)
TypeError: run() got an unexpected keyword argument 'times'
highend
 
Posts: 93
Joined: Fri Jan 20, 2012 2:47 pm

Re: Page-up/down in autocomplete popup and command palette?

Postby Veedrac on Mon Aug 19, 2013 7:39 pm

highend wrote:
Code: Select all
File "D:\Tools\Sublime Text\sublime_plugin.py", line 543, in run_


What is this file?
Veedrac
 
Posts: 19
Joined: Sun Aug 18, 2013 4:16 pm

Re: Page-up/down in autocomplete popup and command palette?

Postby highend on Mon Aug 19, 2013 8:10 pm

It exists on every installation / portable version of ST3 (under Windows) and contains definitions for api commands.

Line 543 is:
Code: Select all
return self.run(edit, **args)


Context:
Code: Select all
class TextCommand(Command):
    def __init__(self, view):
        self.view = view

    def run_(self, edit_token, args):
        if args:
            if 'event' in args:
                del args['event']

            edit = self.view.begin_edit(edit_token, self.name(), args)
            try:
                return self.run(edit, **args)
            finally:
                self.view.end_edit(edit)
        else:
            edit = self.view.begin_edit(edit_token, self.name())
            try:
                return self.run(edit)
            finally:
                self.view.end_edit(edit)

    def run(self, edit):
        pass
highend
 
Posts: 93
Joined: Fri Jan 20, 2012 2:47 pm

Re: Page-up/down in autocomplete popup and command palette?

Postby Veedrac on Mon Aug 19, 2013 10:20 pm

I think I know what's happened - you haven't installed the plugin I said to.

If you do "Tools > New Plugin..." and replace the text with the below and then save to the default place with a good name, it should work.

Code: Select all
"""
Based off of http://www.sublimetext.com/forum/viewtopic.php?t=8677,
and I see no license there so AFAIK you need to ask there any time you
even think about doing anything to this source. Or you can just duck
and hope, like I have.

My changes are hereby released completely and irrevocably into the
Public Domain. THE ORIGINAL CODE MAY NOT BE PUBLIC DOMAIN AND THUS
THIS CODE SHOULD NOT BE THOUGHT OF AS PUBLIC DOMAIN.

- Joshua Landau <joshua@landau.ws>
"""

import sublime, sublime_plugin

class RunMultipleCommandsCommand(sublime_plugin.TextCommand):
   """
   "args" for this takes _either_ "command" or "commands", where
   "commands" is a list of what "command" takes. "args" also takes
   an optional "times" parameter, and just runs itself that many
   times.

   "command" takes either a string (such as "store_selections") or
   a dictionary with a "command" attribute, an optional "args"
   attribute and an optional "context" attribute.

   In the above, the "command" and "args" attribute are as expected,
   and the "context" attribute is one of "window", "app" and "text".
   """
   def run(self, edit, commands=None, command=None, times=1):
      if commands is None:
         commands = [command] if command is not None else []

      for _ in range(times):
         for command in commands:
            self.exec_command(command)


   def exec_command(self, command):
      # Shortcut for simple command described by one string
      if not "command" in command:
         if isinstance(command, str):
            command = {"command": command}

         else:
            raise ValueError("No command name provided.")

      args = command.get("args")

      contexts = {"window": self.view.window(), "app": sublime, "text": self.view}
      context = contexts[command.get("context", "text")]

      context.run_command(command["command"], args)
Veedrac
 
Posts: 19
Joined: Sun Aug 18, 2013 4:16 pm

Re: Page-up/down in autocomplete popup and command palette?

Postby highend on Mon Aug 19, 2013 10:57 pm

I think I know what's happened - you haven't installed the plugin I said to.


I had... Saved it in the packages\user folder as "ScrollInPopup.py". Restarted ST3 afterwards and it was loaded successfully but I got nothing apart from that error that I posted.

I've just deleted the .py file and tried it again. Different name ("PageDownInPopup.py"). Restart and... it works...

I'm unable to explain this behavior^^

Thank you Veedrac.
highend
 
Posts: 93
Joined: Fri Jan 20, 2012 2:47 pm


Return to Technical Support

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 7 guests

cron