feat(编辑器): 添加清除事件常量并优化提及功能
在事件总线常量中添加 editor:clear 事件类型 优化提及功能,确保编辑器获得焦点后光标位置正确
This commit is contained in:
parent
17c1368346
commit
b18a6e5432
@ -783,6 +783,20 @@ const onSubscribeMention = (data) => {
|
||||
// 确保编辑器获得焦点
|
||||
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)
|
||||
}
|
||||
|
@ -5,5 +5,6 @@ export const enum ContactConst {
|
||||
export const enum EditorConst {
|
||||
Mention = 'editor:mention',
|
||||
Quote = 'editor:quote',
|
||||
Edit = 'editor:edit'
|
||||
Edit = 'editor:edit',
|
||||
Clear = 'editor:clear'
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user