mirror of
https://github.com/outline/outline.git
synced 2026-06-13 03:14:59 +03:00
fix: Guard table content changing mid-drag (#12476)
* fix: Guard table content changing mid-drag * docs
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user