Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix scrolling #11681

Merged
merged 2 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2 Fixes/11554.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix scrolling when clicking in the interactive window to not jump around.
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": "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",
"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
9 changes: 7 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, this.props.cellVMs)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it just be output updates where we would want to scroll to the bottom? Or is that trying to get too specific?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch. Expanding Collapsing input cause it to scroll too. We really only want output updates.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, there is a lot of other stuff in cellVMs

this.scrollToBottom();
}
}

public computeIsAtBottom(parent: HTMLDivElement): boolean {
Expand Down