From b4915060c51351919032c62a85a3df9744c8ff33 Mon Sep 17 00:00:00 2001 From: Michael Fix Date: Sun, 9 Feb 2020 12:58:12 -0800 Subject: [PATCH] fix text selection state (#948) --- components/Carbon.js | 19 +++++++++++-------- components/SelectionEditor.js | 6 +++--- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/components/Carbon.js b/components/Carbon.js index d827e2c..a337902 100644 --- a/components/Carbon.js +++ b/components/Carbon.js @@ -113,18 +113,21 @@ class Carbon extends React.PureComponent { onSelectionChange = changes => { if (this.state.selectionAt) { const css = [ - `font-weight: ${changes.bold ? 'bold' : 'initial'}`, - `font-style: ${changes.italics ? 'italic' : 'initial'}`, - `text-decoration: ${changes.underline ? 'underline' : 'initial'}`, + changes.bold && `font-weight: ${changes.bold ? 'bold' : 'initial'}`, + changes.italics && `font-style: ${changes.italics ? 'italic' : 'initial'}`, + changes.underline && `text-decoration: ${changes.underline ? 'underline' : 'initial'}`, changes.color && `color: ${changes.color} !important` ] .filter(Boolean) .join('; ') - this.props.editorRef.current.editor.doc.markText( - this.state.selectionAt.from, - this.state.selectionAt.to, - { css } - ) + + if (css) { + this.props.editorRef.current.editor.doc.markText( + this.state.selectionAt.from, + this.state.selectionAt.to, + { css } + ) + } } } diff --git a/components/SelectionEditor.js b/components/SelectionEditor.js index 6a13f4e..2950f2e 100644 --- a/components/SelectionEditor.js +++ b/components/SelectionEditor.js @@ -56,9 +56,9 @@ function SelectionEditor({ onChange }) { useKeyboardListener('Escape', () => setOpen(false)) const [state, dispatch] = React.useReducer(reducer, { - bold: false, - italics: false, - underline: false, + bold: null, + italics: null, + underline: null, color: null })