diff --git a/src/main/actions/file.js b/src/main/actions/file.js index 6462f989..0996e77f 100644 --- a/src/main/actions/file.js +++ b/src/main/actions/file.js @@ -41,11 +41,16 @@ const handleResponseForSave = (e, { id, markdown, pathname, options }) => { defaultPath: getPath('documents') + '/Untitled.md' }) - return writeMarkdownFile(pathname, markdown, options, win) - .then(() => { - const filename = path.basename(pathname) - win.webContents.send('AGANI::set-pathname', { id, pathname, filename }) - }) + if (pathname && typeof pathname === 'string') { + return writeMarkdownFile(pathname, markdown, options, win) + .then(() => { + const filename = path.basename(pathname) + win.webContents.send('AGANI::set-pathname', { id, pathname, filename }) + return id + }) + } else { + return Promise.resolve() + } } ipcMain.on('AGANI::save-all', (e, unSavedFiles) => { @@ -56,11 +61,12 @@ ipcMain.on('AGANI::save-all', (e, unSavedFiles) => { ipcMain.on('AGANI::save-all-close', (e, unSavedFiles) => { const win = BrowserWindow.fromWebContents(e.sender) Promise.all(unSavedFiles.map(file => handleResponseForSave(e, file))) - .then(() => { - win.send('AGANI::save-all-response') + .then(arr => { + const data = arr.filter(id => id) + win.send('AGANI::save-all-response', { err: null, data }) }) .catch(err => { - win.send('AGANI::save-all-response', err) + win.send('AGANI::save-all-response', { err, data: null }) log(err) }) }) diff --git a/src/renderer/components/editorWithTabs/editor.vue b/src/renderer/components/editorWithTabs/editor.vue index 37b1b5bc..5d758952 100644 --- a/src/renderer/components/editorWithTabs/editor.vue +++ b/src/renderer/components/editorWithTabs/editor.vue @@ -384,8 +384,8 @@ handleMarkdownChange ({ markdown, cursor, renderCursor, history }) { const { editor } = this if (editor) { - this.editor.setMarkdown(markdown, cursor, renderCursor) if (history) editor.setHistory(history) + this.editor.setMarkdown(markdown, cursor, renderCursor) } }, diff --git a/src/renderer/components/sideBar/tree.vue b/src/renderer/components/sideBar/tree.vue index abea0d59..59708d62 100644 --- a/src/renderer/components/sideBar/tree.vue +++ b/src/renderer/components/sideBar/tree.vue @@ -135,6 +135,7 @@ document.addEventListener('click', event => { const target = event.target if (target.tagName !== 'INPUT') { + this.$store.dispatch('CHANGE_ACTIVE_ITEM', {}) this.$store.commit('CREATE_PATH', {}) this.$store.commit('SET_RENAME_CACHE', null) } diff --git a/src/renderer/mixins/index.js b/src/renderer/mixins/index.js index d5bcfa73..cd603370 100644 --- a/src/renderer/mixins/index.js +++ b/src/renderer/mixins/index.js @@ -28,7 +28,6 @@ export const fileMixins = { const isOpened = this.tabs.filter(file => file.pathname === pathname)[0] const fileState = isOpened || getFileStateFromData(data) - this.$store.dispatch('UPDATE_CURRENT_FILE', fileState) if (isMixed && !isOpened) { diff --git a/src/renderer/store/editor.js b/src/renderer/store/editor.js index 764bdae1..5c447b7d 100644 --- a/src/renderer/store/editor.js +++ b/src/renderer/store/editor.js @@ -84,9 +84,15 @@ const mutations = { SET_HISTORY (state, history) { state.currentFile.history = history }, - CLOSE_ALL_TABS (state) { - state.tabs = [] - state.currentFile = {} + CLOSE_TABS (state, arr) { + arr.forEach(id => { + const index = state.tabs.findIndex(f => f.id === id) + state.tabs.splice(index, 1) + if (state.currentFile.id === id) state.currentFile = {} + }) + if (!state.currentFile.id && state.tabs.length) { + state.currentFile = state.tabs[0] + } }, RENAME_IF_NEEDED (state, { src, dest }) { const { tabs } = state @@ -175,10 +181,11 @@ const actions = { }, LISTEN_FOR_SAVE_ALL_CLOSE ({ commit, state }) { - ipcRenderer.on('AGANI::save-all-response', (e, err) => { - if (err) console.log(err) - else { - commit('CLOSE_ALL_TABS') + ipcRenderer.on('AGANI::save-all-response', (e, { err, data }) => { + if (err) { + console.log(err) + } else if (Array.isArray(data) && data.length) { + commit('CLOSE_TABS', data) } }) }, diff --git a/src/renderer/store/help.js b/src/renderer/store/help.js index cb084e9c..57bf20a4 100644 --- a/src/renderer/store/help.js +++ b/src/renderer/store/help.js @@ -8,7 +8,10 @@ export const defaultFileState = { isUtf8BomEncoded: false, lineEnding: 'lf', // lf or crlf adjustLineEndingOnSave: false, - history: null, + history: { + stack: [], + index: -1 + }, cursor: null, wordCount: { paragraph: 0, diff --git a/src/renderer/store/layout.js b/src/renderer/store/layout.js index 2d557ef1..d43dfffe 100644 --- a/src/renderer/store/layout.js +++ b/src/renderer/store/layout.js @@ -2,7 +2,7 @@ import { ipcRenderer } from 'electron' // messages from main process, and do not change the state const state = { - rightColumn: '', + rightColumn: 'files', showSideBar: false, showTabBar: false }