diff --git a/readme.md b/readme.md index 299f71a..18e7335 100644 --- a/readme.md +++ b/readme.md @@ -20,6 +20,7 @@ UX is mainly brought from modern browsers: - Pin/unpin a tab: CTRL + P (macOS: CMD + P) - Close a tab: SHIFT + CTRL + W (macOS: SHIFT + CMD + W) - Change to next tab: CTRL + TAB +- Change to nth tab: CTRL + 1 ~ 9 (this is not configurable yet) Hint: you can change them in the Settings. After change, you need to restart the app. diff --git a/src/PageTabs.tsx b/src/PageTabs.tsx index 90dcf7f..ac81b52 100644 --- a/src/PageTabs.tsx +++ b/src/PageTabs.tsx @@ -313,6 +313,27 @@ const useRegisterKeybindings = ( }, []); }; +const useRegisterSelectNthTabKeybindings = (cb: (nth: number) => void) => { + const cbRef = useEventCallback(cb); + + React.useEffect(() => { + for (let i = 1; i <= 9; i++) { + const setting = { + key: `tabs-select-nth-tab-${i}`, + label: `Select tab ${i}`, + keybinding: { + binding: `mod+${i}`, + mode: "non-editing", + } as SimpleCommandKeybinding, + }; + logseq.App.registerCommandPalette(setting, () => { + cbRef(i); + }); + } + // eslint-disable-next-line react-hooks/exhaustive-deps + }, []); +}; + export function PageTabs(): JSX.Element { const [tabs, setTabs] = useStoreTabs(); const [activeTab, setActiveTab] = useActiveTab(tabs); @@ -475,6 +496,12 @@ export function PageTabs(): JSX.Element { onChangeTab(tabs[idx]); }); + useRegisterSelectNthTabKeybindings(idx => { + if (idx > 0 && idx <= tabs.length) { + onChangeTab(tabs[idx - 1]) + } + }); + return (