From 8300fad52b7d80f291d3e607ebfd66bc7c2d297a Mon Sep 17 00:00:00 2001 From: Suwijak Chaipipat Date: Thu, 22 Sep 2016 22:57:33 +0700 Subject: [PATCH] Prevent backspace to move selection into table-cell (#345) --- examples/tables/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/examples/tables/index.js b/examples/tables/index.js index 82ca34111..18fa6c62c 100644 --- a/examples/tables/index.js +++ b/examples/tables/index.js @@ -100,6 +100,20 @@ class Tables extends React.Component { */ 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 switch (data.key) { case 'backspace': return this.onBackspace(e, state)