Skip to content

Commit c14790b

Browse files
committed
CONSOLE-4407: Use ResizeObserver over automaticLayout
`automaticLayout` has a few problems in this older version, see microsoft/monaco-editor#4277
1 parent b515d0e commit c14790b

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

frontend/packages/console-shared/src/components/editor/BasicCodeEditor.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react';
22
import { loader, Monaco } from '@monaco-editor/react';
33
import { CodeEditor } from '@patternfly/react-code-editor';
4+
import { getResizeObserver } from '@patternfly/react-core';
45
import classNames from 'classnames';
56
import * as monaco from 'monaco-editor';
67
import { useTranslation } from 'react-i18next';
@@ -23,6 +24,22 @@ export const BasicCodeEditor: React.FC<BasicCodeEditorProps> = (props) => {
2324
const [monacoRef, setMonacoRef] = React.useState<Monaco | null>(null);
2425
useConsoleMonacoTheme(monacoRef?.editor);
2526

27+
// TODO(PF6): remove this when https://github.com/patternfly/patternfly-react/issues/11531 is fixed
28+
const handleResize = React.useCallback(() => {
29+
monacoRef?.editor?.getEditors()?.forEach((editor) => {
30+
editor.layout({ width: 0, height: 0 });
31+
editor.layout();
32+
});
33+
}, [monacoRef]);
34+
35+
React.useEffect(() => {
36+
const observer = getResizeObserver(undefined, handleResize, true);
37+
38+
return () => {
39+
observer();
40+
};
41+
}, [handleResize]);
42+
2643
return (
2744
<CodeEditor
2845
copyButtonAriaLabel={t('Copy code to clipboard')}

frontend/packages/console-shared/src/components/editor/CodeEditor.scss

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
.ocs-yaml-editor {
44
.monaco-editor {
5-
// Makes automaticLayout work properly. note that this breaks height="sizeToFit"
6-
position: absolute !important;
7-
85
.monaco-hover-content .markdown-hover {
96
// matches tooltip styling seen back in OpenShift 4.18
107
max-width: 500px;

frontend/packages/console-shared/src/components/editor/yaml-editor-utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import { getSwaggerDefinitions } from '@console/internal/module/k8s/swagger';
77

88
export const defaultEditorOptions: monaco.editor.IEditorOptions = {
99
scrollBeyondLastLine: false,
10-
automaticLayout: true, // paired with position: absolute for auto-resizing
1110
};
1211

1312
const findManagedMetadata = (model: monaco.editor.ITextModel) => {

0 commit comments

Comments
 (0)