obsidian-tasks: When a block-referenced task is made complete, it is completed after rewriting the contents of another task.

Expected Behavior

When a block-referenced task is made complete, the correct task is completed.

Current Behavior

When a block-referenced task is made complete, it is completed after rewriting the contents of another task.

Steps to Reproduce

Complete task2 referenced by ref task2 with Live Preview of the following Markdown

## Category1 
- [ ] task1

## Category 2
- [ ] task2 ^ca47c7

---
- ref task2 ![[#^ca47c7]]
  1. before screen1

  2. after screen2

Context (Environment)

  • Obsidian version: 0.14.13
  • Tasks version: 1.5.1
  • I have tried it with all other plugins disabled and the error still occurs

Possible Solution

No idea.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 27 (3 by maintainers)

Commits related to this issue

Most upvoted comments

working on solving this right now and I admit I’m having a little bit of fun 😄

https://user-images.githubusercontent.com/38915815/218335057-c0a9daeb-c1a4-4e88-840b-25be3fb2c89c.mov

Hi @BluBloos, thanks very much for all your efforts on this. I am really happy to be guided by your recommendations.

I do agree that documenting the issue would be OK too.

Thanks very much for investigating this!

I feel the solution to this is the issue elsewhere about not overwriting a task line whose content differs from the task being completed…

Then, at least the user’s data will not be corrupted.

The other solution is to document an example carefully and log an issue in the Forum. Doing so well enough to get the issue implemented takes several hours of effort in my experience.

As schemar mentioned in a previous comment,

Shouldn’t Obsidian’s API provide the correct section data?

I’m afraid there may indeed be a shortcoming in what Ob API is offering us.

To summarize the issue:

  1. The InlineRenderer class acts on some generated HTML from some .md. This rendering applies when in “Reading” mode or in an inline markdown block.
  2. The inline markdown blocks can be created with ![[noteName]], ![[#someHeader]], and ![[^foo]].
  3. InlineRenderer loops through all list items in the HTML to create a list of tasks (Task[]). The sectionStart for each Task comes direct from a call to myMarkdownPostProcessorContext.getSectionInfo(taskHTMLelem).
  4. the section information returned appears to be relative to the beginning of the inline markdown block, as opposed to the beginning of the source note from which the inline markdown block is sourcing its content.
  5. in the particular repro example used until now for the issue, the section information of (0,0) is returned since within the inline markdown block the task is inside the first section and is the first item. replaceTaskWithTasks sees this section information and replaces our toggled task into the very first task in the source file.
  6. in the screencap I posted just above, I click the second task and thus replacing the second overall task within the source file.
  7. All cases of ![[noteName]] work OK since the inline markdown block begins at the beginning of the source note.

  1. Therefore the troublesome cases are ![[#someHeader]] and ![[^foo]].

Without adjustments to the Ob API (unless someone can ideate a workaround), I suggest it be documented as a “known issue” …

At first I thought it was a rare occurrence too, but I have confirmed that it is reproducible, so I am reporting it. I’m glad to be able to contribute to obsidian-tasks, as I make the most use of it among the obsidian plugins.