Skip to content

Commit 256f14f

Browse files
committed
fix(task-gutter): resolve task ID mismatch and status selection issues
- Fix 'Task with ID not found' error by using correct task lookup from TaskManager index - Remove restriction preventing users from re-selecting current task status - Update visual state immediately when status changes in StatusComponent - Ensure task IDs match expected format when parsing tasks in gutter Resolves issues where task gutter would throw errors for missing task IDs and users couldn't revert to original status during task editing.
1 parent 4164e38 commit 256f14f

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

src/components/StatusComponent.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ export class StatusComponent extends Component {
7878
this.registerDomEvent(interactiveElement, "click", (evt) => {
7979
evt.stopPropagation();
8080
evt.preventDefault();
81-
if (status.text === this.getTaskStatus()) {
82-
return;
83-
}
8481

8582
const options = {
8683
...this.task,
@@ -94,6 +91,15 @@ export class StatusComponent extends Component {
9491

9592
this.params.onTaskUpdate?.(this.task, options);
9693
this.params.onTaskStatusSelected?.(status.text);
94+
95+
// Update the current task status to reflect the change
96+
this.task = { ...this.task, status: status.text };
97+
98+
// Update the visual state
99+
this.containerEl.querySelectorAll('.status-option').forEach(el => {
100+
el.removeClass('current');
101+
});
102+
statusEl.addClass('current');
97103
});
98104
});
99105

src/editor-ext/TaskGutterHandler.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,13 @@ const getTaskFromLine = (
143143
lineNum: number
144144
): Task | null => {
145145
try {
146-
// Try to use TaskParsingService from TaskManager if available and enhanced project is enabled
146+
// Try to get the task from TaskManager's index first
147147
if (plugin.taskManager && plugin.settings.projectConfig?.enableEnhancedProject) {
148-
// Use TaskManager's parsing capability which includes TaskParsingService support
149-
const tasks = plugin.taskManager['parseFileWithConfigurableParser'](filePath, line);
150-
if (tasks.length > 0) {
151-
const task = tasks[0];
152-
// Override line number to match the expected behavior
153-
task.line = lineNum;
154-
return task;
148+
// Try to find the task by ID in the existing index
149+
const taskId = `${filePath}-L${lineNum}`;
150+
const existingTask = plugin.taskManager['indexer'].getTaskById(taskId);
151+
if (existingTask) {
152+
return existingTask;
155153
}
156154
}
157155

@@ -162,7 +160,15 @@ const getTaskFromLine = (
162160
);
163161
}
164162

165-
return taskParser.parseTask(line, filePath, lineNum);
163+
const task = taskParser.parseTask(line, filePath, lineNum);
164+
165+
// If we have a task and enhanced project is enabled, ensure the ID matches what TaskManager expects
166+
if (task && plugin.taskManager && plugin.settings.projectConfig?.enableEnhancedProject) {
167+
// Ensure the task ID matches the format used by TaskManager
168+
task.id = `${filePath}-L${lineNum}`;
169+
}
170+
171+
return task;
166172
} catch (error) {
167173
console.error("Error parsing task:", error);
168174
return null;

0 commit comments

Comments
 (0)