Skip to content

Commit

Permalink
fix: only modify the first line while editing multi-line node
Browse files Browse the repository at this point in the history
fixed #95
  • Loading branch information
SSShooter committed May 9, 2022
1 parent c8ad337 commit e8dbfb3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mind-elixir",
"version": "0.19.4",
"version": "0.19.5",
"description": "Mind elixir is a free open source mind map core.",
"main": "dist/MindElixir.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/exampleData/1.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export default {
children: [
{
topic:
'Drag a node to another node\nand the former one will become a child node of latter one',
'Drag a node to another node\nand the former one will become a child node of latter one',
id: 'bd1f07c598e729dc',
},
],
Expand Down
18 changes: 10 additions & 8 deletions src/nodeOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,21 @@ export const insertParent = function(el, node) {
const newNodeObj = node || this.generateNewObj()
insertParentNodeObj(nodeObj, newNodeObj)
addParentLink(this.nodeData)

const grp0 = nodeEle.parentElement.parentElement
console.time('insertParent_DOM')
const { grp, top } = this.createGroup(newNodeObj, true)
const children = grp0.parentNode
children.insertBefore(grp, grp0.nextSibling)
top.appendChild(createExpander(true))
const children0 = grp0.parentNode
grp0.insertAdjacentElement('afterend', grp)

const c = $d.createElement('children')
c.appendChild(grp0)
top.appendChild(createExpander(true))
top.parentElement.insertBefore(c, top.nextSibling)

if (children.className === 'box') {
grp.className = grp0.className
top.insertAdjacentElement('afterend', c)

if (children0.className === 'box') {
grp.className = grp0.className // l/rhs
grp0.className = ''
grp0.querySelector('.svg3rd').remove()
this.linkDiv()
Expand Down Expand Up @@ -258,7 +260,7 @@ export const addChildFunction = function(nodeEle, node) {
const c = $d.createElement('children')
c.appendChild(grp)
top.appendChild(createExpander(true))
top.parentElement.insertBefore(c, top.nextSibling)
top.insertAdjacentElement('afterend', c)
}
this.linkDiv(grp.offsetParent)
} else if (top.tagName === 'ROOT') {
Expand Down Expand Up @@ -367,7 +369,7 @@ export const moveDownNode = function(el) {
const obj = nodeEle.nodeObj
moveDownObj(obj)
if (grp.nextSibling) {
grp.parentNode.insertBefore(grp, grp.nextSibling.nextSibling)
grp.insertAdjacentElement('afterend', grp.nextSibling)
} else {
grp.parentNode.prepend(grp)
}
Expand Down
11 changes: 6 additions & 5 deletions src/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const findEle = (id: string, instance?) => {
}

export const shapeTpc = function(tpc: Topic, nodeObj: NodeObj) {
tpc.innerText = nodeObj.topic
tpc.textContent = nodeObj.topic

if (nodeObj.style) {
tpc.style.color = nodeObj.style.color || 'inherit'
Expand Down Expand Up @@ -110,7 +110,7 @@ export function createInputDiv(tpc: Topic) {
const origin = tpc.childNodes[0].textContent as string
tpc.appendChild(div)
div.id = 'input-box'
div.innerText = origin
div.textContent = origin
div.contentEditable = 'true'
div.spellcheck = false
div.style.cssText = `min-width:${tpc.offsetWidth - 8}px;`
Expand Down Expand Up @@ -142,18 +142,19 @@ export function createInputDiv(tpc: Topic) {
if (!div) return // 防止重复blur
const node = tpc.nodeObj
const topic = div.textContent!.trim()
console.log(topic)
if (topic === '') node.topic = origin
else node.topic = topic
div.remove()
this.inputDiv = div = null
if (topic === origin) return // 没有修改不做处理
tpc.childNodes[0].textContent = node.topic
this.linkDiv()
this.bus.fire('operation', {
name: 'finishEdit',
obj: node,
origin,
})
if (topic === origin) return // 没有修改不做处理
tpc.childNodes[0].textContent = node.topic
this.linkDiv()
})
console.timeEnd('createInputDiv')
}
Expand Down

0 comments on commit e8dbfb3

Please sign in to comment.