Skip to content

Update CodeMirror to stable version via jupyterlab update. #209

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 3 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/CodeSnippetDisplay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,8 @@ export class CodeSnippetDisplay extends React.Component<
if (target.innerHTML !== new_element.value) {
const newName = new_element.value;

const isDuplicateName = this.props.codeSnippetManager.duplicateNameExists(
newName
);
const isDuplicateName =
this.props.codeSnippetManager.duplicateNameExists(newName);

if (isDuplicateName) {
await showDialog({
Expand Down Expand Up @@ -605,8 +604,8 @@ export class CodeSnippetDisplay extends React.Component<
'--jp-content-font-color3'
);

(this._dragData.dragImage
.children[0] as HTMLElement).style.color = dragImageTextColor;
(this._dragData.dragImage.children[0] as HTMLElement).style.color =
dragImageTextColor;

// add CSS style
this._dragData.dragImage.classList.add(SNIPPET_DRAG_IMAGE);
Expand Down Expand Up @@ -1498,7 +1497,8 @@ export class CodeSnippetDisplay extends React.Component<
if (value.button.accept) {
const dirs = value.value.split('/');

const codeSnippetContentsManager = CodeSnippetContentsService.getInstance();
const codeSnippetContentsManager =
CodeSnippetContentsService.getInstance();

let path = '';
for (let i = 0; i < dirs.length; i++) {
Expand Down
83 changes: 50 additions & 33 deletions src/CodeSnippetEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ export class CodeSnippetEditor extends ReactWidget {
document.getElementById('code-' + this._codeSnippetEditorMetaData.id)
) {
const editorFactory = this.editorServices.factoryService.newInlineEditor;
const getMimeTypeByLanguage = this.editorServices.mimeTypeService
.getMimeTypeByLanguage;
const getMimeTypeByLanguage =
this.editorServices.mimeTypeService.getMimeTypeByLanguage;

this.editor = editorFactory({
host: document.getElementById(
Expand Down Expand Up @@ -257,15 +257,21 @@ export class CodeSnippetEditor extends ReactWidget {
this.dispose();
super.onCloseRequest(msg);
} else if (response.button.label === 'Save') {
const name = (document.querySelector(
`.${CODE_SNIPPET_EDITOR}-${this._codeSnippetEditorMetaData.id} .${CODE_SNIPPET_EDITOR_NAME_INPUT}`
) as HTMLInputElement).value;
const description = (document.querySelector(
`.${CODE_SNIPPET_EDITOR}-${this._codeSnippetEditorMetaData.id} .${CODE_SNIPPET_EDITOR_DESC_INPUT}`
) as HTMLInputElement).value;
const language = (document.querySelector(
`.${CODE_SNIPPET_EDITOR}-${this._codeSnippetEditorMetaData.id} .${CODE_SNIPPET_EDITOR_LANG_INPUT}`
) as HTMLSelectElement).value;
const name = (
document.querySelector(
`.${CODE_SNIPPET_EDITOR}-${this._codeSnippetEditorMetaData.id} .${CODE_SNIPPET_EDITOR_NAME_INPUT}`
) as HTMLInputElement
).value;
const description = (
document.querySelector(
`.${CODE_SNIPPET_EDITOR}-${this._codeSnippetEditorMetaData.id} .${CODE_SNIPPET_EDITOR_DESC_INPUT}`
) as HTMLInputElement
).value;
const language = (
document.querySelector(
`.${CODE_SNIPPET_EDITOR}-${this._codeSnippetEditorMetaData.id} .${CODE_SNIPPET_EDITOR_LANG_INPUT}`
) as HTMLSelectElement
).value;

const validity = validateInputs(name, description, language);
if (validity) {
Expand Down Expand Up @@ -333,15 +339,21 @@ export class CodeSnippetEditor extends ReactWidget {
}

saveChange(event: React.MouseEvent<HTMLElement, MouseEvent>): void {
const name = (document.querySelector(
`.${CODE_SNIPPET_EDITOR}-${this._codeSnippetEditorMetaData.id} .${CODE_SNIPPET_EDITOR_NAME_INPUT}`
) as HTMLInputElement).value;
const description = (document.querySelector(
`.${CODE_SNIPPET_EDITOR}-${this._codeSnippetEditorMetaData.id} .${CODE_SNIPPET_EDITOR_DESC_INPUT}`
) as HTMLInputElement).value;
const language = (document.querySelector(
`.${CODE_SNIPPET_EDITOR}-${this._codeSnippetEditorMetaData.id} .${CODE_SNIPPET_EDITOR_LANG_INPUT}`
) as HTMLSelectElement).value;
const name = (
document.querySelector(
`.${CODE_SNIPPET_EDITOR}-${this._codeSnippetEditorMetaData.id} .${CODE_SNIPPET_EDITOR_NAME_INPUT}`
) as HTMLInputElement
).value;
const description = (
document.querySelector(
`.${CODE_SNIPPET_EDITOR}-${this._codeSnippetEditorMetaData.id} .${CODE_SNIPPET_EDITOR_DESC_INPUT}`
) as HTMLInputElement
).value;
const language = (
document.querySelector(
`.${CODE_SNIPPET_EDITOR}-${this._codeSnippetEditorMetaData.id} .${CODE_SNIPPET_EDITOR_LANG_INPUT}`
) as HTMLSelectElement
).value;

const validity = validateInputs(name, description, language);
if (validity) {
Expand All @@ -350,15 +362,21 @@ export class CodeSnippetEditor extends ReactWidget {
}

async updateSnippet(): Promise<boolean> {
const name = (document.querySelector(
`.${CODE_SNIPPET_EDITOR}-${this._codeSnippetEditorMetaData.id} .${CODE_SNIPPET_EDITOR_NAME_INPUT}`
) as HTMLInputElement).value;
const description = (document.querySelector(
`.${CODE_SNIPPET_EDITOR}-${this._codeSnippetEditorMetaData.id} .${CODE_SNIPPET_EDITOR_DESC_INPUT}`
) as HTMLInputElement).value;
const language = (document.querySelector(
`.${CODE_SNIPPET_EDITOR}-${this._codeSnippetEditorMetaData.id} .${CODE_SNIPPET_EDITOR_LANG_INPUT}`
) as HTMLSelectElement).value;
const name = (
document.querySelector(
`.${CODE_SNIPPET_EDITOR}-${this._codeSnippetEditorMetaData.id} .${CODE_SNIPPET_EDITOR_NAME_INPUT}`
) as HTMLInputElement
).value;
const description = (
document.querySelector(
`.${CODE_SNIPPET_EDITOR}-${this._codeSnippetEditorMetaData.id} .${CODE_SNIPPET_EDITOR_DESC_INPUT}`
) as HTMLInputElement
).value;
const language = (
document.querySelector(
`.${CODE_SNIPPET_EDITOR}-${this._codeSnippetEditorMetaData.id} .${CODE_SNIPPET_EDITOR_LANG_INPUT}`
) as HTMLSelectElement
).value;

this._codeSnippetEditorMetaData.name = name;
this._codeSnippetEditorMetaData.description = description;
Expand Down Expand Up @@ -409,11 +427,10 @@ export class CodeSnippetEditor extends ReactWidget {
).then((res: boolean) => {
if (res) {
// get the id of snippet you are editting
const removedSnippet = this.contentsService.getSnippet(
oldName
)[0];
const removedSnippet =
this.contentsService.getSnippet(oldName)[0];

// delete the one you are editting
// delete the one you are editing
this.contentsService.deleteSnippet(removedSnippet.id);
} else {
return false;
Expand Down
25 changes: 15 additions & 10 deletions src/CodeSnippetInputDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const FILE_DIALOG_CLASS = 'jp-codeSnippet-fileDialog';
/**
* CSS STYLING
*/
// const CODE_SNIPPET_DIALOG_INPUT = 'jp-codeSnippet-dialog-input';
const CODE_SNIPPET_DIALOG_NAME_INPUT = 'jp-codeSnippet-dialog-name-input';
const CODE_SNIPPET_DIALOG_DESC_INPUT = 'jp-codeSnippet-dialog-desc-input';
const CODE_SNIPPET_DIALOG_LANG_INPUT = 'jp-codeSnippet-dialog-lang-input';
Expand Down Expand Up @@ -242,15 +241,21 @@ class InputHandler extends Widget {
getValue(): string[] {
const inputs = [];
inputs.push(
(this.node.querySelector(
`.${CODE_SNIPPET_DIALOG_NAME_INPUT}`
) as HTMLInputElement).value,
(this.node.querySelector(
`.${CODE_SNIPPET_DIALOG_DESC_INPUT}`
) as HTMLInputElement).value,
(this.node.querySelector(
`.${CODE_SNIPPET_DIALOG_LANG_INPUT}`
) as HTMLInputElement).value
(
this.node.querySelector(
`.${CODE_SNIPPET_DIALOG_NAME_INPUT}`
) as HTMLInputElement
).value,
(
this.node.querySelector(
`.${CODE_SNIPPET_DIALOG_DESC_INPUT}`
) as HTMLInputElement
).value,
(
this.node.querySelector(
`.${CODE_SNIPPET_DIALOG_LANG_INPUT}`
) as HTMLInputElement
).value
);

inputs.push(...Private.selectedTags);
Expand Down
6 changes: 3 additions & 3 deletions src/CodeSnippetPreview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ArrayExt } from '@lumino/algorithm';
import { ICodeSnippet, CodeSnippetService } from './CodeSnippetService';

/**
* The class name for preview box
* The class name for preview box.
*/
const PREVIEW_CLASS = 'jp-codeSnippet-preview';
const PREVIEW_CONTENT = 'jp-codeSnippet-preview-content';
Expand Down Expand Up @@ -156,8 +156,8 @@ export class Preview<T> extends Widget {

if (!this.editor && document.getElementById(PREVIEW_CONTENT + this._id)) {
const editorFactory = this.editorServices.factoryService.newInlineEditor;
const getMimeTypeByLanguage = this.editorServices.mimeTypeService
.getMimeTypeByLanguage;
const getMimeTypeByLanguage =
this.editorServices.mimeTypeService.getMimeTypeByLanguage;

let previewFontSize = this.codeSnippetService.settings.get(
'snippetPreviewFontSize'
Expand Down
20 changes: 10 additions & 10 deletions src/CodeSnippetService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface ICodeSnippet {
name: string;
description: string;
language: string;
// code separated by new line
// code separated by a new line
code: string[];
id: number;
tags?: string[];
Expand All @@ -29,7 +29,7 @@ export class CodeSnippetService {
if (
!JSONExt.deepEqual(
newCodeSnippetList,
(this.codeSnippetList as unknown) as PartialJSONValue
this.codeSnippetList as unknown as PartialJSONValue
)
) {
this.codeSnippetList = this.convertToICodeSnippetList(
Expand All @@ -55,7 +55,7 @@ export class CodeSnippetService {
if (this.settingManager.get('snippets').user === undefined) {
// set the user setting + default in the beginning
this.settingManager
.set('snippets', (defaultSnippets as unknown) as PartialJSONValue)
.set('snippets', defaultSnippets as unknown as PartialJSONValue)
.then(() => {
const userSnippets = this.convertToICodeSnippetList(
this.settingManager.get('snippets').user as JSONArray
Expand All @@ -82,7 +82,7 @@ export class CodeSnippetService {
const snippetList: ICodeSnippet[] = [];

snippets.forEach((snippet) => {
snippetList.push((snippet as unknown) as ICodeSnippet);
snippetList.push(snippet as unknown as ICodeSnippet);
});
return snippetList;
}
Expand Down Expand Up @@ -124,7 +124,7 @@ export class CodeSnippetService {
}

await this.settingManager
.set('snippets', (this.codeSnippetList as unknown) as PartialJSONValue)
.set('snippets', this.codeSnippetList as unknown as PartialJSONValue)
.catch((_) => {
return false;
});
Expand Down Expand Up @@ -152,7 +152,7 @@ export class CodeSnippetService {
}

await this.settingManager
.set('snippets', (this.codeSnippetList as unknown) as PartialJSONValue)
.set('snippets', this.codeSnippetList as unknown as PartialJSONValue)
.catch((_) => {
return false;
});
Expand All @@ -168,7 +168,7 @@ export class CodeSnippetService {
}
}
await this.settingManager
.set('snippets', (this.codeSnippetList as unknown) as PartialJSONValue)
.set('snippets', this.codeSnippetList as unknown as PartialJSONValue)
.catch((_) => {
return false;
});
Expand Down Expand Up @@ -196,7 +196,7 @@ export class CodeSnippetService {
}

await this.settingManager
.set('snippets', (this.codeSnippetList as unknown) as PartialJSONValue)
.set('snippets', this.codeSnippetList as unknown as PartialJSONValue)
.catch((_) => {
return false;
});
Expand Down Expand Up @@ -228,7 +228,7 @@ export class CodeSnippetService {
});

await this.settingManager
.set('snippets', (this.codeSnippetList as unknown) as PartialJSONValue)
.set('snippets', this.codeSnippetList as unknown as PartialJSONValue)
.catch((_) => {
return false;
});
Expand All @@ -245,7 +245,7 @@ export class CodeSnippetService {
this.codeSnippetList.forEach((snippet, i) => (snippet.id = i));

await this.settingManager
.set('snippets', (this.codeSnippetList as unknown) as PartialJSONValue)
.set('snippets', this.codeSnippetList as unknown as PartialJSONValue)
.catch((_) => {
return false;
});
Expand Down
4 changes: 2 additions & 2 deletions src/CodeSnippetWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,8 @@ export class CodeSnippetWidget extends ReactWidget {
this.moveCodeSnippet(srcIdx, idx);
}
} else {
const notebook: Notebook = event.mimeData.getData('internal:cells')[0]
.parent;
const notebook: Notebook =
event.mimeData.getData('internal:cells')[0].parent;

const language = notebook.model.defaultKernelLanguage;
// Handle the case where we are copying cells
Expand Down
Loading