diff options
-rw-r--r-- | common/content/hints.js | 98 | ||||
-rw-r--r-- | vimperator/NEWS | 1 | ||||
-rw-r--r-- | vimperator/locale/en-US/options.txt | 50 |
3 files changed, 122 insertions, 27 deletions
diff --git a/common/content/hints.js b/common/content/hints.js index c263ae30..0e112c3b 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -131,13 +131,15 @@ function Hints() //{{{ let baseNodeAbsolute = util.xmlToDom(<span highlight="Hint"/>, doc); - let elem, tagname, text, span, rect; + let elem, tagname, text, span, rect, showtext; let res = buffer.evaluateXPath(hintMode.tags(), doc, null, true); let fragment = util.xmlToDom(<div highlight="hints"/>, doc); let start = pageHints.length; for (let elem in res) { + showtext = false; + // TODO: for iframes, this calculation is wrong rect = elem.getBoundingClientRect(); if (!rect || rect.top > height || rect.bottom < 0 || rect.left > width || rect.right < 0) @@ -152,14 +154,75 @@ function Hints() //{{{ continue; tagname = elem.localName.toLowerCase(); - if (tagname == "input" || tagname == "textarea") - text = elem.value; - else if (tagname == "select") + if (tagname == "input" || tagname == "select" || tagname == "textarea") { - if (elem.selectedIndex >= 0) - text = elem.item(elem.selectedIndex).text; + //TODO: Split this out somewhere... + // <input type="submit|button|reset"> Always use the value + // <input type="radio|checkbox"> Use the value if it is not numeric or label or name + // <input type="password"> Never use the value, use label or name + // <input type="text|file"> <textarea> Use value if set or label or name + // <input type="image"> Use the alt text if present (showtext) or label or name + // <input type="hidden"> Never gets here + // <select> Use the text of the selected item or label or name + text = ""; + let type = elem.type ? elem.type.toLowerCase() : ""; + + if (tagname == "input" && (type == "submit" || type == "button" || type == "reset")) + { + text = elem.value + } else - text = ""; + { + for each (let option in options["hintinputs"].split(",")) + { + if (option == "value") + { + if (tagname == "select") + { + if (elem.selectedIndex >= 0) + text = elem.item(elem.selectedIndex).text; + } + else if (type == "image") + { + if (elem.alt) + { + text = elem.alt; + showtext = true; + } + } + else if (elem.value && type != "password") + { + // radio's and checkboxes often use internal ids as values - maybe make this an option too... + if (! ((type == "radio" || type == "checkbox") && !isNaN(elem.value))) + { + text = elem.value + showtext = true; + } + } + } + else if (option == "label") + { + if (elem.id) + { + //TODO: (possibly) do some guess work for label-like objects + let label = buffer.evaluateXPath("//label[@for='"+elem.id+"']", doc).snapshotItem(0); + if (label) + { + text = label.textContent.toLowerCase(); + showtext = true; + } + } + } + else if (option == "name") + { + text = elem.name; + showtext = true; + } + + if(text) + break; + } + } } else text = elem.textContent.toLowerCase(); @@ -237,7 +300,7 @@ function Hints() //{{{ span.style.top = toppos + "px"; fragment.appendChild(span); - pageHints.push([elem, text, span, null, elem.style.backgroundColor, elem.style.color]); + pageHints.push([elem, text, span, null, elem.style.backgroundColor, elem.style.color, showtext]); } if (doc.body) @@ -276,7 +339,7 @@ function Hints() //{{{ function showHints() { - let elem, tagname, text, rect, span, imgspan; + let elem, tagname, text, rect, span, imgspan, _a, _b, showtext; let hintnum = 1; let validHint = hintMatcher(hintString.toLowerCase()); let activeHint = hintNumber || 1; @@ -291,7 +354,7 @@ function Hints() //{{{ for (let i in (util.interruptibleRange(start, end + 1, 500))) { let hint = pageHints[i]; - [elem, text, span, imgspan] = hint; + [elem, text, span, imgspan, _a, _b, showtext] = hint; let valid = validHint(text); span.style.display = (valid ? "" : "none"); @@ -324,7 +387,7 @@ function Hints() //{{{ setClass(imgspan, activeHint == hintnum); } - span.setAttribute("number", hintnum); + span.setAttribute("number", showtext ? hintnum + ": " + text.substr(0,50): hintnum); if (imgspan) imgspan.setAttribute("number", hintnum); else @@ -616,6 +679,19 @@ function Hints() //{{{ "How words are split for hintmatching", "string", '[.,!?:;/"^$%&?()[\\]{}<>#*+|=~ _-]'); + options.add(["hintinputs", "hi"], + "How text inputs are hinted", + "stringlist", "label,value", + { + completer: function (context) [ + ["value", "Match against the value contained by the input field"], + ["label", "Match against the value of a label for the input field, if one can be found"], + ["name", "Match against the name of an input field, only if neither a name or value could be found."] + ], + validator: Option.validateCompleter + }); + + /////////////////////////////////////////////////////////////////////////////}}} ////////////////////// MAPPINGS //////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////{{{ diff --git a/vimperator/NEWS b/vimperator/NEWS index f8717641..b6c67cf5 100644 --- a/vimperator/NEWS +++ b/vimperator/NEWS @@ -1,5 +1,6 @@ 2009-XX-XX: * version 2.1 (probably) + * add 'hintinputs' * add :silent * add $MY_VIMPERATORRC * add ' and " local marks diff --git a/vimperator/locale/en-US/options.txt b/vimperator/locale/en-US/options.txt index f5cd0a5d..61aa222e 100644 --- a/vimperator/locale/en-US/options.txt +++ b/vimperator/locale/en-US/options.txt @@ -316,6 +316,22 @@ want to stay in Normal mode when browsing between web sites. When "on", it blurs any textbox which often is automatically focused on page load. If you usually like 'focuscontent' but sometimes you'd like to focus the first input field, you can use [m]gi[m] to jump to it. + +____ + + +|\'fh'| |\'followhints'| +||'followhints' 'fh'|| number (default: 0) +____ + +Change the behaviour of [m]<Return>[m] in Hints mode. Possible values: + +`---------`---------------------------------------------------------- +*0* Follow the first hint as soon as typed text uniquely identifies it. +*1* Follow the selected hint on [m]<Return>[m]. +*2* Follow the selected hint on [m]<Return>[m] only if it's been [m]<Tab>[m]-selected. +--------------------------------------------------------------------- + ____ @@ -324,6 +340,7 @@ ____ ____ Show the current window fullscreen. Also hide certain GUI elements like the statusline. + ____ @@ -355,6 +372,23 @@ displayed in the status line when viewing the page. ____ +|\'hin'| |\'hintinputs'| +||'hintinputs' 'hin'|| stringlist (default: "label,value") +____ +When generating hints for input elements that do not have an explicit caption, +this specifies the methods to try and generate a textual hint. It tries the +options in the order that you give, and uses the first that it finds. + +`--------------------`--------------------------------------------------------- +*value* The hint is the value displayed in a text input, or the selected option for a dropdown. +*label* The value of an explicit label for the input, this will not match most manually added labels that are found on sites. +*name* The name of the input will be used, although the name is not designed for user consumption, it is frequently very similar to the label. + +------------------------------------------------------------------------------- + +____ + + |\'hm'| |\'hintmatching'| ||'hintmatching' 'hm'|| string (default: contains) ____ @@ -371,22 +405,6 @@ Change the hint matching algorithm during Hints mode. Possible values: ____ -|\'fh'| |\'followhints'| -||'followhints' 'fh'|| number (default: 0) -____ - -Change the behaviour of [m]<Return>[m] in Hints mode. Possible values: - -`---------`---------------------------------------------------------- -*0* Follow the first hint as soon as typed text uniquely identifies it. - Follow the selected hint on [m]<Return>[m]. -*1* Follow the selected hint on [m]<Return>[m]. -*2* Follow the selected hint on [m]<Return>[m] only if it's been [m]<Tab>[m]-selected. ---------------------------------------------------------------------- - -____ - - |\'ht'| |\'hinttags'| ||'hinttags' 'ht'|| string ____ |