@@ -53,7 +53,7 @@ define(function (require, exports, module) {
5353 /**
5454 * The Emmet api's
5555 */
56- const EXPAND_ABBR = Phoenix . libs . Emmet . expand ;
56+ const expandAbbr = Phoenix . libs . Emmet . expand ;
5757
5858 /**
5959 * A list of all the markup snippets that can be expanded.
@@ -98,7 +98,7 @@ define(function (require, exports, module) {
9898 // make sure we donot have empty spaces
9999 if ( wordObj . word . trim ( ) ) {
100100
101- const expandedAbbr = isExpandable ( editor , wordObj . word ) ;
101+ const expandedAbbr = _isExpandable ( editor , wordObj . word ) ;
102102 if ( expandedAbbr ) {
103103 return true ;
104104 }
@@ -119,7 +119,7 @@ define(function (require, exports, module) {
119119 const wordObj = getWordBeforeCursor ( this . editor ) ;
120120
121121 // Check if the abbreviation is expandable
122- const expandedAbbr = isExpandable ( this . editor , wordObj . word ) ;
122+ const expandedAbbr = _isExpandable ( this . editor , wordObj . word ) ;
123123 if ( ! expandedAbbr ) {
124124 return null ;
125125 }
@@ -166,8 +166,9 @@ define(function (require, exports, module) {
166166 */
167167 EmmetMarkupHints . prototype . insertHint = function ( ) {
168168 const wordObj = getWordBeforeCursor ( this . editor ) ;
169- const expandedAbbr = isExpandable ( this . editor , wordObj . word ) ;
170- updateAbbrInEditor ( this . editor , wordObj , expandedAbbr ) ;
169+ const expandedAbbr = _isExpandable ( this . editor , wordObj . word ) ;
170+ _updateAbbrInEditor ( this . editor , wordObj , expandedAbbr ) ;
171+ Metrics . countEvent ( Metrics . EVENT_TYPE . CODE_HINTS , "emmet" , "htmlInsert" ) ;
171172 return false ;
172173 } ;
173174
@@ -179,7 +180,7 @@ define(function (require, exports, module) {
179180 * @param {Boolean } insideBraces - Flag indicating if we are inside braces (e.g. {} or [])
180181 * @returns True if the character is valid for an abbreviation
181182 */
182- function isEmmetChar ( char , insideBraces ) {
183+ function _isEmmetChar ( char , insideBraces ) {
183184 // Valid abbreviation characters: letters, digits, and some punctuation
184185 // Adjust this regex or the list as needed for your implementation
185186 const validPattern = / [ a - z A - Z 0 - 9 : + * < > ( ) / ! $ \- @ # } { ] / ;
@@ -195,7 +196,7 @@ define(function (require, exports, module) {
195196 * @param {Number } cursorCh - The cursor's character (column) position on that line
196197 * @returns The index (column) where the abbreviation starts
197198 */
198- function findAbbreviationStart ( line , cursorCh ) {
199+ function _findAbbreviationStart ( line , cursorCh ) {
199200 let start = cursorCh ;
200201 let insideBraces = false ;
201202
@@ -217,7 +218,7 @@ define(function (require, exports, module) {
217218 }
218219
219220 // If the character is valid as part of an Emmet abbreviation, continue scanning backwards
220- if ( isEmmetChar ( char , insideBraces ) ) {
221+ if ( _isEmmetChar ( char , insideBraces ) ) {
221222 start -- ;
222223 } else {
223224 break ;
@@ -245,7 +246,7 @@ define(function (require, exports, module) {
245246 const lineText = editor . document . getLine ( pos . line ) ;
246247
247248 // to determine where the abbreviation starts on the line
248- const abbreviationStart = findAbbreviationStart ( lineText , pos . ch ) ;
249+ const abbreviationStart = _findAbbreviationStart ( lineText , pos . ch ) ;
249250
250251 // Optionally, adjust the end position if the cursor is immediately before a closing brace.
251252 let abbreviationEnd = pos . ch ;
@@ -401,7 +402,7 @@ define(function (require, exports, module) {
401402 * }
402403 * @param {String } expandedAbbr - the expanded version of abbr that will replace the abbr
403404 */
404- function updateAbbrInEditor ( editor , wordObj , expandedAbbr ) {
405+ function _updateAbbrInEditor ( editor , wordObj , expandedAbbr ) {
405406 // Get the current line's indentation
406407 const baseIndent = getLineIndentation ( editor , wordObj . start ) ;
407408
@@ -456,30 +457,30 @@ define(function (require, exports, module) {
456457 *
457458 * @param {Editor } editor - the editor instance
458459 * @param {String } word - the abbr
459- * @returns {String | false } - returns the expanded abbr, and if cannot be expanded, returns false
460+ * @returns {String | null } - returns the expanded abbr, and if cannot be expanded, returns null
460461 */
461- function isExpandable ( editor , word ) {
462+ function _isExpandable ( editor , word ) {
462463 const pos = editor . getCursorPos ( ) ;
463464 const line = editor . document . getLine ( pos . line ) ;
464465
465466 // to prevent hints from appearing in <!DOCTYPE html> line. Also to prevent hints from appearing in comments
466467 if ( line . includes ( '<!' ) ) {
467- return false ;
468+ return null ;
468469 }
469470
470471 // to show emmet hint when either a single or three exclamation mark(s) is present
471472 if ( line . includes ( '!!' ) && ! line . includes ( '!!!' ) ) {
472- return false ;
473+ return null ;
473474 }
474475
475476 // if more than three, then don't show emmet hint
476477 if ( line . includes ( '!!!!' ) ) {
477- return false ;
478+ return null ;
478479 }
479480
480481 // make sure that word doesn't contain any negativeSymbols
481482 if ( negativeSymbols . some ( symbol => word . includes ( symbol ) ) ) {
482- return false ;
483+ return null ;
483484 }
484485
485486 // the word must be either in markupSnippetsList, htmlList or it must have a positive symbol
@@ -491,8 +492,7 @@ define(function (require, exports, module) {
491492 positiveSymbols . some ( symbol => word . includes ( symbol ) ) ) {
492493
493494 try {
494- const expanded = EXPAND_ABBR ( word , { syntax : "html" , type : "markup" } ) ;
495- return expanded ;
495+ return expandAbbr ( word , { syntax : "html" , type : "markup" } ) ; // expanded
496496 } catch ( error ) {
497497
498498 // emmet api throws an error when abbr contains unclosed quotes, handling that case
@@ -504,21 +504,20 @@ define(function (require, exports, module) {
504504 const modifiedWord = word + nextChar ;
505505
506506 try {
507- const expandedModified = EXPAND_ABBR ( modifiedWord , { syntax : "html" , type : "markup" } ) ;
508- return expandedModified ;
507+ return expandAbbr ( modifiedWord , { syntax : "html" , type : "markup" } ) ; //expandedModified
509508 } catch ( innerError ) {
510509 // If it still fails, return false
511- return false ;
510+ return null ;
512511 }
513512 }
514513 }
515514
516515 // If no quote is found or expansion fails, return false
517- return false ;
516+ return null ;
518517 }
519518 }
520519
521- return false ;
520+ return null ;
522521 }
523522
524523
0 commit comments