@@ -220,17 +220,31 @@ define(function (require, exports, module) {
220
220
var start = { line : - 1 , ch : - 1 } ,
221
221
end = { line : - 1 , ch : - 1 } ,
222
222
cursor = this . editor . getCursorPos ( ) ,
223
- match ,
224
- matchSemicolonPos ;
223
+ line = this . editor . document . getLine ( cursor . line ) ,
224
+ subLine ,
225
+ ampersandPos ,
226
+ semicolonPos ,
227
+ entityMatch ;
225
228
226
229
end . line = start . line = cursor . line ;
227
230
start . ch = cursor . ch - this . currentQuery . length ;
228
- match = this . editor . document . getLine ( cursor . line ) . slice ( cursor . ch ) ;
229
- matchSemicolonPos = match . indexOf ( ";" ) ;
231
+ subLine = line . slice ( cursor . ch ) ;
232
+ ampersandPos = subLine . indexOf ( "&" ) ;
233
+ semicolonPos = subLine . indexOf ( ";" ) ;
230
234
end . ch = start . ch + this . currentQuery . length ;
231
-
232
- if ( matchSemicolonPos !== - 1 && / ^ ( # * [ 0 - 9 ] + ) | ( [ a - z A - Z ] + ) $ / . test ( match . slice ( 0 , matchSemicolonPos ) ) ) {
233
- end . ch = this . editor . document . getLine ( cursor . line ) . indexOf ( ";" , start . ch ) + 1 ;
235
+
236
+ // We're looking for ';' in line before next '&'
237
+ if ( semicolonPos !== - 1 && ( ampersandPos === - 1 || ampersandPos > semicolonPos ) ) {
238
+
239
+ subLine = subLine . slice ( 0 , semicolonPos ) ;
240
+
241
+ // regexp must match entire subLine string
242
+ entityMatch = subLine . match ( / ^ ( # ? [ 0 - 9 ] + ) | ( [ a - z A - Z ] + ) $ / ) ;
243
+ if ( entityMatch && entityMatch . length > 0 && entityMatch . index === 0 &&
244
+ entityMatch [ 0 ] . length === subLine . length ) {
245
+ // replace entity
246
+ end . ch = line . indexOf ( ";" , start . ch ) + 1 ;
247
+ }
234
248
}
235
249
236
250
completion = completion . slice ( 0 , completion . indexOf ( " " ) ) ;
0 commit comments