From 0642058b3eb0cdee90adaf405f5aac2b6c00965b Mon Sep 17 00:00:00 2001 From: Jason Felice Date: Thu, 6 Jun 2019 17:21:30 -0400 Subject: [PATCH] Fix emission of BufReadFifo events The hook parameter should not be adjusted for the prevention of scrolling. Also, ensure that the last BufReadFifo is triggered if we encounter an error or EOF after appending some data to the buffer. Closes #2946 --- src/buffer_utils.cc | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc index bb0669ff..66f5436c 100644 --- a/src/buffer_utils.cc +++ b/src/buffer_utils.cc @@ -129,17 +129,18 @@ Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, bool scroll // iteration number allows us to go back go back to the event loop and // handle other events sources (such as input) constexpr size_t max_loop = 16; + bool closed = false; size_t loop = 0; char data[buffer_size]; - BufferCoord insert_coord; + BufferCoord insert_coord = buffer->back_coord(); const int fifo = watcher.fd(); do { const ssize_t count = ::read(fifo, data, buffer_size); if (count <= 0) { - buffer->values().erase(fifo_watcher_id); // will delete this - return; + closed = true; + break; } auto pos = buffer->back_coord(); @@ -147,8 +148,6 @@ Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, bool scroll if (prevent_scrolling) pos = buffer->next(pos); - if (loop == 0) - insert_coord = pos; buffer->insert(pos, StringView(data, data+count)); if (prevent_scrolling) @@ -162,8 +161,14 @@ Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, bool scroll } while (++loop < max_loop and fd_readable(fifo)); - buffer->run_hook_in_own_context(Hook::BufReadFifo, - selection_to_string({insert_coord, buffer->back_coord()})); + if (insert_coord != buffer->back_coord()) + { + buffer->run_hook_in_own_context(Hook::BufReadFifo, + selection_to_string({insert_coord, buffer->back_coord()})); + } + + if (closed) + buffer->values().erase(fifo_watcher_id); // will delete this }), std::move(watcher_deleter)); buffer->values()[fifo_watcher_id] = Value(std::move(watcher));