@@ -83,6 +83,115 @@ const threeColumnsWithParagraphAbove = [
8383 } ,
8484] ;
8585
86+ const columnsOnly = [
87+ {
88+ type : "columnList" as const ,
89+ children : [
90+ {
91+ type : "column" as const ,
92+ children : [
93+ { id : "col1-para" , type : "paragraph" as const , content : "col1" } ,
94+ ] ,
95+ } ,
96+ {
97+ type : "column" as const ,
98+ children : [
99+ { id : "col2-para" , type : "paragraph" as const , content : "col2" } ,
100+ ] ,
101+ } ,
102+ ] ,
103+ } ,
104+ ] ;
105+
106+ const columnsWithEmptyFirst = [
107+ {
108+ type : "columnList" as const ,
109+ children : [
110+ {
111+ type : "column" as const ,
112+ children : [
113+ { id : "empty-para" , type : "paragraph" as const , content : "" } ,
114+ ] ,
115+ } ,
116+ {
117+ type : "column" as const ,
118+ children : [
119+ { id : "col2-para" , type : "paragraph" as const , content : "col2" } ,
120+ { id : "col2-trailing" , type : "paragraph" as const , content : "" } ,
121+ ] ,
122+ } ,
123+ ] ,
124+ } ,
125+ ] ;
126+
127+ /** Every bit of text in the document, so a fix can't quietly drop content. */
128+ function texts ( editor : BlockNoteEditor < any , any , any > ) : string [ ] {
129+ const out : string [ ] = [ ] ;
130+ const walk = ( blocks : any [ ] ) => {
131+ for ( const block of blocks ) {
132+ if ( Array . isArray ( block . content ) ) {
133+ const text = block . content . map ( ( c : any ) => c . text ?? "" ) . join ( "" ) ;
134+ if ( text ) {
135+ out . push ( text ) ;
136+ }
137+ }
138+ walk ( block . children ?? [ ] ) ;
139+ }
140+ } ;
141+ walk ( editor . document ) ;
142+ return out . sort ( ) ;
143+ }
144+
145+ // A column layout with nothing after it, and one whose first column is empty,
146+ // both used to throw out of the keydown handler: there is no following block
147+ // to pull in, and no non-empty first column to merge with. The document is
148+ // left alone (or repaired) instead.
149+ describe ( "Delete and Backspace at a column layout's edges" , ( ) => {
150+ it ( "Delete at the end of the last column, with the layout ending the document" , ( ) => {
151+ const editor = getEditor ( ) ;
152+ editor . replaceBlocks ( editor . document , columnsOnly ) ;
153+
154+ editor . setTextCursorPosition ( "col2-para" , "end" ) ;
155+
156+ expect ( ( ) => pressDelete ( editor ) ) . not . toThrow ( ) ;
157+ expect ( ( ) => editor . prosemirrorState . doc . check ( ) ) . not . toThrow ( ) ;
158+ expect ( texts ( editor ) ) . toEqual ( [ "col1" , "col2" ] ) ;
159+ } ) ;
160+
161+ it ( "Delete at the start of an empty first column" , ( ) => {
162+ const editor = getEditor ( ) ;
163+ editor . replaceBlocks ( editor . document , columnsWithEmptyFirst ) ;
164+
165+ editor . setTextCursorPosition ( "empty-para" , "start" ) ;
166+
167+ expect ( ( ) => pressDelete ( editor ) ) . not . toThrow ( ) ;
168+ expect ( ( ) => editor . prosemirrorState . doc . check ( ) ) . not . toThrow ( ) ;
169+ expect ( texts ( editor ) ) . toEqual ( [ "col2" ] ) ;
170+ } ) ;
171+
172+ it ( "Delete at the end of a trailing empty block in the last column" , ( ) => {
173+ const editor = getEditor ( ) ;
174+ editor . replaceBlocks ( editor . document , columnsWithEmptyFirst ) ;
175+
176+ editor . setTextCursorPosition ( "col2-trailing" , "end" ) ;
177+
178+ expect ( ( ) => pressDelete ( editor ) ) . not . toThrow ( ) ;
179+ expect ( ( ) => editor . prosemirrorState . doc . check ( ) ) . not . toThrow ( ) ;
180+ expect ( texts ( editor ) ) . toEqual ( [ "col2" ] ) ;
181+ } ) ;
182+
183+ it ( "Backspace at the start of a column following an empty column" , ( ) => {
184+ const editor = getEditor ( ) ;
185+ editor . replaceBlocks ( editor . document , columnsWithEmptyFirst ) ;
186+
187+ editor . setTextCursorPosition ( "col2-para" , "start" ) ;
188+
189+ expect ( ( ) => pressBackspace ( editor ) ) . not . toThrow ( ) ;
190+ expect ( ( ) => editor . prosemirrorState . doc . check ( ) ) . not . toThrow ( ) ;
191+ expect ( texts ( editor ) ) . toEqual ( [ "col2" ] ) ;
192+ } ) ;
193+ } ) ;
194+
86195describe ( "Backspace with multi-column" , ( ) => {
87196 // TODO: When migrating to vitest browser mode, replace this test with
88197 // a version that presses Backspace 5 times from offset 5 in "hello world"
0 commit comments