From c8419d3afd7a04845785a7914445e3ac016d1e6d Mon Sep 17 00:00:00 2001 From: vorotamoroz Date: Tue, 11 Oct 2022 10:22:38 +0900 Subject: [PATCH] Improved: Improved scrolling performance. --- main.ts | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/main.ts b/main.ts index 56bcead..b86f8da 100644 --- a/main.ts +++ b/main.ts @@ -142,20 +142,25 @@ class NinjaCursorForWindow { moveCursor(ev); }); } + let triggered = false; // Handles scroll till scroll is finish. const applyWheelScroll = (last?: number | boolean) => { - requestAnimationFrame(() => { - if (datumElement) { - const curTop = datumElement.getBoundingClientRect().top; - const diff = curTop - datumTop; - root.style.setProperty("--cursor-offset-y", `${diff}px`); - if (last === false || last != diff) { - requestAnimationFrame(() => applyWheelScroll(diff)); - } else if (last == diff) { - moveCursor(undefined, true); + if (!triggered) { + requestAnimationFrame(() => { + if (datumElement) { + const curTop = datumElement.getBoundingClientRect().top; + const diff = curTop - datumTop; + root.style.setProperty("--cursor-offset-y", `${diff}px`); + if (last === false || last != diff) { + requestAnimationFrame(() => applyWheelScroll(diff)); + } else if (last == diff) { + moveCursor(undefined, true); + } } - } - }); + triggered = false; + }); + triggered = true; + } } registerDomEvent(aw, "wheel", (e: WheelEvent) => { applyWheelScroll(false); @@ -180,7 +185,6 @@ export default class NinjaCursorPlugin extends Plugin { async onload() { - this.registerEvent(this.app.workspace.on("window-open", (win) => { console.log("Open by window-open") const exist = this.Cursors.find(e => e.bufferedWindow == win.win);