Merge pull request #383 from toeverything/feat/editing-experience

Feat/editing experience
This commit is contained in:
Yifeng Wang 2022-09-07 23:02:18 +08:00 committed by GitHub
commit b90ce50c0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -99,7 +99,7 @@ const langs: Record<string, any> = {
dockerfile: () => StreamLanguage.define(dockerFile),
r: () => StreamLanguage.define(r),
};
const DEFAULT_LANG = 'javascript';
const DEFAULT_LANG = 'markdown';
const CodeBlock = styled('div')(({ theme }) => ({
backgroundColor: '#F2F5F9',
padding: '8px 24px',
@ -142,10 +142,13 @@ export const CodeView = ({ block, editor }: CreateCodeView) => {
const langType: string = block.getProperty('lang');
const [extensions, setExtensions] = useState<Extension[]>();
const codeMirror = useRef<ReactCodeMirrorRef>();
useOnSelect(block.id, (_is_select: boolean) => {
const focusCode = () => {
if (codeMirror.current) {
codeMirror?.current?.view?.focus();
}
};
useOnSelect(block.id, (_is_select: boolean) => {
focusCode();
});
const onChange = (value: string) => {
block.setProperty('text', {
@ -158,6 +161,9 @@ export const CodeView = ({ block, editor }: CreateCodeView) => {
};
useEffect(() => {
handleLangChange(langType ? langType : DEFAULT_LANG);
setTimeout(() => {
focusCode();
}, 100);
}, []);
const copyCode = () => {