Skip to content

Commit d38ba58

Browse files
committed
Optimize agent/editor UI updates and simplify runnable initialization
1 parent 5162334 commit d38ba58

6 files changed

Lines changed: 33 additions & 30 deletions

File tree

anycode-base/src/code.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ export class Code {
155155
let q = this.getQuery();
156156
if (q) this.query = lang.query(q);
157157
if (this.query) await this.initInjections();
158-
let tq = this.getRunnablesQuery();
159-
if (tq) this.runnablesQuery = lang.query(tq);
160-
if (this.runnablesQuery || this.isExecutable()) this.updateRunnables();
158+
// let tq = this.getRunnablesQuery();
159+
// if (tq) this.runnablesQuery = lang.query(tq);
160+
// if (this.runnablesQuery || this.isExecutable()) this.updateRunnables();
161161
}
162162
}
163163

anycode/App.tsx

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,23 @@ const App: React.FC = () => {
143143
search.startSearch(pattern);
144144
};
145145

146-
const resolveEditorPaneId = useCallback(() => {
146+
const resolveEditorPaneId = useEvent(() => {
147147
return layoutActionsRef.current?.ensureEditorPanel(editors.activeEditorPaneId);
148-
}, [editors]);
148+
});
149149

150-
const handleOpenFile = useCallback((
150+
const handleOpenFile = useEvent((
151151
path: string, line?: number, column?: number, mode?: DiffMode,
152152
) => {
153153
const paneId = resolveEditorPaneId();
154154
if (!paneId) return;
155155
editors.openFile(path, line, column, paneId, mode);
156-
}, [editors, resolveEditorPaneId]);
156+
});
157157

158-
const handleSelectFile = useCallback((fileId: string) => {
158+
const handleSelectFile = useEvent((fileId: string) => {
159159
const paneId = resolveEditorPaneId();
160160
if (!paneId) return;
161161
editors.setActiveFileId(fileId, paneId);
162-
}, [editors, resolveEditorPaneId]);
162+
});
163163

164164
const handleSearchResultClick = (filePath: string, match: SearchMatch) => {
165165
handleOpenFile(filePath, match.line, match.column);
@@ -186,7 +186,10 @@ const App: React.FC = () => {
186186
}, [editors]);
187187

188188
const handleCycleEditorDiffMode = useCallback((panelKey: string) => {
189-
editors.cycleEditorDiffMode(panelKey);
189+
const changed = editors.cycleEditorDiffMode(panelKey);
190+
if (changed) {
191+
editors.focusEditorInPane(panelKey);
192+
}
190193
}, [editors]);
191194

192195
const sessionsArray = useMemo(() => Array.from(agents.acpSessions.values()), [agents.acpSessions]);
@@ -415,7 +418,7 @@ const App: React.FC = () => {
415418
}
416419
};
417420

