Skip to content

Commit e8dbfb3

Browse files
committed
fix: only modify the first line while editing multi-line node
fixed #95
1 parent c8ad337 commit e8dbfb3

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mind-elixir",
3-
"version": "0.19.4",
3+
"version": "0.19.5",
44
"description": "Mind elixir is a free open source mind map core.",
55
"main": "dist/MindElixir.js",
66
"scripts": {

src/exampleData/1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export default {
170170
children: [
171171
{
172172
topic:
173-
'Drag a node to another node\nand the former one will become a child node of latter one',
173+
'Drag a node to another node\nand the former one will become a child node of latter one',
174174
id: 'bd1f07c598e729dc',
175175
},
176176
],

src/nodeOperation.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -203,19 +203,21 @@ export const insertParent = function(el, node) {
203203
const newNodeObj = node || this.generateNewObj()
204204
insertParentNodeObj(nodeObj, newNodeObj)
205205
addParentLink(this.nodeData)
206+
206207
const grp0 = nodeEle.parentElement.parentElement
207208
console.time('insertParent_DOM')
208209
const { grp, top } = this.createGroup(newNodeObj, true)
209-
const children = grp0.parentNode
210-
children.insertBefore(grp, grp0.nextSibling)
210+
top.appendChild(createExpander(true))
211+
const children0 = grp0.parentNode
212+
grp0.insertAdjacentElement('afterend', grp)
211213

212214
const c = $d.createElement('children')
213215
c.appendChild(grp0)
214-
top.appendChild(createExpander(true))
215-
top.parentElement.insertBefore(c, top.nextSibling)
216216

217-
if (children.className === 'box') {
218-
grp.className = grp0.className
217+
top.insertAdjacentElement('afterend', c)
218+
219+
if (children0.className === 'box') {
220+
grp.className = grp0.className // l/rhs
219221
grp0.className = ''
220222
grp0.querySelector('.svg3rd').remove()
221223
this.linkDiv()
@@ -258,7 +260,7 @@ export const addChildFunction = function(nodeEle, node) {
258260
const c = $d.createElement('children')
259261
c.appendChild(grp)
260262
top.appendChild(createExpander(true))
261-
top.parentElement.insertBefore(c, top.nextSibling)
263+
top.insertAdjacentElement('afterend', c)
262264
}
263265
this.linkDiv(grp.offsetParent)
264266
} else if (top.tagName === 'ROOT') {
@@ -367,7 +369,7 @@ export const moveDownNode = function(el) {
367369
const obj = nodeEle.nodeObj
368370
moveDownObj(obj)
369371
if (grp.nextSibling) {
370-
grp.parentNode.insertBefore(grp, grp.nextSibling.nextSibling)
372+
grp.insertAdjacentElement('afterend', grp.nextSibling)
371373
} else {
372374
grp.parentNode.prepend(grp)
373375
}

src/utils/dom.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const findEle = (id: string, instance?) => {
2121
}
2222

2323
export const shapeTpc = function(tpc: Topic, nodeObj: NodeObj) {
24-
tpc.innerText = nodeObj.topic
24+
tpc.textContent = nodeObj.topic
2525

2626
if (nodeObj.style) {
2727
tpc.style.color = nodeObj.style.color || 'inherit'
@@ -110,7 +110,7 @@ export function createInputDiv(tpc: Topic) {
110110
const origin = tpc.childNodes[0].textContent as string
111111
tpc.appendChild(div)
112112
div.id = 'input-box'
113-
div.innerText = origin
113+
div.textContent = origin
114114
div.contentEditable = 'true'
115115
div.spellcheck = false
116116
div.style.cssText = `min-width:${tpc.offsetWidth - 8}px;`
@@ -142,18 +142,19 @@ export function createInputDiv(tpc: Topic) {
142142
if (!div) return // 防止重复blur
143143
const node = tpc.nodeObj
144144
const topic = div.textContent!.trim()
145+
console.log(topic)
145146
if (topic === '') node.topic = origin
146147
else node.topic = topic
147148
div.remove()
148149
this.inputDiv = div = null
150+
if (topic === origin) return // 没有修改不做处理
151+
tpc.childNodes[0].textContent = node.topic
152+
this.linkDiv()
149153
this.bus.fire('operation', {
150154
name: 'finishEdit',
151155
obj: node,
152156
origin,
153157
})
154-
if (topic === origin) return // 没有修改不做处理
155-
tpc.childNodes[0].textContent = node.topic
156-
this.linkDiv()
157158
})
158159
console.timeEnd('createInputDiv')
159160
}

0 commit comments

Comments
 (0)