diff --git a/ui/src/hooks/helper/index.ts b/ui/src/hooks/helper/index.ts index 19473538..9a77dedb 100644 --- a/ui/src/hooks/helper/index.ts +++ b/ui/src/hooks/helper/index.ts @@ -28,14 +28,19 @@ const { message } = createDiscreteApi(['message']); * @param e * @param config * @param socket + * @param terminalId * @param termSelectionText + * @param k8s_id */ export const handleContextMenu = async ( e: MouseEvent, config: ILunaConfig, socket: WebSocket, - termSelectionText: string + terminalId: string, + termSelectionText: string, + k8s_id: string | undefined ) => { + e.preventDefault(); if (e.ctrlKey || config.quickPaste !== '1') return; let text: string = ''; @@ -44,14 +49,20 @@ export const handleContextMenu = async ( text = await readText(); } catch (e) { if (termSelectionText !== '') text = termSelectionText; - message.info(`${e}`); } - socket.send(formatMessage('1', 'TERMINAL_DATA', text)); - - e.preventDefault(); - - return text; + if (k8s_id) { + socket.send( + JSON.stringify({ + id: terminalId, + k8s_id, + type: 'TERMINAL_K8S_DATA', + data: text + }) + ); + } else { + socket.send(formatMessage(terminalId, 'TERMINAL_DATA', text)); + } }; /** @@ -131,14 +142,16 @@ export const handleCustomKey = (e: KeyboardEvent, terminal: Terminal): boolean = export const handleTerminalSelection = async (terminal: Terminal, termSelectionText: Ref) => { termSelectionText.value = terminal.getSelection().trim(); - clipboard - .writeText(termSelectionText.value) - .then(() => { - message.success('Copied!'); - }) - .catch(e => { - message.error(`Copy Error for ${e}`); - }); + if (termSelectionText.value !== '') { + clipboard + .writeText(termSelectionText.value) + .then(() => {}) + .catch(e => { + message.error(`Copy Error for ${e}`); + }); + } else { + message.warning('Please select the text before copying'); + } }; /** diff --git a/ui/src/hooks/useTerminal.ts b/ui/src/hooks/useTerminal.ts index 61b0b643..231336a2 100644 --- a/ui/src/hooks/useTerminal.ts +++ b/ui/src/hooks/useTerminal.ts @@ -306,7 +306,14 @@ export const useTerminal = async (el: HTMLElement, option: ICallbackOptions): Pr el.addEventListener( 'contextmenu', (e: MouseEvent) => { - handleContextMenu(e, lunaConfig, socket!, termSelectionText.value); + handleContextMenu( + e, + lunaConfig, + socket!, + terminalId.value, + termSelectionText.value, + k8s_id.value + ); }, false ); @@ -482,64 +489,6 @@ export const useTerminal = async (el: HTMLElement, option: ICallbackOptions): Pr } } - // if (option.type === 'common') { - // const [socketResult, terminalResult] = await Promise.allSettled([ - // createSocket(), - // createTerminal(lunaConfig) - // ]); - // - // if (socketResult.status === 'fulfilled' && terminalResult.status === 'fulfilled') { - // if (socketResult.value) { - // socket = socketResult.value; - // } - // terminal = terminalResult.value; - // - // initElEvent(); - // initSocketEvent(); - // initTerminalEvent(); - // initCustomWindowEvent(); - // - // const { createSentry } = useSentry(lastSendTime, option.i18nCallBack); - // - // sentry = createSentry(socket, terminal); - // } else { - // if (socketResult.status === 'rejected') { - // message.error('Socket error:', socketResult.reason); - // } - // if (terminalResult.status === 'rejected') { - // message.error('Terminal error:', terminalResult.reason); - // } - // } - // } else { - // terminal = await createTerminal(lunaConfig); - // socket = option.transSocket!; - // - // initElEvent(); - // initTerminalEvent(); - // initCustomWindowEvent(); - // - // const { createSentry } = useSentry(lastSendTime, option.i18nCallBack); - // - // sentry = createSentry(socket, terminal); - // - // const { currentTab } = storeToRefs(useTerminalStore()); - // - // const messageHandlers = { - // [currentTab.value]: (e: MessageEvent) => { - // handleK8sMessage(JSON.parse(e.data)); - // } - // }; - // - // if (option.transSocket) { - // option.transSocket.addEventListener('message', (e: MessageEvent) => { - // const handler = messageHandlers[currentTab.value]; - // if (handler) { - // handler(e); - // } - // }); - // } - // } - return terminal; };