Use global vim mode flag

This commit is contained in:
Francesco Abbate 2021-03-27 15:54:55 +01:00
parent 296ea8b03d
commit 4b68ce431c
4 changed files with 14 additions and 11 deletions

View File

@ -173,12 +173,7 @@ command.add(nil, {
end,
["core:toggle-vim-mode"] = function()
local mode = core.get_editing_mode(core.active_view)
if mode == 'standard' then
core.set_editing_mode(core.active_view, 'command')
else
core.set_editing_mode(core.active_view, 'standard')
end
core.vim_mode = not core.vim_mode
end,
["core:set-insert-mode"] = function()

View File

@ -56,7 +56,7 @@ function DocView:new(doc)
self.font = "code_font"
self.last_x_offset = {}
self.blink_timer = 0
self.editing_mode = 'standard'
self.editing_mode = 'command'
end
@ -284,7 +284,7 @@ end
function DocView:on_text_input(text)
if self.editing_mode ~= 'command' then
if not core.using_vim_mode(self) or self.editing_mode ~= 'command' then
self.doc:text_input(text)
end
end

View File

@ -395,6 +395,7 @@ function core.init()
core.log_items = {}
core.docs = {}
core.threads = setmetatable({}, { __mode = "k" })
core.vim_mode = false
local project_dir_abs = system.absolute_path(project_dir)
local set_project_ok = project_dir_abs and core.set_project_dir(project_dir_abs)
@ -907,13 +908,20 @@ core.add_save_hook(function(filename)
end)
function core.using_vim_mode(view)
return core.vim_mode and getmetatable(view) == DocView
end
function core.get_editing_mode(view)
return view.get_editing_mode and view:get_editing_mode() or 'standard'
if core.using_vim_mode(view) then
return view:get_editing_mode()
end
end
function core.set_editing_mode(view, mode)
if view.set_editing_mode then
if core.using_vim_mode(view) then
view:set_editing_mode(mode)
end
end

View File

@ -125,7 +125,7 @@ function StatusView:get_items()
self.separator,
string.format("%d%%", line / #dv.doc.lines * 100),
}, {
style.caret, editing_mode ~= 'standard' and string.upper(editing_mode) or '', style.text, self.separator2,
style.caret, core.vim_mode and string.upper(editing_mode) or '', style.text, self.separator2,
indent_label, indent_size,
style.dim, self.separator2, style.text,
style.icon_font, "g",