Skip to content

Commit fe76a02

Browse files
committed
fix(git): update editor original content on git status update to clear diff markers
1 parent e3436fd commit fe76a02

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

anycode/App.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const App: React.FC = () => {
6363
['watcher:create', fileTree.handleWatcherCreate],
6464
['watcher:remove', fileTree.handleWatcherRemove],
6565
['git:update', git.handleGitStatusUpdate],
66+
['git:update', editors.handleGitUpdate],
6667
['acp:message', agents.handleAcpMessage],
6768
['acp:history', agents.handleAcpHistory],
6869
['search:result', search.handleSearchResult],
@@ -78,6 +79,7 @@ const App: React.FC = () => {
7879
isConnected,
7980
editors.handleDiagnostics,
8081
editors.handleWatcherEdits,
82+
editors.handleGitUpdate,
8183
fileTree.handleWatcherCreate,
8284
fileTree.handleWatcherRemove,
8385
git.handleGitStatusUpdate,

anycode/hooks/useEditors.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,27 @@ export const useEditors = ({ wsRef, isConnected, onFileClosed }: UseEditorsParam
11301130
}
11311131
}, []);
11321132

1133+
const handleGitUpdate = useCallback(() => {
1134+
if (!wsRef.current || !isConnected) return;
1135+
1136+
filesRef.current.forEach((file) => {
1137+
const path = file.id;
1138+
const editor = editorRefs.current.get(path);
1139+
if (!editor) return;
1140+
1141+
wsRef.current?.emit('git:file-original', { path }, (response: any) => {
1142+
if (response && response.success && response.content !== undefined) {
1143+
editor.setOriginalCode(response.content);
1144+
1145+
const request = editorOpenRequestsRef.current.get(path);
1146+
if (request) {
1147+
request.originalContent = response.content;
1148+
}
1149+
}
1150+
});
1151+
});
1152+
}, [wsRef, isConnected]);
1153+
11331154
const undoCursor = useCallback(() => {
11341155
if (cursorHistory.current.undoStack.length === 0) return;
11351156

@@ -1206,6 +1227,7 @@ export const useEditors = ({ wsRef, isConnected, onFileClosed }: UseEditorsParam
12061227
handleReferencesPeekKeyDown,
12071228
handleDiagnostics,
12081229
handleWatcherEdits,
1230+
handleGitUpdate,
12091231
undoCursor,
12101232
redoCursor,
12111233
flushAllPendingChanges,

0 commit comments

Comments
 (0)