Skip to content

Commit d7c8a6c

Browse files
committed
css change to scroll output
1 parent a9f0251 commit d7c8a6c

File tree

5 files changed

+35
-10
lines changed

5 files changed

+35
-10
lines changed

extensions/notebook-renderers/src/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import type { ActivationFunction, OutputItem, RendererContext } from 'vscode-notebook-renderer';
7-
import { truncatedArrayOfString } from './textHelper';
7+
import { insertOutput, truncatedArrayOfString } from './textHelper';
88

99
interface IDisposable {
1010
dispose(): void;
@@ -153,7 +153,7 @@ function renderError(outputInfo: OutputItem, container: HTMLElement, ctx: Render
153153
container.classList.add('error');
154154
}
155155

156-
function renderStream(outputInfo: OutputItem, container: HTMLElement, error: boolean, ctx: RendererContext<void> & { readonly settings: { readonly lineLimit: number } }): void {
156+
function renderStream(outputInfo: OutputItem, container: HTMLElement, error: boolean, ctx: RendererContext<void> & { readonly settings: { readonly lineLimit: number; readonly outputScrolling: boolean } }): void {
157157
const outputContainer = container.parentElement;
158158
if (!outputContainer) {
159159
// should never happen
@@ -170,7 +170,7 @@ function renderStream(outputInfo: OutputItem, container: HTMLElement, error: boo
170170
const text = outputInfo.text();
171171

172172
const element = document.createElement('span');
173-
truncatedArrayOfString(outputInfo.id, [text], ctx.settings.lineLimit, element);
173+
insertOutput(outputInfo.id, [text], ctx.settings.lineLimit, true, element);
174174
outputElement.appendChild(element);
175175
return;
176176
}
@@ -180,7 +180,7 @@ function renderStream(outputInfo: OutputItem, container: HTMLElement, error: boo
180180
element.classList.add('output-stream');
181181

182182
const text = outputInfo.text();
183-
truncatedArrayOfString(outputInfo.id, [text], ctx.settings.lineLimit, element);
183+
insertOutput(outputInfo.id, [text], ctx.settings.lineLimit, true, element);
184184
while (container.firstChild) {
185185
container.removeChild(container.firstChild);
186186
}
@@ -205,7 +205,7 @@ export const activate: ActivationFunction<void> = (ctx) => {
205205
const htmlHooks = new Set<HtmlRenderingHook>();
206206
const jsHooks = new Set<JavaScriptRenderingHook>();
207207

208-
const latestContext = ctx as (RendererContext<void> & { readonly settings: { readonly lineLimit: number } });
208+
const latestContext = ctx as (RendererContext<void> & { readonly settings: { readonly lineLimit: number; readonly outputScrolling: boolean } });
209209

210210
const style = document.createElement('style');
211211
style.textContent = `
@@ -225,6 +225,9 @@ export const activate: ActivationFunction<void> = (ctx) => {
225225
}
226226
span.output-stream {
227227
display: inline-block;
228+
width: 100%;
229+
overflow-y: var(--notebook-output-overflow-y);
230+
max-height: 500px;
228231
}
229232
.output-plaintext .code-bold,
230233
.output-stream .code-bold,

extensions/notebook-renderers/src/textHelper.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ function generateViewMoreElement(outputId: string) {
1313
second.textContent = 'size limit';
1414
second.href = `command:workbench.action.openSettings?%5B%22notebook.output.textLineLimit%22%5D`;
1515
const third = document.createElement('span');
16-
third.textContent = '. Open the full output data';
16+
third.textContent = '. Enable scrolling in the settings, or open the full output data ';
1717
const forth = document.createElement('a');
18-
forth.textContent = ' in a text editor';
18+
forth.textContent = 'in a text editor';
1919
forth.href = `command:workbench.action.openLargeOutput?${outputId}`;
2020
container.appendChild(first);
2121
container.appendChild(second);
@@ -49,3 +49,17 @@ export function truncatedArrayOfString(id: string, outputs: string[], linesLimit
4949
container.appendChild(div2);
5050
div2.appendChild(handleANSIOutput(buffer.slice(lineCount - 5).join('\n')));
5151
}
52+
53+
function scrollableArrayOfString(outputs: string[], container: HTMLElement) {
54+
const buffer = outputs.join('\n').split(/\r\n|\r|\n/g);
55+
const spanElement = handleANSIOutput(buffer.slice(0, 5000).join('\n'));
56+
container.appendChild(spanElement);
57+
}
58+
59+
export function insertOutput(id: string, outputs: string[], linesLimit: number, scrollable: boolean, container: HTMLElement) {
60+
if (scrollable) {
61+
scrollableArrayOfString(outputs, container);
62+
} else {
63+
truncatedArrayOfString(id, outputs, linesLimit, container);
64+
}
65+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ interface BacklayerWebviewOptions {
9797
readonly outputFontFamily: string;
9898
readonly markupFontSize: number;
9999
readonly outputLineHeight: number;
100+
readonly outputScrolling: boolean;
100101
}
101102

102103
export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
@@ -233,6 +234,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
233234
key: 'notebook.error.rendererNotFound',
234235
comment: ['$0 is a placeholder for the mime type']
235236
}, "No renderer found for '$0' a"),
237+
'notebook-output-overflow-y': this.options.outputScrolling ? 'scroll' : 'visible',
236238
};
237239
}
238240

@@ -241,7 +243,7 @@ export class BackLayerWebView<T extends ICommonCellInfo> extends Themable {
241243
const preloadsData = this.getStaticPreloadsData();
242244
const preloadScript = preloadsScriptStr(
243245
this.options,
244-
{ dragAndDropEnabled: this.options.dragAndDropEnabled },
246+
{ dragAndDropEnabled: this.options.dragAndDropEnabled }, // add other options
245247
renderersData,
246248
preloadsData,
247249
this.workspaceTrustManagementService.isWorkspaceTrusted(),

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,8 @@ export const NotebookSetting = {
926926
outputLineHeight: 'notebook.outputLineHeight',
927927
outputFontSize: 'notebook.outputFontSize',
928928
outputFontFamily: 'notebook.outputFontFamily',
929-
kernelPickerType: 'notebook.kernelPicker.type'
929+
kernelPickerMRU: 'notebook.experimental.kernelPicker.mru',
930+
outputScrolling: 'notebook.outputScrolling',
930931
} as const;
931932

932933
export const enum CellStatusbarAlignment {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export interface NotebookLayoutConfiguration {
7070
editorOptionsCustomizations: any | undefined;
7171
focusIndicatorGap: number;
7272
interactiveWindowCollapseCodeCells: InteractiveWindowCollapseCodeCells;
73+
outputScrolling: boolean;
7374
}
7475

7576
export interface NotebookOptionsChangeEvent {
@@ -147,6 +148,7 @@ export class NotebookOptions extends Disposable {
147148
const editorOptionsCustomizations = this.configurationService.getValue(NotebookSetting.cellEditorOptionsCustomizations);
148149
const interactiveWindowCollapseCodeCells: InteractiveWindowCollapseCodeCells = this.configurationService.getValue(NotebookSetting.interactiveWindowCollapseCodeCells);
149150
const outputLineHeight = this._computeOutputLineHeight();
151+
const outputScrolling = this.configurationService.getValue<boolean>(NotebookSetting.outputScrolling);
150152

151153
this._layoutConfiguration = {
152154
...(compactView ? compactConfigConstants : defaultConfigConstants),
@@ -183,7 +185,8 @@ export class NotebookOptions extends Disposable {
183185
editorOptionsCustomizations,
184186
focusIndicatorGap: 3,
185187
interactiveWindowCollapseCodeCells,
186-
markdownFoldHintHeight: 22
188+
markdownFoldHintHeight: 22,
189+
outputScrolling: outputScrolling
187190
};
188191

189192
this._register(this.configurationService.onDidChangeConfiguration(e => {
@@ -566,6 +569,7 @@ export class NotebookOptions extends Disposable {
566569
outputFontFamily: this._layoutConfiguration.outputFontFamily,
567570
markupFontSize: this._layoutConfiguration.markupFontSize,
568571
outputLineHeight: this._layoutConfiguration.outputLineHeight,
572+
outputScrolling: this._layoutConfiguration.outputScrolling,
569573
};
570574
}
571575

@@ -584,6 +588,7 @@ export class NotebookOptions extends Disposable {
584588
outputFontFamily: this._layoutConfiguration.outputFontFamily,
585589
markupFontSize: this._layoutConfiguration.markupFontSize,
586590
outputLineHeight: this._layoutConfiguration.outputLineHeight,
591+
outputScrolling: this._layoutConfiguration.outputScrolling,
587592
};
588593
}
589594

0 commit comments

Comments
 (0)