mirror of
https://github.com/taskgenius/taskgenius-plugin.git
synced 2026-07-22 06:40:25 +00:00
fix(date): date and priority issue when using inline editor update content
This commit is contained in:
parent
8d0c349f5c
commit
f6a82d341a
6 changed files with 151 additions and 43 deletions
|
|
@ -68,7 +68,7 @@ module.exports = {
|
|||
"git add .",
|
||||
],
|
||||
"after:release":
|
||||
"echo Successfully released Task Genius v${version} (BETA) to ${repo.repository}.",
|
||||
"echo 'Successfully released Task Genius v${version} (BETA) to ${repo.repository}.'",
|
||||
},
|
||||
git: {
|
||||
requireBranch: ["master", "beta", "develop", "refactor/*"],
|
||||
|
|
@ -96,35 +96,9 @@ module.exports = {
|
|||
},
|
||||
infile: "CHANGELOG-BETA.md",
|
||||
header: "# Beta Changelog\n\nAll notable changes to beta releases will be documented in this file.\n\n",
|
||||
context: {
|
||||
// GitHub 仓库信息,用于生成链接
|
||||
host: "https://github.com",
|
||||
owner: "Quorafind",
|
||||
repository: "Obsidian-Task-Progress-Bar",
|
||||
repoUrl: "https://github.com/Quorafind/Obsidian-Task-Progress-Bar",
|
||||
linkCompare: true, // 生成版本比较链接
|
||||
linkReferences: true, // 生成提交链接
|
||||
},
|
||||
// 限制 git log 的提交范围,避免 ENAMETOOLONG 错误
|
||||
gitRawCommitsOpts: {
|
||||
from: getLastRelevantTag(), // 智能获取上一个相关版本
|
||||
// 简化格式,减少命令行长度
|
||||
format: '%s%n%b%n-hash-%n%H%n-gitTags-%n%d',
|
||||
},
|
||||
writerOpts: {
|
||||
// 确保生成正确的版本标题和链接
|
||||
mainTemplate: `{{#each releases}}
|
||||
## {{#if @root.linkCompare}}[{{version}}]({{@root.repoUrl}}/compare/{{previousTag}}...{{currentTag}}){{else}}{{version}}{{/if}}{{#if title}} "{{title}}"{{/if}}{{#if date}} ({{date}}){{/if}}
|
||||
|
||||
{{#each sections}}
|
||||
### {{title}}
|
||||
|
||||
{{#each commits}}
|
||||
* {{#if scope}}**{{scope}}:** {{/if}}{{subject}}{{#if hash}} ([{{short}}]({{@root.repoUrl}}/commit/{{hash}})){{/if}}
|
||||
{{/each}}
|
||||
|
||||
{{/each}}
|
||||
{{/each}}`,
|
||||
}
|
||||
},
|
||||
"./scripts/ob-bumper.mjs": {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"id": "obsidian-task-progress-bar",
|
||||
"name": "Task Genius",
|
||||
"version": "9.8.0-beta.0",
|
||||
"version": "9.7.6",
|
||||
"minAppVersion": "0.15.2",
|
||||
"description": "Comprehensive task management that includes progress bars, task status cycling, and advanced task tracking features.",
|
||||
"author": "Boninall",
|
||||
|
|
|
|||
|
|
@ -839,7 +839,24 @@ export class InlineEditor extends Component {
|
|||
(input as any)._fieldType = fieldType;
|
||||
(input as any)._updateCallback = updateCallback;
|
||||
|
||||
this.registerDomEvent(input, "input", this.boundHandlers.handleInput);
|
||||
// For date inputs, only save on blur or Enter key, not on input change
|
||||
const isDateField = fieldType && ['dueDate', 'startDate', 'scheduledDate', 'cancelledDate', 'completedDate'].includes(fieldType);
|
||||
|
||||
if (isDateField) {
|
||||
// For date inputs, update the value but don't trigger save on input
|
||||
this.registerDomEvent(input, "input", (e: Event) => {
|
||||
const target = e.target as HTMLInputElement;
|
||||
const updateCallback = (target as any)._updateCallback;
|
||||
if (updateCallback) {
|
||||
updateCallback(target.value);
|
||||
// Don't call debouncedSave here for date fields
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// For non-date inputs, use the regular handler that includes debounced save
|
||||
this.registerDomEvent(input, "input", this.boundHandlers.handleInput);
|
||||
}
|
||||
|
||||
this.registerDomEvent(input, "blur", this.boundHandlers.handleBlur);
|
||||
this.registerDomEvent(
|
||||
input,
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ export class WriteAPI {
|
|||
}
|
||||
|
||||
// Update content if changed
|
||||
if (args.updates.content && args.updates.content !== originalTask.content) {
|
||||
if (args.updates.content !== undefined) {
|
||||
// Extract the task prefix and metadata
|
||||
const prefixMatch = taskLine.match(/^(\s*[-*+]\s*\[[^\]]*\]\s*)/);
|
||||
if (prefixMatch) {
|
||||
|
|
@ -1013,7 +1013,8 @@ export class WriteAPI {
|
|||
}
|
||||
|
||||
// Priority
|
||||
if (args.priority !== undefined && args.priority > 0) {
|
||||
// Only add priority if it's a valid number between 1-5
|
||||
if (typeof args.priority === 'number' && args.priority >= 1 && args.priority <= 5) {
|
||||
if (useDataviewFormat) {
|
||||
let priorityValue: string;
|
||||
switch (args.priority) {
|
||||
|
|
|
|||
|
|
@ -1226,6 +1226,55 @@ export class TaskSpecificView extends ItemView {
|
|||
// Task cache listener will trigger loadTasks -> triggerViewUpdate
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract only the fields that have changed between two tasks
|
||||
*/
|
||||
private extractChangedFields(originalTask: Task, updatedTask: Task): Partial<Task> {
|
||||
const changes: Partial<Task> = {};
|
||||
|
||||
// Check top-level fields
|
||||
if (originalTask.content !== updatedTask.content) {
|
||||
changes.content = updatedTask.content;
|
||||
}
|
||||
if (originalTask.completed !== updatedTask.completed) {
|
||||
changes.completed = updatedTask.completed;
|
||||
}
|
||||
if (originalTask.status !== updatedTask.status) {
|
||||
changes.status = updatedTask.status;
|
||||
}
|
||||
|
||||
// Check metadata fields
|
||||
const metadataChanges: Partial<typeof originalTask.metadata> = {};
|
||||
let hasMetadataChanges = false;
|
||||
|
||||
// Compare each metadata field
|
||||
const metadataFields = ['priority', 'project', 'tags', 'context', 'dueDate', 'startDate', 'scheduledDate', 'completedDate', 'recurrence'];
|
||||
for (const field of metadataFields) {
|
||||
const originalValue = (originalTask.metadata as any)?.[field];
|
||||
const updatedValue = (updatedTask.metadata as any)?.[field];
|
||||
|
||||
// Handle arrays specially (tags)
|
||||
if (field === 'tags') {
|
||||
const origTags = originalValue || [];
|
||||
const updTags = updatedValue || [];
|
||||
if (origTags.length !== updTags.length || !origTags.every((t: string, i: number) => t === updTags[i])) {
|
||||
metadataChanges.tags = updTags;
|
||||
hasMetadataChanges = true;
|
||||
}
|
||||
} else if (originalValue !== updatedValue) {
|
||||
(metadataChanges as any)[field] = updatedValue;
|
||||
hasMetadataChanges = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Only include metadata if there are changes
|
||||
if (hasMetadataChanges) {
|
||||
changes.metadata = metadataChanges as any;
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
private async handleTaskUpdate(originalTask: Task, updatedTask: Task) {
|
||||
if (!this.plugin.writeAPI) {
|
||||
console.error("WriteAPI not available");
|
||||
|
|
@ -1243,10 +1292,14 @@ export class TaskSpecificView extends ItemView {
|
|||
);
|
||||
|
||||
try {
|
||||
// Always use WriteAPI
|
||||
// Extract only the changed fields
|
||||
const updates = this.extractChangedFields(originalTask, updatedTask);
|
||||
|
||||
// Always use WriteAPI with only the changed fields
|
||||
// Use originalTask.id to ensure we're updating the correct task
|
||||
const writeResult = await this.plugin.writeAPI.updateTask({
|
||||
taskId: updatedTask.id,
|
||||
updates: updatedTask,
|
||||
taskId: originalTask.id,
|
||||
updates: updates,
|
||||
});
|
||||
if (!writeResult.success) {
|
||||
throw new Error(writeResult.error || "Failed to update task");
|
||||
|
|
@ -1302,10 +1355,14 @@ export class TaskSpecificView extends ItemView {
|
|||
throw new Error("WriteAPI not available");
|
||||
}
|
||||
try {
|
||||
// Always use WriteAPI
|
||||
// Extract only the changed fields
|
||||
const updates = this.extractChangedFields(originalTask, updatedTask);
|
||||
|
||||
// Always use WriteAPI with only the changed fields
|
||||
// Use originalTask.id to ensure we're updating the correct task
|
||||
const writeResult = await this.plugin.writeAPI.updateTask({
|
||||
taskId: updatedTask.id,
|
||||
updates: updatedTask,
|
||||
taskId: originalTask.id,
|
||||
updates: updates,
|
||||
});
|
||||
if (!writeResult.success) {
|
||||
throw new Error(writeResult.error || "Failed to update task");
|
||||
|
|
|
|||
|
|
@ -1330,6 +1330,55 @@ export class TaskView extends ItemView {
|
|||
await this.updateTask(task, updatedTask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract only the fields that have changed between two tasks
|
||||
*/
|
||||
private extractChangedFields(originalTask: Task, updatedTask: Task): Partial<Task> {
|
||||
const changes: Partial<Task> = {};
|
||||
|
||||
// Check top-level fields
|
||||
if (originalTask.content !== updatedTask.content) {
|
||||
changes.content = updatedTask.content;
|
||||
}
|
||||
if (originalTask.completed !== updatedTask.completed) {
|
||||
changes.completed = updatedTask.completed;
|
||||
}
|
||||
if (originalTask.status !== updatedTask.status) {
|
||||
changes.status = updatedTask.status;
|
||||
}
|
||||
|
||||
// Check metadata fields
|
||||
const metadataChanges: Partial<typeof originalTask.metadata> = {};
|
||||
let hasMetadataChanges = false;
|
||||
|
||||
// Compare each metadata field
|
||||
const metadataFields = ['priority', 'project', 'tags', 'context', 'dueDate', 'startDate', 'scheduledDate', 'completedDate', 'recurrence'];
|
||||
for (const field of metadataFields) {
|
||||
const originalValue = (originalTask.metadata as any)?.[field];
|
||||
const updatedValue = (updatedTask.metadata as any)?.[field];
|
||||
|
||||
// Handle arrays specially (tags)
|
||||
if (field === 'tags') {
|
||||
const origTags = originalValue || [];
|
||||
const updTags = updatedValue || [];
|
||||
if (origTags.length !== updTags.length || !origTags.every((t: string, i: number) => t === updTags[i])) {
|
||||
metadataChanges.tags = updTags;
|
||||
hasMetadataChanges = true;
|
||||
}
|
||||
} else if (originalValue !== updatedValue) {
|
||||
(metadataChanges as any)[field] = updatedValue;
|
||||
hasMetadataChanges = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Only include metadata if there are changes
|
||||
if (hasMetadataChanges) {
|
||||
changes.metadata = metadataChanges as any;
|
||||
}
|
||||
|
||||
return changes;
|
||||
}
|
||||
|
||||
private async handleTaskUpdate(originalTask: Task, updatedTask: Task) {
|
||||
if (!this.plugin.writeAPI) {
|
||||
console.error("WriteAPI not available");
|
||||
|
|
@ -1347,10 +1396,15 @@ export class TaskView extends ItemView {
|
|||
);
|
||||
|
||||
try {
|
||||
// Always use WriteAPI
|
||||
// Extract only the changed fields
|
||||
const updates = this.extractChangedFields(originalTask, updatedTask);
|
||||
console.log("Extracted changes:", updates);
|
||||
|
||||
// Always use WriteAPI with only the changed fields
|
||||
// Use originalTask.id to ensure we're updating the correct task
|
||||
const writeResult = await this.plugin.writeAPI.updateTask({
|
||||
taskId: updatedTask.id,
|
||||
updates: updatedTask
|
||||
taskId: originalTask.id,
|
||||
updates: updates
|
||||
});
|
||||
if (!writeResult.success) {
|
||||
throw new Error(writeResult.error || "Failed to update task");
|
||||
|
|
@ -1404,10 +1458,15 @@ export class TaskView extends ItemView {
|
|||
throw new Error("WriteAPI not available");
|
||||
}
|
||||
try {
|
||||
// Always use WriteAPI
|
||||
// Extract only the changed fields
|
||||
const updates = this.extractChangedFields(originalTask, updatedTask);
|
||||
console.log("Extracted changes:", updates);
|
||||
|
||||
// Always use WriteAPI with only the changed fields
|
||||
// Use originalTask.id to ensure we're updating the correct task
|
||||
const writeResult = await this.plugin.writeAPI.updateTask({
|
||||
taskId: updatedTask.id,
|
||||
updates: updatedTask
|
||||
taskId: originalTask.id,
|
||||
updates: updates
|
||||
});
|
||||
if (!writeResult.success) {
|
||||
throw new Error(writeResult.error || "Failed to update task");
|
||||
|
|
|
|||
Loading…
Reference in a new issue