Notebooks: Fix Grids Not Rendering when Unsaved Notebook Reloaded (#12483) (#12498)

* Clear Output and fix output change

* Fix tests after forced clear + append output
This commit is contained in:
Chris LaFreniere
2020-09-18 20:14:45 -07:00
committed by GitHub
parent 99e11d2e22
commit cc6d84e7f6
3 changed files with 25 additions and 21 deletions

View File

@@ -129,28 +129,31 @@ export class NotebookTextFileModel {
} }
public transformAndApplyEditForOutputUpdate(contentChange: NotebookContentChange, textEditorModel: ITextEditorModel): boolean { public transformAndApplyEditForOutputUpdate(contentChange: NotebookContentChange, textEditorModel: ITextEditorModel): boolean {
this.transformAndApplyEditForClearOutput(contentChange, textEditorModel);
if (Array.isArray(contentChange.cells[0].outputs) && contentChange.cells[0].outputs.length > 0) { if (Array.isArray(contentChange.cells[0].outputs) && contentChange.cells[0].outputs.length > 0) {
let newOutput = JSON.stringify(contentChange.cells[0].outputs[contentChange.cells[0].outputs.length - 1], undefined, ' '); for (let i = 0; i < contentChange.cells[0].outputs.length; i++) {
if (contentChange.cells[0].outputs.length > 1) { let newOutput = JSON.stringify(contentChange.cells[0].outputs[i], undefined, ' ');
newOutput = ', '.concat(newOutput); if (i > 0) {
} else { newOutput = ', '.concat(newOutput);
newOutput = '\n'.concat(newOutput).concat('\n'); } else {
} newOutput = '\n'.concat(newOutput).concat('\n');
}
// Execution count will always be after the end of the outputs in JSON. This is a sanity mechanism. // Execution count will always be after the end of the outputs in JSON. This is a sanity mechanism.
let executionCountMatch = this.getExecutionCountRange(textEditorModel, contentChange.cells[0].cellGuid); let executionCountMatch = this.getExecutionCountRange(textEditorModel, contentChange.cells[0].cellGuid);
if (!executionCountMatch || !executionCountMatch.range) { if (!executionCountMatch || !executionCountMatch.range) {
return false; return false;
} }
let endOutputsRange = this.getEndOfOutputs(textEditorModel, contentChange.cells[0].cellGuid); let endOutputsRange = this.getEndOfOutputs(textEditorModel, contentChange.cells[0].cellGuid);
if (endOutputsRange && endOutputsRange.startLineNumber < executionCountMatch.range.startLineNumber) { if (endOutputsRange && endOutputsRange.startLineNumber < executionCountMatch.range.startLineNumber) {
textEditorModel.textEditorModel.applyEdits([{ textEditorModel.textEditorModel.applyEdits([{
range: new Range(endOutputsRange.startLineNumber, endOutputsRange.startColumn, endOutputsRange.startLineNumber, endOutputsRange.startColumn), range: new Range(endOutputsRange.startLineNumber, endOutputsRange.startColumn, endOutputsRange.startLineNumber, endOutputsRange.startColumn),
text: newOutput text: newOutput
}]); }]);
return true; }
} }
return true;
} }
return false; return false;
} }

View File

@@ -392,6 +392,7 @@ export class DataResourceDataProvider implements IGridDataProvider {
let rows = await this._queryRunner.getQueryRows(i, numRows, this._batchId, this._id); let rows = await this._queryRunner.getQueryRows(i, numRows, this._batchId, this._id);
this.convertData(rows); this.convertData(rows);
} }
this.cellModel.sendChangeToNotebook(NotebookChangeType.CellOutputUpdated);
} }
private convertData(rows: ResultSetSubset): void { private convertData(rows: ResultSetSubset): void {

View File

@@ -693,9 +693,9 @@ suite('Notebook Editor Model', function (): void {
assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(8), ' "source": ['); assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(8), ' "source": [');
assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(12), ' "azdata_cell_guid": "' + newCell.cellGuid + '"'); assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(12), ' "azdata_cell_guid": "' + newCell.cellGuid + '"');
assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(14), ' "outputs": ['); assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(14), ' "outputs": [');
assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(23), ' }, {'); assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(23), '}, {');
assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(31), '}'); assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(31), '}');
assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(32), ' ],'); assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(32), '],');
assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(33), ' "execution_count": null'); assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(33), ' "execution_count": null');
assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(34), ' }'); assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(34), ' }');
@@ -734,7 +734,7 @@ suite('Notebook Editor Model', function (): void {
assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(14), ' "outputs": ['); assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(14), ' "outputs": [');
assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(26), ' "text": "[0em"'); assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(26), ' "text": "[0em"');
assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(27), '}'); assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(27), '}');
assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(28), ' ],'); assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(28), '],');
assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(29), ' "execution_count": null'); assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(29), ' "execution_count": null');
assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(30), ' }'); assert.equal(notebookEditorModel.editorModel.textEditorModel.getLineContent(30), ' }');