mirror of
https://github.com/marktext/marktext.git
synced 2025-05-03 01:40:13 +08:00
parent
471e2381e2
commit
1c42555a10
@ -76,6 +76,7 @@ const pasteCtrl = ContentState => {
|
|||||||
const startBlock = this.getBlock(start.key)
|
const startBlock = this.getBlock(start.key)
|
||||||
const endBlock = this.getBlock(end.key)
|
const endBlock = this.getBlock(end.key)
|
||||||
const parent = this.getParent(startBlock)
|
const parent = this.getParent(startBlock)
|
||||||
|
|
||||||
if (start.key !== end.key) {
|
if (start.key !== end.key) {
|
||||||
this.cutHandler()
|
this.cutHandler()
|
||||||
return this.pasteHandler(event, type)
|
return this.pasteHandler(event, type)
|
||||||
@ -287,19 +288,31 @@ const pasteCtrl = ContentState => {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
if (firstFragment.type === 'p') {
|
if (firstFragment.type === 'p') {
|
||||||
|
if (/^h\d$/.test(startBlock.type)) {
|
||||||
|
// handle paste into header
|
||||||
|
startBlock.text += firstFragment.children[0].text
|
||||||
|
if (firstFragment.children.length > 1) {
|
||||||
|
const newParagraph = this.createBlock('p')
|
||||||
|
firstFragment.children.slice(1).forEach(line => {
|
||||||
|
this.appendChild(newParagraph, line)
|
||||||
|
})
|
||||||
|
this.insertAfter(newParagraph, startBlock)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
startBlock.text += firstFragment.children[0].text
|
startBlock.text += firstFragment.children[0].text
|
||||||
firstFragment.children.slice(1).forEach(line => {
|
firstFragment.children.slice(1).forEach(line => {
|
||||||
if (startBlock.functionType) line.functionType = startBlock.functionType
|
if (startBlock.functionType) line.functionType = startBlock.functionType
|
||||||
if (startBlock.lang) line.lang = startBlock.lang
|
if (startBlock.lang) line.lang = startBlock.lang
|
||||||
this.appendChild(parent, line)
|
this.appendChild(parent, line)
|
||||||
})
|
})
|
||||||
|
}
|
||||||
} else if (/^h\d$/.test(firstFragment.type)) {
|
} else if (/^h\d$/.test(firstFragment.type)) {
|
||||||
startBlock.text += firstFragment.text.split(/\s+/)[1]
|
startBlock.text += firstFragment.text.split(/\s+/)[1]
|
||||||
} else {
|
} else {
|
||||||
startBlock.text += firstFragment.text
|
startBlock.text += firstFragment.text
|
||||||
}
|
}
|
||||||
|
|
||||||
let target = parent
|
let target = /^h\d$/.test(startBlock.type) ? startBlock : parent
|
||||||
tailFragments.forEach(block => {
|
tailFragments.forEach(block => {
|
||||||
this.insertAfter(block, target)
|
this.insertAfter(block, target)
|
||||||
target = block
|
target = block
|
||||||
|
Loading…
Reference in New Issue
Block a user