diff --git a/src/Commands/ToggleDone.ts b/src/Commands/ToggleDone.ts index 877f2d40f2..91931dd99d 100644 --- a/src/Commands/ToggleDone.ts +++ b/src/Commands/ToggleDone.ts @@ -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 [ ]'); diff --git a/tests/Commands/ToggleDone.test.ts b/tests/Commands/ToggleDone.test.ts index 1a3f19f0b1..68814e5e22 100644 --- a/tests/Commands/ToggleDone.test.ts +++ b/tests/Commands/ToggleDone.test.ts @@ -106,26 +106,32 @@ 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'); @@ -133,7 +139,7 @@ describe('ToggleDone', () => { 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|'); @@ -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(