Skip to content

Commit 38b2706

Browse files
committed
fix(dom): improve node removal logic and handle empty wrappers
1 parent 5e46ca7 commit 38b2706

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

src/nodeOperation.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fillParent, refreshIds, unionTopics } from './utils/index'
22
import { findEle, createExpander, shapeTpc } from './utils/dom'
33
import { deepClone } from './utils/index'
4-
import type { Topic } from './types/dom'
4+
import type { Children, Topic } from './types/dom'
55
import { DirectionClass, type MindElixirInstance, type NodeObj } from './types/index'
66
import { insertNodeObj, insertParentNodeObj, moveUpObj, moveDownObj, removeNodeObj, moveNodeObj } from './utils/objectManipulation'
77
import { addChildDom, removeNodeDom } from './utils/domManipulation'
@@ -292,14 +292,25 @@ const moveNode = (from: Topic[], type: 'before' | 'after', to: Topic, mei: MindE
292292
from = from.reverse()
293293
}
294294
const toObj = to.nodeObj
295+
const c: Children[] = []
295296
for (const f of from) {
296297
const obj = f.nodeObj
297298
moveNodeObj(type, obj, toObj)
298299
fillParent(mei.nodeData)
299300
rmSubline(f)
300-
const fromGrp = f.parentElement.parentNode
301-
const toGrp = to.parentElement.parentNode
302-
toGrp.insertAdjacentElement(typeMap[type], fromGrp)
301+
const fromWrp = f.parentElement.parentNode
302+
if (!c.includes(fromWrp.parentElement)) {
303+
c.push(fromWrp.parentElement)
304+
}
305+
const toWrp = to.parentElement.parentNode
306+
toWrp.insertAdjacentElement(typeMap[type], fromWrp)
307+
}
308+
// remove expander and empty wrapper
309+
for (const item of c) {
310+
if (item.childElementCount === 0 && item.tagName !== 'ME-MAIN') {
311+
item.previousSibling.children[1]!.remove()
312+
item.remove()
313+
}
303314
}
304315
mei.linkDiv()
305316
mei.bus.fire('operation', {

src/utils/domManipulation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ export const removeNodeDom = function (tpc: Topic, siblingLength: number) {
5353
if (siblingLength === 0) {
5454
// remove epd when children length === 0
5555
const c = p.parentNode.parentNode
56-
// root doesn't have epd
5756
if (c.tagName !== 'ME-MAIN') {
58-
c.previousSibling.children[1]!.remove()
57+
// Root
58+
c.previousSibling.children[1]!.remove() // remove epd
59+
c.remove() // remove Children div
5960
}
60-
// FIXME: me-children is not removed
6161
}
6262
p.parentNode.remove()
6363
}

0 commit comments

Comments
 (0)