Use global vim mode flag
This commit is contained in:
parent
296ea8b03d
commit
4b68ce431c
|
@ -173,12 +173,7 @@ command.add(nil, {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:toggle-vim-mode"] = function()
|
["core:toggle-vim-mode"] = function()
|
||||||
local mode = core.get_editing_mode(core.active_view)
|
core.vim_mode = not core.vim_mode
|
||||||
if mode == 'standard' then
|
|
||||||
core.set_editing_mode(core.active_view, 'command')
|
|
||||||
else
|
|
||||||
core.set_editing_mode(core.active_view, 'standard')
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
|
|
||||||
["core:set-insert-mode"] = function()
|
["core:set-insert-mode"] = function()
|
||||||
|
|
|
@ -56,7 +56,7 @@ function DocView:new(doc)
|
||||||
self.font = "code_font"
|
self.font = "code_font"
|
||||||
self.last_x_offset = {}
|
self.last_x_offset = {}
|
||||||
self.blink_timer = 0
|
self.blink_timer = 0
|
||||||
self.editing_mode = 'standard'
|
self.editing_mode = 'command'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ end
|
||||||
|
|
||||||
|
|
||||||
function DocView:on_text_input(text)
|
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)
|
self.doc:text_input(text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -395,6 +395,7 @@ function core.init()
|
||||||
core.log_items = {}
|
core.log_items = {}
|
||||||
core.docs = {}
|
core.docs = {}
|
||||||
core.threads = setmetatable({}, { __mode = "k" })
|
core.threads = setmetatable({}, { __mode = "k" })
|
||||||
|
core.vim_mode = false
|
||||||
|
|
||||||
local project_dir_abs = system.absolute_path(project_dir)
|
local project_dir_abs = system.absolute_path(project_dir)
|
||||||
local set_project_ok = project_dir_abs and core.set_project_dir(project_dir_abs)
|
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)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
function core.using_vim_mode(view)
|
||||||
|
return core.vim_mode and getmetatable(view) == DocView
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function core.get_editing_mode(view)
|
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
|
end
|
||||||
|
|
||||||
|
|
||||||
function core.set_editing_mode(view, mode)
|
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)
|
view:set_editing_mode(mode)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -125,7 +125,7 @@ function StatusView:get_items()
|
||||||
self.separator,
|
self.separator,
|
||||||
string.format("%d%%", line / #dv.doc.lines * 100),
|
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,
|
indent_label, indent_size,
|
||||||
style.dim, self.separator2, style.text,
|
style.dim, self.separator2, style.text,
|
||||||
style.icon_font, "g",
|
style.icon_font, "g",
|
||||||
|
|
Loading…
Reference in New Issue