hex.nvim icon indicating copy to clipboard operation
hex.nvim copied to clipboard

Confusing editor behavior

Open shmerl opened this issue 1 year ago • 5 comments

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.

shmerl avatar Jan 21 '24 07:01 shmerl

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.

RaafatTurki avatar Jan 21 '24 09:01 RaafatTurki

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?

shmerl avatar Jan 21 '24 09:01 shmerl

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?

shmerl avatar Jan 25 '24 02:01 shmerl

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

RaafatTurki avatar Jan 25 '24 13:01 RaafatTurki

Yeah, that sounds like it could improve things somewhat! Like you can check for the allowed range of characters for example.

shmerl avatar Jan 25 '24 18:01 shmerl