url-mode: use the first *sub* expression as URL

When auto-matching URLs (or custom regular expressions), use the
first *subexpression* as URL, rather than the while regex match.

This allows us to write custom regular expressions with prefix/suffix
strings that should not be included in the presented match.
This commit is contained in:
Daniel Eklöf 2025-02-03 13:56:57 +01:00
parent 31f536ff8c
commit a984531ce5
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 51 additions and 28 deletions

View file

@ -400,13 +400,13 @@ regex_detected(const struct terminal *term, enum url_action action,
if (r == REG_NOMATCH)
break;
const size_t mlen = matches[0].rm_eo - matches[0].rm_so;
const size_t start = &search_string[matches[0].rm_so] - v->utf8;
const size_t mlen = matches[1].rm_eo - matches[1].rm_so;
const size_t start = &search_string[matches[1].rm_so] - v->utf8;
const size_t end = start + mlen;
LOG_DBG(
"regex match at row %d: %.*srow/col = %dx%d",
matches[0].rm_so, (int)mlen, &search_string[matches[0].rm_so],
matches[1].rm_so, (int)mlen, &search_string[matches[1].rm_so],
v->map[start].row, v->map[start].col);
tll_push_back(