timc1 / kbar

fast, portable, and extensible cmd+k interface for your site
https://kbar.vercel.app
MIT License
4.84k stars 185 forks source link

Control history outside of KBar Item Action #220

Closed olafsulich closed 2 years ago

olafsulich commented 2 years ago

Hi! I wonder how can I control my shortcut actions outside of the actual KBar Item.

Problem: I want to control undo/redo state by shortcuts AND by separate buttons, how can I do it?

Example:

function App () {
  return <KBarProvider>...</KBarProvider>
}

function Parent() {
  const { results } = useMatches();
   useRegisterActions([{
    // ...properties
    shortcut: ['Backspace'],
    perform: () => {}
  }])

  return (
    <Child />
    <KBarResults results={results} onRender={() => {}} />
  )
}

function Child() {

  const handleClick = () => {
    // here I want to undo the internal KBar history state
  }

  return <button onClick={handleClick}>undo</button>
}
stale[bot] commented 2 years ago

Hey! This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.