diff options
| author | Johannes Altmanninger <aclopte@gmail.com> | 2024-11-28 13:24:47 +0100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2024-12-01 22:52:42 +1100 |
| commit | 316bca9d6225007e32e89053dc3b8bd221d40b50 (patch) | |
| tree | ed89267c872b1baf7beeb95bd991a62fc2f4c4ba /src | |
| parent | c52faded6fdba1297e1daf5894ccaa208b83ea7e (diff) | |
Scrolling BufReadFifo to not not report final empty line
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/buffer_utils.cc | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc index fc87fea5..f311b4c6 100644 --- a/src/buffer_utils.cc +++ b/src/buffer_utils.cc @@ -263,7 +263,8 @@ Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, AutoScroll if (insert_begin) { - auto insert_back = m_had_trailing_newline ? m_buffer.back_coord() : m_buffer.prev(m_buffer.back_coord()); + auto insert_back = (m_had_trailing_newline and m_scroll == AutoScroll::No) + ? m_buffer.back_coord() : m_buffer.prev(m_buffer.back_coord()); m_buffer.run_hook_in_own_context( Hook::BufReadFifo, selection_to_string(ColumnType::Byte, m_buffer, {*insert_begin, insert_back})); |
