bugfix: history error and main process error

This commit is contained in:
Jocs 2018-06-06 12:12:18 +08:00
parent 8fd13ed068
commit c099cc3ce7
7 changed files with 35 additions and 19 deletions

View File

@ -41,11 +41,16 @@ const handleResponseForSave = (e, { id, markdown, pathname, options }) => {
defaultPath: getPath('documents') + '/Untitled.md' defaultPath: getPath('documents') + '/Untitled.md'
}) })
if (pathname && typeof pathname === 'string') {
return writeMarkdownFile(pathname, markdown, options, win) return writeMarkdownFile(pathname, markdown, options, win)
.then(() => { .then(() => {
const filename = path.basename(pathname) const filename = path.basename(pathname)
win.webContents.send('AGANI::set-pathname', { id, pathname, filename }) win.webContents.send('AGANI::set-pathname', { id, pathname, filename })
return id
}) })
} else {
return Promise.resolve()
}
} }
ipcMain.on('AGANI::save-all', (e, unSavedFiles) => { 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) => { ipcMain.on('AGANI::save-all-close', (e, unSavedFiles) => {
const win = BrowserWindow.fromWebContents(e.sender) const win = BrowserWindow.fromWebContents(e.sender)
Promise.all(unSavedFiles.map(file => handleResponseForSave(e, file))) Promise.all(unSavedFiles.map(file => handleResponseForSave(e, file)))
.then(() => { .then(arr => {
win.send('AGANI::save-all-response') const data = arr.filter(id => id)
win.send('AGANI::save-all-response', { err: null, data })
}) })
.catch(err => { .catch(err => {
win.send('AGANI::save-all-response', err) win.send('AGANI::save-all-response', { err, data: null })
log(err) log(err)
}) })
}) })

View File

@ -384,8 +384,8 @@
handleMarkdownChange ({ markdown, cursor, renderCursor, history }) { handleMarkdownChange ({ markdown, cursor, renderCursor, history }) {
const { editor } = this const { editor } = this
if (editor) { if (editor) {
this.editor.setMarkdown(markdown, cursor, renderCursor)
if (history) editor.setHistory(history) if (history) editor.setHistory(history)
this.editor.setMarkdown(markdown, cursor, renderCursor)
} }
}, },

View File

@ -135,6 +135,7 @@
document.addEventListener('click', event => { document.addEventListener('click', event => {
const target = event.target const target = event.target
if (target.tagName !== 'INPUT') { if (target.tagName !== 'INPUT') {
this.$store.dispatch('CHANGE_ACTIVE_ITEM', {})
this.$store.commit('CREATE_PATH', {}) this.$store.commit('CREATE_PATH', {})
this.$store.commit('SET_RENAME_CACHE', null) this.$store.commit('SET_RENAME_CACHE', null)
} }

View File

@ -28,7 +28,6 @@ export const fileMixins = {
const isOpened = this.tabs.filter(file => file.pathname === pathname)[0] const isOpened = this.tabs.filter(file => file.pathname === pathname)[0]
const fileState = isOpened || getFileStateFromData(data) const fileState = isOpened || getFileStateFromData(data)
this.$store.dispatch('UPDATE_CURRENT_FILE', fileState) this.$store.dispatch('UPDATE_CURRENT_FILE', fileState)
if (isMixed && !isOpened) { if (isMixed && !isOpened) {

View File

@ -84,9 +84,15 @@ const mutations = {
SET_HISTORY (state, history) { SET_HISTORY (state, history) {
state.currentFile.history = history state.currentFile.history = history
}, },
CLOSE_ALL_TABS (state) { CLOSE_TABS (state, arr) {
state.tabs = [] arr.forEach(id => {
state.currentFile = {} 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 }) { RENAME_IF_NEEDED (state, { src, dest }) {
const { tabs } = state const { tabs } = state
@ -175,10 +181,11 @@ const actions = {
}, },
LISTEN_FOR_SAVE_ALL_CLOSE ({ commit, state }) { LISTEN_FOR_SAVE_ALL_CLOSE ({ commit, state }) {
ipcRenderer.on('AGANI::save-all-response', (e, err) => { ipcRenderer.on('AGANI::save-all-response', (e, { err, data }) => {
if (err) console.log(err) if (err) {
else { console.log(err)
commit('CLOSE_ALL_TABS') } else if (Array.isArray(data) && data.length) {
commit('CLOSE_TABS', data)
} }
}) })
}, },

View File

@ -8,7 +8,10 @@ export const defaultFileState = {
isUtf8BomEncoded: false, isUtf8BomEncoded: false,
lineEnding: 'lf', // lf or crlf lineEnding: 'lf', // lf or crlf
adjustLineEndingOnSave: false, adjustLineEndingOnSave: false,
history: null, history: {
stack: [],
index: -1
},
cursor: null, cursor: null,
wordCount: { wordCount: {
paragraph: 0, paragraph: 0,

View File

@ -2,7 +2,7 @@ import { ipcRenderer } from 'electron'
// messages from main process, and do not change the state // messages from main process, and do not change the state
const state = { const state = {
rightColumn: '', rightColumn: 'files',
showSideBar: false, showSideBar: false,
showTabBar: false showTabBar: false
} }