Skip to content

Commit bbfb99b

Browse files
committed
feat(timer): show timer widget on all first-level tasks
Changed task timer display logic to show timer widgets on all first-level (top-level) tasks, not just those with subtasks. This provides more consistent timer functionality across all main tasks while still excluding completed and abandoned tasks. - Add minimum indentation level detection - Replace subtask requirement with first-level task check - Update logging to reflect new logic
1 parent e77c59f commit bbfb99b

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

src/editor-ext/taskTimer.ts

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,23 @@ function createTaskTimerDecorations(state: EditorState): DecorationSet {
888888

889889
console.log("[TaskTimer] Document has", doc.lines, "lines");
890890

891+
// First pass: find the minimum indentation level among all tasks
892+
let minIndentLevel = Infinity;
893+
for (let i = 1; i <= doc.lines; i++) {
894+
const line = doc.line(i);
895+
const lineText = line.text;
896+
897+
// Check if this line contains a task
898+
if (isTaskLine(lineText)) {
899+
const currentIndent = lineText.match(/^(\s*)/)?.[1].length || 0;
900+
if (currentIndent < minIndentLevel) {
901+
minIndentLevel = currentIndent;
902+
}
903+
}
904+
}
905+
906+
console.log("[TaskTimer] Minimum indent level found:", minIndentLevel);
907+
891908
// Process all lines in the document
892909
for (let i = 1; i <= doc.lines; i++) {
893910
const line = doc.line(i);
@@ -897,29 +914,11 @@ function createTaskTimerDecorations(state: EditorState): DecorationSet {
897914
if (isTaskLine(lineText)) {
898915
console.log("[TaskTimer] Found task line:", lineText.trim());
899916

900-
// Check if this task has any subtasks (not just immediate next line)
917+
// Check if this is a first-level task
901918
const currentIndent = lineText.match(/^(\s*)/)?.[1].length || 0;
902-
let hasSubtasks = false;
903-
904-
// Look ahead for subtasks with greater indentation
905-
for (let j = i + 1; j <= doc.lines; j++) {
906-
const checkLine = doc.line(j);
907-
const checkLineText = checkLine.text;
908-
const checkIndent = checkLineText.match(/^(\s*)/)?.[1].length || 0;
909-
910-
// If we hit a line with same or less indentation, stop checking
911-
if (checkLineText.trim() && checkIndent <= currentIndent) {
912-
break;
913-
}
914-
915-
// If we find a task line with greater indentation, this is a parent
916-
if (checkIndent > currentIndent && isTaskLine(checkLineText)) {
917-
hasSubtasks = true;
918-
break;
919-
}
920-
}
919+
const isFirstLevel = currentIndent === minIndentLevel;
921920

922-
if (hasSubtasks) {
921+
if (isFirstLevel) {
923922
// Check task status - only skip completed tasks without existing timers
924923
const taskStatusMatch = lineText.match(/^\s*[-*+]\s+\[([^\]]+)\]/);
925924
if (taskStatusMatch) {
@@ -950,7 +949,7 @@ function createTaskTimerDecorations(state: EditorState): DecorationSet {
950949
}
951950
}
952951

953-
console.log("[TaskTimer] Found parent task with subtasks at line", i);
952+
console.log("[TaskTimer] Found first-level task at line", i);
954953
// Extract existing block reference if present
955954
const existingBlockId = extractBlockRef(lineText);
956955

@@ -972,7 +971,7 @@ function createTaskTimerDecorations(state: EditorState): DecorationSet {
972971

973972
// Add decoration at the start of the line (this will appear above the task)
974973
decorations.push(timerDeco.range(line.from));
975-
console.log("[TaskTimer] Added timer decoration for line:", i);
974+
console.log("[TaskTimer] Added timer decoration for first-level task at line:", i);
976975
}
977976
}
978977
}

0 commit comments

Comments
 (0)