@@ -222,7 +222,14 @@ export default function useMarkdownActions(
222
222
const startText = rawMarkdown . value . substring ( 0 , selectedText . start )
223
223
224
224
// When removing tabs, ensure string starts with two spaces; or a list item that is already indented. If not, exit
225
- if ( action === 'remove' && ( ! startText . endsWith ( spaces ) && ! startText . endsWith ( ' ' + MARKDOWN_TEMPLATE_UL ) ) ) {
225
+ if (
226
+ action === 'remove' &&
227
+ ! startText . endsWith ( spaces ) &&
228
+ // Not an unordered list
229
+ ! startText . endsWith ( ' ' + MARKDOWN_TEMPLATE_UL ) &&
230
+ // Not an ordered list
231
+ ! / { 2 } \d { 1 , } \. $ / . test ( startText )
232
+ ) {
226
233
return
227
234
}
228
235
@@ -241,8 +248,14 @@ export default function useMarkdownActions(
241
248
// If text starts with an inline template
242
249
if ( startText . endsWith ( MARKDOWN_TEMPLATE_UL ) ) {
243
250
rawMarkdown . value = action === 'add' ? rawMarkdown . value . substring ( 0 , selectedText . start - MARKDOWN_TEMPLATE_UL . length ) + spaces + MARKDOWN_TEMPLATE_UL + rawMarkdown . value . substring ( selectedText . end ) : rawMarkdown . value . substring ( 0 , selectedText . start - spaces . length - MARKDOWN_TEMPLATE_UL . length ) + MARKDOWN_TEMPLATE_UL + rawMarkdown . value . substring ( selectedText . end )
244
- } else if ( startText . endsWith ( MARKDOWN_TEMPLATE_OL ) ) {
245
- rawMarkdown . value = action === 'add' ? rawMarkdown . value . substring ( 0 , selectedText . start - MARKDOWN_TEMPLATE_OL . length ) + spaces + MARKDOWN_TEMPLATE_OL + rawMarkdown . value . substring ( selectedText . end ) : rawMarkdown . value . substring ( 0 , selectedText . start - spaces . length - MARKDOWN_TEMPLATE_OL . length ) + MARKDOWN_TEMPLATE_OL + rawMarkdown . value . substring ( selectedText . end )
251
+ } else if ( / \d { 1 , } \. $ / . test ( startText . split ( NEW_LINE_CHARACTER ) . pop ( ) || '' ) ) {
252
+ // Remove the `1` in the ordered list template
253
+ const numberSuffix = MARKDOWN_TEMPLATE_OL . replace ( '1' , '' )
254
+
255
+ const listNumber = Number ( ( startText . split ( NEW_LINE_CHARACTER ) . at ( - 2 ) || startText . split ( NEW_LINE_CHARACTER ) . pop ( ) || '' ) . trimStart ( ) . split ( numberSuffix ) [ 0 ] ) + 1
256
+ console . log ( 'listNumber' , listNumber )
257
+
258
+ rawMarkdown . value = action === 'add' ? rawMarkdown . value . substring ( 0 , selectedText . start - MARKDOWN_TEMPLATE_OL . length ) + spaces + MARKDOWN_TEMPLATE_OL + rawMarkdown . value . substring ( selectedText . end ) : rawMarkdown . value . substring ( 0 , selectedText . start - spaces . length - ( listNumber + numberSuffix ) . length ) + ( listNumber + numberSuffix ) + rawMarkdown . value . substring ( selectedText . end )
246
259
} else {
247
260
rawMarkdown . value = action === 'add' ? startText + spaces + rawMarkdown . value . substring ( selectedText . end ) : rawMarkdown . value . substring ( 0 , selectedText . start - spaces . length ) + rawMarkdown . value . substring ( selectedText . end )
248
261
}
0 commit comments