Skip to content

Commit 7982657

Browse files
author
Ives van Hoorne
committed
Tweak editor resizing
1 parent b243c8f commit 7982657

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

packages/app/src/app/components/CodeEditor/Monaco/index.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
149149
this.typingsFetcherWorker = null;
150150
this.sizeProbeInterval = null;
151151

152-
this.resizeEditor = debounce(this.resizeEditor, 500);
152+
this.resizeEditor = debounce(this.resizeEditor, 150);
153153
this.commitLibChanges = debounce(this.commitLibChanges, 300);
154154
this.onSelectionChangedDebounced = debounce(
155155
this.onSelectionChangedDebounced,
@@ -167,6 +167,15 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
167167
this.resizeEditorInstantly();
168168
}
169169

170+
if (
171+
this.props.absoluteWidth &&
172+
this.props.absoluteHeight &&
173+
(this.props.absoluteWidth !== nextProps.absoluteWidth ||
174+
this.props.absoluteHeight !== nextProps.absoluteHeight)
175+
) {
176+
this.resizeEditor();
177+
}
178+
170179
if (this.props.readOnly !== nextProps.readOnly && this.editor) {
171180
this.editor.updateOptions({ readOnly: !!nextProps.readOnly });
172181
}
@@ -256,10 +265,13 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
256265
// this.addKeyCommands();
257266

258267
window.addEventListener('resize', this.resizeEditor);
259-
this.sizeProbeInterval = setInterval(
260-
this.resizeEditorInstantly.bind(this),
261-
3000
262-
);
268+
this.sizeProbeInterval = setInterval(() => {
269+
if (this.props.absoluteWidth && this.props.absoluteHeight) {
270+
return;
271+
}
272+
273+
this.resizeEditorInstantly();
274+
}, 3000);
263275

264276
const { dependencies } = this;
265277
if (dependencies != null) {

packages/app/src/app/components/CodeEditor/types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ export interface Editor {
5959
setReceivingCode?: (receivingCode: boolean) => void;
6060
applyOperations?: (operations: { [moduleShortid: string]: any }) => void;
6161
updateUserSelections?: (selections: any) => void;
62+
absoluteWidth?: number;
63+
absoluteHeight?: number;
6264
}
6365

6466
export type Props = {

packages/app/src/app/pages/Sandbox/Editor/Content/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,8 @@ class EditorPreview extends React.Component<Props, State> {
437437
)}
438438
width={editorWidth}
439439
height={editorHeight}
440+
absoluteWidth={this.state.width}
441+
absoluteHeight={this.state.height}
440442
settings={settings(store)}
441443
sendTransforms={this.sendTransforms}
442444
readOnly={store.live.isLive && !store.live.isCurrentEditor}

0 commit comments

Comments
 (0)