mirror of
https://github.com/marktext/marktext.git
synced 2025-05-02 11:20:25 +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) {
|
if (row === 1 && column === 1) {
|
||||||
// Copy cells text if only one is selected
|
// Copy cells text if only one is selected
|
||||||
|
if (tableContents[0][0].text.length > 0) {
|
||||||
event.clipboardData.setData('text/html', '')
|
event.clipboardData.setData('text/html', '')
|
||||||
event.clipboardData.setData('text/plain', tableContents[0][0].text)
|
event.clipboardData.setData('text/plain', tableContents[0][0].text)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Copy as markdown table
|
// Copy as markdown table
|
||||||
const figureBlock = this.createBlock('figure', {
|
const figureBlock = this.createBlock('figure', {
|
||||||
@ -254,12 +256,13 @@ const copyCutCtrl = ContentState => {
|
|||||||
this.appendChild(figureBlock, table)
|
this.appendChild(figureBlock, table)
|
||||||
const { isGitlabCompatibilityEnabled, listIndentation } = this
|
const { isGitlabCompatibilityEnabled, listIndentation } = this
|
||||||
const markdown = new ExportMarkdown([figureBlock], listIndentation, isGitlabCompatibilityEnabled).generate()
|
const markdown = new ExportMarkdown([figureBlock], listIndentation, isGitlabCompatibilityEnabled).generate()
|
||||||
|
if (markdown.length > 0) {
|
||||||
event.clipboardData.setData('text/html', '')
|
event.clipboardData.setData('text/html', '')
|
||||||
event.clipboardData.setData('text/plain', markdown)
|
event.clipboardData.setData('text/plain', markdown)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ContentState.prototype.copyHandler = function (event, type, copyInfo = null) {
|
ContentState.prototype.copyHandler = function (event, type, copyInfo = null) {
|
||||||
if (this.selectedTableCells) {
|
if (this.selectedTableCells) {
|
||||||
@ -270,30 +273,38 @@ const copyCutCtrl = ContentState => {
|
|||||||
const { selectedImage } = this
|
const { selectedImage } = this
|
||||||
if (selectedImage) {
|
if (selectedImage) {
|
||||||
const { token } = selectedImage
|
const { token } = selectedImage
|
||||||
|
if (token.raw.length > 0) {
|
||||||
event.clipboardData.setData('text/html', token.raw)
|
event.clipboardData.setData('text/html', token.raw)
|
||||||
event.clipboardData.setData('text/plain', token.raw)
|
event.clipboardData.setData('text/plain', token.raw)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const { html, text } = this.getClipBoardData()
|
const { html, text } = this.getClipBoardData()
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'normal': {
|
case 'normal': {
|
||||||
|
if (text.length > 0) {
|
||||||
event.clipboardData.setData('text/html', html)
|
event.clipboardData.setData('text/html', html)
|
||||||
event.clipboardData.setData('text/plain', text)
|
event.clipboardData.setData('text/plain', text)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 'copyAsMarkdown': {
|
case 'copyAsMarkdown': {
|
||||||
|
if (text.length > 0) {
|
||||||
event.clipboardData.setData('text/html', '')
|
event.clipboardData.setData('text/html', '')
|
||||||
event.clipboardData.setData('text/plain', text)
|
event.clipboardData.setData('text/plain', text)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case 'copyAsHtml': {
|
case 'copyAsHtml': {
|
||||||
|
if (text.length > 0) {
|
||||||
event.clipboardData.setData('text/html', '')
|
event.clipboardData.setData('text/html', '')
|
||||||
event.clipboardData.setData('text/plain', getSanitizeHtml(text, {
|
event.clipboardData.setData('text/plain', getSanitizeHtml(text, {
|
||||||
superSubScript: this.muya.options.superSubScript,
|
superSubScript: this.muya.options.superSubScript,
|
||||||
footnote: this.muya.options.footnote,
|
footnote: this.muya.options.footnote,
|
||||||
isGitlabCompatibilityEnabled: this.muya.options.isGitlabCompatibilityEnabled
|
isGitlabCompatibilityEnabled: this.muya.options.isGitlabCompatibilityEnabled
|
||||||
}))
|
}))
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,8 +314,10 @@ const copyCutCtrl = ContentState => {
|
|||||||
const anchor = this.getAnchor(block)
|
const anchor = this.getAnchor(block)
|
||||||
const { isGitlabCompatibilityEnabled, listIndentation } = this
|
const { isGitlabCompatibilityEnabled, listIndentation } = this
|
||||||
const markdown = new ExportMarkdown([anchor], listIndentation, isGitlabCompatibilityEnabled).generate()
|
const markdown = new ExportMarkdown([anchor], listIndentation, isGitlabCompatibilityEnabled).generate()
|
||||||
|
if (markdown.length > 0) {
|
||||||
event.clipboardData.setData('text/html', '')
|
event.clipboardData.setData('text/html', '')
|
||||||
event.clipboardData.setData('text/plain', markdown)
|
event.clipboardData.setData('text/plain', markdown)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,11 +326,13 @@ const copyCutCtrl = ContentState => {
|
|||||||
if (typeof codeContent !== 'string') {
|
if (typeof codeContent !== 'string') {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (codeContent.length > 0) {
|
||||||
event.clipboardData.setData('text/html', '')
|
event.clipboardData.setData('text/html', '')
|
||||||
event.clipboardData.setData('text/plain', codeContent)
|
event.clipboardData.setData('text/plain', codeContent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export default copyCutCtrl
|
export default copyCutCtrl
|
||||||
|
Loading…
Reference in New Issue
Block a user