refactor(editor): Update editor theme padding and cursor color

This commit is contained in:
robin
2024-07-17 14:34:09 +08:00
parent a9ee6ca75d
commit 24b6eee8e5
2 changed files with 13 additions and 1 deletions
+7 -1
View File
@@ -26,6 +26,7 @@ import { markdown, markdownLanguage } from '@codemirror/lang-markdown';
import { languages } from '@codemirror/language-data';
import { Editor } from '../types';
import { isDarkTheme } from '@/utils/common';
import createEditorUtils from './extension';
@@ -81,16 +82,18 @@ export const useEditor = ({
const [editor, setEditor] = useState<Editor | null>(null);
const [value, setValue] = useState<string>('');
const init = async () => {
const isDark = isDarkTheme();
const theme = EditorView.theme({
'&': {
height: '100%',
padding: '.375rem .75rem',
},
'&.cm-focused': {
outline: 'none',
},
'.cm-content': {
width: '100%',
padding: '1rem',
},
'.cm-line': {
whiteSpace: 'pre-wrap',
@@ -100,6 +103,9 @@ export const useEditor = ({
'.ͼ7, .ͼ6': {
textDecoration: 'none',
},
'.cm-cursor': {
'border-left-color': isDark ? 'white' : 'black',
},
});
const startState = EditorState.create({
+6
View File
@@ -287,6 +287,11 @@ function changeTheme(mode: 'default' | 'light' | 'dark' | 'system') {
}
}
function isDarkTheme() {
const htmlTag = document.querySelector('html') as HTMLHtmlElement;
return htmlTag.getAttribute('data-bs-theme') === 'dark';
}
export {
thousandthDivision,
formatCount,
@@ -304,4 +309,5 @@ export {
base64ToSvg,
getUaType,
changeTheme,
isDarkTheme,
};