Skip to content

Commit 7b5a16b

Browse files
committed
adjustable output height
1 parent d3351f8 commit 7b5a16b

File tree

4 files changed

+48
-28
lines changed

4 files changed

+48
-28
lines changed

extensions/notebook-renderers/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export const activate: ActivationFunction<void> = (ctx) => {
234234
}
235235
span.output-stream.scrollable {
236236
overflow-y: scroll;
237-
max-height: 400px;
237+
max-height: var(--notebook-cell-output-max-height);
238238
}
239239
span.output-stream.more-above {
240240
box-shadow: var(--vscode-scrollbar-shadow) 0 6px 6px -6px inset

extensions/notebook-renderers/src/textHelper.ts

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,35 @@
55

66
import { handleANSIOutput } from './ansi';
77

8-
function generateViewMoreElement(outputId: string) {
8+
function generateViewMoreElement(outputId: string, adjustableSize: boolean) {
99
const container = document.createElement('span');
1010
const first = document.createElement('span');
11-
first.textContent = 'Output exceeds the ';
12-
const second = document.createElement('a');
13-
second.textContent = 'size limit';
14-
second.href = `command:workbench.action.openSettings?%5B%22notebook.output.textLineLimit%22%5D`;
11+
12+
if (adjustableSize) {
13+
first.textContent = 'Output exceeds the ';
14+
const second = document.createElement('a');
15+
second.textContent = 'size limit';
16+
second.href = `command:workbench.action.openSettings?%5B%22notebook.output.textLineLimit%22%5D`;
17+
container.appendChild(first);
18+
container.appendChild(second);
19+
} else {
20+
first.textContent = 'Output exceeds the maximium size limit';
21+
container.appendChild(first);
22+
}
23+
1524
const third = document.createElement('span');
16-
third.textContent = '. Enable scrolling in the settings, or open the full output data ';
25+
third.textContent = '. Open the full output data ';
1726
const forth = document.createElement('a');
1827
forth.textContent = 'in a text editor';
1928
forth.href = `command:workbench.action.openLargeOutput?${outputId}`;
20-
container.appendChild(first);
21-
container.appendChild(second);
2229
container.appendChild(third);
2330
container.appendChild(forth);
2431
return container;
2532
}
2633

27-
export function truncatedArrayOfString(id: string, outputs: string[], linesLimit: number, container: HTMLElement) {
28-
const buffer = outputs.join('\n').split(/\r\n|\r|\n/g);
34+
export function truncatedArrayOfString(id: string, buffer: string[], linesLimit: number, container: HTMLElement) {
2935
const lineCount = buffer.length;
30-
31-
if (lineCount < linesLimit) {
32-
const spanElement = handleANSIOutput(buffer.slice(0, linesLimit).join('\n'));
33-
container.appendChild(spanElement);
34-
return;
35-
}
36-
37-
container.appendChild(generateViewMoreElement(id));
36+
container.appendChild(generateViewMoreElement(id, true));
3837

3938
const div = document.createElement('div');
4039
container.appendChild(div);
@@ -50,9 +49,11 @@ export function truncatedArrayOfString(id: string, outputs: string[], linesLimit
5049
div2.appendChild(handleANSIOutput(buffer.slice(lineCount - 5).join('\n')));
5150
}
5251

53-
function scrollableArrayOfString(outputs: string[], container: HTMLElement) {
52+
function scrollableArrayOfString(id: string, buffer: string[], container: HTMLElement) {
5453
container.classList.add('scrollable');
54+
container.classList.add('more-below');
5555

56+
// disposable?
5657
container.onscroll = (e) => {
5758
const target = e.target as HTMLElement;
5859
if (target.scrollTop === 0) {
@@ -68,15 +69,27 @@ function scrollableArrayOfString(outputs: string[], container: HTMLElement) {
6869
}
6970
};
7071

71-
const buffer = outputs.join('\n').split(/\r\n|\r|\n/g);
72-
const spanElement = handleANSIOutput(buffer.slice(0, 5000).join('\n'));
73-
container.appendChild(spanElement);
72+
if (buffer.length > 5000) {
73+
container.appendChild(generateViewMoreElement(id, false));
74+
}
75+
const div = document.createElement('div');
76+
container.appendChild(div);
77+
div.appendChild(handleANSIOutput(buffer.slice(0, 5000).join('\n')));
7478
}
7579

7680
export function insertOutput(id: string, outputs: string[], linesLimit: number, scrollable: boolean, container: HTMLElement) {
81+
const buffer = outputs.join('\n').split(/\r\n|\r|\n/g);
82+
const lineCount = buffer.length;
83+
84+
if (lineCount < linesLimit) {
85+
const spanElement = handleANSIOutput(buffer.join('\n'));
86+
container.appendChild(spanElement);
87+
return;
88+
}
89+
7790
if (scrollable) {
78-
scrollableArrayOfString(outputs, container);
91+
scrollableArrayOfString(id, buffer, container);
7992
} else {
80-
truncatedArrayOfString(id, outputs, linesLimit, container);
93+
truncatedArrayOfString(id, buffer, linesLimit, container);
8194
}
8295
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { NOTEBOOK_WEBVIEW_BOUNDARY } from 'vs/workbench/contrib/notebook/browser
3838
import { preloadsScriptStr } from 'vs/workbench/contrib/notebook/browser/view/renderers/webviewPreloads';
3939
import { transformWebviewThemeVars } from 'vs/workbench/contrib/notebook/browser/view/renderers/webviewThemeMapping';
4040
import { MarkupCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/markupCellViewModel';
41-
import { CellUri, INotebookRendererInfo, NotebookSetting, RendererMessagingSpec } from 'vs/workbench/contrib/notebook/common/notebookCommon';
41+
import { CellUri, INotebookRendererInfo, RendererMessagingSpec } from 'vs/workbench/contrib/notebook/common/notebookCommon';
4242
import { INotebookKernel } from 'vs/workbench/contrib/notebook/common/notebookKernelService';
4343
import { IScopedRendererMessaging } from 'vs/workbench/contrib/notebook/common/notebookRendererMessagingService';
4444
import { INotebookService } from 'vs/workbench/contrib/notebook/common/notebookService';
@@ -98,6 +98,7 @@ interface BacklayerWebviewOptions {
9898
readonly markupFontSize: number;
9999
readonly outputLineHeight: number;
100100
readonly outputScrolling: boolean;
101+
readonly outputLineLimit: number;
101102
}
102103

103104
export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
@@ -228,6 +229,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
228229
'notebook-markup-font-size': typeof this.options.markupFontSize === 'number' && this.options.markupFontSize > 0 ? `${this.options.markupFontSize}px` : `calc(${this.options.fontSize}px * 1.2)`,
229230
'notebook-cell-output-font-size': `${this.options.outputFontSize || this.options.fontSize}px`,
230231
'notebook-cell-output-line-height': `${this.options.outputLineHeight}px`,
232+
'notebook-cell-output-max-height': `${this.options.outputLineHeight * this.options.outputLineLimit}px`,
231233
'notebook-cell-output-font-family': this.options.outputFontFamily || this.options.fontFamily,
232234
'notebook-cell-markup-empty-content': nls.localize('notebook.emptyMarkdownPlaceholder', "Empty markdown cell, double click or press enter to edit."),
233235
'notebook-cell-renderer-not-found-error': nls.localize({
@@ -241,7 +243,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
241243
const renderersData = this.getRendererData();
242244
const preloadsData = this.getStaticPreloadsData();
243245
const renderOptions = {
244-
lineLimit: this.configurationService.getValue<number>(NotebookSetting.textOutputLineLimit) ?? 30,
246+
lineLimit: this.options.outputLineLimit,
245247
outputScrolling: this.options.outputScrolling
246248
};
247249
const preloadScript = preloadsScriptStr(

src/vs/workbench/contrib/notebook/common/notebookOptions.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ export interface NotebookLayoutConfiguration {
7171
focusIndicatorGap: number;
7272
interactiveWindowCollapseCodeCells: InteractiveWindowCollapseCodeCells;
7373
outputScrolling: boolean;
74+
outputLineLimit: number;
7475
}
7576

7677
export interface NotebookOptionsChangeEvent {
@@ -149,6 +150,7 @@ export class NotebookOptions extends Disposable {
149150
const interactiveWindowCollapseCodeCells: InteractiveWindowCollapseCodeCells = this.configurationService.getValue(NotebookSetting.interactiveWindowCollapseCodeCells);
150151
const outputLineHeight = this._computeOutputLineHeight();
151152
const outputScrolling = this.configurationService.getValue<boolean>(NotebookSetting.outputScrolling);
153+
const outputLineLimit = this.configurationService.getValue<number>(NotebookSetting.textOutputLineLimit) ?? 30;
152154

153155
this._layoutConfiguration = {
154156
...(compactView ? compactConfigConstants : defaultConfigConstants),
@@ -186,7 +188,8 @@ export class NotebookOptions extends Disposable {
186188
focusIndicatorGap: 3,
187189
interactiveWindowCollapseCodeCells,
188190
markdownFoldHintHeight: 22,
189-
outputScrolling: outputScrolling
191+
outputScrolling: outputScrolling,
192+
outputLineLimit: outputLineLimit
190193
};
191194

192195
this._register(this.configurationService.onDidChangeConfiguration(e => {
@@ -570,6 +573,7 @@ export class NotebookOptions extends Disposable {
570573
markupFontSize: this._layoutConfiguration.markupFontSize,
571574
outputLineHeight: this._layoutConfiguration.outputLineHeight,
572575
outputScrolling: this._layoutConfiguration.outputScrolling,
576+
outputLineLimit: this._layoutConfiguration.outputLineLimit,
573577
};
574578
}
575579

@@ -589,6 +593,7 @@ export class NotebookOptions extends Disposable {
589593
markupFontSize: this._layoutConfiguration.markupFontSize,
590594
outputLineHeight: this._layoutConfiguration.outputLineHeight,
591595
outputScrolling: this._layoutConfiguration.outputScrolling,
596+
outputLineLimit: this._layoutConfiguration.outputLineLimit,
592597
};
593598
}
594599

0 commit comments

Comments
 (0)