Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
I
Ifar-Xml-Edtor
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pangchong
Ifar-Xml-Edtor
Commits
158ac826
Commit
158ac826
authored
Jul 29, 2026
by
pangchong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 优化批量删除节点的定位问题
parent
151025c3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
3 deletions
+59
-3
src/store/editor/index.ts
+59
-3
No files found.
src/store/editor/index.ts
View file @
158ac826
...
@@ -1165,6 +1165,63 @@ export const useEditorStore = defineStore('editor', {
...
@@ -1165,6 +1165,63 @@ export const useEditorStore = defineStore('editor', {
batchDeleteMultipleNodes
(
nodeIds
:
string
[])
{
batchDeleteMultipleNodes
(
nodeIds
:
string
[])
{
if
(
!
this
.
xmlTree
||
nodeIds
.
length
===
0
)
return
if
(
!
this
.
xmlTree
||
nodeIds
.
length
===
0
)
return
const
allDeleteSet
=
new
Set
(
nodeIds
)
// 计算删除完成后选中的新节点 ID(如果当前选中的节点或其祖先节点在被删节点列表中)
let
nextSelectedId
:
string
|
null
=
null
if
(
this
.
selectedNodeId
)
{
let
checkId
=
this
.
selectedNodeId
if
(
checkId
.
includes
(
'-txt-'
))
{
checkId
=
checkId
.
split
(
'-txt-'
)[
0
]
}
let
curr
=
this
.
nodeMap
.
get
(
checkId
)
let
deletedTargetId
=
''
while
(
curr
)
{
if
(
allDeleteSet
.
has
(
curr
.
node
.
id
))
{
deletedTargetId
=
curr
.
node
.
id
break
}
curr
=
curr
.
parent
?
this
.
nodeMap
.
get
(
curr
.
parent
.
id
)
:
undefined
}
if
(
deletedTargetId
)
{
const
findNextSelectedId
=
(
targetId
:
string
):
string
=>
{
const
item
=
this
.
nodeMap
.
get
(
targetId
)
if
(
!
item
||
!
item
.
parent
)
{
return
this
.
xmlTree
?.
id
||
''
}
const
parent
=
item
.
parent
// 如果父节点也被删除了,递归向上寻找父节点的替代选中节点
if
(
allDeleteSet
.
has
(
parent
.
id
))
{
return
findNextSelectedId
(
parent
.
id
)
}
const
children
=
parent
.
children
||
[]
const
index
=
children
.
findIndex
((
c
)
=>
c
.
id
===
targetId
)
if
(
index
!==
-
1
)
{
// 优先向前寻找未删除的兄弟节点
for
(
let
i
=
index
-
1
;
i
>=
0
;
i
--
)
{
if
(
!
allDeleteSet
.
has
(
children
[
i
].
id
))
{
return
children
[
i
].
id
}
}
// 向后寻找未删除的兄弟节点
for
(
let
i
=
index
+
1
;
i
<
children
.
length
;
i
++
)
{
if
(
!
allDeleteSet
.
has
(
children
[
i
].
id
))
{
return
children
[
i
].
id
}
}
}
// 如果所有兄弟节点都被删除了,返回父节点
return
parent
.
id
}
nextSelectedId
=
findNextSelectedId
(
deletedTargetId
)
}
}
this
.
saveSnapshot
()
this
.
saveSnapshot
()
// 1. 优先处理特殊节点 COLSPEC 和 SPANSPEC
// 1. 优先处理特殊节点 COLSPEC 和 SPANSPEC
...
@@ -1195,9 +1252,8 @@ export const useEditorStore = defineStore('editor', {
...
@@ -1195,9 +1252,8 @@ export const useEditorStore = defineStore('editor', {
removeNodes
(
this
.
xmlTree
)
removeNodes
(
this
.
xmlTree
)
}
}
const
allDeleteSet
=
new
Set
(
nodeIds
)
if
(
nextSelectedId
)
{
if
(
allDeleteSet
.
has
(
this
.
selectedNodeId
||
''
))
{
this
.
setSelectedNodeId
(
nextSelectedId
)
this
.
selectedNodeId
=
this
.
xmlTree
.
id
}
}
this
.
rebuildNodeMap
()
this
.
rebuildNodeMap
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment