@@ -23,6 +23,7 @@ import {
2323 formatRange ,
2424} from "../../src/editor/operations" ;
2525import { Formatting } from "../../src/components/views/rooms/MessageComposerFormatBar" ;
26+ import { longestBacktickSequence } from '../../src/editor/deserialize' ;
2627
2728const SERIALIZED_NEWLINE = { "text" : "\n" , "type" : "newline" } ;
2829
@@ -44,6 +45,23 @@ describe('editor/operations: formatting operations', () => {
4445 expect ( model . serializeParts ( ) ) . toEqual ( [ { "text" : "hello _world_!" , "type" : "plain" } ] ) ;
4546 } ) ;
4647
48+ it ( 'works for escaping backticks in between texts' , ( ) => {
49+ const renderer = createRenderer ( ) ;
50+ const pc = createPartCreator ( ) ;
51+ const model = new EditorModel ( [
52+ pc . plain ( "hello ` world!" ) ,
53+ ] , pc , renderer ) ;
54+
55+ const range = model . startRange ( model . positionForOffset ( 0 , false ) ,
56+ model . positionForOffset ( 13 , false ) ) ; // hello ` world
57+
58+ expect ( range . parts [ 0 ] . text . trim ( ) . includes ( "`" ) ) . toBeTruthy ( ) ;
59+ expect ( longestBacktickSequence ( range . parts [ 0 ] . text . trim ( ) ) ) . toBe ( 1 ) ;
60+ expect ( model . serializeParts ( ) ) . toEqual ( [ { "text" : "hello ` world!" , "type" : "plain" } ] ) ;
61+ toggleInlineFormat ( range , "`" . repeat ( longestBacktickSequence ( range . parts [ 0 ] . text . trim ( ) ) + 1 ) ) ;
62+ expect ( model . serializeParts ( ) ) . toEqual ( [ { "text" : "``hello ` world``!" , "type" : "plain" } ] ) ;
63+ } ) ;
64+
4765 it ( 'works for parts of words' , ( ) => {
4866 const renderer = createRenderer ( ) ;
4967 const pc = createPartCreator ( ) ;
0 commit comments