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