Skip to content

Commit

Permalink
fix: completed tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdehaven committed Jan 9, 2024
1 parent 789fc45 commit 09d7b46
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/composables/useMarkdownActions.ts
Original file line number Diff line number Diff line change
@@ -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'

/**
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '- '
Expand Down

0 comments on commit 09d7b46

Please sign in to comment.