Skip to content

Commit da2a2eb

Browse files
Add ability to reset editor layout
1 parent 1629c10 commit da2a2eb

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

packages/app/src/app/overmind/effects/vscode/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,23 @@ export class VSCodeEffect {
248248
}
249249
};
250250

251+
public resetLayout() {
252+
if (this.editorApi) {
253+
// We have to wait for the layout to actually update in the DOM
254+
requestAnimationFrame(() => {
255+
const rootEl = document.querySelector('#vscode-container');
256+
if (rootEl) {
257+
const boundingRect = rootEl.getBoundingClientRect();
258+
259+
this.editorApi.editorPart.layout(
260+
boundingRect.width,
261+
boundingRect.height
262+
);
263+
}
264+
});
265+
}
266+
}
267+
251268
/*
252269
We need to use a callback to set the sandbox-fs into the state of Overmind. The reason
253270
is that we internally read from this state to get information about the files. It is really

packages/app/src/app/overmind/namespaces/editor/actions.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,9 @@ export const quickActionsClosed: Action = ({ state }) => {
467467

468468
export const setPreviewContent: Action = () => {};
469469

470-
export const togglePreviewContent: Action = ({ state }) => {
470+
export const togglePreviewContent: Action = ({ state, effects }) => {
471471
state.editor.previewWindowVisible = !state.editor.previewWindowVisible;
472+
effects.vscode.resetLayout();
472473
};
473474

474475
export const currentTabChanged: Action<{
@@ -540,13 +541,15 @@ export const deleteEnvironmentVariable: AsyncAction<{
540541
effects.codesandboxApi.restartSandbox();
541542
};
542543

543-
export const toggleEditorPreviewLayout: Action = ({ state }) => {
544+
export const toggleEditorPreviewLayout: Action = ({ state, effects }) => {
544545
const currentOrientation = state.editor.previewWindowOrientation;
545546

546547
state.editor.previewWindowOrientation =
547548
currentOrientation === WindowOrientation.VERTICAL
548549
? WindowOrientation.HORIZONTAL
549550
: WindowOrientation.VERTICAL;
551+
552+
effects.vscode.resetLayout();
550553
};
551554

552555
export const previewActionReceived: Action<{

0 commit comments

Comments
 (0)