@@ -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
@@ -73,15 +77,27 @@ export class CMSyntaxHighlighting extends CodeMirrorIntegration {
7377 continue ;
7478 }
7579
80+ let old_mode = editor . getOption ( 'mode' ) ;
81+
7682 // change the mode if the majority of the code is the foreign code
7783 if ( coverage > this . settings . composite . foreignCodeThreshold ) {
78- let old_mode = editor . getOption ( 'mode' ) ;
84+ editors_with_current_highlight . add ( ce_editor ) ;
7985 if ( old_mode != mode . mime ) {
8086 editor . setOption ( 'mode' , mode . mime ) ;
8187 }
8288 }
8389 }
8490 }
91+
92+ if ( editors_with_current_highlight != this . editors_with_active_highlight ) {
93+ for ( let ce_editor of this . editors_with_active_highlight ) {
94+ if ( ! editors_with_current_highlight . has ( ce_editor ) ) {
95+ ce_editor . editor . setOption ( 'mode' , ce_editor . model . mimeType ) ;
96+ }
97+ }
98+ }
99+
100+ this . editors_with_active_highlight = editors_with_current_highlight ;
85101 }
86102}
87103
0 commit comments