mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
enh: swipe to accept completion
This commit is contained in:
parent
684a7f0455
commit
3792051604
@ -49,6 +49,9 @@ export const AIAutocompletion = Extension.create({
|
|||||||
let debounceTimer = null;
|
let debounceTimer = null;
|
||||||
let loading = false;
|
let loading = false;
|
||||||
|
|
||||||
|
let touchStartX = 0;
|
||||||
|
let touchStartY = 0;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
new Plugin({
|
new Plugin({
|
||||||
key: new PluginKey('aiAutocompletion'),
|
key: new PluginKey('aiAutocompletion'),
|
||||||
@ -144,6 +147,43 @@ export const AIAutocompletion = Extension.create({
|
|||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
|
handleDOMEvents: {
|
||||||
|
touchstart: (view, event) => {
|
||||||
|
touchStartX = event.touches[0].clientX;
|
||||||
|
touchStartY = event.touches[0].clientY;
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
touchend: (view, event) => {
|
||||||
|
const touchEndX = event.changedTouches[0].clientX;
|
||||||
|
const touchEndY = event.changedTouches[0].clientY;
|
||||||
|
|
||||||
|
const deltaX = touchEndX - touchStartX;
|
||||||
|
const deltaY = touchEndY - touchStartY;
|
||||||
|
|
||||||
|
// Check if the swipe was primarily horizontal and to the right
|
||||||
|
if (Math.abs(deltaX) > Math.abs(deltaY) && deltaX > 50) {
|
||||||
|
const { state, dispatch } = view;
|
||||||
|
const { selection } = state;
|
||||||
|
const { $head } = selection;
|
||||||
|
const node = $head.parent;
|
||||||
|
|
||||||
|
if (node.type.name === 'paragraph' && node.attrs['data-suggestion']) {
|
||||||
|
const suggestion = node.attrs['data-suggestion'];
|
||||||
|
dispatch(state.tr
|
||||||
|
.insertText(suggestion, $head.pos)
|
||||||
|
.setNodeMarkup($head.before(), null, {
|
||||||
|
...node.attrs,
|
||||||
|
class: null,
|
||||||
|
'data-prompt': null,
|
||||||
|
'data-suggestion': null,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user