-
-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Toggle task done command adds global filter text, if enabled #2015
base: main
Are you sure you want to change the base?
Conversation
Fixes 1320 I like to use the "Tasks: Toggle task done" command to create tasks, but since I have a global filter set I had to manually type the global filter each time. This PR changes the behavior so that if the user has a global filter set then the global filter is inserted when the "Tasks: Toggle task done" is run.
Hi, thanks very much indeed for adding this. I don't personally use a global filter, but I imagine that those who do will find it useful. |
tests/Commands/ToggleDone.test.ts
Outdated
testToggleLine('|- ', '- [ ] #task |'); | ||
testToggleLine('- |', '- [ ] #task |'); | ||
testToggleLine('- |foobar', '- [ ] #task foobar|'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to see some more thorough testing here.
Such as, what happens when there is already #task
present on the line. To ensure that it doesn't add a duplicate tag.
Also, can we test the behaviour with non-tag global filter please?
Also, what happens if the global filter contains characters which are special characters in regular expressions?
(There is some code somewhere to deal with that - like, escaping regex special characters in arbitrary strings).
That's all I can think of for now!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it would be good to have tests for the case where there is no global filter defined, for example to guard against accidental insertion of a space at the beginning of the updated lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay I've added more testing in 86b4372. Does that seem sufficient to you? Are there any other tests that are missing?
Some of those tests revealed a smaller bug which is also fixed in that commit. If the task description was empty then toggling the task done would insert an extra space.
- |#task
would become - [ ] #task|
instead of - [ ] #task|
I also added handling for when the description already includes the global filter.
Also, what happens if the global filter contains characters which are special characters in regular expressions?
I added some tests for this in 6d116e6
Thanks for considering that. I searched the docs for 'command' and only found tangential references, so it's not something to include in the docs right now. I've just made a note in #767 to ensure that the capability added here will (eventually) be documented...
Agreed. As a PR, it will automatically get included in the next release notes.
Having re-read #1320, I am comfortable labelling this a bug fix, just because without this, the command adds lines which Tasks then ignores if the user has a global filter. That seems just wrong. |
Also fix the addition of an empty space when the task doesn't have any description besides the global filter. Otherwise some of test cases felt broken because an extra space would be inserted. '- |#task' would become '- [ ] #task|' instead of '- [ ] #task|' Also fix the case where the task description already includes the global filter. In that case it is not necessary to add the global filter.
Also use the GlobalFilter.includedIn for the check
I'm a bit confused, in my workflow, I use Tasks to manage tasks with Global Filter and I also have tasks without it. I don't want Tasks to manage those. I use So this kind of breaks it for me, there could be other people with this use-case. Maybe it could be possible to add this feature/bugfix with a setting? (Disabled by default) |
Thank you for saying this @ilandikov. Overnight I had a nagging doubt about whether this might be the case, prompted by a dim recollection of someone else saying that they only used Tasks for a small subset of their checkboxes, and it was in their muscle memory to add the global filter in the few areas where they wanted Tasks to track. So yes, I do think that having a setting to turn this PR on will be necessary to avoid disrupting people's muscle memory and workflow. |
src/Commands/ToggleDone.ts
Outdated
const addGlobalFilter = globalFilter != '' && !GlobalFilter.includedIn(line); | ||
const newTaskText = addGlobalFilter ? `[ ] ${globalFilter}` : '[ ]'; | ||
const text = line.replace(TaskRegularExpressions.listItemRegex, `$1$2 ${newTaskText}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It just dawned on me that someone recently spent a lot of time moving all code related to the global filter, including manipulating descriptions, in the new GlobalFilter
class.
If the above cannot be done with the existing methods in GlobalFilter, I feel that the new code should go in to a new method in that class. The existing names there may give ideas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah that makes sense. I took a stab at moving as much of the GlobalFilter-related logic to the GlobalFilter class as I could 750df8d. I didn't go all the way because I wanted to keep the regex-related logic in ToggleDone.ts
. Let me know if this matches what you're thinking! If not then I'm open to suggestions.
Don't automatically insert the global filter when creating a new task, instead only insert the global filter if autoInsertGlobalFilter is true.
Ah I hadn't considered that use case because for me 90% percent of the checkboxes I create I want to be considered as Tasks plugin tasks. In 750df8d I've added a |
Thank you again for offering this contribution, and apologies for not picking this up yet. It's not forgotten and I will get to it. |
@claremacrae Thank you! And I'll try to fix the merge conflict over the weekend |
Thank you. That is useful to know - I will try and do the code review before the weekend then, so if there is any feedback you would only need to look at it once. |
Create a extractLineItemComponents function GlobalFilter now does the insertion into the body and operates only on description instead of the entire line Tweaked listItemRegex to capture the body explicitly
Okay I've pushed up some changes based on pairing as well as a few additional changes (such as extractLineItemComponents), I think the main items still remaining is to update the PR description to reflect all the changes and possibly a refactor that will allow us to reduce the repetition in the tests (i.e. a function tied directly to the auto insert behavior, possibly by testing addGlobalFilterToDescriptionDependingOnSettings directly instead of transitively testing it in ToggleDone). |
Thanks!
Am happy to see the PR description updated...
I have held off saying this as it feels a bit negative, but I basically feel that all the tests added in the PR are now in the wrong place. The logic of the new behaviour should now be tested in the GlobalFilter tests. I would pretty-much revert the changes to ToggleDone.test.ts and then add just these 2 tests:
In other words, the tests in ToggleDone are written in terms of user-visible behaviour. How do you feel about doing more in the testing? If the description above is too vague, and if you are available on Sunday, we could pair on it together. If that won't work, I don't mind editing the tests and pushing to your branch, and then merging. |
Just to note that @ilandikov has added kindly merged in I will have time to review that over the next 2 or 3 weeks, and then figure out a way to first merge this one, and then to merge a PR from ilandikov to add the later stages - so that both contributors get credit... Thanks to both @axelson and @ilandikov for working on this... I hope that this message prevents the possible risk of two people working on it at the same time... |
Setting to draft status any PRs which are not currently mergable... |
New behavior: if the user has a global filter set then the global filter is inserted when the "Tasks: Toggle task done" is run.
Description
The "Tasks: Toggle task done" command will now prepend the globalFilter when creating a new checkbox if the
autoInsertGlobalFilter
setting is enabled. TheautoInsertGlobalFilter
setting defaults to false.Also fix an edge case where an extra empty space was added when the task doesn't have any description besides the global filter. Otherwise some of test cases felt broken because an extra space would be inserted.
Previously
'- |#task'
would become'- [ ] #task|'
(notice the two spaces before #task)Now it becomes
'- [ ] #task|'
TODO:
extractLineItemComponents
)Motivation and Context
Fixes #1320
I like to use the "Tasks: Toggle task done" command to create tasks, but since I have a global filter set I had to manually type the global filter each time. This PR changes the behavior so that if the user has a global filter set then the global filter is inserted when the "Tasks: Toggle task done" is run.
I'm not sure if this requires an update to the documentation. I didn't see anywhere where the behavior of "Tasks: Toggle task done" is explained. However this is a change in behavior that merits a notice in the release notes.
I'm not sure if this should be considered a breaking change.
Proposed release notes text
"Tasks: Toggle task done" now has the ability to prepend the global filter to tasks created with the "Tasks: Toggle task done" command if the "Tasks: Toggle task done" command inserts global task filter setting is enabled.
How has this been tested?
Tested in a test vault and updated the unit tests.
Screenshots (if appropriate)
Types of changes
Changes visible to users:
fix
- non-breaking change which fixes an issue)feat
- non-breaking change which adds functionality)feat!!
orfix!!
- fix or feature that would cause existing functionality to not work as expected)docs
- improvements to any documentation content for users)vault
- improvements to the Tasks-Demo sample vault)contrib
- any improvements to documentation content for contributors - see Contributing to Tasks)Internal changes:
refactor
- non-breaking change which only improves the design or structure of existing code, and making no changes to its external behaviour)test
- additions and improvements to unit tests and the smoke tests)chore
- examples include GitHub Actions, issue templates)Checklist
yarn run lint
.Terms