From d06a1a4e5b6bf069b946c8e3aae08fe3a5418b63 Mon Sep 17 00:00:00 2001 From: Ronald Langeveld Date: Tue, 2 Jan 2024 19:34:30 +0200 Subject: [PATCH] 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. --- .../src/global/form/CodeEditorView.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/admin-x-design-system/src/global/form/CodeEditorView.tsx b/apps/admin-x-design-system/src/global/form/CodeEditorView.tsx index 207b71bd39..c61bd98c03 100644 --- a/apps/admin-x-design-system/src/global/form/CodeEditorView.tsx +++ b/apps/admin-x-design-system/src/global/form/CodeEditorView.tsx @@ -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(function const sizeRef = useRef(null); const [width, setWidth] = useState(100); const [resolvedExtensions, setResolvedExtensions] = React.useState(null); + const [basicSetup, setBasicSetup] = useState({ + crosshairCursor: false + }); const {setFocusState} = useFocusContext(); const handleFocus: FocusEventHandler = (e) => { @@ -63,6 +66,7 @@ const CodeEditorView = forwardRef(function useEffect(() => { Promise.all(extensions).then(setResolvedExtensions); + setBasicSetup(setup => ({setup, searchKeymap: false})); }, [extensions]); useEffect(() => { @@ -90,6 +94,7 @@ const CodeEditorView = forwardRef(function {resolvedExtensions &&