1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-02-22 12:05:47 +01:00

Support multi-character hint modes. Remove bloody fh=2. Closes issue #614.

This commit is contained in:
Kris Maglione
2011-07-30 06:48:22 -04:00
parent 9191f1866a
commit 992da465d7
5 changed files with 35 additions and 27 deletions

View File

@@ -305,6 +305,8 @@ var CommandMode = Class("CommandMode", {
this.keepCommand = userContext.hidden_option_command_afterimage; this.keepCommand = userContext.hidden_option_command_afterimage;
}, },
get autocomplete() options["autocomplete"].length,
get command() this.widgets.command[1], get command() this.widgets.command[1],
set command(val) this.widgets.command = val, set command(val) this.widgets.command = val,
@@ -1031,7 +1033,7 @@ var CommandLine = Module("commandline", {
this.autocompleteTimer = Timer(200, 500, function autocompleteTell(tabPressed) { this.autocompleteTimer = Timer(200, 500, function autocompleteTell(tabPressed) {
if (events.feedingKeys && !tabPressed) if (events.feedingKeys && !tabPressed)
this.ignoredCount++; this.ignoredCount++;
else if (options["autocomplete"].length) { else if (this.session.autocomplete) {
this.itemList.visible = true; this.itemList.visible = true;
this.complete(true, false); this.complete(true, false);
} }

View File

@@ -463,14 +463,8 @@ var HintSession = Class("HintSession", CommandMode, {
// This "followhints" option is *too* confusing. For me, and // This "followhints" option is *too* confusing. For me, and
// presumably for users, too. --Kris // presumably for users, too. --Kris
if (options["followhints"] > 0) { if (options["followhints"] > 0 && !followFirst)
if (!followFirst) return; // no return hit; don't examine uniqueness
return; // no return hit; don't examine uniqueness
// OK. return hit. But there's more than one hint, and
// there's no tab-selected current link. Do not follow in mode 2
dactyl.assert(options["followhints"] != 2 || this.validHints.length == 1 || this.hintNumber);
}
if (!followFirst) { if (!followFirst) {
let firstHref = this.validHints[0].elem.getAttribute("href") || null; let firstHref = this.validHints[0].elem.getAttribute("href") || null;
@@ -740,16 +734,15 @@ var Hints = Module("hints", {
events.listen(appContent, "scroll", this.resizeTimer.closure.tell, false); events.listen(appContent, "scroll", this.resizeTimer.closure.tell, false);
const Mode = Hints.Mode; const Mode = Hints.Mode;
Mode.defaultValue("tags", function () function () options.get("hinttags").matcher);
Mode.prototype.__defineGetter__("matcher", function () Mode.prototype.__defineGetter__("matcher", function ()
options.get("extendedhinttags").getKey(this.name, this.tags())); options.get("extendedhinttags").getKey(this.name, options.get("hinttags").matcher));
this.modes = {}; this.modes = {};
this.addMode(";", "Focus hint", buffer.closure.focusElement); this.addMode(";", "Focus hint", buffer.closure.focusElement);
this.addMode("?", "Show information for hint", function (elem) buffer.showElementInfo(elem)); this.addMode("?", "Show information for hint", function (elem) buffer.showElementInfo(elem));
this.addMode("s", "Save hint", function (elem) buffer.saveLink(elem, false)); this.addMode("s", "Save hint", function (elem) buffer.saveLink(elem, false));
this.addMode("f", "Focus frame", function (elem) dactyl.focus(elem.ownerDocument.defaultView)); this.addMode("f", "Focus frame", function (elem) dactyl.focus(elem.ownerDocument.defaultView));
this.addMode("F", "Focus frame or pseudo-frame", buffer.closure.focusElement, null, isScrollable); this.addMode("F", "Focus frame or pseudo-frame", buffer.closure.focusElement, isScrollable);
this.addMode("o", "Follow hint", function (elem) buffer.followLink(elem, dactyl.CURRENT_TAB)); this.addMode("o", "Follow hint", function (elem) buffer.followLink(elem, dactyl.CURRENT_TAB));
this.addMode("t", "Follow hint in a new tab", function (elem) buffer.followLink(elem, dactyl.NEW_TAB)); this.addMode("t", "Follow hint in a new tab", function (elem) buffer.followLink(elem, dactyl.NEW_TAB));
this.addMode("b", "Follow hint in a background tab", function (elem) buffer.followLink(elem, dactyl.NEW_BACKGROUND_TAB)); this.addMode("b", "Follow hint in a background tab", function (elem) buffer.followLink(elem, dactyl.NEW_BACKGROUND_TAB));
@@ -781,15 +774,22 @@ var Hints = Module("hints", {
* about this mode. * about this mode.
* @param {function(Node)} action The function to be called with the * @param {function(Node)} action The function to be called with the
* element that matches. * element that matches.
* @param {function():string} tags The function that returns an * @param {function(Node):boolean} filter A function used to filter
* XPath expression to decide which elements can be hinted (the * the returned node set.
* default returns options["hinttags"]). * @param {[string]} tags A value to add to the default
* @optional * 'extendedhinttags' value for this mode.
* @optional
*/ */
addMode: function (mode, prompt, action, tags) { addMode: function (mode, prompt, action, filter, tags) {
dactyl.assert(mode.length == 1); if (tags != null) {
arguments[1] = UTF8(prompt); let eht = options.get("extendedhinttags");
this.modes[mode] = Hints.Mode.apply(Hints.Mode, arguments); let update = eht.isDefault;
eht.stringDefaultValue += "," + Option.quote(util.regexp.escape(mode)) + ":" + tags.map(Option.quote);
if (update)
eht.reset();
}
this.modes[mode] = Hints.Mode(mode, UTF8(prompt), action, filter);
}, },
/** /**
@@ -1026,6 +1026,7 @@ var Hints = Module("hints", {
open: function open(mode, opts) { open: function open(mode, opts) {
this._extendedhintCount = opts.count; this._extendedhintCount = opts.count;
commandline.input(["Normal", mode], "", { commandline.input(["Normal", mode], "", {
autocomplete: false,
completer: function (context) { completer: function (context) {
context.compare = function () 0; context.compare = function () 0;
context.completions = [[k, v.prompt] for ([k, v] in Iterator(hints.modes))]; context.completions = [[k, v.prompt] for ([k, v] in Iterator(hints.modes))];
@@ -1034,7 +1035,10 @@ var Hints = Module("hints", {
if (arg) if (arg)
hints.show(arg, opts); hints.show(arg, opts);
}, },
onChange: function () { onChange: function (arg) {
if (Object.keys(hints.modes).some(function (m) m != arg && m.indexOf(arg) == 0))
return;
this.accepted = true; this.accepted = true;
modes.pop(); modes.pop();
} }
@@ -1167,7 +1171,7 @@ var Hints = Module("hints", {
return -1; return -1;
}, },
Mode: Struct("HintMode", "name", "prompt", "action", "tags", "filter") Mode: Struct("HintMode", "name", "prompt", "action", "filter")
.localize("prompt") .localize("prompt")
}, { }, {
modes: function initModes() { modes: function initModes() {
@@ -1235,7 +1239,7 @@ var Hints = Module("hints", {
{ {
keepQuotes: true, keepQuotes: true,
getKey: function (val, default_) getKey: function (val, default_)
let (res = array.nth(this.value, function (re) re.test(val), 0)) let (res = array.nth(this.value, function (re) let (match = re.exec(val)) match && match[0] == val, 0))
res ? res.matcher : default_, res ? res.matcher : default_,
setter: function (vals) { setter: function (vals) {
for (let value in values(vals)) for (let value in values(vals))
@@ -1285,7 +1289,6 @@ var Hints = Module("hints", {
values: { values: {
"0": "Follow the first hint as soon as typed text uniquely identifies it. Follow the selected hint on <Return>.", "0": "Follow the first hint as soon as typed text uniquely identifies it. Follow the selected hint on <Return>.",
"1": "Follow the selected hint on <Return>.", "1": "Follow the selected hint on <Return>.",
"2": "Follow the selected hint on <Return> only if it's been <Tab>-selected."
} }
}); });

View File

@@ -735,7 +735,6 @@
<dl dt="width: 6em;"> <dl dt="width: 6em;">
<dt>0</dt> <dd>Follow the first hint as soon as typed text uniquely identifies it.</dd> <dt>0</dt> <dd>Follow the first hint as soon as typed text uniquely identifies it.</dd>
<dt>1</dt> <dd>Follow the selected hint on <k name="CR"/>.</dd> <dt>1</dt> <dd>Follow the selected hint on <k name="CR"/>.</dd>
<dt>2</dt> <dd>Follow the selected hint on <k name="CR"/> only if it's been <k name="Tab" mode="c"/>-selected.</dd>
</dl> </dl>
</description> </description>
</item> </item>

View File

@@ -199,6 +199,7 @@ var Option = Class("Option", {
set stringValue(value) this.value = this.parse(value), set stringValue(value) this.value = this.parse(value),
get stringDefaultValue() this.stringify(this.defaultValue), get stringDefaultValue() this.stringify(this.defaultValue),
set stringDefaultValue(val) this.defaultValue = this.parse(val),
getKey: function getKey(key) undefined, getKey: function getKey(key) undefined,

View File

@@ -1,8 +1,9 @@
Developers: Developers:
* Kris Maglione * Kris Maglione
* Doug Kearns <dougkearns@gmail.com> * Doug Kearns <dougkearns@gmail.com>
* anekos <anekos@snca.net>
* teramako <teramako@gmail.com> Contributers:
* Štěpán Němec
Inactive/former developers: Inactive/former developers:
* Viktor Kojouharov (Виктор Кожухаров) * Viktor Kojouharov (Виктор Кожухаров)
@@ -14,6 +15,8 @@ Inactive/former developers:
* janus_wel <janus.wel.3@gmail.com> * janus_wel <janus.wel.3@gmail.com>
* Martin Stubenschrott <stubenschrott@vimperator.org> * Martin Stubenschrott <stubenschrott@vimperator.org>
* Conrad Irwin * Conrad Irwin
* anekos <anekos@snca.net>
* teramako <teramako@gmail.com>
Patches (in no special order): Patches (in no special order):
* Ruud Grosmann ('followhints' option) * Ruud Grosmann ('followhints' option)