Remove broken key/value enter/backspace logic

This commit is contained in:
Gregory Schier
2023-10-29 10:45:05 -07:00
parent 705e30b6e0
commit 9e2803fcfb
3 changed files with 29 additions and 69 deletions

View File

@@ -36,7 +36,6 @@ export interface EditorProps {
onChange?: (value: string) => void;
onFocus?: () => void;
onBlur?: () => void;
onEnter?: () => void;
onKeyDown?: (e: KeyboardEvent) => void;
singleLine?: boolean;
wrapLines?: boolean;
@@ -62,7 +61,6 @@ const _Editor = forwardRef<EditorView | undefined, EditorProps>(function Editor(
onFocus,
onBlur,
onKeyDown,
onEnter,
className,
singleLine,
format,
@@ -85,12 +83,6 @@ const _Editor = forwardRef<EditorView | undefined, EditorProps>(function Editor(
handleChange.current = onChange;
}, [onChange]);
// Use ref so we can update the onChange handler without re-initializing the editor
const handleEnter = useRef<EditorProps['onEnter']>(onEnter);
useEffect(() => {
handleEnter.current = onEnter;
}, [onEnter]);
// Use ref so we can update the onChange handler without re-initializing the editor
const handleFocus = useRef<EditorProps['onFocus']>(onFocus);
useEffect(() => {
@@ -172,7 +164,6 @@ const _Editor = forwardRef<EditorView | undefined, EditorProps>(function Editor(
container,
readOnly,
singleLine,
onEnter: handleEnter,
onChange: handleChange,
onFocus: handleFocus,
onBlur: handleBlur,
@@ -252,13 +243,11 @@ function getExtensions({
onFocus,
onBlur,
onKeyDown,
onEnter,
}: Pick<EditorProps, 'singleLine' | 'readOnly'> & {
container: HTMLDivElement | null;
onChange: MutableRefObject<EditorProps['onChange']>;
onFocus: MutableRefObject<EditorProps['onFocus']>;
onBlur: MutableRefObject<EditorProps['onBlur']>;
onEnter: MutableRefObject<EditorProps['onEnter']>;
onKeyDown: MutableRefObject<EditorProps['onKeyDown']>;
}) {
// TODO: Ensure tooltips render inside the dialog if we are in one.
@@ -276,18 +265,6 @@ function getExtensions({
...(readOnly
? [EditorState.readOnly.of(true), EditorView.contentAttributes.of({ tabindex: '-1' })]
: []),
...(singleLine
? [
EditorView.domEventHandlers({
keydown: (e) => {
// Submit nearest form on enter if there is one
if (onEnter != null && e.key === 'Enter') {
onEnter.current?.();
}
},
}),
]
: []),
// Handle onFocus
EditorView.domEventHandlers({