Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add min height to cell outputs #14488

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export async function outputWebviewPreload(ctx: PreloadContext): Promise<void> {
}

calcTotalOutputHeight(): number {
return this.outputElements.reduce((acc, output) => acc + output.element.clientHeight, 0) + 5;
return this.outputElements.reduce((acc, output) => acc + output.element.getBoundingClientRect().height, 0) + 5;
}

createOutputElement(index: number, output: webviewCommunication.Output, items: rendererApi.OutputItem[]): OutputContainer {
Expand Down Expand Up @@ -216,9 +216,11 @@ export async function outputWebviewPreload(ctx: PreloadContext): Promise<void> {
public outputVisibilityChanged(visible: boolean): void {
this.outputElements.forEach(output => {
output.element.style.display = visible ? 'initial' : 'none';
output.containerElement.style.minHeight = visible ? '20px' : '0px';
});
if (visible) {
this.element.getElementsByClassName('output-hidden')?.[0].remove();
window.requestAnimationFrame(() => this.outputElements.forEach(output => sendDidRenderMessage(this, output)));
} else {
const outputHiddenElement = document.createElement('div');
outputHiddenElement.classList.add('output-hidden');
Expand Down Expand Up @@ -290,6 +292,7 @@ export async function outputWebviewPreload(ctx: PreloadContext): Promise<void> {
private createHtmlElement(): void {
this.containerElement = document.createElement('div');
this.containerElement.classList.add('output-container');
this.containerElement.style.minHeight = '20px';
this.element = document.createElement('div');
this.element.id = this.outputId;
this.element.classList.add('output');
Expand Down Expand Up @@ -489,26 +492,16 @@ export async function outputWebviewPreload(ctx: PreloadContext): Promise<void> {
img.dataset.waiting = 'true'; // mark to avoid overriding onload a second time
return new Promise(resolve => { img.onload = img.onerror = resolve; });
})).then(() => {
this.sendDidRenderMessage(cell, output);
new ResizeObserver(() => this.sendDidRenderMessage(cell, output)).observe(cell.element);
sendDidRenderMessage(cell, output);
new ResizeObserver(() => sendDidRenderMessage(cell, output)).observe(cell.element);
});
} else {
this.sendDidRenderMessage(cell, output);
new ResizeObserver(() => this.sendDidRenderMessage(cell, output)).observe(cell.element);
sendDidRenderMessage(cell, output);
new ResizeObserver(() => sendDidRenderMessage(cell, output)).observe(cell.element);
}

}

private sendDidRenderMessage(cell: OutputCell, output: OutputContainer): void {
theia.postMessage(<webviewCommunication.OnDidRenderOutput>{
type: 'didRenderOutput',
cellHandle: cell.cellHandle,
outputId: output.outputId,
outputHeight: cell.calcTotalOutputHeight(),
bodyHeight: document.body.clientHeight
});
}

private async doRender(item: rendererApi.OutputItem, element: HTMLElement, renderer: Renderer, signal: AbortSignal): Promise<{ continue: boolean }> {
try {
await (await renderer.getOrLoad())?.renderOutputItem(item, element, signal);
Expand Down Expand Up @@ -565,6 +558,16 @@ export async function outputWebviewPreload(ctx: PreloadContext): Promise<void> {
}
}();

function sendDidRenderMessage(cell: OutputCell, output: OutputContainer): void {
theia.postMessage(<webviewCommunication.OnDidRenderOutput>{
type: 'didRenderOutput',
cellHandle: cell.cellHandle,
outputId: output.outputId,
outputHeight: cell.calcTotalOutputHeight(),
bodyHeight: document.body.clientHeight
});
}

const kernelPreloads = new class {
private readonly preloads = new Map<string /* uri */, Promise<unknown>>();

Expand Down
Loading