@@ -75,35 +75,16 @@ class ReactMde extends Component {
7575 * @param {function } command
7676 * @memberOf ReactMde
7777 */
78- handleCommand ( command )
79- {
80- let {
81- value : { text } ,
82- onChange
83- } = this . props ;
84- let textarea = this . refs . textarea ;
85- var newValue = command ( text , getSelection ( textarea ) ) ;
86- onChange ( newValue ) ;
87- }
88-
89- handleBoldCommand ( ) {
90- this . handleCommand ( ReactMdeCommands . makeBold ) ;
91- }
92-
93- handleItalicCommand ( ) {
94- this . handleCommand ( ReactMdeCommands . makeItalic ) ;
95- }
96-
97- handleLinkCommand ( ) {
98- this . handleCommand ( ReactMdeCommands . makeLink ) ;
99- }
100-
101- componentDidMount ( ) {
102- this . handleSelection ( ) ;
103- }
104-
105- componentDidUpdate ( ) {
106- this . handleSelection ( ) ;
78+ getCommandHandler ( command ) {
79+ return function ( ) {
80+ let {
81+ value : { text } ,
82+ onChange
83+ } = this . props ;
84+ let textarea = this . refs . textarea ;
85+ var newValue = command ( text , getSelection ( textarea ) ) ;
86+ onChange ( newValue ) ;
87+ }
10788 }
10889
10990 render ( ) {
@@ -117,11 +98,11 @@ class ReactMde extends Component {
11798 < div className = "react-mde" >
11899 < div className = "mde-header" >
119100 < HeaderGroup >
120- < HeaderItem icon = "bold" onClick = { this . handleBoldCommand . bind ( this ) } />
121- < HeaderItem icon = "italic" onClick = { this . handleItalicCommand . bind ( this ) } />
101+ < HeaderItem icon = "bold" onClick = { this . getCommandHandler ( ReactMdeCommands . makeBold ) . bind ( this ) } />
102+ < HeaderItem icon = "italic" onClick = { this . getCommandHandler ( ReactMdeCommands . makeItalic ) . bind ( this ) } />
122103 </ HeaderGroup >
123104 < HeaderGroup >
124- < HeaderItem icon = "link" onClick = { this . handleLinkCommand . bind ( this ) } />
105+ < HeaderItem icon = "link" onClick = { this . getCommandHandler ( ReactMdeCommands . makeLink ) . bind ( this ) } />
125106 < HeaderItem icon = "quote-right" />
126107 < HeaderItem icon = "picture-o" />
127108 </ HeaderGroup >
@@ -133,6 +114,9 @@ class ReactMde extends Component {
133114 < HeaderItem icon = "at" />
134115 < HeaderItem icon = "bookmark" />
135116 </ HeaderGroup >
117+ < HeaderGroup >
118+ < HeaderItem icon = "star" />
119+ </ HeaderGroup >
136120 </ div >
137121 < div className = "mde-text" >
138122 < textarea onChange = { this . handleValueChange . bind ( this ) } value = { text } ref = "textarea" />
@@ -141,6 +125,14 @@ class ReactMde extends Component {
141125 </ div >
142126 ) ;
143127 }
128+
129+ componentDidMount ( ) {
130+ this . handleSelection ( ) ;
131+ }
132+
133+ componentDidUpdate ( ) {
134+ this . handleSelection ( ) ;
135+ }
144136}
145137
146138export default ReactMde ;
0 commit comments