diff --git a/src/App.tsx b/src/App.tsx index 580e8c8..2f2768d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -5,6 +5,50 @@ import "@mantine/core/styles.css"; function App() { const [activeTab, setActiveTab] = useState("1"); + const [panelTexts, setPanelTexts] = useState>({ + "1": "First panel ", + "2": "Second panel ", + "3": "Third panel ", + }); + + const tt: Record = { + "1": "First ", + "2": "Second ", + "3": "Third ", + }; + + const [hotkeyEnabled, setHotkeyEnabled] = useState>({ + "1": true, + "2": true, + "3": true, + }); + useHotkeys( + "ctrl+b", + () => { + if (!activeTab) return; + const textToAppend = tt[activeTab]; + if (textToAppend) { + setPanelTexts((prev) => { + return { + ...prev, + [activeTab]: prev[activeTab] + textToAppend, + }; + }); + + setHotkeyEnabled((prev) => ({ + ...prev, + [activeTab]: false, + })); + } + }, + + { + preventDefault: true, + enableOnFormTags: true, + enabled: activeTab ? hotkeyEnabled[activeTab] : false, + }, + [activeTab, hotkeyEnabled], + ); useHotkeys( "ctrl+1, ctrl+2, ctrl+3", @@ -29,15 +73,13 @@ function App() { - First panel + {panelTexts["1"]} - - Second panel + {panelTexts["2"]} - - Third panel + {panelTexts["3"]}