Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Commands/ToggleDone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const toggleLine = (line: string, path: string): EditorInsertion => {
const statusString = regexMatch[3];
const status = StatusRegistry.getInstance().bySymbol(statusString);
const newStatusString = status.nextStatusSymbol;
return { text: line.replace(TaskRegularExpressions.taskRegex, `$1- [${newStatusString}] $4`) };
return { text: line.replace(TaskRegularExpressions.taskRegex, `$1$2 [${newStatusString}] $4`) };
} else if (TaskRegularExpressions.listItemRegex.test(line)) {
// Convert the list item to a checklist item.
const text = line.replace(TaskRegularExpressions.listItemRegex, '$1$2 [ ]');
Expand Down
20 changes: 15 additions & 5 deletions tests/Commands/ToggleDone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,34 +106,40 @@ describe('ToggleDone', () => {
it('should add checkbox to hyphen and space', () => {
testToggleLine('|- ', '- [ ] |');
testToggleLine('- |', '- [ ] |');
testToggleLine('- |foobar', '- [ ] foobar|');
testToggleLine('1. |foobar', '1. [ ] foobar|');

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

testToggleLine('|- ', '- [ ] |');
testToggleLine('- |', '- [ ] |');
testToggleLine('- |foobar', '- [ ] foobar|');
testToggleLine('1. |foobar', '1. [ ] foobar|');
});

it('should complete a task', () => {
testToggleLine('|- [ ] ', '|- [x] ✅ 2022-09-04');
testToggleLine('- [ ] |', '- [x] | ✅ 2022-09-04');
testToggleLine('- [ ] description|', '- [x] description| ✅ 2022-09-04');

// Issue #449 - cursor jumped 13 characters to the right on completion
testToggleLine('- [ ] I have a |proper description', '- [x] I have a |proper description ✅ 2022-09-04');

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

// Done date is not added if task does not match global filter
testToggleLine('|- [ ] ', '|- [x] ');
testToggleLine('- [ ] |', '- [x] |');
testToggleLine('1. [ ] |', '1. [x] |');

// Done date is added if task does not match global filter
testToggleLine('- [ ] #task|', '- [x] #tas|k ✅ 2022-09-04'); // Extra space added before #; cursor moves left
testToggleLine('* [ ] #task description|', '* [x] #task description| ✅ 2022-09-04');

// Issue #449 - cursor jumped 13 characters to the right on completion
testToggleLine('- [ ] I have a |proper description', '- [x] I have a |proper description');
});

it('should un-complete a completed task', () => {
testToggleLine('|- [x] ✅ 2022-09-04', '|- [ ] ');
testToggleLine('- [x] ✅ 2022-09-04|', '- [ ] |');
testToggleLine('1. [x] ✅ 2022-09-04|', '1. [ ] |');

// Issue #449 - cursor jumped 13 characters to the left on un-completion
testToggleLine('- [x] I have a proper description| ✅ 2022-09-04', '- [ ] I have a proper description|');
Expand All @@ -142,7 +148,11 @@ describe('ToggleDone', () => {

// Done date is not removed if task does not match global filter
testToggleLine('|- [x] ✅ 2022-09-04', '|- [ ] ✅ 2022-09-04');
testToggleLine('- [x] ✅ 2022-09-04|', '- [ ] ✅ 2022-09-04|');
testToggleLine('+ [x] ✅ 2022-09-04|', '+ [ ] ✅ 2022-09-04|');

// Done date is added if task matches the global filter
testToggleLine('|- [x] #task ✅ 2022-09-04', '|- [ ] #task'); // Extra space added before #
testToggleLine('1. [x] #task description ✅ 2022-09-04|', '1. [ ] #task description|');

// Issue #449 - cursor jumped 13 characters to the left on un-completion
testToggleLine(
Expand Down