Skip to content

Commit 144daca

Browse files
authored
Merge pull request #140 from kpinnipa/cell-saving
Multi-cell saving
2 parents 90797d6 + cfad9e5 commit 144daca

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

src/index.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,22 +164,25 @@ function activateCodeSnippet(
164164
execute: () => {
165165
const highlightedCode = getSelectedText();
166166
if (highlightedCode === '') {
167-
//if user just right-clicks the whole cell to save
168-
const curr = document.getElementsByClassName(
169-
'jp-Cell jp-mod-selected'
170-
)[1];
171-
const text = curr as HTMLElement;
172-
const textContent = text.innerText;
173-
const arrayInput = textContent.split('\n');
174-
const indexedInput = arrayInput.slice(1);
175-
for (let i = 0; i < indexedInput.length; i++) {
176-
for (let j = 0; j < indexedInput[i].length; j++) {
177-
if (indexedInput[i].charCodeAt(j) === 8203) {
178-
indexedInput[i] = '';
167+
//if user just right-clicks cell(s) to save
168+
const curr = document.getElementsByClassName('jp-Cell jp-mod-selected');
169+
const resultArray = [];
170+
for (let i = 1; i < curr.length; i++) {
171+
//loop through each cell
172+
const text = curr[i] as HTMLElement;
173+
const textContent = text.innerText;
174+
const arrayInput = textContent.split('\n');
175+
const indexedInput = arrayInput.slice(1);
176+
for (let i = 0; i < indexedInput.length; i++) {
177+
// looping through each line in cell
178+
if (indexedInput[i].charCodeAt(0) === 8203) {
179+
//check if first char in line is invalid
180+
indexedInput[i] = ''; //replace invalid line with empty string
179181
}
182+
resultArray.push(indexedInput[i]); //push cell code lines into result
180183
}
181184
}
182-
CodeSnippetInputDialog(codeSnippetWidget, indexedInput, -1);
185+
CodeSnippetInputDialog(codeSnippetWidget, resultArray, -1);
183186
} else {
184187
CodeSnippetInputDialog(
185188
codeSnippetWidget,

0 commit comments

Comments
 (0)