update
This commit is contained in:
@@ -691,33 +691,54 @@ watch(() => props.sessionId, (newSessionId, oldSessionId) => {
|
|||||||
// onBeforeUnmount 中 cleanupSftpHandlers 的调用已移至新的 onBeforeUnmount 逻辑中
|
// onBeforeUnmount 中 cleanupSftpHandlers 的调用已移至新的 onBeforeUnmount 逻辑中
|
||||||
|
|
||||||
// +++ 注册/注销自定义聚焦动作 +++
|
// +++ 注册/注销自定义聚焦动作 +++
|
||||||
let unregisterFocusAction: (() => void) | null = null; // 用于存储注销函数
|
let unregisterSearchFocusAction: (() => void) | null = null; // 搜索框注销函数
|
||||||
|
let unregisterPathFocusAction: (() => void) | null = null; // 路径编辑框注销函数
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
// 注册一个 async 函数以兼容 Promise 返回类型
|
// 注册搜索框聚焦动作
|
||||||
const focusActionWrapper = async (): Promise<boolean | undefined> => {
|
const focusSearchActionWrapper = async (): Promise<boolean | undefined> => {
|
||||||
if (props.sessionId === sessionStore.activeSessionId) {
|
if (props.sessionId === sessionStore.activeSessionId) {
|
||||||
// 如果是活动会话,调用聚焦函数并返回其结果
|
console.log(`[FileManager ${props.sessionId}-${props.instanceId}] Executing search focus action for active session.`);
|
||||||
console.log(`[FileManager ${props.sessionId}-${props.instanceId}] Executing focus action for active session.`);
|
return focusSearchInput();
|
||||||
return focusSearchInput(); // focusSearchInput 返回 boolean
|
|
||||||
} else {
|
} else {
|
||||||
// 如果不是活动会话,返回 undefined 表示跳过
|
console.log(`[FileManager ${props.sessionId}-${props.instanceId}] Search focus action skipped for inactive session.`);
|
||||||
console.log(`[FileManager ${props.sessionId}-${props.instanceId}] Focus action skipped for inactive session.`);
|
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// 调用 registerFocusAction 并存储返回的注销函数
|
unregisterSearchFocusAction = focusSwitcherStore.registerFocusAction('fileManagerSearch', focusSearchActionWrapper);
|
||||||
unregisterFocusAction = focusSwitcherStore.registerFocusAction('fileManagerSearch', focusActionWrapper);
|
|
||||||
|
// 注册路径编辑框聚焦动作
|
||||||
|
const focusPathActionWrapper = async (): Promise<boolean | undefined> => {
|
||||||
|
if (props.sessionId === sessionStore.activeSessionId) {
|
||||||
|
console.log(`[FileManager ${props.sessionId}-${props.instanceId}] Executing path edit focus action for active session.`);
|
||||||
|
// startPathEdit 本身不是 async,但注册时需要包装成 async 以匹配类型
|
||||||
|
startPathEdit(); // 调用暴露的方法
|
||||||
|
// 假设 startPathEdit 总是尝试聚焦,这里返回 true 表示已尝试
|
||||||
|
// 注意:startPathEdit 内部没有返回成功与否,这里乐观返回 true
|
||||||
|
// 如果需要更精确,startPathEdit 需要返回 boolean
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
console.log(`[FileManager ${props.sessionId}-${props.instanceId}] Path edit focus action skipped for inactive session.`);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
unregisterPathFocusAction = focusSwitcherStore.registerFocusAction('fileManagerPathInput', focusPathActionWrapper);
|
||||||
});
|
});
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
onBeforeUnmount(() => {
|
||||||
// 调用存储的注销函数
|
// 注销搜索框动作
|
||||||
if (unregisterFocusAction) {
|
if (unregisterSearchFocusAction) {
|
||||||
unregisterFocusAction();
|
unregisterSearchFocusAction();
|
||||||
console.log(`[FileManager ${props.sessionId}-${props.instanceId}] Unregistered focus action on unmount.`);
|
console.log(`[FileManager ${props.sessionId}-${props.instanceId}] Unregistered search focus action on unmount.`);
|
||||||
}
|
}
|
||||||
// 清理对函数的引用
|
unregisterSearchFocusAction = null;
|
||||||
unregisterFocusAction = null;
|
|
||||||
|
// 注销路径编辑框动作
|
||||||
|
if (unregisterPathFocusAction) {
|
||||||
|
unregisterPathFocusAction();
|
||||||
|
console.log(`[FileManager ${props.sessionId}-${props.instanceId}] Unregistered path edit focus action on unmount.`);
|
||||||
|
}
|
||||||
|
unregisterPathFocusAction = null;
|
||||||
// // 调用注入的 SFTP 管理器提供的清理函数 (移除,由 store 处理)
|
// // 调用注入的 SFTP 管理器提供的清理函数 (移除,由 store 处理)
|
||||||
// cleanupSftpHandlers();
|
// cleanupSftpHandlers();
|
||||||
// 调用 store 的清理方法
|
// 调用 store 的清理方法
|
||||||
@@ -883,7 +904,7 @@ const focusSearchInput = (): boolean => {
|
|||||||
console.warn(`[FileManager ${props.sessionId}-${props.instanceId}] Could not focus search input.`);
|
console.warn(`[FileManager ${props.sessionId}-${props.instanceId}] Could not focus search input.`);
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
defineExpose({ focusSearchInput });
|
defineExpose({ focusSearchInput, startPathEdit });
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -912,6 +933,7 @@ defineExpose({ focusSearchInput });
|
|||||||
type="text"
|
type="text"
|
||||||
v-model="editablePath"
|
v-model="editablePath"
|
||||||
class="flex-grow bg-transparent text-foreground p-0.5 outline-none min-w-[100px]"
|
class="flex-grow bg-transparent text-foreground p-0.5 outline-none min-w-[100px]"
|
||||||
|
data-focus-id="fileManagerPathInput"
|
||||||
@keyup.enter="handlePathInput"
|
@keyup.enter="handlePathInput"
|
||||||
@blur="handlePathInput"
|
@blur="handlePathInput"
|
||||||
@keyup.esc="cancelPathEdit"
|
@keyup.esc="cancelPathEdit"
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ export const useFocusSwitcherStore = defineStore('focusSwitcher', () => {
|
|||||||
{ id: 'terminalSearch', label: t('focusSwitcher.input.terminalSearch', '终端内搜索') },
|
{ id: 'terminalSearch', label: t('focusSwitcher.input.terminalSearch', '终端内搜索') },
|
||||||
{ id: 'connectionListSearch', label: t('focusSwitcher.input.connectionListSearch', '连接列表搜索') },
|
{ id: 'connectionListSearch', label: t('focusSwitcher.input.connectionListSearch', '连接列表搜索') },
|
||||||
{ id: 'fileEditorActive', label: t('focusSwitcher.input.fileEditorActive', '文件编辑器') },
|
{ id: 'fileEditorActive', label: t('focusSwitcher.input.fileEditorActive', '文件编辑器') },
|
||||||
|
{ id: 'fileManagerPathInput', label: t('focusSwitcher.input.fileManagerPathInput', '文件管理器路径编辑') },
|
||||||
]);
|
]);
|
||||||
const sequenceOrder = ref<string[]>([]); // +++ 新增:存储顺序 +++
|
const sequenceOrder = ref<string[]>([]); // +++ 新增:存储顺序 +++
|
||||||
const itemConfigs = ref<Record<string, FocusItemConfig>>({}); // +++ 新增:存储所有配置 +++
|
const itemConfigs = ref<Record<string, FocusItemConfig>>({}); // +++ 新增:存储所有配置 +++
|
||||||
|
|||||||
Reference in New Issue
Block a user