Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9affc39

Browse files
authored
Fix monacoEditor perf and intellisense in the interactive window (microsoft#7476)
1 parent 9bf27c2 commit 9affc39

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

news/2 Fixes/7241.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix monaco editor layout perf.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ export class InteractivePanel extends React.Component<IInteractivePanelProps, IM
342342
showWatermark={cellVM.cell.id === Identifiers.EditCellId}
343343
editExecutionCount={this.getInputExecutionCount().toString()}
344344
onCodeChange={this.stateController.codeChange}
345-
onCodeCreated={this.stateController.editableCodeCreated}
345+
onCodeCreated={this.stateController.readOnlyCodeCreated}
346346
monacoTheme={this.state.monacoTheme}
347347
openLink={this.stateController.openLink}
348348
expandImage={this.stateController.showPlot}

src/datascience-ui/interactive-common/mainState.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ function generateVMs(inputBlockToggled: (id: string) => void, filePath: string,
182182
const cells = generateCells(filePath);
183183
return cells.map((cell: ICell) => {
184184
const vm = createCellVM(cell, undefined, inputBlockToggled, editable);
185-
vm.useQuickEdit = true;
185+
vm.useQuickEdit = false;
186186
return vm;
187187
});
188188
}

src/datascience-ui/native-editor/nativeEditorStateController.ts

-5
Original file line numberDiff line numberDiff line change
@@ -196,11 +196,6 @@ export class NativeEditorStateController extends MainStateController {
196196
cellVM.inputBlockOpen = true;
197197
cellVM.inputBlockText = newText;
198198

199-
// Turn on quick edit (use a textArea) for any cell that's just been created.
200-
if (cellVM.useQuickEdit === undefined) {
201-
cellVM.useQuickEdit = true;
202-
}
203-
204199
return cellVM;
205200
}
206201

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

+16-7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ interface IMonacoEditorState {
3737
editor?: monacoEditor.editor.IStandaloneCodeEditor;
3838
model: monacoEditor.editor.ITextModel | null;
3939
visibleLineCount: number;
40+
attached: boolean;
4041
}
4142

4243
// Need this to prevent wiping of the current value on a componentUpdate. react-monaco-editor has that problem.
@@ -56,10 +57,11 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
5657
private styleObserver : MutationObserver | undefined;
5758
private watchingMargin: boolean = false;
5859
private throttledUpdateWidgetPosition = throttle(this.updateWidgetPosition.bind(this), 100);
60+
private monacoContainer : HTMLDivElement | undefined;
5961

6062
constructor(props: IMonacoEditorProps) {
6163
super(props);
62-
this.state = { editor: undefined, model: null, visibleLineCount: -1 };
64+
this.state = { editor: undefined, model: null, visibleLineCount: -1, attached: false };
6365
this.containerRef = React.createRef<HTMLDivElement>();
6466
this.measureWidthRef = React.createRef<HTMLDivElement>();
6567
this.debouncedUpdateEditorSize = debounce(this.updateEditorSize.bind(this), 150);
@@ -88,8 +90,12 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
8890
this.outermostParent.addEventListener('mouseleave', this.outermostParentLeave);
8991
}
9092

93+
// Create a dummy DOM node to attach the editor to so that it skips layout.
94+
this.monacoContainer = document.createElement('div');
95+
this.monacoContainer.setAttribute('class', 'monaco-editor-container');
96+
9197
// Create the editor
92-
const editor = monacoEditor.editor.create(this.containerRef.current,
98+
const editor = monacoEditor.editor.create(this.monacoContainer,
9399
{
94100
value: this.props.value,
95101
language: this.props.language,
@@ -153,9 +159,6 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
153159
// Update our margin to include the correct line number style
154160
this.updateMargin(editor);
155161

156-
// Make sure our suggest and hover windows show up on top of other stuff
157-
this.updateWidgetParent(editor);
158-
159162
// If we're readonly, monaco is not putting the aria-readonly property on the textarea
160163
// We should do that
161164
if (this.props.options.readOnly) {
@@ -237,7 +240,6 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
237240
const measureWidthClassName = this.props.measureWidthClassName ? this.props.measureWidthClassName : 'measure-width-div';
238241
return (
239242
<div className='monaco-editor-outer-container' ref={this.containerRef}>
240-
<div className='monaco-editor-container' />
241243
<div className={measureWidthClassName} ref={this.measureWidthRef} />
242244
</div>
243245
);
@@ -371,7 +373,14 @@ export class MonacoEditor extends React.Component<IMonacoEditorProps, IMonacoEdi
371373
if (this.state.visibleLineCount !== currLineCount) {
372374
this.props.lineCountChanged(currLineCount);
373375
}
374-
this.setState({visibleLineCount: currLineCount});
376+
// Make sure to attach to a real dom node.
377+
if (!this.state.attached && this.state.editor && this.monacoContainer) {
378+
this.containerRef.current.appendChild(this.monacoContainer);
379+
380+
// Make sure our suggest and hover windows show up on top of other stuff
381+
this.updateWidgetParent(this.state.editor);
382+
}
383+
this.setState({visibleLineCount: currLineCount, attached: true});
375384
this.state.editor.layout({width, height});
376385

377386
// Also need to update our widget positions

0 commit comments

Comments
 (0)