url-mode: off-by-one error in end-point column of auto-detected URLs

When an auto-detected URL ended *on* the right-most column, the URL
endpoint was off by one, resulting in the underline in URL mode being
one character short.
This commit is contained in:
Daniel Eklöf 2021-06-01 18:58:26 +02:00
parent 19429d13a3
commit 974c3acd78
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 13 additions and 5 deletions

View file

@ -147,6 +147,8 @@
around (https://codeberg.org/dnkl/foot/issues/552). around (https://codeberg.org/dnkl/foot/issues/552).
* Selection incorrectly wrapping rows ending with an explicit newline * Selection incorrectly wrapping rows ending with an explicit newline
(https://codeberg.org/dnkl/foot/issues/565). (https://codeberg.org/dnkl/foot/issues/565).
* Off-by-one error in markup of auto-detected URLs when the URL ends
in the right-most column.
### Security ### Security

View file

@ -320,14 +320,16 @@ auto_detected(const struct terminal *term, enum url_action action,
break; break;
} }
if (c >= term->cols - 1 && row->linebreak) if (c >= term->cols - 1 && row->linebreak) {
/*
* Endpoint is inclusive, and well be subtracting
* 1 from the column when emitting the URL.
*/
c++;
emit_url = true; emit_url = true;
}
if (emit_url) { if (emit_url) {
/* Heuristic to remove trailing characters that
* are valid URL characters, but typically not at
* the end of the URL */
bool done = false;
struct coord end = {c, r}; struct coord end = {c, r};
if (--end.col < 0) { if (--end.col < 0) {
@ -335,6 +337,10 @@ auto_detected(const struct terminal *term, enum url_action action,
end.col = term->cols - 1; end.col = term->cols - 1;
} }
/* Heuristic to remove trailing characters that
* are valid URL characters, but typically not at
* the end of the URL */
bool done = false;
do { do {
switch (url[len - 1]) { switch (url[len - 1]) {
case L'.': case L',': case L':': case L';': case L'?': case L'.': case L',': case L':': case L';': case L'?':