diff options
author | Patrick McDermott <pj@pehjota.net> | 2017-09-26 02:21:17 (EDT) |
---|---|---|
committer | Patrick McDermott <pj@pehjota.net> | 2017-09-26 02:26:35 (EDT) |
commit | 92fe4ae2f819abb70a0ea9405347e169deea8eac (patch) | |
tree | fe8b70c97cb29f0e549d94dc02f321d18e254c6b /src | |
parent | d1920eadf30437f3e122415a520e0186085a9b80 (diff) | |
download | marquee-92fe4ae2f819abb70a0ea9405347e169deea8eac.zip marquee-92fe4ae2f819abb70a0ea9405347e169deea8eac.tar.gz marquee-92fe4ae2f819abb70a0ea9405347e169deea8eac.tar.bz2 |
MqTabChrome: Save user edits to hovered link URI
Don't overwrite such edited URI bar text on mouse target change.
Diffstat (limited to 'src')
-rw-r--r-- | src/tab-chrome.c | 31 | ||||
-rw-r--r-- | src/tab-chrome.h | 1 |
2 files changed, 27 insertions, 5 deletions
diff --git a/src/tab-chrome.c b/src/tab-chrome.c index dc91c9e..71f3ae6 100644 --- a/src/tab-chrome.c +++ b/src/tab-chrome.c @@ -506,6 +506,8 @@ load_failed_cb(WebKitWebView __attribute__((unused)) *web_view, return FALSE; } +/* TODO: <Esc> key in URI bar should reset to URI of current hovered link, if + * any, even if different from chrome->hovered_link_uri. */ static void mouse_target_changed_cb(WebKitWebView __attribute__((unused)) *web_view, WebKitHitTestResult *hit_test_result, @@ -513,11 +515,20 @@ mouse_target_changed_cb(WebKitWebView __attribute__((unused)) *web_view, MqTabChrome *chrome) { if (webkit_hit_test_result_context_is_link(hit_test_result)) { - if (g_strcmp0(gtk_entry_get_text(GTK_ENTRY(chrome->uri_entry)), + if (chrome->hovered_link_uri && g_strcmp0(gtk_entry_get_text( + GTK_ENTRY(chrome->uri_entry)), + chrome->hovered_link_uri) != 0) { + /* The user has edited the hovered link URI in the URI + * bar. */ + } else if (g_strcmp0(gtk_entry_get_text( + GTK_ENTRY(chrome->uri_entry)), webkit_web_view_get_uri(web_view)) == 0) { - gtk_entry_set_text(GTK_ENTRY(chrome->uri_entry), + g_free(chrome->hovered_link_uri); + chrome->hovered_link_uri = g_strdup( webkit_hit_test_result_get_link_uri( hit_test_result)); + gtk_entry_set_text(GTK_ENTRY(chrome->uri_entry), + chrome->hovered_link_uri); gtk_entry_set_attributes(GTK_ENTRY(chrome->uri_entry), chrome->hovered_link_style); } else if (gtk_entry_get_attributes( @@ -526,13 +537,21 @@ mouse_target_changed_cb(WebKitWebView __attribute__((unused)) *web_view, /* The URI bar's text differs from the Web view's URI * because the mouse was already targeting a different * link. */ - gtk_entry_set_text(GTK_ENTRY(chrome->uri_entry), + g_free(chrome->hovered_link_uri); + chrome->hovered_link_uri = g_strdup( webkit_hit_test_result_get_link_uri( hit_test_result)); + gtk_entry_set_text(GTK_ENTRY(chrome->uri_entry), + chrome->hovered_link_uri); } - } else { - if (gtk_entry_get_attributes(GTK_ENTRY(chrome->uri_entry)) == + } else if (gtk_entry_get_attributes(GTK_ENTRY(chrome->uri_entry)) == chrome->hovered_link_style) { + if (g_strcmp0(gtk_entry_get_text(GTK_ENTRY(chrome->uri_entry)), + chrome->hovered_link_uri) == 0) { + /* The user hasn't edited the hovered link URI in the + * URI bar. */ + g_free(chrome->hovered_link_uri); + chrome->hovered_link_uri = NULL; gtk_entry_set_text(GTK_ENTRY(chrome->uri_entry), webkit_web_view_get_uri(web_view)); gtk_entry_set_attributes(GTK_ENTRY(chrome->uri_entry), @@ -598,6 +617,8 @@ loading_cb(WebKitWebView *web_view, static void connect_web_view(MqTabChrome *chrome) { + chrome->hovered_link_uri = NULL; + g_signal_connect(chrome->web_view, "load-changed", G_CALLBACK(load_changed_cb), chrome); g_signal_connect(chrome->web_view, "load-failed", diff --git a/src/tab-chrome.h b/src/tab-chrome.h index 1275de4..01e75f1 100644 --- a/src/tab-chrome.h +++ b/src/tab-chrome.h @@ -37,6 +37,7 @@ struct MqTabChrome { GtkToolItem *stop_reload_button; GtkWidget *uri_entry; PangoAttrList *hovered_link_style; + gchar *hovered_link_uri; WebKitWebView *web_view; gboolean load_failed; GtkWidget *back_forward_popover; |