418-
const handlePanelAdded = useCallback((panelId: PanelId, panelKey: string) => {
421+
const handlePanelAdded = useEvent((panelId: PanelId, panelKey: string) => {
419422
layout.handlePanelAdded(panelId, panelKey);
420423

421424
if (panelId === 'changes') {
@@ -435,9 +438,9 @@ const App: React.FC = () => {
435438
if (panelId === 'terminal') {
436439
terminalPanes.registerPane(panelKey);
437440
}
438-
}, [agentPanes, editors, git.fetchGitStatus, git.fetchBranches, layout, terminalPanes]);
441+
});
439442

440-
const handlePanelRemoved = useCallback((panelId: PanelId, panelKey: string) => {
443+
const handlePanelRemoved = useEvent((panelId: PanelId, panelKey: string) => {
441444
layout.handlePanelRemoved(panelId, panelKey);
442445

443446
if (panelId === 'editor') {
@@ -451,9 +454,9 @@ const App: React.FC = () => {
451454
if (panelId === 'terminal') {
452455
terminalPanes.unregisterPane(panelKey);
453456
}
454-
}, [agentPanes, editors, layout, terminalPanes]);
457+
});
455458

456-
const handlePanelActivated = useCallback((panelId: PanelId, panelKey: string) => {
459+
const handlePanelActivated = useEvent((panelId: PanelId, panelKey: string) => {
457460
layout.handlePanelActivated(panelId, panelKey);
458461

459462
if (panelId === 'editor') {
@@ -478,7 +481,7 @@ const App: React.FC = () => {
478481
if (panelId === 'terminal') {
479482
terminalPanes.setActivePaneId(panelKey);
480483
}
481-
}, [agentPanes, editors, layout, terminalPanes]);
484+
});
482485

483486
return (
484487
<div className="app-container toolbar-header-compact">

anycode/components/agent/AcpMessage.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ const PermissionRequestMessage: React.FC<{
10771077
);
10781078
};
10791079

1080-
export const AcpMessage: React.FC<AcpMessageProps> = ({
1080+
const AcpMessageComponent: React.FC<AcpMessageProps> = ({
10811081
message,
10821082
toolResult,
10831083
toolUpdates,
@@ -1165,3 +1165,5 @@ export const AcpMessage: React.FC<AcpMessageProps> = ({
11651165
return null;
11661166
}
11671167
};
1168+
1169+
export const AcpMessage = React.memo(AcpMessageComponent);

anycode/components/agent/AcpSession.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { AcpIcons } from './AcpIcons';
1313
import { loadItem, saveItem } from '../../storage';
1414

1515
const ACP_INPUT_DRAFTS_STORAGE_KEY = 'acpInputDrafts';
16+
const EMPTY_ARRAY: any[] = [];
1617

1718
const useAutoScroll = (messages: AcpMessage[], isProcessing: boolean) => {
1819
const contentRef = useRef<HTMLDivElement>(null);
@@ -201,7 +202,7 @@ interface AcpSessionProps {
201202
onOpenFileDiff?: (path: string, line?: number, column?: number) => void;
202203
}
203204

204-
export const AcpSession: React.FC<AcpSessionProps> = ({
205+
const AcpSessionComponent: React.FC<AcpSessionProps> = ({
205206
agentId,
206207
title,
207208
isConnected,
@@ -298,7 +299,7 @@ export const AcpSession: React.FC<AcpSessionProps> = ({
298299
<div className="acp-messages-inner" ref={innerRef}>
299300
<AcpMessages
300301
messages={messages}
301-
toolCalls={[]}
302+
toolCalls={EMPTY_ARRAY}
302303
expandedToolCalls={expandedToolCalls}
303304
expandedToolResults={expandedToolResults}
304305
expandedThoughts={expandedThoughts}
@@ -344,3 +345,5 @@ export const AcpSession: React.FC<AcpSessionProps> = ({
344345
</div>
345346
);
346347
};
348+
349+
export const AcpSession = React.memo(AcpSessionComponent);

anycode/features/agents/AgentPanel.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useEffect, useRef } from 'react';
1+
import React, { useEffect, useRef } from 'react';
22
import { AcpSettings } from '../../components/agent/AcpSettings';
33
import { AcpSession } from '../../components/agent/AcpSession';
44
import { AcpEmptyPane } from '../../components/agent/AcpEmptyPane';
@@ -42,7 +42,7 @@ type AgentPanelProps = {
4242
onOpenFileDiff: (path: string, line?: number, column?: number) => void;
4343
};
4444

45-
export const AgentPanel = ({
45+
const AgentPanelComponent = ({
4646
panelKey,
4747
focusRequestToken,
4848
isConnected,
@@ -145,3 +145,5 @@ export const AgentPanel = ({
145145
</div>
146146
);
147147
};
148+
149+
export const AgentPanel = React.memo(AgentPanelComponent);

anycode/hooks/useEditors.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -417,17 +417,10 @@ export const useEditors = ({ wsRef, isConnected, onFileClosed }: UseEditorsParam
417417

418418
const focusEditorInPane = useCallback((paneId: string) => {
419419
setActiveEditorPaneId(paneId);
420-
421420
const fileId = getActiveFileIdForPane(paneId);
422-
if (!fileId) {
423-
return;
424-
}
425-
421+
if (!fileId) return;
426422
const editor = editorRefs.current.get(fileId);
427-
if (!editor) {
428-
return;
429-
}
430-
423+
if (!editor) return;
431424
const cursor = editor.getCursor();
432425
editor.requestFocus(cursor.line, cursor.column);
433426
}, [getActiveFileIdForPane]);

0 commit comments

Comments
 (0)