aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/core/init.lua9
-rw-r--r--data/core/keymap.lua8
-rw-r--r--data/core/vim.lua19
3 files changed, 23 insertions, 13 deletions
diff --git a/data/core/init.lua b/data/core/init.lua
index 52af9b3f..dcf033e2 100644
--- a/data/core/init.lua
+++ b/data/core/init.lua
@@ -714,11 +714,18 @@ function core.try(fn, ...)
return false, err
end
+-- vim module but loaded only when required.
+local vim
function core.on_event(type, ...)
local did_keymap = false
if type == "textinput" then
- -- FIXME: send textinput event to vim key-bindings module in vim mode
+ local vim_mode = core.get_editing_mode(core.active_view)
+ if vim_mode then
+ local vim = require "core.vim"
+ local accepted = vim.on_text_input(vim_mode, ...)
+ if accepted then return false end
+ end
core.root_view:on_text_input(...)
elseif type == "keypressed" then
did_keymap = keymap.on_key_pressed(...)
diff --git a/data/core/keymap.lua b/data/core/keymap.lua
index caee2a21..cc0e0a1c 100644
--- a/data/core/keymap.lua
+++ b/data/core/keymap.lua
@@ -63,11 +63,13 @@ function keymap.on_key_pressed(k)
end
else
local stroke = key_to_stroke(k)
- local mode = core.get_editing_mode(core.active_view)
- if mode then
+ local vim_mode = core.get_editing_mode(core.active_view)
+ if vim_mode then
local vim = require "core.vim"
- local accepted = vim.on_key_pressed(mode, stroke, k)
+ local accepted = vim.on_text_input(vim_mode, nil, stroke)
if accepted then return true end
+ -- if the command is not recognized by vim fall throught to process
+ -- it as an ordinary command
end
local commands = keymap.map[stroke]
if commands then
diff --git a/data/core/vim.lua b/data/core/vim.lua
index d17c6342..c7c86c7c 100644
--- a/data/core/vim.lua
+++ b/data/core/vim.lua
@@ -101,20 +101,21 @@ local function vim_execute(verb, mult, object)
return true
end
-function vim.on_key_pressed(mode, stroke, k)
+function vim.on_text_input(mode, text, stroke)
+ text = text or stroke
if mode == 'command' then
- if command_buffer.verb == '.' and table_find(verbs_imm, stroke) then
- vim_execute(stroke, command_buffer:mult())
+ if command_buffer.verb == '.' and table_find(verbs_imm, text) then
+ vim_execute(text, command_buffer:mult())
command_buffer:reset()
return true
- elseif command_buffer.verb == '.' and table_find(verbs_obj, stroke) then
- command_buffer.verb = stroke
+ elseif command_buffer.verb == '.' and table_find(verbs_obj, text) then
+ command_buffer.verb = text
return true
- elseif string.byte(k) >= string.byte('0') and string.byte(k) <= string.byte('9') then
- command_buffer:add_mult_char(k)
+ elseif string.byte(text) >= string.byte('0') and string.byte(text) <= string.byte('9') then
+ command_buffer:add_mult_char(text)
return true
- elseif table_find(vim_objects, stroke) then
- vim_execute(command_buffer.verb, command_buffer:mult(), stroke)
+ elseif table_find(vim_objects, text) then
+ vim_execute(command_buffer.verb, command_buffer:mult(), text)
command_buffer:reset()
return true
elseif stroke == 'escape' then