Fix:修复非富文本模式下文本中存在<>&字符时再次编辑时部分文本会消失的问题

This commit is contained in:
wanglin2 2023-09-23 10:22:57 +08:00
parent 0f047da78b
commit 8596e3356d
2 changed files with 24 additions and 4 deletions

View File

@ -1,4 +1,10 @@
import { getStrWithBrFromHtml, checkNodeOuter, focusInput, selectAllInput } from '../../utils'
import {
getStrWithBrFromHtml,
checkNodeOuter,
focusInput,
selectAllInput,
htmlEscape
} from '../../utils'
import { ERROR_TYPES } from '../../constants/constant'
// 节点文字编辑类
@ -167,9 +173,11 @@ export default class TextEdit {
let scale = this.mindMap.view.scale
let lineHeight = node.style.merge('lineHeight')
let fontSize = node.style.merge('fontSize')
let textLines = (this.cacheEditingText || node.nodeData.data.text).split(
/\n/gim
)
let textLines = (this.cacheEditingText || node.nodeData.data.text)
.split(/\n/gim)
.map(item => {
return htmlEscape(item)
})
let isMultiLine = node._textData.node.attr('data-ismultiLine') === 'true'
node.style.domText(this.textEditNode, scale, isMultiLine)
this.textEditNode.style.zIndex = nodeTextEditZIndex

View File

@ -797,3 +797,15 @@ export const getNodeIndex = node => {
})
: 0
}
// html转义
export const htmlEscape = str => {
;[
['&', '&amp;'],
['<', '&lt;'],
['>', '&gt;']
].forEach(item => {
str = str.replace(new RegExp(item[0], 'g'), item[1])
})
return str
}