From 9ba99177b9d756e714237e3d8ddfe028b96e4e4b Mon Sep 17 00:00:00 2001 From: yiliang114 <1204183885@qq.com> Date: Thu, 20 Nov 2025 23:50:41 +0800 Subject: [PATCH] =?UTF-8?q?refactor(vscode-ide-companion):=20=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E4=B8=BB=E5=8A=A8=E5=AE=8C=E6=88=90=E5=92=8C=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除了 QwenAgentManager 中的冗余类型导出 - 优化了 App 组件中的会话管理和标题更新逻辑 - 改进了消息输入框的中文输入法支持 - 调整了活动文件指示器的样式 --- .../src/agents/qwenAgentManager.ts | 1 - .../vscode-ide-companion/src/webview/App.scss | 21 ++-------- .../vscode-ide-companion/src/webview/App.tsx | 39 ++++++++++--------- 3 files changed, 24 insertions(+), 37 deletions(-) diff --git a/packages/vscode-ide-companion/src/agents/qwenAgentManager.ts b/packages/vscode-ide-companion/src/agents/qwenAgentManager.ts index 8b767c8f..9c6b9cf1 100644 --- a/packages/vscode-ide-companion/src/agents/qwenAgentManager.ts +++ b/packages/vscode-ide-companion/src/agents/qwenAgentManager.ts @@ -23,7 +23,6 @@ import type { import { QwenConnectionHandler } from './qwenConnectionHandler.js'; import { QwenSessionUpdateHandler } from './qwenSessionUpdateHandler.js'; -// 重新导出类型以保持向后兼容 export type { ChatMessage, PlanEntry, ToolCallUpdateData }; /** diff --git a/packages/vscode-ide-companion/src/webview/App.scss b/packages/vscode-ide-companion/src/webview/App.scss index c40b2821..64abceed 100644 --- a/packages/vscode-ide-companion/src/webview/App.scss +++ b/packages/vscode-ide-companion/src/webview/App.scss @@ -787,30 +787,17 @@ button { min-width: 0; } -/* Active file indicator - shows current file selection (.vo in Claude Code) */ +/* Active file indicator - shows current file selection */ .active-file-indicator { - font-size: 0.85em; - font-family: inherit; - color: var(--app-primary-foreground); - opacity: 0.6; - background: none; - border: none; - padding: 2px 4px; - cursor: default; - text-align: right; - max-width: 50%; + // Inherits all styles from .action-button + // Only add specific overrides here if needed + max-width: 200px; overflow: hidden; text-overflow: ellipsis; - white-space: nowrap; - border-radius: 2px; flex-shrink: 1; min-width: 0; } -.active-file-indicator:hover { - opacity: 1; -} - /* Hide file indicator on very small screens */ @media screen and (max-width: 330px) { .active-file-indicator { diff --git a/packages/vscode-ide-companion/src/webview/App.tsx b/packages/vscode-ide-companion/src/webview/App.tsx index cb8b9a38..d102c665 100644 --- a/packages/vscode-ide-companion/src/webview/App.tsx +++ b/packages/vscode-ide-companion/src/webview/App.tsx @@ -220,6 +220,7 @@ export const App: React.FC = () => { const [editMode, setEditMode] = useState('ask'); const [thinkingEnabled, setThinkingEnabled] = useState(false); const [activeFileName, setActiveFileName] = useState(null); + const [isComposing, setIsComposing] = useState(false); const handlePermissionRequest = React.useCallback( (request: { @@ -401,20 +402,8 @@ export const App: React.FC = () => { case 'qwenSessionList': { const sessions = message.data.sessions || []; setQwenSessions(sessions); - // If no current session is selected and there are sessions, select the first one - if (!currentSessionId && sessions.length > 0) { - const firstSession = sessions[0]; - const firstSessionId = - (firstSession.id as string) || (firstSession.sessionId as string); - const firstSessionTitle = - (firstSession.title as string) || - (firstSession.name as string) || - 'Past Conversations'; - if (firstSessionId) { - setCurrentSessionId(firstSessionId); - setCurrentSessionTitle(firstSessionTitle); - } - } else if (currentSessionId && sessions.length > 0) { + // Only update title if we have a current session selected + if (currentSessionId && sessions.length > 0) { // Update title for the current session if it exists in the list const currentSession = sessions.find( (s: Record) => @@ -443,13 +432,15 @@ export const App: React.FC = () => { message.data.sessionId, ); } - // Update current session title - if (message.data.title || message.data.name) { + // Update current session title from session object + if (message.data.session) { + const session = message.data.session as Record; const title = - (message.data.title as string) || - (message.data.name as string) || + (session.title as string) || + (session.name as string) || 'Past Conversations'; setCurrentSessionTitle(title); + console.log('[App] Session title updated to:', title); } // Load messages from the session if (message.data.messages) { @@ -471,6 +462,9 @@ export const App: React.FC = () => { setMessages([]); setCurrentStreamContent(''); setToolCalls(new Map()); + // Reset session ID and title when conversation is cleared (new session created) + setCurrentSessionId(null); + setCurrentSessionTitle('Past Conversations'); break; case 'activeEditorChanged': { @@ -1028,8 +1022,15 @@ export const App: React.FC = () => { const target = e.target as HTMLDivElement; setInputText(target.textContent || ''); }} + onCompositionStart={() => { + setIsComposing(true); + }} + onCompositionEnd={() => { + setIsComposing(false); + }} onKeyDown={(e) => { - if (e.key === 'Enter' && !e.shiftKey) { + // 如果正在进行中文输入法输入(拼音输入),不处理回车键 + if (e.key === 'Enter' && !e.shiftKey && !isComposing) { e.preventDefault(); handleSubmit(e); }