summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/vimb.18
-rw-r--r--src/dom.c39
-rw-r--r--src/hints.c6
3 files changed, 30 insertions, 23 deletions
diff --git a/doc/vimb.1 b/doc/vimb.1
index aa0ff33..4e2e5bd 100644
--- a/doc/vimb.1
+++ b/doc/vimb.1
@@ -1335,9 +1335,11 @@ Foreground of statusbar for untrusted https pages.
Statusbar font for untrusted https pages.
.TP
.B strict-focus (bool)
-Indicates if vimb follows the instruction of the page to focus a form field
-without user interaction. If set the true, vimb will no switch to input mode
-if the pages say so and vimb will remove the focus from the form field.
+Vimb checks if an editable element is focused and switch to input mode. If
+strict-focus is enabled, this isn't done for focused element on page load
+(without user interaction), instead the focus is removed from the focused
+element. Focus changed that appear after the page was completely loaded are
+not affected by this setting.
.TP
.B strict-ssl (bool)
If 'on', vimb will not load a untrusted https site.
diff --git a/src/dom.c b/src/dom.c
index bd6f6a5..561e3b8 100644
--- a/src/dom.c
+++ b/src/dom.c
@@ -32,24 +32,28 @@ static Element *get_active_element(Document *doc);
void dom_check_auto_insert(WebKitWebView *view)
{
- Document *doc = webkit_web_view_get_dom_document(view);
- Element *active = get_active_element(doc);
+ Element *active;
+ HtmlElement *element;
+ Document *doc = webkit_web_view_get_dom_document(view);
+
+ if (vb.config.strict_focus) {
+ /* if there is focus on an element right after page load - remove it
+ * if strict-focus is enabled */
+ dom_clear_focus(view);
+ } else {
+ /* if active element is editable - switch vimb to input mode */
+ active = get_active_element(doc);
+ auto_insert(active);
+ }
- if (vb.config.strict_focus || !auto_insert(active)) {
- /* if the strict-focus is on also blur the possible active element */
- if (vb.config.strict_focus) {
- dom_clear_focus(view);
- }
- /* the focus was not set automatically - add event listener to track
- * focus events on the document */
- HtmlElement *element = webkit_dom_document_get_body(doc);
- if (!element) {
- element = WEBKIT_DOM_HTML_ELEMENT(webkit_dom_document_get_document_element(doc));
- }
- webkit_dom_event_target_add_event_listener(
- WEBKIT_DOM_EVENT_TARGET(element), "focus", G_CALLBACK(editable_focus_cb), false, NULL
- );
+ /* add event listener to track focus events on the document */
+ element = webkit_dom_document_get_body(doc);
+ if (!element) {
+ element = WEBKIT_DOM_HTML_ELEMENT(webkit_dom_document_get_document_element(doc));
}
+ webkit_dom_event_target_add_event_listener(
+ WEBKIT_DOM_EVENT_TARGET(element), "focus", G_CALLBACK(editable_focus_cb), true, NULL
+ );
}
/**
@@ -209,9 +213,6 @@ static gboolean auto_insert(Element *element)
static gboolean editable_focus_cb(Element *element, Event *event)
{
- webkit_dom_event_target_remove_event_listener(
- WEBKIT_DOM_EVENT_TARGET(element), "focus", G_CALLBACK(editable_focus_cb), false
- );
if (vb.mode->id != 'i') {
EventTarget *target = webkit_dom_event_get_target(event);
auto_insert((void*)target);
diff --git a/src/hints.c b/src/hints.c
index fbeb631..9dec4ad 100644
--- a/src/hints.c
+++ b/src/hints.c
@@ -302,7 +302,11 @@ static gboolean call_hints_function(const char *func, int count, JSValueRef para
/* following return values mark fired hints */
if (!strncmp(value, "DONE:", 5)) {
fire_timeout(false);
- if (!hints.gmode) {
+ /* Change to normal mode only if we are crrently in command mode and
+ * we are not in g-mode hinting. This is required to not switch to
+ * normal mode when the hinting triggered a click that set focus on
+ * editable element that lead vimb to switch to input mode. */
+ if (!hints.gmode && vb.mode->id == 'c') {
mode_enter('n');
}
} else if (!strncmp(value, "INSERT:", 7)) {