Skip to content

Commit 5022ceb

Browse files
committed
fix: 修复内容随后设置标题,会报错,而且无法再编辑的问题
1 parent feac0af commit 5022ceb

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/menus/head/index.ts

-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ class Head extends DropListMenu implements MenuActive {
3333
},
3434
],
3535
clickHandler: (value: string) => {
36-
if (editor.$textElem.html() === EMPTY_P) {
37-
return
38-
}
3936
// 注意 this 是指向当前的 Head 对象
4037
this.command(value)
4138
},

src/text/event-hooks/del-to-keep-p.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,25 @@ function deleteToKeepP(editor: Editor, deleteUpEvents: Function[], deleteDownEve
3232
// 内容空了
3333
$textElem.html(EMPTY_P)
3434

35-
editor.selection.createRangeByElem($textElem, false, true)
35+
/**
36+
* 当编辑器 - 文本区内容为空的情况下,会插入一个空的P,此时应该将选区移动到这个空标签上,重置选区
37+
* bug: 如果选区没有从$textElem上调整到p上,就会有问题,在清空内容,设置标题时,会报错。
38+
*/
39+
const containerElem = $textElem.getNode()
40+
41+
// 设置新的选区
42+
editor.selection.createRangeByElems(
43+
containerElem.childNodes[0],
44+
containerElem.childNodes[0]
45+
)
46+
47+
const $selectionElem = editor.selection.getSelectionContainerElem()!
48+
3649
editor.selection.restoreSelection()
50+
3751
// 设置折叠后的光标位置,在firebox等浏览器下
3852
// 光标设置在end位置会自动换行
39-
editor.selection.moveCursor($textElem.getNode(), 0)
53+
editor.selection.moveCursor($selectionElem.getNode(), 0)
4054
}
4155
}
4256
deleteUpEvents.push(upFn)

0 commit comments

Comments
 (0)