Skip to content

Commit 1108757

Browse files
committed
🐛 粘贴创建任务没有添加块书签
1 parent 61d9570 commit 1108757

File tree

4 files changed

+74
-14
lines changed

4 files changed

+74
-14
lines changed

src/components/CalendarView.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4105,7 +4105,15 @@ export class CalendarView {
41054105

41064106
await writeReminderData(reminderData);
41074107

4108-
// 更新块的书签状态
4108+
// 将绑定的块添加项目ID属性 custom-task-projectId
4109+
const projectId = reminderData[reminderId].projectId;
4110+
if (projectId) {
4111+
const { addBlockProjectId } = await import('../api');
4112+
await addBlockProjectId(blockId, projectId);
4113+
console.debug('CalendarView: bindReminderToBlock - 已为块设置项目ID', blockId, projectId);
4114+
}
4115+
4116+
// 更新块的书签状态(添加⏰书签)
41094117
await updateBlockReminderBookmark(blockId);
41104118

41114119
// 触发更新事件

src/components/EisenhowerMatrixView.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4079,6 +4079,18 @@ export class EisenhowerMatrixView {
40794079
reminderData[task.id].blockId = blockId;
40804080
await writeReminderData(reminderData);
40814081

4082+
// 将绑定的块添加项目ID属性 custom-task-projectId
4083+
const projectId = reminderData[task.id].projectId;
4084+
if (projectId) {
4085+
const { addBlockProjectId } = await import('../api');
4086+
await addBlockProjectId(blockId, projectId);
4087+
console.debug('EisenhowerMatrixView: bindTaskToBlock - 已为块设置项目ID', blockId, projectId);
4088+
}
4089+
4090+
// 更新块的书签状态(添加⏰书签)
4091+
const { updateBlockReminderBookmark } = await import('../api');
4092+
await updateBlockReminderBookmark(blockId);
4093+
40824094
await this.refresh();
40834095
window.dispatchEvent(new CustomEvent('reminderUpdated'));
40844096
}

src/components/ProjectKanbanView.ts

Lines changed: 44 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,7 +2822,7 @@ export class ProjectKanbanView {
28222822
titleEl.dataset.type = 'a';
28232823
titleEl.dataset.href = `siyuan://blocks/${group.blockId}`;
28242824
titleEl.style.cursor = 'pointer';
2825-
titleEl.style.borderBottom = '2px dashed currentColor';
2825+
titleEl.style.textDecoration = 'underline';
28262826
titleEl.style.paddingBottom = '2px';
28272827
titleEl.title = t('clickToJumpToBlock');
28282828
titleEl.addEventListener('click', (e) => {
@@ -2860,10 +2860,22 @@ export class ProjectKanbanView {
28602860
this.showCreateTaskDialog(undefined, gid);
28612861
});
28622862

2863+
// 粘贴新建任务按钮(对应该自定义分组)
2864+
const pasteGroupTaskBtn = document.createElement('button');
2865+
pasteGroupTaskBtn.className = 'b3-button b3-button--outline';
2866+
pasteGroupTaskBtn.title = t('pasteNew');
2867+
pasteGroupTaskBtn.innerHTML = `<svg class="b3-button__icon"><use xlink:href="#iconPaste"></use></svg>`;
2868+
pasteGroupTaskBtn.addEventListener('click', (e) => {
2869+
e.stopPropagation();
2870+
const gid = group.id === 'ungrouped' ? null : group.id;
2871+
this.showPasteTaskDialog(undefined, gid);
2872+
});
2873+
28632874
const headerRight = document.createElement('div');
28642875
headerRight.style.cssText = 'display:flex; align-items:center; gap:8px;';
28652876
headerRight.appendChild(countEl);
28662877
headerRight.appendChild(addGroupTaskBtn);
2878+
headerRight.appendChild(pasteGroupTaskBtn);
28672879

28682880
header.appendChild(headerRight);
28692881

@@ -5068,7 +5080,7 @@ export class ProjectKanbanView {
50685080
}
50695081
}
50705082

5071-
private showPasteTaskDialog(parentTask?: any) {
5083+
private showPasteTaskDialog(parentTask?: any, customGroupId?: string) {
50725084
const dialog = new Dialog({
50735085
title: "粘贴列表新建任务",
50745086
content: `
@@ -5118,9 +5130,9 @@ export class ProjectKanbanView {
51185130
if (hierarchicalTasks.length > 0) {
51195131
// 如果传入 parentTask,则把所有顶级解析项作为 parentTask 的子任务
51205132
if (parentTask) {
5121-
await this.batchCreateTasksWithHierarchy(hierarchicalTasks, parentTask.id);
5133+
await this.batchCreateTasksWithHierarchy(hierarchicalTasks, parentTask.id, customGroupId);
51225134
} else {
5123-
await this.batchCreateTasksWithHierarchy(hierarchicalTasks);
5135+
await this.batchCreateTasksWithHierarchy(hierarchicalTasks, undefined, customGroupId);
51245136
}
51255137
dialog.destroy();
51265138
const totalTasks = this.countTotalTasks(hierarchicalTasks);
@@ -5225,8 +5237,10 @@ export class ProjectKanbanView {
52255237
/**
52265238
* 批量创建层级化任务
52275239
* @param tasks 层级化任务列表
5240+
* @param parentIdForAllTopLevel 所有顶级任务的父任务ID
5241+
* @param customGroupId 自定义分组ID
52285242
*/
5229-
private async batchCreateTasksWithHierarchy(tasks: HierarchicalTask[], parentIdForAllTopLevel?: string) {
5243+
private async batchCreateTasksWithHierarchy(tasks: HierarchicalTask[], parentIdForAllTopLevel?: string, customGroupId?: string) {
52305244
const reminderData = await readReminderData();
52315245
const categoryId = this.project.categoryId; // 继承项目分类
52325246

@@ -5241,7 +5255,8 @@ export class ProjectKanbanView {
52415255
const createTaskRecursively = async (
52425256
task: HierarchicalTask,
52435257
parentId?: string,
5244-
parentPriority?: string
5258+
parentPriority?: string,
5259+
inheritedGroupId?: string
52455260
): Promise<string> => {
52465261
const taskId = `quick_${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
52475262
sortCounter += 10;
@@ -5270,8 +5285,10 @@ export class ProjectKanbanView {
52705285
newTask.parentId = parentId;
52715286
}
52725287

5273-
// 如果有父任务ID,尝试继承父任务的 customGroupId
5274-
if (parentId) {
5288+
// 设置自定义分组ID(优先使用传入的inheritedGroupId,其次继承父任务的customGroupId)
5289+
if (inheritedGroupId) {
5290+
newTask.customGroupId = inheritedGroupId;
5291+
} else if (parentId) {
52755292
const parent = reminderData[parentId];
52765293
if (parent && parent.customGroupId) {
52775294
newTask.customGroupId = parent.customGroupId;
@@ -5291,7 +5308,14 @@ export class ProjectKanbanView {
52915308
newTask.title = block.content || block.fcontent || t('noContentHint');
52925309
}
52935310

5294-
// 更新块的书签状态
5311+
// 将绑定的块添加项目ID属性 custom-task-projectId
5312+
if (this.projectId) {
5313+
const { addBlockProjectId } = await import('../api');
5314+
await addBlockProjectId(task.blockId, this.projectId);
5315+
console.debug('ProjectKanbanView: 粘贴新建任务 - 已为块设置项目ID', task.blockId, this.projectId);
5316+
}
5317+
5318+
// 更新块的书签状态(添加⏰书签)
52955319
await updateBlockReminderBookmark(task.blockId);
52965320
}
52975321
} catch (error) {
@@ -5305,7 +5329,7 @@ export class ProjectKanbanView {
53055329
// 递归创建子任务
53065330
if (task.children && task.children.length > 0) {
53075331
for (let i = 0; i < task.children.length; i++) {
5308-
await createTaskRecursively(task.children[i], taskId, inheritedPriority);
5332+
await createTaskRecursively(task.children[i], taskId, inheritedPriority, inheritedGroupId);
53095333
}
53105334
}
53115335

@@ -5325,7 +5349,7 @@ export class ProjectKanbanView {
53255349
parentPriority = parentTask?.priority;
53265350
}
53275351

5328-
await createTaskRecursively(tasks[i], topParent, parentPriority);
5352+
await createTaskRecursively(tasks[i], topParent, parentPriority, customGroupId);
53295353
}
53305354

53315355
await writeReminderData(reminderData);
@@ -7000,7 +7024,15 @@ export class ProjectKanbanView {
70007024

70017025
await writeReminderData(reminderData);
70027026

7003-
// 更新块的书签状态
7027+
// 将绑定的块添加项目ID属性 custom-task-projectId
7028+
const projectId = reminderData[reminderId].projectId;
7029+
if (projectId) {
7030+
const { addBlockProjectId } = await import('../api');
7031+
await addBlockProjectId(blockId, projectId);
7032+
console.debug('ProjectKanbanView: bindReminderToBlock - 已为块设置项目ID', blockId, projectId);
7033+
}
7034+
7035+
// 更新块的书签状态(添加⏰书签)
70047036
await updateBlockReminderBookmark(blockId);
70057037

70067038
// 触发更新事件

src/components/ReminderPanel.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6157,7 +6157,15 @@ export class ReminderPanel {
61576157

61586158
await writeReminderData(reminderData);
61596159

6160-
// 更新块的书签状态
6160+
// 将绑定的块添加项目ID属性 custom-task-projectId
6161+
const projectId = reminderData[reminderId].projectId;
6162+
if (projectId) {
6163+
const { addBlockProjectId } = await import('../api');
6164+
await addBlockProjectId(blockId, projectId);
6165+
console.debug('ReminderPanel: bindReminderToBlock - 已为块设置项目ID', blockId, projectId);
6166+
}
6167+
6168+
// 更新块的书签状态(添加⏰书签)
61616169
await updateBlockReminderBookmark(blockId);
61626170

61636171
// 触发更新事件

0 commit comments

Comments
 (0)