File tree 2 files changed +27
-2
lines changed
2 files changed +27
-2
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,11 @@ import React, { Component } from 'react';
2
2
import { EditorState } from 'draft-js' ;
3
3
import Editor from 'draft-js-plugins-editor' ;
4
4
import createEmojiPlugin from 'draft-js-emoji-plugin' ;
5
+ import createHighlightPlugin from './highlightPlugin' ;
5
6
import 'draft-js-emoji-plugin/lib/plugin.css'
6
7
8
+ const highlightPlugin = createHighlightPlugin ( ) ;
7
9
const emojiPlugin = createEmojiPlugin ( ) ;
8
-
9
10
const { EmojiSuggestions } = emojiPlugin ;
10
11
11
12
class App extends Component {
@@ -28,7 +29,7 @@ class App extends Component {
28
29
< Editor
29
30
editorState = { this . state . editorState }
30
31
onChange = { this . onChange }
31
- plugins = { [ emojiPlugin ] }
32
+ plugins = { [ highlightPlugin , emojiPlugin ] }
32
33
/>
33
34
< EmojiSuggestions />
34
35
</ div >
Original file line number Diff line number Diff line change
1
+ import { RichUtils } from 'draft-js' ;
2
+
3
+ export default ( ) => {
4
+ return {
5
+ customStyleMap : {
6
+ 'HIGHLIGHT' : {
7
+ background : 'blue' ,
8
+ padding : '0 .3em' ,
9
+ color : '#fff' ,
10
+ }
11
+ } ,
12
+ keyBindingFn : ( e ) => {
13
+ if ( e . metaKey && e . key === 'h' ) {
14
+ return 'highlight' ;
15
+ }
16
+ } ,
17
+ handleKeyCommand : ( command , editorState , { setEditorState } ) => {
18
+ if ( command === 'highlight' ) {
19
+ setEditorState ( RichUtils . toggleInlineStyle ( editorState , 'HIGHLIGHT' ) ) ;
20
+ return true ;
21
+ }
22
+ } ,
23
+ } ;
24
+ } ;
You can’t perform that action at this time.
0 commit comments