Skip to content

Commit c8fc5a5

Browse files
committed
Fix scrolling in the monaco editor (#11089)
* Fix monaco editor scrolling and line height * Add news entry
1 parent 4ccac22 commit c8fc5a5

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

news/2 Fixes/10952.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Scrolling in cells doesn't happen on new line.

src/datascience-ui/react-common/monacoEditor.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,8 +188,11 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
188188
this.subscriptions.push(
189189
editor.onDidLayoutChange(() => {
190190
this.windowResized();
191-
// Also recompute our visible line heights
191+
// Recompute visible line tops
192192
this.debouncedComputeLineTops();
193+
194+
// A layout change may be because of a new line
195+
this.throttledScrollCurrentPosition(editor);
193196
})
194197
);
195198

@@ -243,7 +246,9 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
243246
this.subscriptions.push(
244247
editor.onDidChangeCursorPosition(() => {
245248
this.throttledUpdateWidgetPosition();
246-
this.throttledScrollCurrentPosition(editor);
249+
250+
// Do this after the cursor changes so the text has time to appear
251+
setTimeout(() => this.throttledScrollCurrentPosition(editor), 0);
247252
})
248253
);
249254

@@ -643,14 +648,12 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
643648
const editorDomNode = this.state.editor.getDomNode();
644649
if (editorDomNode) {
645650
const container = editorDomNode.getElementsByClassName('view-lines')[0] as HTMLElement;
646-
const lineHeightPx =
647-
container.firstChild && (container.firstChild as HTMLElement).style.height
648-
? (container.firstChild as HTMLElement).style.height
649-
: `${LINE_HEIGHT}px`;
650-
MonacoEditor.lineHeight =
651-
lineHeightPx && lineHeightPx.endsWith('px')
652-
? parseInt(lineHeightPx.substr(0, lineHeightPx.length - 2), 10)
653-
: LINE_HEIGHT;
651+
if (container.firstChild && (container.firstChild as HTMLElement).style.height) {
652+
const lineHeightPx = (container.firstChild as HTMLElement).style.height;
653+
MonacoEditor.lineHeight = parseInt(lineHeightPx, 10);
654+
} else {
655+
return LINE_HEIGHT;
656+
}
654657
}
655658
}
656659
return MonacoEditor.lineHeight;

0 commit comments

Comments
 (0)