From 11f5f45b8b818394257413b4727c7fd23553ca52 Mon Sep 17 00:00:00 2001 From: Jocs Date: Mon, 1 Oct 2018 13:36:07 +0800 Subject: [PATCH] fix: #393 --- src/renderer/store/editor.js | 4 ++++ src/renderer/store/project.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/renderer/store/editor.js b/src/renderer/store/editor.js index 8f57201f..4f9c7bac 100644 --- a/src/renderer/store/editor.js +++ b/src/renderer/store/editor.js @@ -405,6 +405,7 @@ const actions = { // Content change from realtime preview editor and source code editor LISTEN_FOR_CONTENT_CHANGE ({ commit, state, rootState }, { markdown, wordCount, cursor, history }) { const { autoSave } = rootState.preferences + const { projectTree } = rootState.project const { pathname, markdown: oldMarkdown, id } = state.currentFile const options = getOptionsFromState(state.currentFile) commit('SET_MARKDOWN', markdown) @@ -416,6 +417,9 @@ const actions = { if (history) commit('SET_HISTORY', history) // change save status/save to file only when the markdown changed! if (markdown !== oldMarkdown) { + if (projectTree) { + commit('UPDATE_PROJECT_CONTENT', { markdown, pathname }) + } if (pathname && autoSave) { ipcRenderer.send('AGANI::response-file-save', { id, pathname, markdown, options }) } else { diff --git a/src/renderer/store/project.js b/src/renderer/store/project.js index da3d4eef..7a8aeda9 100644 --- a/src/renderer/store/project.js +++ b/src/renderer/store/project.js @@ -85,6 +85,21 @@ const mutations = { }, SET_RENAME_CACHE (state, 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) } }