diff --git a/common/content/autocommands.js b/common/content/autocommands.js index fc1b882e..894bc67d 100644 --- a/common/content/autocommands.js +++ b/common/content/autocommands.js @@ -271,10 +271,6 @@ const AutoCommands = Module("autocommands", { { completer: function () Iterator(update({ all: "All Events" }, config.autocommands)) }); - - options.add(["strictfocus", "sf"], - "Prevent scripts from focusing input elements without user intervention", - "boolean", true); } }); diff --git a/common/content/dactyl.js b/common/content/dactyl.js index df41e43a..d929a660 100644 --- a/common/content/dactyl.js +++ b/common/content/dactyl.js @@ -1222,6 +1222,7 @@ const Dactyl = Module("dactyl", { for (let [, group] in Iterator(groups)) if (!group.feature || dactyl.has(group.feature)) group.setter(value); + events.checkFocus(); return value; }, completer: function (context) { @@ -1715,12 +1716,13 @@ const Dactyl = Module("dactyl", { "./*[@toolbarname=" + util.escapeString(name, "'") + "]", document, toolbox).snapshotItem(0); - let tbcmd = function (names, desc, action, filter) { + let toolbarCommand = function (names, desc, action, filter) { commands.add(names, desc, function (args) { let toolbar = findToolbar(args[0] || ""); dactyl.assert(toolbar, "E474: Invalid argument"); action(toolbar); + events.checkFocus(); }, { argcount: "1", completer: function (context) { @@ -1732,13 +1734,13 @@ const Dactyl = Module("dactyl", { }); }; - tbcmd(["toolbars[how]", "tbs[how]"], "Show the named toolbar", + toolbarCommand(["toolbars[how]", "tbs[how]"], "Show the named toolbar", function (toolbar) toolbar.collapsed = false, function (item) item.item.collapsed); - tbcmd(["toolbarh[ide]", "tbh[ide]"], "Hide the named toolbar", + toolbarCommand(["toolbarh[ide]", "tbh[ide]"], "Hide the named toolbar", function (toolbar) toolbar.collapsed = true, function (item) !item.item.collapsed); - tbcmd(["toolbart[oggle]", "tbt[oggle]"], "Toggle the named toolbar", + toolbarCommand(["toolbart[oggle]", "tbt[oggle]"], "Toggle the named toolbar", function (toolbar) toolbar.collapsed = !toolbar.collapsed); } diff --git a/common/content/events.js b/common/content/events.js index d8a80ebd..42dbb5ae 100644 --- a/common/content/events.js +++ b/common/content/events.js @@ -693,6 +693,21 @@ const Events = Module("events", { } }, + /** + * Ensures that the currently focused element is visible and blurs + * it if it's not. + */ + checkFocus: function () { + if (dactyl.focus) { + let rect = dactyl.focus.getBoundingClientRect(); + if (!rect.width || !rect.height) { + dactyl.focus.blur(); + // onFocusChange needs to die. + this.onFocusChange(); + } + } + }, + // TODO: Merge with onFocusChange onFocus: function (event) { let elem = event.originalTarget; @@ -1157,6 +1172,11 @@ const Events = Module("events", { }, { arg: true, count: true }); }, + options: function () { + options.add(["strictfocus", "sf"], + "Prevent scripts from focusing input elements without user intervention", + "boolean", true); + }, sanitizer: function () { sanitizer.addItem("macros", { description: "Saved macros",