summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-10-11 08:15:03 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-10-11 08:15:03 +0300
commit463174066a2490522afc9b4dc95efeffbc498354 (patch)
treef90aa69ba3473a9adf76f91f895d95c9144f49d6
parenta4bb1b093e1a452831b55dc40efb38c5479b13b5 (diff)
Focus behavior of the URL entry field
Opening a new tab will now set input focus to the URL field. Switching tabs when the URL field is focused will select the full new URL. There was an issue previously where selecting a bookmark while the URL field was focused would cause unexpected behavior. The URL was first unfocused and that would trigger the document to fetch the URL that was in the input field.
-rw-r--r--src/app.c5
-rw-r--r--src/ui/inputwidget.c10
-rw-r--r--src/ui/window.c6
3 files changed, 14 insertions, 7 deletions
diff --git a/src/app.c b/src/app.c
index 0916919e..347e3661 100644
--- a/src/app.c
+++ b/src/app.c
@@ -959,7 +959,7 @@ iBool handleCommand_App(const char *cmd) {
959 const iBool isDuplicate = argLabel_Command(cmd, "duplicate") != 0; 959 const iBool isDuplicate = argLabel_Command(cmd, "duplicate") != 0;
960 newTab_App(isDuplicate ? document_App() : NULL, iTrue); 960 newTab_App(isDuplicate ? document_App() : NULL, iTrue);
961 if (!isDuplicate) { 961 if (!isDuplicate) {
962 postCommand_App("navigate.home"); 962 postCommand_App("navigate.home focus:1");
963 } 963 }
964 return iTrue; 964 return iTrue;
965 } 965 }
@@ -1055,6 +1055,9 @@ iBool handleCommand_App(const char *cmd) {
1055 cstr_String(constAt_StringSet(urls, iRandoms(0, size_StringSet(urls))))); 1055 cstr_String(constAt_StringSet(urls, iRandoms(0, size_StringSet(urls)))));
1056 } 1056 }
1057 } 1057 }
1058 if (argLabel_Command(cmd, "focus")) {
1059 postCommand_App("navigate.focus");
1060 }
1058 return iTrue; 1061 return iTrue;
1059 } 1062 }
1060 else if (equal_Command(cmd, "bookmark.add")) { 1063 else if (equal_Command(cmd, "bookmark.add")) {
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c
index d29548f1..0fcca40a 100644
--- a/src/ui/inputwidget.c
+++ b/src/ui/inputwidget.c
@@ -181,8 +181,14 @@ void setText_InputWidget(iInputWidget *d, const iString *text) {
181 iConstForEach(String, i, text) { 181 iConstForEach(String, i, text) {
182 pushBack_Array(&d->text, &i.value); 182 pushBack_Array(&d->text, &i.value);
183 } 183 }
184 iZap(d->mark); 184 if (isFocused_Widget(d)) {
185 d->cursor = iMin(d->cursor, size_Array(&d->text)); 185 d->cursor = size_Array(&d->text);
186 selectAll_InputWidget(d);
187 }
188 else {
189 d->cursor = iMin(d->cursor, size_Array(&d->text));
190 iZap(d->mark);
191 }
186 refresh_Widget(as_Widget(d)); 192 refresh_Widget(as_Widget(d));
187} 193}
188 194
diff --git a/src/ui/window.c b/src/ui/window.c
index b90b2b55..41d8078f 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -236,7 +236,8 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
236 setText_InputWidget(url, url_DocumentWidget(document_App())); 236 setText_InputWidget(url, url_DocumentWidget(document_App()));
237 return iTrue; 237 return iTrue;
238 } 238 }
239 if (arg_Command(cmd) && !isFocused_Widget(findWidget_App("lookup"))) { 239 if (arg_Command(cmd) && argLabel_Command(cmd, "enter") &&
240 !isFocused_Widget(findWidget_App("lookup"))) {
240 postCommandf_App( 241 postCommandf_App(
241 "open url:%s", 242 "open url:%s",
242 cstr_String(absoluteUrl_String(&iStringLiteral(""), text_InputWidget(url)))); 243 cstr_String(absoluteUrl_String(&iStringLiteral(""), text_InputWidget(url))));
@@ -261,9 +262,6 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) {
261 } 262 }
262 else if (equal_Command(cmd, "document.request.started")) { 263 else if (equal_Command(cmd, "document.request.started")) {
263 iInputWidget *url = findChild_Widget(navBar, "url"); 264 iInputWidget *url = findChild_Widget(navBar, "url");
264 if (isFocused_Widget(as_Widget(url))) {
265 setFocus_Widget(NULL);
266 }
267 setTextCStr_InputWidget(url, suffixPtr_Command(cmd, "url")); 265 setTextCStr_InputWidget(url, suffixPtr_Command(cmd, "url"));
268 updateTextCStr_LabelWidget(reloadButton, stopCStr_); 266 updateTextCStr_LabelWidget(reloadButton, stopCStr_);
269 return iFalse; 267 return iFalse;