fix: Guard table content changing mid-drag (#12476)

* fix: Guard table content changing mid-drag

* docs
This commit is contained in:
Tom Moor
2026-05-26 20:18:23 -04:00
committed by GitHub
parent 62788c45e0
commit 64ccdca0d7
2 changed files with 36 additions and 14 deletions
+18 -7
View File
@@ -132,13 +132,24 @@ function setupColumnDragTracking(
document.body.classList.remove(EditorStyleHelper.tableDragging);
if (isDragging && currentToIndex !== fromIndex && isInTable(view.state)) {
const moved = moveTableColumn({ from: fromIndex, to: currentToIndex })(
view.state,
view.dispatch
);
if (moved) {
// Select the column at its new position
selectColumn(currentToIndex)(view.state, view.dispatch);
// Verify both indices are still valid for the current table. The document
// may have changed during the drag (e.g. collaborative editing)
const currentCols = getCellsInRow(0)(view.state);
const inBounds =
fromIndex >= 0 &&
fromIndex < currentCols.length &&
currentToIndex >= 0 &&
currentToIndex < currentCols.length;
if (inBounds) {
const moved = moveTableColumn({ from: fromIndex, to: currentToIndex })(
view.state,
view.dispatch
);
if (moved) {
// Select the column at its new position
selectColumn(currentToIndex)(view.state, view.dispatch);
}
}
}
+18 -7
View File
@@ -120,13 +120,24 @@ function setupRowDragTracking(
document.body.classList.remove(EditorStyleHelper.tableDragging);
if (isDragging && currentToIndex !== fromIndex && isInTable(view.state)) {
const moved = moveTableRow({ from: fromIndex, to: currentToIndex })(
view.state,
view.dispatch
);
if (moved) {
// Select the row at its new position
selectRow(currentToIndex)(view.state, view.dispatch);
// Verify both indices are still valid for the current table. The document
// may have changed during the drag (e.g. collaborative editing)
const currentRows = getRowsInTable(view.state);
const inBounds =
fromIndex >= 0 &&
fromIndex < currentRows.length &&
currentToIndex >= 0 &&
currentToIndex < currentRows.length;
if (inBounds) {
const moved = moveTableRow({ from: fromIndex, to: currentToIndex })(
view.state,
view.dispatch
);
if (moved) {
// Select the row at its new position
selectRow(currentToIndex)(view.state, view.dispatch);
}
}
}