Skip to content

Commit 08a8355

Browse files
committed
Fix #97547. absolute position for notebook outputs.
1 parent 3c97285 commit 08a8355

File tree

5 files changed

+47
-15
lines changed

5 files changed

+47
-15
lines changed

src/vs/workbench/contrib/notebook/browser/media/notebook.css

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,9 @@
112112
}
113113

114114
.monaco-workbench .notebookOverlay .output {
115-
padding-left: 8px;
116-
padding-right: 8px;
115+
position: absolute;
116+
height: 0px;
117+
width: 100%;
117118
user-select: text;
118119
transform: translate3d(0px, 0px, 0px);
119120
cursor: auto;
@@ -127,6 +128,13 @@
127128
}
128129

129130
.monaco-workbench .notebookOverlay .output > div.foreground {
131+
width: 100%;
132+
min-height: 24px;
133+
box-sizing: border-box;
134+
}
135+
136+
.monaco-workbench .notebookOverlay .output > div.foreground > .output-inner-container {
137+
width: 100%;
130138
padding: 8px;
131139
box-sizing: border-box;
132140
}
@@ -144,7 +152,7 @@
144152
.monaco-workbench .notebookOverlay .output .multi-mimetype-output {
145153
position: absolute;
146154
top: 4px;
147-
left: -34px;
155+
left: -26px;
148156
width: 16px;
149157
height: 16px;
150158
cursor: pointer;

src/vs/workbench/contrib/notebook/browser/notebookEditorWidget.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,7 @@ registerThemingParticipant((theme, collector) => {
13521352
const containerBackground = theme.getColor(notebookOutputContainerColor);
13531353
if (containerBackground) {
13541354
collector.addRule(`.notebookOverlay .output { background-color: ${containerBackground}; }`);
1355+
collector.addRule(`.notebookOverlay .output-element { background-color: ${containerBackground}; }`);
13551356
}
13561357

13571358
const editorBackgroundColor = theme.getColor(editorBackground);

src/vs/workbench/contrib/notebook/browser/view/renderers/cellRenderer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,8 +1043,10 @@ export class CodeCellRenderer extends AbstractCellRenderer implements IListRende
10431043
elementDisposables.add(new CellContextKeyManager(templateData.contextKeyService, this.notebookEditor.viewModel?.notebookDocument!, element));
10441044

10451045
templateData.focusIndicator.style.height = `${element.layoutInfo.indicatorHeight}px`;
1046+
templateData.outputContainer.style.top = `${element.layoutInfo.outputContainerOffset}px`;
10461047
elementDisposables.add(element.onDidChangeLayout(() => {
10471048
templateData.focusIndicator.style.height = `${element.layoutInfo.indicatorHeight}px`;
1049+
templateData.outputContainer.style.top = `${element.layoutInfo.outputContainerOffset}px`;
10481050
}));
10491051

10501052
this.updateForMetadata(element, templateData);

src/vs/workbench/contrib/notebook/browser/view/renderers/codeCell.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,17 @@ export class CodeCell extends Disposable {
200200
}
201201
}));
202202

