mirror of
https://github.com/marktext/marktext.git
synced 2025-05-02 19:59:41 +08:00
parent
1ab1e853f4
commit
3b9c16779d
1
.github/CHANGELOG.md
vendored
1
.github/CHANGELOG.md
vendored
@ -16,6 +16,7 @@
|
||||
- Fixed some commonmark failed examples and add test case (#943)
|
||||
- Fixed some bugs after press `backspace` (#934, #938)
|
||||
- Change `inline math` vertical align to `top` (#977)
|
||||
- Prevent to open the same file twice, instead select the existing tab (#878)
|
||||
|
||||
### 0.14.0
|
||||
|
||||
|
@ -2,6 +2,7 @@ import { clipboard, ipcRenderer, shell } from 'electron'
|
||||
import path from 'path'
|
||||
import bus from '../bus'
|
||||
import { hasKeys } from '../util'
|
||||
import { isSameFileSync } from '../util/fileSystem'
|
||||
import listToTree from '../util/listToTree'
|
||||
import { createDocumentState, getOptionsFromState, getSingleFileState, getBlankFileState } from './help'
|
||||
import notice from '../services/notification'
|
||||
@ -63,7 +64,7 @@ const mutations = {
|
||||
type: 'primary',
|
||||
time: 20000,
|
||||
showConfirm: false
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
let fileState = null
|
||||
@ -392,6 +393,7 @@ const actions = {
|
||||
}
|
||||
},
|
||||
|
||||
// This event is only used when loading a file during window creation.
|
||||
LISTEN_FOR_OPEN_SINGLE_FILE ({ commit, state, dispatch }) {
|
||||
ipcRenderer.on('AGANI::open-single-file', (e, { markdown, filename, pathname, options }) => {
|
||||
const fileState = getSingleFileState({ markdown, filename, pathname, options })
|
||||
@ -410,6 +412,7 @@ const actions = {
|
||||
})
|
||||
},
|
||||
|
||||
// Open a new tab, optionally with content.
|
||||
LISTEN_FOR_NEW_TAB ({ dispatch }) {
|
||||
ipcRenderer.on('AGANI::new-tab', (e, markdownDocument) => {
|
||||
if (markdownDocument) {
|
||||
@ -457,6 +460,15 @@ const actions = {
|
||||
return
|
||||
}
|
||||
|
||||
// Check if tab already exist and select existing tab if so.
|
||||
const { tabs } = state
|
||||
const { pathname } = markdownDocument
|
||||
const existingTab = tabs.find(t => isSameFileSync(t.pathname, pathname))
|
||||
if (existingTab) {
|
||||
dispatch('UPDATE_CURRENT_FILE', existingTab)
|
||||
return
|
||||
}
|
||||
|
||||
dispatch('SHOW_TAB_VIEW', false)
|
||||
|
||||
const { markdown, isMixedLineEndings } = markdownDocument
|
||||
|
@ -1,3 +1,4 @@
|
||||
import path from 'path'
|
||||
import fse from 'fs-extra'
|
||||
|
||||
export const create = (pathname, type) => {
|
||||
@ -15,3 +16,30 @@ export const paste = ({ src, dest, type }) => {
|
||||
export const rename = (src, dest) => {
|
||||
return fse.move(src, dest)
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the both paths point to the same file.
|
||||
*
|
||||
* @param {*} pathA The first path.
|
||||
* @param {*} pathB The second path.
|
||||
* @param {*} isNormalized Are both paths already normalized.
|
||||
*/
|
||||
export const isSameFileSync = (pathA, pathB, isNormalized=false) => {
|
||||
if (!pathA || !pathB) return false
|
||||
const a = isNormalized ? pathA : path.normalize(pathA)
|
||||
const b = isNormalized ? pathB : path.normalize(pathB)
|
||||
if (a.length !== b.length) {
|
||||
return false
|
||||
} else if (a === b) {
|
||||
return true
|
||||
} else if (a.toLowerCase() === b.toLowerCase()) {
|
||||
try {
|
||||
const fiA = fse.statSync(a)
|
||||
const fiB = fse.statSync(b)
|
||||
return fiA.ino === fiB.ino
|
||||
} catch (_) {
|
||||
// Ignore error
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user