@@ -390,6 +390,14 @@ class DefaultClient implements Client {
390
390
}
391
391
}
392
392
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
+
393
401
/**
394
402
* Take ownership of a document that was previously serviced by another client.
395
403
* This process involves sending a textDocument/didOpen message to the server so
@@ -634,25 +642,24 @@ class DefaultClient implements Client {
634
642
light : { color : "rgba(125,125,125,1.0)" } ,
635
643
dark : { color : "rgba(155,155,155,1.0)" }
636
644
} ;
645
+ let decoration : vscode . TextEditorDecorationType = vscode . window . createTextEditorDecorationType ( renderOptions ) ;
637
646
638
647
// 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 ] ) ;
641
657
}
642
- let decoration : vscode . TextEditorDecorationType = vscode . window . createTextEditorDecorationType ( renderOptions ) ;
643
- this . inactiveRegionsDecorations . set ( params . uri , [ decoration , params . ranges ] ) ;
644
658
645
- // Apply the decorations to all relevant editors
659
+ // Apply the decorations to all *visible* text editors
646
660
let editors : vscode . TextEditor [ ] = vscode . window . visibleTextEditors . filter ( e => e . document . uri . toString ( ) === params . uri ) ;
647
661
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 ) ;
656
663
}
657
664
}
658
665
0 commit comments