From 992da465d7871dc73b6f894faf1826b999967203 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Sat, 30 Jul 2011 06:48:22 -0400 Subject: [PATCH] Support multi-character hint modes. Remove bloody fh=2. Closes issue #614. --- common/content/commandline.js | 4 ++- common/content/hints.js | 49 +++++++++++++++++---------------- common/locale/en-US/options.xml | 1 - common/modules/options.jsm | 1 + pentadactyl/AUTHORS | 7 +++-- 5 files changed, 35 insertions(+), 27 deletions(-) diff --git a/common/content/commandline.js b/common/content/commandline.js index 806d3b70..cae99423 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -305,6 +305,8 @@ var CommandMode = Class("CommandMode", { this.keepCommand = userContext.hidden_option_command_afterimage; }, + get autocomplete() options["autocomplete"].length, + get command() this.widgets.command[1], set command(val) this.widgets.command = val, @@ -1031,7 +1033,7 @@ var CommandLine = Module("commandline", { this.autocompleteTimer = Timer(200, 500, function autocompleteTell(tabPressed) { if (events.feedingKeys && !tabPressed) this.ignoredCount++; - else if (options["autocomplete"].length) { + else if (this.session.autocomplete) { this.itemList.visible = true; this.complete(true, false); } diff --git a/common/content/hints.js b/common/content/hints.js index d0350675..3de5563f 100644 --- a/common/content/hints.js +++ b/common/content/hints.js @@ -463,14 +463,8 @@ var HintSession = Class("HintSession", CommandMode, { // This "followhints" option is *too* confusing. For me, and // presumably for users, too. --Kris - if (options["followhints"] > 0) { - if (!followFirst) - 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 (options["followhints"] > 0 && !followFirst) + return; // no return hit; don't examine uniqueness if (!followFirst) { 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); const Mode = Hints.Mode; - Mode.defaultValue("tags", function () function () options.get("hinttags").matcher); 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.addMode(";", "Focus hint", buffer.closure.focusElement); this.addMode("?", "Show information for hint", function (elem) buffer.showElementInfo(elem)); 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 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("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)); @@ -781,15 +774,22 @@ var Hints = Module("hints", { * about this mode. * @param {function(Node)} action The function to be called with the * element that matches. - * @param {function():string} tags The function that returns an - * XPath expression to decide which elements can be hinted (the - * default returns options["hinttags"]). - * @optional + * @param {function(Node):boolean} filter A function used to filter + * the returned node set. + * @param {[string]} tags A value to add to the default + * 'extendedhinttags' value for this mode. + * @optional */ - addMode: function (mode, prompt, action, tags) { - dactyl.assert(mode.length == 1); - arguments[1] = UTF8(prompt); - this.modes[mode] = Hints.Mode.apply(Hints.Mode, arguments); + addMode: function (mode, prompt, action, filter, tags) { + if (tags != null) { + let eht = options.get("extendedhinttags"); + 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) { this._extendedhintCount = opts.count; commandline.input(["Normal", mode], "", { + autocomplete: false, completer: function (context) { context.compare = function () 0; context.completions = [[k, v.prompt] for ([k, v] in Iterator(hints.modes))]; @@ -1034,7 +1035,10 @@ var Hints = Module("hints", { if (arg) 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; modes.pop(); } @@ -1167,7 +1171,7 @@ var Hints = Module("hints", { return -1; }, - Mode: Struct("HintMode", "name", "prompt", "action", "tags", "filter") + Mode: Struct("HintMode", "name", "prompt", "action", "filter") .localize("prompt") }, { modes: function initModes() { @@ -1235,7 +1239,7 @@ var Hints = Module("hints", { { keepQuotes: true, 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_, setter: function (vals) { for (let value in values(vals)) @@ -1285,7 +1289,6 @@ var Hints = Module("hints", { values: { "0": "Follow the first hint as soon as typed text uniquely identifies it. Follow the selected hint on .", "1": "Follow the selected hint on .", - "2": "Follow the selected hint on only if it's been -selected." } }); diff --git a/common/locale/en-US/options.xml b/common/locale/en-US/options.xml index dc0d5982..3aa6f5a9 100644 --- a/common/locale/en-US/options.xml +++ b/common/locale/en-US/options.xml @@ -735,7 +735,6 @@
0
Follow the first hint as soon as typed text uniquely identifies it.
1
Follow the selected hint on .
-
2
Follow the selected hint on only if it's been -selected.
diff --git a/common/modules/options.jsm b/common/modules/options.jsm index 75c76159..a09fef25 100644 --- a/common/modules/options.jsm +++ b/common/modules/options.jsm @@ -199,6 +199,7 @@ var Option = Class("Option", { set stringValue(value) this.value = this.parse(value), get stringDefaultValue() this.stringify(this.defaultValue), + set stringDefaultValue(val) this.defaultValue = this.parse(val), getKey: function getKey(key) undefined, diff --git a/pentadactyl/AUTHORS b/pentadactyl/AUTHORS index 99ef6bcd..da3e1e89 100644 --- a/pentadactyl/AUTHORS +++ b/pentadactyl/AUTHORS @@ -1,8 +1,9 @@ Developers: * Kris Maglione * Doug Kearns - * anekos - * teramako + +Contributers: + * Štěpán Němec Inactive/former developers: * Viktor Kojouharov (Виктор Кожухаров) @@ -14,6 +15,8 @@ Inactive/former developers: * janus_wel * Martin Stubenschrott * Conrad Irwin + * anekos + * teramako Patches (in no special order): * Ruud Grosmann ('followhints' option)