@@ -11,7 +11,7 @@ class MarkdownEditor extends React.Component {
1111
1212 this . escapeFromEditor = [ 'Control' , 'w' ]
1313
14- this . supportMdWordBold = [ 'Control' , ':' ]
14+ this . supportMdSelectionBold = [ 'Control' , ':' ]
1515
1616 this . state = {
1717 status : 'PREVIEW' ,
@@ -169,19 +169,26 @@ class MarkdownEditor extends React.Component {
169169 if ( ! this . state . isLocked && this . state . status === 'CODE' && this . escapeFromEditor . every ( isNoteHandlerKey ) ) {
170170 document . activeElement . blur ( )
171171 }
172- if ( this . supportMdWordBold . every ( isNoteHandlerKey ) ) {
173- this . addMdBetweenWord ( '**' )
172+ if ( this . supportMdSelectionBold . every ( isNoteHandlerKey ) ) {
173+ this . addMdAroundWord ( '**' )
174174 }
175175 }
176176
177- addMdBetweenWord ( mdElement ) {
177+ addMdAroundWord ( mdElement ) {
178+ if ( this . refs . code . editor . getSelection ( ) ) {
179+ return this . addMdAroundSelection ( mdElement )
180+ }
178181 const currentCaret = this . refs . code . editor . getCursor ( )
179182 const word = this . refs . code . editor . findWordAt ( currentCaret )
180183 const cmDoc = this . refs . code . editor . getDoc ( )
181184 cmDoc . replaceRange ( mdElement , word . anchor )
182185 cmDoc . replaceRange ( mdElement , { line : word . head . line , ch : word . head . ch + mdElement . length } )
183186 }
184187
188+ addMdAroundSelection ( mdElement ) {
189+ this . refs . code . editor . replaceSelection ( `${ mdElement } ${ this . refs . code . editor . getSelection ( ) } ${ mdElement } ` )
190+ }
191+
185192 handleKeyUp ( e ) {
186193 const keyPressed = Object . assign ( this . state . keyPressed , {
187194 [ e . key ] : false
0 commit comments