@@ -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
@@ -73,15 +77,27 @@ export class CMSyntaxHighlighting extends CodeMirrorIntegration {
73
77
continue ;
74
78
}
75
79
80
+ let old_mode = editor . getOption ( 'mode' ) ;
81
+
76
82
// change the mode if the majority of the code is the foreign code
77
83
if ( coverage > this . settings . composite . foreignCodeThreshold ) {
78
- let old_mode = editor . getOption ( 'mode' ) ;
84
+ editors_with_current_highlight . add ( ce_editor ) ;
79
85
if ( old_mode != mode . mime ) {
80
86
editor . setOption ( 'mode' , mode . mime ) ;
81
87
}
82
88
}
83
89
}
84
90
}
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 ;
85
101
}
86
102
}
87
103
0 commit comments