Skip to content

Commit

Permalink
feat: Provide command to trigger bulk replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
johmsalas committed Jul 11, 2022
1 parent 519e62a commit 54e3d9d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions lua/textcase/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ local M = {
quick_replace = plugin.quick_replace,
clear_match = plugin.clear_match,
open_telescope = plugin.open_telescope,
start_replacing_command = plugin.start_replacing_command,
}

return M
24 changes: 24 additions & 0 deletions lua/textcase/plugin/plugin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,30 @@ function M.open_telescope(filter)

end

function M.start_replacing_command()
local mode = vim.api.nvim_get_mode().mode
M.state.telescope_previous_mode = mode
M.state.telescope_previous_buffer = vim.api.nvim_get_current_buf()

if mode == 'n' then
local current_word = vim.fn.expand('<cword>')
vim.api.nvim_feedkeys(":Subs/" .. current_word .. "/", 'i', true)
else
local region = utils.get_visual_region(0, true)
local text = utils.nvim_buf_get_text(
0,
region.start_row - 1,
region.start_col - 1,
region.start_row - 1,
region.end_col
)

local clean_range_key = vim.api.nvim_replace_termcodes("<C-u>", true, false, true)
vim.api.nvim_feedkeys(":" .. clean_range_key .. "Subs/" .. text[1] .. "/", 'i', false)
end

end

function M.replace_word_under_cursor(command)
local current_word = vim.fn.expand('<cword>')
vim.api.nvim_feedkeys(":" .. command .. '/' .. current_word .. '/', "i", false)
Expand Down

0 comments on commit 54e3d9d

Please sign in to comment.