From a9c3a5201a04c1f5eb2e432dbe536739d2beaccf Mon Sep 17 00:00:00 2001 From: chaoszhu Date: Mon, 16 Jun 2025 22:51:40 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E8=8F=9C=E5=8D=95?= =?UTF-8?q?=E9=9A=90=E8=97=8F=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/composables/useContextMenu.js | 5 +++++ web/src/views/terminal/components/terminal-tab.vue | 12 ++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/web/src/composables/useContextMenu.js b/web/src/composables/useContextMenu.js index f099694..cf831b1 100644 --- a/web/src/composables/useContextMenu.js +++ b/web/src/composables/useContextMenu.js @@ -5,6 +5,7 @@ import ElementPlus from 'element-plus' export function useContextMenu() { const menuRef = ref(null) + const isVisible = ref(false) let contextMenuApp = null let contextMenuInstance = null let isClosing = false @@ -61,11 +62,13 @@ export function useContextMenu() { ]) contextMenuInstance._container = container + isVisible.value = true } const closeMenu = () => { if (contextMenuInstance && !isClosing) { isClosing = true + isVisible.value = false contextMenuInstance.closeMenu() setTimeout(() => { @@ -95,6 +98,7 @@ export function useContextMenu() { } isClosing = true + isVisible.value = false contextMenuInstance.closeMenu() try { @@ -116,6 +120,7 @@ export function useContextMenu() { return { menuRef, + isVisible, showMenu, closeMenu } diff --git a/web/src/views/terminal/components/terminal-tab.vue b/web/src/views/terminal/components/terminal-tab.vue index 3aba44e..833b866 100644 --- a/web/src/views/terminal/components/terminal-tab.vue +++ b/web/src/views/terminal/components/terminal-tab.vue @@ -61,7 +61,7 @@ const fitAddon = ref(null) const socketConnected = ref(false) const curStatus = ref(CONNECTING) const terminalRef = ref(null) -const { showMenu, closeMenu } = useContextMenu() +const { showMenu, closeMenu, isVisible } = useContextMenu() const cursorTheme = { cursor: '#00ff41', cursorAccent: '#000000' @@ -380,6 +380,11 @@ const onData = () => { } if (!socket.value || !socketConnected.value) return + // 检查是否按下ESC键且右键菜单正在显示 + if (key === '\x1b') { // ESC键的ASCII码是27,对应字符是'\x1b' + if (isVisible.value) return closeMenu() + } + if (isLongPressCtrl.value || isLongPressAlt.value) { const keyCode = key.toUpperCase().charCodeAt(0) console.log('keyCode: ', keyCode) @@ -482,7 +487,10 @@ const handleRightClick = async (e) => { } const copySelection = str ? { label: '复制', - onClick: async () => await handleCopySelection() + onClick: async () => { + await handleCopySelection() + focusTab() + } } : null const pasteSelection = str ? { label: '粘贴选中内容',