Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix overflow widgets for monaco #682

Merged
merged 6 commits into from
Jul 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/toolpad-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"json-to-ts": "^1.7.0",
"json5": "^2.2.1",
"lodash-es": "^4.17.21",
"monaco-editor": "0.34.0-dev.20220725",
"next": "12.2.0",
"node-fetch": "^3.2.6",
"node-fetch-har": "^1.0.1",
Expand Down Expand Up @@ -110,7 +111,6 @@
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"glob": "^8.0.3",
"monaco-editor": "^0.34.0-dev.20220722",
"webpack": "^5.73.0"
},
"typings": "./index.d.ts",
Expand Down
17 changes: 17 additions & 0 deletions packages/toolpad-app/src/components/MonacoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import clsx from 'clsx';
import cuid from 'cuid';
import invariant from 'invariant';
import monacoEditorTheme from '../monacoEditorTheme';
import muiTheme from '../theme';

function getExtension(language: string): string {
switch (language) {
Expand Down Expand Up @@ -107,6 +108,19 @@ const EditorRoot = styled('div')(({ theme }) => ({
},
}));

let overflowWidgetsDomNode: HTMLDivElement | null = null;
function getOverflowWidgetsDomNode(): HTMLDivElement {
if (!overflowWidgetsDomNode) {
overflowWidgetsDomNode = document.createElement('div');
// See https://github.com/microsoft/monaco-editor/issues/2233#issuecomment-913170212
overflowWidgetsDomNode.classList.add('monaco-editor');
overflowWidgetsDomNode.style.zIndex = String(muiTheme.zIndex.tooltip + 1);
document.body.append(overflowWidgetsDomNode);
}

return overflowWidgetsDomNode;
}

export interface MonacoEditorHandle {
editor: monaco.editor.IStandaloneCodeEditor;
monaco: typeof monaco;
Expand Down Expand Up @@ -190,6 +204,9 @@ export default React.forwardRef<MonacoEditorHandle, MonacoEditorProps>(function
tabSize: 2,
automaticLayout: true,
theme: monacoEditorTheme,
fixedOverflowWidgets: true,
// See https://github.com/microsoft/monaco-editor/issues/181
overflowWidgetsDomNode: getOverflowWidgetsDomNode(),
...extraOptions,
});

Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8954,10 +8954,10 @@ modify-values@^1.0.0:
resolved "https://registry.yarnpkg.com/modify-values/-/modify-values-1.0.1.tgz#b3939fa605546474e3e3e3c63d64bd43b4ee6022"
integrity sha512-xV2bxeN6F7oYjZWTe/YPAy6MN2M+sL4u/Rlm2AHCIVGfo2p1yGmBHQ6vHehl4bRTZBdHu3TSkWdYgkwpYzAGSw==

monaco-editor@^0.34.0-dev.20220722:
version "0.34.0-dev.20220722"
resolved "https://registry.yarnpkg.com/monaco-editor/-/monaco-editor-0.34.0-dev.20220722.tgz#58bbb9477c2790c346c156e80d74585b6691b2e3"
integrity sha512-6l2hFsHOJE+5TQFDoWBeoACKcissTeLD5+xJ2HrtvP86sHnpnZy7ffbcFQCKpInJKIBSP7+y/bpctYn8eSAYTQ==
monaco-editor@0.34.0-dev.20220725:
version "0.34.0-dev.20220725"
resolved "https://registry.yarnpkg.com/monaco-editor/-/monaco-editor-0.34.0-dev.20220725.tgz#79e6bdef9dd3e1e5a66ebbbef549604064695b22"
integrity sha512-MiuJINwVQyqEEieWQ2NEcapjmi2MiAibthhpK2Tj2pd5tMHtZMO2PpoAKQla1cwxfhTlkb7e+cv0a+CN7Cl67A==

mrmime@^1.0.0:
version "1.0.1"
Expand Down