Handle block visual/select modes, refactor mode handling (#498)
This commit is contained in:
@@ -1,51 +1,40 @@
|
|||||||
local api = {}
|
local api = {}
|
||||||
|
|
||||||
api.in_insert_enter_autocmd = nil
|
local CTRL_V = vim.api.nvim_replace_termcodes('<C-v>', true, true, true)
|
||||||
|
local CTRL_S = vim.api.nvim_replace_termcodes('<C-s>', true, true, true)
|
||||||
|
|
||||||
api.get_mode = function()
|
api.get_mode = function()
|
||||||
if api.is_insert_mode() then
|
local mode = vim.api.nvim_get_mode().mode:sub(1, 1)
|
||||||
return 'i'
|
if mode == 'i' then
|
||||||
elseif api.is_visual_mode() then
|
return 'i' -- insert
|
||||||
return 'x'
|
elseif mode == 'v' or mode == 'V' or mode == CTRL_V then
|
||||||
elseif api.is_select_mode() then
|
return 'x' -- visual
|
||||||
return 's'
|
elseif mode == 's' or mode == 'S' or mode == CTRL_S then
|
||||||
elseif api.is_cmdline_mode() then
|
return 's' -- select
|
||||||
return 'c'
|
elseif mode == 'c' and vim.fn.getcmdtype() ~= '=' then
|
||||||
|
return 'c' -- cmdline
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
api.is_insert_mode = function()
|
api.is_insert_mode = function()
|
||||||
return vim.tbl_contains({
|
return api.get_mode() == 'i'
|
||||||
'i',
|
|
||||||
'ic',
|
|
||||||
'ix',
|
|
||||||
}, vim.api.nvim_get_mode().mode)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
api.is_cmdline_mode = function()
|
api.is_cmdline_mode = function()
|
||||||
local is_cmdline_mode = vim.tbl_contains({
|
return api.get_mode() == 'c'
|
||||||
'c',
|
|
||||||
'cv',
|
|
||||||
}, vim.api.nvim_get_mode().mode)
|
|
||||||
return is_cmdline_mode and vim.fn.getcmdtype() ~= '='
|
|
||||||
end
|
end
|
||||||
|
|
||||||
api.is_select_mode = function()
|
api.is_select_mode = function()
|
||||||
return vim.tbl_contains({
|
return api.get_mode() == 's'
|
||||||
's',
|
|
||||||
'S',
|
|
||||||
}, vim.api.nvim_get_mode().mode)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
api.is_visual_mode = function()
|
api.is_visual_mode = function()
|
||||||
return vim.tbl_contains({
|
return api.get_mode() == 'x'
|
||||||
'v',
|
|
||||||
'V',
|
|
||||||
}, vim.api.nvim_get_mode().mode)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
api.is_suitable_mode = function()
|
api.is_suitable_mode = function()
|
||||||
return api.is_insert_mode() or api.is_cmdline_mode()
|
local mode = api.get_mode()
|
||||||
|
return mode == 'i' or mode == 'c'
|
||||||
end
|
end
|
||||||
|
|
||||||
api.get_current_line = function()
|
api.get_current_line = function()
|
||||||
|
|||||||
Reference in New Issue
Block a user