@@ -107,7 +107,7 @@ function showFlowDiagram(data: {nodes: any[], edges: any[]}, context: vscode.Ext
107107 console . log ( 'Creating new panel' ) ;
108108 panel = vscode . window . createWebviewPanel (
109109 'codeFlow' ,
110- ' CodeFlow Diagram',
110+ ` CodeFlow: ${ data . nodes [ 0 ] ?. label || 'Function Diagram'} ` ,
111111 vscode . ViewColumn . Beside ,
112112 {
113113 enableScripts : true
@@ -343,9 +343,41 @@ function getWebviewContent(data: {nodes: any[], edges: any[]}) {
343343 background-color: var(--vscode-menu-selectionBackground);
344344 color: var(--vscode-menu-selectionForeground);
345345 }
346+ .search-container {
347+ position: absolute;
348+ top: 5px;
349+ right: 25px;
350+ z-index: 1000;
351+ display: flex;
352+ gap: 5px;
353+ }
354+
355+ .search-input {
356+ padding: 5px 10px;
357+ border: 1px solid var(--vscode-input-border);
358+ background-color: var(--vscode-input-background);
359+ color: var(--vscode-input-foreground);
360+ border-radius: 3px;
361+ width: 200px;
362+ }
363+
364+ .search-message {
365+ position: absolute;
366+ top: 40px;
367+ right: 10px;
368+ background-color: var(--vscode-notifications-background);
369+ color: var(--vscode-notifications-foreground);
370+ padding: 5px 10px;
371+ border-radius: 3px;
372+ display: none;
373+ }
346374 </style>
347375 </head>
348376 <body>
377+ <div class="search-container">
378+ <input type="text" id="searchInput" class="search-input" placeholder="Search function...">
379+ </div>
380+ <div id="search-message" class="search-message"></div>
349381 <div id="mynetwork"></div>
350382 <div id="context-menu">
351383 <button id="visualize">Visualize</button>
@@ -558,6 +590,69 @@ function getWebviewContent(data: {nodes: any[], edges: any[]}) {
558590 }
559591 }
560592
593+ // Add this after network initialization
594+ const searchInput = document.getElementById('searchInput');
595+ const searchMessage = document.getElementById('search-message');
596+
597+ searchInput.addEventListener('input', function(e) {
598+ const searchTerm = e.target.value.toLowerCase();
599+ if (!searchTerm) {
600+ searchMessage.style.display = 'none';
601+ network.unselectAll();
602+ return;
603+ }
604+
605+ const matchingNodes = nodes.get().filter(node =>
606+ node.label.toLowerCase().includes(searchTerm)
607+ );
608+
609+ if (matchingNodes.length > 0) {
610+ const firstMatch = matchingNodes[0];
611+ network.selectNodes([firstMatch.id]);
612+ network.focus(firstMatch.id, {
613+ scale: 1,
614+ animation: true
615+ });
616+ searchMessage.textContent = \`Found \${matchingNodes.length} match\${matchingNodes.length > 1 ? 'es' : ''}\`;
617+ searchMessage.style.display = 'block';
618+ } else {
619+ network.unselectAll();
620+ searchMessage.textContent = 'No matches found';
621+ searchMessage.style.display = 'block';
622+ }
623+ });
624+
625+ // Add keyboard navigation for search results
626+ let currentMatchIndex = 0;
627+ document.addEventListener('keydown', function(e) {
628+ if (!searchInput.value) return;
629+
630+ const matchingNodes = nodes.get().filter(node =>
631+ node.label.toLowerCase().includes(searchInput.value.toLowerCase())
632+ );
633+
634+ if (matchingNodes.length === 0) return;
635+
636+ if (e.key === 'Enter') {
637+ if (e.shiftKey) {
638+ // Previous match
639+ currentMatchIndex = (currentMatchIndex - 1 + matchingNodes.length) % matchingNodes.length;
640+ } else {
641+ // Next match
642+ currentMatchIndex = (currentMatchIndex + 1) % matchingNodes.length;
643+ }
644+
645+ const currentMatch = matchingNodes[currentMatchIndex];
646+ network.selectNodes([currentMatch.id]);
647+ network.focus(currentMatch.id, {
648+ scale: 1,
649+ animation: true
650+ });
651+ searchMessage.textContent = \`Showing \${currentMatchIndex + 1} of \${matchingNodes.length} matches\`;
652+ searchMessage.style.display = 'block';
653+ }
654+ });
655+
561656 // Initialize the network with initial data
562657 initNetwork(${ JSON . stringify ( data ) } , ${ JSON . stringify ( Array . from ( nodePositions . entries ( ) ) ) } );
563658 })();
0 commit comments