Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: shortcuts configuration #228

Merged
merged 5 commits into from
Jun 8, 2021
Merged

feat: shortcuts configuration #228

merged 5 commits into from
Jun 8, 2021

Conversation

yjl9903
Copy link
Contributor

@yjl9903 yjl9903 commented Jun 7, 2021

Fixes #209

Add shortcuts configuration.

Create ./setup/shortcuts.ts with the following content:

import { defineShortcutsSetup, NavOperations } from '@slidev/types'

export default defineShortcutsSetup((nav: NavOperations) => {
  return [
    {
      key: 'enter',
      fn: () => nav.next(),
      autoRepeat: true,
    },
    {
      key: 'backspace',
      fn: () => nav.prev(),
      autoRepeat: true,
    },
  ]
})

Related type declaration:

export interface NavOperations {
  next: () => void
  prev: () => Promise<void>
  nextSlide: () => void
  prevSlide: () => Promise<void>
  downloadPDF: () => Promise<void>
  toggleDark: () => void
  toggleOverview: () => void
  escapeOverview: () => void
  showGotoDialog: () => void
}

export interface ShortcutOptions {
  key: string
  fn: () => void
  autoRepeat?: boolean
}

export type ShortcutsSetup = (nav: NavOperations) => Array<ShortcutOptions>

export function defineShortcutsSetup(fn: ShortcutsSetup) {
  return fn
}

@antfu
Copy link
Member

antfu commented Jun 8, 2021

Could you also open another PR to the docs repo adding these info? Thanks!

@antfu antfu merged commit 25dfa6f into slidevjs:main Jun 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Configure navigation shortcuts
2 participants