Open randy3k opened 7 years ago
Similar feature C-o
has been implemented at https://github.com/jonathanslenders/python-prompt-toolkit/issues/416 but I argue that the down arrow is more intuitive.
PS: I am not using the prompt_toolkit.shortcuts.prompt
function but rather have my own classes, so history is persistent between prompts.
For reference, I used the following keybinds to mimick this feature. I am wishing there will be some kind of official support.
last_working_index = [-1]
last_history = Condition(lambda cli: cli.current_buffer.working_index == len(cli.current_buffer._working_lines)-1)
is_empty = Condition(lambda cli: len(cli.current_buffer.text) == 0)
@registry.add_binding(Keys.ControlJ, filter=foo & bar)
def _(event):
last_working_index[0] = event.cli.current_buffer.working_index
# do your stuff
@registry.add_binding(Keys.Down, filter=is_empty & last_history)
def _(event):
if last_working_index[0] >= 0:
event.cli.current_buffer.go_to_history(last_working_index[0] + 1)
last_working_index[0] = -1
After using Control-R to search history and executing the result, it would be nice to have the down key mapped to the next item of the searched result in the history list. For example.
With such implementation, it is much easier to replay history commands.