@@ -29,10 +29,12 @@ const FEATURE_ID = PLUGIN_ID + ':syntax_highlighting';
29
29
export class CMSyntaxHighlighting extends CodeMirrorIntegration {
30
30
lab_integration : SyntaxLabIntegration ;
31
31
settings : IFeatureSettings < LSPSyntaxHighlightingSettings > ;
32
+ editors_with_active_highlight : Set < CodeMirrorEditor > ;
32
33
33
34
constructor ( options : IEditorIntegrationOptions ) {
34
35
super ( options ) ;
35
36
this . virtual_document . changed . connect ( this . update_mode . bind ( this ) , this ) ;
37
+ this . editors_with_active_highlight = new Set ( ) ;
36
38
}
37
39
38
40
private get_mode ( language : string ) {
@@ -52,10 +54,12 @@ export class CMSyntaxHighlighting extends CodeMirrorIntegration {
52
54
53
55
update_mode ( ) {
54
56
let root = this . virtual_document ;
57
+ let editors_with_current_highlight = new Set < CodeMirrorEditor > ( ) ;
58
+
55
59
for ( let map of root . foreign_document_maps ) {
56
60
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 ;
59
63
let lines = editor . getValue ( '\n' ) ;
60
64
let total_area = lines . concat ( '' ) . length ;
61
65
@@ -75,13 +79,24 @@ export class CMSyntaxHighlighting extends CodeMirrorIntegration {
75
79
76
80
// change the mode if the majority of the code is the foreign code
77
81
if ( coverage > this . settings . composite . foreignCodeThreshold ) {
82
+ editors_with_current_highlight . add ( ce_editor ) ;
78
83
let old_mode = editor . getOption ( 'mode' ) ;
79
84
if ( old_mode != mode . mime ) {
80
85
editor . setOption ( 'mode' , mode . mime ) ;
81
86
}
82
87
}
83
88
}
84
89
}
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 ;
85
100
}
86
101
}
87
102
0 commit comments