@@ -536,7 +536,7 @@ describe("nativeMarkdownDocumentChunks", () => {
536536 ) . toEqual ( [
537537 {
538538 kind : "rich" ,
539- key : "rich:blockquote:0" ,
539+ key : "rich:blockquote:offset: 0" ,
540540 node : blockquote ,
541541 } ,
542542 ] ) ;
@@ -663,7 +663,7 @@ describe("nativeMarkdownDocumentChunks", () => {
663663 expect ( chunks [ 0 ] ) . toMatchObject ( { kind : "selectable" } ) ;
664664 expect ( chunks [ 1 ] ) . toEqual ( {
665665 kind : "rich" ,
666- key : "rich:code_block:11" ,
666+ key : "rich:code_block:offset: 11" ,
667667 node : document . children ?. [ 1 ] ,
668668 } ) ;
669669 expect ( chunks [ 2 ] ) . toMatchObject ( { kind : "selectable" } ) ;
@@ -700,7 +700,7 @@ describe("nativeMarkdownDocumentChunks", () => {
700700 expect ( nativeMarkdownDocumentChunks ( document ) ) . toEqual ( [
701701 {
702702 kind : "rich" ,
703- key : "rich:list:0" ,
703+ key : "rich:list:offset: 0" ,
704704 node : document . children ?. [ 0 ] ,
705705 } ,
706706 ] ) ;
@@ -728,7 +728,7 @@ describe("nativeMarkdownDocumentChunks", () => {
728728 expect ( chunks [ 0 ] ) . toMatchObject ( { kind : "selectable" } ) ;
729729 expect ( chunks [ 1 ] ) . toEqual ( {
730730 kind : "rich" ,
731- key : "rich:horizontal_rule:1" ,
731+ key : "rich:horizontal_rule:index: 1" ,
732732 node : document . children ?. [ 1 ] ,
733733 } ) ;
734734 expect ( chunks [ 2 ] ) . toMatchObject ( { kind : "selectable" } ) ;
@@ -774,7 +774,7 @@ describe("nativeMarkdownDocumentChunks", () => {
774774 expect ( chunks [ 0 ] ) . toMatchObject ( { kind : "selectable" } ) ;
775775 expect ( chunks [ 1 ] ) . toEqual ( {
776776 kind : "rich" ,
777- key : "rich:list:1" ,
777+ key : "rich:list:index: 1" ,
778778 node : document . children ?. [ 1 ] ,
779779 } ) ;
780780 expect ( chunks [ 2 ] ) . toMatchObject ( { kind : "selectable" } ) ;
@@ -824,6 +824,89 @@ describe("nativeMarkdownDocumentChunks", () => {
824824 } ) ;
825825 } ) ;
826826
827+ it ( "keys positioned and offset-free siblings in separate namespaces" , ( ) => {
828+ const positioned : MarkdownNode = {
829+ type : "blockquote" ,
830+ beg : 1 ,
831+ end : 10 ,
832+ children : [ { type : "paragraph" , children : [ { type : "text" , content : "Positioned" } ] } ] ,
833+ } ;
834+ const offsetFree : MarkdownNode = {
835+ type : "blockquote" ,
836+ children : [ { type : "paragraph" , children : [ { type : "text" , content : "Generated" } ] } ] ,
837+ } ;
838+ const chunks = nativeMarkdownDocumentChunks ( {
839+ type : "document" ,
840+ children : [
841+ { type : "paragraph" , beg : 0 , end : 0 , children : [ ] } ,
842+ offsetFree ,
843+ positioned ,
844+ { type : "paragraph" , children : [ { type : "text" , content : "Tail" } ] } ,
845+ ] ,
846+ } ) ;
847+
848+ expect ( chunks . map ( ( chunk ) => chunk . key ) ) . toEqual ( [
849+ "selectable:offset:0" ,
850+ "rich:blockquote:index:1" ,
851+ "rich:blockquote:offset:1" ,
852+ "selectable:index:3" ,
853+ ] ) ;
854+ } ) ;
855+
856+ it ( "gives every offset-free selectable group its own key" , ( ) => {
857+ const chunks = nativeMarkdownDocumentChunks ( {
858+ type : "document" ,
859+ children : [
860+ { type : "paragraph" , children : [ { type : "text" , content : "One" } ] } ,
861+ { type : "horizontal_rule" } ,
862+ { type : "paragraph" , children : [ { type : "text" , content : "Two" } ] } ,
863+ { type : "horizontal_rule" } ,
864+ { type : "paragraph" , children : [ { type : "text" , content : "Three" } ] } ,
865+ ] ,
866+ } ) ;
867+
868+ expect ( chunks . map ( ( chunk ) => chunk . key ) ) . toEqual ( [
869+ "selectable:index:0" ,
870+ "rich:horizontal_rule:index:1" ,
871+ "selectable:index:2" ,
872+ "rich:horizontal_rule:index:3" ,
873+ "selectable:index:4" ,
874+ ] ) ;
875+ } ) ;
876+
877+ it ( "keeps positioned chunk keys stable while text streams in" , ( ) => {
878+ const before : MarkdownNode = {
879+ type : "document" ,
880+ children : [
881+ { type : "paragraph" , beg : 0 , end : 5 , children : [ { type : "text" , content : "Intro" } ] } ,
882+ {
883+ type : "code_block" ,
884+ language : "ts" ,
885+ beg : 7 ,
886+ end : 20 ,
887+ children : [ { type : "text" , content : "const a" } ] ,
888+ } ,
889+ ] ,
890+ } ;
891+ const after : MarkdownNode = {
892+ type : "document" ,
893+ children : [
894+ { type : "paragraph" , beg : 0 , end : 5 , children : [ { type : "text" , content : "Intro" } ] } ,
895+ {
896+ type : "code_block" ,
897+ language : "ts" ,
898+ beg : 7 ,
899+ end : 40 ,
900+ children : [ { type : "text" , content : "const a = 1;\nconst b" } ] ,
901+ } ,
902+ ] ,
903+ } ;
904+
905+ expect ( nativeMarkdownDocumentChunks ( after ) . map ( ( chunk ) => chunk . key ) ) . toEqual (
906+ nativeMarkdownDocumentChunks ( before ) . map ( ( chunk ) => chunk . key ) ,
907+ ) ;
908+ } ) ;
909+
827910 it ( "keeps a plain list in one selectable native text container" , ( ) => {
828911 const list : MarkdownNode = {
829912 type : "list" ,
0 commit comments