@@ -57,6 +57,7 @@ export function CodeSnippetInputDialog(
57
57
idx : number
58
58
) : Promise < Contents . IModel | null > {
59
59
const tags : string [ ] = [ ] ;
60
+ const langTags : string [ ] = [ ] ;
60
61
const codeSnippetManager = CodeSnippetService . getCodeSnippetService ( ) ;
61
62
62
63
const snippets = codeSnippetManager . snippets ;
@@ -70,9 +71,12 @@ export function CodeSnippetInputDialog(
70
71
}
71
72
}
72
73
}
74
+ if ( ! langTags . includes ( snippet . language ) ) {
75
+ langTags . push ( snippet . language ) ;
76
+ }
73
77
}
74
78
75
- const body : InputHandler = new InputHandler ( tags , language ) ;
79
+ const body : InputHandler = new InputHandler ( tags , language , langTags ) ;
76
80
77
81
return showInputDialog (
78
82
codeSnippetWidget ,
@@ -262,8 +266,8 @@ class InputHandler extends Widget {
262
266
* Construct a new "code snippet" dialog.
263
267
* readonly inputNode: HTMLInputElement; <--- in Widget class
264
268
*/
265
- constructor ( tags : string [ ] , language : string ) {
266
- super ( { node : Private . createInputNode ( tags , language ) } ) ;
269
+ constructor ( snippetTags : string [ ] , language : string , langTags : string [ ] ) {
270
+ super ( { node : Private . createInputNode ( snippetTags , language , langTags ) } ) ;
267
271
this . addClass ( FILE_DIALOG_CLASS ) ;
268
272
}
269
273
@@ -295,7 +299,8 @@ class MessageHandler extends Widget {
295
299
*/
296
300
class Private {
297
301
static selectedTags : string [ ] = [ ] ;
298
- static allTags : string [ ] ;
302
+ static allSnippetTags : string [ ] ;
303
+ static allLangTags : string [ ] ;
299
304
300
305
static handleOnBlur ( event : Event ) : void {
301
306
const target = event . target as HTMLElement ;
@@ -307,8 +312,13 @@ class Private {
307
312
/**
308
313
* Create the node for a code snippet form handler. This is what's creating all of the elements to be displayed.
309
314
*/
310
- static createInputNode ( tags : string [ ] , language : string ) : HTMLElement {
311
- Private . allTags = tags ;
315
+ static createInputNode (
316
+ snippetTags : string [ ] ,
317
+ language : string ,
318
+ langTags : string [ ]
319
+ ) : HTMLElement {
320
+ Private . allSnippetTags = snippetTags ;
321
+ Private . allLangTags = langTags ;
312
322
const body = document . createElement ( 'form' ) ;
313
323
314
324
const nameTitle = document . createElement ( 'label' ) ;
@@ -347,7 +357,7 @@ class Private {
347
357
348
358
const tagList = document . createElement ( 'li' ) ;
349
359
tagList . classList . add ( CODE_SNIPPET_INPUTTAG_LIST ) ;
350
- for ( const tag of tags ) {
360
+ for ( const tag of snippetTags ) {
351
361
const tagElem = document . createElement ( 'ul' ) ;
352
362
tagElem . className = `${ CODE_SNIPPET_INPUT_TAG } tag unapplied-tag` ;
353
363
const tagBtn = document . createElement ( 'button' ) ;
@@ -412,10 +422,18 @@ class Private {
412
422
413
423
if ( inputElement . value !== '' && event . keyCode === 13 ) {
414
424
// duplicate tag
415
- if ( Private . allTags . includes ( inputElement . value ) ) {
425
+ if ( Private . allSnippetTags . includes ( inputElement . value ) ) {
416
426
alert ( 'Duplicate Tag Name!' ) ;
417
427
return ;
418
428
}
429
+
430
+ if ( Private . allLangTags . includes ( inputElement . value ) ) {
431
+ alert (
432
+ 'This tag already exists in language tags!\nIf you want to create this tag, lowercase the first letter.'
433
+ ) ;
434
+ return ;
435
+ }
436
+
419
437
event . preventDefault ( ) ;
420
438
421
439
// create new tag
@@ -446,7 +464,7 @@ class Private {
446
464
447
465
// add it to the selected tags
448
466
Private . selectedTags . push ( tagBtn . innerText ) ;
449
- Private . allTags . push ( tagBtn . innerText ) ;
467
+ Private . allSnippetTags . push ( tagBtn . innerText ) ;
450
468
451
469
// reset InputElement
452
470
inputElement . blur ( ) ;
0 commit comments