Allow pasting text into the code block language text-box (#598)

This commit is contained in:
Felix Häusler 2018-12-09 04:25:00 +01:00 committed by Ran Luo
parent 7ebb04d48e
commit a77b9ab6f1
3 changed files with 52 additions and 1 deletions

17
.github/CHANGELOG.md vendored
View File

@ -1,3 +1,20 @@
### [unreleased]
**:cactus:Feature**
- Added an error handler
**:butterfly:Optimization**
**:beetle:Bug fix**
- Fix dark preview box background color (#587)
- Use white PDF background color (#583)
- Fix document printing
- Restore default Mark Text style after exporting/printing
- Prevent enter key as language identifier (#569)
- Allow pasting text into the code block language text-box (#553)
### 0.13.65
**:butterfly:Optimization**

View File

@ -12,7 +12,8 @@ const clickCtrl = ContentState => {
start.key === end.key &&
start.offset !== end.offset &&
HAS_TEXT_BLOCK_REG.test(block.type) &&
block.functionType !== 'codeLine'
block.functionType !== 'codeLine' &&
block.functionType !== 'languageInput'
) {
const reference = this.getPositionReference()
const { formats } = this.selectionFormats()

View File

@ -91,6 +91,39 @@ const pasteCtrl = ContentState => {
}
}
// Extract the first line from the language identifier (GH#553)
if (startBlock.type === 'span' && startBlock.functionType === 'languageInput') {
let language = text.trim().match(/^.*$/m)[0] || ''
const oldLanguageLength = startBlock.text.length
let offset = 0
if (start.offset !== 0 || end.offset !== oldLanguageLength) {
const prePartText = startBlock.text.substring(0, start.offset)
const postPartText = startBlock.text.substring(end.offset)
// Expect that the language doesn't contain new lines
language = prePartText + language + postPartText
offset = prePartText.length + language.length
} else {
offset = language.length
}
startBlock.text = language
const key = startBlock.key
this.cursor = {
start: { key, offset },
end: { key, offset }
}
// Hide code picker float box
const { eventCenter } = this.muya
eventCenter.dispatch('muya-code-picker', { reference: null })
// Update code block language and render
this.updateCodeLanguage(startBlock, language)
return
}
if (startBlock.type === 'span' && startBlock.functionType === 'codeLine') {
let referenceBlock = startBlock
const blockText = startBlock.text