1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-22 15:02:51 +02:00

Prevent backspace to move selection into table-cell (#345)

This commit is contained in:
Suwijak Chaipipat
2016-09-22 22:57:33 +07:00
committed by Ian Storm Taylor
parent 447a6aace4
commit 8300fad52b

View File

@@ -100,6 +100,20 @@ class Tables extends React.Component {
*/ */
onKeyDown = (e, data, state) => { onKeyDown = (e, data, state) => {
const { document, selection } = state
const { startKey } = selection
const startNode = document.getDescendant(startKey)
if (selection.isAtStartOf(startNode)) {
const previous = document.getPreviousText(startNode)
const prevBlock = document.getClosestBlock(previous)
if (prevBlock.type == 'table-cell') {
e.preventDefault()
return state
}
}
if (state.startBlock.type != 'table-cell') return if (state.startBlock.type != 'table-cell') return
switch (data.key) { switch (data.key) {
case 'backspace': return this.onBackspace(e, state) case 'backspace': return this.onBackspace(e, state)