@@ -29,10 +29,12 @@ const FEATURE_ID = PLUGIN_ID + ':syntax_highlighting';
2929export class CMSyntaxHighlighting extends CodeMirrorIntegration {
3030 lab_integration : SyntaxLabIntegration ;
3131 settings : IFeatureSettings < LSPSyntaxHighlightingSettings > ;
32+ editors_with_active_highlight : Set < CodeMirrorEditor > ;
3233
3334 constructor ( options : IEditorIntegrationOptions ) {
3435 super ( options ) ;
3536 this . virtual_document . changed . connect ( this . update_mode . bind ( this ) , this ) ;
37+ this . editors_with_active_highlight = new Set ( ) ;
3638 }
3739
3840 private get_mode ( language : string ) {
@@ -52,10 +54,12 @@ export class CMSyntaxHighlighting extends CodeMirrorIntegration {
5254
5355 update_mode ( ) {
5456 let root = this . virtual_document ;
57+ let editors_with_current_highlight = new Set < CodeMirrorEditor > ( ) ;
58+
5559 for ( let map of root . foreign_document_maps ) {
5660 for ( let [ range , block ] of map . entries ( ) ) {
57- let ce_editor = block . editor ;
58- let editor = ( ce_editor as CodeMirrorEditor ) . editor ;
61+ let ce_editor = block . editor as CodeMirrorEditor ;
62+ let editor = ce_editor . editor ;
5963 let lines = editor . getValue ( '\n' ) ;
6064 let total_area = lines . concat ( '' ) . length ;
6165
@@ -75,13 +79,24 @@ export class CMSyntaxHighlighting extends CodeMirrorIntegration {
7579
7680 // change the mode if the majority of the code is the foreign code
7781 if ( coverage > this . settings . composite . foreignCodeThreshold ) {
82+ editors_with_current_highlight . add ( ce_editor ) ;
7883 let old_mode = editor . getOption ( 'mode' ) ;
7984 if ( old_mode != mode . mime ) {
8085 editor . setOption ( 'mode' , mode . mime ) ;
8186 }
8287 }
8388 }
8489 }
90+
91+ if ( editors_with_current_highlight != this . editors_with_active_highlight ) {
92+ for ( let ce_editor of this . editors_with_active_highlight ) {
93+ if ( ! editors_with_current_highlight . has ( ce_editor ) ) {
94+ ce_editor . editor . setOption ( 'mode' , ce_editor . model . mimeType ) ;
95+ }
96+ }
97+ }
98+
99+ this . editors_with_active_highlight = editors_with_current_highlight ;
85100 }
86101}
87102
0 commit comments