From 27f1357fc0cb8f9a5c807d95d53c35b50556d10f Mon Sep 17 00:00:00 2001 From: litruv Date: Thu, 23 Jul 2026 14:57:57 +1000 Subject: [PATCH] Remove editor beforeinput autocorrect workaround. --- src/app/components/editor/Editor.tsx | 47 +--------------------------- 1 file changed, 1 insertion(+), 46 deletions(-) diff --git a/src/app/components/editor/Editor.tsx b/src/app/components/editor/Editor.tsx index 9ef0595..a29cd9b 100644 --- a/src/app/components/editor/Editor.tsx +++ b/src/app/components/editor/Editor.tsx @@ -6,11 +6,9 @@ import React, { forwardRef, useCallback, useState, - useEffect, - useRef, } from 'react'; import { Box, Scroll, Text } from 'folds'; -import { Descendant, Editor, createEditor, Transforms, Range, Element as SlateElement, Text as SlateText, Point } from 'slate'; +import { Descendant, Editor, createEditor, Element as SlateElement, Text as SlateText } from 'slate'; import { Slate, Editable, @@ -172,48 +170,6 @@ export const CustomEditor = forwardRef( [editor, onKeyDown] ); - const handleBeforeInput = useCallback( - (event: Event) => { - const inputEvent = event as InputEvent; - - // Handle autocorrect replacement that causes text duplication - if (inputEvent.inputType === 'insertReplacementText' || - inputEvent.inputType === 'insertFromComposition') { - const { selection } = editor; - if (!selection) return; - - // Get the data being inserted - const data = inputEvent.data || inputEvent.dataTransfer?.getData('text/plain'); - - if (data) { - event.preventDefault(); - - // If there's selected text, delete it first - if (selection && !Range.isCollapsed(selection)) { - Transforms.delete(editor, { at: selection }); - } - - // Insert the replacement text - editor.insertText(data); - } - } - }, - [editor] - ); - - const editableRef = useRef(null); - - useEffect(() => { - const editableElement = editableRef.current?.querySelector('[data-slate-editor="true"]'); - if (!editableElement) return; - - editableElement.addEventListener('beforeinput', handleBeforeInput, { capture: true }); - - return () => { - editableElement.removeEventListener('beforeinput', handleBeforeInput, { capture: true }); - }; - }, [handleBeforeInput]); - const renderPlaceholder = useCallback( ({ attributes, children }: RenderPlaceholderProps) => ( @@ -259,7 +215,6 @@ export const CustomEditor = forwardRef( size="0" visibility="Hover" hideTrack - ref={editableRef} >