Improve smooth scrolling

box-drawing
cpsdqs 7 years ago
parent 57cdd04523
commit 29b813457c
Signed by untrusted user: cpsdqs
GPG Key ID: 3F59586BB7448DD1
  1. 14
      js/term/screen.js

@ -268,10 +268,20 @@ module.exports = class TermScreen extends EventEmitter {
} }
}) })
let aggregateWheelDelta = 0
this.canvas.addEventListener('wheel', e => { this.canvas.addEventListener('wheel', e => {
if (this.mouseMode.clicks) { if (this.mouseMode.clicks) {
this.input.onMouseWheel(...this.screenToGrid(e.offsetX, e.offsetY), if (Math.abs(e.wheelDeltaY) === 120) {
e.deltaY > 0 ? 1 : -1) // 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 // prevent page scrolling
e.preventDefault() e.preventDefault()

Loading…
Cancel
Save