Skip to content

Fix scrolling in the monaco editor #11089

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

Merged
merged 2 commits into from
Apr 11, 2020
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
1 change: 1 addition & 0 deletions news/2 Fixes/10952.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Scrolling in cells doesn't happen on new line.
23 changes: 13 additions & 10 deletions src/datascience-ui/react-common/monacoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,11 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
this.subscriptions.push(
editor.onDidLayoutChange(() => {
this.windowResized();
// Also recompute our visible line heights
// Recompute visible line tops
this.debouncedComputeLineTops();

// A layout change may be because of a new line
this.throttledScrollCurrentPosition(editor);
})
);

Expand Down Expand Up @@ -243,7 +246,9 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
this.subscriptions.push(
editor.onDidChangeCursorPosition(() => {
this.throttledUpdateWidgetPosition();
this.throttledScrollCurrentPosition(editor);

// Do this after the cursor changes so the text has time to appear
setTimeout(() => this.throttledScrollCurrentPosition(editor), 0);
})
);

Expand Down Expand Up @@ -643,14 +648,12 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
const editorDomNode = this.state.editor.getDomNode();
if (editorDomNode) {
const container = editorDomNode.getElementsByClassName('view-lines')[0] as HTMLElement;
const lineHeightPx =
container.firstChild && (container.firstChild as HTMLElement).style.height
? (container.firstChild as HTMLElement).style.height
: `${LINE_HEIGHT}px`;
MonacoEditor.lineHeight =
lineHeightPx && lineHeightPx.endsWith('px')
? parseInt(lineHeightPx.substr(0, lineHeightPx.length - 2), 10)
: LINE_HEIGHT;
if (container.firstChild && (container.firstChild as HTMLElement).style.height) {
const lineHeightPx = (container.firstChild as HTMLElement).style.height;
MonacoEditor.lineHeight = parseInt(lineHeightPx, 10);
} else {
return LINE_HEIGHT;
}
}
}
return MonacoEditor.lineHeight;
Expand Down