fix: Allow delete table row and column with mod+backspace

This commit is contained in:
Tom Moor
2024-06-04 21:59:22 -04:00
parent dd4c8c5546
commit 7a32271992
3 changed files with 43 additions and 1 deletions

View File

@@ -8,6 +8,8 @@ import {
tableNodeTypes,
toggleHeader,
addColumn,
deleteRow,
deleteColumn,
} from "prosemirror-tables";
import { chainTransactions } from "../lib/chainTransactions";
import { getCellsInColumn, isHeaderEnabled } from "../queries/table";
@@ -210,6 +212,40 @@ export function addRowBefore({ index }: { index?: number }): Command {
};
}
/**
* A command that deletes the current selected row, if any.
*
* @returns The command
*/
export function deleteRowSelection(): Command {
return (state, dispatch) => {
if (
state.selection instanceof CellSelection &&
state.selection.isRowSelection()
) {
return deleteRow(state, dispatch);
}
return false;
};
}
/**
* A command that deletes the current selected column, if any.
*
* @returns The command
*/
export function deleteColSelection(): Command {
return (state, dispatch) => {
if (
state.selection instanceof CellSelection &&
state.selection.isColSelection()
) {
return deleteColumn(state, dispatch);
}
return false;
};
}
/**
* A command that safely adds a column taking into account any existing heading column on the far
* left of the table, and preventing it moving "into" the table.