[epiphany] Add CTRL+Enter url auto completion



commit c5467348cf2c0daadaedd4d5cc881a135d20e52e
Author: Jan-Michael Brummer <jan brummer tabos org>
Date:   Sun Feb 24 19:25:04 2019 +0100

    Add CTRL+Enter url auto completion
    
    Adds a shortcut to auto complete a non valid url to www."url text".com
    
    Fixes: https://gitlab.gnome.org/GNOME/epiphany/issues/645

 lib/widgets/ephy-location-entry.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)
---
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index a663a0831..b7445f9f5 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -530,10 +530,28 @@ entry_key_press_cb (GtkEntry          *entry,
       g_signal_handlers_unblock_by_func (location_entry->url_entry, G_CALLBACK (editable_changed_cb), 
location_entry);
     }
 
+    if (state == GDK_CONTROL_MASK) {
+      g_autofree gchar *text = g_strdup (gtk_entry_get_text (GTK_ENTRY (location_entry->url_entry)));
+      gchar *url = g_strstrip (text);
+
+      /* Remove control mask to prevent opening address in a new window */
+      event->state &= ~GDK_CONTROL_MASK;
+
+      if (!g_utf8_strchr (url, -1, ' ') && !g_utf8_strchr (url, -1, '.')) {
+        g_autofree gchar *new_url = g_strdup_printf ("www.%s.com", 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 GDK_EVENT_STOP;
   }
 
-  return FALSE;
+  return GDK_EVENT_PROPAGATE;
 }
 
 static void


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