Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confusing editor behavior #17

Open
shmerl opened this issue Jan 21, 2024 · 5 comments
Open

Confusing editor behavior #17

shmerl opened this issue Jan 21, 2024 · 5 comments

Comments

@shmerl
Copy link

shmerl commented Jan 21, 2024

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.

@RaafatTurki
Copy link
Owner

RaafatTurki commented Jan 21, 2024

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.

@shmerl
Copy link
Author

shmerl commented Jan 21, 2024

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
Copy link
Author

shmerl commented Jan 25, 2024

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?

@RaafatTurki
Copy link
Owner

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

@shmerl
Copy link
Author

shmerl commented Jan 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants