import { behavior, scroll, scrollStep } from './utils'

export function scrollDown (event) {
  scroll(event.repeat, scrollStep, 'scrollTop')
}

export function scrollUp (event) {
  scroll(event.repeat, -scrollStep, 'scrollTop')
}

export function scrollLeft (event) {
  scroll(event.repeat, -scrollStep, 'scrollLeft')
}

export function scrollRight (event) {
  scroll(event.repeat, scrollStep, 'scrollLeft')
}

export function scrollPageDown () {
  scrollBy({
    top: innerHeight * 0.9,
    behavior
  })
}

export function scrollPageUp () {
  scrollBy({
    top: -innerHeight * 0.9,
    behavior
  })
}

export function scrollHalfPageDown () {
  scrollBy({
    top: innerHeight / 2,
    behavior
  })
}

export function scrollHalfPageUp () {
  scrollBy({
    top: -innerHeight / 2,
    behavior
  })
}

export function scrollToBottom () {
  scrollTo({
    top: document.documentElement.scrollHeight,
    behavior
  })
}

export function scrollToTop () {
  scrollTo({
    top: 0,
    behavior
  })
}

export function scrollToLeft () {
  scrollTo({
    left: 0,
    behavior
  })
}

export function scrollToRight () {
  scrollTo({
    left: document.documentElement.scrollWidth,
    behavior
  })
}

import { behavior, scroll, scrollStep } from './utils'

export function scrollDown (event) {
  scroll(event.repeat, scrollStep, 'scrollTop')
}

export function scrollUp (event) {
  scroll(event.repeat, -scrollStep, 'scrollTop')
}

export function scrollLeft (event) {
  scroll(event.repeat, -scrollStep, 'scrollLeft')
}

export function scrollRight (event) {
  scroll(event.repeat, scrollStep, 'scrollLeft')
}

export function scrollPageDown () {
  scrollBy({
    top: innerHeight * 0.9,
    behavior
  })
}

export function scrollPageUp () {
  scrollBy({
    top: -innerHeight * 0.9,
    behavior
  })
}

export function scrollHalfPageDown () {
  scrollTo({
    top: window.pageYOffset + window.innerHeight / 2,
    left: 0,
    behavior: behavior
  })
}

export function scrollHalfPageUp () {
  scrollTo({
    top: window.pageYOffset - window.innerHeight / 2,
    left: 0,
    behavior: behavior
  })
}

export function scrollToBottom () {
  scrollTo({
    top: document.documentElement.scrollHeight,
    behavior
  })
}

export function scrollToTop () {
  scrollTo({
    top: 0,
    behavior
  })
}

export function scrollToLeft () {
  scrollTo({
    left: 0,
    behavior
  })
}

export function scrollToRight () {
  scrollTo({
    left: document.documentElement.scrollWidth,
    behavior
  })
}

Fix a bug in Firefox with scrolling half pages
Fix a bug in Firefox with scrolling half pages

In newer Firefox versions (around version 63), the window.scrollBy call
sometimes does not do anything at all, and later on will scroll the page
twice. This causes erratic behaviour when using half page scrolling with
Saka key.

I have not been able to determine when exactly, or why the scrollBy call
sometimes doesn't work, but changing the call to scrollTo does prevent
the bug from showing up.

Untested in other browsers, but behaviour should be mostly unchanged.
