add option to set custom css;

This commit is contained in:
Carl Chang 2022-05-18 01:08:14 +08:00
parent 7c9b0ec129
commit ff169d77ac
6 changed files with 35 additions and 2 deletions

View File

@ -324,6 +324,11 @@
2 2
] ]
}, },
"customCss": {
"description": "Custom CSS--Custom CSS to apply to the current theme.",
"type": "string",
"default": ""
},
"spellcheckerEnabled": { "spellcheckerEnabled": {
"description": "Spelling--Whether spell checking is enabled.", "description": "Spelling--Whether spell checking is enabled.",
"type": "boolean", "type": "boolean",

View File

@ -37,7 +37,7 @@
</template> </template>
<script> <script>
import { addStyles, addThemeStyle } from '@/util/theme' import { addStyles, addThemeStyle, addCustomStyle } from '@/util/theme'
import Recent from '@/components/recent' import Recent from '@/components/recent'
import EditorWithTabs from '@/components/editorWithTabs' import EditorWithTabs from '@/components/editorWithTabs'
import TitleBar from '@/components/titleBar' import TitleBar from '@/components/titleBar'
@ -78,6 +78,7 @@ export default {
showTabBar: state => state.layout.showTabBar, showTabBar: state => state.layout.showTabBar,
sourceCode: state => state.preferences.sourceCode, sourceCode: state => state.preferences.sourceCode,
theme: state => state.preferences.theme, theme: state => state.preferences.theme,
customCss: state => state.preferences.customCss,
textDirection: state => state.preferences.textDirection textDirection: state => state.preferences.textDirection
}), }),
...mapState({ ...mapState({
@ -105,6 +106,13 @@ export default {
addThemeStyle(value) addThemeStyle(value)
} }
}, },
customCss: function (value, oldValue) {
if (value !== oldValue) {
addCustomStyle({
customCss: value
})
}
},
zoom: function (zoom) { zoom: function (zoom) {
ipcRenderer.emit('mt::window-zoom', null, zoom) ipcRenderer.emit('mt::window-zoom', null, zoom)
} }

View File

@ -16,6 +16,10 @@
:options="autoSwitchThemeOptions" :options="autoSwitchThemeOptions"
:onChange="value => onSelectChange('autoSwitchTheme', value)" :onChange="value => onSelectChange('autoSwitchTheme', value)"
></cur-select> ></cur-select>
<div>
<div style="font-size: smaller; color: var(--editorColor)">Custom CSS</div>
<textarea style="width: 100%" rows="10" :value="customCss" @change="event => onSelectChange('customCss', event.target.value)"></textarea>
</div>
<separator v-show="false"></separator> <separator v-show="false"></separator>
<section v-show="false" class="import-themes ag-underdevelop"> <section v-show="false" class="import-themes ag-underdevelop">
<div> <div>
@ -53,7 +57,8 @@ export default {
computed: { computed: {
...mapState({ ...mapState({
autoSwitchTheme: state => state.preferences.autoSwitchTheme, autoSwitchTheme: state => state.preferences.autoSwitchTheme,
theme: state => state.preferences.theme theme: state => state.preferences.theme,
customCss: state => state.preferences.customCss
}) })
}, },
created () { created () {

View File

@ -55,6 +55,7 @@ const state = {
theme: 'light', theme: 'light',
autoSwitchTheme: 2, autoSwitchTheme: 2,
customCss: '',
spellcheckerEnabled: false, spellcheckerEnabled: false,
spellcheckerIsHunspell: false, // macOS/Windows 10 only spellcheckerIsHunspell: false, // macOS/Windows 10 only

View File

@ -150,6 +150,19 @@ ${getEmojiPickerPatch()}
` `
} }
export const addCustomStyle = options => {
const { customCss } = options
if (!customCss) return
let customStyleEle = document.querySelector('#custom-styles')
if (!customStyleEle) {
customStyleEle = document.createElement('style')
customStyleEle.id = 'custom-styles'
document.head.appendChild(customStyleEle)
}
customStyleEle.innerHTML = customCss
}
export const addElementStyle = () => { export const addElementStyle = () => {
const ID = 'mt-el-style' const ID = 'mt-el-style'
let sheet = document.querySelector(`#${ID}`) let sheet = document.querySelector(`#${ID}`)

View File

@ -51,6 +51,7 @@
"theme": "light", "theme": "light",
"autoSwitchTheme": 2, "autoSwitchTheme": 2,
"customCss": "",
"spellcheckerEnabled": false, "spellcheckerEnabled": false,
"spellcheckerIsHunspell": false, "spellcheckerIsHunspell": false,