MCPcopy Create free account
hub / github.com/TanStack/hotkeys / App

Function App

examples/solid/createHotkeySequence/src/index.tsx:13–256  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11import './index.css'
12
13function App() {
14 const [lastSequence, setLastSequence] = createSignal<string | null>(null)
15 const [history, setHistory] = createSignal<Array<string>>([])
16 const [helloSequenceEnabled, setHelloSequenceEnabled] = createSignal(true)
17 const addToHistory = (action: string) => {
18 setLastSequence(action)
19 setHistory((h) => [...h.slice(-9), action])
20 }
21
22 createHotkeySequence(['G', 'G'], () => addToHistory('gg → Go to top'))
23 createHotkeySequence(['Shift+G'], () => addToHistory('G → Go to bottom'))
24 createHotkeySequence(['D', 'D'], () => addToHistory('dd → Delete line'))
25 createHotkeySequence(['Y', 'Y'], () => addToHistory('yy → Yank (copy) line'))
26 createHotkeySequence(['D', 'W'], () => addToHistory('dw → Delete word'))
27 createHotkeySequence(['C', 'I', 'W'], () =>
28 addToHistory('ciw → Change inner word'),
29 )
30
31 createHotkeySequence(
32 ['ArrowUp', 'ArrowUp', 'ArrowDown', 'ArrowDown'],
33 () => addToHistory('↑↑↓↓ → Konami code (partial)'),
34 { timeout: 1500 },
35 )
36
37 createHotkeySequence(
38 ['ArrowLeft', 'ArrowRight', 'ArrowLeft', 'ArrowRight'],
39 () => addToHistory('←→←→ → Side to side!'),
40 { timeout: 1500 },
41 )
42
43 createHotkeySequence(
44 ['H', 'E', 'L', 'L', 'O'],
45 () => addToHistory('hello → Hello World!'),
46 () => ({ enabled: helloSequenceEnabled() }),
47 )
48
49 createHotkeySequence(['Shift+R', 'Shift+T'], () =>
50 addToHistory('⇧R ⇧T → Chained Shift+letter (2 steps)'),
51 )
52
53 createHotkey('Escape', () => {
54 setLastSequence(null)
55 setHistory([])
56 })
57
58 return (
59 <div class="app">
60 <header>
61 <h1>createHotkeySequence</h1>
62 <p>
63 Register multi-key sequences (like Vim commands). Keys must be pressed
64 within the timeout window (default: 1000ms).
65 </p>
66 </header>
67
68 <main>
69 <section class="demo-section">
70 <h2>Vim-Style Commands</h2>

Callers

nothing calls this directly

Calls 3

createHotkeySequenceFunction · 0.90
createHotkeyFunction · 0.90
addToHistoryFunction · 0.70

Tested by

no test coverage detected