Disabled Codemirror searchKeymap in Admin X (#19423)
refs https://linear.app/tryghost/issue/PROD-287/cmdf-in-code-injection - wired in the default basicSetup and then explicitly disable the search keymap to avoid cmd+f triggering the codemirror search and instead brings up the default browser finder.
This commit is contained in:
parent
9e2558931f
commit
d06a1a4e5b
@ -1,5 +1,5 @@
|
||||
import {Extension} from '@codemirror/state';
|
||||
import CodeMirror, {ReactCodeMirrorProps, ReactCodeMirrorRef} from '@uiw/react-codemirror';
|
||||
import CodeMirror, {ReactCodeMirrorProps, ReactCodeMirrorRef, BasicSetupOptions} from '@uiw/react-codemirror';
|
||||
import clsx from 'clsx';
|
||||
import React, {FocusEventHandler, forwardRef, useEffect, useId, useRef, useState} from 'react';
|
||||
import {useFocusContext} from '../../providers/DesignSystemProvider';
|
||||
@ -49,6 +49,9 @@ const CodeEditorView = forwardRef<ReactCodeMirrorRef, CodeEditorProps>(function
|
||||
const sizeRef = useRef<HTMLDivElement>(null);
|
||||
const [width, setWidth] = useState(100);
|
||||
const [resolvedExtensions, setResolvedExtensions] = React.useState<Extension[] | null>(null);
|
||||
const [basicSetup, setBasicSetup] = useState<BasicSetupOptions>({
|
||||
crosshairCursor: false
|
||||
});
|
||||
const {setFocusState} = useFocusContext();
|
||||
|
||||
const handleFocus: FocusEventHandler<HTMLDivElement> = (e) => {
|
||||
@ -63,6 +66,7 @@ const CodeEditorView = forwardRef<ReactCodeMirrorRef, CodeEditorProps>(function
|
||||
|
||||
useEffect(() => {
|
||||
Promise.all(extensions).then(setResolvedExtensions);
|
||||
setBasicSetup(setup => ({setup, searchKeymap: false}));
|
||||
}, [extensions]);
|
||||
|
||||
useEffect(() => {
|
||||
@ -90,6 +94,7 @@ const CodeEditorView = forwardRef<ReactCodeMirrorRef, CodeEditorProps>(function
|
||||
{resolvedExtensions && <div className={height === 'full' ? 'h-full' : ''} style={{width}}>
|
||||
<CodeMirror
|
||||
ref={ref}
|
||||
basicSetup={basicSetup}
|
||||
className={styles}
|
||||
extensions={resolvedExtensions}
|
||||
height={height === 'full' ? '100%' : height}
|
||||
|
Loading…
Reference in New Issue
Block a user