Skip to content

Commit 27038c4

Browse files
authored
Merge branch 'master' into server_settings
2 parents 635b7b4 + 66bc95f commit 27038c4

9 files changed

+39
-24
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ eggs/
3131
lib/
3232
lib64/
3333
parts/
34-
dist/
3534
sdist/
3635
var/
3736
wheels/
-118 KB
Binary file not shown.
118 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.

docs/getting_started/changelog.rst

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
Changelog
44
---------
5+
6+
v2.0.1
7+
^^^^^^
8+
* Fixed the issue with creating the snippet from scratch or editing the snippet in the editor.
9+
510
v2.0.0
611
^^^^^^
712
* Fixed the issue with the keyboard shortcut by making it user-configurable.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jupyterlab-code-snippets",
3-
"version": "2.0.0",
3+
"version": "2.0.1",
44
"description": "EXPERIMENTAL: Save, reuse, and share code snippets using JupyterLab Code Snippets",
55
"keywords": [
66
"jupyter",

src/CodeSnippetEditor.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { CodeSnippetService } from './CodeSnippetService';
3232
import { CodeSnippetWidget } from './CodeSnippetWidget';
3333
import { SUPPORTED_LANGUAGES } from './CodeSnippetLanguages';
3434
import { CodeSnippetEditorTags } from './CodeSnippetEditorTags';
35+
import { saveOverWriteFile } from './CodeSnippetInputDialog';
3536

3637
/**
3738
* CSS style classes
@@ -364,14 +365,14 @@ export class CodeSnippetEditor extends ReactWidget {
364365
message += 'Name must be filled out\n';
365366
status = false;
366367
}
367-
if (name.match(/[^a-z0-9_]+/)) {
368+
if (name.match(/[^a-zA-Z0-9_]+/)) {
368369
message += 'Wrong format of the name\n';
369370
status = false;
370371
}
371-
if (description === '') {
372-
message += 'Description must be filled out\n';
373-
status = false;
374-
}
372+
// if (description === '') {
373+
// message += 'Description must be filled out\n';
374+
// status = false;
375+
// }
375376
if (description.match(/[^a-zA-Z0-9_ ,.?!]+/)) {
376377
message += 'Wrong format of the description\n';
377378
status = false;
@@ -579,18 +580,17 @@ export class CodeSnippetEditor extends ReactWidget {
579580
></input>
580581
<p className={CODE_SNIPPET_EDITOR_INPUTNAME_VALIDITY}>
581582
{
582-
'Name of the code snippet MUST be lowercased, alphanumeric or composed of underscore(_)'
583+
'Name of the code snippet MUST be alphanumeric or composed of underscore(_)'
583584
}
584585
</p>
585586
<label className={CODE_SNIPPET_EDITOR_LABEL}>
586-
Description (required)
587+
Description (optional)
587588
</label>
588589
<input
589590
className={CODE_SNIPPET_EDITOR_DESC_INPUT}
590591
defaultValue={this._codeSnippetEditorMetaData.description}
591592
placeholder={'Description'}
592593
type="text"
593-
required
594594
pattern={'[a-zA-Z0-9_ ,.?!]+'}
595595
onMouseDown={(
596596
event: React.MouseEvent<HTMLInputElement, MouseEvent>

src/CodeSnippetInputDialog.ts

+25-14
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,24 @@ export function CodeSnippetInputDialog(
7171
}
7272
}
7373

74+
const body: InputHandler = new InputHandler(tags);
75+
76+
return showInputDialog(tags, idx, codeSnippetWidget, code, body);
77+
}
78+
79+
/**
80+
* This function creates the actual input form and processes the inputs given.
81+
*/
82+
export function showInputDialog(
83+
tags: string[],
84+
idx: number,
85+
codeSnippetWidget: CodeSnippetWidget,
86+
code: string[],
87+
body: InputHandler
88+
): Promise<Contents.IModel | null> {
7489
return showCodeSnippetForm({
7590
title: 'Save Code Snippet',
76-
body: new InputHandler(tags),
77-
// focusNodeSelector: 'input',
91+
body: body,
7892
buttons: [
7993
CodeSnippetForm.cancelButton(),
8094
CodeSnippetForm.okButton({ label: 'Save' })
@@ -87,15 +101,15 @@ export function CodeSnippetInputDialog(
87101
console.log(idx);
88102

89103
if (validateForm(result) === false) {
90-
return CodeSnippetInputDialog(codeSnippetWidget, code, idx); // This works but it wipes out all the data they entered previously...
104+
showInputDialog(tags, idx, codeSnippetWidget, code, body);
91105
} else {
92106
// if (idx === -1) {
93107
// idx = codeSnippetWidget.codeSnippetWidgetModel.snippets.length;
94108
// }
95109

96110
const tags = result.value.slice(3);
97111
const newSnippet: ICodeSnippet = {
98-
name: result.value[0].replace(' ', '').toLowerCase(),
112+
name: result.value[0].replace(' ', ''),
99113
description: result.value[1],
100114
language: result.value[2],
101115
code: code,
@@ -109,7 +123,7 @@ export function CodeSnippetInputDialog(
109123
snippet,
110124
newSnippet
111125
);
112-
126+
console.log('uh reached here');
113127
result
114128
.then(newSnippets => {
115129
codeSnippetWidget.renderCodeSnippetsSignal.emit(newSnippets);
@@ -238,20 +252,18 @@ export function validateForm(
238252
message += 'Name must be filled out\n';
239253
status = false;
240254
}
241-
if (name.match(/[^a-z0-9_]+/)) {
255+
if (name.match(/[^a-zA-Z0-9_]+/)) {
256+
//allow lowercase, uppercase, alphanumeric, and underscore
242257
message += 'Wrong format of the name\n';
243258
status = false;
244259
}
245-
if (description === '') {
246-
message += 'Description must be filled out\n';
247-
status = false;
248-
}
249260
if (description.match(/[^a-zA-Z0-9_ ,.?!]+/)) {
261+
//alphanumeric but can include space or punctuation
250262
message += 'Wrong format of the description\n';
251263
status = false;
252264
}
253265
if (language === '') {
254-
message += 'Language must be filled out';
266+
message += 'Language must be filled out\n';
255267
status = false;
256268
}
257269
if (!SUPPORTED_LANGUAGES.includes(language)) {
@@ -321,7 +333,7 @@ class Private {
321333
const body = document.createElement('form');
322334
const nameValidity = document.createElement('p');
323335
nameValidity.textContent =
324-
'Name of the code snippet MUST be lowercased, alphanumeric, or composed of underscore(_)';
336+
'Name of the code snippet MUST be alphanumeric, or composed of underscore(_)';
325337
nameValidity.className = CODE_SNIPPET_INPUTNAME_VALIDITY;
326338

327339
const descriptionValidity = document.createElement('p');
@@ -338,10 +350,9 @@ class Private {
338350
name.onblur = Private.handleOnBlur;
339351

340352
const descriptionTitle = document.createElement('label');
341-
descriptionTitle.textContent = 'Description (required)';
353+
descriptionTitle.textContent = 'Description (optional)';
342354
const description = document.createElement('input');
343355
description.className = CODE_SNIPPET_DIALOG_INPUT;
344-
description.required = true;
345356
description.pattern = '[a-zA-Z0-9_ ,.?!]+';
346357
description.onblur = Private.handleOnBlur;
347358

0 commit comments

Comments
 (0)