@@ -390,6 +390,14 @@ class DefaultClient implements Client {
390390 }
391391 }
392392
393+ public onDidChangeVisibleTextEditors ( editors : vscode . TextEditor [ ] ) : void {
394+ //Apply text decorations to inactive regions
395+ for ( let e of editors ) {
396+ let value : [ vscode . TextEditorDecorationType , vscode . Range [ ] ] = this . inactiveRegionsDecorations . get ( e . document . uri . toString ( ) ) ;
397+ e . setDecorations ( value [ 0 ] , value [ 1 ] ) ;
398+ }
399+ }
400+
393401 /**
394402 * Take ownership of a document that was previously serviced by another client.
395403 * This process involves sending a textDocument/didOpen message to the server so
@@ -634,25 +642,24 @@ class DefaultClient implements Client {
634642 light : { color : "rgba(125,125,125,1.0)" } ,
635643 dark : { color : "rgba(155,155,155,1.0)" }
636644 } ;
645+ let decoration : vscode . TextEditorDecorationType = vscode . window . createTextEditorDecorationType ( renderOptions ) ;
637646
638647 // Recycle the active text decorations when we receive a new set of inactive regions
639- if ( this . inactiveRegionsDecorations . has ( params . uri ) ) {
640- this . inactiveRegionsDecorations . get ( params . uri ) [ 0 ] . dispose ( ) ;
648+ let valuePair : [ vscode . TextEditorDecorationType , vscode . Range [ ] ] = this . inactiveRegionsDecorations . get ( params . uri ) ;
649+ if ( valuePair !== undefined ) {
650+ // Disposing of and resetting the decoration will undo previously applied text decorations
651+ valuePair [ 0 ] . dispose ( ) ;
652+ valuePair [ 0 ] = decoration ;
653+
654+ valuePair [ 1 ] = params . ranges ; // As vscode.TextEditor.setDecorations only applies to visible editors, we must cache the range when another editor become visible
655+ } else { // The entry does not exist. Make a new one
656+ this . inactiveRegionsDecorations . set ( params . uri , [ decoration , params . ranges ] ) ;
641657 }
642- let decoration : vscode . TextEditorDecorationType = vscode . window . createTextEditorDecorationType ( renderOptions ) ;
643- this . inactiveRegionsDecorations . set ( params . uri , [ decoration , params . ranges ] ) ;
644658
645- // Apply the decorations to all relevant editors
659+ // Apply the decorations to all *visible* text editors
646660 let editors : vscode . TextEditor [ ] = vscode . window . visibleTextEditors . filter ( e => e . document . uri . toString ( ) === params . uri ) ;
647661 for ( let e of editors ) {
648- e . setDecorations ( this . inactiveRegionsDecorations . get ( params . uri ) [ 0 ] , params . ranges ) ;
649- }
650- }
651-
652- public onDidChangeVisibleTextEditors ( editors : vscode . TextEditor [ ] ) : void {
653- for ( let e of editors ) {
654- let value : [ vscode . TextEditorDecorationType , vscode . Range [ ] ] = this . inactiveRegionsDecorations . get ( e . document . uri . toString ( ) ) ;
655- e . setDecorations ( value [ 0 ] , value [ 1 ] ) ;
662+ e . setDecorations ( decoration , params . ranges ) ;
656663 }
657664 }
658665
0 commit comments