diff --git a/src/Obsidian/Cache.ts b/src/Obsidian/Cache.ts index 3f3387dd6d..454b45d694 100644 --- a/src/Obsidian/Cache.ts +++ b/src/Obsidian/Cache.ts @@ -43,43 +43,43 @@ export function getTasksFromFileContent2( let sectionIndex = 0; const line2ListItem: Map = new Map(); for (const listItem of listItems) { - if (listItem.task !== undefined) { - const lineNumber = listItem.position.start.line; - if (lineNumber >= linesInFile) { - /* - Obsidian CachedMetadata has told us that there is a task on lineNumber, but there are - not that many lines in the file. - - This was the underlying cause of all the 'Stuck on "Loading Tasks..."' messages, - as it resulted in the line 'undefined' being parsed. - - Somehow the file had been shortened whilst Obsidian was closed, meaning that - when Obsidian started up, it got the new file content, but still had the old cached - data about locations of list items in the file. - */ - logger.debug( - `${filePath} Obsidian gave us a line number ${lineNumber} past the end of the file. ${linesInFile}.`, - ); - return tasks; - } - if (currentSection === null || currentSection.position.end.line < lineNumber) { - // We went past the current section (or this is the first task). - // Find the section that is relevant for this task and the following of the same section. - currentSection = Cache.getSection(lineNumber, fileCache.sections); - sectionIndex = 0; - } + const lineNumber = listItem.position.start.line; + if (lineNumber >= linesInFile) { + /* + Obsidian CachedMetadata has told us that there is a task on lineNumber, but there are + not that many lines in the file. + + This was the underlying cause of all the 'Stuck on "Loading Tasks..."' messages, + as it resulted in the line 'undefined' being parsed. + + Somehow the file had been shortened whilst Obsidian was closed, meaning that + when Obsidian started up, it got the new file content, but still had the old cached + data about locations of list items in the file. + */ + logger.debug( + `${filePath} Obsidian gave us a line number ${lineNumber} past the end of the file. ${linesInFile}.`, + ); + return tasks; + } + if (currentSection === null || currentSection.position.end.line < lineNumber) { + // We went past the current section (or this is the first task). + // Find the section that is relevant for this task and the following of the same section. + currentSection = Cache.getSection(lineNumber, fileCache.sections); + sectionIndex = 0; + } - if (currentSection === null) { - // Cannot process a task without a section. - continue; - } + if (currentSection === null) { + // Cannot process a task without a section. + continue; + } - const line = fileLines[lineNumber]; - if (line === undefined) { - logger.debug(`${filePath}: line ${lineNumber} - ignoring 'undefined' line.`); - continue; - } + const line = fileLines[lineNumber]; + if (line === undefined) { + logger.debug(`${filePath}: line ${lineNumber} - ignoring 'undefined' line.`); + continue; + } + if (listItem.task !== undefined) { let task; try { task = Task.fromLine({