Repository: obsidian-tasks-group/obsidian-tasks
Pull request #3033 (2024-08-15 22:00:40)

Show hide on completion
# Types of changes

<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->

Changes visible to users:

- [x] **New feature** (prefix: `feat` - non-breaking change which adds functionality)
  - Issue/discussion: https://github.com/obsidian-tasks-group/obsidian-tasks/issues/3031
- [x] **Documentation** (prefix: `docs` - improvements to any documentation content **for users**)

Internal changes:

- [x] **Tests** (prefix: `test` - additions and improvements to unit tests and the smoke tests)

## Description

<!--- Remember to provide a general summary of your changes in the Title above -->

<!--- Describe your changes in detail -->

1. Add new instructions:

```
hide on completion
show on completion
```

2. Document those, and also document `task.onCompletion`, added in the last release.
3. Update the Quick Reference page.

## Motivation and Context

<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. -->

Fixes https://github.com/obsidian-tasks-group/obsidian-tasks/issues/3031.

## How has this been tested?

<!--- Please describe in detail how you tested your changes. -->
<!--- Include details of your testing environment, tests ran to see how -->
<!--- your change affects other areas of the code, etc. -->

- Adding new tests
- Manual exploratory testing, confirming it really does work.

## Screenshots (if appropriate)

## Checklist

<!--- Go over all the following points, and put an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->

