mirror of
https://github.com/marktext/marktext.git
synced 2025-05-02 02:40:36 +08:00
Don't copy (or on cut) empty data to the clipboard, matches native behavior (#3130)
This commit is contained in:
parent
5cf4c73383
commit
c841facdfa
@ -243,8 +243,10 @@ const copyCutCtrl = ContentState => {
|
||||
|
||||
if (row === 1 && column === 1) {
|
||||
// Copy cells text if only one is selected
|
||||
if (tableContents[0][0].text.length > 0) {
|
||||
event.clipboardData.setData('text/html', '')
|
||||
event.clipboardData.setData('text/plain', tableContents[0][0].text)
|
||||
}
|
||||
} else {
|
||||
// Copy as markdown table
|
||||
const figureBlock = this.createBlock('figure', {
|
||||
@ -254,12 +256,13 @@ const copyCutCtrl = ContentState => {
|
||||
this.appendChild(figureBlock, table)
|
||||
const { isGitlabCompatibilityEnabled, listIndentation } = this
|
||||
const markdown = new ExportMarkdown([figureBlock], listIndentation, isGitlabCompatibilityEnabled).generate()
|
||||
|
||||
if (markdown.length > 0) {
|
||||
event.clipboardData.setData('text/html', '')
|
||||
event.clipboardData.setData('text/plain', markdown)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ContentState.prototype.copyHandler = function (event, type, copyInfo = null) {
|
||||
if (this.selectedTableCells) {
|
||||
@ -270,30 +273,38 @@ const copyCutCtrl = ContentState => {
|
||||
const { selectedImage } = this
|
||||
if (selectedImage) {
|
||||
const { token } = selectedImage
|
||||
if (token.raw.length > 0) {
|
||||
event.clipboardData.setData('text/html', token.raw)
|
||||
event.clipboardData.setData('text/plain', token.raw)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
const { html, text } = this.getClipBoardData()
|
||||
switch (type) {
|
||||
case 'normal': {
|
||||
if (text.length > 0) {
|
||||
event.clipboardData.setData('text/html', html)
|
||||
event.clipboardData.setData('text/plain', text)
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'copyAsMarkdown': {
|
||||
if (text.length > 0) {
|
||||
event.clipboardData.setData('text/html', '')
|
||||
event.clipboardData.setData('text/plain', text)
|
||||
}
|
||||
break
|
||||
}
|
||||
case 'copyAsHtml': {
|
||||
if (text.length > 0) {
|
||||
event.clipboardData.setData('text/html', '')
|
||||
event.clipboardData.setData('text/plain', getSanitizeHtml(text, {
|
||||
superSubScript: this.muya.options.superSubScript,
|
||||
footnote: this.muya.options.footnote,
|
||||
isGitlabCompatibilityEnabled: this.muya.options.isGitlabCompatibilityEnabled
|
||||
}))
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@ -303,8 +314,10 @@ const copyCutCtrl = ContentState => {
|
||||
const anchor = this.getAnchor(block)
|
||||
const { isGitlabCompatibilityEnabled, listIndentation } = this
|
||||
const markdown = new ExportMarkdown([anchor], listIndentation, isGitlabCompatibilityEnabled).generate()
|
||||
if (markdown.length > 0) {
|
||||
event.clipboardData.setData('text/html', '')
|
||||
event.clipboardData.setData('text/plain', markdown)
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
@ -313,11 +326,13 @@ const copyCutCtrl = ContentState => {
|
||||
if (typeof codeContent !== 'string') {
|
||||
return
|
||||
}
|
||||
if (codeContent.length > 0) {
|
||||
event.clipboardData.setData('text/html', '')
|
||||
event.clipboardData.setData('text/plain', codeContent)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default copyCutCtrl
|
||||
|
Loading…
Reference in New Issue
Block a user