fix: Allow delete table row and column with mod+backspace
This commit is contained in:
@@ -402,8 +402,8 @@ export class Editor extends React.PureComponent<
|
||||
schema: this.schema,
|
||||
doc,
|
||||
plugins: [
|
||||
...this.plugins,
|
||||
...this.keymaps,
|
||||
...this.plugins,
|
||||
dropCursor({
|
||||
color: this.props.theme.cursor,
|
||||
}),
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -19,6 +19,8 @@ import {
|
||||
createTable,
|
||||
sortTable,
|
||||
setTableAttr,
|
||||
deleteColSelection,
|
||||
deleteRowSelection,
|
||||
} from "../commands/table";
|
||||
import { MarkdownSerializerState } from "../lib/markdown/serializer";
|
||||
import tablesRule from "../rules/tables";
|
||||
@@ -86,6 +88,10 @@ export default class Table extends Node {
|
||||
Tab: chainCommands(goToNextCell(1), addRowAndMoveSelection()),
|
||||
"Shift-Tab": goToNextCell(-1),
|
||||
"Mod-Enter": addRowAndMoveSelection(),
|
||||
"Mod-Backspace": chainCommands(
|
||||
deleteColSelection(),
|
||||
deleteRowSelection()
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user