Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jun 27, 2023

Conversation

mrjones2014
Copy link
Owner

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:

  • Triggering keymaps from legendary.nvim in all modes (normal, insert, visual)
  • Creating keymaps via legendary.nvim, then triggering via the keymap in all modes (normal, insert, visual)
  • Triggering commands from legendary.nvim in all modes (normal, insert, visual)
  • Creating commands via legendary.nvim, then running the command manually from the command line
  • augroup/autocmds created through legendary.nvim work correctly

@mrjones2014
Copy link
Owner Author

@notEvil mind giving it a test?

@notEvil
Copy link

notEvil commented Jun 24, 2023

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

@mrjones2014
Copy link
Owner Author

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
Copy link

notEvil commented Jun 24, 2023

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
Copy link
Owner Author

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

@mrjones2014
Copy link
Owner Author

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
Copy link
Owner Author

@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
Copy link

notEvil commented Jun 27, 2023

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

@mrjones2014
Copy link
Owner Author

Thanks for helping me test!

@mrjones2014 mrjones2014 changed the title feat(api): Add API to repeat last selected item feat(api): Add command + API to repeat last selected item Jun 27, 2023
@mrjones2014 mrjones2014 merged commit 05b0c41 into master Jun 27, 2023
3 checks passed
@mrjones2014 mrjones2014 deleted the mrj/384/dot-repeat branch June 27, 2023 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Repeat most recent
2 participants