Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions news/2 Fixes/6580.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Changed the way scrolling is treated. Now we only check for the position of the scroll, the size of the cell won't matter.
Still the interactive window will snap to the bottom if you already are at the bottom, and will stay in place if you are not. Like a chat window.
Tested to work with:
- regular code
- dataframes
- big and regular plots
29 changes: 26 additions & 3 deletions src/datascience-ui/history-react/MainPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
private stackLimit = 10;
private updateCount = 0;
private renderCount = 0;
private internalScrollCount = 0;
private editCellRef: Cell | null = null;
private mainPanel: HTMLDivElement | null = null;
private variableExplorerRef: React.RefObject<VariableExplorer>;
Expand Down Expand Up @@ -68,7 +69,8 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
editorOptions: this.computeEditorOptions(),
currentExecutionCount: 0,
debugging: false,
enableGather: getSettings && getSettings().enableGather
enableGather: getSettings && getSettings().enableGather,
isAtBottom: true
};

// Add test state if necessary
Expand Down Expand Up @@ -151,7 +153,7 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
<section id='main-panel-variable' aria-label={getLocString('DataScience.collapseVariableExplorerLabel', 'Variables')}>
{this.renderVariablePanel(baseTheme)}
</section>
<main id='main-panel-content'>
<main id='main-panel-content' onScroll={this.handleScroll}>
{this.renderContentPanel(baseTheme)}
</main>
<section id='main-panel-footer' aria-label={getLocString('DataScience.editSection', 'Input new cells here')}>
Expand All @@ -161,6 +163,26 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
);
}

// This handles the scrolling. Its called from the props of contentPanel.
// We only scroll when the state indicates we are at the bottom of the interactive window,
// otherwise it sometimes scrolls when the user wasn't at the bottom.
public scrollDiv = (div: HTMLDivElement) => {
if (this.state.isAtBottom) {
this.internalScrollCount += 1;
div.scrollIntoView({ behavior: 'auto', block: 'start', inline: 'nearest' });
}
}

public handleScroll = (e: React.UIEvent<HTMLDivElement>) => {
if (this.internalScrollCount > 0) {
this.internalScrollCount -= 1;
} else {
this.setState({
isAtBottom: e.currentTarget.scrollHeight - e.currentTarget.scrollTop === e.currentTarget.clientHeight
Copy link
Member

Choose a reason for hiding this comment

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

Just to check does this need any wiggle room in it?

Copy link
Author

Choose a reason for hiding this comment

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

I don't feel its confusing, it sticks if you are all the way on the bottom. If not it stays there.

});
}
}

// tslint:disable-next-line:no-any cyclomatic-complexity max-func-body-length
public handleMessage = (msg: string, payload?: any) => {
switch (msg) {
Expand Down Expand Up @@ -445,7 +467,8 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
openLink: this.openLink,
expandImage: this.showPlot,
gatherCode: this.gatherCode,
enableGather: this.state.enableGather
enableGather: this.state.enableGather,
scrollToBottom: this.scrollDiv
};
}
private getToolbarProps = (baseTheme: string): IToolbarPanelProps => {
Expand Down
10 changes: 3 additions & 7 deletions src/datascience-ui/history-react/contentPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export interface IContentPanelProps {
onCodeCreated(code: string, file: string, cellId: string, modelId: string): void;
openLink(uri: monacoEditor.Uri): void;
expandImage(imageHtml: string): void;
scrollToBottom(div: HTMLDivElement): void;
}

export class ContentPanel extends React.Component<IContentPanelProps> {
Expand Down Expand Up @@ -122,13 +123,8 @@ export class ContentPanel extends React.Component<IContentPanelProps> {
private scrollIntoView() {
// Force auto here as smooth scrolling can be canceled by updates to the window
// from elsewhere (and keeping track of these would make this hard to maintain)
if (this.bottomRef.current
// This condition prevents window to scroll down when user is not near the bottom.
// We increase window.innerHeight by 20% to still snap to the bottom when creating
// multiple default plots. User needs to do about 3 'scrolls' up from the bottom
// to prevent the window to snap to the bottom.
&& this.bottomRef.current.getBoundingClientRect().bottom <= window.innerHeight * 1.2) {
this.bottomRef.current.scrollIntoView({ behavior: 'auto', block: 'start', inline: 'nearest' });
if (this.bottomRef.current) {
this.props.scrollToBottom(this.bottomRef.current);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/datascience-ui/history-react/mainPanelState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface IMainPanelState {
currentExecutionCount: number;
debugging: boolean;
enableGather?: boolean;
isAtBottom: boolean;
}

// tslint:disable-next-line: no-multiline-string
Expand Down Expand Up @@ -63,7 +64,8 @@ export function generateTestState(inputBlockToggled: (id: string) => void, fileP
editorOptions: {},
currentExecutionCount: 0,
debugging: false,
enableGather: false
enableGather: false,
isAtBottom: true
};
}

Expand Down