Fix editor stale callbacks and recent item deletion

This commit is contained in:
Gregory Schier
2023-10-30 07:06:21 -07:00
parent 51949f4fbf
commit 8b5d7ae3ed
9 changed files with 45 additions and 20 deletions

View File

@@ -102,14 +102,17 @@ export const Input = forwardRef<EditorView | undefined, InputProps>(function Inp
const wrapperRef = useRef<HTMLDivElement>(null);
// Submit nearest form on Enter key press
const handleKeyDown = useCallback((e: KeyboardEvent) => {
if (e.key !== 'Enter') return;
const handleKeyDown = useCallback(
(e: KeyboardEvent) => {
if (e.key !== 'Enter') return;
const form = wrapperRef.current?.closest('form');
if (!isValid || form == null) return;
const form = wrapperRef.current?.closest('form');
if (!isValid || form == null) return;
form?.dispatchEvent(new Event('submit', { cancelable: true, bubbles: true }));
}, [isValid]);
form?.dispatchEvent(new Event('submit', { cancelable: true, bubbles: true }));
},
[isValid],
);
return (
<VStack ref={wrapperRef} className="w-full">