@@ -18,6 +18,10 @@ export class CSSClassDefinitionLocator {
18
18
return this . getStandardFormatClassName ( ) ;
19
19
}
20
20
21
+ if ( this . isTargetHTMLElement ( ) ) {
22
+ return this . getHTMlElementName ( ) ;
23
+ }
24
+
21
25
if ( this . isDirectiveFormat ( ) && this . initialNodeAt . name ) {
22
26
return this . getDefinitionRangeWithinStyleSection ( `.${ this . initialNodeAt . name } ` ) ;
23
27
}
@@ -41,6 +45,18 @@ export class CSSClassDefinitionLocator {
41
45
return false ;
42
46
}
43
47
48
+ /**
49
+ * HTML Element target:
50
+ * <main>
51
+ */
52
+ private isTargetHTMLElement ( ) {
53
+ if ( this . initialNodeAt ?. type == 'Element' ) {
54
+ return true ;
55
+ }
56
+
57
+ return false ;
58
+ }
59
+
44
60
/**
45
61
* Conditional Expression format:
46
62
* class="{current === 'baz' ? 'selected' : ''
@@ -104,8 +120,25 @@ export class CSSClassDefinitionLocator {
104
120
return this . getDefinitionRangeWithinStyleSection ( `.${ cssClassName } ` ) ;
105
121
}
106
122
123
+ private getHTMlElementName ( ) {
124
+ const result = this . getDefinitionRangeWithinStyleSection ( `${ this . initialNodeAt . name } ` ) ;
125
+ if ( result ) {
126
+ //Shift start/end to get the highlight right
127
+ const originalStart = result . start . character ;
128
+ result . start . character -= 1 ;
129
+ if ( this . initialNodeAt . name ) {
130
+ result . end . character = originalStart + this . initialNodeAt . name . length ;
131
+ }
132
+
133
+ return result ;
134
+ }
135
+ }
136
+
107
137
private getDefinitionRangeWithinStyleSection ( targetClass : string ) {
108
- let indexOccurence = this . document . content . indexOf ( targetClass , 0 ) ;
138
+ let indexOccurence = this . document . content . indexOf (
139
+ targetClass ,
140
+ this . document . styleInfo ?. start
141
+ ) ;
109
142
110
143
while ( indexOccurence >= 0 ) {
111
144
if ( this . isOffsetWithinStyleSection ( indexOccurence ) ) {
@@ -124,6 +157,8 @@ export class CSSClassDefinitionLocator {
124
157
}
125
158
126
159
return targetRange ;
160
+ } else {
161
+ break ;
127
162
}
128
163
}
129
164
}
0 commit comments