Skip to content

Commit

Permalink
Improved: Improved scrolling performance.
Browse files Browse the repository at this point in the history
  • Loading branch information
vrtmrz committed Oct 11, 2022
1 parent 7569211 commit c8419d3
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit c8419d3

Please sign in to comment.