Skip to content

Commit

Permalink
Fix WYSIWYG bugs (strapi#7370)
Browse files Browse the repository at this point in the history
* Fixes strapi#7314

Signed-off-by: soupette <cyril.lpz@gmail.com>

* Fixes strapi#4300

Signed-off-by: soupette <cyril.lpz@gmail.com>
Signed-off-by: Gil Fernandes <gil.fernandes@onepointltd.com>
  • Loading branch information
soupette authored and onepointconsulting committed Aug 13, 2020
1 parent 7d86336 commit e387973
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const CONTROLS = [
className: 'underline',
hideLabel: true,
handler: 'addContent',
text: '__textToReplace__',
text: '<u>textToReplace</u>',
},
{
label: 'S',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ export function getBlockContent(style) {
case 'UNDERLINE':
return {
innerContent: 'underlined text',
endReplacer: '_',
startReplacer: '_',
endReplacer: '<u>',
startReplacer: '</u>',
};
case 'LINK':
return {
Expand All @@ -72,7 +72,7 @@ export const getDefaultSelectionOffsets = (
content,
startReplacer,
endReplacer,
initPosition = 0,
initPosition = 0
) => ({
anchorOffset: initPosition + content.length - trimStart(content, startReplacer).length,
focusOffset: initPosition + trimEnd(content, endReplacer).length,
Expand Down Expand Up @@ -104,7 +104,7 @@ export function getKeyCommandData(command) {
style = 'ITALIC';
break;
case 'underline':
content = '__textToReplace__';
content = '<u>textToReplace</u>';
style = 'UNDERLINE';
break;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ class Wysiwyg extends React.Component {
const newContentState = this.createNewContentStateFromBlock(newBlock);
const newEditorState = this.createNewEditorState(newContentState, text);

this.sendData(newEditorState);

return this.setState(
{
editorState: newEditorState,
Expand Down Expand Up @@ -402,6 +404,9 @@ class Wysiwyg extends React.Component {

newEditorState = EditorState.acceptSelection(newEditorState, updatedSelection);

// Update the parent reducer
this.sendData(newEditorState);

return this.setState({
editorState: EditorState.forceSelection(newEditorState, newEditorState.getSelection()),
});
Expand Down Expand Up @@ -711,6 +716,7 @@ class Wysiwyg extends React.Component {
setRef={editor => (this.domEditor = editor)}
stripPastedStyles
tabIndex={this.props.tabIndex}
spellCheck
/>
<input className="editorInput" tabIndex="-1" />
</div>
Expand Down

0 comments on commit e387973

Please sign in to comment.