about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJosh Rickmar <jrick@devio.us>2012-07-05 10:10:34 -0400
committerJosh Rickmar <jrick@devio.us>2012-07-05 10:10:34 -0400
commit72ce72c612c1782aa9293e9798768f3ca808e736 (patch)
treeb88f3ba020af7dda51e356bc69e2507efb1de509
parenta5b5e1de045cab38f969984f66addc840a7fb89c (diff)
downloadxombrero-72ce72c612c1782aa9293e9798768f3ca808e736.tar.gz
Make the autofocus code a bit smarter by first saving the original
text in the text box and seeing if it's any different from the new
text before attempting to enter command mode.  Before, there was only
a check to see if there was any text.  This also only sets t->active
if it is not NULL, so only the page's default text entry box is ever
used when entering insert_mode, instead of the last text box that was
typed into.
-rw-r--r--inputfocus.c12
-rw-r--r--xombrero.c4
-rw-r--r--xombrero.h1
3 files changed, 14 insertions, 3 deletions
diff --git a/inputfocus.c b/inputfocus.c
index ab69947..951782d 100644
--- a/inputfocus.c
+++ b/inputfocus.c
@@ -239,8 +239,11 @@ dom_is_input(struct tab *t, char **text)
 		aa = (WebKitDOMHTMLElement*)a;
 		if (WEBKIT_DOM_IS_HTML_ELEMENT(aa) &&
 		    webkit_dom_html_element_get_is_content_editable(aa)) {
-			t->active = a;
+			if (t->active == NULL)
+				t->active = a;
 			*text = get_element_text((WebKitDOMNode *)a);
+			if (t->active_text == NULL)
+				t->active_text = g_strdup(*text);
 			return (1);
 		}
 		break;
@@ -251,8 +254,11 @@ dom_is_input(struct tab *t, char **text)
 
 	if (WEBKIT_DOM_IS_HTML_INPUT_ELEMENT((WebKitDOMNode *)a) ||
 	    WEBKIT_DOM_IS_HTML_TEXT_AREA_ELEMENT((WebKitDOMNode *)a)) {
-		t->active = a;
+		if (t->active == NULL)
+			t->active = a;
 		*text = get_element_text((WebKitDOMNode *)a);
+		if (t->active_text == NULL)
+			t->active_text = g_strdup(*text);
 		return (1);
 	}
 
@@ -302,7 +308,7 @@ input_autofocus(struct tab *t)
 			t->mode = XT_MODE_COMMAND;
 	} else {
 		if (dom_is_input(t, &text)) {
-			if (text != NULL && g_strcmp0(text, "")) {
+			if (text != NULL && g_strcmp0(text, t->active_text)) {
 				g_free(text);
 				t->mode = XT_MODE_INSERT;
 			} else if (t->active) {
diff --git a/xombrero.c b/xombrero.c
index 3802e0e..0b5c10d 100644
--- a/xombrero.c
+++ b/xombrero.c
@@ -4122,6 +4122,10 @@ notify_load_status_cb(WebKitWebView* wview, GParamSpec* pspec, struct tab *t)
 
 		/* DOM is changing, unreference the previous focused element */
 		t->active = NULL;
+		if (t->active_text) {
+			g_free(t->active_text);
+			t->active_text = NULL;
+		}
 
 		/* take focus if we are visible */
 		focus_webview(t);
diff --git a/xombrero.h b/xombrero.h
index feb0d4c..9971804 100644
--- a/xombrero.h
+++ b/xombrero.h
@@ -288,6 +288,7 @@ struct tab {
 
 	/* focused text entry */
 	WebKitDOMElement	*active;
+	char			*active_text;
 };
 TAILQ_HEAD(tab_list, tab);