From 456ca26906e84e3cadd670328ed5dca7718da50c Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Tue, 23 Feb 2021 11:58:10 +0200 Subject: "Go to Root" respects user names in URL The behavior of navigating to root should match what is displayed in the top banner. --- src/ui/documentwidget.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) (limited to 'src/ui') diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 2e81838f..146b0de7 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -1025,17 +1025,7 @@ static void updateTrust_DocumentWidget_(iDocumentWidget *d, const iGmResponse *r } static void parseUser_DocumentWidget_(iDocumentWidget *d) { - clear_String(d->titleUser); - iRegExp *userPats[2] = { new_RegExp("~([^/?]+)", 0), - new_RegExp("/users/([^/?]+)", caseInsensitive_RegExpOption) }; - iRegExpMatch m; - init_RegExpMatch(&m); - iForIndices(i, userPats) { - if (matchString_RegExp(userPats[i], d->mod.url, &m)) { - setRange_String(d->titleUser, capturedRange_RegExpMatch(&m, 1)); - } - iRelease(userPats[i]); - } + setRange_String(d->titleUser, urlUser_String(d->mod.url)); } static iBool updateFromHistory_DocumentWidget_(iDocumentWidget *d) { @@ -1956,9 +1946,14 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) else if (equal_Command(cmd, "navigate.root") && document_App() == d) { iUrl parts; init_Url(&parts, d->mod.url); + const char *rootEnd = parts.path.start; + const iRangecc user = urlUser_String(d->mod.url); + if (!isEmpty_Range(&user)) { + rootEnd = user.end; + } postCommandf_App( "open url:%s/", - cstr_Rangecc((iRangecc){ constBegin_String(d->mod.url), parts.path.start })); + cstr_Rangecc((iRangecc){ constBegin_String(d->mod.url), rootEnd })); return iTrue; } else if (equalWidget_Command(cmd, w, "scroll.moved")) { -- cgit v1.2.3