@@ -1028,6 +1028,56 @@ describe("inline code entry", () => {
10281028 }
10291029 }
10301030
1031+ it . each ( [ "" , "this is a " ] ) (
1032+ "formats code after %j when the opening backtick is typed last" ,
1033+ ( prefix ) => {
1034+ const editor = editorFor ( ) ;
1035+ type ( editor , `${ prefix } test\` after` ) ;
1036+ editor . commands . setTextSelection ( prefix . length + 1 ) ;
1037+ type ( editor , "`" ) ;
1038+
1039+ expect ( editor . state . doc . textContent ) . toBe ( `${ prefix } test after` ) ;
1040+ expect ( serializeEditorDoc ( editor . state . doc ) . value ) . toBe ( `${ prefix } \`test\` after` ) ;
1041+ expect ( editor . state . selection . from ) . toBe ( prefix . length + 1 ) ;
1042+ type ( editor , "new " ) ;
1043+ expect ( serializeEditorDoc ( editor . state . doc ) . value ) . toBe ( `${ prefix } \`new test\` after` ) ;
1044+ editor . commands . setTextSelection ( editor . state . doc . content . size - 1 ) ;
1045+ type ( editor , " plain" ) ;
1046+ expect ( serializeEditorDoc ( editor . state . doc ) . value ) . toBe ( `${ prefix } \`new test\` after plain` ) ;
1047+ const formatted = editor . state . doc . toJSON ( ) ;
1048+ let undos = 0 ;
1049+ while ( editor . commands . undo ( ) ) undos += 1 ;
1050+ expect ( undos ) . toBeGreaterThan ( 0 ) ;
1051+ expect ( editor . state . doc . textContent ) . toBe ( "" ) ;
1052+ for ( let i = 0 ; i < undos ; i += 1 ) expect ( editor . commands . redo ( ) ) . toBe ( true ) ;
1053+ expect ( editor . state . doc . toJSON ( ) ) . toEqual ( formatted ) ;
1054+ } ,
1055+ ) ;
1056+
1057+ it . each ( [
1058+ { name : "doubled closing ticks" , text : "test``" } ,
1059+ { name : "a code block" , text : "test`" , block : "codeBlock" } ,
1060+ { name : "bold text" , text : "test`" , mark : "bold" } ,
1061+ { name : "existing inline code" , text : "test`" , mark : "code" } ,
1062+ ] ) ( "keeps an opening tick literal before $name" , ( { text, block, mark } ) => {
1063+ const editor = editorFor ( block , mark ) ;
1064+ type ( editor , text ) ;
1065+ editor . commands . setTextSelection ( 1 ) ;
1066+ type ( editor , "`" ) ;
1067+ expect ( editor . state . doc . textContent ) . toBe ( `\`${ text } ` ) ;
1068+ } ) ;
1069+
1070+ it . each ( [ "hardBreak" , "composer-mention" ] ) ( "does not pair ticks across a %s" , ( nodeType ) => {
1071+ const editor = editorFor ( ) ;
1072+ type ( editor , "before" ) ;
1073+ editor . commands . insertContent ( { type : nodeType } ) ;
1074+ type ( editor , "after`" ) ;
1075+ editor . commands . setTextSelection ( 1 ) ;
1076+ type ( editor , "`" ) ;
1077+ expect ( editor . state . doc . firstChild ?. firstChild ?. marks ) . toEqual ( [ ] ) ;
1078+ expect ( editor . state . doc . textContent ) . toBe ( "`beforeafter`" ) ;
1079+ } ) ;
1080+
10311081 it . each ( [ "" , "prefix " , "@README.md" ] ) (
10321082 "formats a filled pair after %j, leaves following text plain, and keeps the normal input rule" ,
10331083 ( prefix ) => {
0 commit comments