@@ -17,16 +17,26 @@ const changeCurrentInlineStyle = (editorState, matchArr, style) => {
17
17
focusOffset,
18
18
} ) ;
19
19
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 ;
22
28
29
+ const inlineStyles = [ ] ;
23
30
let newContentState = currentContent ;
24
31
25
32
// remove markdown delimiter at end
26
33
newContentState = Modifier . removeRange (
27
34
newContentState ,
28
35
wordSelection . merge ( {
29
- anchorOffset : wordSelection . getFocusOffset ( ) - markdownCharacterLength ,
36
+ anchorOffset :
37
+ wordSelection . getFocusOffset ( ) -
38
+ markdownCharacterLength -
39
+ matchTerminatorLength ,
30
40
} )
31
41
) ;
32
42
@@ -50,11 +60,22 @@ const changeCurrentInlineStyle = (editorState, matchArr, style) => {
50
60
newContentState ,
51
61
wordSelection . merge ( {
52
62
anchorOffset : index ,
53
- focusOffset : focusOffset - markdownCharacterLength * 2 ,
63
+ focusOffset :
64
+ focusOffset - markdownCharacterLength * 2 - matchTerminatorLength ,
54
65
} ) ,
55
66
style
56
67
) ;
57
68
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
+
58
79
const newEditorState = EditorState . push (
59
80
editorState ,
60
81
newContentState ,
0 commit comments