legendary.nvim
legendary.nvim copied to clipboard
[Feature]: Allow :Legendary to accept a selection
Similar Issues
- [X] Before filing, I have searched for similar issues.
Description
It just takes a simple {range = true}. And it allows us to utilize commands from the :Legendary panel that run on a selection.
This should absolutely be doable, and not that difficult to implement. Basically:
- Add
opts.range = trueto the:Legendarycommand inlua/legendary/api/cmds.lua - In the function that implements the command, grab the current range, if one was passed
- Pass the range down to the UI via the
optsparameter- instead of just
l.find(), dol.find({ range = the_range_we_got }) - Update the
M.select(opts)function inlua/legendary/ui/init.luato accept anopts.rangeoption - Pass
opts.rangeinto the Executor context builder like so:local context = Executor.build_context(nil, opts.range) - Update the
M.build_context(buf)function inlua/legendary/api/executor.lualike the following:
- instead of just
---Build a context object containing information about the editor
---state *before* triggering the finder so that it can be
---restored before executing the item.
---@param buf number buffer ID to build context for, used only for testing
---@overload fun():LegendaryEditorContext
---@overload fun(buf:number):LegendaryEditorContext
---@return table
function M.build_context(buf, range)
buf = buf or vim.api.nvim_get_current_buf()
return {
buf = buf,
buftype = vim.api.nvim_buf_get_option(buf, 'buftype') or '',
filetype = vim.api.nvim_buf_get_option(buf, 'filetype') or '',
mode = vim.fn.mode(),
cursor_pos = vim.api.nvim_win_get_cursor(vim.api.nvim_get_current_win()),
marks = range or Toolbox.get_marks(),
}
end
Well I think you can already filter out commands specific to the visual/selection mode when activate Legendary:
{
mode = { "n", "v", "i" }, "<C-S-P>"
, function()
require("legendary")
.find( { filters = { filters.current_mode() } })
end ,
description = "Window: open command palette (Legendary plugin)"
}
I didn't use it extensively though.
Not from cmdline. :<‘>’Legendary doesn’t currently work.
Oh yeah, it's for user cmd... overlooked that.