Skip to content

Commit

Permalink
Merge pull request #3149 from obsidian-tasks-group/fix-toggle-in-live…
Browse files Browse the repository at this point in the history
…-preview

fix: Correct the direct toggling of non-recurring tasks in Live Preview
  • Loading branch information
claremacrae authored Oct 27, 2024
2 parents accd202 + 86bffd5 commit 9d462e2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,38 +58,60 @@ Work through all the tasks below, until zero tasks remain in this query:
## The Smoke Tests
### Completion of tasks
### Toggling tasks
#### Completion of tasks
- [ ] #task Mark this task complete in **Source view** using **Tasks: Toggle task done** command
- [ ] #task Mark this task complete by clicking on it in **Reading view**
- [ ] #task Mark this task complete by clicking on it in **Live Preview**
- [ ] #task Mark this task complete by clicking on it in **Live Preview** - ==ensure the checkbox is redrawn correctly==
- [ ] #task **check**: Checked all above methods for **completing tasks** - and they worked
### Un-completion of tasks
#### Un-completion of tasks
<!-- markdownlint-disable ul-style -->
* [x] #task Mark this task not complete in **Source view** using **Tasks: Toggle task done** command ✅ 2022-07-05
* [x] #task Mark this task not complete by clicking on it in **Reading view** ✅ 2022-07-05
* [x] #task Mark this task not complete by clicking on it in **Live Preview** ✅ 2022-07-05
* [x] #task Mark this task not complete by clicking on it in **Live Preview** - ==ensure the checkbox is redrawn correctly== ✅ 2022-07-05
* [ ] #task **check**: Checked all above methods for **un-completing tasks** - and they worked
<!-- markdownlint-enable ul-style -->
### Recurring Tasks
#### Recurring Tasks
Confirm that when a recurring task is completed, a new task is created, all the date fields are incremented, and the indentation is unchanged.
> [!Todo]
>
> - [ ] #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
>
> > - [ ] #task Complete this recurring task in **Reading view**🔁 every day 🛫 2022-02-17 ⏳ 2022-02-18 📅 2022-02-19
> > - [ ] #task Complete this recurring task in **Reading view** 🔁 every day 🛫 2022-02-17 ⏳ 2022-02-18 📅 2022-02-19
- [ ] #task Complete this recurring task in **Live Preview**🔁 every day 🛫 2022-02-17 ⏳ 2022-02-18 📅 2022-02-19
- [ ] #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
> - [ ] #task **check**: Checked all above steps for **recurring tasks** worked
### On Completion
#### On Completion Delete: Non-recurring tasks
Confirm that the **task line is deleted**.
- [ ] #task Complete this auto-deleting non-recurring task in **Source view** using **Tasks: Toggle task done** command 🏁 delete 📅 2024-10-27
- [ ] #task Complete this auto-deleting non-recurring task in **Reading view** 🏁 delete 📅 2024-10-27
- [ ] #task Complete this auto-deleting non-recurring task in **Live Preview** 🏁 delete 📅 2024-10-27
- [ ] #task **check**: Checked all above steps for **auto-deleting non-recurring tasks** worked
#### On Completion Delete: Recurring Tasks
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.
- [ ] #task Complete this auto-deleting recurring task in **Source view** using **Tasks: Toggle task done** command 🔁 every day 🏁 delete 📅 2024-10-27
- [ ] #task Complete this auto-deleting recurring task in **Reading view** 🔁 every day 🏁 delete 📅 2024-10-27
- [ ] #task Complete this auto-deleting recurring task in **Live Preview** - ==ensure the checkbox is redrawn correctly== 🔁 every day 🏁 delete 📅 2024-10-27
- [ ] #task **check**: Checked all above steps for **auto-deleting recurring tasks** worked
### Rendering of Task Blocks
Steps to do:
Expand Down
23 changes: 23 additions & 0 deletions src/Obsidian/LivePreviewExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,29 @@ class LivePreviewExtension implements PluginValue {
});
this.view.dispatch(transaction);

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

return true;
}
}

0 comments on commit 9d462e2

Please sign in to comment.