feat(编辑器): 添加清除事件常量并优化提及功能

在事件总线常量中添加 editor:clear 事件类型
优化提及功能,确保编辑器获得焦点后光标位置正确
This commit is contained in:
Phoenix 2025-06-06 12:00:12 +08:00
parent 17c1368346
commit b18a6e5432
2 changed files with 16 additions and 1 deletions

View File

@ -783,6 +783,20 @@ const onSubscribeMention = (data) => {
// //
editorRef.value?.focus() editorRef.value?.focus()
//
const selection = window.getSelection()
if (!selection.rangeCount || !editorRef.value.contains(selection.anchorNode)) {
const range = document.createRange()
if (editorRef.value.lastChild) {
range.setStartAfter(editorRef.value.lastChild)
} else {
range.setStart(editorRef.value, 0)
}
range.collapse(true)
selection.removeAllRanges()
selection.addRange(range)
}
// @ // @
insertMention(data) insertMention(data)
} }

View File

@ -5,5 +5,6 @@ export const enum ContactConst {
export const enum EditorConst { export const enum EditorConst {
Mention = 'editor:mention', Mention = 'editor:mention',
Quote = 'editor:quote', Quote = 'editor:quote',
Edit = 'editor:edit' Edit = 'editor:edit',
Clear = 'editor:clear'
} }