-
-
Notifications
You must be signed in to change notification settings - Fork 244
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
Tasks rendered in Reading Mode are not always updated when source file is edited #1680
Comments
Hey Clare, this is good information. It clarifies the issue a lot! Cache EventsThe // Line 91:
this.renderEventRef = this.events.onCacheUpdate(this.render.bind(this)); The This solution could potentially be inefficient. However, since I assume a limited number of open panes at any time, it could be fine. Inline Renderer's Task HandlingAnother thing I noticed are const task = fileTasks[sectionIndex];
const renderedElement = renderedElements[sectionIndex];
if (task === undefined || renderedElement === undefined) {
// Assuming match of tasks in file and render preview.
// If there is a mis-match in the numbers, we still process
// what we can.
continue;
} The comment before the "Correct" SolutionI don't know what the "correct" solution would be. Replacing the inline HTML has been dirty from the beginning. It was a kind of 80/20 solution. But I also don't know what better to do if Tasks should support rendering tasks with, for example, the setting "remove global filter". |
Some notes on the behaviour as a consequence of this issue... Setup
Note: The blank lines are important, so if in the Tasks repo, don't run
Behaviour in Tasks 1.25.0 - wrong line overwritten
With feaafaf - latest code on
|
const line = fileLines[listItemCache.position.start.line]; | |
if (line.includes(globalFilter)) { | |
if (sectionIndex === originalTask.sectionIndex) { | |
if (line === originalTask.originalMarkdown) { | |
listItem = listItemCache; | |
} else { | |
errorAndNotice( | |
`Tasks: Unable to find task in file ${originalTask.path}. |
Update 2023-03-20 - that traceback has been fixed in #1772.
See the comment #1680 (comment) in #1680. If lines had been deleted from a file, and it was not yet saved when user then toggled a line near the end of the file in Reading mode, there could be an access of a non-existent line number. The resultant output was: plugin:obsidian-tasks-plugin:17605 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'includes') at eval (plugin:obsidian-tasks-plugin:17605:14) at Generator.next (<anonymous>) at fulfilled (plugin:obsidian-tasks-plugin:173:24)
…1772) * fix: Prevent exception if toggling in unsaved file in Reading mode See the comment #1680 (comment) in #1680. If lines had been deleted from a file, and it was not yet saved when user then toggled a line near the end of the file in Reading mode, there could be an access of a non-existent line number. The resultant output was: plugin:obsidian-tasks-plugin:17605 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'includes') at eval (plugin:obsidian-tasks-plugin:17605:14) at Generator.next (<anonymous>) at fulfilled (plugin:obsidian-tasks-plugin:173:24) * comment: Fix typo
1680 - Reading Mode line numbers not updated on editing.md
Please check that this issue hasn't been reported before.
Expected Behavior
This is initially a placeholder report: I will edit and add more info as I find more out.
Given a file is open in both two panes:
When I add or remove lines from the file
Then rendered tasks in the Reading pane should always be updated, so that that when I toggle them, the correct line is toggled.
Current behaviour
Given a file is open in both two panes:
When I add or remove lines from the file
Then rendered tasks in the Reading pane are only updated when any tasks in the file are edited
Steps to reproduce
Summary
The steps below make some changes to the Tasks source code so that some internal information is made visible.
Whenever Tasks renders a task, this code will add the following line for debugging purposes:
The information is:
Making this information visible has revealed that in Reading mode, the rendering of tasks is not updated when lines are added and removed from the source file.
I believe that this is one fundamental cause of Tasks sometimes updating the wrong source line.
Steps
Now experiment.
Initial Display
Initially, the sectionStart and sectionIndex are consistent between rendered tasks and rendered task blocks in Reading mode
Other things to note:
InlineRenderer
does not populate that informationtask.sectionIndex
is actually the 0-based index of the first task in a section, not the 0-based index of the section headingExperiment
Add and remove some lines in the source view, in various locations.
You will see that the position numbers in the tasks block are updated, but the ones in the rendered tasks are not.
The patches
These are based on code in my fork, at this revision: claremacrae@dfb720e
Which Operating Systems are you using?
Obsidian Version
1.1.14
Tasks Plugin Version
1.25.0
Checks
Possible solution
I suspect the problem is that
InlineRenderer
should probably useMarkdownPostProcessorContext.addChild()
This is based on these instructions:
https://github.com/obsidianmd/obsidian-api/blob/bceb489fc25ceba5973119d6e57759d64850f90d/obsidian.d.ts#L1927-L1936
The text was updated successfully, but these errors were encountered: