fix: Block Editor在行尾输入空格会唤出AI对话框改成双击空格唤出AI对话框
This commit is contained in:
parent
6b2add165c
commit
727d98c40d
@ -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 输入框外部时关闭 */
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user