@@ -524,8 +524,12 @@ kill_tabpage (url win_u, url u) {
524524 tm_window win_tabpage= vw->win_tabpage ;
525525 if (win_tabpage == NULL ) return ;
526526 if (win == NULL ) win= win_tabpage;
527- url current_u = get_current_view_safe ();
528- bool is_current = (!is_none (current_u) && current_u == u);
527+ // 「当前标签页」以是否附着在窗口上(即正在窗口中显示)为准,而非全局焦点
528+ // 视图:AI 侧边栏打开时焦点在聊天输入框(tmfs://chat/<sid>/input 嵌入视
529+ // 图),get_current_view_safe() 并非窗口中显示的文档视图,按焦点判定会
530+ // 把正在显示的标签误判成非当前标签,跳过 detach/attach,导致关闭后 tab
531+ // 栏不刷新、窗口仍显示已删除的视图(需点击其他标签才消失)。
532+ bool is_current = (vw->win != NULL );
529533 bool refresh_tabbar_for_non_current= !is_current;
530534
531535 // 第一步: 设定 win_tabpage
@@ -598,15 +602,18 @@ kill_tabpage (url win_u, url u) {
598602 }
599603
600604 // 关闭非当前标签页时,可能不会立即触发标签栏刷新。
601- // 对同一 tabpage 窗口中的当前编辑器执行 suspend/resume,
602- // 以强制触发一次 UI 更新。
605+ // 对该 tabpage 窗口中正在显示的编辑器执行 suspend/resume,
606+ // 以强制触发一次 UI 更新。这里取窗口实际显示的视图而非全局焦点视图:
607+ // AI 侧边栏打开时焦点在聊天输入框的嵌入视图(win_tabpage 为空),
608+ // 按焦点视图取会跳过刷新,tab 栏同样不更新。
603609 if (refresh_tabbar_for_non_current) {
604- tm_view current_vw= concrete_view (get_current_view_safe ());
605- if (current_vw != NULL && current_vw->win_tabpage == win_tabpage) {
606- editor current_ed= current_vw->ed ;
607- if (current_ed != NULL ) {
608- current_ed->suspend ();
609- current_ed->resume ();
610+ tm_view shown_vw=
611+ concrete_view (window_to_view (abstract_window (win_tabpage)));
612+ if (shown_vw != NULL ) {
613+ editor shown_ed= shown_vw->ed ;
614+ if (shown_ed != NULL ) {
615+ shown_ed->suspend ();
616+ shown_ed->resume ();
610617 }
611618 }
612619 }
0 commit comments