Skip to content

Commit cb0d23a

Browse files
committed
Fixed error with editor staying open. Uppercase added, dialog changed for rename in new snippet editor.
1 parent d4f774a commit cb0d23a

File tree

1 file changed

+16
-31
lines changed

1 file changed

+16
-31
lines changed

src/CodeSnippetEditor.tsx

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ export class CodeSnippetEditor extends ReactWidget {
414414
const newPath =
415415
'snippets/' + this._codeSnippetEditorMetaData.name + '.json';
416416

417-
//const oldPath = 'snippets/' + this.oldCodeSnippetName + '.json';
417+
let nameCheck = false;
418418

419419
if (!this._codeSnippetEditorMetaData.fromScratch) {
420420
const oldPath = 'snippets/' + this.oldCodeSnippetName + '.json';
@@ -424,27 +424,21 @@ export class CodeSnippetEditor extends ReactWidget {
424424
try {
425425
await this.contentsService.rename(oldPath, newPath);
426426
} catch (error) {
427-
console.log('tffff');
428427
await showDialog({
429428
title: 'Duplicate Name of Code Snippet',
430429
body: <p> {`"${newPath}" already exists.`} </p>,
431430
buttons: [Dialog.okButton({ label: 'Dismiss' })]
432431
});
433432
return false;
434433
}
435-
console.log('huhhh');
436434
// set new name as an old name
437435
this.oldCodeSnippetName = this._codeSnippetEditorMetaData.name;
438436
}
439437
} else {
440-
let nameCheck = false;
441438
await this.contentsService
442439
.getData(newPath, 'file')
443440
.then(async (value: Contents.IModel) => {
444441
if (value.name) {
445-
console.log(
446-
this.codeSnippetWidget.codeSnippetWidgetModel.snippets[37]
447-
);
448442
const oldSnippet: ICodeSnippet = JSON.parse(value.content);
449443
const newSnippet: ICodeSnippet = {
450444
name: this._codeSnippetEditorMetaData.name,
@@ -454,18 +448,12 @@ export class CodeSnippetEditor extends ReactWidget {
454448
id: this._codeSnippetEditorMetaData.id,
455449
tags: this._codeSnippetEditorMetaData.selectedTags
456450
};
457-
console.log(oldSnippet.id);
458-
// await showDialog({
459-
// title: 'Duplicate Name of Code Snippet',
460-
// body: <p> {`"${newPath}" already exists.`} </p>,
461-
// buttons: [Dialog.okButton({ label: 'Dismiss' })]
462-
// });
463451
const result = saveOverWriteFile(
464452
this.codeSnippetWidget.codeSnippetWidgetModel,
465453
oldSnippet,
466454
newSnippet
467455
);
468-
result
456+
await result
469457
.then(newSnippets => {
470458
this.codeSnippetWidget.renderCodeSnippetsSignal.emit(
471459
newSnippets
@@ -480,28 +468,25 @@ export class CodeSnippetEditor extends ReactWidget {
480468
})
481469
.catch(() => {
482470
nameCheck = true;
483-
console.log('hi');
484471
});
485-
if (!nameCheck) {
486-
console.log('gdi');
487-
return false;
488-
}
489472
}
490473

491474
this.saved = true;
492475

493-
await this.contentsService.save(newPath, {
494-
type: 'file',
495-
format: 'text',
496-
content: JSON.stringify({
497-
name: this._codeSnippetEditorMetaData.name,
498-
description: this._codeSnippetEditorMetaData.description,
499-
language: this._codeSnippetEditorMetaData.language,
500-
code: this._codeSnippetEditorMetaData.code,
501-
id: this._codeSnippetEditorMetaData.id,
502-
tags: this._codeSnippetEditorMetaData.selectedTags
503-
})
504-
});
476+
if (nameCheck) {
477+
await this.contentsService.save(newPath, {
478+
type: 'file',
479+
format: 'text',
480+
content: JSON.stringify({
481+
name: this._codeSnippetEditorMetaData.name,
482+
description: this._codeSnippetEditorMetaData.description,
483+
language: this._codeSnippetEditorMetaData.language,
484+
code: this._codeSnippetEditorMetaData.code,
485+
id: this._codeSnippetEditorMetaData.id,
486+
tags: this._codeSnippetEditorMetaData.selectedTags
487+
})
488+
});
489+
}
505490

506491
// remove the dirty state
507492
this.title.className = this.title.className.replace(

0 commit comments

Comments
 (0)