Skip to content

Commit 46df174

Browse files
author
minjk-bl
committed
Edit insert cell codes for lab4.x
1 parent 3ef773e commit 46df174

File tree

1 file changed

+69
-28
lines changed

1 file changed

+69
-28
lines changed

visualpython/js/com/com_interface.js

Lines changed: 69 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,23 @@ define([
122122
var notebook = notebookPanel.content;
123123
var notebookModel = notebook.model;
124124

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, {});
129127
// 셀 추가
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);
132142

133143
if (exec == true) {
134144
try{
@@ -147,16 +157,17 @@ define([
147157
// add # before the lines
148158
command = '#' + command.split('\n').join('\n#');
149159
}
150-
160+
161+
// LAB 4.x: console insert and run
162+
widget.promptCell.model.sharedModel.setSource(command)
151163
// execute or not
152164
if (exec == true) {
153165
// 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()
160171
}
161172
widget.promptCell.inputArea.editor.focus();
162173
}
@@ -263,15 +274,24 @@ define([
263274
var notebookModel = notebook.model;
264275

265276
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);
270279
// 셀 추가
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+
275295
if (exec == true) {
276296
try{
277297
NotebookActions.run(notebook, sessionContext);
@@ -280,9 +300,27 @@ define([
280300
}
281301
}
282302
} 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+
}
286324
}
287325
} else {
288326
// No session found
@@ -299,10 +337,13 @@ define([
299337

300338
} else if (vpConfig.extensionType === 'lab' || vpConfig.extensionType === 'lite') {
301339
// 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+
}
306347
}
307348

308349
com_util.renderSuccessMessage('Your code is successfully generated.');

0 commit comments

Comments
 (0)