Skip to content

Commit

Permalink
Improve smooth scrolling
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsdqs committed Oct 1, 2017
1 parent 57cdd04 commit 29b8134
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions js/term/screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,20 @@ module.exports = class TermScreen extends EventEmitter {
}
})

let aggregateWheelDelta = 0
this.canvas.addEventListener('wheel', e => {
if (this.mouseMode.clicks) {
this.input.onMouseWheel(...this.screenToGrid(e.offsetX, e.offsetY),
e.deltaY > 0 ? 1 : -1)
if (Math.abs(e.wheelDeltaY) === 120) {
// mouse wheel scrolling
this.input.onMouseWheel(...this.screenToGrid(e.offsetX, e.offsetY), e.deltaY > 0 ? 1 : -1)
} else {
// smooth scrolling
aggregateWheelDelta -= e.wheelDeltaY
if (Math.abs(aggregateWheelDelta) >= 40) {
this.input.onMouseWheel(...this.screenToGrid(e.offsetX, e.offsetY), aggregateWheelDelta > 0 ? 1 : -1)
aggregateWheelDelta = 0
}
}

// prevent page scrolling
e.preventDefault()
Expand Down

0 comments on commit 29b8134

Please sign in to comment.