@@ -76,7 +76,7 @@ const wrapContentWithHeading = (arrg, attributes, newSelection = null) => {
76
76
selection
77
77
)
78
78
79
- tr . delete ( start , titleEndPos )
79
+ tr . delete ( start + 1 , titleEndPos )
80
80
81
81
let titleHMap = getHeadingsBlocksMap ( tr . doc , titleStartPos , tr . mapping . map ( titleEndPos ) )
82
82
const { prevHStartPos } = getPrevHeadingPos ( tr . doc , titleStartPos , start )
@@ -88,7 +88,12 @@ const wrapContentWithHeading = (arrg, attributes, newSelection = null) => {
88
88
const insertFirstNodes = prevBlock . endBlockPos - ( shouldNested ? 2 : 0 )
89
89
tr . insert ( insertFirstNodes , headingNode )
90
90
91
- const updatedSelection = putTextSelectionEndNode ( tr , insertFirstNodes , headingNode )
91
+ const targetPos = Math . min (
92
+ insertFirstNodes + headingNode [ 0 ] . firstChild . nodeSize ,
93
+ tr . doc . content . size - 1
94
+ )
95
+
96
+ const updatedSelection = new TextSelection ( tr . doc . resolve ( targetPos ) )
92
97
tr . setSelection ( updatedSelection )
93
98
94
99
return insertRemainingHeadings ( {
@@ -140,14 +145,14 @@ const wrapContentWithHeading = (arrg, attributes, newSelection = null) => {
140
145
141
146
const insertFirstNodesPos = tr . mapping . map ( newStartPos )
142
147
143
- tr . delete ( insertFirstNodesPos , block . parent . end )
148
+ tr . delete ( insertFirstNodesPos , $to . end ( 1 ) )
144
149
tr . insert ( insertFirstNodesPos , newHeadingNode )
145
150
146
151
const updatedSelection = putTextSelectionEndNode ( tr , insertFirstNodesPos , newHeadingNode )
147
152
tr . setSelection ( updatedSelection )
148
153
149
154
titleStartPos = newSelection ? $from . start ( 1 ) : $from . start ( 1 ) - 1
150
- titleEndPos = newSelection ? tr . curSelection . $to . end ( 1 ) : $to . end ( 1 )
155
+ titleEndPos = newSelection ? tr . curSelection . $to . end ( 1 ) : tr . mapping . map ( $to . end ( 1 ) )
151
156
152
157
try {
153
158
insertRemainingHeadings ( {
@@ -160,7 +165,7 @@ const wrapContentWithHeading = (arrg, attributes, newSelection = null) => {
160
165
} )
161
166
return true
162
167
} catch ( error ) {
163
- console . error ( '[Heading][wrapContentWithHeading]: error insertRemainingHeadings' )
168
+ console . error ( '[Heading][wrapContentWithHeading]: error insertRemainingHeadings' , error )
164
169
return false
165
170
}
166
171
}
0 commit comments