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
this.insertAfter(activeBlock, anchorBlock)
}
if (activeBlock) {
event.preventDefault()
const offset = 0
@ -200,7 +199,8 @@ const arrowCtrl = ContentState => {
return this.render()
}
} else if (
}
if (
(preBlock && preBlock.type === 'pre' && event.key === EVENT_KEYS.ArrowUp) ||
(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 startBlock = this.getBlock(start.key)
const endBlock = this.getBlock(end.key)
// bugfix: #67 problem 1
// fix: #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) {
// fix: unexpect remove all editor html. #67 problem 4
if (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)
if (start.key !== end.key) {
this.removeBlocks(startBlock, endBlock)
}
let newBlock = this.getNextSibling(startBlock)
if (!newBlock) {
this.blocks = [this.createBlock()]
newBlock = this.blocks[0]
}
const key = newBlock.key
const offset = 0
@ -100,11 +99,11 @@ const backspaceCtrl = ContentState => {
}
return this.render()
}
if (start.key !== end.key) {
event.preventDefault()
const key = start.key
const offset = start.offset
const startRemainText = startBlock.type === 'pre'
? startBlock.text.substring(0, start.offset - 1)
: startBlock.text.substring(0, start.offset)
@ -171,7 +170,7 @@ const backspaceCtrl = ContentState => {
if (block.type === 'pre') {
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)) {
const anchorBlock = block.functionType === 'html' ? this.getParent(this.getParent(block)) : block
event.preventDefault()

View File

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