@@ -202,6 +202,27 @@ function checkReturnForState(config, editorState, ev) {
202202 return newEditorState ;
203203}
204204
205+ const unstickyInlineStyles = ( character , editorState ) => {
206+ const selection = editorState . getSelection ( ) ;
207+ if ( ! selection . isCollapsed ( ) ) return editorState ;
208+
209+ const startOffset = selection . getStartOffset ( ) ;
210+ const content = editorState . getCurrentContent ( ) ;
211+ const block = content . getBlockForKey ( selection . getStartKey ( ) ) ;
212+ const entity = block . getEntityAt ( startOffset - 1 ) ;
213+ if ( entity !== null ) return editorState ;
214+
215+ // If we're currently in a style, but the next character doesn't have a style (or doesn't exist)
216+ // we insert the characters manually without the inline style to "unsticky" them
217+ const style = block . getInlineStyleAt ( startOffset - 1 ) ;
218+ if ( style . size === 0 ) return editorState ;
219+ const nextStyle = block . getInlineStyleAt ( startOffset ) ;
220+ if ( nextStyle . size !== 0 ) return editorState ;
221+
222+ const newContent = Modifier . insertText ( content , selection , character ) ;
223+ return EditorState . push ( editorState , newContent , "insert-characters" ) ;
224+ } ;
225+
205226const defaultConfig = {
206227 renderLanguageSelect : defaultRenderSelect ,
207228 languages : defaultLanguages ,
@@ -348,6 +369,12 @@ const createMarkdownPlugin = (_config = {}) => {
348369 // If we're in a link - don't transform markdown
349370 if ( inLink ( editorState ) ) return "not-handled" ;
350371
372+ const unsticky = unstickyInlineStyles ( character , editorState ) ;
373+ if ( editorState !== unsticky ) {
374+ setEditorState ( unsticky ) ;
375+ return "handled" ;
376+ }
377+
351378 const newEditorState = checkCharacterForState (
352379 config ,
353380 editorState ,
0 commit comments