@@ -3,11 +3,6 @@ import { XMLValidator } from 'fast-xml-parser'
3
3
4
4
export function setupXMLValidation ( monaco : typeof MonacoTypes ) {
5
5
const markerId = 'xml-validation'
6
- const contentChangeListeners = new Map < MonacoTypes . editor . ITextModel , MonacoTypes . IDisposable > ( )
7
-
8
- monaco . editor . onWillDisposeModel ( model => {
9
- contentChangeListeners . delete ( model )
10
- } )
11
6
12
7
function validate ( model : MonacoTypes . editor . ITextModel ) {
13
8
const markers : MonacoTypes . editor . IMarkerData [ ] = [ ]
@@ -33,7 +28,8 @@ export function setupXMLValidation(monaco: typeof MonacoTypes) {
33
28
monaco . editor . setModelMarkers ( model , markerId , markers )
34
29
}
35
30
36
- monaco . editor . onDidChangeModelLanguage ( ( { model } ) => {
31
+ const contentChangeListeners = new Map < MonacoTypes . editor . ITextModel , MonacoTypes . IDisposable > ( )
32
+ function manageContentChangeListener ( model : MonacoTypes . editor . ITextModel ) {
37
33
const isXml = model . getModeId ( ) === 'xml'
38
34
const listener = contentChangeListeners . get ( model )
39
35
@@ -48,5 +44,15 @@ export function setupXMLValidation(monaco: typeof MonacoTypes) {
48
44
contentChangeListeners . delete ( model )
49
45
monaco . editor . setModelMarkers ( model , markerId , [ ] )
50
46
}
47
+ }
48
+
49
+ monaco . editor . onWillDisposeModel ( model => {
50
+ contentChangeListeners . delete ( model )
51
+ } )
52
+ monaco . editor . onDidChangeModelLanguage ( ( { model } ) => {
53
+ manageContentChangeListener ( model )
54
+ } )
55
+ monaco . editor . onDidCreateModel ( model => {
56
+ manageContentChangeListener ( model )
51
57
} )
52
58
}
0 commit comments