Skip to content

WorkBuddy、CodeBuddy 桌面端增强助手:签到猫猫旅行成长计划查询、多账号独立备份、点切即用;免打扰模式让 AI 无人值守跑长任务;跨账号会话迁移、异常中断自动续接;暂存/快捷提示词;毛玻璃主题与更多实用功能。

fix: preserve official navigation during task switches

[email protected]f02679b2046f
diff --git a/scripts/inject.js b/scripts/inject.js
index c029c49..f9ecf59 100644
--- a/scripts/inject.js
+++ b/scripts/inject.js
@@ -1164,6 +1164,7 @@ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
for (var ni = 0; ni < nav.length; ni++) nav[ni].remove();
var ss = document.querySelectorAll('#wbs-style');
for (var j = 0; j < ss.length; j++) ss[j].remove();
+ if (document.documentElement) document.documentElement.removeAttribute('data-wbs-message-nav');
var dbg = document.querySelectorAll('#wbs-diag-badge, #wbs-debug-panel');
for (var k = 0; k < dbg.length; k++) dbg[k].remove();
// [CodeBuddy IDE 状态栏] 清理 IDE 模式注入的浮层 root 与原生菜单去重样式,确保 reinjection 幂等
@@ -4548,19 +4549,13 @@ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
} catch (e) {}
}
- // WorkBuddy 自带的会话历史索引使用稳定的 aside class,但父级 teams 布局会变化。
- // 开启 WorkDaddy 消息索引时移除官方导航,避免两套索引重叠;body observer 会在官方重建后再次清理。
- function removeOfficialConversationHistoryNavigation(enabled) {
- if (!enabled || typeof document === 'undefined' || typeof document.querySelectorAll !== 'function') return 0;
- var removed = 0;
- var nodes;
- try { nodes = document.querySelectorAll('aside.conversation-history-navigation'); } catch (_) { return 0; }
- for (var i = 0; i < nodes.length; i++) {
- try {
- if (nodes[i] && typeof nodes[i].remove === 'function') { nodes[i].remove(); removed++; }
- } catch (_) {}
- }
- return removed;
+ // 官方导航由 React 管理,直接删除会让切会话时的卸载抛出 removeChild NotFoundError。
+ // 只通过 CSS 隐藏,保留父子关系;新建的导航自动匹配,关闭开关或销毁注入时恢复。
+ function setOfficialConversationHistoryNavigationHidden(hidden) {
+ var html = document.documentElement;
+ if (!html) return;
+ if (hidden) html.setAttribute('data-wbs-message-nav', '');
+ else html.removeAttribute('data-wbs-message-nav');
}
// 会话消息导航:完整索引来自 controller.messageStore,DOM 仅用于判断当前可见位置。
@@ -5010,8 +5005,8 @@ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
}
function setEnabled(enabled) {
+ setOfficialConversationHistoryNavigationHidden(enabled);
if (enabled) {
- removeOfficialConversationHistoryNavigation(true);
sync();
return;
}
@@ -5166,9 +5161,10 @@ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
listen(window, 'resize', onWindowChange);
listen(window, 'scroll', onWindowChange, true);
- removeOfficialConversationHistoryNavigation(sessState.messageNav);
+ setOfficialConversationHistoryNavigationHidden(sessState.messageNav);
sync();
registerDisposer(function () {
+ setOfficialConversationHistoryNavigationHidden(false);
disposed = true;
if (syncTimer) clearTimeout(syncTimer);
if (tooltipTimer) clearTimeout(tooltipTimer);
@@ -5316,7 +5312,6 @@ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
function onDomChange() {
if (!alive) return;
guardSessionChange();
- removeOfficialConversationHistoryNavigation(sessState.messageNav);
if (messageNavigation) messageNavigation.sync();
scheduleForkButtons();
scheduleFabPos();
@@ -17763,6 +17758,7 @@ if (typeof window !== 'undefined' && typeof document !== 'undefined') {
'html.cb-dark .wbs-fork-button,html[data-theme="dark"] .wbs-fork-button,body[data-vscode-theme-name*="dark" i] .wbs-fork-button{color:var(--wb-icon-secondary,rgba(255,255,255,.7))}',
'html.cb-dark .wbs-fork-button:hover,html[data-theme="dark"] .wbs-fork-button:hover,body[data-vscode-theme-name*="dark" i] .wbs-fork-button:hover{color:var(--wb-color-text-primary,#f2f3f5);background:var(--wb-bg-hover,rgba(255,255,255,.1))}',
/* 会话消息索引:跟随官方消息视口定位,tooltip 使用主题感知的毛玻璃表面 */
+ 'html[data-wbs-message-nav] aside.conversation-history-navigation{display:none!important}',
'.wbs-message-nav-root{position:fixed;width:24px;z-index:1000;pointer-events:none;user-select:none;-webkit-user-select:none;font-family:-apple-system,BlinkMacSystemFont,"PingFang SC","Microsoft YaHei",sans-serif;color:var(--wb-color-text-primary,#1f1f1f)}',
'.wbs-message-nav-rail{display:flex;width:24px;height:100%;box-sizing:border-box;flex-direction:column;align-items:center;justify-content:flex-start;gap:0;overflow:hidden;padding:6px 0;border:1px solid transparent;border-radius:8px;background:color-mix(in srgb,var(--wb-bg-popover,#fff) 16%,transparent);box-shadow:none;backdrop-filter:none;-webkit-backdrop-filter:none;pointer-events:auto;touch-action:none;cursor:pointer;scrollbar-width:none;transition:background-color .18s ease,border-color .18s ease,box-shadow .18s ease,backdrop-filter .18s ease}',
'.wbs-message-nav-rail:hover,.wbs-message-nav-rail:focus-within{border-color:color-mix(in srgb,var(--wb-border-subtle,#d9dadd) 72%,transparent);background:color-mix(in srgb,var(--wb-bg-popover,#fff) 48%,transparent);box-shadow:0 5px 18px rgba(24,28,36,.10);backdrop-filter:blur(14px) saturate(1.12);-webkit-backdrop-filter:blur(14px) saturate(1.12)}',
diff --git a/test/message-navigation-removal.test.js b/test/message-navigation-removal.test.js
index 90fbf6d..549d95a 100644
--- a/test/message-navigation-removal.test.js
+++ b/test/message-navigation-removal.test.js
@@ -7,32 +7,82 @@ const vm = require('node:vm');
const source = fs.readFileSync(path.join(__dirname, '../scripts/inject.js'), 'utf8');
-function harness(nodes) {
+function harness() {
+ const attributes = new Map();
+ const documentElement = {
+ setAttribute(name, value) { attributes.set(name, value); },
+ removeAttribute(name) { attributes.delete(name); },
+ hasAttribute(name) { return attributes.has(name); },
+ };
+ const parents = [];
+ function mountNavigation() {
+ const parent = {
+ children: [],
+ removeChild(node) {
+ const index = this.children.indexOf(node);
+ if (index < 0) throw new DOMException('The node to be removed is not a child of this node.', 'NotFoundError');
+ this.children.splice(index, 1);
+ node.parentNode = null;
+ },
+ };
+ const aside = {
+ parentNode: parent,
+ remove() { if (this.parentNode) this.parentNode.removeChild(this); },
+ };
+ parent.children.push(aside);
+ parents.push(parent);
+ return { parent, aside };
+ }
const document = {
+ documentElement,
querySelectorAll(selector) {
assert.equal(selector, 'aside.conversation-history-navigation');
- return nodes;
+ return parents.flatMap(parent => parent.children);
},
};
- const start = source.indexOf('function removeOfficialConversationHistoryNavigation(');
+ const name = 'setOfficialConversationHistoryNavigationHidden';
+ const start = source.indexOf('function ' + name + '(');
const end = source.indexOf('\n // 会话消息导航:', start);
- assert.ok(start >= 0 && end > start, 'official navigation cleanup helper missing');
+ assert.ok(start >= 0 && end > start, 'official navigation visibility helper missing');
const context = { document };
vm.runInNewContext(source.slice(start, end), context);
- return context.removeOfficialConversationHistoryNavigation;
+ return { setHidden: context[name], mountNavigation, documentElement };
}
-test('message index cleanup removes every official history navigation regardless of parent path', () => {
- const removed = [];
- const nodes = [{ remove: () => removed.push(1) }, { remove: () => removed.push(1) }];
- const clean = harness(nodes);
- assert.equal(clean(false), 0);
- assert.equal(removed.length, 0);
- assert.equal(clean(true), 2);
- assert.equal(removed.length, 2);
+test('switching between two tasks leaves official navigation nodes available for React to unmount', () => {
+ const { setHidden, mountNavigation } = harness();
+ let tasks = [mountNavigation(), mountNavigation()];
+ for (let i = 0; i < 100; i++) {
+ setHidden(true);
+ const index = i % tasks.length;
+ const { parent, aside } = tasks[index];
+ assert.doesNotThrow(() => parent.removeChild(aside), 'official unmount must not throw NotFoundError');
+ assert.equal(parent.children.length, 0);
+ tasks[index] = mountNavigation();
+ }
+});
+
+test('message index visibility is reversible and also covers navigation mounted after enabling', () => {
+ const { setHidden, mountNavigation, documentElement } = harness();
+ const first = mountNavigation();
+ setHidden(true);
+ const second = mountNavigation();
+ assert.equal(first.aside.parentNode, first.parent);
+ assert.equal(second.aside.parentNode, second.parent);
+ assert.equal(documentElement.hasAttribute('data-wbs-message-nav'), true);
+ setHidden(false);
+ assert.equal(documentElement.hasAttribute('data-wbs-message-nav'), false);
+ assert.deepEqual(first.parent.children, [first.aside]);
+ assert.deepEqual(second.parent.children, [second.aside]);
});
-test('message index cleanup is wired to enable and DOM rescan paths', () => {
- assert.match(source, /function setEnabled\(enabled\)[\s\S]*?removeOfficialConversationHistoryNavigation\(true\)/);
- assert.match(source, /function onDomChange\(\)[\s\S]*?removeOfficialConversationHistoryNavigation\(sessState\.messageNav\)/);
+test('official navigation uses theme-independent CSS hiding and restores on disable or disposal', () => {
+ assert.match(source, /html\[data-wbs-message-nav\] aside\.conversation-history-navigation\{display:none!important\}/);
+ const start = source.indexOf(' function createMessageNavigation(');
+ const end = source.indexOf(' var messageNavigation = createMessageNavigation();', start);
+ const navigation = source.slice(start, end);
+ assert.match(navigation, /function setEnabled\(enabled\)\s*\{\s*setOfficialConversationHistoryNavigationHidden\(enabled\)/);
+ assert.match(navigation, /setOfficialConversationHistoryNavigationHidden\(sessState\.messageNav\)/);
+ assert.match(navigation, /registerDisposer\(function \(\)\s*\{\s*setOfficialConversationHistoryNavigationHidden\(false\)/);
+ assert.doesNotMatch(source, /removeOfficialConversationHistoryNavigation/);
});