This commit is contained in:
Baobhan Sith
2025-05-01 20:10:29 +08:00
parent 4196a2f51d
commit f4c05fe82a
4 changed files with 40 additions and 6 deletions
@@ -7,7 +7,7 @@ import { useSettingsStore } from '../stores/settings.store';
import { useQuickCommandsStore } from '../stores/quickCommands.store'; import { useQuickCommandsStore } from '../stores/quickCommands.store';
import { useCommandHistoryStore } from '../stores/commandHistory.store'; import { useCommandHistoryStore } from '../stores/commandHistory.store';
const emit = defineEmits(['send-command', 'search', 'find-next', 'find-previous', 'close-search']); const emit = defineEmits(['send-command', 'search', 'find-next', 'find-previous', 'close-search', 'clear-terminal']); // 添加 clear-terminal 事件
const { t } = useI18n(); const { t } = useI18n();
const focusSwitcherStore = useFocusSwitcherStore(); const focusSwitcherStore = useFocusSwitcherStore();
const settingsStore = useSettingsStore(); const settingsStore = useSettingsStore();
@@ -223,6 +223,14 @@ onBeforeUnmount(() => {
<template> <template>
<div class="flex items-center px-2 py-1.5 bg-background gap-2"> <!-- Removed border-t and border-border/50 --> <div class="flex items-center px-2 py-1.5 bg-background gap-2"> <!-- Removed border-t and border-border/50 -->
<div class="flex-grow flex items-center bg-transparent relative gap-2"> <!-- Adjusted gap --> <div class="flex-grow flex items-center bg-transparent relative gap-2"> <!-- Adjusted gap -->
<!-- Clear Terminal Button -->
<button
@click="emit('clear-terminal')"
class="flex-shrink-0 flex items-center justify-center w-8 h-8 border border-border/50 rounded-lg text-text-secondary transition-colors duration-200 hover:bg-border hover:text-foreground"
:title="t('commandInputBar.clearTerminal', '清空终端')"
>
<i class="fas fa-eraser text-base"></i>
</button>
<!-- Focus Switcher Config Button --> <!-- Focus Switcher Config Button -->
<button <button
@click="focusSwitcherStore.toggleConfigurator(true)" @click="focusSwitcherStore.toggleConfigurator(true)"
@@ -64,6 +64,7 @@ const emit = defineEmits({
'find-next': null, // () 'find-next': null, // ()
'find-previous': null, // () 'find-previous': null, // ()
'close-search': null, // () 'close-search': null, // ()
'clear-terminal': null, // () +++ 添加 clear-terminal 事件 +++
// --- 移除 RDP 事件 --- // --- 移除 RDP 事件 ---
}); });
@@ -214,6 +215,7 @@ const componentProps = computed(() => {
onFindNext: () => emit('find-next'), onFindNext: () => emit('find-next'),
onFindPrevious: () => emit('find-previous'), onFindPrevious: () => emit('find-previous'),
onCloseSearch: () => emit('close-search'), onCloseSearch: () => emit('close-search'),
onClearTerminal: () => emit('clear-terminal'), // --- 移除日志 ---
}; };
case 'connections': case 'connections':
// WorkspaceConnectionList 需要转发 connect-request 等事件 // WorkspaceConnectionList 需要转发 connect-request 等事件
@@ -507,6 +509,7 @@ onMounted(() => {
@find-next="emit('find-next')" @find-next="emit('find-next')"
@find-previous="emit('find-previous')" @find-previous="emit('find-previous')"
@close-search="emit('close-search')" @close-search="emit('close-search')"
@clear-terminal="() => emit('clear-terminal')" <!-- --- 移除日志 --- -->
class="flex-grow overflow-auto" class="flex-grow overflow-auto"
/> />
</pane> </pane>
@@ -399,7 +399,12 @@ const clearSearch = () => {
searchAddon?.clearDecorations(); searchAddon?.clearDecorations();
}; };
defineExpose({ write, findNext, findPrevious, clearSearch }); // +++ 添加 clear 方法 +++
const clear = () => {
terminal?.clear();
};
defineExpose({ write, findNext, findPrevious, clearSearch, clear }); // 暴露 clear 方法
// --- 应用终端背景 --- // --- 应用终端背景 ---
@@ -293,6 +293,23 @@ const handleCloseSearch = () => {
} }
}; };
// +++ 新增:处理清空终端事件 +++
const handleClearTerminal = () => {
const currentSession = activeSession.value;
if (!currentSession) {
console.warn('[WorkspaceView] Cannot clear terminal, no active session.');
return;
}
const terminalManager = currentSession.terminalManager as (SshTerminalInstance | undefined);
// 调用 Terminal.vue 组件暴露的 clear 方法
if (terminalManager && terminalManager.terminalInstance?.value && typeof terminalManager.terminalInstance.value.clear === 'function') {
console.log(`[WorkspaceView] Clearing terminal for active session ${currentSession.sessionId}`);
terminalManager.terminalInstance.value.clear();
} else {
console.warn(`[WorkspaceView] Cannot clear terminal for session ${currentSession.sessionId}, terminal manager, instance, or clear method not available.`);
}
};
// Removed computed properties for search results, will pass manager directly // Removed computed properties for search results, will pass manager directly
// --- 编辑器操作处理 (用于 FileEditorContainer) --- // --- 编辑器操作处理 (用于 FileEditorContainer) ---
const handleCloseEditorTab = (tabId: string) => { const handleCloseEditorTab = (tabId: string) => {
@@ -415,6 +432,7 @@ const handleCloseEditorTab = (tabId: string) => {
@find-next="handleFindNext" @find-next="handleFindNext"
@find-previous="handleFindPrevious" @find-previous="handleFindPrevious"
@close-search="handleCloseSearch" @close-search="handleCloseSearch"
@clear-terminal="handleClearTerminal"
></LayoutRenderer> <!-- 修正使用单独的结束标签 --> ></LayoutRenderer> <!-- 修正使用单独的结束标签 -->
<div v-else class="pane-placeholder"> <!-- 确保 v-else 紧随 v-if --> <div v-else class="pane-placeholder"> <!-- 确保 v-else 紧随 v-if -->
{{ t('layout.loading', '加载布局中...') }} {{ t('layout.loading', '加载布局中...') }}