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