From 0af0b5340e1afc30bf19253d5829d16cd0691807 Mon Sep 17 00:00:00 2001 From: Kris Maglione Date: Tue, 7 Dec 2010 01:21:42 -0500 Subject: [PATCH] Minor mode magic. --- common/content/editor.js | 4 ++-- common/content/events.js | 18 +++++++++--------- common/content/modes.js | 16 ++++++++-------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/common/content/editor.js b/common/content/editor.js index e8f18340..6e307b14 100644 --- a/common/content/editor.js +++ b/common/content/editor.js @@ -11,8 +11,8 @@ /** @instance editor */ const Editor = Module("editor", { - get isCaret() modes.getStack(1).main === modes.CARET, - get isTextEdit() modes.getStack(1).main === modes.TEXT_EDIT, + get isCaret() modes.getStack(1).main == modes.CARET, + get isTextEdit() modes.getStack(1).main == modes.TEXT_EDIT, unselectText: function (toEnd) { try { diff --git a/common/content/events.js b/common/content/events.js index 7dee4535..3e99b85c 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -738,7 +738,7 @@ const Events = Module("events", { if (elem instanceof HTMLTextAreaElement || (elem && util.computedStyle(elem).MozUserModify == "read-write") || elem == null && win && Editor.getEditor(win)) { - if (modes.main === modes.VISUAL && elem.selectionEnd == elem.selectionStart) + if (modes.main == modes.VISUAL && elem.selectionEnd == elem.selectionStart) modes.pop(); if (!(modes.main & (modes.INSERT | modes.TEXT_EDIT | modes.VISUAL))) @@ -764,7 +764,7 @@ const Events = Module("events", { if (elem == null && urlbar && urlbar.inputField == this._lastFocus) util.threadYield(true); - while (modes.getMode(modes.main).ownsFocus) + while (modes.main.ownsFocus) modes.pop(); } finally { @@ -938,7 +938,7 @@ const Events = Module("events", { } else { // Hack. - if (map.name == "" && main === modes.QUOTE) + if (map.name == "" && main == modes.QUOTE) stop = false; else { if (modes.isReplaying && !this.waitForPageLoad()) @@ -969,11 +969,11 @@ const Events = Module("events", { this._input.motionCount = null; if (!isEscape(key)) { - stop = (mode.main === modes.TEXT_EDIT); + stop = (mode.main == modes.TEXT_EDIT); if (stop) dactyl.beep(); - if (mode.main === modes.COMMAND_LINE) + if (mode.main == modes.COMMAND_LINE) if (!(mode.extended & modes.INPUT_MULTILINE)) dactyl.trapErrors(commandline.onEvent, commandline, event); } @@ -993,7 +993,7 @@ const Events = Module("events", { // This is a stupid, silly, and revolting hack. if (isEscape(key)) this.onEscape(); - if (main === modes.QUOTE) + if (main == modes.QUOTE) modes.push(main); } }, @@ -1007,8 +1007,8 @@ const Events = Module("events", { (!dactyl.focus || Events.isContentNode(dactyl.focus)) && options.get("passkeys").has(events.toString(event)); - if (modes.main === modes.PASS_THROUGH || - modes.main === modes.QUOTE + if (modes.main == modes.PASS_THROUGH || + modes.main == modes.QUOTE && modes.getStack(1).main !== modes.PASS_THROUGH && !shouldPass() || !modes.passThrough && shouldPass()) @@ -1048,7 +1048,7 @@ const Events = Module("events", { let controller = document.commandDispatcher.getControllerForCommand("cmd_copy"); let couldCopy = controller && controller.isCommandEnabled("cmd_copy"); - if (dactyl.mode === modes.VISUAL) { + if (dactyl.mode == modes.VISUAL) { if (!couldCopy) modes.pop(); // Really not ideal. } diff --git a/common/content/modes.js b/common/content/modes.js index 14505f1d..594646c3 100644 --- a/common/content/modes.js +++ b/common/content/modes.js @@ -94,7 +94,7 @@ const Modes = Module("modes", { statusline.updateUrl(); if (prev.mainMode.input || prev.mainMode.ownsFocus) dactyl.focusContent(true); - if (prev.main === modes.NORMAL) { + if (prev.main == modes.NORMAL) { dactyl.focusContent(true); // clear any selection made let selection = window.content.getSelection(); @@ -141,7 +141,7 @@ const Modes = Module("modes", { addMode: function (name, extended, options, params) { let disp = name.replace("_", " ", "g"); - this[name] = 1 << this._lastMode++; + let mode = this[name] = new Number(1 << this._lastMode++); if (typeof extended == "object") { params = options; @@ -149,7 +149,7 @@ const Modes = Module("modes", { extended = false; } - let mode = util.extend({ + util.extend(mode, { count: true, disp: disp, extended: extended, @@ -221,9 +221,9 @@ const Modes = Module("modes", { let oldMain = this._main, oldExtended = this._extended; - if (typeof extendedMode === "number") + if (extendedMode != null) this._extended = extendedMode; - if (typeof mainMode === "number") { + if (mainMode != null) { this._main = mainMode; if (!extendedMode) this._extended = this.NONE; @@ -265,9 +265,9 @@ const Modes = Module("modes", { }, onCaretChange: function onPrefChange(value) { - if (!value && modes.main === modes.CARET) + if (!value && modes.main == modes.CARET) modes.pop(); - if (value && modes.main === modes.NORMAL) + if (value && modes.main == modes.NORMAL) modes.push(modes.CARET); }, @@ -325,7 +325,7 @@ const Modes = Module("modes", { let struct = Struct("main", "extended", "params", "saved"); struct.prototype.__defineGetter__("mainMode", function () modes.getMode(this.main)); struct.prototype.toString = function () !loaded.modes ? this.main : "[mode " + - modes.getMode(this.main).name + + this.mainMode.name + (!this.extended ? "" : "(" + [modes.getMode(1 << i).name for (i in util.range(0, 32)) if (this.extended & (1 << i))].join("|") +