@@ -10,6 +10,7 @@ export default class ExpressionHighlighter extends EventDispatcher {
10
10
this . editor = editor ;
11
11
this . activeMarks = [ ] ;
12
12
this . hoverMarks = [ ] ;
13
+ this . widgets = [ ] ;
13
14
}
14
15
15
16
draw ( tokens ) {
@@ -60,13 +61,52 @@ export default class ExpressionHighlighter extends EventDispatcher {
60
61
} ) ;
61
62
}
62
63
64
+ drawError ( errors ) {
65
+ this . clearError ( ) ;
66
+
67
+ const pre = ExpressionHighlighter . CSS_PREFIX ;
68
+ const editor = this . editor ;
69
+ editor . operation ( ( ) => {
70
+ for ( const error of errors ) {
71
+ const location = Editor . calcRangePos (
72
+ this . editor ,
73
+ error . location . start ,
74
+ error . location . end - error . location . start
75
+ ) ;
76
+ const widget = document . createElement ( "span" ) ;
77
+ widget . className = `${ pre } -error` ;
78
+
79
+ widget . style . height = `2px` ;
80
+ widget . style . zIndex = "10" ;
81
+ widget . setAttribute ( "data-tippy-content" , error . message ) ;
82
+
83
+ editor . addWidget ( location . startPos , widget ) ;
84
+ const startCoords = editor . charCoords ( location . startPos , "local" ) ;
85
+ const endCoords = editor . charCoords ( location . endPos , "local" ) ;
86
+ widget . style . left = `${ startCoords . left + 1 } px` ;
87
+ widget . style . top = `${ startCoords . bottom } px` ;
88
+ widget . style . width = `${ endCoords . left - startCoords . left - 2 } px` ;
89
+
90
+ this . widgets . push ( widget ) ;
91
+ }
92
+ } ) ;
93
+ }
94
+
63
95
clear ( ) {
64
96
this . editor . operation ( ( ) => {
65
- let marks = this . activeMarks ;
66
- for ( var i = 0 , l = marks . length ; i < l ; i ++ ) {
67
- marks [ i ] . clear ( ) ;
97
+ for ( const mark of this . activeMarks ) {
98
+ mark . clear ( ) ;
99
+ }
100
+ this . activeMarks . length = 0 ;
101
+ } ) ;
102
+ }
103
+
104
+ clearError ( ) {
105
+ this . editor . operation ( ( ) => {
106
+ for ( const widget of this . widgets ) {
107
+ widget . parentNode . removeChild ( widget ) ;
68
108
}
69
- marks . length = 0 ;
109
+ this . widgets . length = 0 ;
70
110
} ) ;
71
111
}
72
112
@@ -77,9 +117,7 @@ export default class ExpressionHighlighter extends EventDispatcher {
77
117
return ;
78
118
}
79
119
80
- while ( this . hoverMarks . length ) {
81
- this . hoverMarks . pop ( ) . clear ( ) ;
82
- }
120
+ this . clearHover ( ) ;
83
121
84
122
if ( selection ) {
85
123
this . drawBorder ( selection , "selected" ) ;
@@ -119,9 +157,12 @@ export default class ExpressionHighlighter extends EventDispatcher {
119
157
}
120
158
121
159
clearHover ( ) {
122
- while ( this . hoverMarks . length ) {
123
- this . hoverMarks . pop ( ) . clear ( ) ;
124
- }
160
+ this . editor . operation ( ( ) => {
161
+ for ( const mark of this . hoverMarks ) {
162
+ mark . clear ( ) ;
163
+ }
164
+ this . hoverMarks . length = 0 ;
165
+ } ) ;
125
166
}
126
167
}
127
168
0 commit comments