feat(ui): 添加编辑器与对话框联动功能
- 新增 ActiveFileInfo 类型定义 - IDE 组件支持 onActiveFileChange 回调通知活动文件变化 - ChatInput 显示当前活动文件并支持自动附加到消息 - 用户可切换自动附加开关,设置持久化到 localStorage - 排除 / 和 : 命令避免与斜杠命令和系统命令冲突
This commit is contained in:
@@ -23,6 +23,7 @@ import {
|
||||
listSessions,
|
||||
createSession,
|
||||
type Session,
|
||||
type ActiveFileInfo,
|
||||
} from '@ai-assistant/ui';
|
||||
import { ChatPage } from './pages/Chat';
|
||||
|
||||
@@ -45,6 +46,18 @@ export function App() {
|
||||
return saved ? parseFloat(saved) : 70;
|
||||
});
|
||||
|
||||
// 编辑器联动状态
|
||||
const [activeFile, setActiveFile] = useState<ActiveFileInfo | null>(null);
|
||||
const [autoAttachActiveFile, setAutoAttachActiveFile] = useState(() => {
|
||||
const saved = localStorage.getItem('ai-assistant-auto-attach-file');
|
||||
return saved !== 'false'; // 默认开启
|
||||
});
|
||||
|
||||
// 持久化自动附加开关状态
|
||||
useEffect(() => {
|
||||
localStorage.setItem('ai-assistant-auto-attach-file', String(autoAttachActiveFile));
|
||||
}, [autoAttachActiveFile]);
|
||||
|
||||
// 初始化:加载会话
|
||||
useEffect(() => {
|
||||
const HAS_SESSIONS_KEY = 'ai-assistant-has-sessions';
|
||||
@@ -146,7 +159,7 @@ export function App() {
|
||||
className="hidden md:flex flex-col"
|
||||
style={{ width: `${idePanelWidth}%` }}
|
||||
>
|
||||
<IDE />
|
||||
<IDE onActiveFileChange={setActiveFile} />
|
||||
</div>
|
||||
|
||||
{/* 可拖拽分割线 */}
|
||||
@@ -175,6 +188,9 @@ export function App() {
|
||||
onOpenLSP={() => setShowLSP(true)}
|
||||
onOpenDiagnostics={() => setShowDiagnostics(true)}
|
||||
onOpenSessions={() => setShowSessions(true)}
|
||||
activeFile={activeFile}
|
||||
autoAttachActiveFile={autoAttachActiveFile}
|
||||
onAutoAttachActiveFileToggle={setAutoAttachActiveFile}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex-1 flex items-center justify-center h-full">
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
SubagentProgress,
|
||||
DiagnosticsIndicator,
|
||||
ToolbarOverflowMenu,
|
||||
type ActiveFileInfo,
|
||||
} from '@ai-assistant/ui';
|
||||
|
||||
interface ChatPageProps {
|
||||
@@ -35,6 +36,13 @@ interface ChatPageProps {
|
||||
onOpenLSP?: () => void;
|
||||
onOpenDiagnostics?: () => void;
|
||||
onOpenSessions?: () => void;
|
||||
// 编辑器联动
|
||||
/** 当前编辑器活动文件 */
|
||||
activeFile?: ActiveFileInfo | null;
|
||||
/** 是否自动附加当前编辑器文件 */
|
||||
autoAttachActiveFile?: boolean;
|
||||
/** 自动附加开关变更回调 */
|
||||
onAutoAttachActiveFileToggle?: (enabled: boolean) => void;
|
||||
}
|
||||
|
||||
export function ChatPage({
|
||||
@@ -52,6 +60,9 @@ export function ChatPage({
|
||||
onOpenLSP,
|
||||
onOpenDiagnostics,
|
||||
onOpenSessions,
|
||||
activeFile,
|
||||
autoAttachActiveFile,
|
||||
onAutoAttachActiveFileToggle,
|
||||
}: ChatPageProps) {
|
||||
const {
|
||||
messages,
|
||||
@@ -228,6 +239,9 @@ export function ChatPage({
|
||||
onAgentModeChange={setAgentMode}
|
||||
autoApprove={autoApprove}
|
||||
onAutoApproveChange={setAutoApprove}
|
||||
activeFile={activeFile}
|
||||
autoAttachActiveFile={autoAttachActiveFile}
|
||||
onAutoAttachActiveFileToggle={onAutoAttachActiveFileToggle}
|
||||
/>
|
||||
|
||||
{/* Permission Dialog */}
|
||||
|
||||
Reference in New Issue
Block a user