@@ -17,24 +17,40 @@ 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
33
43
let afterSelection = newContentState . getSelectionAfter ( ) ;
34
44
35
45
afterSelection = afterSelection . merge ( {
36
- anchorOffset : afterSelection . getFocusOffset ( ) - markdownCharacterLength ,
37
- focusOffset : afterSelection . getFocusOffset ( ) - markdownCharacterLength ,
46
+ anchorOffset :
47
+ afterSelection . getFocusOffset ( ) -
48
+ markdownCharacterLength -
49
+ matchTerminatorLength ,
50
+ focusOffset :
51
+ afterSelection . getFocusOffset ( ) -
52
+ markdownCharacterLength -
53
+ matchTerminatorLength ,
38
54
} ) ;
39
55
40
56
// remove markdown delimiter at start
@@ -50,11 +66,22 @@ const changeCurrentInlineStyle = (editorState, matchArr, style) => {
50
66
newContentState ,
51
67
wordSelection . merge ( {
52
68
anchorOffset : index ,
53
- focusOffset : focusOffset - markdownCharacterLength * 2 ,
69
+ focusOffset :
70
+ focusOffset - markdownCharacterLength * 2 - matchTerminatorLength ,
54
71
} ) ,
55
72
style
56
73
) ;
57
74
75
+ // Check if a terminator exists and re-add it after the styled text
76
+ if ( matchTerminatorLength > 0 ) {
77
+ newContentState = Modifier . insertText (
78
+ newContentState ,
79
+ afterSelection ,
80
+ matchTerminatorLength
81
+ ) ;
82
+ afterSelection = newContentState . getSelectionAfter ( ) ;
83
+ }
84
+
58
85
const newEditorState = EditorState . push (
59
86
editorState ,
60
87
newContentState ,
0 commit comments