Skip to content

Commit 019ce4a

Browse files
committed
Save on right click working. Invalid char error.
1 parent 00dcd7c commit 019ce4a

File tree

1 file changed

+42
-7
lines changed

1 file changed

+42
-7
lines changed

src/index.ts

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ import {
2222
CodeSnippetEditor,
2323
ICodeSnippetEditorMetadata
2424
} from './CodeSnippetEditor';
25+
import {
26+
/*NotebookPanel,*/
27+
/*NotebookActions,*/
28+
NotebookTracker
29+
} from '@jupyterlab/notebook';
30+
//import { ReadonlyPartialJSONObject } from '@lumino/coreutils';
2531

2632
const CODE_SNIPPET_EXTENSION_ID = 'code-snippet-extension';
2733

@@ -56,9 +62,23 @@ function activateCodeSnippet(
5662
app: JupyterFrontEnd,
5763
palette: ICommandPalette,
5864
restorer: ILayoutRestorer,
59-
editorServices: IEditorServices
65+
editorServices: IEditorServices,
66+
trackerNotebook: NotebookTracker
6067
): void {
6168
console.log('JupyterLab extension code-snippets is activated!');
69+
// const { shell } = app;
70+
71+
// Get the current widget and activate unless the args specify otherwise.
72+
// function getCurrent(args: ReadonlyPartialJSONObject): NotebookPanel | null {
73+
// const widget = trackerNotebook.currentWidget;
74+
// const activate = args['activate'] !== false;
75+
76+
// if (activate && widget) {
77+
// shell.activateById(widget.id);
78+
// }
79+
80+
// return widget;
81+
// }
6282

6383
const getCurrentWidget = (): Widget => {
6484
return app.shell.currentWidget;
@@ -163,12 +183,27 @@ function activateCodeSnippet(
163183
iconClass: 'some-css-icon-class',
164184
execute: () => {
165185
const highlightedCode = getSelectedText();
166-
167-
CodeSnippetInputDialog(
168-
codeSnippetWidget,
169-
highlightedCode.split('\n'),
170-
-1
171-
);
186+
if (highlightedCode === '') {
187+
//let current = getCurrent(args);
188+
const curr = document.getElementsByClassName(
189+
'jp-Cell jp-mod-selected'
190+
)[1];
191+
const text = curr as HTMLElement;
192+
const textContent = text.innerText;
193+
const arrayInput = textContent.split('\n');
194+
const indexedInput = arrayInput.slice(1);
195+
// console.log(textContent);
196+
// for (let i = 0; i < indexedInput.length; i++) {
197+
// console.log(indexedInput[i]);
198+
// }
199+
CodeSnippetInputDialog(codeSnippetWidget, indexedInput, -1);
200+
} else {
201+
CodeSnippetInputDialog(
202+
codeSnippetWidget,
203+
highlightedCode.split('\n'),
204+
-1
205+
);
206+
}
172207
// if highlightedCode is empty, check the code of the entire cell.
173208
}
174209
});

0 commit comments

Comments
 (0)