Skip to content

Commit

Permalink
Add hintkeys option to change default numbered hint key labels. Vrome…
Browse files Browse the repository at this point in the history
…rc setting hintkeys and hintkeysdisplayuppercase.
  • Loading branch information
bgoldsworthy committed Mar 28, 2012
1 parent 3792268 commit e5362ca
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
15 changes: 15 additions & 0 deletions Features.mkd
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@
One more thing, Press <Enter> would open current highlighted element.
<C-Enter> 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)
<M-f> Start Hint mode, but open multiple links in a new tab. (refer `f` for more)

Expand Down
46 changes: 37 additions & 9 deletions src/frontend/modules/hint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 : ''});
Expand Down Expand Up @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -88,17 +116,17 @@ var Hint = (function() {
function handleInput(e) {
key = getKey(e);

// If user are inputing number
if (/^\d$/.test(key) || (key == '<BackSpace>' && selected !== 0)) {
selected = (key == '<BackSpace>') ? parseInt(selected / 10) : selected * 10 + Number(key);
// If user are inputing hintkey
if (new RegExp("^[" + hintKeys + "]$").test(key) || (key == '<BackSpace>' && selected !== "")) {
selected = (key == '<BackSpace>') ? 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 {
Expand Down Expand Up @@ -155,7 +183,7 @@ var Hint = (function() {
}

function delayToWaitKeyDown(){
selected = 0;
selected = "";
matched = [];

for (var i = 0, j = elements.length; i < j; i++) {
Expand Down Expand Up @@ -211,7 +239,7 @@ var Hint = (function() {
if (!multi_mode) {
setTimeout(remove,200);
} else {
selected = 0;
selected = "";
CmdBox.set({title : 'HintMode'});
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/shared/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"},
Expand Down

0 comments on commit e5362ca

Please sign in to comment.