import { ChangeEvent, FC, memo, useCallback } from 'react' import useScopeValue from '@/shared/hooks/use-scope-value' import OLTooltip from '@/features/ui/components/ol/ol-tooltip' import { sendMB } from '../../../infrastructure/event-tracking' import { isValidTeXFile } from '../../../main/is-valid-tex-file' import { useTranslation } from 'react-i18next' import { useEditorManagerContext } from '@/features/ide-react/context/editor-manager-context' function EditorSwitch() { const { t } = useTranslation() const [visual, setVisual] = useScopeValue('editor.showVisual') const { openDocName } = useEditorManagerContext() const richTextAvailable = openDocName ? isValidTeXFile(openDocName) : false const handleChange = useCallback( (event: ChangeEvent) => { const editorType = event.target.value switch (editorType) { case 'cm6': setVisual(false) break case 'rich-text': setVisual(true) break } sendMB('editor-switch-change', { editorType }) }, [setVisual] ) return (
Editor mode.
) } const RichTextToggle: FC<{ checked: boolean disabled: boolean handleChange: (event: ChangeEvent) => void }> = ({ checked, disabled, handleChange }) => { const { t } = useTranslation() const toggle = ( ) if (disabled) { return ( {toggle} ) } return toggle } export default memo(EditorSwitch)