Commit bae2f4d0 by pangchong

fix: 优化树菜单定位与高亮逻辑,当选中的是未生成虚拟节点的文本片段时自动回退到父级节点

parent f13e58fd
......@@ -445,6 +445,21 @@ export function useNodeTree(
return text.replace(regex, '<mark class="highlight-mark">$1</mark>')
}
const effectiveSelectedId = computed(() => {
const selId = editorStore.selectedNodeId
if (!selId) return null
if (flatList.value.some((item) => item.id === selId)) {
return selId
}
if (selId.includes('-txt-')) {
const parentId = selId.split('-txt-')[0]
if (flatList.value.some((item) => item.id === parentId)) {
return parentId
}
}
return selId
})
// 树展开与定位同步辅助函数
const syncTreeSelection = (newId: string | null, shouldExpand = true) => {
if (!newId) return
......@@ -485,7 +500,8 @@ export function useNodeTree(
if (isTreeSelecting.value) {
return
}
const idx = flatList.value.findIndex((item) => item.id === newId)
const targetScrollId = effectiveSelectedId.value || newId
const idx = flatList.value.findIndex((item) => item.id === targetScrollId)
if (idx !== -1 && viewportRef.value) {
const itemTop = idx * ITEM_HEIGHT
const vHeight = viewportRef.value.clientHeight
......@@ -1320,6 +1336,7 @@ export function useNodeTree(
handleScroll,
hasCustomColor,
getNodeStyle,
effectiveSelectedId,
// 批量管理模式
isBatchMode,
selectedKeys,
......
......@@ -62,7 +62,7 @@
:key="item.id"
class="flex items-center h-[32px] px-2 rounded cursor-pointer transition-colors group/row tree-node-content"
:class="[
editorStore.selectedNodeId === item.id
effectiveSelectedId === item.id
? 'bg-primary text-white tree-node-selected'
: (showDropdown || isAnyModalVisible) && contextNodeId === item.id
? 'tree-node-context-active'
......@@ -112,7 +112,7 @@
<div
v-if="item.hasChildren"
class="w-4 h-4 flex items-center justify-center mr-1 text-color3 hover:text-color1 cursor-pointer transition-colors z-10"
:class="[editorStore.selectedNodeId === item.id ? 'text-white/80 hover:text-white' : 'text-primary']"
:class="[effectiveSelectedId === item.id ? 'text-white/80 hover:text-white' : 'text-primary']"
@click.stop="toggleExpand(item.id)"
>
<!-- 展开状态:减号 -->
......@@ -131,7 +131,7 @@
<!-- Icon -->
<div
class="mr-1.5 flex items-center justify-center shrink-0 z-10"
:class="[editorStore.selectedNodeId === item.id ? 'text-white' : '']"
:class="[effectiveSelectedId === item.id ? 'text-white' : '']"
>
<n-icon size="16">
<component :is="getNodeIcon(item)" />
......@@ -147,7 +147,7 @@
v-if="item.subtitle"
class="text-xs truncate"
:class="[
editorStore.selectedNodeId === item.id
effectiveSelectedId === item.id
? 'text-white/70'
: (showDropdown || isAnyModalVisible) && contextNodeId === item.id
? 'tree-node-context-active-subtitle'
......@@ -249,6 +249,7 @@ const {
handleDropdownSelect,
hasCustomColor,
getNodeStyle,
effectiveSelectedId,
// 批量管理模式
isBatchMode,
selectedKeys,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment