mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 18:47:58 +01:00
Minor enhancements to <C-i>/<C-o>
This commit is contained in:
@@ -279,7 +279,7 @@ var Buffer = Module("buffer", {
|
||||
localStorePrototype: memoize({
|
||||
instance: {},
|
||||
get jumps() [],
|
||||
jumpsIndex: 0
|
||||
jumpsIndex: -1
|
||||
}),
|
||||
|
||||
/**
|
||||
@@ -1268,10 +1268,12 @@ var Buffer = Module("buffer", {
|
||||
* null, to not alter the horizontal scroll offset.
|
||||
* @param {number|null} top The top absolute pixel offset. If
|
||||
* null, to not alter the vertical scroll offset.
|
||||
* @param {string} reason The reason for the scroll event. See
|
||||
* {@link marks.push}. @optional
|
||||
*/
|
||||
scrollTo: function scrollTo(elem, left, top) {
|
||||
scrollTo: function scrollTo(elem, left, top, reason) {
|
||||
if (elem.ownerDocument == buffer.focusedFrame.document)
|
||||
marks.push();
|
||||
marks.push(reason);
|
||||
|
||||
if (left != null)
|
||||
elem.scrollLeft = left;
|
||||
@@ -1288,7 +1290,7 @@ var Buffer = Module("buffer", {
|
||||
* Scrolls the currently given element horizontally.
|
||||
*
|
||||
* @param {Element} elem The element to scroll.
|
||||
* @param {string} increment The increment by which to scroll.
|
||||
* @param {string} unit The increment by which to scroll.
|
||||
* Possible values are: "columns", "pages"
|
||||
* @param {number} number The possibly fractional number of
|
||||
* increments to scroll. Positive values scroll to the right while
|
||||
@@ -1296,11 +1298,12 @@ var Buffer = Module("buffer", {
|
||||
* @throws {FailedAssertion} if scrolling is not possible in the
|
||||
* given direction.
|
||||
*/
|
||||
scrollHorizontal: function scrollHorizontal(elem, increment, number) {
|
||||
scrollHorizontal: function scrollHorizontal(elem, unit, number) {
|
||||
let fontSize = parseInt(util.computedStyle(elem).fontSize);
|
||||
if (increment == "columns")
|
||||
let increment;
|
||||
if (unit == "columns")
|
||||
increment = fontSize; // Good enough, I suppose.
|
||||
else if (increment == "pages")
|
||||
else if (unit == "pages")
|
||||
increment = elem.clientWidth - fontSize;
|
||||
else
|
||||
throw Error();
|
||||
@@ -1310,14 +1313,14 @@ var Buffer = Module("buffer", {
|
||||
let left = elem.dactylScrollDestX !== undefined ? elem.dactylScrollDestX : elem.scrollLeft;
|
||||
elem.dactylScrollDestX = undefined;
|
||||
|
||||
Buffer.scrollTo(elem, left + number * increment, null);
|
||||
Buffer.scrollTo(elem, left + number * increment, null, "h-" + unit);
|
||||
},
|
||||
|
||||
/**
|
||||
* Scrolls the currently given element vertically.
|
||||
*
|
||||
* @param {Element} elem The element to scroll.
|
||||
* @param {string} increment The increment by which to scroll.
|
||||
* @param {string} unit The increment by which to scroll.
|
||||
* Possible values are: "lines", "pages"
|
||||
* @param {number} number The possibly fractional number of
|
||||
* increments to scroll. Positive values scroll upward while
|
||||
@@ -1325,11 +1328,12 @@ var Buffer = Module("buffer", {
|
||||
* @throws {FailedAssertion} if scrolling is not possible in the
|
||||
* given direction.
|
||||
*/
|
||||
scrollVertical: function scrollVertical(elem, increment, number) {
|
||||
scrollVertical: function scrollVertical(elem, unit, number) {
|
||||
let fontSize = parseInt(util.computedStyle(elem).lineHeight);
|
||||
if (increment == "lines")
|
||||
let increment;
|
||||
if (unit == "lines")
|
||||
increment = fontSize;
|
||||
else if (increment == "pages")
|
||||
else if (unit == "pages")
|
||||
increment = elem.clientHeight - fontSize;
|
||||
else
|
||||
throw Error();
|
||||
@@ -1339,7 +1343,7 @@ var Buffer = Module("buffer", {
|
||||
let top = elem.dactylScrollDestY !== undefined ? elem.dactylScrollDestY : elem.scrollTop;
|
||||
elem.dactylScrollDestY = undefined;
|
||||
|
||||
Buffer.scrollTo(elem, null, top + number * increment);
|
||||
Buffer.scrollTo(elem, null, top + number * increment, "v-" + unit);
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -78,16 +78,32 @@ var Marks = Module("marks", {
|
||||
|
||||
/**
|
||||
* Push the current buffer position onto the jump stack.
|
||||
*
|
||||
* @param {string} reason The reason for this scroll event. Multiple
|
||||
* scroll events for the same reason are coalesced. @optional
|
||||
*/
|
||||
push: function push() {
|
||||
if (!this.jumping) {
|
||||
let mark = this.add("'");
|
||||
push: function push(reason) {
|
||||
let store = buffer.localStore;
|
||||
store.jumps[store.jumpsIndex++] = mark;
|
||||
store.jumps.length = store.jumpsIndex;
|
||||
let jump = store.jumps[store.jumpsIndex];
|
||||
|
||||
if (reason && jump && jump.reason == reason)
|
||||
return;
|
||||
|
||||
let mark = this.add("'");
|
||||
|
||||
if (!this.jumping) {
|
||||
store.jumps[++store.jumpsIndex] = { mark: mark, reason: reason };
|
||||
store.jumps.length = store.jumpsIndex + 1;
|
||||
|
||||
if (store.jumps.length > this.maxJumps) {
|
||||
store.jumps = store.jumps.slice(-this.maxJumps);
|
||||
store.jumpsIndex = store.jumps.length - 1;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
maxJumps: 200,
|
||||
|
||||
/**
|
||||
* Jump to the given offset in the jump stack.
|
||||
*
|
||||
@@ -96,13 +112,16 @@ var Marks = Module("marks", {
|
||||
* @returns {number} The actual change in offset.
|
||||
*/
|
||||
jump: function jump(offset) {
|
||||
let store = buffer.localStore;
|
||||
if (offset < 0 && store.jumpsIndex == store.jumps.length - 1)
|
||||
this.push();
|
||||
|
||||
return this.withSavedValues(["jumping"], function _jump() {
|
||||
this.jumping = true;
|
||||
let store = buffer.localStore;
|
||||
let idx = Math.constrain(store.jumpsIndex + offset, 0, store.jumps.length - 1);
|
||||
let orig = store.jumpsIndex;
|
||||
|
||||
if (idx in store.jumps && !dactyl.trapErrors("_scrollTo", this, store.jumps[idx]))
|
||||
if (idx in store.jumps && !dactyl.trapErrors("_scrollTo", this, store.jumps[idx].mark))
|
||||
store.jumpsIndex = idx;
|
||||
return store.jumpsIndex - orig;
|
||||
});
|
||||
|
||||
@@ -12,6 +12,7 @@ BUGS:
|
||||
- RC file is sourced once per window
|
||||
|
||||
FEATURES:
|
||||
9 Add more tests.
|
||||
9 <C-o>/<C-i> should work as in Vim (i.e., save page positions as well as
|
||||
locations in the history list).
|
||||
9 clean up error message codes and document
|
||||
|
||||
Reference in New Issue
Block a user