@@ -472,13 +472,74 @@ describe("composer rich text document model", () => {
472472 "> **bold** and @README.md inside" ,
473473 "> - looks like a list but stays quote text" ,
474474 "> > nested stays literal inside the quote" ,
475- "before\n> quoted\nafter " ,
475+ "before\n> quoted" ,
476476 "> quote\n\n> another" ,
477477 "- item\n> quote after list" ,
478+ "> quoted\n\ncomment" ,
479+ "> line one\n> line two\n\ncomment" ,
478480 ] ) ( "round-trips the quote %s through a real ProseMirror document" , ( value ) => {
479481 expect ( roundTrip ( value ) . value ) . toBe ( value ) ;
480482 } ) ;
481483
484+ describe ( "a paragraph after a quote" , ( ) => {
485+ const paragraph = ( text ?: string ) => ( {
486+ type : "paragraph" ,
487+ ...( text ? { content : [ { type : "text" , text } ] } : { } ) ,
488+ } ) ;
489+ const quote = ( ...lines : string [ ] ) => ( {
490+ type : "blockquote" ,
491+ attrs : { prefix : "> " } ,
492+ content : lines . map ( ( line ) => paragraph ( line ) ) ,
493+ } ) ;
494+ const serialize = ( ...content : object [ ] ) => {
495+ const doc = ProseMirrorNode . fromJSON ( schema , { type : "doc" , content } ) ;
496+ doc . check ( ) ;
497+ return { doc, map : serializeEditorDoc ( doc ) } ;
498+ } ;
499+
500+ it ( "is written after a blank line, or Markdown folds it into the quote" , ( ) => {
501+ expect ( serialize ( quote ( "quoted" ) , paragraph ( "Comment to it" ) ) . map . value ) . toBe (
502+ "> quoted\n\nComment to it" ,
503+ ) ;
504+ expect ( serialize ( quote ( "a" , "b" ) , paragraph ( "comment" ) ) . map . value ) . toBe (
505+ "> a\n> b\n\ncomment" ,
506+ ) ;
507+ } ) ;
508+
509+ it ( "does not double up on the empty line the user left themselves" , ( ) => {
510+ expect ( serialize ( quote ( "quoted" ) , paragraph ( ) , paragraph ( "Comment to it" ) ) . map . value ) . toBe (
511+ "> quoted\n\nComment to it" ,
512+ ) ;
513+ } ) ;
514+
515+ it ( "settles on the blank line when a draft glued it to the quote" , ( ) => {
516+ const settled = "before\n> quoted\n\nafter" ;
517+ expect ( roundTrip ( "before\n> quoted\nafter" ) . value ) . toBe ( settled ) ;
518+ expect ( roundTrip ( settled ) . value ) . toBe ( settled ) ;
519+ } ) ;
520+
521+ it . each ( [ "# Heading" , "- item" , "3. item" , "---" , "```\ncode\n```" ] ) (
522+ "leaves %s on the next line, since it opens its own block" ,
523+ ( next ) => {
524+ const value = `> quoted\n${ next } ` ;
525+ expect ( roundTrip ( value ) . value ) . toBe ( value ) ;
526+ } ,
527+ ) ;
528+
529+ it ( "keeps every offset mapped through the blank line" , ( ) => {
530+ const { doc, map } = serialize ( quote ( "quoted" ) , paragraph ( "Comment" ) ) ;
531+ for ( let flat = 0 ; flat <= map . docLength ; flat += 1 ) {
532+ expect ( collapsedToFlat ( map , flatToCollapsed ( map , flat ) ) ) . toBe ( flat ) ;
533+ }
534+ // The caret on the end of the quote stays on it, and the blank line is
535+ // not a place to type: it clamps to the start of the comment.
536+ expect ( flatToCollapsed ( map , "quoted" . length ) ) . toBe ( "> quoted" . length ) ;
537+ expect ( collapsedToFlat ( map , "> quoted\n" . length ) ) . toBe ( "quoted" . length + 1 ) ;
538+ expect ( flatToCollapsed ( map , "quoted" . length + 1 ) ) . toBe ( "> quoted\n\n" . length ) ;
539+ expect ( flatToPm ( map , "quoted" . length + 1 ) ) . toBe ( doc . child ( 0 ) . nodeSize + 1 ) ;
540+ } ) ;
541+ } ) ;
542+
482543 it . each ( [
483544 "---" ,
484545 "***" ,
0 commit comments