From 3bc2a07ec9c261c62495367ebef0cfdc19ed2628 Mon Sep 17 00:00:00 2001 From: Baobhan Sith <80159437+Heavrnl@users.noreply.github.com> Date: Wed, 28 May 2025 11:04:54 +0800 Subject: [PATCH] update --- .../src/components/FavoritePathsModal.vue | 17 +++++++++++++---- packages/frontend/src/components/Terminal.vue | 10 ---------- .../frontend/src/composables/workspaceEvents.ts | 1 - 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/packages/frontend/src/components/FavoritePathsModal.vue b/packages/frontend/src/components/FavoritePathsModal.vue index c7fde6e..8b51aff 100644 --- a/packages/frontend/src/components/FavoritePathsModal.vue +++ b/packages/frontend/src/components/FavoritePathsModal.vue @@ -92,8 +92,19 @@ const handleDelete = async (pathItem: FavoritePathItem) => { }; const handleSendToTerminal = (pathItem: FavoritePathItem) => { - emitWorkspaceEvent('favoritePath:sendToActiveTerminal', { path: pathItem.path }); - closeModal(); // Optionally close modal after sending + const activeSession = sessionStore.activeSession; + if (activeSession && activeSession.terminalManager) { + const escapedPath = `"${pathItem.path.replace(/"/g, '\\"')}"`; + const command = `cd ${escapedPath}\n`; + try { + activeSession.terminalManager.sendData(command); + } catch (error) { + console.error('[FavoritePathsModal] Failed to send command to active terminal:', error); + } + } else { + console.warn('[FavoritePathsModal] No active session with a terminal manager found to send path to.'); + } + closeModal(); }; const closeModal = () => { @@ -102,8 +113,6 @@ const closeModal = () => { const updatePosition = () => { if (!props.isVisible || !props.triggerElement || !modalContentRef.value) { - // If not visible or refs not available, do nothing or hide. - // v-if handles DOM presence, so style isn't applied when not isVisible. return; } diff --git a/packages/frontend/src/components/Terminal.vue b/packages/frontend/src/components/Terminal.vue index 087bc3d..61c2ec7 100644 --- a/packages/frontend/src/components/Terminal.vue +++ b/packages/frontend/src/components/Terminal.vue @@ -571,15 +571,6 @@ onMounted(() => { terminalRef.value.addEventListener('touchcancel', handleTouchEnd, { passive: false }); // Also handle cancel } - // Listen for favorite path to send to terminal - subscribeToWorkspaceEvent('favoritePath:sendToActiveTerminal', ({ path }) => { - if (terminal && props.isActive && sessionStore.activeSessionId === props.sessionId) { - // Ensure path is quoted to handle spaces or special characters - const command = `cd "${path.replace(/"/g, '\\"')}"\n`; // Escape existing quotes in path - emitWorkspaceEvent('terminal:input', { sessionId: props.sessionId, data: command }); - terminal.focus(); // Focus terminal after sending command - } - }); } }); @@ -624,7 +615,6 @@ onBeforeUnmount(() => { terminalRef.value.removeEventListener('touchcancel', handleTouchEnd); } - unsubscribeFromWorkspaceEvent('favoritePath:sendToActiveTerminal'); }); diff --git a/packages/frontend/src/composables/workspaceEvents.ts b/packages/frontend/src/composables/workspaceEvents.ts index 96e14ad..071413d 100644 --- a/packages/frontend/src/composables/workspaceEvents.ts +++ b/packages/frontend/src/composables/workspaceEvents.ts @@ -53,7 +53,6 @@ export type WorkspaceEventPayloads = { // Suspended SSH Session Events 'suspendedSession:actionCompleted': void; // Emitted when a resume/remove action is completed - 'favoritePath:sendToActiveTerminal': { path: string }; // Event to send a path to the active terminal }; // 创建 mitt 事件发射器实例