mirror of
https://github.com/marktext/marktext.git
synced 2025-05-02 22:10:24 +08:00
fix: #393
This commit is contained in:
parent
94db7a7c7f
commit
11f5f45b8b
@ -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 {
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user