[epiphany] Allow to leave out slashes in URL between URL scheme and scheme specific part



commit 75db37c993467970ae358c72d6cd7734ff7b6d35
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Wed Feb 27 21:16:40 2019 +0100

    Allow to leave out slashes in URL between URL scheme and scheme specific part
    
    Allow writing http and https urls without slashes.
    
    Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/377

 lib/widgets/ephy-location-entry.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
---
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 5dac616ce..a663a0831 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -514,8 +514,24 @@ entry_key_press_cb (GtkEntry          *entry,
 
   if (event->keyval == GDK_KEY_Return ||
       event->keyval == GDK_KEY_KP_Enter ||
-      event->keyval == GDK_KEY_ISO_Enter)
+      event->keyval == GDK_KEY_ISO_Enter) {
+    g_autofree gchar *text = g_strdup (gtk_entry_get_text (GTK_ENTRY (location_entry->url_entry)));
+    gchar *url = g_strstrip (text);
+    g_autofree gchar *new_url = NULL;
+
+    if (strlen (url) > 5 && g_str_has_prefix (url, "http:") && url[5] != '/')
+      new_url = g_strdup_printf ("http://%s";, url + 5);
+    else if (strlen (url) > 6 && g_str_has_prefix (url, "https:") && url[6] != '/')
+      new_url = g_strdup_printf ("https://%s";, url + 6);
+
+    if (new_url) {
+      g_signal_handlers_block_by_func (location_entry->url_entry, G_CALLBACK (editable_changed_cb), 
location_entry);
+      gtk_entry_set_text (GTK_ENTRY (location_entry->url_entry), new_url);
+      g_signal_handlers_unblock_by_func (location_entry->url_entry, G_CALLBACK (editable_changed_cb), 
location_entry);
+    }
+
     ephy_location_entry_activate (location_entry);
+  }
 
   return FALSE;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]