prompt-toolkit / python-prompt-toolkit

Library for building powerful interactive command line applications in Python
https://python-prompt-toolkit.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
9.32k stars 714 forks source link

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

Open zokrezyl opened 6 days ago

zokrezyl commented 6 days ago

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

zokrezyl commented 6 days ago

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()]
zokrezyl commented 6 days ago

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