From d68e2036abf1c3c512579487272b437847e5ffad Mon Sep 17 00:00:00 2001 From: rchiodo Date: Fri, 5 Apr 2019 14:30:51 -0700 Subject: [PATCH] Fix scrolling in the history window --- news/2 Fixes/5131.md | 1 + .../history-react/MainPanel.tsx | 29 ++---------------- .../history-react/contentPanel.tsx | 30 +++++++++++++++++++ 3 files changed, 33 insertions(+), 27 deletions(-) create mode 100644 news/2 Fixes/5131.md diff --git a/news/2 Fixes/5131.md b/news/2 Fixes/5131.md new file mode 100644 index 000000000000..1ca666812ede --- /dev/null +++ b/news/2 Fixes/5131.md @@ -0,0 +1 @@ +Fix scrolling in the interactive window. diff --git a/src/datascience-ui/history-react/MainPanel.tsx b/src/datascience-ui/history-react/MainPanel.tsx index 6f6b15da28eb..b4bf12b4be62 100644 --- a/src/datascience-ui/history-react/MainPanel.tsx +++ b/src/datascience-ui/history-react/MainPanel.tsx @@ -31,7 +31,6 @@ class HistoryPostOffice extends PostOffice {} export class MainPanel extends React.Component implements IMessageHandler { private stackLimit = 10; - private bottom: HTMLDivElement | undefined; private updateCount = 0; private renderCount = 0; private sentStartup = false; @@ -61,13 +60,7 @@ export class MainPanel extends React.Component this.variableExplorerRef = React.createRef(); } - public componentDidMount() { - this.scrollToBottom(); - } - public componentDidUpdate(_prevProps: Readonly, _prevState: Readonly, _snapshot?: {}) { - this.scrollToBottom(); - // If in test mode, update our outputs if (this.props.testMode) { this.updateCount = this.updateCount + 1; @@ -91,7 +84,6 @@ export class MainPanel extends React.Component -
); } @@ -208,7 +200,8 @@ export class MainPanel extends React.Component saveEditCellRef: this.saveEditCellRef, gotoCellCode: this.gotoCellCode, deleteCell: this.deleteCell, - submitInput: this.submitInput + submitInput: this.submitInput, + skipNextScroll: this.state.skipNextScroll ? true : false }; } private getHeaderProps = (baseTheme: string): IHeaderPanelProps => { @@ -446,24 +439,6 @@ export class MainPanel extends React.Component this.sendMessage(HistoryMessages.Export, cellContents); } - private scrollToBottom = () => { - if (this.bottom && this.bottom.scrollIntoView && !this.state.skipNextScroll && !this.props.testMode) { - // Delay this until we are about to render. React hasn't setup the size of the bottom element - // yet so we need to delay. 10ms looks good from a user point of view - setTimeout(() => { - if (this.bottom) { - this.bottom.scrollIntoView({behavior: 'smooth', block : 'end', inline: 'end'}); - } - }, 100); - } - } - - private updateBottom = (newBottom: HTMLDivElement) => { - if (newBottom !== this.bottom) { - this.bottom = newBottom; - } - } - private updateSelf = (r: HTMLDivElement) => { this.mainPanel = r; } diff --git a/src/datascience-ui/history-react/contentPanel.tsx b/src/datascience-ui/history-react/contentPanel.tsx index 4c22de3cbe3f..a1895e0eee10 100644 --- a/src/datascience-ui/history-react/contentPanel.tsx +++ b/src/datascience-ui/history-react/contentPanel.tsx @@ -18,6 +18,7 @@ export interface IContentPanelProps { testMode?: boolean; codeTheme: string; submittedText: boolean; + skipNextScroll: boolean; saveEditCellRef(ref: Cell | null): void; gotoCellCode(index: number): void; deleteCell(index: number): void; @@ -25,10 +26,19 @@ export interface IContentPanelProps { } export class ContentPanel extends React.Component { + private bottom: HTMLDivElement | undefined; constructor(prop: IContentPanelProps) { super(prop); } + public componentDidMount() { + this.scrollToBottom(); + } + + public componentDidUpdate() { + this.scrollToBottom(); + } + public render() { const newContentTop = `${this.props.contentTop.toString()}px solid transparent`; @@ -43,6 +53,7 @@ export class ContentPanel extends React.Component { {this.renderCells()} +
); } @@ -72,4 +83,23 @@ export class ContentPanel extends React.Component { ); } + + private scrollToBottom = () => { + if (this.bottom && this.bottom.scrollIntoView && !this.props.skipNextScroll && !this.props.testMode) { + // Delay this until we are about to render. React hasn't setup the size of the bottom element + // yet so we need to delay. 10ms looks good from a user point of view + setTimeout(() => { + if (this.bottom) { + this.bottom.scrollIntoView({behavior: 'smooth', block : 'end', inline: 'end'}); + } + }, 100); + } + } + + private updateBottom = (newBottom: HTMLDivElement) => { + if (newBottom !== this.bottom) { + this.bottom = newBottom; + } + } + }