diff --git a/data/core/commands/core.lua b/data/core/commands/core.lua index 46994dc4..5e870305 100644 --- a/data/core/commands/core.lua +++ b/data/core/commands/core.lua @@ -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() diff --git a/data/core/docview.lua b/data/core/docview.lua index 8f3ca7f6..11923181 100644 --- a/data/core/docview.lua +++ b/data/core/docview.lua @@ -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 diff --git a/data/core/init.lua b/data/core/init.lua index 5542a718..60c2255d 100644 --- a/data/core/init.lua +++ b/data/core/init.lua @@ -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 diff --git a/data/core/statusview.lua b/data/core/statusview.lua index bf3ddecd..73ef89ba 100644 --- a/data/core/statusview.lua +++ b/data/core/statusview.lua @@ -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",