Sublime Forum

Raising a Text Input Handler with a Key binding


I suspect I’ve missed something fundamental here.

I’ve got a TextCommand that uses a TextInputHandler as its input and works fine from the command palette (as it is declared in the sublime-commands file).

How do I call this command with a key binding? When I try to do so I get an error that indicates that the TextCommand's run() function is running before the input() function and the InputHandler it returns. Using print() for debugging more or less confirms this.

This prior thread seems to indicate that what I’m doing should be possible, so I guesseither I’m missing something in my implementation or I’ve run into a bug.

Relevant code extracted below.

class OpenNoteCommand(sublime_plugin.TextCommand):
    def run(self, edit, **kwargs):
        if not kwargs['note_select']:

        open_selected_note(self.view, kwargs['note_select'])

    def input(self, args):
        return NoteSearchInputHandler()

class NoteSearchInputHandler(sublime_plugin.TextInputHandler):

    def placeholder(self) -> str:
        return 'Search query'

    def next_input(self, args):
        return NoteSelectInputHandler(query = args['note_search'])

class NoteSelectInputHandler(sublime_plugin.ListInputHandler):

    def __init__(self, query):

        self.results = sp.check_output([
            ZKL_COM, 'q', query])

    def list_items(self):

        values = get_note_id_title(self.results)
        return values


// commands
{"caption": "Open Note", "command": "open_note"},

// key binding
		"keys": ["super+t"],
		"command": "open_note"



As a follow up I thought I’d put together a simple prototype of what I’m trying to test this.

Plugin code is below. As a command palette command it works fine. The final effect is to print the input values to the console. But when used through a key binding, no input quick panel appears and the print out to the console is an empty dictionary. It’s feeling to me more like a bug now ???

I’m on sublime 4136.

class RandomTestInputCommand(sublime_plugin.TextCommand):
    def run(self, edit, **args):
        print(f'random test command {args}')
    def input(self, args):
        return RandomTestInputHandler()

class RandomTestInputHandler(sublime_plugin.TextInputHandler):

    def next_input(self, args):
        return RandomTestListInputHandler(args['random_test'])

class RandomTestListInputHandler(sublime_plugin.ListInputHandler):
    def __init__(self, word):
        self.list_values = list(word)
    def list_items(self):
        return self.list_values


	{"caption": "Random command test", "command": "random_test_input"},

Result in the console when free text input is “hello” and then from the individual characters in the list input “h” is selected:

random test command {'random_test': 'hello', 'random_test_list': 'h'}

Keybinding config:

		"keys": ["super+k", "t", "i"],
		"command": "random_test_input"

Output to the console (where no input panels appear):

random test command {}


A possible work around used in some of the common built in key-bindings is to use the show_overlay command to bring up the command palette with the required text already entered. The user then only needs to press enter to run the commnd … which is OK i guess.

Example key binding:

		"keys": ["super+k", "t", "i"],
		"command": "show_overlay",
		"args": {"overlay": "command_palette", "text": "random input test"}



What you want is a key binding like the one you specified here, only instead of passing it the text argument, pass it the command argument and specify the name of the command you want it to invoke.

1 Like


Huh! I hope that’s documented somewhere! If not … how did you know?


For future reference, @OdatNurd is talking about something like this (adapted from the keybinding above):

		"keys": ["super+k", "t", "i"],
		"command": "show_overlay",
		"args": {"overlay": "command_palette", "command": "random_test_input"}

1 Like


There’s not any official documentation for any of the commands in Sublime other than their usage in key bindings and in the command palette.

As to how I know that, I can’t say exactly. Could be a key binding or command palette entry that currently exists (not at a PC to check) or failing that if I had to guess it was specifically stated in the discord or on the forum by one of the developers.

Living and breathing Sublime as much as I have for the past 7 years, I’ve amassed somewhat of a knowledge without remembering where it came from. :smiley:

1 Like