Skip to content

Commit 9d462e2

Browse files
authored
Merge pull request #3149 from obsidian-tasks-group/fix-toggle-in-live-preview
fix: Correct the direct toggling of non-recurring tasks in Live Preview
2 parents accd202 + 86bffd5 commit 9d462e2

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

resources/sample_vaults/Tasks-Demo/Manual Testing/Smoke Testing the Tasks Plugin.md

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,38 +58,60 @@ Work through all the tasks below, until zero tasks remain in this query:
5858
5959
## The Smoke Tests
6060
61-
### Completion of tasks
61+
### Toggling tasks
62+
63+
#### Completion of tasks
6264
6365
- [ ] #task Mark this task complete in **Source view** using **Tasks: Toggle task done** command
6466
- [ ] #task Mark this task complete by clicking on it in **Reading view**
65-
- [ ] #task Mark this task complete by clicking on it in **Live Preview**
67+
- [ ] #task Mark this task complete by clicking on it in **Live Preview** - ==ensure the checkbox is redrawn correctly==
6668
- [ ] #task **check**: Checked all above methods for **completing tasks** - and they worked
6769
68-
### Un-completion of tasks
70+
#### Un-completion of tasks
6971
7072
<!-- markdownlint-disable ul-style -->
7173
7274
* [x] #task Mark this task not complete in **Source view** using **Tasks: Toggle task done** command ✅ 2022-07-05
7375
* [x] #task Mark this task not complete by clicking on it in **Reading view** ✅ 2022-07-05
74-
* [x] #task Mark this task not complete by clicking on it in **Live Preview** ✅ 2022-07-05
76+
* [x] #task Mark this task not complete by clicking on it in **Live Preview** - ==ensure the checkbox is redrawn correctly== ✅ 2022-07-05
7577
* [ ] #task **check**: Checked all above methods for **un-completing tasks** - and they worked
7678
7779
<!-- markdownlint-enable ul-style -->
7880
79-
### Recurring Tasks
81+
#### Recurring Tasks
8082
8183
Confirm that when a recurring task is completed, a new task is created, all the date fields are incremented, and the indentation is unchanged.
8284
8385
> [!Todo]
8486
>
8587
> - [ ] #task Complete this recurring task in **Source view** using **Tasks: Toggle task done** command 🔁 every day 🛫 2022-02-17 ⏳ 2022-02-18 📅 2022-02-19
8688
>
87-
> > - [ ] #task Complete this recurring task in **Reading view**🔁 every day 🛫 2022-02-17 ⏳ 2022-02-18 📅 2022-02-19
89+
> > - [ ] #task Complete this recurring task in **Reading view** 🔁 every day 🛫 2022-02-17 ⏳ 2022-02-18 📅 2022-02-19
8890
89-
- [ ] #task Complete this recurring task in **Live Preview**🔁 every day 🛫 2022-02-17 ⏳ 2022-02-18 📅 2022-02-19
91+
- [ ] #task Complete this recurring task in **Live Preview** - ==ensure the checkbox is redrawn correctly== 🔁 every day 🛫 2022-02-17 ⏳ 2022-02-18 📅 2022-02-19
9092
9193
> - [ ] #task **check**: Checked all above steps for **recurring tasks** worked
9294
95+
### On Completion
96+
97+
#### On Completion Delete: Non-recurring tasks
98+
99+
Confirm that the **task line is deleted**.
100+
101+
- [ ] #task Complete this auto-deleting non-recurring task in **Source view** using **Tasks: Toggle task done** command 🏁 delete 📅 2024-10-27
102+
- [ ] #task Complete this auto-deleting non-recurring task in **Reading view** 🏁 delete 📅 2024-10-27
103+
- [ ] #task Complete this auto-deleting non-recurring task in **Live Preview** 🏁 delete 📅 2024-10-27
104+
- [ ] #task **check**: Checked all above steps for **auto-deleting non-recurring tasks** worked
105+
106+
#### On Completion Delete: Recurring Tasks
107+
108+
Confirm that when an auto-deleting recurring task is completed, a **new task is created replacing the old task**, and the checkbox remains not-done.
109+
110+
- [ ] #task Complete this auto-deleting recurring task in **Source view** using **Tasks: Toggle task done** command 🔁 every day 🏁 delete 📅 2024-10-27
111+
- [ ] #task Complete this auto-deleting recurring task in **Reading view** 🔁 every day 🏁 delete 📅 2024-10-27
112+
- [ ] #task Complete this auto-deleting recurring task in **Live Preview** - ==ensure the checkbox is redrawn correctly== 🔁 every day 🏁 delete 📅 2024-10-27
113+
- [ ] #task **check**: Checked all above steps for **auto-deleting recurring tasks** worked
114+
93115
### Rendering of Task Blocks
94116
95117
Steps to do:

src/Obsidian/LivePreviewExtension.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,29 @@ class LivePreviewExtension implements PluginValue {
9090
});
9191
this.view.dispatch(transaction);
9292

93+
// Dirty workaround.
94+
// While the code in this method properly updates the `checked` state
95+
// of the target checkbox, some Obsidian internals revert the state.
96+
// This means that the checkbox would remain in its original `checked`
97+
// state (`true` or `false`), even though the underlying document
98+
// updates correctly.
99+
// As a "fix", we set the checkbox's `checked` state *explicitly* after a
100+
// timeout in case we need to revert Obsidian's possibly wrongful reversal.
101+
const needToForceCheckedProperty = toggled.length === 1;
102+
if (needToForceCheckedProperty) {
103+
// The smoke tests show the workaround is only needed when the event replaces
104+
// a single task line.
105+
// (When one task line becomes two because of recurrence, both the
106+
// edited task lines are rendered correctly by this code)
107+
// Since the advent of 'on completion: delete', we cannot rely on the
108+
// event target's opinion of the new status, as that facility means
109+
// that the new status *may* be different from that in the event.
110+
const desiredCheckedStatus = toggled[0].status.symbol !== ' ';
111+
setTimeout(() => {
112+
target.checked = desiredCheckedStatus;
113+
}, 1);
114+
}
115+
93116
return true;
94117
}
95118
}

0 commit comments

Comments
 (0)