mirror of
https://github.com/marktext/marktext.git
synced 2025-05-03 00:01:19 +08:00
Don't show save dialog for an empty/not changed document (#548)
* Don't show save dialog for an empty document * Fix blank document was always encoded as LF
This commit is contained in:
parent
2e133e21e0
commit
72ef20edd8
4
.github/CHANGELOG.md
vendored
4
.github/CHANGELOG.md
vendored
@ -1,9 +1,10 @@
|
||||
### 0.13.58
|
||||
### 0.13.61
|
||||
|
||||
**:butterfly:Optimization**
|
||||
|
||||
- Show tab bar when opening a new tab
|
||||
- Use default bold (`CmdOrCtrl+B`) and italics (`CmdOrCtrl+I`) key binding (#346)
|
||||
- Don't show save dialog for an empty document (#422)
|
||||
|
||||
**:beetle:Bug fix**
|
||||
|
||||
@ -14,6 +15,7 @@
|
||||
- fix: #535 Application menu is not updated when switching windows
|
||||
- fix #216 and #311 key binding issues on Linux and Windows
|
||||
- fix #546 paste issue in table
|
||||
- fix: Blank document was always encoded as `LF`
|
||||
|
||||
### 0.13.50
|
||||
|
||||
|
@ -241,7 +241,7 @@ const actions = {
|
||||
|
||||
LISTEN_FOR_CLOSE ({ commit, state }) {
|
||||
ipcRenderer.on('AGANI::ask-for-close', e => {
|
||||
const unSavedFiles = state.tabs.filter(file => !(file.isSaved && /[^\n]/.test(file.markdown)))
|
||||
const unSavedFiles = state.tabs.filter(file => !file.isSaved)
|
||||
.map(file => {
|
||||
const { id, filename, pathname, markdown } = file
|
||||
const options = getOptionsFromState(file)
|
||||
@ -421,12 +421,19 @@ const actions = {
|
||||
const { pathname, markdown: oldMarkdown, id } = state.currentFile
|
||||
const options = getOptionsFromState(state.currentFile)
|
||||
commit('SET_MARKDOWN', markdown)
|
||||
|
||||
// ignore new line which is added if the editor text is empty (#422)
|
||||
if (oldMarkdown.length === 0 && markdown.length === 1 && markdown[0] === '\n') {
|
||||
return
|
||||
}
|
||||
|
||||
// set word count
|
||||
if (wordCount) commit('SET_WORD_COUNT', wordCount)
|
||||
// set cursor
|
||||
if (cursor) commit('SET_CURSOR', cursor)
|
||||
// set history
|
||||
if (history) commit('SET_HISTORY', history)
|
||||
|
||||
// change save status/save to file only when the markdown changed!
|
||||
if (markdown !== oldMarkdown) {
|
||||
if (projectTree) {
|
||||
|
@ -7,7 +7,7 @@ export const defaultFileState = {
|
||||
markdown: '',
|
||||
isUtf8BomEncoded: false,
|
||||
lineEnding: 'lf', // lf or crlf
|
||||
adjustLineEndingOnSave: false,
|
||||
adjustLineEndingOnSave: false, // convert editor buffer (LF) to CRLF when saving
|
||||
textDirection: 'ltr',
|
||||
history: {
|
||||
stack: [],
|
||||
@ -45,6 +45,8 @@ export const getFileStateFromData = data => {
|
||||
} = data
|
||||
const id = getUniqueId()
|
||||
|
||||
assertLineEnding(adjustLineEndingOnSave, lineEnding)
|
||||
|
||||
return Object.assign(fileState, {
|
||||
id,
|
||||
markdown,
|
||||
@ -71,6 +73,7 @@ export const getBlankFileState = (tabs, lineEnding = 'lf', markdown = '') => {
|
||||
|
||||
return Object.assign(fileState, {
|
||||
lineEnding,
|
||||
adjustLineEndingOnSave: lineEnding.toLowerCase() === 'crlf',
|
||||
id,
|
||||
filename: `Untitled-${++untitleId}`,
|
||||
markdown
|
||||
@ -81,6 +84,8 @@ export const getSingleFileState = ({ id = getUniqueId(), markdown, filename, pat
|
||||
const fileState = JSON.parse(JSON.stringify(defaultFileState))
|
||||
const { isUtf8BomEncoded, lineEnding, adjustLineEndingOnSave } = options
|
||||
|
||||
assertLineEnding(adjustLineEndingOnSave, lineEnding)
|
||||
|
||||
return Object.assign(fileState, {
|
||||
id,
|
||||
markdown,
|
||||
@ -91,3 +96,11 @@ export const getSingleFileState = ({ id = getUniqueId(), markdown, filename, pat
|
||||
adjustLineEndingOnSave
|
||||
})
|
||||
}
|
||||
|
||||
const assertLineEnding = (adjustLineEndingOnSave, lineEnding) => {
|
||||
lineEnding = lineEnding.toLowerCase()
|
||||
if ((adjustLineEndingOnSave && lineEnding !== 'crlf') ||
|
||||
(!adjustLineEndingOnSave && lineEnding === 'crlf')) {
|
||||
console.error('Assertion failed: Line ending is "CRLF" but document is saved as "LF".')
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user