fix: 文本删完后存在的图片会消失

This commit is contained in:
郑温剑 2021-05-14 19:14:37 +08:00
parent 745fa10388
commit 5b14868cc5
2 changed files with 7 additions and 3 deletions

View File

@ -16,9 +16,13 @@ import $ from '../../utils/dom-core'
function deleteToKeepP(editor: Editor, deleteUpEvents: Function[], deleteDownEvents: Function[]) {
function upFn() {
const $textElem = editor.$textElem
const html = editor.$textElem.html()
const text = editor.$textElem.text()
const txtHtml = html.trim()
const emptyTags: string[] = ['<p><br></p>', '<br>', EMPTY_P]
// 编辑器中的字符是""或空白,说明内容为空
if (/^\s*$/.test(editor.$textElem.text())) {
if (/^\s*$/.test(text) && (!txtHtml || emptyTags.includes(txtHtml))) {
// 内容空了
const $p = $(EMPTY_P)
$textElem.html(' ') // 一定要先清空,否则在 firefox 下有问题

View File

@ -31,7 +31,7 @@ describe('editor.text event-hooks tab-to-space test', () => {
fn()
})
expect(editor.$textElem.html()).toEqual(` ${EMPTY_P}`)
expect(editor.$textElem.html().trim()).toEqual(`${EMPTY_P}`)
})
test('当编辑器内容只有 <br> 时,执行 up 函数,则会插入 EMPTY_P 内容', () => {
@ -47,7 +47,7 @@ describe('editor.text event-hooks tab-to-space test', () => {
fn()
})
expect(editor.$textElem.html()).toEqual(` ${EMPTY_P}`)
expect(editor.$textElem.html().trim()).toEqual(`${EMPTY_P}`)
})
test('当编辑器内容清空到只剩下 EMPTY_P 内容时,则不允许再删除', () => {