Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions PR.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# fix-task-prop-based-ident

## Property-based task identification preserves tags

This change prevents property-based identification from mutating tags automatically. Tags are only written when the user explicitly sets them (including default tags), while the identifying property is still applied.

Examples (illustrative):

- Creating a task with property identification and tags like `client, urgent` keeps those tags; no extra task tag is injected.
- Updating priority/status without touching tags leaves existing tags unchanged.

## Changelog

### Task Identification

- Only add the identifying task tag to frontmatter when tag-based identification is enabled.
- In property-based mode, preserve user/default tags without filtering them out.
- Only write `frontmatter.tags` during updates when tags are explicitly provided; otherwise leave tags untouched.
- Fixes callumalpass/tasknotes#1391.
36 changes: 13 additions & 23 deletions src/services/TaskService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,15 @@ export class TaskService {
icsEventId: taskData.icsEventId || undefined,
};

const shouldAddTaskTag = this.plugin.settings.taskIdentificationMethod === "tag";
const taskTagForFrontmatter = shouldAddTaskTag
? this.plugin.settings.taskTag
: undefined;

// Use field mapper to convert to frontmatter with proper field mapping
const frontmatter = this.plugin.fieldMapper.mapToFrontmatter(
completeTaskData,
this.plugin.settings.taskTag,
taskTagForFrontmatter,
this.plugin.settings.storeTitleInFilename
);

Expand All @@ -361,12 +366,8 @@ export class TaskService {
lower === "true" || lower === "false" ? lower === "true" : propValue;
frontmatter[propName] = coercedValue as any;
}
// Remove task tag from tags array if using property identification
const filteredTags = tagsArray.filter(
(tag: string) => tag !== this.plugin.settings.taskTag
);
if (filteredTags.length > 0) {
frontmatter.tags = filteredTags;
if (tagsArray.length > 0) {
frontmatter.tags = tagsArray;
}
} else {
// Tags are handled separately (not via field mapper)
Expand Down Expand Up @@ -1374,23 +1375,12 @@ export class TaskService {
}

if (updates.hasOwnProperty("tags")) {
let tagsToSet = updates.tags;
// Remove task tag if using property identification
if (this.plugin.settings.taskIdentificationMethod === "property" && tagsToSet) {
tagsToSet = tagsToSet.filter(
(tag: string) => tag !== this.plugin.settings.taskTag
);
}
frontmatter.tags = tagsToSet;
} else if (originalTask.tags) {
let tagsToSet = originalTask.tags;
// Remove task tag if using property identification
if (this.plugin.settings.taskIdentificationMethod === "property") {
tagsToSet = tagsToSet.filter(
(tag: string) => tag !== this.plugin.settings.taskTag
);
const tagsToSet = Array.isArray(updates.tags) ? [...updates.tags] : [];
if (tagsToSet.length > 0) {
frontmatter.tags = tagsToSet;
} else {
delete frontmatter.tags;
}
frontmatter.tags = tagsToSet;
}
});

Expand Down