diff --git a/common/content/commandline.js b/common/content/commandline.js index 08f091ff..976b04d5 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -42,7 +42,7 @@ var CommandWidgets = Class("CommandWidgets", { @@ -88,6 +88,7 @@ var CommandWidgets = Class("CommandWidgets", { this.addElement({ name: "command", + test: function (stack, prev) stack.pop && !isinstance(prev.main, modes.COMMAND_LINE), id: "commandline-command", get: function (elem) { // The long path is because of complications with the @@ -163,6 +164,7 @@ var CommandWidgets = Class("CommandWidgets", { if (!(obj.noValue || obj.getValue)) { Object.defineProperty(this, obj.name, Modes.boundProperty({ + test: obj.test, get: function get_widgetValue() { let elem = self.getGroup(obj.name, obj.value)[obj.name]; @@ -569,9 +571,6 @@ var CommandLine = Module("commandline", { nodeSet.commandline.completionList.visible = false; }, - _multilineEnd: Modes.boundProperty(), - _multilineCallback: Modes.boundProperty(), - _lastClearable: Modes.boundProperty(), messages: Modes.boundProperty(), @@ -759,20 +758,21 @@ var CommandLine = Module("commandline", { * callback with that string as a parameter. * * @param {string} end - * @param {function(string)} callbackFunc + * @param {function(string)} callback */ // FIXME: Buggy, especially when pasting. - inputMultiline: function inputMultiline(end, callbackFunc) { + inputMultiline: function inputMultiline(end, callback) { let cmd = this.command; - modes.push(modes.COMMAND_LINE, modes.INPUT_MULTILINE, { - keyModes: [modes.INPUT_MULTILINE] + modes.push(modes.INPUT_MULTILINE, null, { + mappingSelf: { + end: "\n" + end + "\n", + callback: callback + } }); if (cmd != false) this._echoLine(cmd, this.HL_NORMAL); // save the arguments, they are needed in the event handler onKeyPress - this._multilineEnd = "\n" + end + "\n"; - this._multilineCallback = callbackFunc; this.multilineInputVisible = true; this.widgets.multilineInput.value = ""; @@ -781,23 +781,25 @@ var CommandLine = Module("commandline", { this.timeout(function () { dactyl.focus(this.widgets.multilineInput); }, 10); }, + get commandMode() this.commandSession && isinstance(modes.main, modes.COMMAND_LINE), + events: update( iter(CommandMode.prototype.events).map( function ([event, handler]) [ event, function (event) { - if (this.commandSession) + if (this.commandMode) handler.call(this.commandSession, event); } ]).toObject(), { blur: function onBlur(event) { this.timeout(function () { - if (this.commandSession && event.originalTarget === this.widgets.active.command.inputField) + if (this.commandMode && event.originalTarget === this.widgets.active.command.inputField) dactyl.focus(this.widgets.active.command.inputField); }); }, focus: function onFocus(event) { - if (!this.commandSession + if (!this.commandMode && event.originalTarget === this.widgets.active.command.inputField) { event.target.blur(); dactyl.beep(); @@ -816,7 +818,7 @@ var CommandLine = Module("commandline", { */ multilineInputEvents: { blur: function onBlur(event) { - if (modes.extended & modes.INPUT_MULTILINE) + if (modes.main == modes.INPUT_MULTILINE) this.timeout(function () { dactyl.focus(this.widgets.multilineInput.inputField); }); @@ -1355,6 +1357,11 @@ var CommandLine = Module("commandline", { bases: [modes.COMMAND_LINE], input: true }); + + modes.addMode("INPUT_MULTILINE", { + bases: [modes.INSERT], + input: true + }); }, mappings: function init_mappings() { @@ -1364,18 +1371,17 @@ var CommandLine = Module("commandline", { mappings.add([modes.INPUT_MULTILINE], ["", "", ""], "Begin a new line", - function (args) { + function ({ self }) { let text = "\n" + commandline.widgets.multilineInput .value.substr(0, commandline.widgets.multilineInput.selectionStart) + "\n"; - let index = text.indexOf(commandline._multilineEnd); + let index = text.indexOf(self.end); if (index >= 0) { text = text.substring(1, index); - let callback = commandline._multilineCallback; modes.pop(); - return function () callback.call(commandline, text); + return function () self.callback.call(commandline, text); } return Events.PASS; }); diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 50339829..73fabff2 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -326,7 +326,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { if (typeof str == "object" && "echoerr" in str) str = str.echoerr; else if (isinstance(str, ["Error"])) - str = <>{str.fileName.replace(/^.*? -> /, "")}: {str.lineNumber}: {str}; + str = <>{str.fileName.replace(/^.* -> /, "")}: {str.lineNumber}: {str}; if (options["errorbells"]) dactyl.beep(); @@ -1131,7 +1131,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { }); params = params || {}; - if (isArray(params)) + if (isString(params)) params = { where: params }; let flags = 0; diff --git a/common/content/events.js b/common/content/events.js index bc2b1e63..7be1d152 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -138,7 +138,7 @@ var ProcessorStack = Class("ProcessorStack", { if (result === Events.KILL) this.actions = []; - else if (!this.actions.length) + else if (!this.actions.length && !processors.length) for (let input in values(this.processors)) if (input.fallthrough) { if (result === Events.KILL) @@ -1330,11 +1330,11 @@ var Events = Module("events", { }; }, mappings: function () { - mappings.add(modes.all, + mappings.add(modes.MAIN, ["", ""], "Temporarily ignore all " + config.appName + " key bindings", function () { modes.push(modes.PASS_THROUGH); }); - mappings.add(modes.all, + mappings.add(modes.MAIN, ["", ""], "Pass through next key", function () { if (modes.main == modes.QUOTE) @@ -1342,12 +1342,12 @@ var Events = Module("events", { modes.push(modes.QUOTE); }); - mappings.add(modes.all, + mappings.add(modes.BASE, [""], "Do nothing", function () {}); // macros - mappings.add([modes.NORMAL, modes.TEXT_AREA, modes.PLAYER].filter(util.identity), + mappings.add([modes.COMMAND], ["q", ""], "Record a key sequence into a macro", function ({ arg }) { events._macroKeys.pop(); @@ -1355,7 +1355,7 @@ var Events = Module("events", { }, { get arg() !modes.recording }); - mappings.add([modes.NORMAL, modes.TEXT_AREA, modes.PLAYER].filter(util.identity), + mappings.add([modes.COMMAND], ["@", ""], "Play a macro", function ({ arg, count }) { count = Math.max(count, 1); diff --git a/common/content/modes.js b/common/content/modes.js index fe9b0275..012cb280 100644 --- a/common/content/modes.js +++ b/common/content/modes.js @@ -110,7 +110,7 @@ var Modes = Module("modes", { this.addMode("INPUT", { char: "I", description: "The base mode for input modes, including Insert and Command Line", - bases: [this.BASE], + bases: [this.MAIN], input: true }); this.addMode("INSERT", { @@ -154,11 +154,6 @@ var Modes = Module("modes", { input: true }); - this.addMode("INPUT_MULTILINE", { - extended: true, - hidden: true, - input: true - }); this.addMode("LINE", { extended: true, hidden: true }); @@ -269,11 +264,11 @@ var Modes = Module("modes", { delayed: [], delay: function (callback, self) { this.delayed.push([callback, self]); }, - save: function save(id, obj, prop) { + save: function save(id, obj, prop, test) { if (!(id in this.boundProperties)) for (let elem in array.iterValues(this._modeStack)) - elem.saved[id] = { obj: obj, prop: prop, value: obj[prop] }; - this.boundProperties[id] = { obj: Cu.getWeakReference(obj), prop: prop }; + elem.saved[id] = { obj: obj, prop: prop, value: obj[prop], test: test }; + this.boundProperties[id] = { obj: Cu.getWeakReference(obj), prop: prop, test: test }; }, // helper function to set both modes in one go @@ -299,15 +294,17 @@ var Modes = Module("modes", { let push = mainMode != null && !(stack && stack.pop) && Modes.StackElement(this._main, this._extended, params, {}); + if (push && this.topOfStack) { if (this.topOfStack.params.leave) dactyl.trapErrors("leave", this.topOfStack.params, { push: push }, push); - for (let [id, { obj, prop }] in Iterator(this.boundProperties)) { + + for (let [id, { obj, prop, test }] in Iterator(this.boundProperties)) { if (!obj.get()) delete this.boundProperties[id]; else - this.topOfStack.saved[id] = { obj: obj.get(), prop: prop, value: obj.get()[prop] }; + this.topOfStack.saved[id] = { obj: obj.get(), prop: prop, value: obj.get()[prop], test: test }; } } @@ -319,8 +316,9 @@ var Modes = Module("modes", { this._modeStack.push(push); if (stack && stack.pop) - for (let { obj, prop, value } in values(this.topOfStack.saved)) - obj[prop] = value; + for (let { obj, prop, value, test } in values(this.topOfStack.saved)) + if (!test || !test(stack, prev)) + obj[prop] = value; this.show(); @@ -460,7 +458,7 @@ var Modes = Module("modes", { return val === undefined ? value : val; }, set: function (val) { - modes.save(id, this, prop); + modes.save(id, this, prop, desc.test); if (desc.set) value = desc.set.call(this, val); value = !desc.set || value === undefined ? val : value; diff --git a/common/modules/addons.jsm b/common/modules/addons.jsm index 8fbbba32..2cd642a8 100644 --- a/common/modules/addons.jsm +++ b/common/modules/addons.jsm @@ -232,17 +232,6 @@ var Addon = Class("Addon", { } }); -iter.forEach(properties(config.addon), function (prop) { - let desc = Object.getOwnPropertyDescriptor(config.addon, prop); - if (callable(desc.value)) - Addon.prototype[prop] = function proxy() this.addon[prop].apply(this.addon, arguments); - else - Object.defineProperty(Addon.prototype, prop, { - get: function get_proxy() this.addon[prop], - set: function set_proxy(val) this.addon[prop] = val - }); -}); - var AddonList = Class("AddonList", { init: function init(modules, types, filter) { this.modules = modules; @@ -533,6 +522,17 @@ var addonErrors = array.toObject([ endModule(); +iter.forEach(properties(config.addon), function (prop) { + let desc = Object.getOwnPropertyDescriptor(config.addon, prop); + if (callable(desc.value)) + Addon.prototype[prop] = function proxy() this.addon[prop].apply(this.addon, arguments); + else + Object.defineProperty(Addon.prototype, prop, { + get: function get_proxy() this.addon[prop], + set: function set_proxy(val) this.addon[prop] = val + }); +}); + } catch(e){ if (isString(e)) e = Error(e); dump(e.fileName+":"+e.lineNumber+": "+e+"\n" + e.stack); } // vim: set fdm=marker sw=4 ts=4 et ft=javascript: diff --git a/common/modules/completion.jsm b/common/modules/completion.jsm index 7c352d1b..9f291f02 100644 --- a/common/modules/completion.jsm +++ b/common/modules/completion.jsm @@ -83,7 +83,7 @@ var CompletionContext = Class("CompletionContext", { self.waitingForTab = false; delete self._generate; - delete self._ignoreCase; + delete self.ignoreCase; if (self != this) return self; ["_caret", "contextList", "maxItems", "onUpdate", "selectionTypes", "tabPressed", "updateAsync", "value"].forEach(function (key) { @@ -305,7 +305,7 @@ var CompletionContext = Class("CompletionContext", { get filter() this._filter != null ? this._filter : this.value.substr(this.offset, this.caret), set filter(val) { - delete this._ignoreCase; + delete this.ignoreCase; return this._filter = val; }, @@ -401,18 +401,15 @@ var CompletionContext = Class("CompletionContext", { this.noUpdate = false; }, - get ignoreCase() { - if (this._ignoreCase == null) { - let mode = this.wildcase; - if (mode == "match") - this._ignoreCase = false; - if (mode == "ignore") - this._ignoreCase = true; - this._ignoreCase = !/[A-Z]/.test(this.filter); - } - return this._ignoreCase; - }, - set ignoreCase(val) this._ignoreCase = val, + ignoreCase: Class.memoize(function () { + let mode = this.wildcase; + if (mode == "match") + return false; + else if (mode == "ignore") + return true; + else + return !/[A-Z]/.test(this.filter); + }), /** * Returns a list of all completion items which match the current @@ -483,8 +480,13 @@ var CompletionContext = Class("CompletionContext", { filtered = filtered.slice(0, this.maxItems); // Sorting - if (this.sortResults && this.compare) + if (this.sortResults && this.compare) { filtered.sort(this.compare); + if (!this.anchored) { + let filter = this.filter; + filtered.sort(function (a, b) (b.text.indexOf(filter) == 0) - (a.text.indexOf(filter) == 0)); + } + } return this.cache.filtered = filtered; } @@ -573,7 +575,7 @@ var CompletionContext = Class("CompletionContext", { * @param {number} count The number of characters to advance the context. */ advance: function advance(count) { - delete this._ignoreCase; + delete this.ignoreCase; let advance = count; if (this.quote && count) { advance = this.quote[1](this.filter.substr(0, count)).length;