diff --git a/src/text/event-hooks/del-to-keep-p.ts b/src/text/event-hooks/del-to-keep-p.ts
index 09d682a..bff02a8 100644
--- a/src/text/event-hooks/del-to-keep-p.ts
+++ b/src/text/event-hooks/del-to-keep-p.ts
@@ -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[] = ['
', '
', EMPTY_P]
// 编辑器中的字符是""或空白,说明内容为空
- if (/^\s*$/.test(editor.$textElem.text())) {
+ if (/^\s*$/.test(text) && (!txtHtml || emptyTags.includes(txtHtml))) {
// 内容空了
const $p = $(EMPTY_P)
$textElem.html(' ') // 一定要先清空,否则在 firefox 下有问题
diff --git a/test/unit/text/del-to-keep-p.test.ts b/test/unit/text/del-to-keep-p.test.ts
index ac60866..aad9f15 100644
--- a/test/unit/text/del-to-keep-p.test.ts
+++ b/test/unit/text/del-to-keep-p.test.ts
@@ -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('当编辑器内容只有
时,执行 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 内容时,则不允许再删除', () => {