Confusing editor behavior
May be I'm not getting how this plugin works, but when in the hex / bytes area, I can input any text there, not just 00 - FF values. Is that intended? It feels confusing or at least not correct for hex editing.
Hmm, I understand
Yes rn you are allowed to type stuff other than 00 - FF which isn't ideal but afaik there isn't a "sane" way of preventing it.
The way it works is it dumps the bytes of a file into a buffer, you then can edit your "hex/bytes" are with just 00-FF values and upon saving it would reconstruct the file out of the buffer.
What happens if you put something else there besides 00-FF though? It just feeds that to xxd and it depends on how it handles it?
That might be very suboptimal, but is there a way to put a hook on any key input and if it's within the hex plane, it can filter what input is allowed.
Something like this may be?
Turns out it's totally possible to control what char insert on each key press.
For instance the following prevents the s char from being inserted into the buffer:
vim.api.nvim_create_autocmd({ "InsertCharPre" }, {
callback = function(ev)
if (vim.v.char == "s") then
vim.v.char = ''
end
end
})
However that doesn't include other content modification methods like replacing, pasting, inc, dec .. etc Also there are 3rd party plugins that can modify the buffer.
I might implement just the char inserting snippet above tho
Yeah, that sounds like it could improve things somewhat! Like you can check for the allowed range of characters for example.