mirror of
https://github.com/marktext/marktext.git
synced 2025-05-03 04:51:28 +08:00
Check for same file before pasting (#3034)
This commit is contained in:
parent
fed1dac48f
commit
34e4a22857
@ -142,7 +142,7 @@ const actions = {
|
|||||||
const { pathname } = state.activeItem
|
const { pathname } = state.activeItem
|
||||||
shell.trashItem(pathname).catch(err => {
|
shell.trashItem(pathname).catch(err => {
|
||||||
notice.notify({
|
notice.notify({
|
||||||
title: 'Deletion Error',
|
title: 'Error while deleting',
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: err.message
|
message: err.message
|
||||||
})
|
})
|
||||||
@ -156,15 +156,25 @@ const actions = {
|
|||||||
const { clipboard } = state
|
const { clipboard } = state
|
||||||
const { pathname, isDirectory } = state.activeItem
|
const { pathname, isDirectory } = state.activeItem
|
||||||
const dirname = isDirectory ? pathname : path.dirname(pathname)
|
const dirname = isDirectory ? pathname : path.dirname(pathname)
|
||||||
if (clipboard) {
|
if (clipboard && clipboard.src) {
|
||||||
clipboard.dest = dirname + PATH_SEPARATOR + path.basename(clipboard.src)
|
clipboard.dest = dirname + PATH_SEPARATOR + path.basename(clipboard.src)
|
||||||
|
|
||||||
|
if (path.normalize(clipboard.src) === path.normalize(clipboard.dest)) {
|
||||||
|
notice.notify({
|
||||||
|
title: 'Paste Forbidden',
|
||||||
|
type: 'warning',
|
||||||
|
message: 'Source and destination must not be the same.'
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
paste(clipboard)
|
paste(clipboard)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
commit('SET_CLIPBOARD', null)
|
commit('SET_CLIPBOARD', null)
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
notice.notify({
|
notice.notify({
|
||||||
title: 'Paste Error',
|
title: 'Error while pasting',
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: err.message
|
message: err.message
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user