@@ -122,13 +122,23 @@ define([
122
122
var notebook = notebookPanel . content ;
123
123
var notebookModel = notebook . model ;
124
124
125
- var cellModel = notebookModel . contentFactory . createCell ( type , { } ) ;
126
- cellModel . value . text = command ;
127
-
128
- const newCellIndex = notebook . activeCellIndex + 1 ;
125
+ // LAB 4.x: notebookPanel.content.contentFactory.createCodeCell / createMarkdownCell
126
+ // var cellModel = notebookModel.contentFactory.createCell(type, {});
129
127
// 셀 추가
130
- notebookModel . cells . insert ( newCellIndex , cellModel ) ;
131
- notebook . activeCellIndex = newCellIndex ;
128
+ // LAB 4.x: insert cell api 변경
129
+ // notebookModel.cells.insert(newCellIndex, cellModel);
130
+ // notebook.activeCellIndex = newCellIndex;
131
+ NotebookActions . insertBelow ( notebook ) ;
132
+ try {
133
+ NotebookActions . changeCellType ( notebook , type ) ;
134
+ } catch ( err ) {
135
+ vpLog . display ( VP_LOG_TYPE . ERROR , err ) ;
136
+ }
137
+ // let activeCellIndex = notebook.activeCellIndex;
138
+ // let cell = notebookModel.cells.model.getCell(activeCellIndex);
139
+ // cell.setSource(command);
140
+ let activeCell = notebook . activeCell ;
141
+ activeCell . model . sharedModel . setSource ( command ) ;
132
142
133
143
if ( exec == true ) {
134
144
try {
@@ -147,16 +157,17 @@ define([
147
157
// add # before the lines
148
158
command = '#' + command . split ( '\n' ) . join ( '\n#' ) ;
149
159
}
150
-
160
+
161
+ // LAB 4.x: console insert and run
162
+ widget . promptCell . model . sharedModel . setSource ( command )
151
163
// execute or not
152
164
if ( exec == true ) {
153
165
// console allow only code cell
154
- var cellModel = widget . createCodeCell ( ) ;
155
- cellModel . model . value . text = command ;
156
- widget . addCell ( cellModel ) ;
157
- widget . _execute ( cellModel ) ;
158
- } else {
159
- widget . promptCell . model . value . text = command ;
166
+ // var cellModel = widget.createCodeCell();
167
+ // cellModel.model.value.text = command;
168
+ // widget.addCell(cellModel);
169
+ // widget._execute(cellModel);
170
+ widget . execute ( )
160
171
}
161
172
widget . promptCell . inputArea . editor . focus ( ) ;
162
173
}
@@ -263,15 +274,24 @@ define([
263
274
var notebookModel = notebook . model ;
264
275
265
276
var options = { } ;
266
- var cellModel = notebookModel . contentFactory . createCell ( type , options ) ;
267
- cellModel . value . text = command ;
268
-
269
- const newCellIndex = notebook . activeCellIndex + 1 ;
277
+ // LAB 4.x: notebookPanel.content.contentFactory.createCodeCell / createMarkdownCell
278
+ // var cellModel = notebookModel.contentFactory.createCell(type, options);
270
279
// 셀 추가
271
- notebookModel . cells . insert ( newCellIndex , cellModel ) ;
272
- notebook . activeCellIndex = newCellIndex ;
273
-
274
- var cell = notebook . activeCell ;
280
+ // LAB 4.x: insert cell api 변경
281
+ // notebookModel.cells.insert(newCellIndex, cellModel);
282
+ // notebook.activeCellIndex = newCellIndex;
283
+ NotebookActions . insertBelow ( notebook ) ;
284
+ try {
285
+ NotebookActions . changeCellType ( notebook , type ) ;
286
+ } catch ( err ) {
287
+ vpLog . display ( VP_LOG_TYPE . ERROR , err ) ;
288
+ }
289
+ // let activeCellIndex = notebook.activeCellIndex;
290
+ // let cell = notebookModel.cells.model.getCell(activeCellIndex);
291
+ // cell.setSource(command);
292
+ let activeCell = notebook . activeCell ;
293
+ activeCell . model . sharedModel . setSource ( command ) ;
294
+
275
295
if ( exec == true ) {
276
296
try {
277
297
NotebookActions . run ( notebook , sessionContext ) ;
@@ -280,9 +300,27 @@ define([
280
300
}
281
301
}
282
302
} else if ( sessionType === 'console' ) {
283
- var console = notebookPanel . content ;
284
- var cellModel = console . contentFactory . createCell ( type , { } ) ;
285
- cellModel . value . text = command ;
303
+ // LAB 4.x: notebookPanel.console.contentFactory.createCodeCell
304
+ // var console = notebookPanel.content;
305
+ // var cellModel = console.contentFactory.createCell(type, {});
306
+ var labConsole = notebookPanel . content ;
307
+ var widget = labConsole . widgets [ 0 ] ;
308
+ if ( type === 'markdown' ) {
309
+ // add # before the lines
310
+ command = '#' + command . split ( '\n' ) . join ( '\n#' ) ;
311
+ }
312
+
313
+ // LAB 4.x: console insert and run
314
+ widget . promptCell . model . sharedModel . setSource ( command )
315
+ // execute or not
316
+ if ( exec == true ) {
317
+ // console allow only code cell
318
+ // var cellModel = widget.createCodeCell();
319
+ // cellModel.model.value.text = command;
320
+ // widget.addCell(cellModel);
321
+ // widget._execute(cellModel);
322
+ widget . execute ( )
323
+ }
286
324
}
287
325
} else {
288
326
// No session found
@@ -299,10 +337,13 @@ define([
299
337
300
338
} else if ( vpConfig . extensionType === 'lab' || vpConfig . extensionType === 'lite' ) {
301
339
// LAB: TODO:
302
- let activeCell = notebookPanel . content . activeCell ;
303
- let activeCellTop = $ ( activeCell . node ) . position ( ) . top ;
304
- // scroll to current cell
305
- $ ( vpKernel . getLabNotebookPanel ( ) . content . activeCell . node ) [ 0 ] . scrollIntoView ( true ) ;
340
+ let sessionType = notebookPanel . sessionContext . type ;
341
+ if ( sessionType === 'notebook' ) {
342
+ let activeCell = notebookPanel . content . activeCell ;
343
+ let activeCellTop = $ ( activeCell . node ) . position ( ) . top ;
344
+ // scroll to current cell
345
+ $ ( notebookPanel . content . activeCell . node ) [ 0 ] . scrollIntoView ( true ) ;
346
+ }
306
347
}
307
348
308
349
com_util . renderSuccessMessage ( 'Your code is successfully generated.' ) ;
0 commit comments