@@ -20,6 +20,7 @@ export class ResxProvider implements vscode.CustomTextEditorProvider {
2020 private static readonly viewType = AppConstants . viewTypeId ;
2121 private registered = false ;
2222 private currentPanel : vscode . WebviewPanel | undefined = undefined ;
23+ private panelsByDocument = new Map < string , vscode . WebviewPanel > ( ) ;
2324
2425 constructor (
2526 private readonly context : vscode . ExtensionContext
@@ -31,6 +32,7 @@ export class ResxProvider implements vscode.CustomTextEditorProvider {
3132 _token : vscode . CancellationToken
3233 ) : Promise < void > {
3334 this . currentPanel = webviewPanel ;
35+ this . panelsByDocument . set ( document . uri . toString ( ) , webviewPanel ) ;
3436 webviewPanel . webview . options = {
3537 enableScripts : true ,
3638 localResourceRoots : [ vscode . Uri . joinPath ( this . context . extensionUri , 'out' ) , vscode . Uri . joinPath ( this . context . extensionUri , 'media' ) ]
@@ -56,12 +58,18 @@ export class ResxProvider implements vscode.CustomTextEditorProvider {
5658 const inputs = newResourceInput ( this . context ) ;
5759 // then do something with them
5860 inputs . then ( ( result ) => {
59- this . currentPanel ?. webview . postMessage ( {
60- type : 'add' ,
61- key : result . key ,
62- value : result . value ,
63- comment : result . comment
64- } ) ;
61+ // Find the active webview panel for the current document
62+ const activePanel = this . getActivePanel ( ) ;
63+ if ( activePanel ) {
64+ activePanel . webview . postMessage ( {
65+ type : 'add' ,
66+ key : result . key ,
67+ value : result . value ,
68+ comment : result . comment
69+ } ) ;
70+ } else {
71+ vscode . window . showErrorMessage ( 'No active ResX editor found' ) ;
72+ }
6573 } ) ;
6674 } ) ;
6775
@@ -113,6 +121,7 @@ export class ResxProvider implements vscode.CustomTextEditorProvider {
113121 } ) ;
114122
115123 webviewPanel . onDidDispose ( ( ) => {
124+ this . panelsByDocument . delete ( document . uri . toString ( ) ) ;
116125 changeDocumentSubscription . dispose ( ) ;
117126 changeConfigurationSubscription . dispose ( ) ;
118127 } ) ;
@@ -153,6 +162,23 @@ export class ResxProvider implements vscode.CustomTextEditorProvider {
153162 } , 100 ) ;
154163 }
155164
165+ private getActivePanel ( ) : vscode . WebviewPanel | undefined {
166+ // Try to get the active tab and find the corresponding panel
167+ const activeTab = vscode . window . tabGroups . activeTabGroup . activeTab ;
168+ if ( activeTab && activeTab . input && 'uri' in activeTab . input ) {
169+ const activeUri = ( activeTab . input as any ) . uri ;
170+ if ( activeUri ) {
171+ const panel = this . panelsByDocument . get ( activeUri . toString ( ) ) ;
172+ if ( panel ) {
173+ return panel ;
174+ }
175+ }
176+ }
177+
178+ // Fallback to currentPanel if we can't determine the active tab
179+ return this . currentPanel ;
180+ }
181+
156182 private async updateTextDocument ( document : vscode . TextDocument , json : any ) {
157183 try {
158184 const parsedJson = JSON . parse ( json ) ;
0 commit comments