mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 04:49:35 +00:00
* Fix #132143. Softer image update on rerun. * Output raw data update required.
This commit is contained in:
parent
5b8361bc71
commit
7ab8a39a89
|
@ -48,6 +48,14 @@ function renderImage(outputInfo: OutputItem, element: HTMLElement): IDisposable
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (element.firstChild) {
|
||||||
|
const display = element.firstChild as HTMLElement;
|
||||||
|
if (display.firstChild && display.firstChild.nodeName === 'IMG' && display.firstChild instanceof HTMLImageElement) {
|
||||||
|
display.firstChild.src = src;
|
||||||
|
return disposable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const image = document.createElement('img');
|
const image = document.createElement('img');
|
||||||
image.src = src;
|
image.src = src;
|
||||||
const display = document.createElement('div');
|
const display = document.createElement('div');
|
||||||
|
@ -301,6 +309,7 @@ export const activate: ActivationFunction<void> = (ctx) => {
|
||||||
case 'image/jpeg':
|
case 'image/jpeg':
|
||||||
case 'image/git':
|
case 'image/git':
|
||||||
{
|
{
|
||||||
|
disposables.get(outputInfo.id)?.dispose();
|
||||||
const disposable = renderImage(outputInfo, element);
|
const disposable = renderImage(outputInfo, element);
|
||||||
disposables.set(outputInfo.id, disposable);
|
disposables.set(outputInfo.id, disposable);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,13 +25,13 @@ export class NotebookCellOutputTextModel extends Disposable implements ICellOutp
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
readonly _rawOutput: IOutputDto
|
private _rawOutput: IOutputDto
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
replaceData(items: IOutputItemDto[]) {
|
replaceData(rawData: IOutputDto) {
|
||||||
this._rawOutput.outputs = items;
|
this._rawOutput = rawData;
|
||||||
this._onDidChangeData.fire();
|
this._onDidChangeData.fire();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -280,23 +280,25 @@ export class NotebookCellTextModel extends Disposable implements ICell {
|
||||||
}
|
}
|
||||||
|
|
||||||
spliceNotebookCellOutputs(splice: NotebookCellOutputsSplice): void {
|
spliceNotebookCellOutputs(splice: NotebookCellOutputsSplice): void {
|
||||||
this.outputs.splice(splice.start, splice.deleteCount, ...splice.newOutputs);
|
if (splice.deleteCount > 0 && splice.newOutputs.length > 0) {
|
||||||
this._onDidChangeOutputs.fire(splice);
|
const commonLen = Math.min(splice.deleteCount, splice.newOutputs.length);
|
||||||
|
// update
|
||||||
|
for (let i = 0; i < commonLen; i++) {
|
||||||
|
const currentOutput = this.outputs[splice.start + i];
|
||||||
|
const newOutput = splice.newOutputs[i];
|
||||||
|
|
||||||
|
this.replaceOutput(currentOutput.outputId, newOutput);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.outputs.splice(splice.start + commonLen, splice.deleteCount - commonLen, ...splice.newOutputs.slice(commonLen));
|
||||||
|
this._onDidChangeOutputs.fire({ start: splice.start + commonLen, deleteCount: splice.deleteCount - commonLen, newOutputs: splice.newOutputs.slice(commonLen) });
|
||||||
|
} else {
|
||||||
|
this.outputs.splice(splice.start, splice.deleteCount, ...splice.newOutputs);
|
||||||
|
this._onDidChangeOutputs.fire(splice);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
changeOutputItems(outputId: string, append: boolean, items: IOutputItemDto[]): boolean {
|
private _optimizeOutputItems(output: ICellOutput) {
|
||||||
const outputIndex = this.outputs.findIndex(output => output.outputId === outputId);
|
|
||||||
|
|
||||||
if (outputIndex < 0) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const output = this.outputs[outputIndex];
|
|
||||||
if (append) {
|
|
||||||
output.appendData(items);
|
|
||||||
} else {
|
|
||||||
output.replaceData(items);
|
|
||||||
}
|
|
||||||
if (output.outputs.length > 1 && output.outputs.every(item => isTextStreamMime(item.mime))) {
|
if (output.outputs.length > 1 && output.outputs.every(item => isTextStreamMime(item.mime))) {
|
||||||
// Look for the mimes in the items, and keep track of their order.
|
// Look for the mimes in the items, and keep track of their order.
|
||||||
// Merge the streams into one output item, per mime type.
|
// Merge the streams into one output item, per mime type.
|
||||||
|
@ -322,7 +324,37 @@ export class NotebookCellTextModel extends Disposable implements ICell {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
replaceOutput(outputId: string, newOutputItem: ICellOutput) {
|
||||||
|
const outputIndex = this.outputs.findIndex(output => output.outputId === outputId);
|
||||||
|
|
||||||
|
if (outputIndex < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const output = this.outputs[outputIndex];
|
||||||
|
output.replaceData(newOutputItem);
|
||||||
|
this._optimizeOutputItems(output);
|
||||||
|
this._onDidChangeOutputItems.fire();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
changeOutputItems(outputId: string, append: boolean, items: IOutputItemDto[]): boolean {
|
||||||
|
const outputIndex = this.outputs.findIndex(output => output.outputId === outputId);
|
||||||
|
|
||||||
|
if (outputIndex < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const output = this.outputs[outputIndex];
|
||||||
|
if (append) {
|
||||||
|
output.appendData(items);
|
||||||
|
} else {
|
||||||
|
output.replaceData({ outputId: outputId, outputs: items, metadata: output.metadata });
|
||||||
|
}
|
||||||
|
|
||||||
|
this._optimizeOutputItems(output);
|
||||||
this._onDidChangeOutputItems.fire();
|
this._onDidChangeOutputItems.fire();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -205,7 +205,7 @@ export interface ICellOutput {
|
||||||
metadata?: Record<string, any>;
|
metadata?: Record<string, any>;
|
||||||
outputId: string;
|
outputId: string;
|
||||||
onDidChangeData: Event<void>;
|
onDidChangeData: Event<void>;
|
||||||
replaceData(items: IOutputItemDto[]): void;
|
replaceData(items: IOutputDto): void;
|
||||||
appendData(items: IOutputItemDto[]): void;
|
appendData(items: IOutputItemDto[]): void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue