refactor(vscode-ide-companion): 重构主动完成和会话管理

- 移除了 QwenAgentManager 中的冗余类型导出
- 优化了 App 组件中的会话管理和标题更新逻辑
- 改进了消息输入框的中文输入法支持
- 调整了活动文件指示器的样式
This commit is contained in:
yiliang114
2025-11-20 23:50:41 +08:00
parent 7d2411e72f
commit 9ba99177b9
3 changed files with 24 additions and 37 deletions

View File

@@ -23,7 +23,6 @@ import type {
import { QwenConnectionHandler } from './qwenConnectionHandler.js'; import { QwenConnectionHandler } from './qwenConnectionHandler.js';
import { QwenSessionUpdateHandler } from './qwenSessionUpdateHandler.js'; import { QwenSessionUpdateHandler } from './qwenSessionUpdateHandler.js';
// 重新导出类型以保持向后兼容
export type { ChatMessage, PlanEntry, ToolCallUpdateData }; export type { ChatMessage, PlanEntry, ToolCallUpdateData };
/** /**

View File

@@ -787,30 +787,17 @@ button {
min-width: 0; min-width: 0;
} }
/* Active file indicator - shows current file selection (.vo in Claude Code) */ /* Active file indicator - shows current file selection */
.active-file-indicator { .active-file-indicator {
font-size: 0.85em; // Inherits all styles from .action-button
font-family: inherit; // Only add specific overrides here if needed
color: var(--app-primary-foreground); max-width: 200px;
opacity: 0.6;
background: none;
border: none;
padding: 2px 4px;
cursor: default;
text-align: right;
max-width: 50%;
overflow: hidden; overflow: hidden;
text-overflow: ellipsis; text-overflow: ellipsis;
white-space: nowrap;
border-radius: 2px;
flex-shrink: 1; flex-shrink: 1;
min-width: 0; min-width: 0;
} }
.active-file-indicator:hover {
opacity: 1;
}
/* Hide file indicator on very small screens */ /* Hide file indicator on very small screens */
@media screen and (max-width: 330px) { @media screen and (max-width: 330px) {
.active-file-indicator { .active-file-indicator {

View File

@@ -220,6 +220,7 @@ export const App: React.FC = () => {
const [editMode, setEditMode] = useState<EditMode>('ask'); const [editMode, setEditMode] = useState<EditMode>('ask');
const [thinkingEnabled, setThinkingEnabled] = useState(false); const [thinkingEnabled, setThinkingEnabled] = useState(false);
const [activeFileName, setActiveFileName] = useState<string | null>(null); const [activeFileName, setActiveFileName] = useState<string | null>(null);
const [isComposing, setIsComposing] = useState(false);
const handlePermissionRequest = React.useCallback( const handlePermissionRequest = React.useCallback(
(request: { (request: {
@@ -401,20 +402,8 @@ export const App: React.FC = () => {
case 'qwenSessionList': { case 'qwenSessionList': {
const sessions = message.data.sessions || []; const sessions = message.data.sessions || [];
setQwenSessions(sessions); setQwenSessions(sessions);
// If no current session is selected and there are sessions, select the first one // Only update title if we have a current session selected
if (!currentSessionId && sessions.length > 0) { 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) {
// Update title for the current session if it exists in the list // Update title for the current session if it exists in the list
const currentSession = sessions.find( const currentSession = sessions.find(
(s: Record<string, unknown>) => (s: Record<string, unknown>) =>
@@ -443,13 +432,15 @@ export const App: React.FC = () => {
message.data.sessionId, message.data.sessionId,
); );
} }
// Update current session title // Update current session title from session object
if (message.data.title || message.data.name) { if (message.data.session) {
const session = message.data.session as Record<string, unknown>;
const title = const title =
(message.data.title as string) || (session.title as string) ||
(message.data.name as string) || (session.name as string) ||
'Past Conversations'; 'Past Conversations';
setCurrentSessionTitle(title); setCurrentSessionTitle(title);
console.log('[App] Session title updated to:', title);
} }
// Load messages from the session // Load messages from the session
if (message.data.messages) { if (message.data.messages) {
@@ -471,6 +462,9 @@ export const App: React.FC = () => {
setMessages([]); setMessages([]);
setCurrentStreamContent(''); setCurrentStreamContent('');
setToolCalls(new Map()); setToolCalls(new Map());
// Reset session ID and title when conversation is cleared (new session created)
setCurrentSessionId(null);
setCurrentSessionTitle('Past Conversations');
break; break;
case 'activeEditorChanged': { case 'activeEditorChanged': {
@@ -1028,8 +1022,15 @@ export const App: React.FC = () => {
const target = e.target as HTMLDivElement; const target = e.target as HTMLDivElement;
setInputText(target.textContent || ''); setInputText(target.textContent || '');
}} }}
onCompositionStart={() => {
setIsComposing(true);
}}
onCompositionEnd={() => {
setIsComposing(false);
}}
onKeyDown={(e) => { onKeyDown={(e) => {
if (e.key === 'Enter' && !e.shiftKey) { // 如果正在进行中文输入法输入(拼音输入),不处理回车键
if (e.key === 'Enter' && !e.shiftKey && !isComposing) {
e.preventDefault(); e.preventDefault();
handleSubmit(e); handleSubmit(e);
} }