Always links by number with Return and remove styles

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.
This commit is contained in:
Alexander Friesen 2011-03-05 00:12:44 +01:00 committed by Christian Dywan
parent 3e47ac9e3f
commit 353924a117

View file

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