]> spindle.queued.net Git - midori/commitdiff
Always links by number with Return and remove styles
authorAlexander Friesen <a_06357@fastmail.fm>
Fri, 4 Mar 2011 23:12:44 +0000 (00:12 +0100)
committerChristian Dywan <christian@twotoasts.de>
Fri, 4 Mar 2011 23:23:33 +0000 (00:23 +0100)
Return is always required to confirm the typed number, which
is consistent and more usable with Control for new tab.

Hiding links now actually removes the extra spans.

Opening links in a new tab keeps the links visible.

Escape resets the typed digits.

midori/midori-view.c

index fc1948b2ee2df4203315b4d90a210a931856dcf4..d0cb178efc1e6b6ad5b2952ba38fcc45122c0840 100644 (file)
@@ -1866,28 +1866,29 @@ gtk_widget_key_press_event_cb (WebKitWebView* web_view,
                 NULL);
             view->find_links = 0;
         }
-        else if (digit != -1 || event->keyval == GDK_Return)
+        else if (digit != -1 && event->keyval != GDK_Return && event->keyval != GDK_Escape)
+        {
+            if (view->find_links > -1)
+                view->find_links *= 10;
+            view->find_links += digit;
+        }
+        else if (event->keyval == GDK_Escape)
+        {
+            view->find_links = 0;
+        }
+        else if (event->keyval == GDK_Return)
         {
             gchar* script;
-            if (event->keyval != GDK_Return)
-            {
-                if (view->find_links > -1)
-                    view->find_links *= 10;
-                view->find_links += digit;
-            }
             script = g_strdup_printf (
                 "var links = document.getElementsByClassName ('midoriHKD87346');"
                 "var i = %d; var return_key = %d;"
-                "if (return_key || typeof links[i * 10] == 'undefined') {"
-                "    for (var j = 0; j < links.length; j++)"
-                "        links[j].style.display = 'none !important';"
+                "if (return_key) {"
                 "    if (typeof links[i] != 'undefined')"
                 "        links[i].parentNode.href; }",
                 view->find_links, event->keyval == GDK_Return);
             result = sokoke_js_script_eval (js_context, script, NULL);
             if (result && strstr (result, "://"))
             {
-                view->find_links = -1;
                 if (MIDORI_MOD_NEW_TAB (event->state))
                 {
                     gboolean background = view->open_tabs_in_the_background;
@@ -1896,20 +1897,33 @@ gtk_widget_key_press_event_cb (WebKitWebView* web_view,
                     g_signal_emit (view, signals[NEW_TAB], 0, result, background);
                 }
                 else
+                {
+                    gchar* dummy = sokoke_js_script_eval (js_context,
+                        "var links = document.getElementsByClassName ('midoriHKD87346');"
+                        "for (var i = links.length - 1; i >= 0; i--) {"
+                        "   var parent = links[i].parentNode;"
+                        "   parent.removeChild(links[i]); }",
+                        NULL);
+                    g_free (dummy);
+                    view->find_links = -1;
                     midori_view_set_uri (view, result);
+                }
             }
             g_free (script);
+            g_free (result);
+            view->find_links = 0;
         }
         else
         {
             result = sokoke_js_script_eval (js_context,
                 "var links = document.getElementsByClassName ('midoriHKD87346');"
-                "for (var i = 0; i < links.length; i++)"
-                "  links[i].style.display = 'none !important';",
+                "for (var i = links.length - 1; i >= 0; i--) {"
+                "   var parent = links[i].parentNode;"
+                "   parent.removeChild(links[i]); }",
                 NULL);
+            g_free (result);
             view->find_links = -1;
         }
-        g_free (result);
         return FALSE;
     }