修复windows换行符

This commit is contained in:
hanhh 2021-07-26 22:57:59 +08:00
parent da70b0799a
commit 105c0f802f
3 changed files with 52 additions and 41 deletions

View File

@ -3,7 +3,7 @@ import { Button, message, Modal, TreeSelect } from 'antd';
import config from '@/utils/config'; import config from '@/utils/config';
import { PageContainer } from '@ant-design/pro-layout'; import { PageContainer } from '@ant-design/pro-layout';
import { request } from '@/utils/http'; import { request } from '@/utils/http';
import Editor from "@monaco-editor/react"; import Editor from '@monaco-editor/react';
const Config = () => { const Config = () => {
const [width, setWidth] = useState('100%'); const [width, setWidth] = useState('100%');
@ -65,18 +65,19 @@ const Config = () => {
useEffect(() => { useEffect(() => {
const media = window.matchMedia('(prefers-color-scheme: dark)'); const media = window.matchMedia('(prefers-color-scheme: dark)');
const storageTheme = localStorage.getItem('qinglong_dark_theme'); const storageTheme = localStorage.getItem('qinglong_dark_theme');
const isDark = (media.matches && storageTheme !== 'light') || storageTheme === 'dark'; const isDark =
(media.matches && storageTheme !== 'light') || storageTheme === 'dark';
setTheme(isDark ? 'vs-dark' : 'vs'); setTheme(isDark ? 'vs-dark' : 'vs');
media.addEventListener('change', (e) => { media.addEventListener('change', (e) => {
if (storageTheme === 'auto' || !storageTheme) { if (storageTheme === 'auto' || !storageTheme) {
if (e.matches) { if (e.matches) {
setTheme('vs-dark') setTheme('vs-dark');
} else { } else {
setTheme('vs'); setTheme('vs');
} }
} }
}) });
},[]) }, []);
return ( return (
<PageContainer <PageContainer
@ -119,9 +120,11 @@ const Config = () => {
minimap: { enabled: width === '100%' }, minimap: { enabled: width === '100%' },
lineNumbersMinChars: 3, lineNumbersMinChars: 3,
folding: false, folding: false,
glyphMargin: false glyphMargin: false,
}}
onChange={(val) => {
setValue((val as string).replace(/\r\n/g, '\n'));
}} }}
onChange={(val) => {setValue(val as string)}}
/> />
</PageContainer> </PageContainer>
); );

View File

@ -2,7 +2,7 @@ import { useState, useEffect, useCallback, Key, useRef } from 'react';
import { TreeSelect, Tree, Input } from 'antd'; import { TreeSelect, Tree, Input } from 'antd';
import config from '@/utils/config'; import config from '@/utils/config';
import { PageContainer } from '@ant-design/pro-layout'; import { PageContainer } from '@ant-design/pro-layout';
import Editor from "@monaco-editor/react"; import Editor from '@monaco-editor/react';
import { request } from '@/utils/http'; import { request } from '@/utils/http';
import styles from './index.module.less'; import styles from './index.module.less';
@ -123,18 +123,19 @@ const Log = () => {
useEffect(() => { useEffect(() => {
const media = window.matchMedia('(prefers-color-scheme: dark)'); const media = window.matchMedia('(prefers-color-scheme: dark)');
const storageTheme = localStorage.getItem('qinglong_dark_theme'); const storageTheme = localStorage.getItem('qinglong_dark_theme');
const isDark = (media.matches && storageTheme !== 'light') || storageTheme === 'dark'; const isDark =
(media.matches && storageTheme !== 'light') || storageTheme === 'dark';
setTheme(isDark ? 'vs-dark' : 'vs'); setTheme(isDark ? 'vs-dark' : 'vs');
media.addEventListener('change', (e) => { media.addEventListener('change', (e) => {
if (storageTheme === 'auto' || !storageTheme) { if (storageTheme === 'auto' || !storageTheme) {
if (e.matches) { if (e.matches) {
setTheme('vs-dark') setTheme('vs-dark');
} else { } else {
setTheme('vs'); setTheme('vs');
} }
} }
}) });
},[]) }, []);
return ( return (
<PageContainer <PageContainer
@ -199,9 +200,11 @@ const Log = () => {
fontFamily: 'Source Code Pro', fontFamily: 'Source Code Pro',
folding: false, folding: false,
glyphMargin: false, glyphMargin: false,
wordWrap: 'on' wordWrap: 'on',
}}
onChange={(val, ev) => {
setValue((val as string).replace(/\r\n/g, '\n'));
}} }}
onChange={(val, ev) => {setValue(val as string)}}
/> />
</div> </div>
</PageContainer> </PageContainer>

View File

@ -2,7 +2,7 @@ import { useState, useEffect, useCallback, Key, useRef } from 'react';
import { TreeSelect, Tree, Input } from 'antd'; import { TreeSelect, Tree, Input } from 'antd';
import config from '@/utils/config'; import config from '@/utils/config';
import { PageContainer } from '@ant-design/pro-layout'; import { PageContainer } from '@ant-design/pro-layout';
import Editor from "@monaco-editor/react"; import Editor from '@monaco-editor/react';
import { request } from '@/utils/http'; import { request } from '@/utils/http';
import styles from './index.module.less'; import styles from './index.module.less';
@ -23,6 +23,7 @@ const LangMap: any = {
'.py': 'python', '.py': 'python',
'.js': 'javascript', '.js': 'javascript',
'.sh': 'shell', '.sh': 'shell',
'.ts': 'typescript',
}; };
const Script = () => { const Script = () => {
@ -98,18 +99,19 @@ const Script = () => {
useEffect(() => { useEffect(() => {
const media = window.matchMedia('(prefers-color-scheme: dark)'); const media = window.matchMedia('(prefers-color-scheme: dark)');
const storageTheme = localStorage.getItem('qinglong_dark_theme'); const storageTheme = localStorage.getItem('qinglong_dark_theme');
const isDark = (media.matches && storageTheme !== 'light') || storageTheme === 'dark'; const isDark =
(media.matches && storageTheme !== 'light') || storageTheme === 'dark';
setTheme(isDark ? 'vs-dark' : 'vs'); setTheme(isDark ? 'vs-dark' : 'vs');
media.addEventListener('change', (e) => { media.addEventListener('change', (e) => {
if (storageTheme === 'auto' || !storageTheme) { if (storageTheme === 'auto' || !storageTheme) {
if (e.matches) { if (e.matches) {
setTheme('vs-dark') setTheme('vs-dark');
} else { } else {
setTheme('vs'); setTheme('vs');
} }
} }
}) });
},[]) }, []);
return ( return (
<PageContainer <PageContainer
@ -173,8 +175,11 @@ const Script = () => {
lineNumbersMinChars: 3, lineNumbersMinChars: 3,
folding: false, folding: false,
glyphMargin: false, glyphMargin: false,
default
}}
onChange={(val) => {
setValue((val as string).replace(/\r\n/g, '\n'));
}} }}
onChange={(val) => {setValue(val as string)}}
/> />
</div> </div>
</PageContainer> </PageContainer>