Skip to content

Commit b39177b

Browse files
committed
fix: Make 'Tasks: Toggle task done' convert non-list-items straight to checklists (#1158)
This is for consistency with the built-in 'Toggle checkbox status' command. Fixes #1158.
1 parent 51c2078 commit b39177b

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/Commands/ToggleDone.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ export const toggleLine = (line: string, path: string): EditorInsertion => {
108108
const text = line.replace(TaskRegularExpressions.listItemRegex, '$1$2 [ ]');
109109
return { text, moveTo: { ch: text.length } };
110110
} else {
111-
// Convert the line to a list item.
112-
const text = line.replace(TaskRegularExpressions.indentationRegex, '$1- ');
111+
// Convert the line to a checklist item.
112+
const text = line.replace(TaskRegularExpressions.indentationRegex, '$1- [ ] ');
113113
return { text, moveTo: { ch: text.length } };
114114
}
115115
}

tests/Commands/ToggleDone.test.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ describe('ToggleDone', () => {
9393
// Most of the tests are run twice. The second time, they are tested with tasks that
9494
// do not match the global filter.
9595

96-
it('should add hyphen and space to empty line', () => {
97-
testToggleLine('|', '- |');
98-
testToggleLine('foo|bar', '- foobar|');
96+
it('should add checkbox to empty line, and lines without list items', () => {
97+
testToggleLine('|', '- [ ] |');
98+
testToggleLine('foo|bar', '- [ ] foobar|');
9999

100100
GlobalFilter.getInstance().set('#task');
101101

102-
testToggleLine('|', '- |');
103-
testToggleLine('foo|bar', '- foobar|');
102+
testToggleLine('|', '- [ ] |');
103+
testToggleLine('foo|bar', '- [ ] foobar|');
104104
});
105105

106106
it('should add checkbox to hyphen and space', () => {

0 commit comments

Comments
 (0)