example of throttle / debounce to try

page-down-up-bugfix
John McLear 2021-01-08 15:20:09 +00:00
parent 996f0e8a1d
commit 14e24f5a3c
2 changed files with 25 additions and 1 deletions

View File

@ -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();

View File

@ -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 {