From e5362ca39147eb65e990920bfaf82d5cdeed5f4d Mon Sep 17 00:00:00 2001 From: Brandon Goldsworthy Date: Wed, 28 Mar 2012 13:42:46 -0700 Subject: [PATCH] Add hintkeys option to change default numbered hint key labels. Vromerc setting hintkeys and hintkeysdisplayuppercase. --- Features.mkd | 15 ++++++++++++ src/frontend/modules/hint.js | 46 +++++++++++++++++++++++++++++------- src/shared/options.js | 2 ++ 3 files changed, 54 insertions(+), 9 deletions(-) diff --git a/Features.mkd b/Features.mkd index fcfcbb09..4ce7248d 100644 --- a/Features.mkd +++ b/Features.mkd @@ -124,6 +124,21 @@ One more thing, Press would open current highlighted element. would open all available hints in current page. + You can use the `hintkeys` vromerc setting to change the characters used for 'numbering', the default value + for this setting is 0123456789. So, for example, `set hintkeys=asdfghjkl;` would label the hints using + the keys of the home row. Values for hintkey do not need to be 10 characters long: `set hintkeys=asdf` + will also work. + + Tip: Any keys not listed in hintkeys can be used for filtering. Filtering is not case-sensitive, but + hintkeys are. So if your hintkeys are "asdfg" you can use filtering to select the `Gmail` link in + the above example by typing `MA`, and if your hintkeys are 'ASDF' you can type `ma` to select the `Gmail` + link and you would need to type `GA` to select the link tagged with those keys. + + Finally, you can set hintkeysdisplayuppercase if you want the hintkey 'numbers' to be converted to + uppercase before they're displayed, but to still act like lowercase hintkeys. This is helpful for + readability The default value for this setting is 0. If you add `set hintkeysdisplayuppercase=1` + in your vromerc the links will be 'numbered' A,S,D,F... but you will still type a,s,d,f,... to select them. + F Start Hint mode, but open links in new tabs. (refer `f` for more) Start Hint mode, but open multiple links in a new tab. (refer `f` for more) diff --git a/src/frontend/modules/hint.js b/src/frontend/modules/hint.js index 3db58aa2..c5c47118 100644 --- a/src/frontend/modules/hint.js +++ b/src/frontend/modules/hint.js @@ -5,9 +5,12 @@ var Hint = (function() { function start(newTab, multiMode) { hintMode = true; multi_mode = multiMode; - selected = 0; // set current selected number + selected = ""; // set current selected hint currentHint = false; new_tab = newTab; + hintKeys = Option.get("hintkeys"); + numKeys = hintKeys.length; + hintKeysUppercase = Option.get("hintkeysdisplayuppercase"); initHintMode(); CmdBox.set({title : 'HintMode',pressDown : handleInput, content : ''}); @@ -39,6 +42,31 @@ var Hint = (function() { } } + function numberToHintKeys(/* int */ number) { + var r = ""; + while(true) { + r = hintKeys[number % numKeys] + r; + if(number < numKeys) { break; } + number = parseInt(number/numKeys); + } + + if (hintKeysUppercase) + return r.toUpperCase(); + else + return r; + } + + function hintKeysToNumber(/* string */ searchKeys) { + var d,r = 0; + while(true) { + d = searchKeys.slice(0,1); + searchKeys = searchKeys.slice(1); + r = (r*numKeys) + hintKeys.indexOf(d); + if (searchKeys == "") { break; } + } + return r; + } + function setHintIndex(elems) { var div = removeHighlightBox(/* create_after_remove */ true); var win_top = window.scrollY / Zoom.current(); @@ -55,7 +83,7 @@ var Hint = (function() { span.style.left = elem_left + 'px'; span.style.top = elem_top + 'px'; span.style.backgroundColor = 'red'; - span.innerHTML = i + 1; // set number for available elements + span.innerHTML = numberToHintKeys(i + 1) // set number for available elements frag.appendChild(span); setHighlight(elem, /* set_active */ false); @@ -88,17 +116,17 @@ var Hint = (function() { function handleInput(e) { key = getKey(e); - // If user are inputing number - if (/^\d$/.test(key) || (key == '' && selected !== 0)) { - selected = (key == '') ? parseInt(selected / 10) : selected * 10 + Number(key); + // If user are inputing hintkey + if (new RegExp("^[" + hintKeys + "]$").test(key) || (key == '' && selected !== "")) { + selected = (key == '') ? selected.slice(0,-1) : selected + key; CmdBox.set({title : 'HintMode (' + selected + ')'}); - var index = selected - 1; + var index = hintKeysToNumber(selected) - 1; setHighlight(matched[index], /* set_active */ true); currentHint = matched[index]; e.preventDefault(); - if (selected * 10 > matched.length) { + if (index * numKeys > matched.length) { return execSelect(currentHint); } } else { @@ -155,7 +183,7 @@ var Hint = (function() { } function delayToWaitKeyDown(){ - selected = 0; + selected = ""; matched = []; for (var i = 0, j = elements.length; i < j; i++) { @@ -211,7 +239,7 @@ var Hint = (function() { if (!multi_mode) { setTimeout(remove,200); } else { - selected = 0; + selected = ""; CmdBox.set({title : 'HintMode'}); } } diff --git a/src/shared/options.js b/src/shared/options.js index c2a93636..ae5dd0f4 100644 --- a/src/shared/options.js +++ b/src/shared/options.js @@ -3,6 +3,8 @@ var Option = (function() { nextpattern : ['(下|后)一页','下一頁','^\\s*Next\\s*$','^>$','^More$','(^(>>|››|»))|((»|››|>>)$)'], previouspattern : ['(上|前)一页','上一頁','^\\s*Prev(ious)?\\s*$','^<$','(^(<<|‹‹|«))|((<<|‹‹|«)$)'], disablesites : "", + hintkeys : "0123456789", + hintkeysdisplayuppercase : 0, editor : "gvim -f", server_port: 20000, searchengines : {"google":"http://www.google.com/search?q={{keyword}}", "yahoo":"http://search.yahoo.com/search?p={{keyword}}", "bing":"http://www.bing.com/search?q={{keyword}}", "wikipedia":"http://en.wikipedia.org/wiki/{{keyword}}","answers":"http://www.answers.com/main/ntquery?s={{keyword}}", "twitter":"https://twitter.com/search/{{keyword}}"},