Skip to content

Commit 51c2078

Browse files
authored
Merge pull request #3709 from obsidian-tasks-group/issue-3708-list-markers
fix: 'Tasks: Toggle task done' keeps list markers if no Global Filter (#3708)
2 parents 5f44825 + 9274c9d commit 51c2078

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/Commands/ToggleDone.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const toggleLine = (line: string, path: string): EditorInsertion => {
102102
const statusString = regexMatch[3];
103103
const status = StatusRegistry.getInstance().bySymbol(statusString);
104104
const newStatusString = status.nextStatusSymbol;
105-
return { text: line.replace(TaskRegularExpressions.taskRegex, `$1- [${newStatusString}] $4`) };
105+
return { text: line.replace(TaskRegularExpressions.taskRegex, `$1$2 [${newStatusString}] $4`) };
106106
} else if (TaskRegularExpressions.listItemRegex.test(line)) {
107107
// Convert the list item to a checklist item.
108108
const text = line.replace(TaskRegularExpressions.listItemRegex, '$1$2 [ ]');

tests/Commands/ToggleDone.test.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,34 +106,40 @@ describe('ToggleDone', () => {
106106
it('should add checkbox to hyphen and space', () => {
107107
testToggleLine('|- ', '- [ ] |');
108108
testToggleLine('- |', '- [ ] |');
109-
testToggleLine('- |foobar', '- [ ] foobar|');
109+
testToggleLine('1. |foobar', '1. [ ] foobar|');
110110

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

113113
testToggleLine('|- ', '- [ ] |');
114114
testToggleLine('- |', '- [ ] |');
115-
testToggleLine('- |foobar', '- [ ] foobar|');
115+
testToggleLine('1. |foobar', '1. [ ] foobar|');
116116
});
117117

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

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

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

128+
// Done date is not added if task does not match global filter
127129
testToggleLine('|- [ ] ', '|- [x] ');
128-
testToggleLine('- [ ] |', '- [x] |');
130+
testToggleLine('1. [ ] |', '1. [x] |');
131+
132+
// Done date is added if task does not match global filter
133+
testToggleLine('- [ ] #task|', '- [x] #tas|k ✅ 2022-09-04'); // Extra space added before #; cursor moves left
134+
testToggleLine('* [ ] #task description|', '* [x] #task description| ✅ 2022-09-04');
129135

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

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

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

143149
// Done date is not removed if task does not match global filter
144150
testToggleLine('|- [x] ✅ 2022-09-04', '|- [ ] ✅ 2022-09-04');
145-
testToggleLine('- [x] ✅ 2022-09-04|', '- [ ] ✅ 2022-09-04|');
151+
testToggleLine('+ [x] ✅ 2022-09-04|', '+ [ ] ✅ 2022-09-04|');
152+
153+
// Done date is added if task matches the global filter
154+
testToggleLine('|- [x] #task ✅ 2022-09-04', '|- [ ] #task'); // Extra space added before #
155+
testToggleLine('1. [x] #task description ✅ 2022-09-04|', '1. [ ] #task description|');
146156

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

0 commit comments

Comments
 (0)