fix: whole selection can not be canceled (#962)

* fix: whole selection can not be canceled

* add null check in clickCtrl
This commit is contained in:
Ran Luo 2019-04-23 23:41:55 +08:00 committed by GitHub
parent 413b3f92db
commit c4664546bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 16 deletions

View File

@ -156,7 +156,9 @@ const backspaceCtrl = ContentState => {
// 2. select table from the first cell to the last cell, press backsapce.
if (/th/.test(startBlock.type) && start.offset === 0 && !startBlock.preSibling) {
if (
end.offset === endBlock.text.length && startOutmostBlock === endOutmostBlock && !endBlock.nextSibling && !maybeLastRow.nextSibling ||
end.offset === endBlock.text.length &&
startOutmostBlock === endOutmostBlock &&
!endBlock.nextSibling && !maybeLastRow.nextSibling ||
startOutmostBlock !== endOutmostBlock
) {
event.preventDefault()

View File

@ -107,19 +107,6 @@ const clickCtrl = ContentState => {
eventCenter.dispatch('muya-format-picker', { reference, formats })
}
// bugfix: figure block click
if (block.type === 'figure' && block.functionType === 'table') {
// first cell in thead
const cursorBlock = block.children[1].children[0].children[0].children[0]
const offset = cursorBlock.text.length
const key = cursorBlock.key
this.cursor = {
start: { key, offset },
end: { key, offset }
}
needRender = true
}
// update '```xxx' to code block when you click other place or use press arrow key.
if (block && start.key !== this.cursor.start.key) {
const oldBlock = this.getBlock(this.cursor.start.key)
@ -137,9 +124,22 @@ const clickCtrl = ContentState => {
}
const needMarkedUpdate = this.checkNeedRender(this.cursor) || this.checkNeedRender({ start, end })
this.cursor = { start, end }
if (needMarkedUpdate || needRender) {
if (needRender) {
this.cursor = { start, end }
return this.partialRender()
} else if (needMarkedUpdate) {
// Fix: whole select can not be canceled #613
requestAnimationFrame(() => {
const cursor = selection.getCursorRange()
if (!cursor.start || !cursor.end) {
return
}
this.cursor = cursor
return this.partialRender()
})
} else {
this.cursor = { start, end }
}
}
}