prompt-toolkit/python-prompt-toolkit

[bug] (apparently), keybinding for <any> filter is called endlessly without any key typed

Opened this issue · 2 comments

Hi,

am not sure if this is a bug or feature, but the keybinding filtering function is called enndlesly.

I wanted to use it to have an overview of the keybindings and implement a plugin like the nvim "which-key" plugin.

    @Condition
    def unasigned_filter():
        print("filter called")
        return True #does not matter if I return True or False

    @bindings.add("<any>", filter=unasigned_filter)
    def _(event):
        return

thanks
Z

key_processor.py arround line 126
output;

keys (<Keys.CPRResponse: '<cursor-position-response>'>,)
keys (<Keys.CPRResponse: '<cursor-position-response>'>,)
keys (<Keys.CPRResponse: '<cursor-position-response>'>,)
keys (<Keys.CPRResponse: '<cursor-position-response>'>,)
keys (<Keys.CPRResponse: '<cursor-position-response>'>,)
keys (<Keys.CPRResponse: '<cursor-position-response>'>,)
keys (<Keys.CPRResponse: '<cursor-position-response>'>,)
keys (<Keys.CPRResponse: '<cursor-position-response>'>,)
keys (<Keys.CPRResponse: '<cursor-position-response>'>,)
keys (<Keys.CPRResponse: '<cursor-position-response>'>,)
keys (<Keys.CPRResponse: '<cursor-position-response>'>,)
keys (<Keys.CPRResponse: '<cursor-position-response>'>,)
keys (<Keys.CPRResponse: '<cursor-position-response>'>,)

        keys = tuple(k.key for k in key_presses)
        print("keys", keys)

        # Try match, with mode flag
        return [b for b in self._bindings.get_bindings_for_keys(keys) if b.filter()]

Some other suggestions/questions

The filter should receive the event. Most cases is redundant, but in case

And a question:

given that in the filter I do not have the event, cannot do what I wanted to do.

in the keybinding, is it possible to add back the event to the event queue?

Key binding for in vi mode would be also very usefull