Skip to content
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

fix: Major improvements to toggling tasks in Reading view #1780

Merged
merged 31 commits into from
Mar 21, 2023

Conversation

claremacrae
Copy link
Collaborator

@claremacrae claremacrae commented Mar 21, 2023

Description

tl;dr

Numerous improvements to the behaviour of toggling tasks in Reading view.

  • The correct line is found more often.
  • And if the correct line cannot be found, a meaningful message is displayed, to give the user chance of fixing the problem.

This started as a spike/experiment to see what I could learn about how File.replaceTaskWithTasks() worked. By the end of it, I had made enough improvements that I decided to submit it as-is.

For the cases where a task markdown line appears only once in the file it:

Gory Detail

  • File.ts
    • New behaviours added, for searching for a task line within a file:
      • First, use the original task's original line number: If that line in the current file content matches the original markdown, just edit that line - no need to search
      • Second, if there is only one exact, identical copy of the original task's original markdown, use that line - no need to use the unreliable section info
      • If none of those work, fall back on the old section-based info
    • If the task to toggle could not be found, give the user a clear, actionable message (re-open the file & if possible, remove identical, duplicate tasks
    • Add some debug logging (disabled by default)
    • Re-instate Obsidian's own 'File changed externally, merging changes' facility, for when Tasks edits an un-saved file
      • This seems to be working well
      • Fixing this involved:
        1. removing the recently-added auto-save mechanism in File.ts
        2. re-instating the original retry() if a line could not be found, perhaps because the cache was out-of-date
  • Logging
    • Connect up logging.ts so it can now be used
    • Improve formatting and precision of time-stamps in logging.ts messages
  • Improve a few manual test files in:
    • resources/sample_vaults/Tasks-Demo/Manual Testing/Task Toggling Scenarios/

Motivation and Context

See above.

How has this been tested?

Screenshots (if appropriate)

Example error message that is shown if the line to toggle cannot be found:

image

Types of changes

Changes visible to users:

  • Bug fix (prefix: fix - non-breaking change which fixes an issue)
  • Sample vault (prefix: vault - improvements to the Tasks-Demo sample vault)

Internal changes:

  • Refactor (prefix: refactor - non-breaking change which only improves the design or structure of existing code, and making no changes to its external behaviour)
  • Tests (prefix: test - additions and improvements to unit tests and the smoke tests)

Checklist

Terms

This confims that the timeout mechanism really is working.
This is an optimisation for cases where the file has not
been edited and the line number is valid.

It removes the uncertainty of the existing sections-based
mechanism.
This fixes #688, in the usual case where the embedded task
only appears once in the file.

It also fixes #1680, again so long as the task line only
appears once in the file.
The code now works well without it.

It seems that if we don't auto-save, Obsidian takes care
of merging any changes made in to the file correctly.
1680 - Reading Mode line numbers not updated on editing.md
Also increase the message duration to 15 seconds, to allow user time
to read this longer message.

Example output:

Tasks: Could not find the correct task line to update.

The task line not updated is:
- [ ] #task task2b ^ca47c7

In this markdown file:
"Manual Testing/Task Toggling Scenarios/Embed Task in to Note.md"

Note: further clicks on this checkbox will usually now be ignored until the file is opened (or certain, specific edits are made - it's complicated).

Recommendations:

1. Close all panes that have the above file open, and then re-open the file.

2. Check for exactly identical copies of the task line, in this file, and see if you can make them different.
This will be tidied up later, as part of #1778.
@claremacrae claremacrae added the scope: data integrity Problems that may cause loss or corruption of user data label Mar 21, 2023
@claremacrae claremacrae merged commit 4ea7087 into main Mar 21, 2023
@claremacrae claremacrae deleted the improve-reading-view-toggling branch March 21, 2023 21:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: data integrity Problems that may cause loss or corruption of user data
Projects
Status: 🎉 Released
1 participant