@@ -23,7 +23,7 @@ export class TagViewComponent extends TwoColumnViewBase<string> {
2323 constructor (
2424 parentEl : HTMLElement ,
2525 app : App ,
26- plugin : TaskProgressBarPlugin
26+ plugin : TaskProgressBarPlugin ,
2727 ) {
2828 // 配置基类需要的参数
2929 const config : TwoColumnViewConfig = {
@@ -45,31 +45,32 @@ export class TagViewComponent extends TwoColumnViewBase<string> {
4545 * @returns Normalized tag with # prefix
4646 */
4747 private normalizeTag ( tag : string ) : string {
48- if ( typeof tag !== ' string' ) {
48+ if ( typeof tag !== " string" ) {
4949 return tag ;
5050 }
51-
51+
5252 // Trim whitespace
5353 const trimmed = tag . trim ( ) ;
54-
54+
5555 // If empty or already starts with #, return as is
56- if ( ! trimmed || trimmed . startsWith ( '#' ) ) {
56+ if ( ! trimmed || trimmed . startsWith ( "#" ) ) {
5757 return trimmed ;
5858 }
59-
59+
6060 // Add # prefix
6161 return `#${ trimmed } ` ;
6262 }
6363
6464 /**
6565 * 重写基类中的索引构建方法,为标签创建索引
66+ * 使用 sourceTasks(筛选后的任务)构建索引,确保左侧栏只显示相关标签
6667 */
6768 protected buildItemsIndex ( ) : void {
6869 // 清除已有索引
6970 this . allTagsMap . clear ( ) ;
7071
71- // 为每个任务的标签建立索引
72- this . allTasks . forEach ( ( task ) => {
72+ // 使用 sourceTasks(筛选后的任务) 为每个任务的标签建立索引
73+ this . sourceTasks . forEach ( ( task ) => {
7374 if ( task . metadata . tags && task . metadata . tags . length > 0 ) {
7475 task . metadata . tags . forEach ( ( tag ) => {
7576 // 跳过非字符串类型的标签
@@ -139,7 +140,7 @@ export class TagViewComponent extends TwoColumnViewBase<string> {
139140 private renderTagHierarchy (
140141 node : Record < string , any > ,
141142 parentEl : HTMLElement ,
142- level : number
143+ level : number ,
143144 ) {
144145 // 按字母排序键,但排除元数据属性
145146 const keys = Object . keys ( node )
@@ -212,7 +213,7 @@ export class TagViewComponent extends TwoColumnViewBase<string> {
212213 this . renderTagHierarchy (
213214 childNode ,
214215 childrenContainer ,
215- level + 1
216+ level + 1 ,
216217 ) ;
217218 }
218219 } ) ;
@@ -260,9 +261,9 @@ export class TagViewComponent extends TwoColumnViewBase<string> {
260261 set . forEach ( ( id ) => resultTaskIds . add ( id ) ) ;
261262 } ) ;
262263
263- // 将任务ID转换为实际任务对象
264- this . filteredTasks = this . allTasks . filter ( ( task ) =>
265- resultTaskIds . has ( task . id )
264+ // 将任务ID转换为实际任务对象(从 sourceTasks 中筛选,保持外部过滤状态)
265+ this . filteredTasks = this . sourceTasks . filter ( ( task ) =>
266+ resultTaskIds . has ( task . id ) ,
266267 ) ;
267268
268269 // 按优先级和截止日期排序
@@ -313,7 +314,7 @@ export class TagViewComponent extends TwoColumnViewBase<string> {
313314 ( taskTag ) =>
314315 // 跳过非字符串类型的标签
315316 typeof taskTag === "string" &&
316- ( taskTag === tag || taskTag . startsWith ( tag + "/" ) )
317+ ( taskTag === tag || taskTag . startsWith ( tag + "/" ) ) ,
317318 ) ;
318319 } ) ;
319320
@@ -346,7 +347,7 @@ export class TagViewComponent extends TwoColumnViewBase<string> {
346347 let title = t ( this . config . rightColumnDefaultTitle ) ;
347348 if ( this . selectedItems . items . length > 1 ) {
348349 title = `${ this . selectedItems . items . length } ${ t (
349- this . config . multiSelectText
350+ this . config . multiSelectText ,
350351 ) } `;
351352 }
352353 const countText = `${ this . filteredTasks . length } ${ t ( "tasks" ) } ` ;
@@ -364,7 +365,7 @@ export class TagViewComponent extends TwoColumnViewBase<string> {
364365 const toggleEl = headerEl . createDiv ( { cls : "section-toggle" } ) ;
365366 setIcon (
366367 toggleEl ,
367- section . isExpanded ? "chevron-down" : "chevron-right"
368+ section . isExpanded ? "chevron-down" : "chevron-right" ,
368369 ) ;
369370 const titleEl = headerEl . createDiv ( { cls : "section-title" } ) ;
370371 titleEl . setText ( `#${ section . tag . replace ( "#" , "" ) } ` ) ;
@@ -382,7 +383,7 @@ export class TagViewComponent extends TwoColumnViewBase<string> {
382383 taskListEl ,
383384 this . plugin ,
384385 this . app ,
385- this . config . rendererContext
386+ this . config . rendererContext ,
386387 ) ;
387388 section . renderer . onTaskSelected = this . onTaskSelected ;
388389 section . renderer . onTaskCompleted = this . onTaskCompleted ;
@@ -393,15 +394,15 @@ export class TagViewComponent extends TwoColumnViewBase<string> {
393394 section . tasks ,
394395 this . isTreeView ,
395396 this . allTasksMap ,
396- t ( "No tasks found for this tag." )
397+ t ( "No tasks found for this tag." ) ,
397398 ) ;
398399
399400 // 注册切换事件
400401 this . registerDomEvent ( headerEl , "click" , ( ) => {
401402 section . isExpanded = ! section . isExpanded ;
402403 setIcon (
403404 toggleEl ,
404- section . isExpanded ? "chevron-down" : "chevron-right"
405+ section . isExpanded ? "chevron-down" : "chevron-right" ,
405406 ) ;
406407 section . isExpanded ? taskListEl . show ( ) : taskListEl . hide ( ) ;
407408 } ) ;
@@ -446,9 +447,12 @@ export class TagViewComponent extends TwoColumnViewBase<string> {
446447 * 更新任务
447448 */
448449 public updateTask ( updatedTask : Task ) : void {
450+ // 更新 allTasksMap
451+ this . allTasksMap . set ( updatedTask . id , updatedTask ) ;
452+
449453 let needsFullRefresh = false ;
450454 const taskIndex = this . allTasks . findIndex (
451- ( t ) => t . id === updatedTask . id
455+ ( t ) => t . id === updatedTask . id ,
452456 ) ;
453457
454458 if ( taskIndex !== - 1 ) {
@@ -469,6 +473,14 @@ export class TagViewComponent extends TwoColumnViewBase<string> {
469473 needsFullRefresh = true ; // 新任务,需要完全刷新
470474 }
471475
476+ // 同时更新 sourceTasks(如果任务存在于其中)
477+ const sourceIndex = this . sourceTasks . findIndex (
478+ ( t ) => t . id === updatedTask . id ,
479+ ) ;
480+ if ( sourceIndex !== - 1 ) {
481+ this . sourceTasks [ sourceIndex ] = updatedTask ;
482+ }
483+
472484 // 如果标签变化或任务是新的,重建索引并完全刷新UI
473485 if ( needsFullRefresh ) {
474486 this . buildItemsIndex ( ) ;
@@ -477,7 +489,7 @@ export class TagViewComponent extends TwoColumnViewBase<string> {
477489 } else {
478490 // 否则,仅更新过滤列表中的任务
479491 const filteredIndex = this . filteredTasks . findIndex (
480- ( t ) => t . id === updatedTask . id
492+ ( t ) => t . id === updatedTask . id ,
481493 ) ;
482494 if ( filteredIndex !== - 1 ) {
483495 this . filteredTasks [ filteredIndex ] = updatedTask ;
@@ -495,13 +507,13 @@ export class TagViewComponent extends TwoColumnViewBase<string> {
495507 // 跳过非字符串类型的标签
496508 typeof taskTag === "string" &&
497509 ( taskTag === section . tag ||
498- taskTag . startsWith ( section . tag + "/" ) )
510+ taskTag . startsWith ( section . tag + "/" ) ) ,
499511 )
500512 ) {
501513 // 检查任务是否实际存在于此分区的列表中
502514 if (
503515 section . tasks . some (
504- ( t ) => t . id === updatedTask . id
516+ ( t ) => t . id === updatedTask . id ,
505517 )
506518 ) {
507519 section . renderer ?. updateTask ( updatedTask ) ;
0 commit comments