From 0e8e9e7110edea38a7c3e11fba5a3015827596f7 Mon Sep 17 00:00:00 2001 From: Zheng Chaoping Date: Mon, 5 Sep 2016 23:55:43 +0800 Subject: [PATCH 1/2] Fix `TypeError: options is undefined` When open a new window and close it, then press `gg` in the original window will throw `TypeError: options is undefined`. --- common/content/dactyl.js | 14 +++++++++++++- common/content/events.js | 3 --- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 53106cada..48e2a96bd 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -2071,8 +2071,20 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { dactyl.initialized = true; util.delay(() => { - if (services.focus.activeWindow === window) + if (services.focus.activeWindow === window) { overlay.activeWindow = window; + } else { + const onActivate = evt => { + if (evt.target === window) { + overlay.activeWindow = window; + } + } + window.addEventListener("activate", onActivate, true); + window.addEventListener("unload", function onUnload() { + window.removeEventListener("unload", onUnload); + window.removeEventListener("activate", onActivate, true); + }); + } util.flushLateMethods(dactyl); }); diff --git a/common/content/events.js b/common/content/events.js index 9cd552b5e..574d75665 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -618,9 +618,6 @@ var Events = Module("events", { util.trapErrors("addEditActionListener", DOM(elem).editor, editor); - if (elem == window) - overlay.activeWindow = window; - overlay.setData(elem, "had-focus", true); if (event.target instanceof Ci.nsIDOMXULTextBoxElement) if (Events.isHidden(elem, true)) From 2d4bfe7e05e2a002a02220f7e4618bf805086362 Mon Sep 17 00:00:00 2001 From: Zheng Chaoping Date: Tue, 6 Sep 2016 10:37:50 +0800 Subject: [PATCH 2/2] Improve to listen to 'activate' event --- common/content/dactyl.js | 19 ------------------- common/content/events.js | 6 ++++++ 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/common/content/dactyl.js b/common/content/dactyl.js index 48e2a96bd..0b675140f 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -2069,25 +2069,6 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), { statusline.update(); dactyl.log(_("dactyl.initialized", config.appName), 0); dactyl.initialized = true; - - util.delay(() => { - if (services.focus.activeWindow === window) { - overlay.activeWindow = window; - } else { - const onActivate = evt => { - if (evt.target === window) { - overlay.activeWindow = window; - } - } - window.addEventListener("activate", onActivate, true); - window.addEventListener("unload", function onUnload() { - window.removeEventListener("unload", onUnload); - window.removeEventListener("activate", onActivate, true); - }); - } - - util.flushLateMethods(dactyl); - }); } }); diff --git a/common/content/events.js b/common/content/events.js index 574d75665..57729de79 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -870,6 +870,12 @@ var Events = Module("events", { autocommands.trigger("Fullscreen", { url: this._fullscreen ? "on" : "off", state: this._fullscreen }); } statusline.updateZoomLevel(); + }, + + activate: function onActivate(event) { + if (event.target === window) { + overlay.activeWindow = window; + } } },