refactor: use CodeEditor for customizing css (#6877)

* refactor: use CodeEditor for customizing css

* fix: editor height
This commit is contained in:
one 2025-06-09 19:56:57 +08:00 committed by GitHub
parent b951d89c6a
commit d9c20c8815
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 9 deletions

View File

@ -26,6 +26,7 @@ interface Props {
onSave?: (newContent: string) => void onSave?: (newContent: string) => void
onChange?: (newContent: string) => void onChange?: (newContent: string) => void
setTools?: (value: React.SetStateAction<CodeTool[]>) => void setTools?: (value: React.SetStateAction<CodeTool[]>) => void
height?: string
minHeight?: string minHeight?: string
maxHeight?: string maxHeight?: string
/** 用于覆写编辑器的某些设置 */ /** 用于覆写编辑器的某些设置 */
@ -54,6 +55,7 @@ const CodeEditor = ({
onSave, onSave,
onChange, onChange,
setTools, setTools,
height,
minHeight, minHeight,
maxHeight, maxHeight,
options, options,
@ -193,6 +195,7 @@ const CodeEditor = ({
value={initialContent.current} value={initialContent.current}
placeholder={placeholder} placeholder={placeholder}
width="100%" width="100%"
height={height}
minHeight={minHeight} minHeight={minHeight}
maxHeight={collapsible && !isExpanded ? (maxHeight ?? '350px') : 'none'} maxHeight={collapsible && !isExpanded ? (maxHeight ?? '350px') : 'none'}
editable={true} editable={true}

View File

@ -1,4 +1,5 @@
import { SyncOutlined } from '@ant-design/icons' import { SyncOutlined } from '@ant-design/icons'
import CodeEditor from '@renderer/components/CodeEditor'
import { HStack } from '@renderer/components/Layout' import { HStack } from '@renderer/components/Layout'
import { isMac, THEME_COLOR_PRESETS } from '@renderer/config/constant' import { isMac, THEME_COLOR_PRESETS } from '@renderer/config/constant'
import { useTheme } from '@renderer/context/ThemeProvider' import { useTheme } from '@renderer/context/ThemeProvider'
@ -16,7 +17,7 @@ import {
setSidebarIcons setSidebarIcons
} from '@renderer/store/settings' } from '@renderer/store/settings'
import { ThemeMode } from '@renderer/types' import { ThemeMode } from '@renderer/types'
import { Button, ColorPicker, Input, Segmented, Switch } from 'antd' import { Button, ColorPicker, Segmented, Switch } from 'antd'
import { Minus, Plus, RotateCcw } from 'lucide-react' import { Minus, Plus, RotateCcw } from 'lucide-react'
import { FC, useCallback, useEffect, useMemo, useState } from 'react' import { FC, useCallback, useEffect, useMemo, useState } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
@ -307,17 +308,24 @@ const DisplaySettings: FC = () => {
</TitleExtra> </TitleExtra>
</SettingTitle> </SettingTitle>
<SettingDivider /> <SettingDivider />
<Input.TextArea <CodeEditor
value={customCss} value={customCss}
onChange={(e) => { language="css"
dispatch(setCustomCss(e.target.value))
}}
placeholder={t('settings.display.custom.css.placeholder')} placeholder={t('settings.display.custom.css.placeholder')}
style={{ onChange={(value) => dispatch(setCustomCss(value))}
minHeight: 200, height="350px"
fontFamily: 'monospace' options={{
collapsible: true,
wrappable: true,
autocompletion: true,
lineNumbers: true,
foldGutter: true,
keymap: true
}}
style={{
outline: '0.5px solid var(--color-border)',
borderRadius: '5px'
}} }}
spellCheck={false}
/> />
</SettingGroup> </SettingGroup>
</SettingContainer> </SettingContainer>