Skip to content

Commit

Permalink
Port scrolling fix to release (#11688)
Browse files Browse the repository at this point in the history
* Fix scrolling (#11681)

* Fix scrolling

* Review feedback - fix scrolling on expand/collapse

* Update changelog

* Update package.json

Co-authored-by: Jim Griesmer <jimgries@microsoft.com>
  • Loading branch information
rchiodo and greazer committed May 8, 2020
1 parent c5e366f commit 11c0cbf
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
([#11579](https://github.com/Microsoft/vscode-python/issues/11579))
1. When VS quits, make sure to save contents of notebook for next reopen.
([#11557](https://github.com/Microsoft/vscode-python/issues/11557))
1. Fix scrolling when clicking in the interactive window to not jump around.
([#11554](https://github.com/Microsoft/vscode-python/issues/11554))

### Code Health

Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1761,6 +1761,12 @@
"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.",
"scope": "resource"
},
"python.dataScience.alwaysScrollOnNewCell": {
"type": "boolean",
"default": false,
"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.",
"scope": "resource"
},
"python.dataScience.enableScrollingForCellOutputs": {
"type": "boolean",
"default": true,
Expand Down
1 change: 1 addition & 0 deletions src/client/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ export interface IDataScienceSettings {
disableJupyterAutoStart?: boolean;
jupyterCommandLineArguments: string[];
widgetScriptSources: WidgetCDNs[];
alwaysScrollOnNewCell?: boolean;
}

export type WidgetCDNs = 'unpkg.com' | 'jsdelivr.com';
Expand Down
4 changes: 3 additions & 1 deletion src/datascience-ui/history-react/interactivePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,9 @@ ${buildSettingsCss(this.props.settings)}`}</style>
if (this.internalScrollCount > 0) {
this.internalScrollCount -= 1;
} else if (this.contentPanelRef.current) {
const isAtBottom = this.contentPanelRef.current.computeIsAtBottom(e.currentTarget);
const isAtBottom = this.props.settings?.alwaysScrollOnNewCell
? true
: this.contentPanelRef.current.computeIsAtBottom(e.currentTarget);
this.props.scroll(isAtBottom);
}
};
Expand Down
17 changes: 15 additions & 2 deletions src/datascience-ui/interactive-common/contentPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
'use strict';
import * as React from 'react';

import * as fastDeepEqual from 'fast-deep-equal';
import { IDataScienceExtraSettings } from '../../client/datascience/types';
import { InputHistory } from './inputHistory';
import { ICellViewModel } from './mainState';
Expand Down Expand Up @@ -37,8 +38,12 @@ export class ContentPanel extends React.Component<IContentPanelProps> {
public componentDidMount() {
this.scrollToBottom();
}
public componentWillReceiveProps() {
this.scrollToBottom();
public componentWillReceiveProps(prevProps: IContentPanelProps) {
// Scroll if we suddenly finished or updated a cell. This should happen on
// finish, updating output, etc.
if (!fastDeepEqual(prevProps.cellVMs.map(this.outputCheckable), this.props.cellVMs.map(this.outputCheckable))) {
this.scrollToBottom();
}
}

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

private outputCheckable = (cellVM: ICellViewModel) => {
// Return the properties that if they change means a cell updated something
return {
outputs: cellVM.cell.data.outputs,
state: cellVM.cell.state
};
};

private renderCells = () => {
return this.props.cellVMs.map((cellVM: ICellViewModel, index: number) => {
return this.props.renderCell(cellVM, index);
Expand Down

0 comments on commit 11c0cbf

Please sign in to comment.