feat: 优化菜单隐藏逻辑

This commit is contained in:
chaoszhu
2025-06-16 22:51:40 +08:00
parent 39baeac2ea
commit a9c3a5201a
2 changed files with 15 additions and 2 deletions
+5
View File
@@ -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
}
@@ -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: '粘贴选中内容',