Skip to content

Commit 7003a9b

Browse files
authored
Fix scrolling in the history window (#5133)
For #5131 <!-- If an item below does not apply to you, then go ahead and check it off as "done" and strikethrough the text, e.g.: - [x] ~Has unit tests & system/integration tests~ --> - [x] Pull request represents a single change (i.e. not fixing disparate/unrelated things in a single PR) - [x] Title summarizes what is changing - [x] Has a [news entry](https://github.com/Microsoft/vscode-python/tree/master/news) file (remember to thank yourself!) - [ ] Has sufficient logging. - [ ] Has telemetry for enhancements. - [ ] Unit tests & system/integration tests are added/updated - [ ] [Test plan](https://github.com/Microsoft/vscode-python/blob/master/.github/test_plan.md) is updated as appropriate - [ ] [`package-lock.json`](https://github.com/Microsoft/vscode-python/blob/master/package-lock.json) has been regenerated by running `npm install` (if dependencies have changed) - [ ] The wiki is updated with any design decisions/details.
1 parent d2cc712 commit 7003a9b

File tree

3 files changed

+33
-27
lines changed

3 files changed

+33
-27
lines changed

news/2 Fixes/5131.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix scrolling in the interactive window.

src/datascience-ui/history-react/MainPanel.tsx

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ class HistoryPostOffice extends PostOffice<IHistoryMapping> {}
3131

3232
export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState> implements IMessageHandler {
3333
private stackLimit = 10;
34-
private bottom: HTMLDivElement | undefined;
3534
private updateCount = 0;
3635
private renderCount = 0;
3736
private sentStartup = false;
@@ -61,13 +60,7 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
6160
this.variableExplorerRef = React.createRef<VariableExplorer>();
6261
}
6362

64-
public componentDidMount() {
65-
this.scrollToBottom();
66-
}
67-
6863
public componentDidUpdate(_prevProps: Readonly<IMainPanelProps>, _prevState: Readonly<IMainPanelState>, _snapshot?: {}) {
69-
this.scrollToBottom();
70-
7164
// If in test mode, update our outputs
7265
if (this.props.testMode) {
7366
this.updateCount = this.updateCount + 1;
@@ -91,7 +84,6 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
9184
<HistoryPostOffice messageHandlers={[this]} ref={this.updatePostOffice} />
9285
<HeaderPanel {...headerProps} />
9386
<ContentPanel {...contentProps} />
94-
<div ref={this.updateBottom}/>
9587
</div>
9688
);
9789
}
@@ -208,7 +200,8 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
208200
saveEditCellRef: this.saveEditCellRef,
209201
gotoCellCode: this.gotoCellCode,
210202
deleteCell: this.deleteCell,
211-
submitInput: this.submitInput
203+
submitInput: this.submitInput,
204+
skipNextScroll: this.state.skipNextScroll ? true : false
212205
};
213206
}
214207
private getHeaderProps = (baseTheme: string): IHeaderPanelProps => {
@@ -446,24 +439,6 @@ export class MainPanel extends React.Component<IMainPanelProps, IMainPanelState>
446439
this.sendMessage(HistoryMessages.Export, cellContents);
447440
}
448441

449-
private scrollToBottom = () => {
450-
if (this.bottom && this.bottom.scrollIntoView && !this.state.skipNextScroll && !this.props.testMode) {
451-
// Delay this until we are about to render. React hasn't setup the size of the bottom element
452-
// yet so we need to delay. 10ms looks good from a user point of view
453-
setTimeout(() => {
454-
if (this.bottom) {
455-
this.bottom.scrollIntoView({behavior: 'smooth', block : 'end', inline: 'end'});
456-
}
457-
}, 100);
458-
}
459-
}
460-
461-
private updateBottom = (newBottom: HTMLDivElement) => {
462-
if (newBottom !== this.bottom) {
463-
this.bottom = newBottom;
464-
}
465-
}
466-
467442
private updateSelf = (r: HTMLDivElement) => {
468443
this.mainPanel = r;
469444
}

src/datascience-ui/history-react/contentPanel.tsx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,27 @@ export interface IContentPanelProps {
1818
testMode?: boolean;
1919
codeTheme: string;
2020
submittedText: boolean;
21+
skipNextScroll: boolean;
2122
saveEditCellRef(ref: Cell | null): void;
2223
gotoCellCode(index: number): void;
2324
deleteCell(index: number): void;
2425
submitInput(code: string): void;
2526
}
2627

2728
export class ContentPanel extends React.Component<IContentPanelProps> {
29+
private bottom: HTMLDivElement | undefined;
2830
constructor(prop: IContentPanelProps) {
2931
super(prop);
3032
}
3133

34+
public componentDidMount() {
35+
this.scrollToBottom();
36+
}
37+
38+
public componentDidUpdate() {
39+
this.scrollToBottom();
40+
}
41+
3242
public render() {
3343
const newContentTop = `${this.props.contentTop.toString()}px solid transparent`;
3444

@@ -43,6 +53,7 @@ export class ContentPanel extends React.Component<IContentPanelProps> {
4353
{this.renderCells()}
4454
</div>
4555
</div>
56+
<div ref={this.updateBottom}/>
4657
</div>
4758
);
4859
}
@@ -72,4 +83,23 @@ export class ContentPanel extends React.Component<IContentPanelProps> {
7283
</ErrorBoundary>
7384
);
7485
}
86+
87+
private scrollToBottom = () => {
88+
if (this.bottom && this.bottom.scrollIntoView && !this.props.skipNextScroll && !this.props.testMode) {
89+
// Delay this until we are about to render. React hasn't setup the size of the bottom element
90+
// yet so we need to delay. 10ms looks good from a user point of view
91+
setTimeout(() => {
92+
if (this.bottom) {
93+
this.bottom.scrollIntoView({behavior: 'smooth', block : 'end', inline: 'end'});
94+
}
95+
}, 100);
96+
}
97+
}
98+
99+
private updateBottom = (newBottom: HTMLDivElement) => {
100+
if (newBottom !== this.bottom) {
101+
this.bottom = newBottom;
102+
}
103+
}
104+
75105
}

0 commit comments

Comments
 (0)