fix: Mutate clipboard content when copying from a single table cell. (#7798)

* fix: Mutate clipboard content when copying from a single table cell.
closes #7794

* refactor
This commit is contained in:
Tom Moor
2024-10-18 08:35:21 -04:00
committed by GitHub
parent 9e378899ff
commit 4e6572d686
+30 -1
View File
@@ -1,5 +1,5 @@
import Token from "markdown-it/lib/token";
import { NodeSpec } from "prosemirror-model";
import { NodeSpec, Slice } from "prosemirror-model";
import { Plugin } from "prosemirror-state";
import { DecorationSet, Decoration } from "prosemirror-view";
import { addRowBefore, selectRow, selectTable } from "../commands/table";
@@ -71,6 +71,35 @@ export default class TableCell extends Node {
return [
new Plugin({
props: {
transformCopied: (slice) => {
// check if the copied selection is a single table, with a single row, with a single cell. If so,
// copy the cell content only not a table with a single cell. This leads to more predictable pasting
// behavior, both in and outside the app.
if (slice.content.childCount === 1) {
const table = slice.content.firstChild;
if (
table?.type.spec.tableRole === "table" &&
table.childCount === 1
) {
const row = table.firstChild;
if (
row?.type.spec.tableRole === "row" &&
row.childCount === 1
) {
const cell = row.firstChild;
if (cell?.type.spec.tableRole === "cell") {
return new Slice(
cell.content,
slice.openStart,
slice.openEnd
);
}
}
}
}
return slice;
},
handleDOMEvents: {
mousedown: (view, event) => {
if (!(event.target instanceof HTMLElement)) {