Skip to content

Commit e4b91d2

Browse files
committed
Fix the performance by introducing the max height
1 parent cdfd53b commit e4b91d2

File tree

1 file changed

+8
-18
lines changed

1 file changed

+8
-18
lines changed

src/main/resources/web/dist/monaco.js

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const maxAllowedHeight = 600;
2+
13
function mymonaco(config) {
24
require.config({paths: {'vs': 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.39.0/min/vs'}});
35
require(['vs/editor/editor.main'], initializeEditors);
@@ -6,9 +8,7 @@ function mymonaco(config) {
68
const right_container_id = config.rcid;/*'right-container';*/
79
const leftContainer = document.getElementById(left_container_id);
810
const rightContainer = document.getElementById(right_container_id);
9-
let isLayoutUpdating = false;
10-
let lastUpdateDebounce = Date.now();
11-
let isInitialLayout = true; // Flag to track the initial layout
11+
1212
Promise.all([
1313
Promise.resolve(monaco.editor.create(leftContainer, getEditorOptions(config, config.left.content))),
1414
Promise.resolve(monaco.editor.create(rightContainer, getEditorOptions(config, config.right.content)))
@@ -41,23 +41,13 @@ function mymonaco(config) {
4141

4242
if (config.spv === true) {
4343
const updateEditorsLayout = () => {
44-
isInitialLayout = false; // Disable the initial layout update flag
45-
if (Date.now() - lastUpdateDebounce > 2000 && !isLayoutUpdating)
46-
return; // Debounce layout updates
47-
lastUpdateDebounce = Date.now();
48-
isLayoutUpdating = true;
4944
const leftHeight = leftEditor.getContentHeight();
5045
const rightHeight = rightEditor.getContentHeight();
51-
const editorHeight = Math.max(leftHeight, rightHeight);
52-
53-
if (isInitialLayout){
54-
leftContainer.style.height = 500 + 'px';
55-
rightContainer.style.height = 500 + 'px';
56-
}
57-
else {
58-
leftContainer.style.height = leftHeight + 'px';
59-
rightContainer.style.height = rightHeight + 'px';
60-
}
46+
let maxHeight = Math.max(leftHeight, rightHeight);
47+
const editorHeight = maxHeight > maxAllowedHeight ? maxAllowedHeight : maxHeight;
48+
console.log(editorHeight);
49+
leftContainer.style.height = editorHeight + 'px';
50+
rightContainer.style.height = editorHeight + 'px';
6151
leftEditor.layout();
6252
rightEditor.layout();
6353
};

0 commit comments

Comments
 (0)