fix text selection state (#948)

main
Michael Fix 5 years ago committed by GitHub
parent 622c8a7722
commit b4915060c5

@ -113,13 +113,15 @@ class Carbon extends React.PureComponent {
onSelectionChange = changes => { onSelectionChange = changes => {
if (this.state.selectionAt) { if (this.state.selectionAt) {
const css = [ const css = [
`font-weight: ${changes.bold ? 'bold' : 'initial'}`, changes.bold && `font-weight: ${changes.bold ? 'bold' : 'initial'}`,
`font-style: ${changes.italics ? 'italic' : 'initial'}`, changes.italics && `font-style: ${changes.italics ? 'italic' : 'initial'}`,
`text-decoration: ${changes.underline ? 'underline' : 'initial'}`, changes.underline && `text-decoration: ${changes.underline ? 'underline' : 'initial'}`,
changes.color && `color: ${changes.color} !important` changes.color && `color: ${changes.color} !important`
] ]
.filter(Boolean) .filter(Boolean)
.join('; ') .join('; ')
if (css) {
this.props.editorRef.current.editor.doc.markText( this.props.editorRef.current.editor.doc.markText(
this.state.selectionAt.from, this.state.selectionAt.from,
this.state.selectionAt.to, this.state.selectionAt.to,
@ -127,6 +129,7 @@ class Carbon extends React.PureComponent {
) )
} }
} }
}
render() { render() {
const config = { ...DEFAULT_SETTINGS, ...this.props.config } const config = { ...DEFAULT_SETTINGS, ...this.props.config }

@ -56,9 +56,9 @@ function SelectionEditor({ onChange }) {
useKeyboardListener('Escape', () => setOpen(false)) useKeyboardListener('Escape', () => setOpen(false))
const [state, dispatch] = React.useReducer(reducer, { const [state, dispatch] = React.useReducer(reducer, {
bold: false, bold: null,
italics: false, italics: null,
underline: false, underline: null,
color: null color: null
}) })

Loading…
Cancel
Save