import React, { useEffect, useId, useRef } from 'react' import { __ } from '@wordpress/i18n' import { useSubmitSnippet } from '../../../../hooks/useSubmitSnippet' import { handleUnknownError } from '../../../../utils/errors' import { isMacOS } from '../../../../utils/screen' import { useSnippetForm } from '../WithSnippetFormContext' import { Button } from '../../../common/Button' import { ExpandIcon } from '../../../common/icons/ExpandIcon' import { MinimiseIcon } from '../../../common/icons/MinimiseIcon' import { CodeEditorShortcuts } from './CodeEditorShortcuts' import type { Dispatch, RefObject, SetStateAction } from 'react' interface EditorTextareaProps { textareaRef: RefObject } const useFocusEditorShortcut = ( textareaRef: RefObject ) => { const { codeEditorInstance } = useSnippetForm() useEffect(() => { const focusEditor = () => { if (codeEditorInstance) { codeEditorInstance.codemirror.focus() return } textareaRef.current?.focus() } window.addEventListener('code_snippets_focus_editor', focusEditor) return () => { window.removeEventListener('code_snippets_focus_editor', focusEditor) } }, [codeEditorInstance, textareaRef]) } const EditorTextarea: React.FC = ({ textareaRef }) => { const descriptionId = useId() const { snippet, setSnippet } = useSnippetForm() return (

{__('In the editing area, the Tab key enters a tab character. To exit the code editor, press the Escape key and then the Tab key.', 'code-snippets')}