+
@@ -11,7 +11,8 @@
export default {
props: {
markdown: String,
- cursor: Object
+ cursor: Object,
+ theme: String
},
data () {
return {
@@ -19,14 +20,28 @@
editor: null
}
},
+ watch: {
+ theme: function (value, oldValue) {
+ const cm = this.$refs.sourceCode.querySelector('.CodeMirror')
+ if (value !== oldValue) {
+ if (value === 'dark') {
+ cm.classList.remove('cm-s-default')
+ cm.classList.add('cm-s-railscasts')
+ } else {
+ cm.classList.add('cm-s-default')
+ cm.classList.remove('cm-s-railscasts')
+ }
+ }
+ }
+ },
created () {
this.$nextTick(() => {
- const { markdown = '' } = this
+ const { markdown = '', theme } = this
this.contentState = new ContentState()
const container = this.$refs.sourceCode
- const editor = this.editor = codeMirror(container, {
+ const codeMirrorConfig = {
// theme: 'railscasts',
- value: markdown,
+ value: '',
lineNumbers: true,
autofocus: true,
lineWrapping: true,
@@ -38,9 +53,22 @@
return ''
}
}
- })
+ }
+ if (theme === 'dark') codeMirrorConfig.theme = 'railscasts'
+ this.editor = codeMirror(container, codeMirrorConfig)
bus.$on('file-loaded', this.setMarkdown)
+ this.listenChange()
+
+ this.setMarkdown(markdown)
+ })
+ },
+ beforeDestory () {
+ bus.$off('file-loaded', this.setMarkdown)
+ },
+ methods: {
+ listenChange () {
+ const { editor } = this
editor.on('cursorActivity', (cm, event) => {
const cursor = cm.getCursor()
const markdown = cm.getValue()
@@ -51,13 +79,7 @@
})
setMode(editor, 'markdown')
- this.setMarkdown(markdown)
- })
- },
- beforeDestory () {
- bus.$off('file-loaded', this.setMarkdown)
- },
- methods: {
+ },
setMarkdown (markdown) {
const { editor, cursor } = this
this.editor.setValue(markdown)
@@ -89,4 +111,11 @@
.source-code .CodeMirror-activeline-gutter {
background: #F2F6FC;
}
+ .dark {
+ background: rgb(43, 43, 43);
+ }
+ .dark.source-code .CodeMirror-activeline-background,
+ .dark.source-code .CodeMirror-activeline-gutter {
+ background: #333;
+ }
diff --git a/src/renderer/components/titleBar.vue b/src/renderer/components/titleBar.vue
index 8499536d..2865a872 100644
--- a/src/renderer/components/titleBar.vue
+++ b/src/renderer/components/titleBar.vue
@@ -1,6 +1,6 @@
@@ -37,7 +37,8 @@
filename: String,
pathname: String,
active: Boolean,
- wordCount: Object
+ wordCount: Object,
+ theme: String
},
computed: {
paths () {
@@ -122,4 +123,16 @@
background: #F2F6FC;
color: #606266;
}
+ /* css for dark theme */
+ .dark {
+ background: rgb(43, 43, 43);
+ color: #909399;
+ }
+ .dark .title:hover {
+ color: #F2F6FC;
+ }
+ .dark .word-count:hover {
+ background: rgb(71, 72, 66);
+ color: #C0C4CC;
+ }
diff --git a/src/renderer/store/editor.js b/src/renderer/store/editor.js
index 555fcd4f..9707f319 100644
--- a/src/renderer/store/editor.js
+++ b/src/renderer/store/editor.js
@@ -9,6 +9,8 @@ const state = {
matches: [],
value: ''
},
+ theme: '',
+ themeCSS: null,
typewriter: false, // typewriter mode
focus: false, // focus mode
sourceCode: false, // source code mode
@@ -26,6 +28,12 @@ const state = {
}
const mutations = {
+ SET_THEME (state, { theme, themeCSS }) {
+ state.theme = theme
+ if (themeCSS) {
+ state.themeCSS = themeCSS
+ }
+ },
SET_MODE (state, { type, checked }) {
state[type] = checked
},
@@ -57,6 +65,13 @@ const mutations = {
}
const actions = {
+ ASK_FOR_THEME ({ commit }) {
+ ipcRenderer.send('AGANI::ask-for-theme')
+ ipcRenderer.on('AGANI::theme', (e, themes) => {
+ console.log(themes)
+ commit('SET_THEME', themes)
+ })
+ },
SEARCH ({ commit }, value) {
commit('SET_SEARCH', value)
},