1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 14:27:59 +01:00

Add 'ambiguous' attribute to hints which can't be unambiguously typed.

This commit is contained in:
Kris Maglione
2011-05-11 13:49:37 -04:00
parent 8faa8a7113
commit 4a85962ccc
2 changed files with 33 additions and 2 deletions

View File

@@ -30,7 +30,7 @@ var Buffer = Module("buffer", {
if (verbose) if (verbose)
for (let link in engines) for (let link in engines)
yield [link.title || /*L*/ "Engine " + n++, yield [link.title || /*L*/ "Engine " + n++,
<a xmlns={XHTML} href={link.href} onclick="window.external.AddSearchProvider(this.href); return false;">{link.href}</a>]; <a xmlns={XHTML} href={link.href} onclick="if (event.button == 0) { window.external.AddSearchProvider(this.href); return false; }">{link.href}</a>];
} }
if (!verbose && nEngines) if (!verbose && nEngines)

View File

@@ -70,6 +70,15 @@ var HintSession = Class("HintSession", CommandMode, {
hints.setClass(this.imgSpan, this.valid ? val : null); hints.setClass(this.imgSpan, this.valid ? val : null);
}, },
get ambiguous() this.span.hasAttribute("ambiguous"),
set ambiguous(val) {
let meth = val ? "setAttribute" : "removeAttribute";
this.elem[meth]("ambiguous", "true");
this.span[meth]("ambiguous", "true");
if (this.imgSpan)
this.imgSpan[meth]("ambiguous", "true");
},
get valid() this._valid, get valid() this._valid,
set valid(val) { set valid(val) {
this._valid = val, this._valid = val,
@@ -155,6 +164,21 @@ var HintSession = Class("HintSession", CommandMode, {
return res.reverse().join(""); return res.reverse().join("");
}, },
/**
* The reverse of {@link #getHintString}. Given a hint string,
* returns its index.
*
* @param {string} str The hint's string.
* @returns {number} The hint's index.
*/
getHintNumber: function getHintNumber(str) {
let base = this.hintKeys.length;
let res = 0;
for (let char in values(str))
res = res * base + this.hintKeys.indexOf(char);
return res;
},
/** /**
* Returns true if the given key string represents a * Returns true if the given key string represents a
* pseudo-hint-number. * pseudo-hint-number.
@@ -511,9 +535,11 @@ var HintSession = Class("HintSession", CommandMode, {
for (let elem in util.evaluateXPath("//*[@dactyl:highlight='hints']", doc)) for (let elem in util.evaluateXPath("//*[@dactyl:highlight='hints']", doc))
elem.parentNode.removeChild(elem); elem.parentNode.removeChild(elem);
for (let i in util.range(start, end + 1)) for (let i in util.range(start, end + 1)) {
this.pageHints[i].ambiguous = false;
this.pageHints[i].valid = false; this.pageHints[i].valid = false;
} }
}
styles.system.remove("hint-positions"); styles.system.remove("hint-positions");
this.reset(); this.reset();
@@ -586,12 +612,17 @@ var HintSession = Class("HintSession", CommandMode, {
hint.span.setAttribute("number", str); hint.span.setAttribute("number", str);
if (hint.imgSpan) if (hint.imgSpan)
hint.imgSpan.setAttribute("number", str); hint.imgSpan.setAttribute("number", str);
hint.active = activeHint == hintnum; hint.active = activeHint == hintnum;
this.validHints.push(hint); this.validHints.push(hint);
hintnum++; hintnum++;
} }
} }
for (let [i, hint] in Iterator(this.validHints))
hint.ambiguous = i * this.hintKeys.length < this.validHints.length;
if (options["usermode"]) { if (options["usermode"]) {
let css = []; let css = [];
for (let hint in values(this.pageHints)) { for (let hint in values(this.pageHints)) {