1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-11 14:44:12 +01:00

Handle "gi" properly on frameset documents when no last focused element.

This commit is contained in:
Kris Maglione
2010-10-03 15:04:11 -04:00
parent 60df536305
commit 49d6841b0d
2 changed files with 16 additions and 10 deletions

View File

@@ -348,8 +348,8 @@ const Buffer = Module("buffer", {
* @property {Node} The last focused input field in the buffer. Used
* by the "gi" key binding.
*/
get lastInputField() window.content.document.lastInputField || null,
set lastInputField(value) { window.content.document.lastInputField = value; },
get lastInputField() this.localStore.lastInputField && this.localStore.lastInputField.get() || null,
set lastInputField(value) { this.localStore.lastInputField = value && Cu.getWeakReference(value); },
/**
* @property {string} The current top-level document's URL.
@@ -1609,24 +1609,30 @@ const Buffer = Module("buffer", {
mappings.add(myModes, ["gi"],
"Focus last used input field",
function (count) {
if (count < 1 && buffer.lastInputField)
buffer.focusElement(buffer.lastInputField);
else {
let elem = buffer.lastInputField;
if (count >= 1 || !elem || !Events.isContentNode(elem)) {
let xpath = ["input", "textarea[not(@disabled) and not(@readonly)]"];
let elements = [m for (m in util.evaluateXPath(xpath))].filter(function (elem) {
let frames = array([buffer.focusedFrame].concat(
buffer.allFrames().filter(function (f) f != buffer.focusedFrame)));
let elements = frames.map(function (win) [m for (m in util.evaluateXPath(xpath, win.document))])
.flatten().filter(function (elem) {
if (elem.readOnly || elem instanceof HTMLInputElement && !set.has(Events.editableInputs, elem.type))
return false;
let computedStyle = util.computedStyle(elem);
return computedStyle.visibility != "hidden" && computedStyle.display != "none" &&
computedStyle.MozUserFocus != "ignore";
});
dactyl.assert(elements.length > 0);
let elem = elements[Math.constrain(count, 1, elements.length) - 1];
buffer.focusElement(elem);
util.scrollIntoView(elem);
elem = elements[Math.constrain(count, 1, elements.length) - 1];
}
buffer.focusElement(elem);
util.scrollIntoView(elem);
},
{ count: true });

View File

@@ -962,7 +962,7 @@ const array = Class("array", Array, {
},
array: ary,
toString: function () this.array.toString(),
concat: function () this.array.concat.apply(this.array, arguments),
concat: function () this.__noSuchMethod__("concat", Array.slice(arguments)),
filter: function () this.__noSuchMethod__("filter", Array.slice(arguments)),
map: function () this.__noSuchMethod__("map", Array.slice(arguments))
};