diff --git a/src/editor/contentState/backspaceCtrl.js b/src/editor/contentState/backspaceCtrl.js index dd1568ed..cb58c603 100644 --- a/src/editor/contentState/backspaceCtrl.js +++ b/src/editor/contentState/backspaceCtrl.js @@ -74,10 +74,34 @@ const backspaceCtrl = ContentState => { ContentState.prototype.backspaceHandler = function (event) { const { start, end } = selection.getCursorRange() + const startBlock = this.getBlock(start.key) + const endBlock = this.getBlock(end.key) + // bugfix: #67 problem 1 + if (startBlock.icon) return event.preventDefault() + // fixbug: unexpect remove all editor html. + if (start.key === end.key && startBlock.type === 'figure' && !startBlock.preSibling) { + event.preventDefault() + let newBlock + if (this.blocks.length === 1) { + startBlock.type = 'p' + startBlock.text = '' + startBlock.children = [] + newBlock = startBlock + } else { + this.removeBlock(startBlock) + newBlock = this.getNextSibling(startBlock) + } + const key = newBlock.key + const offset = 0 + this.cursor = { + start: { key, offset }, + end: { key, offset } + } + return this.render() + } + if (start.key !== end.key) { event.preventDefault() - const startBlock = this.getBlock(start.key) - const endBlock = this.getBlock(end.key) const key = start.key const offset = start.offset diff --git a/src/editor/contentState/updateCtrl.js b/src/editor/contentState/updateCtrl.js index facbecf5..9502e618 100644 --- a/src/editor/contentState/updateCtrl.js +++ b/src/editor/contentState/updateCtrl.js @@ -240,6 +240,11 @@ const updateCtrl = ContentState => { ContentState.prototype.updateState = function (event) { const { floatBox } = this const { start, end } = selection.getCursorRange() + const key = start.key + const block = this.getBlock(key) + // bugfix: #67 problem 1 + if (block.icon) return event.preventDefault() + const { start: oldStart, end: oldEnd } = this.cursor if (event.type === 'keyup' && (event.key === 'ArrowUp' || event.key === 'ArrowDown') && floatBox.show) { @@ -291,12 +296,10 @@ const updateCtrl = ContentState => { } return } - const key = start.key + const oldKey = lastCursor ? lastCursor.start.key : null const paragraph = document.querySelector(`#${key}`) let text = getTextContent(paragraph, [ CLASS_OR_ID['AG_MATH_RENDER'] ]) - const block = this.getBlock(key) - let needRender = false if (event.type === 'click' && block.type === 'figure' && block.functionType === 'table') { // first cell in thead