url-mode: fix auto-detection of URLs in the top corner of the viewport

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 <n> 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 <n> 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"
This commit is contained in:
Daniel Eklöf 2021-03-06 13:06:54 +01:00
parent e8a8d122f0
commit be980a6282
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -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++) {