Skip to content

armgit / plane

Public Imported from GitHub
0

πŸ”₯πŸ”₯πŸ”₯ Open-source Jira, Linear, Monday, and ClickUp alternative. Plane is a modern project management platform to manage tasks, sprints, docs, and triage.

[WIKI-498] regression: table bugs #7631

Aaryan Khandelwal34e231230f36
diff --git a/packages/editor/src/core/extensions/table/plugins/drag-handles/column/plugin.ts b/packages/editor/src/core/extensions/table/plugins/drag-handles/column/plugin.ts
index 6cefa24b6f..d25591e475 100644
--- a/packages/editor/src/core/extensions/table/plugins/drag-handles/column/plugin.ts
+++ b/packages/editor/src/core/extensions/table/plugins/drag-handles/column/plugin.ts
@@ -14,6 +14,9 @@ import { ColumnDragHandle, ColumnDragHandleProps } from "./drag-handle";
type TableColumnDragHandlePluginState = {
decorations?: DecorationSet;
+ // track table structure to detect changes
+ tableWidth?: number;
+ tableNodePos?: number;
};
const TABLE_COLUMN_DRAG_HANDLE_PLUGIN_KEY = new PluginKey("tableColumnHandlerDecorationPlugin");
@@ -31,20 +34,33 @@ export const TableColumnDragHandlePlugin = (editor: Editor): Plugin<TableColumnD
const tableMap = TableMap.get(table.node);
- let isStale = false;
- const mapped = prev.decorations?.map(tr.mapping, tr.doc);
- for (let col = 0; col < tableMap.width; col++) {
- const pos = getTableCellWidgetDecorationPos(table, tableMap, col);
- if (mapped?.find(pos, pos + 1)?.length !== 1) {
- isStale = true;
- break;
+ // Check if table structure changed (width or position)
+ const tableStructureChanged = prev.tableWidth !== tableMap.width || prev.tableNodePos !== table.pos;
+
+ let isStale = tableStructureChanged;
+
+ // Only do position-based stale check if structure hasn't changed
+ if (!isStale) {
+ const mapped = prev.decorations?.map(tr.mapping, tr.doc);
+ for (let col = 0; col < tableMap.width; col++) {
+ const pos = getTableCellWidgetDecorationPos(table, tableMap, col);
+ if (mapped?.find(pos, pos + 1)?.length !== 1) {
+ isStale = true;
+ break;
+ }
}
}
if (!isStale) {
- return { decorations: mapped };
+ const mapped = prev.decorations?.map(tr.mapping, tr.doc);
+ return {
+ decorations: mapped,
+ tableWidth: tableMap.width,
+ tableNodePos: table.pos,
+ };
}
+ // recreate all decorations
const decorations: Decoration[] = [];
for (let col = 0; col < tableMap.width; col++) {
@@ -63,6 +79,8 @@ export const TableColumnDragHandlePlugin = (editor: Editor): Plugin<TableColumnD
return {
decorations: DecorationSet.create(newState.doc, decorations),
+ tableWidth: tableMap.width,
+ tableNodePos: table.pos,
};
},
},
diff --git a/packages/editor/src/core/extensions/table/plugins/drag-handles/row/plugin.ts b/packages/editor/src/core/extensions/table/plugins/drag-handles/row/plugin.ts
index d84f942ba4..92cf0eea9d 100644
--- a/packages/editor/src/core/extensions/table/plugins/drag-handles/row/plugin.ts
+++ b/packages/editor/src/core/extensions/table/plugins/drag-handles/row/plugin.ts
@@ -14,6 +14,9 @@ import { RowDragHandle, RowDragHandleProps } from "./drag-handle";
type TableRowDragHandlePluginState = {
decorations?: DecorationSet;
+ // track table structure to detect changes
+ tableHeight?: number;
+ tableNodePos?: number;
};
const TABLE_ROW_DRAG_HANDLE_PLUGIN_KEY = new PluginKey("tableRowDragHandlePlugin");
@@ -31,20 +34,33 @@ export const TableRowDragHandlePlugin = (editor: Editor): Plugin<TableRowDragHan
const tableMap = TableMap.get(table.node);
- let isStale = false;
- const mapped = prev.decorations?.map(tr.mapping, tr.doc);
- for (let row = 0; row < tableMap.height; row++) {
- const pos = getTableCellWidgetDecorationPos(table, tableMap, row * tableMap.width);
- if (mapped?.find(pos, pos + 1)?.length !== 1) {
- isStale = true;
- break;
+ // Check if table structure changed (height or position)
+ const tableStructureChanged = prev.tableHeight !== tableMap.height || prev.tableNodePos !== table.pos;
+
+ let isStale = tableStructureChanged;
+
+ // Only do position-based stale check if structure hasn't changed
+ if (!isStale) {
+ const mapped = prev.decorations?.map(tr.mapping, tr.doc);
+ for (let row = 0; row < tableMap.height; row++) {
+ const pos = getTableCellWidgetDecorationPos(table, tableMap, row * tableMap.width);
+ if (mapped?.find(pos, pos + 1)?.length !== 1) {
+ isStale = true;
+ break;
+ }
}
}
if (!isStale) {
- return { decorations: mapped };
+ const mapped = prev.decorations?.map(tr.mapping, tr.doc);
+ return {
+ decorations: mapped,
+ tableHeight: tableMap.height,
+ tableNodePos: table.pos,
+ };
}
+ // recreate all decorations
const decorations: Decoration[] = [];
for (let row = 0; row < tableMap.height; row++) {
@@ -61,7 +77,11 @@ export const TableRowDragHandlePlugin = (editor: Editor): Plugin<TableRowDragHan
decorations.push(Decoration.widget(pos, () => dragHandleComponent.element));
}
- return { decorations: DecorationSet.create(newState.doc, decorations) };
+ return {
+ decorations: DecorationSet.create(newState.doc, decorations),
+ tableHeight: tableMap.height,
+ tableNodePos: table.pos,
+ };
},
},
props: {
diff --git a/packages/editor/src/core/plugins/drag-handle.ts b/packages/editor/src/core/plugins/drag-handle.ts
index 5d05f80fc8..b525759d95 100644
--- a/packages/editor/src/core/plugins/drag-handle.ts
+++ b/packages/editor/src/core/plugins/drag-handle.ts
@@ -379,7 +379,9 @@ const handleNodeSelection = (
let draggedNodePos = nodePosAtDOM(node, view, options);
if (draggedNodePos == null || draggedNodePos < 0) return;
- if (node.matches("blockquote")) {
+ if (node.matches("table")) {
+ draggedNodePos = draggedNodePos - 2;
+ } else if (node.matches("blockquote")) {
draggedNodePos = nodePosAtDOMForBlockQuotes(node, view);
if (draggedNodePos === null || draggedNodePos === undefined) return;
} else {