Skip to content

Commit

Permalink
adding api to get current visual selection
Browse files Browse the repository at this point in the history
  • Loading branch information
MagicDuck committed Sep 20, 2024
1 parent 0d8dd71 commit ccc7a36
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions doc/grug-far.txt
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ require('grug-far').update_instance_prefills({instanceName}, {prefills}, {clearO
{search=, replacement=, filesFilter=, flags=, paths=}
{clearOld}(boolean) if given, old input values are ignored

require('grug-far').get_current_visual_selection() *grug-far.get_current_visual_selection()*
Gets the current visual selection as a string.
This is provided as a utility for users so they don't have to rewrite.

Return: ~
{visual_selection}(string)

==============================================================================
4. Highlights *grug-far-highlights*

Expand Down
14 changes: 14 additions & 0 deletions lua/grug-far.lua
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,20 @@ function M.with_visual_selection(options)
return M._open_internal(resolvedOpts, { is_visual = true })
end

--- gets the current visual selection as a string
--- This is provided as a utility for users so they don't have to rewrite
---@return string
function M.get_current_visual_selection()
local isVisualMode = vim.fn.mode():lower():find('v') ~= nil
if isVisualMode then
-- needed to make visual selection work
vim.cmd([[normal! vv]])
end

local selection_lines = utils.getVisualSelectionLines()
return vim.fn.join(selection_lines, '\n')
end

---@deprecated use open(same options) instead
--- launch grug-far with the given overrides
---@param options? GrugFarOptionsOverride
Expand Down

0 comments on commit ccc7a36

Please sign in to comment.