@@ -164,22 +164,25 @@ function activateCodeSnippet(
164
164
execute : ( ) => {
165
165
const highlightedCode = getSelectedText ( ) ;
166
166
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
179
181
}
182
+ resultArray . push ( indexedInput [ i ] ) ; //push cell code lines into result
180
183
}
181
184
}
182
- CodeSnippetInputDialog ( codeSnippetWidget , indexedInput , - 1 ) ;
185
+ CodeSnippetInputDialog ( codeSnippetWidget , resultArray , - 1 ) ;
183
186
} else {
184
187
CodeSnippetInputDialog (
185
188
codeSnippetWidget ,
0 commit comments