Skip to content

Commit 226b8f8

Browse files
authored
Fix scrolling (#11681)
* Fix scrolling * Review feedback - fix scrolling on expand/collapse
1 parent d6c7781 commit 226b8f8

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

news/2 Fixes/11554.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix scrolling when clicking in the interactive window to not jump around.

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,12 @@
17611761
"description": "Maximum size (in pixels) of text output in the Python Interactive window and Notebook Editor before a scrollbar appears. First enable scrolling for cell outputs in settings.",
17621762
"scope": "resource"
17631763
},
1764+
"python.dataScience.alwaysScrollOnNewCell": {
1765+
"type": "boolean",
1766+
"default": false,
1767+
"description": "If a new cell comes in, scroll the interactive window to the bottom regardless of where the scroll bar is. The default is to only scroll if the current position was already at the bottom when the new cell is created",
1768+
"scope": "resource"
1769+
},
17641770
"python.dataScience.enableScrollingForCellOutputs": {
17651771
"type": "boolean",
17661772
"default": true,

src/client/common/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ export interface IDataScienceSettings {
389389
disableJupyterAutoStart?: boolean;
390390
jupyterCommandLineArguments: string[];
391391
widgetScriptSources: WidgetCDNs[];
392+
alwaysScrollOnNewCell?: boolean;
392393
}
393394

394395
export type WidgetCDNs = 'unpkg.com' | 'jsdelivr.com';

src/datascience-ui/history-react/interactivePanel.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,9 @@ ${buildSettingsCss(this.props.settings)}`}</style>
373373
if (this.internalScrollCount > 0) {
374374
this.internalScrollCount -= 1;
375375
} else if (this.contentPanelRef.current) {
376-
const isAtBottom = this.contentPanelRef.current.computeIsAtBottom(e.currentTarget);
376+
const isAtBottom = this.props.settings?.alwaysScrollOnNewCell
377+
? true
378+
: this.contentPanelRef.current.computeIsAtBottom(e.currentTarget);
377379
this.props.scroll(isAtBottom);
378380
}
379381
};

src/datascience-ui/interactive-common/contentPanel.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
'use strict';
44
import * as React from 'react';
55

6+
import * as fastDeepEqual from 'fast-deep-equal';
67
import { IDataScienceExtraSettings } from '../../client/datascience/types';
78
import { InputHistory } from './inputHistory';
89
import { ICellViewModel } from './mainState';
@@ -37,8 +38,12 @@ export class ContentPanel extends React.Component<IContentPanelProps> {
3738
public componentDidMount() {
3839
this.scrollToBottom();
3940
}
40-
public componentWillReceiveProps() {
41-
this.scrollToBottom();
41+
public componentWillReceiveProps(prevProps: IContentPanelProps) {
42+
// Scroll if we suddenly finished or updated a cell. This should happen on
43+
// finish, updating output, etc.
44+
if (!fastDeepEqual(prevProps.cellVMs.map(this.outputCheckable), this.props.cellVMs.map(this.outputCheckable))) {
45+
this.scrollToBottom();
46+
}
4247
}
4348

4449
public computeIsAtBottom(parent: HTMLDivElement): boolean {
@@ -61,6 +66,14 @@ export class ContentPanel extends React.Component<IContentPanelProps> {
6166
);
6267
}
6368

69+
private outputCheckable = (cellVM: ICellViewModel) => {
70+
// Return the properties that if they change means a cell updated something
71+
return {
72+
outputs: cellVM.cell.data.outputs,
73+
state: cellVM.cell.state
74+
};
75+
};
76+
6477
private renderCells = () => {
6578
return this.props.cellVMs.map((cellVM: ICellViewModel, index: number) => {
6679
return this.props.renderCell(cellVM, index);

0 commit comments

Comments
 (0)