Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions apps/desktop2/src/components/main/body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function Body() {
const { chat } = useShell();

useTabCloseHotkey();
useTabSelectHotkeys();

if (!currentTab) {
return null;
Expand Down Expand Up @@ -250,6 +251,31 @@ const useTabCloseHotkey = () => {
);
};

const useTabSelectHotkeys = () => {
const { tabs, select } = useTabs();

useHotkeys(
["mod+1", "mod+2", "mod+3", "mod+4", "mod+5", "mod+6", "mod+7", "mod+8", "mod+9"],
(event) => {
const key = event.key;

const targetIndex = key === "9"
? tabs.length - 1
: Number.parseInt(key, 10) - 1;

const target = tabs[targetIndex];
if (!target) {
return;
}

event.preventDefault();
select(target);
},
{ enableOnFormTags: true },
[tabs, select],
);
};

function useScrollActiveTabIntoView(tabs: Tab[]) {
const tabRefsMap = useRef<Map<string, HTMLDivElement>>(new Map());

Expand Down
Loading
Loading