fix: Block Editor在行尾输入空格会唤出AI对话框改成双击空格唤出AI对话框

This commit is contained in:
jingrow 2026-06-16 14:35:02 +08:00
parent 6b2add165c
commit 727d98c40d

View File

@ -659,12 +659,15 @@ const aiInputOverlayRef = ref<HTMLElement | null>(null)
/** 是否为续写模式(行尾空格,非空段落) */
const aiIsContinuation = ref(false)
/** 空格键触发 AI 输入条 */
// AI
/** 双击空格300ms 内)触发 AI 输入条;单次空格正常插入字符 */
let _lastSpaceTime = 0
let _wasEmptyBeforeDblSpace = false
const DBL_SPACE_TIMEOUT = 300
function handleAISpaceTrigger(event: KeyboardEvent) {
const editor = editorRef.value
if (!editor || !editor.isEditable) return
//
if (event.key !== ' ' || event.ctrlKey || event.metaKey || event.altKey) return
const { $from } = editor.state.selection
@ -672,16 +675,22 @@ function handleAISpaceTrigger(event: KeyboardEvent) {
const isEmptyParagraph = $from.parent.content.size === 0
const isAtEnd = $from.parentOffset >= $from.parent.content.size
//
if (!isEmptyParagraph && !isAtEnd) return
event.preventDefault()
const now = Date.now()
aiIsContinuation.value = !isEmptyParagraph
if (now - _lastSpaceTime < DBL_SPACE_TIMEOUT) {
// 300ms AI
event.preventDefault()
aiIsContinuation.value = !_wasEmptyBeforeDblSpace
showAskDialog.value = true
_lastSpaceTime = 0
return
}
// 使 AskAIDialog
showAskDialog.value = true
//
_lastSpaceTime = now
_wasEmptyBeforeDblSpace = isEmptyParagraph
}
/** 点击 AI 输入框外部时关闭 */