From 5bb1f5bb5f597d8ad059a306bdcc08a9c2b0a39b Mon Sep 17 00:00:00 2001 From: Baobhan Sith <80159437+Heavrnl@users.noreply.github.com> Date: Tue, 22 Apr 2025 00:55:22 +0800 Subject: [PATCH] Update FileEditorContainer.vue --- .../src/components/FileEditorContainer.vue | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/packages/frontend/src/components/FileEditorContainer.vue b/packages/frontend/src/components/FileEditorContainer.vue index f76887c..cd35b88 100644 --- a/packages/frontend/src/components/FileEditorContainer.vue +++ b/packages/frontend/src/components/FileEditorContainer.vue @@ -112,10 +112,45 @@ defineExpose({ focusActiveEditor }); // +++ 注册/注销自定义聚焦动作 +++ onMounted(() => { focusSwitcherStore.registerFocusAction('fileEditorActive', focusActiveEditor); + // +++ 添加键盘事件监听器 +++ + window.addEventListener('keydown', handleKeyDown); }); onBeforeUnmount(() => { focusSwitcherStore.unregisterFocusAction('fileEditorActive'); + // +++ 移除键盘事件监听器 +++ + window.removeEventListener('keydown', handleKeyDown); }); + +// +++ 新增:处理键盘事件以切换标签 +++ +const handleKeyDown = (event: KeyboardEvent) => { + // 检查是否在编辑器内部或其容器内触发(避免全局冲突) + // 这里简化处理,假设只要此组件挂载就监听,更精确的判断可能需要检查 event.target + if (event.altKey && (event.key === 'ArrowLeft' || event.key === 'ArrowRight')) { + event.preventDefault(); + event.stopPropagation(); + + if (!props.activeTabId || props.tabs.length <= 1) { + return; // 没有活动标签或只有一个标签,无需切换 + } + + const currentIndex = props.tabs.findIndex(tab => tab.id === props.activeTabId); + if (currentIndex === -1) { + return; // 未找到当前标签索引 + } + + let nextIndex: number; + if (event.key === 'ArrowLeft') { + nextIndex = (currentIndex - 1 + props.tabs.length) % props.tabs.length; + } else { // ArrowRight + nextIndex = (currentIndex + 1) % props.tabs.length; + } + + const nextTabId = props.tabs[nextIndex]?.id; + if (nextTabId) { + emit('activate-tab', nextTabId); + } + } +};