mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 09:08:48 +01:00
don't emit events when splices are empty, fixes https://github.com/microsoft/vscode/issues/119608
This commit is contained in:
committed by
Rob Lourens
parent
5a241c767a
commit
23713de2be
@@ -143,11 +143,12 @@ export class NotebookCellTextModel extends Disposable implements ICell {
|
||||
}
|
||||
|
||||
spliceNotebookCellOutputs(splices: NotebookCellOutputsSplice[]): void {
|
||||
splices.reverse().forEach(splice => {
|
||||
this.outputs.splice(splice[0], splice[1], ...splice[2]);
|
||||
});
|
||||
|
||||
this._onDidChangeOutputs.fire(splices);
|
||||
if (splices.length > 0) {
|
||||
splices.reverse().forEach(splice => {
|
||||
this.outputs.splice(splice[0], splice[1], ...splice[2]);
|
||||
});
|
||||
this._onDidChangeOutputs.fire(splices);
|
||||
}
|
||||
}
|
||||
|
||||
getEvaluatedMetadata(documentMetadata: NotebookDocumentMetadata): NotebookCellMetadata {
|
||||
|
||||
@@ -735,6 +735,9 @@ export class NotebookTextModel extends Disposable implements INotebookTextModel
|
||||
}
|
||||
|
||||
private _spliceNotebookCellOutputs(cellHandle: number, splices: NotebookCellOutputsSplice[], computeUndoRedo: boolean): void {
|
||||
if (splices.length === 0) {
|
||||
return;
|
||||
}
|
||||
const cell = this._mapping.get(cellHandle);
|
||||
if (cell) {
|
||||
cell.spliceNotebookCellOutputs(splices);
|
||||
|
||||
@@ -404,4 +404,74 @@ suite('NotebookTextModel', () => {
|
||||
assert.strictEqual(model.cells[0].outputs.length, 2);
|
||||
});
|
||||
});
|
||||
|
||||
test('Clearing output of an empty notebook makes it dirty #119608', function () {
|
||||
withTestNotebook([
|
||||
['var a = 1;', 'javascript', CellKind.Code, [], { editable: true }],
|
||||
['var b = 2;', 'javascript', CellKind.Code, [], { editable: true }]
|
||||
], (editor) => {
|
||||
const model = editor.viewModel.notebookDocument;
|
||||
|
||||
let event: NotebookTextModelChangedEvent | undefined;
|
||||
|
||||
model.onDidChangeContent(e => { event = e; });
|
||||
|
||||
{
|
||||
// 1: add ouput -> event
|
||||
const success = model.applyEdits(
|
||||
[{
|
||||
editType: CellEditType.Output, index: 0, outputs: [
|
||||
{ outputId: 'out1', outputs: [{ mime: 'application/x.notebook.stream', value: 1 }] }
|
||||
],
|
||||
append: false
|
||||
}], true, undefined, () => undefined, undefined, false
|
||||
);
|
||||
|
||||
assert.ok(success);
|
||||
assert.strictEqual(model.cells[0].outputs.length, 1);
|
||||
assert.ok(event);
|
||||
}
|
||||
|
||||
{
|
||||
// 2: clear all output w/ output -> event
|
||||
event = undefined;
|
||||
const success = model.applyEdits(
|
||||
[{
|
||||
editType: CellEditType.Output,
|
||||
index: 0,
|
||||
outputs: [],
|
||||
append: false
|
||||
}, {
|
||||
editType: CellEditType.Output,
|
||||
index: 1,
|
||||
outputs: [],
|
||||
append: false
|
||||
}], true, undefined, () => undefined, undefined, false
|
||||
);
|
||||
assert.ok(success);
|
||||
assert.ok(event);
|
||||
}
|
||||
|
||||
{
|
||||
// 2: clear all output wo/ output -> NO event
|
||||
event = undefined;
|
||||
const success = model.applyEdits(
|
||||
[{
|
||||
editType: CellEditType.Output,
|
||||
index: 0,
|
||||
outputs: [],
|
||||
append: false
|
||||
}, {
|
||||
editType: CellEditType.Output,
|
||||
index: 1,
|
||||
outputs: [],
|
||||
append: false
|
||||
}], true, undefined, () => undefined, undefined, false
|
||||
);
|
||||
|
||||
assert.ok(success);
|
||||
assert.ok(event === undefined);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user