diff --git a/common/content/buffer.js b/common/content/buffer.js index cdcdba97..dda58534 100644 --- a/common/content/buffer.js +++ b/common/content/buffer.js @@ -1490,8 +1490,8 @@ const Buffer = Module("buffer", { liberator.assert(elements.length > 0); let elem = elements[util.Math.constrain(count, 1, elements.length) - 1]; - elem.scrollIntoView(); buffer.focusElement(elem); + util.scrollIntoView(elem); } }, { count: true }); diff --git a/common/content/commandline.js b/common/content/commandline.js index 3d358b7c..81e54619 100644 --- a/common/content/commandline.js +++ b/common/content/commandline.js @@ -1034,7 +1034,7 @@ const CommandLine = Module("commandline", { sanitize: function (timespan) { let range = [0, Number.MAX_VALUE]; if (liberator.has("sanitizer") && (timespan || options["sanitizetimespan"])) - range = sanitizer.getClearRange(timespan || options["sanitizetimespan"]); + range = Sanitizer.getClearRange(timespan || options["sanitizetimespan"]); const self = this; this.store.mutate("filter", function (item) { diff --git a/common/content/sanitizer.js b/common/content/sanitizer.js index 1b3afcc4..146f6fa4 100644 --- a/common/content/sanitizer.js +++ b/common/content/sanitizer.js @@ -19,6 +19,7 @@ const Sanitizer = Module("sanitizer", { init: function () { const self = this; liberator.loadScript("chrome://browser/content/sanitize.js", Sanitizer); + Sanitizer.getClearRange = Sanitizer.Sanitizer.getClearRange; this.__proto__.__proto__ = new Sanitizer.Sanitizer; // Good enough. // TODO: remove this version test diff --git a/common/content/util.js b/common/content/util.js index d1c5656f..77e74526 100644 --- a/common/content/util.js +++ b/common/content/util.js @@ -673,6 +673,20 @@ const Util = Module("util", { return str; }, + /** + * Scrolls an element into view if and only if it's not already + * fully visible. + * + * @param {Node} elem The element to make visible. + */ + scrollIntoView: function scrollIntoView(elem) { + let win = elem.ownerDocument.defaultView; + let rect = elem.getBoundingClientRect(); + if (!(rect && rect.top < win.innerHeight && rect.bottom >= 0 && rect.left < win.innerWidth && rect.right >= 0)) + elem.scrollIntoView(); + }, + + /** * Returns an array of URLs parsed from str. *