fix: #67 problem 4

This commit is contained in:
Jocs 2018-04-16 14:58:01 +08:00
parent 7e447e7c82
commit 52473f5768
3 changed files with 17 additions and 23 deletions

View File

@ -182,7 +182,6 @@ const arrowCtrl = ContentState => {
activeBlock.temp = true activeBlock.temp = true
this.insertAfter(activeBlock, anchorBlock) this.insertAfter(activeBlock, anchorBlock)
} }
if (activeBlock) { if (activeBlock) {
event.preventDefault() event.preventDefault()
const offset = 0 const offset = 0
@ -200,7 +199,8 @@ const arrowCtrl = ContentState => {
return this.render() return this.render()
} }
} else if ( }
if (
(preBlock && preBlock.type === 'pre' && event.key === EVENT_KEYS.ArrowUp) || (preBlock && preBlock.type === 'pre' && event.key === EVENT_KEYS.ArrowUp) ||
(preBlock && preBlock.type === 'pre' && event.key === EVENT_KEYS.ArrowLeft && left === 0) (preBlock && preBlock.type === 'pre' && event.key === EVENT_KEYS.ArrowLeft && left === 0)
) { ) {

View File

@ -76,20 +76,19 @@ const backspaceCtrl = ContentState => {
const { start, end } = selection.getCursorRange() const { start, end } = selection.getCursorRange()
const startBlock = this.getBlock(start.key) const startBlock = this.getBlock(start.key)
const endBlock = this.getBlock(end.key) const endBlock = this.getBlock(end.key)
// bugfix: #67 problem 1 // fix: #67 problem 1
if (startBlock.icon) return event.preventDefault() if (startBlock.icon) return event.preventDefault()
// fixbug: unexpect remove all editor html. // fix: unexpect remove all editor html. #67 problem 4
if (start.key === end.key && startBlock.type === 'figure' && !startBlock.preSibling) { if (startBlock.type === 'figure' && !startBlock.preSibling) {
event.preventDefault() event.preventDefault()
let newBlock this.removeBlock(startBlock)
if (this.blocks.length === 1) { if (start.key !== end.key) {
startBlock.type = 'p' this.removeBlocks(startBlock, endBlock)
startBlock.text = '' }
startBlock.children = [] let newBlock = this.getNextSibling(startBlock)
newBlock = startBlock if (!newBlock) {
} else { this.blocks = [this.createBlock()]
this.removeBlock(startBlock) newBlock = this.blocks[0]
newBlock = this.getNextSibling(startBlock)
} }
const key = newBlock.key const key = newBlock.key
const offset = 0 const offset = 0
@ -100,11 +99,11 @@ const backspaceCtrl = ContentState => {
} }
return this.render() return this.render()
} }
if (start.key !== end.key) { if (start.key !== end.key) {
event.preventDefault() event.preventDefault()
const key = start.key const key = start.key
const offset = start.offset const offset = start.offset
const startRemainText = startBlock.type === 'pre' const startRemainText = startBlock.type === 'pre'
? startBlock.text.substring(0, start.offset - 1) ? startBlock.text.substring(0, start.offset - 1)
: startBlock.text.substring(0, start.offset) : startBlock.text.substring(0, start.offset)
@ -171,7 +170,7 @@ const backspaceCtrl = ContentState => {
if (block.type === 'pre') { if (block.type === 'pre') {
const cm = this.codeBlocks.get(id) const cm = this.codeBlocks.get(id)
// if event.preventDefault(), U can not use backspace in language input. // if event.preventDefault(), you can not use backspace in language input.
if (isCursorAtBegin(cm) && onlyHaveOneLine(cm)) { if (isCursorAtBegin(cm) && onlyHaveOneLine(cm)) {
const anchorBlock = block.functionType === 'html' ? this.getParent(this.getParent(block)) : block const anchorBlock = block.functionType === 'html' ? this.getParent(this.getParent(block)) : block
event.preventDefault() event.preventDefault()

View File

@ -1,7 +1,5 @@
import mousetrap from 'mousetrap' import mousetrap from 'mousetrap'
import { import { getUniqueId } from './utils'
getUniqueId
} from './utils'
class EventCenter { class EventCenter {
constructor () { constructor () {
@ -71,10 +69,7 @@ class EventCenter {
} }
// Determine whether the event has been bind // Determine whether the event has been bind
checkHasBind (cTarget, cEvent, cListener, cCapture) { checkHasBind (cTarget, cEvent, cListener, cCapture) {
let i for (const { target, event, listener, capture } of this.events) {
let len = this.events.length
for (i = 0; i < len; i++) {
const { target, event, listener, capture } = this.events[i]
if (target === cTarget && event === cEvent && listener === cListener && capture === cCapture) { if (target === cTarget && event === cEvent && listener === cListener && capture === cCapture) {
return true return true
} }