From b685655e516787317dd05352a5d6e2c35c677389 Mon Sep 17 00:00:00 2001 From: Grol Grol Date: Fri, 8 Aug 2025 13:06:19 +0300 Subject: [PATCH] fix infinite loop with tasks plugin --- src/core/model/line/CheckboxLine.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/core/model/line/CheckboxLine.ts b/src/core/model/line/CheckboxLine.ts index e54fc5e..d7f2a6f 100644 --- a/src/core/model/line/CheckboxLine.ts +++ b/src/core/model/line/CheckboxLine.ts @@ -52,9 +52,11 @@ export class CheckboxLine extends AbstractLine { } - private static getNewCheckboxLineFromTasksApi(api: any, checkboxLine: CheckboxLine, targetState: CheckboxState): CheckboxLine|null { + private static getNewCheckboxLineFromTasksApi(api: any, checkboxLine: CheckboxLine, targetState: CheckboxState): CheckboxLine | null { let line: CheckboxLine | null = checkboxLine; - const startChar = checkboxLine.checkChar; + const seenChars = new Set(); + seenChars.add(checkboxLine.checkChar); + while (true) { const textLine = line.toResultText(); const newTextLine = api.executeToggleTaskDoneCommand(textLine, null); @@ -62,12 +64,14 @@ export class CheckboxLine extends AbstractLine { if (!newBox) { return null; } - if (newBox.checkboxState === targetState){ + if (newBox.checkboxState === targetState) { return newBox; } - if (newBox.checkChar === startChar){ + if (seenChars.has(newBox.checkChar)) { return null; } + + seenChars.add(newBox.checkChar); line = newBox; } } @@ -77,7 +81,7 @@ export class CheckboxLine extends AbstractLine { if (taskPlugin) { const api = taskPlugin.apiV1; const res = CheckboxLine.getNewCheckboxLineFromTasksApi(api, this, state); - if (res !== null){ + if (res !== null) { this.listText = res.listText; } }