mirror of
https://github.com/outline/outline.git
synced 2026-06-13 11:25:03 +03:00
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:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user