@@ -17,16 +17,26 @@ const changeCurrentInlineStyle = (editorState, matchArr, style) => {
1717    focusOffset, 
1818  } ) ; 
1919
20-   const  inlineStyles  =  [ ] ; 
21-   const  markdownCharacterLength  =  ( matchArr [ 0 ] . length  -  matchArr [ 1 ] . length )  /  2 ; 
20+   // check if match contains a terminator group at the end 
21+   let  matchTerminatorLength  =  0 ; 
22+   if  ( matchArr . length  ==  3 )  { 
23+     matchTerminatorLength  =  matchArr [ 2 ] . length ; 
24+   } 
25+ 
26+   const  markdownCharacterLength  = 
27+     ( matchArr [ 0 ] . length  -  matchArr [ 1 ] . length  -  matchTerminatorLength )  /  2 ; 
2228
29+   const  inlineStyles  =  [ ] ; 
2330  let  newContentState  =  currentContent ; 
2431
2532  // remove markdown delimiter at end 
2633  newContentState  =  Modifier . removeRange ( 
2734    newContentState , 
2835    wordSelection . merge ( { 
29-       anchorOffset : wordSelection . getFocusOffset ( )  -  markdownCharacterLength , 
36+       anchorOffset :
37+         wordSelection . getFocusOffset ( )  - 
38+         markdownCharacterLength  - 
39+         matchTerminatorLength , 
3040    } ) 
3141  ) ; 
3242
@@ -50,11 +60,22 @@ const changeCurrentInlineStyle = (editorState, matchArr, style) => {
5060    newContentState , 
5161    wordSelection . merge ( { 
5262      anchorOffset : index , 
53-       focusOffset : focusOffset  -  markdownCharacterLength  *  2 , 
63+       focusOffset :
64+         focusOffset  -  markdownCharacterLength  *  2  -  matchTerminatorLength , 
5465    } ) , 
5566    style 
5667  ) ; 
5768
69+   // Check if a terminator exists and re-add it after the styled text 
70+   if  ( matchTerminatorLength  >  0 )  { 
71+     newContentState  =  Modifier . insertText ( 
72+       newContentState , 
73+       afterSelection , 
74+       matchArr [ 2 ] 
75+     ) ; 
76+     afterSelection  =  newContentState . getSelectionAfter ( ) ; 
77+   } 
78+ 
5879  const  newEditorState  =  EditorState . push ( 
5980    editorState , 
6081    newContentState , 
0 commit comments