@@ -114,7 +114,8 @@ interface DataViewRequestMessage {
114114 filterModel ?: Record < string , unknown > ;
115115}
116116
117- const dynamicDataViewPanels = new WeakSet < vscode . WebviewPanel > ( ) ;
117+ const dynamicDataViewPanels = new Map < string , vscode . WebviewPanel > ( ) ;
118+ let dynamicDataViewReloadRevision = 0 ;
118119
119120function escapeHtml ( text : string ) : string {
120121 const map : Record < string , string > = {
@@ -127,13 +128,7 @@ function escapeHtml(text: string): string {
127128 return text . replace ( / [ & < > " ' ] / g, c => map [ c ] ) ;
128129}
129130
130- function formatDataViewPanelTitle ( baseTitle : string , totalRows : number ) : string {
131- return `${ baseTitle } (rows: ${ totalRows . toLocaleString ( ) } )` ;
132- }
133-
134131function attachDynamicDataViewBridge ( panel : vscode . WebviewPanel , viewId : string , baseTitle : string ) : void {
135- dynamicDataViewPanels . add ( panel ) ;
136-
137132 const postResponse = ( requestId : number , ok : boolean , result ?: unknown , error ?: string ) => {
138133 void panel . webview . postMessage ( {
139134 message : 'dataview/response' ,
@@ -159,9 +154,7 @@ function attachDynamicDataViewBridge(panel: vscode.WebviewPanel, viewId: string,
159154 if ( ! result || typeof result . totalRows !== 'number' ) {
160155 throw new Error ( 'Invalid dataview_init response: missing or invalid totalRows' ) ;
161156 }
162- if ( Number . isFinite ( result . totalRows ) ) {
163- panel . title = formatDataViewPanelTitle ( baseTitle , result . totalRows ) ;
164- }
157+ panel . title = baseTitle ;
165158 postResponse ( msg . requestId , true , result ) ;
166159 return ;
167160 }
@@ -180,9 +173,7 @@ function attachDynamicDataViewBridge(panel: vscode.WebviewPanel, viewId: string,
180173 if ( ! result || typeof result . totalRows !== 'number' ) {
181174 throw new Error ( 'Invalid dataview_page response: missing or invalid totalRows' ) ;
182175 }
183- if ( Number . isFinite ( result . totalRows ) ) {
184- panel . title = formatDataViewPanelTitle ( baseTitle , result . totalRows ) ;
185- }
176+ panel . title = baseTitle ;
186177 postResponse ( msg . requestId , true , result ) ;
187178 return ;
188179 }
@@ -192,8 +183,9 @@ function attachDynamicDataViewBridge(panel: vscode.WebviewPanel, viewId: string,
192183 method : 'dataview_dispose' ,
193184 params : { view_id : viewId } ,
194185 } ) ;
195- // Remove from panels set to prevent duplicate disposal on panel close
196- dynamicDataViewPanels . delete ( panel ) ;
186+ if ( dynamicDataViewPanels . get ( viewId ) === panel ) {
187+ dynamicDataViewPanels . delete ( viewId ) ;
188+ }
197189 postResponse ( msg . requestId , true , true ) ;
198190 return ;
199191 }
@@ -205,10 +197,10 @@ function attachDynamicDataViewBridge(panel: vscode.WebviewPanel, viewId: string,
205197 } ) ;
206198
207199 panel . onDidDispose ( ( ) => {
208- if ( ! dynamicDataViewPanels . has ( panel ) ) {
200+ if ( dynamicDataViewPanels . get ( viewId ) !== panel ) {
209201 return ;
210202 }
211- dynamicDataViewPanels . delete ( panel ) ;
203+ dynamicDataViewPanels . delete ( viewId ) ;
212204 void sessionRequest ( {
213205 method : 'dataview_dispose' ,
214206 params : { view_id : viewId } ,
@@ -641,6 +633,17 @@ export async function showDataView(source: string, type: string, title: string,
641633 console . info ( `[showDataView] source: ${ source } , type: ${ type } , title: ${ title } , file: ${ file } , viewer: ${ viewer } , viewId: ${ String ( viewId ?? '' ) } ` ) ;
642634
643635 if ( source === 'table' ) {
636+ if ( viewId ) {
637+ const existing = dynamicDataViewPanels . get ( viewId ) ;
638+ if ( existing ) {
639+ existing . title = title ;
640+ existing . reveal ( ViewColumn [ viewer as keyof typeof ViewColumn ] , true ) ;
641+ const content = await getTableHtml ( existing . webview , undefined , title ) ;
642+ existing . webview . html = `${ content } \n<!-- dataview-reload:${ ++ dynamicDataViewReloadRevision } -->` ;
643+ return ;
644+ }
645+ }
646+
644647 const panel = window . createWebviewPanel ( 'dataview' , title ,
645648 {
646649 preserveFocus : true ,
@@ -652,12 +655,13 @@ export async function showDataView(source: string, type: string, title: string,
652655 retainContextWhenHidden : true ,
653656 localResourceRoots : [ Uri . file ( resDir ) ] ,
654657 } ) ;
655- const content = await getTableHtml ( panel . webview , file || undefined , title ) ;
656658 panel . iconPath = new UriIcon ( 'open-preview' ) ;
657- panel . webview . html = content ;
658659 if ( viewId ) {
660+ dynamicDataViewPanels . set ( viewId , panel ) ;
659661 attachDynamicDataViewBridge ( panel , viewId , title ) ;
660662 }
663+ const content = await getTableHtml ( panel . webview , file || undefined , title ) ;
664+ panel . webview . html = content ;
661665 } else if ( source === 'list' ) {
662666 const panel = window . createWebviewPanel ( 'dataview' , title ,
663667 {
0 commit comments