MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / onFileClick

Function onFileClick

website/src/components/CodeGraphViewer.tsx:1170–1216  ·  view source on GitHub ↗
(path: string | null, targetLine?: number)

Source from the content-addressed store, hash-verified

1168 }, [fileContents]);
1169
1170 const onFileClick = (path: string | null, targetLine?: number) => {
1171 if (!path) {
1172 setSelectedFile(null);
1173 setFocusSet(null);
1174 setCodeContent(null);
1175 setCodeError(null);
1176 setHighlightLine(null);
1177 return;
1178 }
1179
1180 setHighlightLine(targetLine || null);
1181
1182 if (path !== selectedFile) {
1183 setSelectedFile(path);
1184 loadFileCode(path);
1185 } else if (targetLine) {
1186 setCodePanelTab('code');
1187 setTimeout(() => {
1188 const el = codeBodyRef.current?.querySelector(`[data-line="${targetLine}"]`);
1189 el?.scrollIntoView({ behavior: 'smooth', block: 'center' });
1190 }, 100);
1191 }
1192
1193 const fileNode = data.nodes.find((n: any) => n.file === path && n.type === 'File');
1194 if (fileNode) {
1195 if (fgRef.current) {
1196 fgRef.current.centerAt(fileNode.x, fileNode.y, 800);
1197 fgRef.current.zoom(2.5, 800);
1198 }
1199
1200 const nodesInFocus = new Set<number>();
1201 const linksInFocus = new Set<any>();
1202 nodesInFocus.add(fileNode.id);
1203
1204 data.links.forEach((l: any) => {
1205 const sId = typeof l.source === 'object' ? l.source.id : l.source;
1206 const tId = typeof l.target === 'object' ? l.target.id : l.target;
1207 if (sId === fileNode.id || tId === fileNode.id) {
1208 nodesInFocus.add(sId);
1209 nodesInFocus.add(tId);
1210 linksInFocus.add(l);
1211 }
1212 });
1213
1214 setFocusSet({ nodes: nodesInFocus, links: linksInFocus });
1215 }
1216 };
1217
1218 const onGraphNodeClick = (node: any) => {
1219 if (isPathMode) {

Callers 3

TreeItemFunction · 0.70
onGraphNodeClickFunction · 0.70
CodeGraphViewerFunction · 0.70

Calls 1

addMethod · 0.45

Tested by

no test coverage detected