Skip to content

Commit

Permalink
fix: determine correct scroll target
Browse files Browse the repository at this point in the history
  • Loading branch information
flolu committed Nov 23, 2022
1 parent be655d8 commit b144e17
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 119 deletions.
30 changes: 19 additions & 11 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
)
}

Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
107 changes: 0 additions & 107 deletions yarn.lock

This file was deleted.

0 comments on commit b144e17

Please sign in to comment.