mirror of
https://github.com/open-webui/open-webui
synced 2024-12-29 07:12:07 +00:00
refac: autocomplete
This commit is contained in:
parent
2fac9b45cd
commit
746fe9ea16
@ -65,8 +65,6 @@ export const AIAutocompletion = Extension.create({
|
|||||||
let touchStartX = 0;
|
let touchStartX = 0;
|
||||||
let touchStartY = 0;
|
let touchStartY = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return [
|
return [
|
||||||
new Plugin({
|
new Plugin({
|
||||||
key: new PluginKey('aiAutocompletion'),
|
key: new PluginKey('aiAutocompletion'),
|
||||||
@ -153,6 +151,9 @@ export const AIAutocompletion = Extension.create({
|
|||||||
.generateCompletion(prompt)
|
.generateCompletion(prompt)
|
||||||
.then((suggestion) => {
|
.then((suggestion) => {
|
||||||
if (suggestion && suggestion.trim() !== '') {
|
if (suggestion && suggestion.trim() !== '') {
|
||||||
|
if (
|
||||||
|
view.state.selection.$head.pos === view.state.selection.$head.end()
|
||||||
|
) {
|
||||||
view.dispatch(
|
view.dispatch(
|
||||||
newState.tr.setNodeMarkup(currentPos, null, {
|
newState.tr.setNodeMarkup(currentPos, null, {
|
||||||
...newNode.attrs,
|
...newNode.attrs,
|
||||||
@ -162,6 +163,7 @@ export const AIAutocompletion = Extension.create({
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
loading = false;
|
loading = false;
|
||||||
@ -209,10 +211,32 @@ export const AIAutocompletion = Extension.create({
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
// Add mousedown behavior
|
||||||
|
mouseup: (view, event) => {
|
||||||
|
const { state, dispatch } = view;
|
||||||
|
const { selection } = state;
|
||||||
|
const { $head } = selection;
|
||||||
|
const node = $head.parent;
|
||||||
|
|
||||||
mousedown: () => {
|
|
||||||
// Reset debounce timer on mouse click
|
// Reset debounce timer on mouse click
|
||||||
clearTimeout(debounceTimer);
|
clearTimeout(debounceTimer);
|
||||||
|
|
||||||
|
// If a suggestion exists and the cursor moves, remove the suggestion
|
||||||
|
if (
|
||||||
|
node.type.name === 'paragraph' &&
|
||||||
|
node.attrs['data-suggestion'] &&
|
||||||
|
view.state.selection.$head.pos !== view.state.selection.$head.end()
|
||||||
|
) {
|
||||||
|
dispatch(
|
||||||
|
state.tr.setNodeMarkup($head.before(), null, {
|
||||||
|
...node.attrs,
|
||||||
|
class: null,
|
||||||
|
'data-prompt': null,
|
||||||
|
'data-suggestion': null
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user