perf(Mode): remove `InputBytes` class

pull/20/head
Iron-E 1 year ago
parent 69beec5e8e
commit 34b94a246d
No known key found for this signature in database
GPG Key ID: 83A6AEB40395D40D

@ -13,23 +13,16 @@ local utils = require 'libmodal/src/utils'
--- @field private help? libmodal.utils.Help
--- @field private indicator libmodal.utils.Indicator
--- @field private input libmodal.utils.Vars
--- @field private input_bytes? number[]
--- @field private instruction fun()|{[string]: fun()|string}
--- @field private mappings libmodal.collections.ParseTable
--- @field private name string
--- @field private popups libmodal.collections.Stack
--- @field private show_name fun()
--- @field private supress_exit boolean
--- @field private timeouts_enabled boolean
local Mode = utils.classes.new()
local InputBytes = utils.classes.new(
{
clear = function(self)
for i, _ in ipairs(self) do
self[i] = nil
end
end
})
local HELP = '?'
local TIMEOUT =
{
@ -70,7 +63,7 @@ function Mode:check_input_for_mapping()
self.help:show()
end
self.input_bytes:clear()
self.input_bytes = {}
elseif command_type == globals.TYPE_TBL and globals.is_true(self.timeouts_enabled) then -- the command was a table, meaning that it MIGHT match.
self.flush_input_timer:start( -- start the timer
TIMEOUT.LEN, 0, vim.schedule_wrap(function()
@ -81,14 +74,14 @@ function Mode:check_input_for_mapping()
self.execute_instruction(cmd[ParseTable.CR])
end
-- clear input
self.input_bytes:clear()
self.input_bytes = {}
self.popups:peek():refresh(self.input_bytes)
end)
)
else -- the command was an actual vim command.
--- @diagnostic disable-next-line:param-type-mismatch already checked `cmd` != `table`
self.execute_instruction(cmd)
self.input_bytes:clear()
self.input_bytes = {}
end
self.popups:peek():refresh(self.input_bytes)
@ -137,7 +130,7 @@ function Mode:get_user_input()
end
-- echo the indicator.
self:show_name()
self.show_name()
-- capture input.
local user_input = vim.fn.getchar()
@ -188,13 +181,11 @@ function Mode:tear_down()
utils.api.redraw()
end
return
{
--- create a new mode.
--- @param name string the name of the mode.
--- @param instruction fun()|string|table a Lua function, keymap dictionary, Vimscript command.
--- @return libmodal.Mode
new = function(name, instruction, supress_exit)
--- create a new mode.
--- @param name string the name of the mode.
--- @param instruction fun()|string|table a Lua function, keymap dictionary, Vimscript command.
--- @return libmodal.Mode
function Mode.new(name, instruction, supress_exit)
name = vim.trim(name)
-- inherit the metatable.
@ -230,7 +221,7 @@ return
self.help = utils.Help.new(self.instruction, 'KEY MAP')
end
self.input_bytes = setmetatable({}, InputBytes)
self.input_bytes = {}
-- build the parse tree.
--- @diagnostic disable-next-line:param-type-mismatch already checked `self.instruction` != `table`
@ -247,5 +238,6 @@ return
end
return self
end
}
end
return Mode

Loading…
Cancel
Save