diff --git a/src/block_utils.ts b/src/block_utils.ts index eba094c..a8f5061 100644 --- a/src/block_utils.ts +++ b/src/block_utils.ts @@ -20,10 +20,8 @@ export abstract class BlockUtils { console.log('error reading FileCache (empty file?)'); return; } - let currentBlock: SectionCache | ListItemCache = (() => { - const i = sections.findIndex(section => section.position.start.line > cursor.line); - return i > 0 ? sections[i - 1] : sections[sections.length - 1]; - })(); + const foundSectionIndex = sections.findIndex(section => section.position.start.line > cursor.line); + let currentBlock: SectionCache | ListItemCache = foundSectionIndex > 0 ? sections[foundSectionIndex - 1] : sections[sections.length - 1]; if (currentBlock?.type == "list") { currentBlock = fileCache.listItems?.find(section => section.position.start.line <= cursor.line &&