@@ -348,23 +348,30 @@ define(function (require, exports, module) {
348348 * @returns {Object | false } - Cursor position {line, ch} or false if no pattern found
349349 */
350350 function findCursorPosition ( editor , indentedAbbr , startPos ) {
351- const totalLines = startPos . line + indentedAbbr . split ( '\n' ) . length ;
351+ const abbrLines = indentedAbbr . split ( '\n' ) ;
352352
353- for ( let i = startPos . line ; i < totalLines ; i ++ ) {
354- const line = editor . document . getLine ( i ) ;
353+ for ( let lineOffset = 0 ; lineOffset < abbrLines . length ; lineOffset ++ ) {
354+ const abbrLine = abbrLines [ lineOffset ] ;
355355
356- for ( let j = 0 ; j < line . length - 1 ; j ++ ) {
357- const pair = line [ j ] + line [ j + 1 ] ;
356+ // Search for empty quotes "" or ''
357+ for ( let j = 0 ; j < abbrLine . length - 1 ; j ++ ) {
358+ const pair = abbrLine [ j ] + abbrLine [ j + 1 ] ;
358359
359360 if ( pair === '""' || pair === "''" ) {
360- return { line : i , ch : j + 1 } ;
361+ const absoluteLine = startPos . line + lineOffset ;
362+ const absoluteCh = ( lineOffset === 0 ) ? startPos . ch + j + 1 : j + 1 ;
363+ return { line : absoluteLine , ch : absoluteCh } ;
361364 }
362365 }
363- for ( let j = 0 ; j < line . length - 1 ; j ++ ) {
364- const pair = line [ j ] + line [ j + 1 ] ;
366+
367+ // Search for >< pattern (cursor between tags)
368+ for ( let j = 0 ; j < abbrLine . length - 1 ; j ++ ) {
369+ const pair = abbrLine [ j ] + abbrLine [ j + 1 ] ;
365370
366371 if ( pair === '><' ) {
367- return { line : i , ch : j + 1 } ;
372+ const absoluteLine = startPos . line + lineOffset ;
373+ const absoluteCh = ( lineOffset === 0 ) ? startPos . ch + j + 1 : j + 1 ;
374+ return { line : absoluteLine , ch : absoluteCh } ;
368375 }
369376 }
370377 }
@@ -374,7 +381,7 @@ define(function (require, exports, module) {
374381 // |
375382 // </body>
376383 // here in such scenarios, we want the cursor to be placed in between
377- // Look for opening and closing tag pairs with empty line in between
384+ const totalLines = startPos . line + abbrLines . length ;
378385 for ( let i = startPos . line ; i < totalLines ; i ++ ) {
379386 const line = editor . document . getLine ( i ) . trim ( ) ;
380387 if ( line . endsWith ( '>' ) && line . includes ( '<' ) && ! line . includes ( '</' ) ) {
0 commit comments