|
@@ -66,25 +66,27 @@ export const AIAutocompletion = Extension.create({
|
|
const node = $head.parent
|
|
const node = $head.parent
|
|
|
|
|
|
if (event.key === 'Tab') {
|
|
if (event.key === 'Tab') {
|
|
- if (!node.attrs['data-suggestion']) {
|
|
|
|
- // Generate completion
|
|
|
|
- if (loading) return true
|
|
|
|
- loading = true
|
|
|
|
- const prompt = node.textContent
|
|
|
|
- this.options.generateCompletion(prompt).then(suggestion => {
|
|
|
|
- if (suggestion && suggestion.trim() !== '') {
|
|
|
|
- dispatch(state.tr.setNodeMarkup($head.before(), null, {
|
|
|
|
- ...node.attrs,
|
|
|
|
- class: 'ai-autocompletion',
|
|
|
|
- 'data-prompt': prompt,
|
|
|
|
- 'data-suggestion': suggestion,
|
|
|
|
- }))
|
|
|
|
- }
|
|
|
|
- // If suggestion is empty or null, do nothing
|
|
|
|
- }).finally(() => {
|
|
|
|
- loading = false
|
|
|
|
- })
|
|
|
|
- } else {
|
|
|
|
|
|
+ // if (!node.attrs['data-suggestion']) {
|
|
|
|
+ // // Generate completion
|
|
|
|
+ // if (loading) return true
|
|
|
|
+ // loading = true
|
|
|
|
+ // const prompt = node.textContent
|
|
|
|
+ // this.options.generateCompletion(prompt).then(suggestion => {
|
|
|
|
+ // if (suggestion && suggestion.trim() !== '') {
|
|
|
|
+ // dispatch(state.tr.setNodeMarkup($head.before(), null, {
|
|
|
|
+ // ...node.attrs,
|
|
|
|
+ // class: 'ai-autocompletion',
|
|
|
|
+ // 'data-prompt': prompt,
|
|
|
|
+ // 'data-suggestion': suggestion,
|
|
|
|
+ // }))
|
|
|
|
+ // }
|
|
|
|
+ // // If suggestion is empty or null, do nothing
|
|
|
|
+ // }).finally(() => {
|
|
|
|
+ // loading = false
|
|
|
|
+ // })
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+ if (node.attrs['data-suggestion']) {
|
|
// Accept suggestion
|
|
// Accept suggestion
|
|
const suggestion = node.attrs['data-suggestion']
|
|
const suggestion = node.attrs['data-suggestion']
|
|
dispatch(state.tr
|
|
dispatch(state.tr
|
|
@@ -96,8 +98,8 @@ export const AIAutocompletion = Extension.create({
|
|
'data-suggestion': null,
|
|
'data-suggestion': null,
|
|
})
|
|
})
|
|
)
|
|
)
|
|
|
|
+ return true
|
|
}
|
|
}
|
|
- return true
|
|
|
|
} else {
|
|
} else {
|
|
|
|
|
|
if (node.attrs['data-suggestion']) {
|
|
if (node.attrs['data-suggestion']) {
|