This commit is contained in:
Jocs 2018-10-01 13:36:07 +08:00
parent 94db7a7c7f
commit 11f5f45b8b
2 changed files with 19 additions and 0 deletions

View File

@ -405,6 +405,7 @@ const actions = {
// Content change from realtime preview editor and source code editor // Content change from realtime preview editor and source code editor
LISTEN_FOR_CONTENT_CHANGE ({ commit, state, rootState }, { markdown, wordCount, cursor, history }) { LISTEN_FOR_CONTENT_CHANGE ({ commit, state, rootState }, { markdown, wordCount, cursor, history }) {
const { autoSave } = rootState.preferences const { autoSave } = rootState.preferences
const { projectTree } = rootState.project
const { pathname, markdown: oldMarkdown, id } = state.currentFile const { pathname, markdown: oldMarkdown, id } = state.currentFile
const options = getOptionsFromState(state.currentFile) const options = getOptionsFromState(state.currentFile)
commit('SET_MARKDOWN', markdown) commit('SET_MARKDOWN', markdown)
@ -416,6 +417,9 @@ const actions = {
if (history) commit('SET_HISTORY', history) if (history) commit('SET_HISTORY', history)
// change save status/save to file only when the markdown changed! // change save status/save to file only when the markdown changed!
if (markdown !== oldMarkdown) { if (markdown !== oldMarkdown) {
if (projectTree) {
commit('UPDATE_PROJECT_CONTENT', { markdown, pathname })
}
if (pathname && autoSave) { if (pathname && autoSave) {
ipcRenderer.send('AGANI::response-file-save', { id, pathname, markdown, options }) ipcRenderer.send('AGANI::response-file-save', { id, pathname, markdown, options })
} else { } else {

View File

@ -85,6 +85,21 @@ const mutations = {
}, },
SET_RENAME_CACHE (state, cache) { SET_RENAME_CACHE (state, cache) {
state.renameCache = cache state.renameCache = cache
},
UPDATE_PROJECT_CONTENT (state, { markdown, pathname }) {
if (!state.projectTree) return
const travel = folder => {
folder.files.filter(file => file.isMarkdown)
.forEach(file => {
if (file.pathname === pathname) {
file.data.markdown = markdown
}
})
for (const childFolder of folder.folders) {
travel(childFolder)
}
}
travel(state.projectTree)
} }
} }