diff --git a/src/composables/useMarkdownActions.ts b/src/composables/useMarkdownActions.ts index 615f61c..a8461f8 100644 --- a/src/composables/useMarkdownActions.ts +++ b/src/composables/useMarkdownActions.ts @@ -1,6 +1,6 @@ import { reactive, nextTick } from 'vue' import type { Ref } from 'vue' -import { InlineFormatWrapper, DEFAULT_CODEBLOCK_LANGUAGE, MARKDOWN_TEMPLATE_CODEBLOCK, MARKDOWN_TEMPLATE_TASK, MARKDOWN_TEMPLATE_UL, MARKDOWN_TEMPLATE_OL, MARKDOWN_TEMPLATE_BLOCKQUOTE, MARKDOWN_TEMPLATE_TABLE, NEW_LINE_CHARACTER } from '@/constants' +import { InlineFormatWrapper, DEFAULT_CODEBLOCK_LANGUAGE, MARKDOWN_TEMPLATE_CODEBLOCK, MARKDOWN_TEMPLATE_TASK, MARKDOWN_TEMPLATE_TASK_COMPLETED, MARKDOWN_TEMPLATE_UL, MARKDOWN_TEMPLATE_OL, MARKDOWN_TEMPLATE_BLOCKQUOTE, MARKDOWN_TEMPLATE_TABLE, NEW_LINE_CHARACTER } from '@/constants' import type { InlineFormat, MarkdownTemplate } from '@/types' /** @@ -464,14 +464,22 @@ export default function useMarkdownActions( } } else { // All other templates (other than ordered list) - if (lastLine.trimStart().startsWith(template)) { + + // Check if completed task item + const isCompletedTask = template === MARKDOWN_TEMPLATE_TASK && lastLine.trimStart().toLowerCase().startsWith(MARKDOWN_TEMPLATE_TASK_COMPLETED.toLowerCase()) + + if (lastLine.trimStart().startsWith(template) || isCompletedTask) { templateLength = template.length // If the last list item is empty, remove the template instead if (lastLine.trimStart() === template) { removeNewLineTemplate = true } else { // Add a new line appended with the same template with indentation, if applicable - newLineContent += lastLine.split(template)[0] + template + if (isCompletedTask) { + newLineContent += lastLine.toLowerCase().split(MARKDOWN_TEMPLATE_TASK_COMPLETED.toLowerCase())[0] + template + } else { + newLineContent += lastLine.split(template)[0] + template + } } // We found a match, so exit the loop break diff --git a/src/constants.ts b/src/constants.ts index 43bca22..fa972e9 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -34,6 +34,7 @@ export const MARKDOWN_TEMPLATE_TABLE = /** The markdown template for a task. Ensure trailing space remains */ export const MARKDOWN_TEMPLATE_TASK = '- [ ] ' +export const MARKDOWN_TEMPLATE_TASK_COMPLETED = '- [x] ' /** The markdown template for an unordered list. Ensure trailing space remains */ export const MARKDOWN_TEMPLATE_UL = '- '