mirror of
https://github.com/open-webui/open-webui
synced 2025-03-04 03:18:03 +00:00
refac: autocompletion
This commit is contained in:
parent
9e436fe6b0
commit
c192475528
@ -112,6 +112,10 @@ export const AIAutocompletion = Extension.create({
|
|||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Start debounce logic for AI generation only if the cursor is at the end of the paragraph
|
||||||
|
if (selection.empty && $head.pos === $head.end()) {
|
||||||
|
|
||||||
// Set up debounce for AI generation
|
// Set up debounce for AI generation
|
||||||
if (this.options.debounceTime !== null) {
|
if (this.options.debounceTime !== null) {
|
||||||
clearTimeout(debounceTimer)
|
clearTimeout(debounceTimer)
|
||||||
@ -123,8 +127,9 @@ export const AIAutocompletion = Extension.create({
|
|||||||
const newState = view.state
|
const newState = view.state
|
||||||
const newNode = newState.doc.nodeAt(currentPos)
|
const newNode = newState.doc.nodeAt(currentPos)
|
||||||
|
|
||||||
|
const currentIsAtEnd = newState.selection.$head.pos === newState.selection.$head.end()
|
||||||
// Check if the node still exists and is still a paragraph
|
// Check if the node still exists and is still a paragraph
|
||||||
if (newNode && newNode.type.name === 'paragraph') {
|
if (newNode && newNode.type.name === 'paragraph' && currentIsAtEnd) {
|
||||||
const prompt = newNode.textContent
|
const prompt = newNode.textContent
|
||||||
|
|
||||||
if (prompt.trim() !== ''){
|
if (prompt.trim() !== ''){
|
||||||
@ -147,6 +152,7 @@ export const AIAutocompletion = Extension.create({
|
|||||||
}, this.options.debounceTime)
|
}, this.options.debounceTime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
handleDOMEvents: {
|
handleDOMEvents: {
|
||||||
@ -185,6 +191,12 @@ export const AIAutocompletion = Extension.create({
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
mousedown: () => {
|
||||||
|
// Reset debounce timer on mouse click
|
||||||
|
clearTimeout(debounceTimer)
|
||||||
|
return false
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
Loading…
Reference in New Issue
Block a user