Skip to content

Commit

Permalink
chore: Use same way to exit visual mode everywhere and move to utils
Browse files Browse the repository at this point in the history
Signed-off-by: Tomas Slusny <slusnucky@gmail.com>
  • Loading branch information
deathbeam committed May 28, 2024
1 parent 180bbd9 commit c21c87d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
5 changes: 1 addition & 4 deletions lua/CopilotChat/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -315,11 +315,8 @@ function M.open(config, source, no_insert)
winnr = vim.api.nvim_get_current_win(),
})

-- Exit insert mode if we are in insert mode
vim.cmd('stopinsert')

-- Exit visual mode if we are in visual mode
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<esc>', true, false, true), 'x', false)
utils.exit_visual_mode()

-- Recreate the window if the layout has changed
if should_reset then
Expand Down
2 changes: 2 additions & 0 deletions lua/CopilotChat/integrations/fzflua.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local fzflua = require('fzf-lua')
local chat = require('CopilotChat')
local utils = require('CopilotChat.utils')

local M = {}

Expand All @@ -11,6 +12,7 @@ function M.pick(pick_actions, opts)
return
end

utils.exit_visual_mode()
opts = vim.tbl_extend('force', {
prompt = pick_actions.prompt .. '> ',
preview = fzflua.shell.raw_preview_action_cmd(function(items)
Expand Down
6 changes: 2 additions & 4 deletions lua/CopilotChat/integrations/telescope.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ local themes = require('telescope.themes')
local conf = require('telescope.config').values
local previewers = require('telescope.previewers')
local chat = require('CopilotChat')
local utils = require('CopilotChat.utils')

local M = {}

Expand All @@ -17,10 +18,7 @@ function M.pick(pick_actions, opts)
return
end

if vim.fn.mode():lower():find('v') then
vim.cmd('normal! v')
end

utils.exit_visual_mode()
opts = themes.get_dropdown(opts or {})
pickers
.new(opts, {
Expand Down
8 changes: 8 additions & 0 deletions lua/CopilotChat/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,12 @@ function M.table_equals(a, b)
return true
end

--- Exit visual mode if we are in it
function M.exit_visual_mode()
if vim.fn.mode():lower():find('v') then
-- NOTE: vim.cmd('normal! v') does not work properly when executed from keymap
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes('<esc>', true, false, true), 'x', false)
end
end

return M

0 comments on commit c21c87d

Please sign in to comment.