<commit_before>import { isModalActive } from 'bemuse/ui-dialogs'
import { useLatest } from 'bemuse/utils/useLatest'
import { useEffect } from 'react'
import { NotechartPreview } from './NotechartPreview'
import { PreviewAction } from './PreviewState'

let rememberedMeasureNumber: number | null = null

export const PreviewKeyHandler: React.FC<{
  notechartPreview: NotechartPreview
  dispatch: React.Dispatch<PreviewAction>
  onReload: () => void
}> = (props) => {
  const getLatestNotechartPreview = useLatest(props.notechartPreview)
  useEffect(() => {
    const onKeyDown = (e: KeyboardEvent) => {
      if (isModalActive()) return
      console.log(e.key)
      if (e.key === 'ArrowUp') {
        props.dispatch({ speedUp: true })
        e.preventDefault()
      }
      if (e.key === 'ArrowDown') {
        props.dispatch({ speedDown: true })
        e.preventDefault()
      }
      if (e.key === ' ') {
        props.dispatch({ playPause: true })
        e.preventDefault()
      }
      if (e.key === 'Home') {
        props.dispatch({ home: true })
        e.preventDefault()
      }
      if (e.key === 'g') {
        props.dispatch({ pause: true })
        const measure = +(
          prompt(
            'Measure number',
            rememberedMeasureNumber ? `${rememberedMeasureNumber}` : ''
          ) || ''
        )
        if (!isNaN(measure)) {
          rememberedMeasureNumber = measure
          props.dispatch({
            jumpToTime: {
              time: getLatestNotechartPreview().measureToSeconds(measure),
            },
          })
        }
        e.preventDefault()
      }
      if (e.key === 'r') {
        props.onReload()
        e.preventDefault()
      }
      if (e.key === 'ArrowLeft') {
        props.dispatch({
          jumpByMeasure: {
            direction: -1,
            preview: getLatestNotechartPreview(),
          },
        })
        e.preventDefault()
      }
      if (e.key === 'ArrowRight') {
        props.dispatch({
          jumpByMeasure: {
            direction: 1,
            preview: getLatestNotechartPreview(),
          },
        })<commit_msg>Do not listen to cmd+r or ctrl+r<commit_after>import { isModalActive } from 'bemuse/ui-dialogs'
import { useLatest } from 'bemuse/utils/useLatest'
import { useEffect } from 'react'
import { NotechartPreview } from './NotechartPreview'
import { PreviewAction } from './PreviewState'

let rememberedMeasureNumber: number | null = null

export const PreviewKeyHandler: React.FC<{
  notechartPreview: NotechartPreview
  dispatch: React.Dispatch<PreviewAction>
  onReload: () => void
}> = (props) => {
  const getLatestNotechartPreview = useLatest(props.notechartPreview)
  useEffect(() => {
    const onKeyDown = (e: KeyboardEvent) => {
      if (isModalActive()) return
      console.log(e.key)
      if (e.key === 'ArrowUp') {
        props.dispatch({ speedUp: true })
        e.preventDefault()
      }
      if (e.key === 'ArrowDown') {
        props.dispatch({ speedDown: true })
        e.preventDefault()
      }
      if (e.key === ' ') {
        props.dispatch({ playPause: true })
        e.preventDefault()
      }
      if (e.key === 'Home') {
        props.dispatch({ home: true })
        e.preventDefault()
      }
      if (e.key === 'g') {
        props.dispatch({ pause: true })
        const measure = +(
          prompt(
            'Measure number',
            rememberedMeasureNumber ? `${rememberedMeasureNumber}` : ''
          ) || ''
        )
        if (!isNaN(measure)) {
          rememberedMeasureNumber = measure
          props.dispatch({
            jumpToTime: {
              time: getLatestNotechartPreview().measureToSeconds(measure),
            },
          })
        }
        e.preventDefault()
      }
      if (e.key === 'r' && !e.ctrlKey && !e.metaKey) {
        props.onReload()
        e.preventDefault()
      }
      if (e.key === 'ArrowLeft') {
        props.dispatch({
          jumpByMeasure: {
            direction: -1,
            preview: getLatestNotechartPreview(),
          },
        })
        e.preventDefault()
      }
      if (e.key === 'ArrowRight') {
        props.dispatch({
          jumpByMeasure: {
            direction: 1,
            preview: getLatestNotechartPreview(),
          },
        })
{'fraction_non_alphanumeric': 0.137963178746213, 'fraction_numerical': 0.0009321836401771149, 'mean_word_length': 1.9538885065381968, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '1678506', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1255, 'n_words': 250}