<commit_before>package visceljs

import org.scalajs.dom
import org.scalajs.dom.raw.KeyboardEvent
import rescala.default.{Event, Evt, implicitScheduler}
import rescala.reactives.Events
import visceljs.render.FitType

object Navigation {
  sealed trait Navigate
  case object Next extends Navigate
  case object Prev extends Navigate
  case class Mode(i: FitType) extends Navigate

  case class Position(cur: Int, max: Int) {
    def mov(nav: Navigate): Position = nav match {
      case Navigation.Next => Position(math.min(cur + 1, max), max)
      case Navigation.Prev => Position(math.max(cur - 1, 0), max)
      case _         => this
    }
    def mov(i: Int): Position = set(cur + i)
    def set(i: Int): Position = Position(math.max(0, math.min(i, max)), max)
    def limit(m: Int): Position = copy(max = m)
  }

  val navigate            = Evt[Navigate]
  val handleKeypress      = Events.fromCallback[KeyboardEvent](dom.document.onkeydown = _)
  val keypressNavigations = handleKeypress.event.map(_.key).collect {
    case "ArrowLeft"  => Prev
    case "ArrowRight" => Next
    case "1"          => Mode(FitType.W)
    case "2"          => Mode(FitType.WH)
    case "3"          => Mode(FitType.O)
    case "4"          => Mode(FitType.SW)
    case "5"          => Mode(FitType.SWH)
    case "0"          => Mode(FitType.O)
  }

  val navigationEvents: Event[Navigate] = keypressNavigations || navigate

}<commit_msg>limit max<commit_after>package visceljs

import org.scalajs.dom
import org.scalajs.dom.raw.KeyboardEvent
import rescala.default.{Event, Evt, implicitScheduler}
import rescala.reactives.Events
import visceljs.render.FitType

object Navigation {
  sealed trait Navigate
  case object Next extends Navigate
  case object Prev extends Navigate
  case class Mode(i: FitType) extends Navigate

  case class Position(cur: Int, max: Int) {
    def mov(nav: Navigate): Position = nav match {
      case Navigation.Next => Position(math.min(cur + 1, max), max)
      case Navigation.Prev => Position(math.max(cur - 1, 0), max)
      case _         => this
    }
    def mov(i: Int): Position = set(cur + i)
    def set(i: Int): Position = Position(math.max(0, math.min(i, max)), max)
    def limit(m: Int): Position = copy(max = m - 1)
  }

  val navigate            = Evt[Navigate]
  val handleKeypress      = Events.fromCallback[KeyboardEvent](dom.document.onkeydown = _)
  val keypressNavigations = handleKeypress.event.map(_.key).collect {
    case "ArrowLeft"  => Prev
    case "ArrowRight" => Next
    case "1"          => Mode(FitType.W)
    case "2"          => Mode(FitType.WH)
    case "3"          => Mode(FitType.O)
    case "4"          => Mode(FitType.SW)
    case "5"          => Mode(FitType.SWH)
    case "0"          => Mode(FitType.O)
  }

  val navigationEvents: Event[Navigate] = keypressNavigations || navigate

}
{'fraction_non_alphanumeric': 0.12035087719298246, 'fraction_numerical': 0.007368421052631579, 'mean_word_length': 2.9108367626886147, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6976868', 'n_tokens_mistral': 959, 'n_tokens_neox': 928, 'n_words': 240}