enh: swipe to accept completion
Some checks are pending
Deploy to HuggingFace Spaces / check-secret (push) Waiting to run
Deploy to HuggingFace Spaces / deploy (push) Blocked by required conditions
Create and publish Docker images with specific build args / build-main-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-main-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/amd64) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/arm64) (push) Waiting to run
Create and publish Docker images with specific build args / merge-main-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-cuda-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-ollama-images (push) Blocked by required conditions
Python CI / Format Backend (3.11) (push) Waiting to run
Frontend Build / Format & Build Frontend (push) Waiting to run
Frontend Build / Frontend Unit Tests (push) Waiting to run
Integration Test / Run Cypress Integration Tests (push) Waiting to run
Integration Test / Run Migration Tests (push) Waiting to run

This commit is contained in:
Timothy Jaeryang Baek 2024-11-30 01:06:56 -08:00
parent 684a7f0455
commit 3792051604

View File

@ -49,6 +49,9 @@ export const AIAutocompletion = Extension.create({
let debounceTimer = null;
let loading = false;
let touchStartX = 0;
let touchStartY = 0;
return [
new Plugin({
key: new PluginKey('aiAutocompletion'),
@ -144,6 +147,43 @@ export const AIAutocompletion = Extension.create({
}
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;
},
},
},
}),
]