fix(mode): incompatible with vim.v.count

pull/26/head
Iron-E 3 months ago
parent 1ecc4add3b
commit 78794426f4
No known key found for this signature in database
GPG Key ID: 569E791B76A42A1A

@ -161,6 +161,9 @@ FUNCTIONS *libmodal-usage-function
that |getchar()| completes. The user input is received through
`g:{name}ModeInput` (see above).
- |v:count| and |v:count1| are provided through `g:{name}ModeCount`
and `g:{name}ModeCount1` respectively.
*Error you cannot pass a funcref to Lua from Vimscript!
       - If you want to use a |funcref()| for {instruction}, it
       must be the name of the function as a `string`. >

@ -7,6 +7,9 @@ local utils = require 'libmodal.utils' --- @type libmodal.utils
--- @field private global_exit libmodal.utils.Vars
--- @field private global_input libmodal.utils.Vars
--- @field private help? libmodal.utils.Help
--- @field private input libmodal.utils.Vars
--- @field private count libmodal.utils.Vars
--- @field private count1 libmodal.utils.Vars
--- @field private input_bytes? number[]
--- @field private instruction fun()|{[string]: fun()|string}
--- @field private local_exit boolean
@ -27,6 +30,12 @@ local TIMEOUT =
}
TIMEOUT.CHAR_NUMBER = TIMEOUT.CHAR:byte()
--- Byte for 0
local ZERO = string.byte(0)
--- Byte for 9
local NINE = string.byte(9)
--- execute the `instruction`.
--- @private
--- @param instruction fun(libmodal.Mode)|string a Lua function or Vimscript command.
@ -38,6 +47,8 @@ function Mode:execute_instruction(instruction)
vim.api.nvim_command(instruction)
end
self.count:set(0)
self.count1:set(1)
self:redraw_virtual_cursor()
end
@ -104,6 +115,9 @@ function Mode:enter()
self.popups:push(utils.Popup.new())
end
self.count:set(0)
self.count1:set(1)
self.local_exit = false
--- HACK: https://github.com/neovim/neovim/issues/20793
@ -173,6 +187,13 @@ function Mode:get_user_input()
-- set the global input variable to the new input.
self.global_input:set(user_input)
if ZERO <= user_input and user_input <= NINE then
local oldCount = self.count:get()
local newCount = tonumber(oldCount .. string.char(user_input))
self.count:set(newCount)
self.count1:set(math.max(1, newCount))
end
if not self.supress_exit and user_input == globals.ESC_NR then -- the user wants to exit.
return false -- as in, "I don't want to continue."
else -- the user wants to continue.
@ -256,6 +277,8 @@ function Mode.new(name, instruction, supress_exit)
-- inherit the metatable.
local self = setmetatable(
{
count = utils.Vars.new('count', name),
count1 = utils.Vars.new('count1', name),
global_exit = utils.Vars.new('exit', name),
global_input = utils.Vars.new('input', name),
instruction = instruction,

Loading…
Cancel
Save