From fff183e32ec27ac80c157b142900cd93bd5a9da4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20H=C3=A4usler?= Date: Mon, 30 Nov 2020 22:16:32 +0100 Subject: [PATCH] Allow to copy table cells text as plaintext (#2409) --- src/muya/lib/contentState/copyCutCtrl.js | 25 +++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/muya/lib/contentState/copyCutCtrl.js b/src/muya/lib/contentState/copyCutCtrl.js index ca9718f7..493b5c6b 100644 --- a/src/muya/lib/contentState/copyCutCtrl.js +++ b/src/muya/lib/contentState/copyCutCtrl.js @@ -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,13 +239,23 @@ const copyCutCtrl = ContentState => { tableContents.push(rowWrapper) } - const table = this.createTableInFigure({ rows: row, columns: column }, tableContents) - this.appendChild(figureBlock, table) - const { isGitlabCompatibilityEnabled, listIndentation } = this - const markdown = new ExportMarkdown([figureBlock], listIndentation, isGitlabCompatibilityEnabled).generate() + 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 + const markdown = new ExportMarkdown([figureBlock], listIndentation, isGitlabCompatibilityEnabled).generate() - event.clipboardData.setData('text/html', '') - event.clipboardData.setData('text/plain', markdown) + event.clipboardData.setData('text/html', '') + event.clipboardData.setData('text/plain', markdown) + } } }