mirror of
https://github.com/marktext/marktext.git
synced 2025-05-03 01:21:41 +08:00
bugfix: history error and main process error
This commit is contained in:
parent
8fd13ed068
commit
c099cc3ce7
@ -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)
|
||||
})
|
||||
})
|
||||
|
@ -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)
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
}
|
||||
})
|
||||
},
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user