diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 3540805e..6a906f1a 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -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** diff --git a/src/muya/lib/contentState/clickCtrl.js b/src/muya/lib/contentState/clickCtrl.js index 49b46fdf..1e5caad9 100644 --- a/src/muya/lib/contentState/clickCtrl.js +++ b/src/muya/lib/contentState/clickCtrl.js @@ -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() diff --git a/src/muya/lib/contentState/pasteCtrl.js b/src/muya/lib/contentState/pasteCtrl.js index b02437d9..46c68adb 100644 --- a/src/muya/lib/contentState/pasteCtrl.js +++ b/src/muya/lib/contentState/pasteCtrl.js @@ -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