Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed: Keyboard shortcuts for k8s #1492

Merged
merged 1 commit into from
Sep 13, 2024
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
48 changes: 48 additions & 0 deletions ui/src/components/Kubernetes/MainContent/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import { useLogger } from '@/hooks/useLogger.ts';
import { useTreeStore } from '@/store/modules/tree.ts';
import { useParamsStore } from '@/store/modules/params.ts';
import { useTerminalStore } from '@/store/modules/terminal.ts';
import { useDebounceFn } from '@vueuse/core';

const message = useMessage();
const { debug } = useLogger('K8s-CustomTerminal');
Expand Down Expand Up @@ -672,6 +673,40 @@ const handleWriteData = async (type: string) => {
});
};

/**
* 切换到上一个 Tab
*/
const switchToPreviousTab = () => {
const currentIndex = panels.value.findIndex(panel => panel.name === nameRef.value);

if (currentIndex > 0) {
nameRef.value = panels.value[currentIndex - 1].name as string;
} else {
nameRef.value = panels.value[panels.value.length - 1].name as string;
}

findNodeById(nameRef.value);

terminalStore.setTerminalConfig('currentTab', nameRef.value);
};

/**
* 切换到下一个 Tab
*/
const switchToNextTab = () => {
const currentIndex = panels.value.findIndex(panel => panel.name === nameRef.value);

if (currentIndex < panels.value.length - 1) {
nameRef.value = panels.value[currentIndex + 1].name as string;
} else {
nameRef.value = panels.value[0].name as string;
}

findNodeById(nameRef.value);

terminalStore.setTerminalConfig('currentTab', nameRef.value);
};

onMounted(() => {
nextTick(() => {
initializeDraggable();
Expand Down Expand Up @@ -754,9 +789,22 @@ onMounted(() => {
terminalStore.setTerminalConfig('currentTab', key);
deleteUserCounter.value++;
});

const debouncedSwitchToPreviousTab = useDebounceFn(() => {
switchToPreviousTab();
}, 200);

const debouncedSwitchToNextTab = useDebounceFn(() => {
switchToNextTab();
}, 200);

mittBus.on('alt-shift-left', debouncedSwitchToPreviousTab);
mittBus.on('alt-shift-right', debouncedSwitchToNextTab);
});

onBeforeUnmount(() => {
mittBus.off('alt-shift-left', switchToPreviousTab);
mittBus.off('alt-shift-right', switchToNextTab);
mittBus.off('connect-terminal');
});
</script>
Expand Down
16 changes: 13 additions & 3 deletions ui/src/hooks/helper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { createDiscreteApi } from 'naive-ui';
import { readText } from 'clipboard-polyfill';
import { fireEvent, preprocessInput } from '@/utils';

import mittBus from '@/utils/mittBus.ts';
import * as clipboard from 'clipboard-polyfill';
import { BASE_WS_URL, MaxTimeout } from '@/config';

Expand Down Expand Up @@ -125,13 +126,21 @@ export const handleCustomKey = (
if (e.altKey && e.shiftKey && (e.key === 'ArrowRight' || e.key === 'ArrowLeft')) {
switch (e.key) {
case 'ArrowRight':
sendEventToLuna('KEYEVENT', 'alt+shift+right', lunaId, origin);
if (lunaId && origin) {
sendEventToLuna('KEYEVENT', 'alt+shift+right', lunaId, origin);
} else {
mittBus.emit('alt-shift-right');
}

break;
case 'ArrowLeft':
sendEventToLuna('KEYEVENT', 'alt+shift+left', lunaId, origin);
if (lunaId && origin) {
sendEventToLuna('KEYEVENT', 'alt+shift+left', lunaId, origin);
} else {
mittBus.emit('alt-shift-left');
}
break;
}

return false;
}

Expand Down Expand Up @@ -172,6 +181,7 @@ export const handleTerminalSelection = async (terminal: Terminal, termSelectionT
* @param config
* @param socket
*/
// todo
export const handleTerminalOnData = (
data: string,
type: string,
Expand Down
2 changes: 2 additions & 0 deletions ui/src/utils/mittBus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { customTreeOption } from '@/hooks/interface';
import { shareUser } from '@/views/interface';

type Event = {
'alt-shift-right': void;
'alt-shift-left': void;
'open-setting': void;
'fold-tree-click': void;
'show-theme-config': void;
Expand Down
Loading