From b144e17c948c0c45c04c858896509370631d518f Mon Sep 17 00:00:00 2001 From: flolu Date: Wed, 23 Nov 2022 20:14:43 +0100 Subject: [PATCH] fix: determine correct scroll target --- main.ts | 30 ++++++++------ manifest.json | 2 +- yarn.lock | 107 -------------------------------------------------- 3 files changed, 20 insertions(+), 119 deletions(-) delete mode 100644 yarn.lock diff --git a/main.ts b/main.ts index bbc5a6f..634ffaf 100644 --- a/main.ts +++ b/main.ts @@ -52,18 +52,25 @@ export default class ScrollSpeed extends Plugin { scrollListener = (event: AugmentedWheelEvent) => { event.preventDefault() - // TODO scrolling doesn't work when hovering over a tooltip + // https://stackoverflow.com/a/39245638/8586803 + const path = event.path || (event.composedPath && (event.composedPath() as Element[])) - if (this.isTrackPadUsed(event) || !this.settings.enableAnimations) { - this.scrollWithoutAnimation(event) - } else { - this.scrollWithAnimation(event) + for (const element of path) { + if (this.isScrollable(element, event)) { + this.target = element + + if (this.isTrackPadUsed(event) || !this.settings.enableAnimations) { + this.scrollWithoutAnimation(event) + } else { + this.scrollWithAnimation(event) + } + + break + } } } scrollWithoutAnimation(event: AugmentedWheelEvent) { - this.target = event.path.find(el => el.scrollHeight > el.clientHeight) - const acceleration = event.altKey ? this.settings.speed * this.settings.altMultiplier : this.settings.speed @@ -72,8 +79,6 @@ export default class ScrollSpeed extends Plugin { } scrollWithAnimation(event: AugmentedWheelEvent) { - this.target = event.path.find(el => el.scrollHeight > el.clientHeight) - // TODO horizontal scrolling, too this.positionY = this.target.scrollTop @@ -127,9 +132,12 @@ export default class ScrollSpeed extends Plugin { if (this.target) this.target = undefined } - isScrollable(element: Element, horizontal: boolean) { + isScrollable(element: Element, event: AugmentedWheelEvent) { + const isHorizontal = event.deltaX && !event.deltaY + return ( - this.isContentOverflowing(element, horizontal) && this.hasOverflowStyle(element, horizontal) + this.isContentOverflowing(element, isHorizontal) && + this.hasOverflowStyle(element, isHorizontal) ) } diff --git a/manifest.json b/manifest.json index e05e17b..e498f2f 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "id": "scroll-speed", "name": "Scroll Speed", - "version": "1.2.0", + "version": "1.2.1", "minAppVersion": "1.0.3", "description": "This plugin allows you to change the scroll speed inside Obsidian notes.", "author": "Florian Ludewig", diff --git a/yarn.lock b/yarn.lock deleted file mode 100644 index 66f0926..0000000 --- a/yarn.lock +++ /dev/null @@ -1,107 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -"@codemirror/state@^6.0.0", "@codemirror/state@^6.1.4": - "integrity" "sha512-g+3OJuRylV5qsXuuhrc6Cvs1NQluNioepYMM2fhnpYkNk7NgX+j0AFuevKSVKzTDmDyt9+Puju+zPdHNECzCNQ==" - "resolved" "https://registry.npmjs.org/@codemirror/state/-/state-6.1.4.tgz" - "version" "6.1.4" - -"@codemirror/view@^6.0.0": - "integrity" "sha512-xBKP8N3AXOs06VcKvIuvIQoUlGs7Hb78ftJWahLaRX909jKPMgGxR5XjvrawzTTZMSTU3DzdjDNPwG6fPM/ypQ==" - "resolved" "https://registry.npmjs.org/@codemirror/view/-/view-6.5.1.tgz" - "version" "6.5.1" - dependencies: - "@codemirror/state" "^6.1.4" - "style-mod" "^4.0.0" - "w3c-keyname" "^2.2.4" - -"@types/codemirror@0.0.108": - "integrity" "sha512-3FGFcus0P7C2UOGCNUVENqObEb4SFk+S8Dnxq7K6aIsLVs/vDtlangl3PEO0ykaKXyK56swVF6Nho7VsA44uhw==" - "resolved" "https://registry.npmjs.org/@types/codemirror/-/codemirror-0.0.108.tgz" - "version" "0.0.108" - dependencies: - "@types/tern" "*" - -"@types/estree@*": - "integrity" "sha512-WulqXMDUTYAXCjZnk6JtIHPigp55cVtDgDrO2gHRwhyJto21+1zbVCtOYB2L1F9w4qCQ0rOGWBnBe0FNTiEJIQ==" - "resolved" "https://registry.npmjs.org/@types/estree/-/estree-1.0.0.tgz" - "version" "1.0.0" - -"@types/node@^16.11.1": - "integrity" "sha512-jh6m0QUhIRcZpNv7Z/rpN+ZWXOicUUQbSoWks7Htkbb9IjFQj4kzcX/xFCkjstCj5flMsN8FiSvt+q+Tcs4Llg==" - "resolved" "https://registry.npmjs.org/@types/node/-/node-16.18.3.tgz" - "version" "16.18.3" - -"@types/tern@*": - "integrity" "sha512-JAUw1iXGO1qaWwEOzxTKJZ/5JxVeON9kvGZ/osgZaJImBnyjyn0cjovPsf6FNLmyGY8Vw9DoXZCMlfMkMwHRWg==" - "resolved" "https://registry.npmjs.org/@types/tern/-/tern-0.23.4.tgz" - "version" "0.23.4" - dependencies: - "@types/estree" "*" - -"esbuild-linux-64@0.13.8": - "integrity" "sha512-Bm8SYmFtvfDCIu9sjKppFXzRXn2BVpuCinU1ChTuMtdKI/7aPpXIrkqBNOgPTOQO9AylJJc1Zw6EvtKORhn64w==" - "resolved" "https://registry.npmjs.org/esbuild-linux-64/-/esbuild-linux-64-0.13.8.tgz" - "version" "0.13.8" - -"esbuild@0.13.8": - "integrity" "sha512-A4af7G7YZLfG5OnARJRMtlpEsCkq/zHZQXewgPA864l9D6VjjbH1SuFYK/OSV6BtHwDGkdwyRrX0qQFLnMfUcw==" - "resolved" "https://registry.npmjs.org/esbuild/-/esbuild-0.13.8.tgz" - "version" "0.13.8" - optionalDependencies: - "esbuild-android-arm64" "0.13.8" - "esbuild-darwin-64" "0.13.8" - "esbuild-darwin-arm64" "0.13.8" - "esbuild-freebsd-64" "0.13.8" - "esbuild-freebsd-arm64" "0.13.8" - "esbuild-linux-32" "0.13.8" - "esbuild-linux-64" "0.13.8" - "esbuild-linux-arm" "0.13.8" - "esbuild-linux-arm64" "0.13.8" - "esbuild-linux-mips64le" "0.13.8" - "esbuild-linux-ppc64le" "0.13.8" - "esbuild-netbsd-64" "0.13.8" - "esbuild-openbsd-64" "0.13.8" - "esbuild-sunos-64" "0.13.8" - "esbuild-windows-32" "0.13.8" - "esbuild-windows-64" "0.13.8" - "esbuild-windows-arm64" "0.13.8" - -"moment@2.29.4": - "integrity" "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==" - "resolved" "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz" - "version" "2.29.4" - -"obsidian@^0.16.3": - "integrity" "sha512-hal9qk1A0GMhHSeLr2/+o3OpLmImiP+Y+sx2ewP13ds76KXsziG96n+IPFT0mSkup1zSwhEu+DeRhmbcyCCXWw==" - "resolved" "https://registry.npmjs.org/obsidian/-/obsidian-0.16.3.tgz" - "version" "0.16.3" - dependencies: - "@types/codemirror" "0.0.108" - "moment" "2.29.4" - -"prettier@^2.4.1": - "integrity" "sha512-ujppO+MkdPqoVINuDFDRLClm7D78qbDt0/NR+wp5FqEZOoTNAjPHWj17QRhu7geIHJfcNhRk1XVQmF8Bp3ye+g==" - "resolved" "https://registry.npmjs.org/prettier/-/prettier-2.7.1.tgz" - "version" "2.7.1" - -"style-mod@^4.0.0": - "integrity" "sha512-OPhtyEjyyN9x3nhPsu76f52yUGXiZcgvsrFVtvTkyGRQJ0XK+GPc6ov1z+lRpbeabka+MYEQxOYRnt5nF30aMw==" - "resolved" "https://registry.npmjs.org/style-mod/-/style-mod-4.0.0.tgz" - "version" "4.0.0" - -"tslib@2.3.1": - "integrity" "sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw==" - "resolved" "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz" - "version" "2.3.1" - -"typescript@4.4.4": - "integrity" "sha512-DqGhF5IKoBl8WNf8C1gu8q0xZSInh9j1kJJMqT3a94w1JzVaBU4EXOSMrz9yDqMT0xt3selp83fuFMQ0uzv6qA==" - "resolved" "https://registry.npmjs.org/typescript/-/typescript-4.4.4.tgz" - "version" "4.4.4" - -"w3c-keyname@^2.2.4": - "integrity" "sha512-f+fciywl1SJEniZHD6H+kUO8gOnwIr7f4ijKA6+ZvJFjeGi1r4PDLl53Ayud9O/rk64RqgoQine0feoeOU0kXg==" - "resolved" "https://registry.npmjs.org/w3c-keyname/-/w3c-keyname-2.2.6.tgz" - "version" "2.2.6"