diff --git a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/constants.js b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/constants.js index 318b803a1c..88352f3c23 100644 --- a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/constants.js +++ b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/constants.js @@ -17,10 +17,10 @@ export const NEW_CONTROLS = [ {label: 'OL', style: 'ordered-list-item', className: 'styleButtonOL', hideLabel: true, handler: 'addOlBlock', text: '1. innerText' }, ], [ - {label: '<>', style: 'code-block', handler: 'addEntity', text: '```innerText```' }, + {label: '<>', style: 'code-block', handler: 'addSimpleBlock', text: '```innerText```' }, {label: 'img', style: 'IMG', className: 'styleButtonImg', hideLabel: true, handler: 'addLinkMediaBlockWithSelection', text: '![innerText](link)' }, {label: 'Link', style: 'LINK', className: 'styleButtonLink',hideLabel: true, handler: 'addEntity', text: '[innerText](link)' }, - {label: 'quotes', style: 'blockquote', className: 'styleButtonBlockQuote', hideLabel: true, handler: 'addEntity', text: '> innerText' }, + {label: 'quotes', style: 'blockquote', className: 'styleButtonBlockQuote', hideLabel: true, handler: 'addSimpleBlock', text: '> innerText' }, ], ]; diff --git a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/helpers.js b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/helpers.js index 621aa09b38..41fb61059c 100644 --- a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/helpers.js +++ b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/helpers.js @@ -29,12 +29,6 @@ export function getInnerText(style) { case 'UNDERLINE': innerText = '__text underlined__'; break; - case 'code-block': - innerText = '```code block```'; - break; - case 'blockquote': - innerText = '> quotes'; - break; case 'LINK': innerText = '[text](link)'; break; diff --git a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/index.js b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/index.js index 1fb7f1d018..25772fc33b 100644 --- a/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/index.js +++ b/packages/strapi-helper-plugin/lib/src/components/Wysiwyg/index.js @@ -243,6 +243,18 @@ class Wysiwyg extends React.Component { .set('selectionAfter', contentState.getSelectionAfter()) ) + addSimpleBlock = (content, style) => { + const selectedText = this.getSelectedText(); + const defaultContent = style === 'code-block' ? 'code block' : 'quote'; + const innerContent = selectedText === '' ? replace(content, 'innerText', defaultContent) : replace(content, 'innerText', selectedText); + const newBlock = this.createNewBlock(innerContent); + const newContentState = this.createNewContentStateFromBlock(newBlock); + const newEditorState = this.createNewEditorState(newContentState, innerContent); + + return this.setState({ editorState: EditorState.moveFocusToEnd(newEditorState) }); + } + + addLinkMediaBlockWithSelection = () => { const selectedText = this.getSelectedText(); const link = selectedText === '' ? '![text](link)' : `![text](${selectedText})`; @@ -384,6 +396,7 @@ class Wysiwyg extends React.Component { addEntity: this.addEntity, addLinkMediaBlockWithSelection: this.addLinkMediaBlockWithSelection, addOlBlock: this.addOlBlock, + addSimpleBlock: this.addSimpleBlock, addUlBlock: this.addUlBlock, }} onToggle={this.toggleInlineStyle}