diff --git a/packages/desktop/src/renderer/src/components/editorWithTabs/editor.vue b/packages/desktop/src/renderer/src/components/editorWithTabs/editor.vue index 33ba5ec73c..88434680dd 100644 --- a/packages/desktop/src/renderer/src/components/editorWithTabs/editor.vue +++ b/packages/desktop/src/renderer/src/components/editorWithTabs/editor.vue @@ -2,13 +2,6 @@
+ family ? `${family}, ${defaultFontFamily}` : defaultFontFamily +const resolveCodeFont = (family: string): string => `${family}, ${DEFAULT_CODE_FONT_FAMILY}` const selectionChange = ref(null) const editor = ref(null) const isShowClose = ref(false) @@ -552,13 +548,19 @@ watch(focus, (value) => { watch(fontSize, (value, oldValue) => { if (value !== oldValue && editor.value) { - editor.value.setFont({ fontSize: value }) + editor.value.setOptions({ fontSize: value }) } }) watch(lineHeight, (value, oldValue) => { if (value !== oldValue && editor.value) { - editor.value.setFont({ lineHeight: value }) + editor.value.setOptions({ lineHeight: value }) + } +}) + +watch(editorFontFamily, (value, oldValue) => { + if (value !== oldValue && editor.value) { + editor.value.setOptions({ editorFontFamily: resolveEditorFont(value) }) } }) @@ -572,7 +574,7 @@ watch(preferLooseListItem, (value, oldValue) => { watch(tabSize, (value, oldValue) => { if (value !== oldValue && editor.value) { - editor.value.setTabSize(value) + editor.value.setOptions({ tabSize: value }) } }) @@ -660,8 +662,8 @@ watch(editorLineWidth, (value, oldValue) => { }) watch(wrapCodeBlocks, (value, oldValue) => { - if (value !== oldValue) { - setWrapCodeBlocks(value) + if (value !== oldValue && editor.value) { + editor.value.setOptions({ wrapCodeBlocks: value }) } }) @@ -714,7 +716,9 @@ watch(autoCheck, (value, oldValue) => { }) watch(codeFontSize, (value, oldValue) => { - if (value !== oldValue) { + if (value !== oldValue && editor.value) { + editor.value.setOptions({ codeFontSize: value }) + // Source-mode CodeMirror is a separate surface muya doesn't own. addCommonStyle({ codeFontSize: value, codeFontFamily: codeFontFamily.value, @@ -730,7 +734,9 @@ watch(codeBlockLineNumbers, (value, oldValue) => { }) watch(codeFontFamily, (value, oldValue) => { - if (value !== oldValue) { + if (value !== oldValue && editor.value) { + editor.value.setOptions({ codeFontFamily: resolveCodeFont(value) }) + // Source-mode CodeMirror is a separate surface muya doesn't own. addCommonStyle({ codeFontSize: codeFontSize.value, codeFontFamily: value, @@ -1695,6 +1701,10 @@ onMounted(() => { tabSize: tabSize.value, fontSize: fontSize.value, lineHeight: lineHeight.value, + editorFontFamily: resolveEditorFont(editorFontFamily.value), + codeFontSize: codeFontSize.value, + codeFontFamily: resolveCodeFont(codeFontFamily.value), + wrapCodeBlocks: wrapCodeBlocks.value, codeBlockLineNumbers: codeBlockLineNumbers.value, listIndentation: listIndentation.value, frontmatterType: frontmatterType.value, @@ -1917,7 +1927,6 @@ onMounted(() => { document.addEventListener('keyup', keyup) - setWrapCodeBlocks(wrapCodeBlocks.value) setEditorWidth(editorLineWidth.value) }) diff --git a/packages/desktop/src/renderer/src/prefComponents/spellchecker/index.vue b/packages/desktop/src/renderer/src/prefComponents/spellchecker/index.vue index 7b35a22ab8..6198e2ff92 100644 --- a/packages/desktop/src/renderer/src/prefComponents/spellchecker/index.vue +++ b/packages/desktop/src/renderer/src/prefComponents/spellchecker/index.vue @@ -223,6 +223,14 @@ const handleDeleteClick = (selectedItem: CustomDictionaryWord): void => { .pref-spellchecker .el-table tr { background: var(--editorBgColor); } +/* Element Plus colours table cells with its own grey --el-text-color-regular, + which the app never themes, so the custom-dictionary words rendered as + low-contrast grey on every theme. Use the theme's editor text colour. */ +.pref-spellchecker .el-table, +.pref-spellchecker .el-table th.el-table__cell, +.pref-spellchecker .el-table td.el-table__cell { + color: var(--editorColor); +} .pref-spellchecker .el-table th.el-table__cell.is-leaf, .pref-spellchecker .el-table th, .pref-spellchecker .el-table td { @@ -240,11 +248,14 @@ const handleDeleteClick = (selectedItem: CustomDictionaryWord): void => { .pref-spellchecker .el-table__fixed::before { background: var(--tableBorderColor); } -.pref-spellchecker .el-table__body tr.hover-row.current-row > td, -.pref-spellchecker .el-table__body tr.hover-row.el-table__row--striped.current-row > td, -.pref-spellchecker .el-table__body tr.hover-row.el-table__row--striped > td, -.pref-spellchecker .el-table__body tr.hover-row > td { - background: var(--selectionColor); +/* Theme Element Plus's table colour variables so the active theme is honoured + instead of EP's light defaults: the hovered row (--el-fill-color-light, a + near-white bar that hides the text) and the header background + (--el-fill-color-blank / white, which left the fixed "Options" column header + a white block on dark themes). */ +.pref-spellchecker .el-table { + --el-table-row-hover-bg-color: var(--selectionColor); + --el-table-header-bg-color: var(--editorBgColor); } .pref-spellchecker .el-table .el-table__cell { padding: 2px 0; diff --git a/packages/desktop/src/renderer/src/util/theme.ts b/packages/desktop/src/renderer/src/util/theme.ts index 00c5d22f96..fdba7d49d3 100644 --- a/packages/desktop/src/renderer/src/util/theme.ts +++ b/packages/desktop/src/renderer/src/util/theme.ts @@ -197,26 +197,6 @@ export const addThemeStyle = (theme: string): void => { } } -export const setWrapCodeBlocks = (value: boolean): void => { - const CODE_WRAP_STYLE_ID = 'ag-code-wrap' - let result = '' - if (value) { - result = - '.mu-code-block .mu-code { display: block; white-space: pre-wrap; word-break: break-word; overflow: hidden; }' - } else { - result = - '.mu-code-block .mu-code { display: block; white-space: pre; word-break: break-word; overflow: auto; }' - } - let styleEle = document.querySelector(`#${CODE_WRAP_STYLE_ID}`) as HTMLStyleElement | null - if (!styleEle) { - styleEle = document.createElement('style') - styleEle.setAttribute('id', CODE_WRAP_STYLE_ID) - document.head.appendChild(styleEle) - } - - styleEle.innerHTML = result -} - export const setEditorWidth = (value: string): void => { const EDITOR_WIDTH_STYLE_ID = 'editor-width' let result = '' @@ -256,13 +236,7 @@ export const addCommonStyle = (options: CommonStyleOptions): void => { } sheet.innerHTML = `${scrollbarStyle} -span code, -td code, -th code, -code, -code[class*="language-"], -.CodeMirror, -.mu-code-block { +.CodeMirror { font-family: ${codeFontFamily}, ${DEFAULT_CODE_FONT_FAMILY}; font-size: ${codeFontSize}px; } diff --git a/packages/desktop/test/e2e/code-block-wrap.spec.ts b/packages/desktop/test/e2e/code-block-wrap.spec.ts index 4a414c12d8..30e7d7b93b 100644 --- a/packages/desktop/test/e2e/code-block-wrap.spec.ts +++ b/packages/desktop/test/e2e/code-block-wrap.spec.ts @@ -5,15 +5,11 @@ import { launchWithMarkdown } from './helpers' // Post-migration (muyajs -> @muyajs/core) coverage backfill for the // "Wrap Code Blocks" and "Code Block Line Numbers" editor preferences. // -// The wrap preference is implemented as an injected