helix icon indicating copy to clipboard operation
helix copied to clipboard

add prompt history search by input

Open QiBaobin opened this issue 2 years ago • 3 comments

QiBaobin avatar Jun 17 '22 08:06 QiBaobin

How about making this the default behaviour of up/down keys and instead of just matching by prefix we match by substring, similar to how fish shell does history searching:

↑ (Up) and ↓ (Down) (or Control+P and Control+N for emacs aficionados) search the command history for the previous/next command containing the string that was specified on the commandline before the search was started. If the commandline was empty when the search started, all commands match.

https://fishshell.com/docs/current/interactive.html#shared-bindings

sudormrfbin avatar Jun 21 '22 06:06 sudormrfbin

How about making this the default behaviour of up/down keys and instead of just matching by prefix we match by substring, similar to how fish shell does history searching:

↑ (Up) and ↓ (Down) (or Control+P and Control+N for emacs aficionados) search the command history for the previous/next command containing the string that was specified on the commandline before the search was started. If the commandline was empty when the search started, all commands match.

https://fishshell.com/docs/current/interactive.html#shared-bindings

@sudormrfbin Changed, please take another look.

QiBaobin avatar Jun 24 '22 06:06 QiBaobin

I like this behavior 👍

There's one difference from fish history navigation that I notice: if you hit down/C-n enough I think you should be able to get back to your original prompt. So if you have :open CHANGELOG.md and :open README.md in the history and have a prompt of :op:

  • C-p should give :open README.md (current behavior ✔️)
  • C-p should give :open CHANGELOG.md (✔️)
  • C-n should give :open README.md (✔️)
  • C-n should give :op (✖️: current behavior is the last item in history, :open README.md)

so that if you don't like the options in the history you can continue from what you typed.

the-mikedavis avatar Oct 29 '22 16:10 the-mikedavis

I like this behavior 👍

There's one difference from fish history navigation that I notice: if you hit down/C-n enough I think you should be able to get back to your original prompt. So if you have :open CHANGELOG.md and :open README.md in the history and have a prompt of :op:

* `C-p` should give `:open README.md` (current behavior ✔️)

* `C-p` should give `:open CHANGELOG.md` (✔️)

* `C-n` should give `:open README.md` (✔️)

* `C-n` should give `:op` (✖️: current behavior is the last item in history, `:open README.md`)

so that if you don't like the options in the history you can continue from what you typed.

Done, please take another look, thanks!

QiBaobin avatar Nov 17 '22 07:11 QiBaobin

it seems that below test failed because of the behavior change, did I miss something? If not, please let me know how I shall update it.

QiBaobin avatar Nov 21 '22 02:11 QiBaobin

Hello, anything I can do to help get this merged? I can have a go at fixing the tests if you'd like @QiBaobin?

mogest avatar Jan 21 '23 22:01 mogest

Hello, anything I can do to help get this merged? I can have a go at fixing the tests if you'd like @QiBaobin?

Thanks, it would be great if you can help on this. And I think we also need get @the-mikedavis approve this.

QiBaobin avatar Jan 24 '23 06:01 QiBaobin

It merged cleanly with master but I found a few problems with the matching logic so got those fixed up.

Helix master and vim both stop at the start and end of the lists, and your implementation keeps going around in a loop. I've left the loop in there but probably worth a quick discussion as to whether that's desired. (I think it's great.)

Tests + integration tests are passing locally for me, do you want to merge my branch into yours and see what CI thinks?

mogest avatar Jan 24 '23 09:01 mogest

It merged cleanly with master but I found a few problems with the matching logic so got those fixed up.

Helix master and vim both stop at the start and end of the lists, and your implementation keeps going around in a loop. I've left the loop in there but probably worth a quick discussion as to whether that's desired. (I think it's great.)

Tests + integration tests are passing locally for me, do you want to merge my branch into yours and see what CI thinks?

merged to my branch, thanks! But It seems that the test still fail.

QiBaobin avatar Jan 24 '23 10:01 QiBaobin

No go—it's late here but I'll check out the fail tomorrow morning.

mogest avatar Jan 24 '23 10:01 mogest

Got it failing in a docker container, strange that it doesn't fail on MacOS. Fixed in 8059c10 on my branch if you'd like to merge.

mogest avatar Jan 24 '23 18:01 mogest