nvim-libmodal icon indicating copy to clipboard operation
nvim-libmodal copied to clipboard

Attempt to compare number with string in Mode.lua:296

Open IkaSek opened this issue 1 year ago • 1 comments

Error detected while processing LspAttach Autocommands for "*":
Error during nvim-libmodal mode: 

...ocal/share/nvim/lazy/nvim-libmodal/lua/libmodal/Mode.lua:296: attempt to compare number with string

let me be honest, i'm a noob. i don't understand the source code, is it something wrong i'm doing?

IkaSek avatar May 04 '24 22:05 IkaSek

now i'm no lua expert, but what i did here is

if tonumber(user_input) ~= nil and 0 <= tonumber(user_input) and tonumber(user_input) <= 9 or not tonumber(user_input) == nil then
         local oldCount = self.count:get()
         local newCount = tonumber(oldCount .. string.char(user_input))
         self.count:set(newCount)
 end

IkaSek avatar May 05 '24 19:05 IkaSek

Can you share the mode which produced this error?

Iron-E avatar May 06 '24 20:05 Iron-E

This looks like a regression. From what I can tell the problem occurs because of this.

getchar will not always return a number (for example, pressing the left arrow key will return a string with the same value as "<Left>"), so when you press any key that produces a string, it will be compared against a number and will error out.

I will try to submit a fix later today

vE5li avatar May 08 '24 14:05 vE5li

Seems like it really is that easy: https://github.com/Iron-E/nvim-libmodal/pull/38 I tested it with my own plugin and it works perfectly again

vE5li avatar May 08 '24 14:05 vE5li

This can be closed now I believe. Can you still produce the error on master @IkaSek?

vE5li avatar May 10 '24 07:05 vE5li