fix: #522 paste bug when paste into empty line

This commit is contained in:
Jocs 2018-10-25 21:19:12 +08:00
parent 3c52ecf87a
commit f0c691ea98
2 changed files with 3 additions and 3 deletions

View File

@ -133,7 +133,7 @@ const enterCtrl = ContentState => {
} }
} }
const { key } = newBlock const { key } = newBlock.children[0]
const offset = 0 const offset = 0
this.cursor = { this.cursor = {
start: { key, offset }, start: { key, offset },

View File

@ -70,7 +70,6 @@ const pasteCtrl = ContentState => {
event.preventDefault() event.preventDefault()
const text = event.clipboardData.getData('text/plain') const text = event.clipboardData.getData('text/plain')
let html = event.clipboardData.getData('text/html') let html = event.clipboardData.getData('text/html')
html = this.standardizeHTML(html) html = this.standardizeHTML(html)
const copyType = this.checkCopyType(html, text) const copyType = this.checkCopyType(html, text)
const { start, end } = this.cursor const { start, end } = this.cursor
@ -97,7 +96,6 @@ const pasteCtrl = ContentState => {
const blockText = startBlock.text const blockText = startBlock.text
const prePartText = blockText.substring(0, start.offset) const prePartText = blockText.substring(0, start.offset)
const postPartText = blockText.substring(end.offset) const postPartText = blockText.substring(end.offset)
console.log(prePartText, '|', postPartText)
const textList = text.split(LINE_BREAKS_REG) const textList = text.split(LINE_BREAKS_REG)
if (textList.length > 1) { if (textList.length > 1) {
textList.forEach((line, i) => { textList.forEach((line, i) => {
@ -190,7 +188,9 @@ const pasteCtrl = ContentState => {
return getLastBlock(lastBlock.children) return getLastBlock(lastBlock.children)
} }
} }
const lastBlock = getLastBlock(stateFragments) const lastBlock = getLastBlock(stateFragments)
let key = lastBlock.key let key = lastBlock.key
let offset = lastBlock.text.length let offset = lastBlock.text.length
lastBlock.text += cacheText lastBlock.text += cacheText