@@ -3,7 +3,6 @@ define(function (require, exports, module) {
33 const Global = require ( "./global" ) ;
44 const UIHelper = require ( "./UIHelper" ) ;
55
6-
76 /**
87 * map the language IDs to their file extensions for snippet matching
98 * this is needed because we expect the user to enter file extensions and not the file type inside the input field
@@ -13,41 +12,40 @@ define(function (require, exports, module) {
1312 */
1413 function mapLanguageToExtension ( languageId ) {
1514 const languageMap = {
16- ' javascript' : ' .js' ,
17- ' css' : ' .css' ,
18- ' html' : ' .html' ,
19- ' php' : ' .php' ,
20- ' python' : ' .py' ,
21- ' java' : ' .java' ,
22- 'c' : '.c' ,
23- ' cpp' : ' .cpp' ,
24- ' csharp' : ' .cs' ,
25- ' typescript' : ' .ts' ,
26- ' json' : ' .json' ,
27- ' xml' : ' .xml' ,
28- ' sql' : ' .sql' ,
29- ' sass' : ' .sass' ,
30- ' scss' : ' .scss' ,
31- ' less' : ' .less' ,
32- ' stylus' : ' .styl' ,
33- ' coffeescript' : ' .coffee' ,
34- ' markdown' : ' .md' ,
35- ' yaml' : ' .yml' ,
36- ' ruby' : ' .rb' ,
37- 'go' : ' .go' ,
38- ' rust' : ' .rs' ,
39- ' swift' : ' .swift' ,
40- ' kotlin' : ' .kt' ,
41- ' dart' : ' .dart' ,
42- ' vue' : ' .vue' ,
43- ' jsx' : ' .jsx' ,
44- ' tsx' : ' .tsx'
15+ javascript : " .js" ,
16+ css : " .css" ,
17+ html : " .html" ,
18+ php : " .php" ,
19+ python : " .py" ,
20+ java : " .java" ,
21+ c : ".c" ,
22+ cpp : " .cpp" ,
23+ csharp : " .cs" ,
24+ typescript : " .ts" ,
25+ json : " .json" ,
26+ xml : " .xml" ,
27+ sql : " .sql" ,
28+ sass : " .sass" ,
29+ scss : " .scss" ,
30+ less : " .less" ,
31+ stylus : " .styl" ,
32+ coffeescript : " .coffee" ,
33+ markdown : " .md" ,
34+ yaml : " .yml" ,
35+ ruby : " .rb" ,
36+ go : " .go" ,
37+ rust : " .rs" ,
38+ swift : " .swift" ,
39+ kotlin : " .kt" ,
40+ dart : " .dart" ,
41+ vue : " .vue" ,
42+ jsx : " .jsx" ,
43+ tsx : " .tsx"
4544 } ;
4645
4746 return languageMap [ languageId ] || languageId ;
4847 }
4948
50-
5149 /**
5250 * This function is responsible to get the snippet data from all the required input fields
5351 * it is called when the save button is clicked
@@ -139,7 +137,7 @@ define(function (require, exports, module) {
139137 const effectiveExtension = mapLanguageToExtension ( languageContext ) ;
140138
141139 // if we have a proper mapping (starts with .), use language context matching
142- if ( effectiveExtension . startsWith ( '.' ) ) {
140+ if ( effectiveExtension . startsWith ( "." ) ) {
143141 const supportedExtensions = snippet . fileExtension
144142 . toLowerCase ( )
145143 . split ( "," )
@@ -241,13 +239,11 @@ define(function (require, exports, module) {
241239 // create highlighting for matching characters like other hint providers
242240 if ( query && query . length > 0 ) {
243241 // use the StringMatch to get proper highlighting ranges
244- const matchResult = StringMatch . stringMatch ( abbr , query , { preferPrefixMatches : true } ) ;
242+ const matchResult = StringMatch . stringMatch ( abbr , query , { preferPrefixMatches : true } ) ;
245243 if ( matchResult && matchResult . stringRanges ) {
246244 matchResult . stringRanges . forEach ( function ( item ) {
247245 if ( item . matched ) {
248- $hint . append ( $ ( "<span>" )
249- . text ( item . text )
250- . addClass ( "matched-hint" ) ) ;
246+ $hint . append ( $ ( "<span>" ) . text ( item . text ) . addClass ( "matched-hint" ) ) ;
251247 } else {
252248 $hint . append ( item . text ) ;
253249 }
@@ -463,7 +459,7 @@ define(function (require, exports, module) {
463459 // to insert the tab character
464460 textarea . value = value . substring ( 0 , start ) + "\t" + value . substring ( end ) ;
465461 textarea . selectionStart = textarea . selectionEnd = start + 1 ;
466- $ ( textarea ) . trigger ( ' input' ) ;
462+ $ ( textarea ) . trigger ( " input" ) ;
467463 }
468464 }
469465
@@ -475,51 +471,66 @@ define(function (require, exports, module) {
475471
476472 // Allow navigation and function keys
477473 const allowedKeys = [
478- 'Backspace' , 'Delete' , 'Tab' , 'Escape' , 'Enter' ,
479- 'ArrowLeft' , 'ArrowRight' , 'ArrowUp' , 'ArrowDown' ,
480- 'Home' , 'End' , 'PageUp' , 'PageDown' ,
481- 'F1' , 'F2' , 'F3' , 'F4' , 'F5' , 'F6' , 'F7' , 'F8' , 'F9' , 'F10' , 'F11' , 'F12'
474+ "Backspace" ,
475+ "Delete" ,
476+ "Tab" ,
477+ "Escape" ,
478+ "Enter" ,
479+ "ArrowLeft" ,
480+ "ArrowRight" ,
481+ "ArrowUp" ,
482+ "ArrowDown" ,
483+ "Home" ,
484+ "End" ,
485+ "PageUp" ,
486+ "PageDown" ,
487+ "F1" ,
488+ "F2" ,
489+ "F3" ,
490+ "F4" ,
491+ "F5" ,
492+ "F6" ,
493+ "F7" ,
494+ "F8" ,
495+ "F9" ,
496+ "F10" ,
497+ "F11" ,
498+ "F12"
482499 ] ;
483500
484501 if ( allowedKeys . includes ( e . key ) ) {
485502 return ; // Allow these keys to work normally
486503 }
487504
488505 // Prevent space character
489- if ( e . key === ' ' ) {
506+ if ( e . key === " " ) {
490507 e . preventDefault ( ) ;
491508
492509 // Determine if this is the edit form or new form
493- const isEditForm = abbrBox . id === 'edit-abbr-box' ;
494- const inputId = isEditForm ? 'edit-abbr-box' : 'abbr-box' ;
495- const wrapperId = isEditForm ? 'edit-abbr-box-wrapper' : 'abbr-box-wrapper' ;
496- const errorId = isEditForm ? 'edit-abbreviation-space-error' : 'abbreviation-space-error' ;
497-
498- UIHelper . showError (
499- inputId ,
500- wrapperId ,
501- "Space is not accepted as a valid abbreviation character." ,
502- errorId
503- ) ;
510+ const isEditForm = abbrBox . id === "edit-abbr-box" ;
511+ const inputId = isEditForm ? "edit-abbr-box" : "abbr-box" ;
512+ const wrapperId = isEditForm ? "edit-abbr-box-wrapper" : "abbr-box-wrapper" ;
513+ const errorId = isEditForm ? "edit-abbreviation-space-error" : "abbreviation-space-error" ;
514+
515+ UIHelper . showError ( inputId , wrapperId , "Space is not accepted as a valid abbreviation character." , errorId ) ;
504516 return ;
505517 }
506518
507519 // Check for character limit (30 characters) - only for printable characters
508- if ( abbrBox . value . length >= 30 && e . key . length === 1 && e . key . match ( / [ a - z A - Z 0 - 9 ! @ # $ % ^ & * ( ) _ + \- = \[ \] { } ; ' : " \\ | , . < > \/ ? ] / ) ) {
520+ if (
521+ abbrBox . value . length >= 30 &&
522+ e . key . length === 1 &&
523+ e . key . match ( / [ a - z A - Z 0 - 9 ! @ # $ % ^ & * ( ) _ + \- = \[ \] { } ; ' : " \\ | , . < > \/ ? ] / )
524+ ) {
509525 e . preventDefault ( ) ;
510526
511527 // Determine if this is the edit form or new form
512- const isEditForm = abbrBox . id === 'edit-abbr-box' ;
513- const inputId = isEditForm ? 'edit-abbr-box' : 'abbr-box' ;
514- const wrapperId = isEditForm ? 'edit-abbr-box-wrapper' : 'abbr-box-wrapper' ;
515- const errorId = isEditForm ? 'edit-abbreviation-length-error' : 'abbreviation-length-error' ;
516-
517- UIHelper . showError (
518- inputId ,
519- wrapperId ,
520- "Abbreviation cannot be more than 30 characters." ,
521- errorId
522- ) ;
528+ const isEditForm = abbrBox . id === "edit-abbr-box" ;
529+ const inputId = isEditForm ? "edit-abbr-box" : "abbr-box" ;
530+ const wrapperId = isEditForm ? "edit-abbr-box-wrapper" : "abbr-box-wrapper" ;
531+ const errorId = isEditForm ? "edit-abbreviation-length-error" : "abbreviation-length-error" ;
532+
533+ UIHelper . showError ( inputId , wrapperId , "Abbreviation cannot be more than 30 characters." , errorId ) ;
523534 }
524535 }
525536
@@ -575,21 +586,16 @@ define(function (require, exports, module) {
575586
576587 // Show appropriate error message
577588 if ( wasTruncated || hadSpaces ) {
578- const isEditForm = $input . attr ( "id" ) === ' edit-abbr-box' ;
579- const inputId = isEditForm ? ' edit-abbr-box' : ' abbr-box' ;
580- const wrapperId = isEditForm ? ' edit-abbr-box-wrapper' : ' abbr-box-wrapper' ;
589+ const isEditForm = $input . attr ( "id" ) === " edit-abbr-box" ;
590+ const inputId = isEditForm ? " edit-abbr-box" : " abbr-box" ;
591+ const wrapperId = isEditForm ? " edit-abbr-box-wrapper" : " abbr-box-wrapper" ;
581592
582593 // Prioritize length error over space error if both occurred
583594 if ( wasTruncated ) {
584- const errorId = isEditForm ? 'edit-abbreviation-paste-length-error' : 'abbreviation-paste-length-error' ;
585- UIHelper . showError (
586- inputId ,
587- wrapperId ,
588- "Abbreviation cannot be more than 30 characters." ,
589- errorId
590- ) ;
595+ const errorId = isEditForm ? "edit-abbreviation-paste-length-error" : "abbreviation-paste-length-error" ;
596+ UIHelper . showError ( inputId , wrapperId , "Abbreviation cannot be more than 30 characters." , errorId ) ;
591597 } else if ( hadSpaces ) {
592- const errorId = isEditForm ? ' edit-abbreviation-paste-space-error' : ' abbreviation-paste-space-error' ;
598+ const errorId = isEditForm ? " edit-abbreviation-paste-space-error" : " abbreviation-paste-space-error" ;
593599 UIHelper . showError (
594600 inputId ,
595601 wrapperId ,
0 commit comments