mrjones2014 / legendary.nvim

🗺️ A legend for your keymaps, commands, and autocmds, integrates with which-key.nvim, lazy.nvim, and more.
MIT License
1.14k stars 19 forks source link

feat(api): Add command + API to repeat last selected item #385

Closed mrjones2014 closed 1 year ago

mrjones2014 commented 1 year ago

Resolves: #384

How to Test

  1. Run legendary.nvim's finder UI and select a command
  2. Call :LegendaryRepeat or :lua require('legendary').repeat_previous()
  3. It should execute the last selected item again

Testing for Regressions

I have tested the following:

mrjones2014 commented 1 year ago

@notEvil mind giving it a test?

notEvil commented 1 year ago

It works. There is one problem though: the item could be invalid because the context changed (buffer, filter, ...).

mrjones2014 commented 1 year ago

What do you mean? The context gets rebuilt when the item is re-executed. It will operate on the new context. Is that not what you were expecting?

notEvil commented 1 year ago

Sorry, I should pay more attention to terminology. With context I meant the state the repeat is initiated in. For instance, the last item could be available only for specific buffers or modes, or item filters could return false where they returned true previously.

mrjones2014 commented 1 year ago

Ah, I see. I'll keep thinking on it.

mrjones2014 commented 1 year ago

We'll probably need to keep track of the filters used on the last select and see if the item matches the filters as well.

mrjones2014 commented 1 year ago

@notEvil I've pushed an update so that it only executes the item if it still matches the previous set of filters used.

You can escape this behavior by running the command with a bang, or passing true to the Lua function:

:LegendaryRepeat
" ignore filters like
:LegendaryRepeat!

or in Lua

require('legendary').repeat_previous()
require('legendary').repeat_previous(--[[ ignore_filters: ]] true)
notEvil commented 1 year ago

I just tested it and it works as expected. Thanks!

mrjones2014 commented 1 year ago

Thanks for helping me test!