Allow to copy table cells text as plaintext (#2409)

This commit is contained in:
Felix Häusler 2020-11-30 22:16:32 +01:00 committed by GitHub
parent f6ac392c32
commit fff183e32e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -223,9 +223,6 @@ const copyCutCtrl = ContentState => {
if (selectedTableCells) {
event.preventDefault()
const { row, column, cells } = selectedTableCells
const figureBlock = this.createBlock('figure', {
functionType: 'table'
})
const tableContents = []
let i
let j
@ -242,6 +239,15 @@ const copyCutCtrl = ContentState => {
tableContents.push(rowWrapper)
}
if (row === 1 && column === 1) {
// Copy cells text if only one is selected
event.clipboardData.setData('text/html', '')
event.clipboardData.setData('text/plain', tableContents[0][0].text)
} else {
// Copy as markdown table
const figureBlock = this.createBlock('figure', {
functionType: 'table'
})
const table = this.createTableInFigure({ rows: row, columns: column }, tableContents)
this.appendChild(figureBlock, table)
const { isGitlabCompatibilityEnabled, listIndentation } = this
@ -251,6 +257,7 @@ const copyCutCtrl = ContentState => {
event.clipboardData.setData('text/plain', markdown)
}
}
}
ContentState.prototype.copyHandler = function (event, type, copyInfo = null) {
if (this.selectedTableCells) {