1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2025-12-20 23:27:59 +01:00

Minor enhancements to <C-i>/<C-o>

This commit is contained in:
Kris Maglione
2011-08-09 14:50:51 -04:00
parent 9df1f7b6cf
commit 9bdb4411af
3 changed files with 44 additions and 20 deletions

View File

@@ -279,7 +279,7 @@ var Buffer = Module("buffer", {
localStorePrototype: memoize({ localStorePrototype: memoize({
instance: {}, instance: {},
get jumps() [], get jumps() [],
jumpsIndex: 0 jumpsIndex: -1
}), }),
/** /**
@@ -1268,10 +1268,12 @@ var Buffer = Module("buffer", {
* null, to not alter the horizontal scroll offset. * null, to not alter the horizontal scroll offset.
* @param {number|null} top The top absolute pixel offset. If * @param {number|null} top The top absolute pixel offset. If
* null, to not alter the vertical scroll offset. * 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) if (elem.ownerDocument == buffer.focusedFrame.document)
marks.push(); marks.push(reason);
if (left != null) if (left != null)
elem.scrollLeft = left; elem.scrollLeft = left;
@@ -1288,7 +1290,7 @@ var Buffer = Module("buffer", {
* Scrolls the currently given element horizontally. * Scrolls the currently given element horizontally.
* *
* @param {Element} elem The element to scroll. * @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" * Possible values are: "columns", "pages"
* @param {number} number The possibly fractional number of * @param {number} number The possibly fractional number of
* increments to scroll. Positive values scroll to the right while * 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 * @throws {FailedAssertion} if scrolling is not possible in the
* given direction. * given direction.
*/ */
scrollHorizontal: function scrollHorizontal(elem, increment, number) { scrollHorizontal: function scrollHorizontal(elem, unit, number) {
let fontSize = parseInt(util.computedStyle(elem).fontSize); let fontSize = parseInt(util.computedStyle(elem).fontSize);
if (increment == "columns") let increment;
if (unit == "columns")
increment = fontSize; // Good enough, I suppose. increment = fontSize; // Good enough, I suppose.
else if (increment == "pages") else if (unit == "pages")
increment = elem.clientWidth - fontSize; increment = elem.clientWidth - fontSize;
else else
throw Error(); throw Error();
@@ -1310,14 +1313,14 @@ var Buffer = Module("buffer", {
let left = elem.dactylScrollDestX !== undefined ? elem.dactylScrollDestX : elem.scrollLeft; let left = elem.dactylScrollDestX !== undefined ? elem.dactylScrollDestX : elem.scrollLeft;
elem.dactylScrollDestX = undefined; 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. * Scrolls the currently given element vertically.
* *
* @param {Element} elem The element to scroll. * @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" * Possible values are: "lines", "pages"
* @param {number} number The possibly fractional number of * @param {number} number The possibly fractional number of
* increments to scroll. Positive values scroll upward while * 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 * @throws {FailedAssertion} if scrolling is not possible in the
* given direction. * given direction.
*/ */
scrollVertical: function scrollVertical(elem, increment, number) { scrollVertical: function scrollVertical(elem, unit, number) {
let fontSize = parseInt(util.computedStyle(elem).lineHeight); let fontSize = parseInt(util.computedStyle(elem).lineHeight);
if (increment == "lines") let increment;
if (unit == "lines")
increment = fontSize; increment = fontSize;
else if (increment == "pages") else if (unit == "pages")
increment = elem.clientHeight - fontSize; increment = elem.clientHeight - fontSize;
else else
throw Error(); throw Error();
@@ -1339,7 +1343,7 @@ var Buffer = Module("buffer", {
let top = elem.dactylScrollDestY !== undefined ? elem.dactylScrollDestY : elem.scrollTop; let top = elem.dactylScrollDestY !== undefined ? elem.dactylScrollDestY : elem.scrollTop;
elem.dactylScrollDestY = undefined; elem.dactylScrollDestY = undefined;
Buffer.scrollTo(elem, null, top + number * increment); Buffer.scrollTo(elem, null, top + number * increment, "v-" + unit);
}, },
/** /**

View File

@@ -78,16 +78,32 @@ var Marks = Module("marks", {
/** /**
* Push the current buffer position onto the jump stack. * 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() { push: function push(reason) {
if (!this.jumping) {
let mark = this.add("'");
let store = buffer.localStore; let store = buffer.localStore;
store.jumps[store.jumpsIndex++] = mark; let jump = store.jumps[store.jumpsIndex];
store.jumps.length = 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. * Jump to the given offset in the jump stack.
* *
@@ -96,13 +112,16 @@ var Marks = Module("marks", {
* @returns {number} The actual change in offset. * @returns {number} The actual change in offset.
*/ */
jump: function jump(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() { return this.withSavedValues(["jumping"], function _jump() {
this.jumping = true; this.jumping = true;
let store = buffer.localStore;
let idx = Math.constrain(store.jumpsIndex + offset, 0, store.jumps.length - 1); let idx = Math.constrain(store.jumpsIndex + offset, 0, store.jumps.length - 1);
let orig = store.jumpsIndex; 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; store.jumpsIndex = idx;
return store.jumpsIndex - orig; return store.jumpsIndex - orig;
}); });

View File

@@ -12,6 +12,7 @@ BUGS:
- RC file is sourced once per window - RC file is sourced once per window
FEATURES: FEATURES:
9 Add more tests.
9 <C-o>/<C-i> should work as in Vim (i.e., save page positions as well as 9 <C-o>/<C-i> should work as in Vim (i.e., save page positions as well as
locations in the history list). locations in the history list).
9 clean up error message codes and document 9 clean up error message codes and document