summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohannes Altmanninger <aclopte@gmail.com>2024-11-23 10:54:35 +0100
committerMaxime Coste <mawww@kakoune.org>2024-11-28 08:09:30 +1100
commit658915086fc4883c45f1af98f1b37a01822e9feb (patch)
tree0fc29916c14bccfc0305736231f3594113a8138f /src
parent5d378fa3a5139ca7c075ddf1a533856f53943f73 (diff)
Fix BufReadFifo overlapping range on partial line
As reported in [1], when reading from a fifo a buffer that is not newline-terminated, we add a newline automatically, and include that in the range reported to BufReadFifo. I'm not 100% sure if this is really wrong but since the typical consumer of BufReadFifo does something like select %val{hook_param} exec |grep foo<ret> it seems safe to remove this newline; doing so means that 1. "grep foo" will no longer see a newline in stdin, which seems good. 2. Kakoune will strip a trailing newline from the command output, since the input didn't have one. So the input is the same. Let's remove any artificially-added newline from the hook parameter. [1]: https://lists.sr.ht/~mawww/kakoune/%3CZzXjfXnETd2gbeXa@thristian.org%3E
Diffstat (limited to 'src')
-rw-r--r--src/buffer_utils.cc5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/buffer_utils.cc b/src/buffer_utils.cc
index 9a46504d..5e55036c 100644
--- a/src/buffer_utils.cc
+++ b/src/buffer_utils.cc
@@ -258,9 +258,12 @@ Buffer* create_fifo_buffer(String name, int fd, Buffer::Flags flags, bool scroll
}
if (insert_begin)
+ {
+ auto insert_back = m_had_trailing_newline ? 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, m_buffer.back_coord()}));
+ selection_to_string(ColumnType::Byte, m_buffer, {*insert_begin, insert_back}));
+ }
if (closed)
m_buffer.values().erase(fifo_watcher_id); // will delete this