Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom CSS Support #3279

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/preferences/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@
2
]
},
"customCss": {
"description": "Custom CSS--Custom CSS to apply to the current theme.",
"type": "string",
"default": ""
},
"spellcheckerEnabled": {
"description": "Spelling--Whether spell checking is enabled.",
"type": "boolean",
Expand Down
4 changes: 4 additions & 0 deletions src/renderer/components/editorWithTabs/tabs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ export default {
closeAll () {
this.$store.dispatch('CLOSE_ALL_TABS')
},
changeMaxWidth (width) {
this.$store.dispatch('CHANGE_SIDE_BAR_WIDTH', width)
},
rename (tabId) {
const tab = this.tabs.find(f => f.id === tabId)
if (tab && tab.pathname) {
Expand Down Expand Up @@ -129,6 +132,7 @@ export default {
bus.$on('TABS::rename', this.rename)
bus.$on('TABS::copy-path', this.copyPath)
bus.$on('TABS::show-in-folder', this.showInFolder)
bus.$on('EDITOR_TABS::change-max-width', this.changeMaxWidth)
})
},
mounted () {
Expand Down
10 changes: 9 additions & 1 deletion src/renderer/pages/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</template>

<script>
import { addStyles, addThemeStyle } from '@/util/theme'
import { addStyles, addThemeStyle, addCustomStyle } from '@/util/theme'
import Recent from '@/components/recent'
import EditorWithTabs from '@/components/editorWithTabs'
import TitleBar from '@/components/titleBar'
Expand Down Expand Up @@ -78,6 +78,7 @@ export default {
showTabBar: state => state.layout.showTabBar,
sourceCode: state => state.preferences.sourceCode,
theme: state => state.preferences.theme,
customCss: state => state.preferences.customCss,
textDirection: state => state.preferences.textDirection
}),
...mapState({
Expand Down Expand Up @@ -105,6 +106,13 @@ export default {
addThemeStyle(value)
}
},
customCss: function (value, oldValue) {
if (value !== oldValue) {
addCustomStyle({
customCss: value
})
}
},
zoom: function (zoom) {
ipcRenderer.emit('mt::window-zoom', null, zoom)
}
Expand Down
7 changes: 6 additions & 1 deletion src/renderer/prefComponents/theme/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
:options="autoSwitchThemeOptions"
:onChange="value => onSelectChange('autoSwitchTheme', value)"
></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>
<section v-show="false" class="import-themes ag-underdevelop">
<div>
Expand Down Expand Up @@ -53,7 +57,8 @@ export default {
computed: {
...mapState({
autoSwitchTheme: state => state.preferences.autoSwitchTheme,
theme: state => state.preferences.theme
theme: state => state.preferences.theme,
customCss: state => state.preferences.customCss
})
},
created () {
Expand Down
1 change: 1 addition & 0 deletions src/renderer/store/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const state = {

theme: 'light',
autoSwitchTheme: 2,
customCss: '',

spellcheckerEnabled: false,
spellcheckerIsHunspell: false, // macOS/Windows 10 only
Expand Down
13 changes: 13 additions & 0 deletions src/renderer/util/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
const ID = 'mt-el-style'
let sheet = document.querySelector(`#${ID}`)
Expand Down
1 change: 1 addition & 0 deletions static/preference.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@

"theme": "light",
"autoSwitchTheme": 2,
"customCss": "",

"spellcheckerEnabled": false,
"spellcheckerIsHunspell": false,
Expand Down