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

[Feature]: Allow :Legendary to accept a selection #321

Open
1 task done
lateef-k opened this issue Mar 22, 2023 · 4 comments
Open
1 task done

[Feature]: Allow :Legendary to accept a selection #321

lateef-k opened this issue Mar 22, 2023 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@lateef-k
Copy link

Similar Issues

  • 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.

@lateef-k lateef-k added the enhancement New feature or request label Mar 22, 2023
@mrjones2014 mrjones2014 added the good first issue Good for newcomers label Mar 22, 2023
@mrjones2014 mrjones2014 removed their assignment Mar 22, 2023
@mrjones2014
Copy link
Owner

This should absolutely be doable, and not that difficult to implement. Basically:

  • Add opts.range = true to the :Legendary command in lua/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 opts parameter
    • instead of just l.find(), do l.find({ range = the_range_we_got })
    • Update the M.select(opts) function in lua/legendary/ui/init.lua to accept an opts.range option
    • Pass opts.range into the Executor context builder like so: local context = Executor.build_context(nil, opts.range)
    • Update the M.build_context(buf) function in lua/legendary/api/executor.lua like the following:
---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

@hinell
Copy link
Contributor

hinell commented May 17, 2023

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.

@mrjones2014
Copy link
Owner

Not from cmdline. :<‘>’Legendary doesn’t currently work.

@hinell
Copy link
Contributor

hinell commented Oct 19, 2023

Oh yeah, it's for user cmd... overlooked that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants