Closed sminez closed 1 month ago
I tried digging into at what point things break in the example failure described above and ended up seemingly tracking it down to inserting strings into the buffer once the gap is below a certain threshold. For the example in the regression test the break point is a gap size of 15 it seems? Forcing the gap to be resized at this point (a change in behaviour) fixes the issue, or at least, gets this specific regression test to pass. What I'm still not sure about is why this works and why 15 is the important value (the inserted string has length 11 so it's not a case of overflowing the gap).
My concern is that this "fix" is just kicking things down the line to show up again later. I'd prefer to fully understand why this is happening and be able to reproduce it with a simpler test case that is easier to reason about.
Closing for now as the issue hasn't resurfaced since committing the fix last week.
Describe the bug
In some circumstances (still trying to pin down the exact cause) it is possible to insert into a buffer and have the new text end up in the wrong place. This also causes undo of the edits in question to further mangle the buffer state.
Triggering this is quite tricky to do without a known case as it involves manipulating the internal state of the gap buffer in a particular way that sets things up for a following edit to start breaking things.
To Reproduce
So far the only reliable way I have of reproducing this is the exact case where I encountered it, but I suspect that this is the cause of some other odd behaviour I've seen in a few places as well. In all cases that I think are related, this involves opening an existing file and then making edits towards the end of the file (but not at the end of the file).
Test data
ad
x@
to select and execute the first Edit commandChanging the first line to begin
Edit 6,30 ...
instead will run just fine. If you then manually start adding the expected quote you should see that it is inserting the quote beforesave
on the second to last line that causes things to start breaking (with additional edits past that point making things worse). All I've been able to identify so far is that that character offset within the visible buffer is exactly the byte offset ofself.gap_end
for the underlying gap buffer. So I suspect that the issue is something to do with the implementation of char_to_byte_impl but that is not confirmed yet.Expected behavior
Edits at any point within a buffer work.
Screenshots
This is the resulting buffer state after running the Edit command:
The last two lines should have had the same edit made to them: quotes being placed around the text before and after the central
--
delimiter.