Inserting split CRLF pair causes GtkTextBuffer lines to get out of sync
@kaiw
Submitted by Kai Willadsen Link to original bug (#631468)
Description
Created attachment 171788 Testcase
When inserting text into a GtkTextBuffer, a gtk_text_buffer_insert where the string ends in '\r' and the next _insert string starts in '\n' gives different (incorrect) results to inserting the '\r\n' as a pair. Specifically, inserting '\r' creates an additional line in the GtkTextBuffer, which is not retroactively adjusted for when the second half of the split CRLF pair is inserted. There is no visible symptom of this in the corresponding GtkTextView, but any code that relies on GtkTextBuffer line indices will break.
In the real world, a split pair can be inserted when, for example, reading from a file in 4K chunks and inserting each chunk into the buffer. If a '\r\n' pair occurs on the split between chunk boundaries, bad things happen.
A minimal testcase is attached. Apologies for the terrible C---it's a quick port from a Python testcase---but it illustrates the point.
Attachment 171788, "Testcase":
testbuffer.c
Version: 3.8.x