- [x] My code follows the code style of this project and passes `yarn run lint`.
- [x] My change requires a change to the documentation.
- [x] I have [updated the documentation](https://publish.obsidian.md/tasks-contributing/Documentation/About+Documentation) accordingly.
- [x] My change has adequate [Unit Test coverage](https://publish.obsidian.md/tasks-contributing/Testing/About+Testing).

## Terms

<!--
By submitting this pull request, you must agree to follow our
[contributing guide](https://publish.obsidian.md/tasks-contributing) and
[Code of Conduct](https://github.com/obsidian-tasks-group/obsidian-tasks/blob/main/CODE_OF_CONDUCT.md).
Put an x in the boxes to confirm you agree.
-->

- [x] My contribution follows this project's [contributing guide](https://publish.obsidian.md/tasks-contributing)
- [x] I agree to follow this project's [Code of Conduct](https://github.com/obsidian-tasks-group/obsidian-tasks/blob/main/CODE_OF_CONDUCT.md)



Patch:
diff --git a/docs/Queries/Layout.md b/docs/Queries/Layout.md
index 805787a8..f257c1c0 100644
--- a/docs/Queries/Layout.md
+++ b/docs/Queries/Layout.md
@@ -27,6 +27,7 @@ The following elements exist:
 - `due date`
 - `done date`
 - `recurrence rule`
+- `on completion`
 - `tags`
 - `task count`
 
diff --git a/docs/Quick Reference.md b/docs/Quick Reference.md
index 07c814d1..73bf87d2 100644
--- a/docs/Quick Reference.md
+++ b/docs/Quick Reference.md
@@ -34,6 +34,8 @@ This table summarizes the filters and other options available inside a `tasks` b
 | **[[Filters#Recurrence\|Recurrence]]**                                                                                                                                                                                                                                                                                                               |                                             |                        |                        |                                                                                                                                |
 | `is recurring`<br>`is not recurring`                                                                                                                                                                                                                                                                                                                 | `sort by recurring`                         | `group by recurring`   |                        | `task.isRecurring`                                                                                                             |
 | `recurrence (includes, does not include) <string>`<br>`recurrence (regex matches, regex does not match) /regex/i`                                                                                                                                                                                                                                    |                                             | `group by recurrence`  | `hide recurrence rule` | `task.recurrenceRule`                                                                                                          |
+| **[[On Completion]]**                                                                                                                                                                                                                                                                                                                                |                                             |                        |                        |                                                                                                                                |
+|                                                                                                                                                                                                                                                                                                                                                      |                                             |                        | `hide on completion`   | `task.onCompletion`                                                                                                            |
 | **[[Filters#Priority\|Priority]]** and **[[Urgency\|urgency]]**                                                                                                                                                                                                                                                                                      |                                             |                        |                        |                                                                                                                                |
 | `priority is (above, below, not)? (lowest, low, none, medium, high, highest)`                                                                                                                                                                                                                                                                        | `sort by priority`                          | `group by priority`    | `hide priority`        | `task.priorityName`<br>`task.priorityNameGroupText`<br>`task.priorityNumber`                                                   |
 |                                                                                                                                                                                                                                                                                                                                                      | `sort by urgency`                           | `group by urgency`     | `show urgency`         | `task.urgency`                                                                                                                 |
diff --git a/docs/Scripting/Task Properties.md b/docs/Scripting/Task Properties.md
index 47cb9361..23258c87 100644
--- a/docs/Scripting/Task Properties.md
+++ b/docs/Scripting/Task Properties.md
@@ -174,6 +174,10 @@ For more information, including adding your own customised statuses, see [[Statu
     - **or** an empty string (`''`) if:
         - **either** it does not have a recurrence rule,
         - **or** the recurrence rule is invalid (such as `🔁  every seven weeks`, for example).
+1. `task.onCompletion` (added in Tasks 7.8.0) will have one of these values:
+    - `delete`
+    - `keep`
+    - `` (empty string), which is the default, when the task has no [[On Completion]] action specified.
 1. Note that if there is a [[Global Filter]] enabled in settings, and the filter is a tag, it will be removed from `task.tags`.
 
 ## Values for File Properties
diff --git a/src/Query/Query.ts b/src/Query/Query.ts
index 5915f41a..b3ff5c27 100644
--- a/src/Query/Query.ts
+++ b/src/Query/Query.ts
@@ -36,7 +36,7 @@ export class Query implements IQuery {
     private _ignoreGlobalQuery: boolean = false;
 
     private readonly hideOptionsRegexp =
-        /^(hide|show) (task count|backlink|priority|cancelled date|created date|start date|scheduled date|done date|due date|recurrence rule|edit button|postpone button|urgency|tags|depends on|id)/i;
+        /^(hide|show) (task count|backlink|priority|cancelled date|created date|start date|scheduled date|done date|due date|recurrence rule|edit button|postpone button|urgency|tags|depends on|id|on completion)/i;
     private readonly shortModeRegexp = /^short/i;
     private readonly fullModeRegexp = /^full/i;
     private readonly explainQueryRegexp = /^explain/i;
@@ -342,6 +342,9 @@ ${statement.explainStatement('    ')}
                 case 'depends on':
                     this._taskLayoutOptions.setVisibility(TaskLayoutComponent.DependsOn, !hide);
                     break;
+                case 'on completion':
+                    this._taskLayoutOptions.setVisibility(TaskLayoutComponent.OnCompletion, !hide);
+                    break;
                 default:
                     this.setError('do not understand hide/show option', new Statement(line, line));
             }


Test patch:
diff --git a/tests/Query/Query.test.ts b/tests/Query/Query.test.ts
index a0610b96..74fa93a0 100644
--- a/tests/Query/Query.test.ts
+++ b/tests/Query/Query.test.ts
@@ -21,6 +21,7 @@ import type { FilteringCase } from '../TestingTools/FilterTestHelpers';
 import { shouldSupportFiltering } from '../TestingTools/FilterTestHelpers';
 import { TaskBuilder } from '../TestingTools/TaskBuilder';
 import { Priority } from '../../src/Task/Priority';
+import { TaskLayoutComponent } from '../../src/Layout/TaskLayoutOptions';
 
 window.moment = moment;
 
@@ -456,6 +457,7 @@ describe('Query parsing', () => {
             'hide due date',
             'hide edit button',
             'hide id',
+            'hide on completion',
             'hide priority',
             'hide recurrence rule',
             'hide scheduled date',
@@ -478,6 +480,7 @@ describe('Query parsing', () => {
             'show due date',
             'show edit button',
             'show id',
+            'show on completion',
             'show priority',
             'show recurrence rule',
             'show scheduled date',
@@ -1287,6 +1290,18 @@ describe('Query', () => {
         });
     });
 
+    describe('show and hide', () => {
+        it('should show "on completion" by default', () => {
+            const query = new Query('');
+            expect(query.taskLayoutOptions.isShown(TaskLayoutComponent.OnCompletion)).toEqual(true);
+        });
+
+        it('should allow to hide "on completion"', () => {
+            const query = new Query('hide on completion');
+            expect(query.taskLayoutOptions.isShown(TaskLayoutComponent.OnCompletion)).toEqual(false);
+        });
+    });
+
     describe('sorting', () => {
         const doneTask = new TaskBuilder().status(Status.DONE).build();
         const todoTask = new TaskBuilder().status(Status.TODO).build();