From 92fe4ae2f819abb70a0ea9405347e169deea8eac Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Tue, 26 Sep 2017 02:21:17 -0400 Subject: MqTabChrome: Save user edits to hovered link URI Don't overwrite such edited URI bar text on mouse target change. --- (limited to 'src/tab-chrome.c') 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: 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", -- cgit v0.9.1