Skip to content

Commit 7cc2231

Browse files
committed
Set language from kernel as a default language in inputDialog
1 parent 5e6beb8 commit 7cc2231

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/CodeSnippetInputDialog.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ export interface IFileContainer extends JSONObject {
5353
export function CodeSnippetInputDialog(
5454
codeSnippetWidget: CodeSnippetWidget,
5555
code: string[],
56+
language: string,
5657
idx: number
5758
): Promise<Contents.IModel | null> {
5859
const tags: string[] = [];
5960
const codeSnippetManager = CodeSnippetService.getCodeSnippetService();
6061

6162
const snippets = codeSnippetManager.snippets;
6263

64+
// get all active tags
6365
for (const snippet of snippets) {
6466
if (snippet.tags) {
6567
for (const tag of snippet.tags) {
@@ -70,14 +72,15 @@ export function CodeSnippetInputDialog(
7072
}
7173
}
7274

73-
const body: InputHandler = new InputHandler(tags);
75+
const body: InputHandler = new InputHandler(tags, language);
7476

7577
return showInputDialog(
7678
codeSnippetWidget,
7779
tags,
7880
idx,
7981
codeSnippetManager,
8082
code,
83+
language,
8184
body
8285
);
8386
}
@@ -91,6 +94,7 @@ export function showInputDialog(
9194
idx: number,
9295
codeSnippetManager: CodeSnippetService,
9396
code: string[],
97+
language: string,
9498
body: InputHandler
9599
): Promise<Contents.IModel | null> {
96100
return showCodeSnippetForm({
@@ -112,6 +116,7 @@ export function showInputDialog(
112116
idx,
113117
codeSnippetManager,
114118
code,
119+
language,
115120
body
116121
);
117122
} else {
@@ -255,8 +260,8 @@ class InputHandler extends Widget {
255260
* Construct a new "code snippet" dialog.
256261
* readonly inputNode: HTMLInputElement; <--- in Widget class
257262
*/
258-
constructor(tags: string[]) {
259-
super({ node: Private.createInputNode(tags) });
263+
constructor(tags: string[], language: string) {
264+
super({ node: Private.createInputNode(tags, language) });
260265
this.addClass(FILE_DIALOG_CLASS);
261266
}
262267

@@ -300,7 +305,7 @@ class Private {
300305
/**
301306
* Create the node for a code snippet form handler. This is what's creating all of the elements to be displayed.
302307
*/
303-
static createInputNode(tags: string[]): HTMLElement {
308+
static createInputNode(tags: string[], language: string): HTMLElement {
304309
Private.allTags = tags;
305310
const body = document.createElement('form');
306311

@@ -324,15 +329,17 @@ class Private {
324329
const languageInput = document.createElement('input');
325330
languageInput.className = CODE_SNIPPET_DIALOG_INPUT;
326331
languageInput.setAttribute('list', 'languages');
332+
// capitalize the first character
333+
languageInput.value = language[0].toUpperCase() + language.slice(1);
327334
languageInput.required = true;
328335
const languageOption = document.createElement('datalist');
329336
languageOption.id = 'languages';
330337
languageOption.onblur = Private.handleOnBlur;
331338

332339
SUPPORTED_LANGUAGES.sort();
333-
for (const language of SUPPORTED_LANGUAGES) {
340+
for (const supportedLanguage of SUPPORTED_LANGUAGES) {
334341
const option = document.createElement('option');
335-
option.value = language;
342+
option.value = supportedLanguage;
336343
languageOption.appendChild(option);
337344
}
338345

0 commit comments

Comments
 (0)