This commit is contained in:
Baobhan Sith
2025-05-28 11:04:54 +08:00
parent 50f3724ef8
commit 3bc2a07ec9
3 changed files with 13 additions and 15 deletions
@@ -92,8 +92,19 @@ const handleDelete = async (pathItem: FavoritePathItem) => {
}; };
const handleSendToTerminal = (pathItem: FavoritePathItem) => { const handleSendToTerminal = (pathItem: FavoritePathItem) => {
emitWorkspaceEvent('favoritePath:sendToActiveTerminal', { path: pathItem.path }); const activeSession = sessionStore.activeSession;
closeModal(); // Optionally close modal after sending 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 = () => { const closeModal = () => {
@@ -102,8 +113,6 @@ const closeModal = () => {
const updatePosition = () => { const updatePosition = () => {
if (!props.isVisible || !props.triggerElement || !modalContentRef.value) { 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; return;
} }
@@ -571,15 +571,6 @@ onMounted(() => {
terminalRef.value.addEventListener('touchcancel', handleTouchEnd, { passive: false }); // Also handle cancel 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); terminalRef.value.removeEventListener('touchcancel', handleTouchEnd);
} }
unsubscribeFromWorkspaceEvent('favoritePath:sendToActiveTerminal');
}); });
@@ -53,7 +53,6 @@ export type WorkspaceEventPayloads = {
// Suspended SSH Session Events // Suspended SSH Session Events
'suspendedSession:actionCompleted': void; // Emitted when a resume/remove action is completed '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 事件发射器实例 // 创建 mitt 事件发射器实例