Skip to content

Commit

Permalink
feat: Support moonicipal.fix_echo in the remaining modes ('c', `'…
Browse files Browse the repository at this point in the history
…r'` and `'R'`)

Note that `'c'` just delays until the command finishes. `'r'` does the
same, but when testing it looks like the deferred function was not
actually invoked in that mode, so I'm not 100% sure it's necessary.
  • Loading branch information
idanarye committed Oct 31, 2023
1 parent 320b1e8 commit b0d7a2b
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lua/moonicipal/util.lua
Expand Up @@ -70,7 +70,7 @@ local function get_keybind_prefix_for_running_command()
local mode = vim.fn.mode()
if mode == 'n' then
return ':'
elseif mode == 'i' then
elseif mode == 'i' or mode == 'R' then
return '<C-o>:'
elseif mode == 'v' or mode == 'V' or mode == CTRL_V then
return ':<C-u>'
Expand All @@ -84,20 +84,25 @@ local function get_keybind_prefix_for_running_command()
end
end
return ':'
-- TODO:
-- elseif mode == 'R' then
-- elseif mode == 'c' then
-- elseif mode == 'r' then
elseif mode == 'c' or mode == 'r' then
return nil
end
error('Cannot fix echo from mode ' .. vim.inspect(mode))
end

local function resume_threads()
local prefix = vim.api.nvim_replace_termcodes(get_keybind_prefix_for_running_command(), true, false, true)
local keycmd = 'lua require"moonicipal.util"._resume_all_threads()\n'
vim.api.nvim_feedkeys(prefix .. keycmd, 'n', false)
if next(resumable_threads) ~= nil then
vim.defer_fn(resume_threads, 1)
local prefix = get_keybind_prefix_for_running_command()
if prefix == nil then
if next(resumable_threads) ~= nil then
vim.defer_fn(resume_threads, 100)
end
else
prefix = vim.api.nvim_replace_termcodes(prefix, true, false, true)
local keycmd = 'lua require"moonicipal.util"._resume_all_threads()\n'
vim.api.nvim_feedkeys(prefix .. keycmd, 'ni', false)
if next(resumable_threads) ~= nil then
vim.defer_fn(resume_threads, 1)
end
end
end

Expand Down

0 comments on commit b0d7a2b

Please sign in to comment.