From be980a62825a01b7c3a6b62cf59a3161bf7e0ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 6 Mar 2021 13:06:54 +0100 Subject: [PATCH] url-mode: fix auto-detection of URLs in the top corner of the viewport MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ‘proto_chars’ variable is kind of like a FIFO, where characters from the grid is pushed to the back of it. I.e. the last bytes are at the *end* of the array. This was what the protocol matching logic expected. However, it was only true after reading ‘max_prot_len’ characters from the grid. Before that, the last bytes from the grid was in the *beginning* of ‘proto_chars’. This meant we did not detect URLs starting in the top left corner of the viewport. Test case: foot sh -c "echo http://test.com && sleep 9999" --- url-mode.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/url-mode.c b/url-mode.c index 362ea3af..6aa56a43 100644 --- a/url-mode.c +++ b/url-mode.c @@ -259,11 +259,11 @@ auto_detected(const struct terminal *term, enum url_action action, proto_start[i] = proto_start[i + 1]; } - if (proto_char_count == max_prot_len) - proto_char_count--; + if (proto_char_count >= max_prot_len) + proto_char_count = max_prot_len - 1; - proto_chars[proto_char_count] = wc; - proto_start[proto_char_count] = (struct coord){c, r}; + proto_chars[max_prot_len - 1] = wc; + proto_start[max_prot_len - 1] = (struct coord){c, r}; proto_char_count++; for (size_t i = 0; i < ALEN(prots); i++) {