example of throttle / debounce to try
parent
996f0e8a1d
commit
14e24f5a3c
|
@ -59,6 +59,7 @@ function Ace2Inner() {
|
|||
const DEBUG = false; // $$ build script replaces the string "var DEBUG=true;//$$" with "var DEBUG=false;"
|
||||
// changed to false
|
||||
let isSetUp = false;
|
||||
let lastPageUpOrDownEvent;
|
||||
|
||||
const THE_TAB = ' '; // 4
|
||||
const MAX_LIST_LEVEL = 16;
|
||||
|
@ -3064,9 +3065,30 @@ function Ace2Inner() {
|
|||
const isPageUp = evt.which === 33;
|
||||
let previousCharacterOffset;
|
||||
const isShiftKey = shiftKey;
|
||||
|
||||
const pageUpOrDownTooSoon = () => {
|
||||
const delay = 250;
|
||||
|
||||
if (!lastPageUpOrDownEvent) {
|
||||
lastPageUpOrDownEvent = Date.now();
|
||||
return false;
|
||||
}
|
||||
|
||||
const nextValidTime = lastPageUpOrDownEvent + delay;
|
||||
if (Date.now() >= nextValidTime) {
|
||||
lastPageUpOrDownEvent = Date.now();
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isPageUp) {
|
||||
// Approach #99991248928175 to solve this problem....
|
||||
|
||||
// debounce / throttle press and hold page key
|
||||
if (pageUpOrDownTooSoon()) return;
|
||||
|
||||
// only make history of x offset if it's not 0.
|
||||
if (rep.selStart[1] !== 0 && rep.selEnd[1] !== 0) {
|
||||
previousCharacterOffset = [
|
||||
|
@ -3130,6 +3152,9 @@ function Ace2Inner() {
|
|||
}
|
||||
// END OF PAGE UP
|
||||
if (isPageDown) {
|
||||
// debounce / throttle press and hold page key
|
||||
if (pageUpOrDownTooSoon()) return;
|
||||
|
||||
// Bottom of document - do nothing if we are at the very end
|
||||
// JM TODO: Check if Linemarker modifies width..
|
||||
const originalPosition = scroll._getViewPortTopBottom();
|
||||
|
|
|
@ -358,7 +358,6 @@ Scroll.prototype.movePage = function (direction) {
|
|||
const lineHeight = linePosition.top - linePosition.bottom;
|
||||
let pixelsToScroll = viewport.top - viewport.bottom + offset;
|
||||
if (direction === 'up') {
|
||||
// buffer pixels unscrolled our safety net here. You can't use the current or previous
|
||||
// line height because it might be a very long line..
|
||||
pixelsToScroll = -Math.abs(pixelsToScroll - lineHeight);
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue