Sublime Forum

Selecting from popup with something else than "enter"?

#1

(First off sorry for my third post of the day. I’ll lay off after this one.)

After selecting a file from the “goto anything” popup window after typing a partial name and using the up and down arrows, I’d like to open the file using another key binding than “enter”. For example, I would like “ctrl+L” to open the currently selected file.

Is this possible?

Or maybe with a plugin?

(The thing is, “ctrl+L” is my “soft newline” command and I use it much more than the “enter” key, actually. So I think “ctrl+L == enter” and I’d like the popup window to think that way too, aha :slight_smile: .)

0 Likes

#2

What did you bind your ctrl+l to?

0 Likes

#3

Hi. I bound ctrl+l to my own command called soft_insert_newline. I put the full implementation of that command down below for reference.

NB: ctrl+l does not seem to be executed when I type it. (It closes the popup window, but does not execute in the currently active view even if, say, the currently active view was the item selected by the popup list.)

code:

def move_to_eol(view, extend=False):
    view.run_command("move_to", {"to": "eol", "extend": extend})

def insert_characters(view, thing):
    view.run_command("insert", {"characters": thing})

def soft_insert_newline(view):
    move_to_eol(view)
    insert_characters(view, '\n')

class SoftInsertNewlineCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        soft_insert_newline(self.view)
0 Likes

#4

In the meanwhile I have succeeded in doing this by taking the following drastic measures:

– use my system keymapper to remap control+l (control-L) system-wide to the ordinary enter key
– use my system keymapper remap standard enter key to shift+enter if sublime text is the current application
– bind ordinary enter to my custom soft_newline command in sublime text IF the popup is not showing
– bind shift+ender to an ordinary newline insertion in sublime text

After all that runaround, it works.

However, I still suspect one might be able to do it without external key remappings, with a keyboard shortcut like this, say:

{ "keys": ["ctrl+l"], "command": "press_enter", "context": [
    { "key": "overlay_visible", "operator": "equal", "operand": true},
]},

Where for the press_enter command I tried this:

class PressEnterCommand(sublime_plugin.TextCommand):
    def run(self, edit):
        insert_characters(self.view, '\n')

This “almost” works in the sense that if I run, say, insert_characters(self.view, 'a') instead of insert_characters(self.view, '\n') it actually inserts an “a” in the popup panel. But somehow the newline “\n” isn’t registered as an “enter” keypress by the panel… :frowning:

0 Likes