Created
January 10, 2023 16:53
-
-
Save agoose77/50ab1f18f1d32958720addccb2dbe7b7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"allowCDN": "awaiting-decision", | |
"requirejsCDN": "https://cdn.jsdelivr.net/npm/", | |
"urls": [], | |
"showIconInLauncher": true, | |
"plugins": [ | |
"import {\n JupyterFrontEnd,\n JupyterFrontEndPlugin,\n} from \'@jupyterlab/application\';\nimport { ITranslator, nullTranslator } from \'@jupyterlab/translation\';\nimport { FileEditor, IEditorTracker } from \'@jupyterlab/fileeditor\';\nimport { Notebook, INotebookTracker } from \'@jupyterlab/notebook\';\nimport { ICommandPalette } from \'@jupyterlab/apputils\'\n\n/**\n * This is an example hello world plugin.\n * Open Command Palette with Ctrl+Shift+C\n * (Command+Shift+C on Mac) and select\n * \"Load Current File as Extension\"\n */\nnamespace CommandIDs {\n export const toggleComment = \'codemirror:toggle-comment\';\n}\n\n\nfunction toggleNotebook(widget: Notebook) {\n const cell = widget.content.activeCell;\n if (cell?.model.type !== \'code\') {\n return;\n }\n\n const editor = cell.editor as CodeMirrorEditor;\n editor.editor.toggleComment({ indent: true });\n}\n\n\nfunction toggleEditor(widget: FileEditor) {\n const editor = widget.content.editor as CodeMirrorEditor;\n editor.editor.toggleComment({ indent: true });\n}\n\n\nconst plugin: JupyterFrontEndPlugin<void> = {\n id: \'codemirror-toggle-comment:plugin\',\n autoStart: true,\n optional: [ITranslator, ICommandPalette, INotebookTracker, IEditorTracker],\n activate: (\n app: JupyterFrontEnd, \n translator?: ITranslator | null,\n palette?: ICommandPalette | null,\n notebookTracker?: INotebookTracker | null\n editorTracker?: INEditorTracker | null\n ) => {\n console.log(\"ACTIVATE\", translator);\n const trans = (translator ?? nullTranslator).load(\'jupyterlab\');\n app.commands.addCommand(CommandIDs.toggleComment, {\n label: trans.__(\'Toggle Comment\'),\n caption: \'Comment/uncomment the current buffer\',\n execute: () => {\n const widget = app.shell.currentWidget;\n if (widget == null) {\n return;\n }\n if (widget === notebookTracker.currentWidget) {\n return toggleNotebook(widget as Notebook);\n } else if (widget === editorTracker.currentWidget) {\n return toggleEditor(widget as FileEditor);\n \n }\n \n });\n if (!!palette){\n palette.addItem({\n command: CommandIDs.toggleComment,\n category: \'Codemirror\',\n args: {}\n })\n }\n },\n};\n\n\nexport default plugin;" | |
], | |
"toolbar": [ | |
{ | |
"args": {}, | |
"command": "codemirror:toggle-comment", | |
"disabled": false, | |
"rank": 50, | |
"name": "Toggle Comment" | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment