fix(vscode-ide-companion): 修复新建会话按钮,在同一 view column 创建新 tab

问题:
- 之前的实现会复用现有 panel 并清空当前会话
- 期望行为是在同一 view column(不创建分屏)中创建新的 VS Code tab

解决方案:
1. 修改 qwenCode.openNewChatTab 命令
   - 总是创建新的 WebviewProvider 和 WebviewPanel
   - PanelManager 的 findExistingQwenCodeViewColumn() 确保在同一 column 打开
2. 修改 MessageHandler 中的 openNewChatTab 处理
   - 调用 VS Code 命令创建新 panel/tab
3. 移除不再需要的 createNewSession 方法

效果:
- 点击新建会话按钮会在同一 view column 中创建新的 VS Code tab
- 类似 Claude Code 的交互方式
- 不会创建新的分屏

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
yiliang114
2025-11-20 23:14:40 +08:00
parent 95b67bbebd
commit 5a9f5e3432
9 changed files with 73 additions and 47 deletions

View File

@@ -42,12 +42,19 @@ export class PanelManager {
return false; // Panel already exists
}
// Find if there's already a Qwen Code webview tab open and get its view column
const existingQwenViewColumn = this.findExistingQwenCodeViewColumn();
// If we found an existing Qwen Code tab, open in the same view column
// Otherwise, open beside the active editor
const targetViewColumn = existingQwenViewColumn ?? vscode.ViewColumn.Beside;
this.panel = vscode.window.createWebviewPanel(
'qwenCode.chat',
'Qwen Code Chat',
'Qwen Code',
{
viewColumn: vscode.ViewColumn.Beside, // Open on right side of active editor
preserveFocus: true, // Don't steal focus from editor
viewColumn: targetViewColumn,
preserveFocus: false, // Focus the new tab
},
{
enableScripts: true,
@@ -69,6 +76,30 @@ export class PanelManager {
return true; // New panel created
}
/**
* 查找已存在的 Qwen Code webview 所在的 view column
* @returns 找到的 view column如果没有则返回 undefined
*/
private findExistingQwenCodeViewColumn(): vscode.ViewColumn | undefined {
const allTabs = vscode.window.tabGroups.all.flatMap((g) => g.tabs);
for (const tab of allTabs) {
const input: unknown = (tab as { input?: unknown }).input;
const isWebviewInput = (inp: unknown): inp is { viewType: string } =>
!!inp && typeof inp === 'object' && 'viewType' in inp;
if (isWebviewInput(input) && input.viewType === 'qwenCode.chat') {
// Found an existing Qwen Code tab, get its view column
const tabGroup = vscode.window.tabGroups.all.find((g) =>
g.tabs.includes(tab),
);
return tabGroup?.viewColumn;
}
}
return undefined;
}
/**
* 自动锁定编辑器组(仅在新创建 Panel 时调用)
*/