mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-21 15:47:59 +01:00
Fix some marks issues. Always scroll to the [count]th line rather than the [count]th percent with n_G.
This commit is contained in:
@@ -348,7 +348,7 @@ var Buffer = Module("buffer", {
|
|||||||
* @property {number} The buffer's horizontal scroll percentile.
|
* @property {number} The buffer's horizontal scroll percentile.
|
||||||
*/
|
*/
|
||||||
get scrollXPercent() {
|
get scrollXPercent() {
|
||||||
let elem = this.findScrollable(0, true);
|
let elem = Buffer.Scrollable(this.findScrollable(0, true));
|
||||||
if (elem.scrollWidth - elem.clientWidth === 0)
|
if (elem.scrollWidth - elem.clientWidth === 0)
|
||||||
return 0;
|
return 0;
|
||||||
return elem.scrollLeft * 100 / (elem.scrollWidth - elem.clientWidth);
|
return elem.scrollLeft * 100 / (elem.scrollWidth - elem.clientWidth);
|
||||||
@@ -358,7 +358,7 @@ var Buffer = Module("buffer", {
|
|||||||
* @property {number} The buffer's vertical scroll percentile.
|
* @property {number} The buffer's vertical scroll percentile.
|
||||||
*/
|
*/
|
||||||
get scrollYPercent() {
|
get scrollYPercent() {
|
||||||
let elem = this.findScrollable(0, false);
|
let elem = Buffer.Scrollable(this.findScrollable(0, false));
|
||||||
if (elem.scrollHeight - elem.clientHeight === 0)
|
if (elem.scrollHeight - elem.clientHeight === 0)
|
||||||
return 0;
|
return 0;
|
||||||
return elem.scrollTop * 100 / (elem.scrollHeight - elem.clientHeight);
|
return elem.scrollTop * 100 / (elem.scrollHeight - elem.clientHeight);
|
||||||
@@ -788,25 +788,6 @@ var Buffer = Module("buffer", {
|
|||||||
if (Buffer.isScrollable(elem, dir, horizontal))
|
if (Buffer.isScrollable(elem, dir, horizontal))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (!(elem instanceof Element))
|
|
||||||
return {
|
|
||||||
__proto__: elem.documentElement || elem.ownerDocument.documentElement,
|
|
||||||
|
|
||||||
win: elem.defaultView || elem.ownerDocument.defaultView,
|
|
||||||
|
|
||||||
get clientWidth() this.win.innerWidth,
|
|
||||||
get clientHeight() this.win.innerHeight,
|
|
||||||
|
|
||||||
get scrollWidth() this.win.scrollMaxX + this.win.innerWidth,
|
|
||||||
get scrollHeight() this.win.scrollMaxY + this.win.innerHeight,
|
|
||||||
|
|
||||||
get scrollLeft() this.win.scrollX,
|
|
||||||
set scrollLeft(val) { this.win.scrollTo(val, this.win.scrollY) },
|
|
||||||
|
|
||||||
get scrollTop() this.win.scrollY,
|
|
||||||
set scrollTop(val) { this.win.scrollTo(this.win.scrollX, val) }
|
|
||||||
};
|
|
||||||
|
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1213,6 +1194,30 @@ var Buffer = Module("buffer", {
|
|||||||
PageInfo: Struct("PageInfo", "name", "title", "action")
|
PageInfo: Struct("PageInfo", "name", "title", "action")
|
||||||
.localize("title"),
|
.localize("title"),
|
||||||
|
|
||||||
|
Scrollable: function Scrollable(elem) {
|
||||||
|
if (elem instanceof Element)
|
||||||
|
return elem;
|
||||||
|
if (isinstance(elem, [Window, Document]))
|
||||||
|
return {
|
||||||
|
__proto__: elem.documentElement || elem.ownerDocument.documentElement,
|
||||||
|
|
||||||
|
win: elem.defaultView || elem.ownerDocument.defaultView,
|
||||||
|
|
||||||
|
get clientWidth() this.win.innerWidth,
|
||||||
|
get clientHeight() this.win.innerHeight,
|
||||||
|
|
||||||
|
get scrollWidth() this.win.scrollMaxX + this.win.innerWidth,
|
||||||
|
get scrollHeight() this.win.scrollMaxY + this.win.innerHeight,
|
||||||
|
|
||||||
|
get scrollLeft() this.win.scrollX,
|
||||||
|
set scrollLeft(val) { this.win.scrollTo(val, this.win.scrollY) },
|
||||||
|
|
||||||
|
get scrollTop() this.win.scrollY,
|
||||||
|
set scrollTop(val) { this.win.scrollTo(this.win.scrollX, val) }
|
||||||
|
};
|
||||||
|
return elem;
|
||||||
|
},
|
||||||
|
|
||||||
ZOOM_MIN: Class.Memoize(function () prefs.get("zoom.minPercent")),
|
ZOOM_MIN: Class.Memoize(function () prefs.get("zoom.minPercent")),
|
||||||
ZOOM_MAX: Class.Memoize(function () prefs.get("zoom.maxPercent")),
|
ZOOM_MAX: Class.Memoize(function () prefs.get("zoom.maxPercent")),
|
||||||
|
|
||||||
@@ -1318,9 +1323,10 @@ var Buffer = Module("buffer", {
|
|||||||
* {@link marks.push}. @optional
|
* {@link marks.push}. @optional
|
||||||
*/
|
*/
|
||||||
scrollTo: function scrollTo(elem, left, top, reason) {
|
scrollTo: function scrollTo(elem, left, top, reason) {
|
||||||
if (elem.ownerDocument == buffer.focusedFrame.document)
|
if (~[elem, elem.document, elem.ownerDocument].indexOf(buffer.focusedFrame.document))
|
||||||
marks.push(reason);
|
marks.push(reason);
|
||||||
|
|
||||||
|
elem = Buffer.Scrollable(elem);
|
||||||
if (left != null)
|
if (left != null)
|
||||||
elem.scrollLeft = left;
|
elem.scrollLeft = left;
|
||||||
if (top != null)
|
if (top != null)
|
||||||
@@ -1346,6 +1352,8 @@ var Buffer = Module("buffer", {
|
|||||||
*/
|
*/
|
||||||
scrollHorizontal: function scrollHorizontal(elem, unit, number) {
|
scrollHorizontal: function scrollHorizontal(elem, unit, number) {
|
||||||
let fontSize = parseInt(DOM(elem).style.fontSize);
|
let fontSize = parseInt(DOM(elem).style.fontSize);
|
||||||
|
|
||||||
|
elem = Buffer.Scrollable(elem);
|
||||||
let increment;
|
let increment;
|
||||||
if (unit == "columns")
|
if (unit == "columns")
|
||||||
increment = fontSize; // Good enough, I suppose.
|
increment = fontSize; // Good enough, I suppose.
|
||||||
@@ -1376,6 +1384,8 @@ var Buffer = Module("buffer", {
|
|||||||
*/
|
*/
|
||||||
scrollVertical: function scrollVertical(elem, unit, number) {
|
scrollVertical: function scrollVertical(elem, unit, number) {
|
||||||
let fontSize = parseInt(DOM(elem).style.lineHeight);
|
let fontSize = parseInt(DOM(elem).style.lineHeight);
|
||||||
|
|
||||||
|
elem = Buffer.Scrollable(elem);
|
||||||
let increment;
|
let increment;
|
||||||
if (unit == "lines")
|
if (unit == "lines")
|
||||||
increment = fontSize;
|
increment = fontSize;
|
||||||
@@ -1405,6 +1415,7 @@ var Buffer = Module("buffer", {
|
|||||||
* scroll vertically.
|
* scroll vertically.
|
||||||
*/
|
*/
|
||||||
scrollToPercent: function scrollToPercent(elem, horizontal, vertical) {
|
scrollToPercent: function scrollToPercent(elem, horizontal, vertical) {
|
||||||
|
elem = Buffer.Scrollable(elem);
|
||||||
Buffer.scrollTo(elem,
|
Buffer.scrollTo(elem,
|
||||||
horizontal == null ? null
|
horizontal == null ? null
|
||||||
: (elem.scrollWidth - elem.clientWidth) * (horizontal / 100),
|
: (elem.scrollWidth - elem.clientWidth) * (horizontal / 100),
|
||||||
@@ -1423,7 +1434,7 @@ var Buffer = Module("buffer", {
|
|||||||
* column ordinal to scroll to.
|
* column ordinal to scroll to.
|
||||||
*/
|
*/
|
||||||
scrollToPosition: function scrollToPosition(elem, horizontal, vertical) {
|
scrollToPosition: function scrollToPosition(elem, horizontal, vertical) {
|
||||||
let style = DOM(elem).style;
|
let style = DOM(elem.body || elem).style;
|
||||||
Buffer.scrollTo(elem,
|
Buffer.scrollTo(elem,
|
||||||
horizontal == null ? null :
|
horizontal == null ? null :
|
||||||
horizontal == 0 ? 0 : this._exWidth(elem) * horizontal,
|
horizontal == 0 ? 0 : this._exWidth(elem) * horizontal,
|
||||||
@@ -1438,6 +1449,8 @@ var Buffer = Module("buffer", {
|
|||||||
*/
|
*/
|
||||||
getScrollPosition: function getPosition(elem) {
|
getScrollPosition: function getPosition(elem) {
|
||||||
let style = DOM(elem).style;
|
let style = DOM(elem).style;
|
||||||
|
|
||||||
|
elem = Buffer.Scrollable(elem);
|
||||||
return {
|
return {
|
||||||
x: elem.scrollLeft && elem.scrollLeft / this._exWidth(elem),
|
x: elem.scrollLeft && elem.scrollLeft / this._exWidth(elem),
|
||||||
y: elem.scrollTop / parseFloat(style.lineHeight)
|
y: elem.scrollTop / parseFloat(style.lineHeight)
|
||||||
@@ -1446,7 +1459,7 @@ var Buffer = Module("buffer", {
|
|||||||
|
|
||||||
_exWidth: function _exWidth(elem) {
|
_exWidth: function _exWidth(elem) {
|
||||||
let div = DOM(<elem style="width: 1ex !important; position: absolute !important; padding: 0 !important; display: block;"/>,
|
let div = DOM(<elem style="width: 1ex !important; position: absolute !important; padding: 0 !important; display: block;"/>,
|
||||||
elem.ownerDocument).appendTo(elem);
|
elem.ownerDocument).appendTo(elem.body || elem);
|
||||||
try {
|
try {
|
||||||
return parseFloat(div.style.width);
|
return parseFloat(div.style.width);
|
||||||
}
|
}
|
||||||
@@ -1847,8 +1860,10 @@ var Buffer = Module("buffer", {
|
|||||||
args.count);
|
args.count);
|
||||||
if (elem)
|
if (elem)
|
||||||
elem.scrollIntoView(true);
|
elem.scrollIntoView(true);
|
||||||
|
else if (args.count)
|
||||||
|
buffer.scrollToPosition(null, args.count);
|
||||||
else
|
else
|
||||||
buffer.scrollToPercent(null, args.count != null ? args.count : 100);
|
buffer.scrollToPercent(null, 100);
|
||||||
},
|
},
|
||||||
{ count: true });
|
{ count: true });
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ var Marks = Module("marks", {
|
|||||||
this._urlMarks
|
this._urlMarks
|
||||||
).sort(function (a, b) String.localeCompare(a[0], b[0])),
|
).sort(function (a, b) String.localeCompare(a[0], b[0])),
|
||||||
|
|
||||||
get localURI() buffer.focusedFrame.document.documentURI,
|
get localURI() buffer.focusedFrame.document.documentURI.replace(/#.*/, ""),
|
||||||
|
|
||||||
Mark: function Mark(params) {
|
Mark: function Mark(params) {
|
||||||
let win = buffer.focusedFrame;
|
let win = buffer.focusedFrame;
|
||||||
@@ -40,7 +40,7 @@ var Marks = Module("marks", {
|
|||||||
|
|
||||||
params = params || {};
|
params = params || {};
|
||||||
|
|
||||||
params.location = doc.documentURI,
|
params.location = doc.documentURI.replace(/#.*/, ""),
|
||||||
params.offset = buffer.scrollPosition;
|
params.offset = buffer.scrollPosition;
|
||||||
params.path = DOM(buffer.findScrollable(0, params.offset.x)).xpath;
|
params.path = DOM(buffer.findScrollable(0, params.offset.x)).xpath;
|
||||||
params.timestamp = Date.now() * 1000;
|
params.timestamp = Date.now() * 1000;
|
||||||
@@ -175,7 +175,7 @@ var Marks = Module("marks", {
|
|||||||
let tab = mark.tab && mark.tab.get();
|
let tab = mark.tab && mark.tab.get();
|
||||||
if (!tab || !tab.linkedBrowser || tabs.allTabs.indexOf(tab) == -1)
|
if (!tab || !tab.linkedBrowser || tabs.allTabs.indexOf(tab) == -1)
|
||||||
for ([, tab] in iter(tabs.visibleTabs, tabs.allTabs)) {
|
for ([, tab] in iter(tabs.visibleTabs, tabs.allTabs)) {
|
||||||
if (tab.linkedBrowser.contentDocument.documentURI === mark.location)
|
if (tab.linkedBrowser.contentDocument.documentURI.replace(/#.*/, "") === mark.location)
|
||||||
break;
|
break;
|
||||||
tab = null;
|
tab = null;
|
||||||
}
|
}
|
||||||
@@ -183,7 +183,7 @@ var Marks = Module("marks", {
|
|||||||
if (tab) {
|
if (tab) {
|
||||||
tabs.select(tab);
|
tabs.select(tab);
|
||||||
let doc = tab.linkedBrowser.contentDocument;
|
let doc = tab.linkedBrowser.contentDocument;
|
||||||
if (doc.documentURI == mark.location) {
|
if (doc.documentURI.replace(/#.*/, "") == mark.location) {
|
||||||
dactyl.log(_("mark.jumpingToURL", Marks.markToString(char, mark)), 5);
|
dactyl.log(_("mark.jumpingToURL", Marks.markToString(char, mark)), 5);
|
||||||
this._scrollTo(mark);
|
this._scrollTo(mark);
|
||||||
}
|
}
|
||||||
@@ -231,6 +231,7 @@ var Marks = Module("marks", {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
util.assert(node);
|
util.assert(node);
|
||||||
|
if (node instanceof Element)
|
||||||
DOM(node).scrollIntoView();
|
DOM(node).scrollIntoView();
|
||||||
|
|
||||||
if (mark.offset)
|
if (mark.offset)
|
||||||
|
|||||||
@@ -135,8 +135,7 @@
|
|||||||
<p>
|
<p>
|
||||||
Go to the end of the document. With <oa>count</oa>,
|
Go to the end of the document. With <oa>count</oa>,
|
||||||
go to the <oa>count</oa>th line as determined by <o>linenumbers</o>,
|
go to the <oa>count</oa>th line as determined by <o>linenumbers</o>,
|
||||||
or to the <oa>count</oa>th percent of the document if the line number
|
or by the line height of the document body otherwise.
|
||||||
can't be determined.
|
|
||||||
</p>
|
</p>
|
||||||
</description>
|
</description>
|
||||||
</item>
|
</item>
|
||||||
|
|||||||
@@ -372,6 +372,10 @@ var DOM = Class("DOM", {
|
|||||||
*/
|
*/
|
||||||
get style() {
|
get style() {
|
||||||
let node = this[0];
|
let node = this[0];
|
||||||
|
if (node instanceof Ci.nsIDOMWindow)
|
||||||
|
node = node.document;
|
||||||
|
if (node instanceof Ci.nsIDOMDocument)
|
||||||
|
node = node.documentElement;
|
||||||
while (node && !(node instanceof Ci.nsIDOMElement) && node.parentNode)
|
while (node && !(node instanceof Ci.nsIDOMElement) && node.parentNode)
|
||||||
node = node.parentNode;
|
node = node.parentNode;
|
||||||
|
|
||||||
@@ -462,6 +466,8 @@ var DOM = Class("DOM", {
|
|||||||
*/
|
*/
|
||||||
get xpath() {
|
get xpath() {
|
||||||
function quote(val) "'" + val.replace(/[\\']/g, "\\$&") + "'";
|
function quote(val) "'" + val.replace(/[\\']/g, "\\$&") + "'";
|
||||||
|
if (!this[0] instanceof Ci.nsIDOMElement)
|
||||||
|
return null;
|
||||||
|
|
||||||
let res = [];
|
let res = [];
|
||||||
let doc = this.document;
|
let doc = this.document;
|
||||||
|
|||||||
@@ -484,10 +484,11 @@ var RangeFind = Class("RangeFind", {
|
|||||||
let saved = ["lastRange", "lastString", "range", "regexp"].map(function (s) [s, this[s]], this);
|
let saved = ["lastRange", "lastString", "range", "regexp"].map(function (s) [s, this[s]], this);
|
||||||
let res;
|
let res;
|
||||||
try {
|
try {
|
||||||
|
let regexp = this.regexp && word != util.regexp.escape(word);
|
||||||
this.lastRange = null;
|
this.lastRange = null;
|
||||||
if (this.regexp) {
|
|
||||||
let re = RegExp(word, "gm" + this.flags);
|
|
||||||
this.regexp = false;
|
this.regexp = false;
|
||||||
|
if (regexp) {
|
||||||
|
let re = RegExp(word, "gm" + this.flags);
|
||||||
for (this.range in array.iterValues(this.ranges)) {
|
for (this.range in array.iterValues(this.ranges)) {
|
||||||
for (let match in util.regexp.iterate(re, DOM.stringify(this.range.range, true))) {
|
for (let match in util.regexp.iterate(re, DOM.stringify(this.range.range, true))) {
|
||||||
let lastRange = this.lastRange;
|
let lastRange = this.lastRange;
|
||||||
@@ -635,8 +636,9 @@ var RangeFind = Class("RangeFind", {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let word = pattern;
|
let word = pattern;
|
||||||
|
let regexp = this.regexp && word != util.regexp.escape(word);
|
||||||
|
|
||||||
if (this.regexp)
|
if (regexp)
|
||||||
try {
|
try {
|
||||||
RegExp(pattern);
|
RegExp(pattern);
|
||||||
}
|
}
|
||||||
@@ -661,7 +663,7 @@ var RangeFind = Class("RangeFind", {
|
|||||||
if (this.backward && !again)
|
if (this.backward && !again)
|
||||||
start = RangeFind.endpoint(this.startRange, false);
|
start = RangeFind.endpoint(this.startRange, false);
|
||||||
|
|
||||||
if (this.regexp) {
|
if (regexp) {
|
||||||
let range = this.range.range.cloneRange();
|
let range = this.range.range.cloneRange();
|
||||||
range[this.backward ? "setEnd" : "setStart"](
|
range[this.backward ? "setEnd" : "setStart"](
|
||||||
start.startContainer, start.startOffset);
|
start.startContainer, start.startOffset);
|
||||||
|
|||||||
Reference in New Issue
Block a user