203+
this._register(viewCell.onDidChangeLayout(() => {
204+
this.outputElements.forEach((value, key) => {
205+
const index = viewCell.outputs.indexOf(key);
206+
if (index >= 0) {
207+
const top = this.viewCell.getOutputOffsetInContainer(index);
208+
value.style.top = `${top}px`;
209+
}
210+
});
211+
212+
}));
213+
203214
const updateFocusMode = () => viewCell.focusMode = templateData.editor!.hasWidgetFocus() ? CellFocusMode.Editor : CellFocusMode.Container;
204215
this._register(templateData.editor!.onDidFocusEditorWidget(() => {
205216
updateFocusMode();
@@ -311,15 +322,21 @@ export class CodeCell extends Disposable {
311322
}
312323
let pickedMimeTypeRenderer = currOutput.orderedMimeTypes![currOutput.pickedMimeTypeIndex!];
313324

325+
const innerContainer = DOM.$('.output-inner-container');
326+
DOM.append(outputItemDiv, innerContainer);
327+
314328
if (pickedMimeTypeRenderer.isResolved) {
315329
// html
316-
result = this.notebookEditor.getOutputRenderer().render({ outputKind: CellOutputKind.Rich, data: { 'text/html': pickedMimeTypeRenderer.output! } } as any, outputItemDiv, 'text/html');
330+
result = this.notebookEditor.getOutputRenderer().render({ outputKind: CellOutputKind.Rich, data: { 'text/html': pickedMimeTypeRenderer.output! } } as any, innerContainer, 'text/html');
317331
} else {
318-
result = this.notebookEditor.getOutputRenderer().render(currOutput, outputItemDiv, pickedMimeTypeRenderer.mimeType);
332+
result = this.notebookEditor.getOutputRenderer().render(currOutput, innerContainer, pickedMimeTypeRenderer.mimeType);
319333
}
320334
} else {
321335
// for text and error, there is no mimetype
322-
result = this.notebookEditor.getOutputRenderer().render(currOutput, outputItemDiv, undefined);
336+
const innerContainer = DOM.$('.output-inner-container');
337+
DOM.append(outputItemDiv, innerContainer);
338+
339+
result = this.notebookEditor.getOutputRenderer().render(currOutput, innerContainer, undefined);
323340
}
324341

325342
if (!result) {
@@ -340,6 +357,8 @@ export class CodeCell extends Disposable {
340357
this.notebookEditor.createInset(this.viewCell, currOutput, result.shadowContent, this.viewCell.getOutputOffset(index));
341358
} else {
342359
DOM.addClass(outputItemDiv, 'foreground');
360+
DOM.addClass(outputItemDiv, 'output-element');
361+
outputItemDiv.style.position = 'absolute';
343362
}
344363

345364
let hasDynamicHeight = result.hasDynamicHeight;
@@ -352,10 +371,9 @@ export class CodeCell extends Disposable {
352371
};
353372
const elementSizeObserver = getResizesObserver(outputItemDiv, dimension, () => {
354373
if (this.templateData.outputContainer && document.body.contains(this.templateData.outputContainer!)) {
355-
let height = elementSizeObserver.getHeight() + 8 * 2; // include padding
374+
let height = Math.ceil(elementSizeObserver.getHeight());
356375

357376
if (clientHeight === height) {
358-
// console.log(this.viewCell.outputs);
359377
return;
360378
}
361379

@@ -375,13 +393,13 @@ export class CodeCell extends Disposable {
375393
if (result.shadowContent) {
376394
// webview
377395
// noop
378-
// let cachedHeight = this.viewCell.getOutputHeight(currOutput);
379396
} else {
380397
// static output
381-
382-
// @TODO@rebornix, if we stop checking output height, we need to evaluate it later when checking the height of output container
383-
let clientHeight = outputItemDiv.clientHeight;
398+
let clientHeight = Math.ceil(outputItemDiv.clientHeight);
384399
this.viewCell.updateOutputHeight(index, clientHeight);
400+
401+
const top = this.viewCell.getOutputOffsetInContainer(index);
402+
outputItemDiv.style.top = `${top}px`;
385403
}
386404
}
387405
}

src/vs/workbench/contrib/notebook/browser/viewModel/codeCellViewModel.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,18 @@ export class CodeCellViewModel extends BaseCellViewModel implements ICellViewMod
201201
this.layoutChange({ outputHeight: true });
202202
}
203203

204-
getOutputOffset(index: number): number {
204+
getOutputOffsetInContainer(index: number) {
205205
this._ensureOutputsTop();
206206

207207
if (index >= this._outputCollection.length) {
208208
throw new Error('Output index out of range!');
209209
}
210210

211-
const offset = this._outputsTop!.getAccumulatedValue(index - 1);
212-
return this.layoutInfo.outputContainerOffset + offset;
211+
return this._outputsTop!.getAccumulatedValue(index - 1);
212+
}
213+
214+
getOutputOffset(index: number): number {
215+
return this.layoutInfo.outputContainerOffset + this.getOutputOffsetInContainer(index);
213216
}
214217

215218
spliceOutputHeights(start: number, deleteCnt: number, heights: number[]) {

0 commit comments

Comments
 (0)