caleb-allen / VimBindings.jl

Vim bindings for the Julia REPL
https://caleb-allen.github.io/VimBindings.jl/
MIT License
111 stars 3 forks source link

latex characters cause certain actions to break on the last two characters #95

Closed ArbitRandomUser closed 5 months ago

ArbitRandomUser commented 7 months ago

seems to be triggered by certain latex characters are in the prompt

julia> 0b0000 ⊻ 0b0000

deleting the last 0 (and second last 0) character with x , or replacing (r) does not work, ( not sure other ways this is broken , but these two are what i noticed as of now)

pkg version:

[51b3953f] VimBindings v0.3.12
caleb-allen commented 7 months ago

Thank you for the report—on the surface, it seems it could be related to these other issues related to bad behavior when the cursor is at the end of the prompt, #92 and #93. Or perhaps it's an issue of counting the text width incorrectly when determining the valid range for an operation, because this would explain why the bug surfaces with special characters like which occupy more than one byte.

Ideally, no operation should be operating directly with bytes, but alas I wrote much of the code before I properly understood Julia's String implementation.

Hopefully there's a common root cause that will get all these fixed for the next version

caleb-allen commented 7 months ago

Ha, okay this is funny. I wrote a unit test containing your example, and then identified what I believe is the source of the bug (indeed using the byte length of the prompt). But still, the test is failing.

Turns out that the utility function I created to help write concise tests is itself broken! The idea is that I ought to be able to write a string which is transformed into a test prompt buffer, and it just needs to contain a pipe | where the cursor ought to be (and optionally a mode indicator by wrapping the mode in a pipe, e.g. |i| for insert mode). For instance:

julia> testbuf("f(x) = x * |2")
 VimBuffer("f(x) = x * |n|2")

But for a prompt containing characters represented by multiple codeunits...

julia> testbuf("0b0000 ⊻ 0b000|0")
 VimBuffer("0b0000 ⊻ 0b0|n|000")

It does not behave well. Oops! Quite a challenge to hammer a nail when your hammer is only a hammer for the easy nails!

Anyways, I'm fixing up that test buffer mechanism, certainly needs to be rock solid. Then I'll test the changes I've made that I am hopeful fix this (it does in my REPL) and put out a release once that's verified.

caleb-allen commented 5 months ago

This should be fixed in #97 and will be included in the next release