{
const ele = this.$refs.editor
this.editor = new Aganippe(ele)
+ const { container } = this.editor
+ const { markdown } = this
- bus.$on('file-loaded', this.handleFileLoaded)
+ if (markdown.trim()) {
+ this.setMarkdownToEditor(markdown)
+ }
+
+ bus.$on('file-loaded', this.setMarkdownToEditor)
bus.$on('undo', () => this.editor.undo())
bus.$on('redo', () => this.editor.redo())
bus.$on('export', this.handleExport)
@@ -125,8 +133,6 @@
bus.$on('replaceValue', this.handReplace)
bus.$on('find', this.handleFind)
- const { container } = this.editor
-
this.editor.on('change', (markdown, wordCount) => {
this.$store.dispatch('SAVE_FILE', { markdown, wordCount })
})
@@ -210,16 +216,23 @@
this.dialogTableVisible = false
this.editor && this.editor.createTable(this.tableChecker)
},
- handleFileLoaded (file) {
- this.editor && this.editor.setMarkdown(file)
+ setMarkdownToEditor (markdown) {
+ const { cursor } = this
+ this.editor && this.editor.setMarkdown(markdown, cursor)
}
},
beforeDestroy () {
- bus.$off('file-loaded', this.handleFileLoaded)
- bus.$off('export-styled-html', this.handleExport('styledHtml'))
+ bus.$off('file-loaded', this.setMarkdownToEditor)
+ bus.$off('undo', () => this.editor.undo())
+ bus.$off('redo', () => this.editor.redo())
+ bus.$off('export', this.handleExport)
bus.$off('paragraph', this.handleEditParagraph)
+ bus.$off('format', this.handleInlineFormat)
bus.$off('searchValue', this.handleSearch)
+ bus.$off('replaceValue', this.handReplace)
bus.$off('find', this.handleFind)
+
+ // this.editor.destroy()
this.editor = null
}
}
@@ -231,6 +244,12 @@
.editor-wrapper {
height: calc(100vh - 22px);
}
+ .editor-wrapper.source {
+ position: absolute;
+ z-index: -1;
+ left: -10000px;
+ opacity: 0;
+ }
.editor-component {
height: 100%;
overflow: auto;
diff --git a/src/renderer/components/search.vue b/src/renderer/components/search.vue
index e28f4ac1..09885637 100644
--- a/src/renderer/components/search.vue
+++ b/src/renderer/components/search.vue
@@ -136,31 +136,39 @@
}
},
created () {
- bus.$on('find', () => {
+ bus.$on('find', this.listenFind)
+ bus.$on('replace', this.listenReplace)
+ bus.$on('findNext', this.listenFindNext)
+ bus.$on('findPrev', this.listenFindPrev)
+ document.addEventListener('click', this.docClick)
+ document.addEventListener('keyup', this.docKeyup)
+ },
+ beforeDestroy () {
+ bus.$off('find', this.listenFind)
+ bus.$off('replace', this.listenReplace)
+ bus.$off('findNext', this.listenFindNext)
+ bus.$off('findPrev', this.listenFindPrev)
+ document.removeEventListener('click', this.docClick)
+ document.removeEventListener('keyup', this.docKeyup)
+ },
+ methods: {
+ listenFind () {
this.showSearch = true
this.type = 'search'
this.$nextTick(() => {
this.$refs.search.focus()
})
- })
- bus.$on('replace', () => {
+ },
+ listenReplace () {
this.showSearch = true
this.type = 'replace'
- })
- bus.$on('findNext', () => {
+ },
+ listenFindNext () {
this.find('next')
- })
- bus.$on('findPrev', () => {
+ },
+ listenFindPrev () {
this.find('prev')
- })
- document.addEventListener('click', this.docClick)
- document.addEventListener('keyup', this.docKeyup)
- },
- beforeDestroy () {
- document.removeEventListener('click', this.docClick)
- document.removeEventListener('keyup', this.docKeyup)
- },
- methods: {
+ },
docKeyup (event) {
if (event.key === 'Escape') {
this.emitSearch(true)
diff --git a/src/renderer/components/sourceCode.vue b/src/renderer/components/sourceCode.vue
new file mode 100644
index 00000000..087159bf
--- /dev/null
+++ b/src/renderer/components/sourceCode.vue
@@ -0,0 +1,86 @@
+
+
+
+
+
+
+
+
diff --git a/src/renderer/components/titleBar.vue b/src/renderer/components/titleBar.vue
index 410ba2a8..8499536d 100644
--- a/src/renderer/components/titleBar.vue
+++ b/src/renderer/components/titleBar.vue
@@ -34,6 +34,7 @@
}
},
props: {
+ filename: String,
pathname: String,
active: Boolean,
wordCount: Object
@@ -42,10 +43,6 @@
paths () {
const pathnameToken = this.pathname.split('/').filter(i => i)
return pathnameToken.slice(0, pathnameToken.length - 1).slice(-3)
- },
- filename () {
- const pathnameToken = this.pathname.split('/').filter(i => i)
- return pathnameToken.pop()
}
},
methods: {
diff --git a/src/renderer/store/editor.js b/src/renderer/store/editor.js
index 63762197..555fcd4f 100644
--- a/src/renderer/store/editor.js
+++ b/src/renderer/store/editor.js
@@ -12,9 +12,10 @@ const state = {
typewriter: false, // typewriter mode
focus: false, // focus mode
sourceCode: false, // source code mode
- pathname: 'Untitled - unsaved',
+ pathname: '',
isSaved: true,
markdown: '',
+ cursor: null,
windowActive: true,
wordCount: {
paragraph: 0,
@@ -49,6 +50,9 @@ const mutations = {
},
SET_WORD_COUNT (state, wordCount) {
state.wordCount = wordCount
+ },
+ SET_CURSOR (state, cursor) {
+ state.cursor = cursor
}
}
@@ -119,9 +123,10 @@ const actions = {
const { filename, pathname } = state
ipcRenderer.send('AGANI::response-export', { type, content, filename, pathname })
},
- SAVE_FILE ({ commit, state }, { markdown, wordCount }) {
+ SAVE_FILE ({ commit, state }, { markdown, wordCount, cursor }) {
commit('SET_MARKDOWN', markdown)
- commit('SET_WORD_COUNT', wordCount)
+ if (wordCount) commit('SET_WORD_COUNT', wordCount)
+ if (cursor) commit('SET_CURSOR', cursor)
const { pathname } = state
if (pathname) {
commit('SET_STATUS', true)