@@ -82,10 +82,12 @@ export const removeNote: Command = (state, dispatch, view) => {
8282 if ( dispatch ) {
8383 const noteTitleNode = $cursor . parent ;
8484 const noteNode = $cursor . node ( - 1 ) ;
85- const content = noteNode . content . replaceChild (
86- 0 ,
87- pType ( schema ) . create ( null , noteTitleNode . content ) ,
85+
86+ const noteContentNode = noteNode . lastChild ! ;
87+ const content = Fragment . from ( pType ( schema ) . create ( null , noteTitleNode . content ) ) . append (
88+ noteContentNode . content ,
8889 ) ;
90+
8991 const from = $cursor . before ( - 1 ) ;
9092 const to = from + noteNode . nodeSize ;
9193 const tr = state . tr . replaceWith ( from , to , content ) ;
@@ -107,18 +109,22 @@ export const backToNoteTitle: Command = (state, dispatch, view) => {
107109 if ( ! $cursor ) return false ;
108110 if (
109111 ! isSameNodeType ( $cursor . parent , pType ( schema ) ) ||
110- ! isSameNodeType ( $cursor . node ( - 1 ) , noteType ( schema ) )
112+ ! isSameNodeType ( $cursor . node ( - 1 ) , noteContentType ( schema ) ) ||
113+ ! isSameNodeType ( $cursor . node ( - 2 ) , noteType ( schema ) )
111114 ) {
112115 return false ;
113116 }
114- const noteNode = $cursor . node ( - 1 ) ;
115- if ( $cursor . parent !== noteNode . maybeChild ( 1 ) ) return false ;
117+
118+ const noteNode = $cursor . node ( - 2 ) ;
119+ const noteContentNode = $cursor . node ( - 1 ) ;
120+ if ( $cursor . parent !== noteContentNode . firstChild ) return false ;
121+
116122 if ( view ?. endOfTextblock ( 'backward' , state ) ) {
117123 if ( dispatch ) {
118124 const noteTitleNode = noteNode . firstChild ! ;
119125 dispatch (
120126 state . tr . setSelection (
121- TextSelection . create ( state . doc , $cursor . before ( - 1 ) + noteTitleNode . nodeSize ) ,
127+ TextSelection . create ( state . doc , $cursor . before ( - 2 ) + noteTitleNode . nodeSize ) ,
122128 ) ,
123129 ) ;
124130 }
0 commit comments