@@ -76,8 +76,12 @@ export function activate(context: vscode.ExtensionContext) {
7676 } ) ) ;
7777
7878 context . subscriptions . push ( vscode . commands . registerCommand ( 'rtlDebugger.addToWaveform' , ( treeItem ) => {
79- if ( rtlDebugger . waveformProvider ) {
80- rtlDebugger . waveformProvider . addVariable ( treeItem . designation . variable ) ;
79+ if ( rtlDebugger . lastActiveWaveformTab ) {
80+ console . log ( rtlDebugger . lastActiveWaveformTab ) ;
81+ const target = rtlDebugger . waveformProviders . get ( rtlDebugger . lastActiveWaveformTab ) ;
82+ if ( target ) {
83+ target . addVariable ( treeItem . designation . variable ) ;
84+ }
8185 }
8286 } ) ) ;
8387
@@ -96,19 +100,48 @@ export function activate(context: vscode.ExtensionContext) {
96100 globalWatchList . remove ( treeItem . metadata . index ) ) ) ;
97101
98102 context . subscriptions . push ( vscode . commands . registerCommand ( 'rtlDebugger.browseWaveforms' , ( ) => {
103+ const viewKey = `rtlDebugger.waveforms.${ rtlDebugger . nextWaveformviewId ++ } ` ;
99104 const webviewPanel = vscode . window . createWebviewPanel (
100- 'rtlDebugger.waveforms' ,
101- 'Waveforms' , {
105+ viewKey ,
106+ 'Waveforms' ,
107+ {
102108 viewColumn : vscode . ViewColumn . Beside ,
103- } , {
109+ } ,
110+ {
104111 enableScripts : true ,
105112 retainContextWhenHidden : true ,
106- } ) ;
113+ }
114+ ) ;
115+ console . log ( `Creating web view panel with viewType ${ webviewPanel . viewType } ` ) ;
107116 const bundleRoot = vscode . Uri . joinPath ( context . extensionUri , 'out/' ) ;
108- rtlDebugger . waveformProvider = new WaveformProvider ( rtlDebugger , webviewPanel , bundleRoot ) ;
109- context . subscriptions . push ( rtlDebugger . waveformProvider ) ;
117+ const waveformProvider = new WaveformProvider ( rtlDebugger , webviewPanel , bundleRoot ) ;
118+ rtlDebugger . waveformProviders . set ( viewKey , waveformProvider ) ;
119+ rtlDebugger . lastActiveWaveformTab = viewKey ;
120+ context . subscriptions . push ( waveformProvider ) ;
110121 } ) ) ;
111122
123+ vscode . window . tabGroups . onDidChangeTabs ( event => {
124+ const activeWaveformTab = event . changed . map ( ( tab , _ ) => {
125+ if ( tab . input instanceof vscode . TabInputWebview ) {
126+ console . log ( `${ tab . input . viewType } ` ) ;
127+
128+ const key = tab . input . viewType . match ( / .* ( r t l D e b u g g e r .w a v e f o r m s \. \d + ) / ) ;
129+
130+ if ( key ) {
131+ return key [ 1 ] ;
132+ } else {
133+ return null ;
134+ }
135+ } else {
136+ return null ;
137+ }
138+ } ) . find ( ( id ) => id !== null ) ;
139+
140+ if ( activeWaveformTab ) {
141+ rtlDebugger . lastActiveWaveformTab = activeWaveformTab ;
142+ }
143+ } ) ;
144+
112145 // For an unknown reason, the `vscode.open` command (which does the exact same thing) ignores the options.
113146 context . subscriptions . push ( vscode . commands . registerCommand ( 'rtlDebugger.openDocument' ,
114147 ( uri : vscode . Uri , options : vscode . TextDocumentShowOptions ) => {
0 commit comments