Skip to content

Commit 11c0cbf

Browse files
rchiodogreazer
andauthored
Port scrolling fix to release (#11688)
* Fix scrolling (#11681) * Fix scrolling * Review feedback - fix scrolling on expand/collapse * Update changelog * Update package.json Co-authored-by: Jim Griesmer <[email protected]>
1 parent c5e366f commit 11c0cbf

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@
8080
([#11579](https://github.com/Microsoft/vscode-python/issues/11579))
8181
1. When VS quits, make sure to save contents of notebook for next reopen.
8282
([#11557](https://github.com/Microsoft/vscode-python/issues/11557))
83+
1. Fix scrolling when clicking in the interactive window to not jump around.
84+
([#11554](https://github.com/Microsoft/vscode-python/issues/11554))
8385

8486
### Code Health
8587

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": "Automatically scroll the interactive window to show the output of the last statement executed. If false, the interactive window will only automatically scroll if the bottom of the prior cell is visible.",
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)