refac: rich text input paste behaviour
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 J. Baek 2024-10-25 11:51:49 -07:00
parent af3456511b
commit 0b38584e52
2 changed files with 23 additions and 1 deletions

View File

@ -189,7 +189,7 @@ input[type='number'] {
} }
.ProseMirror { .ProseMirror {
@apply h-full min-h-fit max-h-full; @apply h-full min-h-fit max-h-full whitespace-pre-wrap;
} }
.ProseMirror:focus { .ProseMirror:focus {

View File

@ -288,6 +288,12 @@
return false; return false;
} }
// Replace tabs with four spaces
function handleTabIndentation(text: string): string {
// Replace each tab character with four spaces
return text.replace(/\t/g, ' ');
}
onMount(() => { onMount(() => {
const initialDoc = markdownToProseMirrorDoc(value || ''); // Convert the initial content const initialDoc = markdownToProseMirrorDoc(value || ''); // Convert the initial content
@ -403,6 +409,22 @@
}, },
paste: (view, event) => { paste: (view, event) => {
if (event.clipboardData) { if (event.clipboardData) {
// Extract plain text from clipboard and paste it without formatting
const plainText = event.clipboardData.getData('text/plain');
if (plainText) {
const modifiedText = handleTabIndentation(plainText);
console.log(modifiedText);
// Replace the current selection with the plain text content
const tr = view.state.tr.replaceSelectionWith(
view.state.schema.text(modifiedText),
false
);
view.dispatch(tr.scrollIntoView());
event.preventDefault(); // Prevent the default paste behavior
return true;
}
// Check if the pasted content contains image files // Check if the pasted content contains image files
const hasImageFile = Array.from(event.clipboardData.files).some((file) => const hasImageFile = Array.from(event.clipboardData.files).some((file) =>
file.type.startsWith('image/') file.type.startsWith('image/')