@@ -82,10 +82,12 @@ export const removeNote: Command = (state, dispatch, view) => {
82
82
if ( dispatch ) {
83
83
const noteTitleNode = $cursor . parent ;
84
84
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 ,
88
89
) ;
90
+
89
91
const from = $cursor . before ( - 1 ) ;
90
92
const to = from + noteNode . nodeSize ;
91
93
const tr = state . tr . replaceWith ( from , to , content ) ;
@@ -107,18 +109,22 @@ export const backToNoteTitle: Command = (state, dispatch, view) => {
107
109
if ( ! $cursor ) return false ;
108
110
if (
109
111
! 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 ) )
111
114
) {
112
115
return false ;
113
116
}
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
+
116
122
if ( view ?. endOfTextblock ( 'backward' , state ) ) {
117
123
if ( dispatch ) {
118
124
const noteTitleNode = noteNode . firstChild ! ;
119
125
dispatch (
120
126
state . tr . setSelection (
121
- TextSelection . create ( state . doc , $cursor . before ( - 1 ) + noteTitleNode . nodeSize ) ,
127
+ TextSelection . create ( state . doc , $cursor . before ( - 2 ) + noteTitleNode . nodeSize ) ,
122
128
) ,
123
129
) ;
124
130
}
0 commit comments