<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kakoune.git/test/commands/fifo-read-ranges-scroll/cmd, branch master</title>
<subtitle>Unnamed repository; edit this file 'description' to name the repository.
</subtitle>
<link rel='alternate' type='text/html' href='https://git.vinkies.net/kakoune.git/'/>
<entry>
<title>Scrolling BufReadFifo to not not report final empty line</title>
<updated>2024-12-01T11:52:42+00:00</updated>
<author>
<name>Johannes Altmanninger</name>
<email>aclopte@gmail.com</email>
</author>
<published>2024-11-28T12:24:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.vinkies.net/kakoune.git/commit/?id=316bca9d6225007e32e89053dc3b8bd221d40b50'/>
<id>316bca9d6225007e32e89053dc3b8bd221d40b50</id>
<content type='text'>
Whereas nonscrolling fifos generally[^1] append to the very end of
the buffer, scrolling fifos generally insert *before* the final
empty line.

This means that every single BufReadFifo hook in a scrolling fifo will
report an additional newline.  This is clearly wrong.  Even reporting
it only once would be wrong, because the newline is not added by a
fifo read.

This behavior has always existed for "edit -scroll -fifo" buffers.
For stdin buffers, it was re-introduced in c3b01a3c9 (Add back option
to scroll in stdin buffers, 2024-11-27).

Fix this by ending the reported range before the final empty line.

Handle one edge case: if the inserted range did not end with a
newline, the final empty line collapses into the previous line.
In this case we already don't report the newline because it's declared
"artificially-added" by 658915086 (Fix BufReadFifo overlapping range
on partial line, 2024-11-23).

This fixes the problem described at
https://github.com/mawww/kakoune/issues/5255#issuecomment-2505650511

Tests are copied verbatim from the no-scroll cases (not yet sure how
to share logic / parameterize a test in a nice way):

	$ diff -ur test/commands/fifo-read-ranges{,-scroll}
	-edit -fifo fifo *fifo*
	+edit -fifo fifo -scroll *fifo*
	$ diff -ur test/commands/fifo-read-ranges-noeol{,-scroll}
	-edit -fifo fifo *fifo*
	+edit -fifo fifo -scroll *fifo*

[^1]: unless the very last character is a fake newline (except for
      the first read, to not scroll) which we already don't report.
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Whereas nonscrolling fifos generally[^1] append to the very end of
the buffer, scrolling fifos generally insert *before* the final
empty line.

This means that every single BufReadFifo hook in a scrolling fifo will
report an additional newline.  This is clearly wrong.  Even reporting
it only once would be wrong, because the newline is not added by a
fifo read.

This behavior has always existed for "edit -scroll -fifo" buffers.
For stdin buffers, it was re-introduced in c3b01a3c9 (Add back option
to scroll in stdin buffers, 2024-11-27).

Fix this by ending the reported range before the final empty line.

Handle one edge case: if the inserted range did not end with a
newline, the final empty line collapses into the previous line.
In this case we already don't report the newline because it's declared
"artificially-added" by 658915086 (Fix BufReadFifo overlapping range
on partial line, 2024-11-23).

This fixes the problem described at
https://github.com/mawww/kakoune/issues/5255#issuecomment-2505650511

Tests are copied verbatim from the no-scroll cases (not yet sure how
to share logic / parameterize a test in a nice way):

	$ diff -ur test/commands/fifo-read-ranges{,-scroll}
	-edit -fifo fifo *fifo*
	+edit -fifo fifo -scroll *fifo*
	$ diff -ur test/commands/fifo-read-ranges-noeol{,-scroll}
	-edit -fifo fifo *fifo*
	+edit -fifo fifo -scroll *fifo*

[^1]: unless the very last character is a fake newline (except for
      the first read, to not scroll) which we already don't report.
</pre>
</div>
</content>
</entry>
</feed>
