From cc01ecc8402c7a32303461fc37bfcb3a31405945 Mon Sep 17 00:00:00 2001 From: Menci Date: Sat, 27 Apr 2019 00:46:56 +0800 Subject: [PATCH] Auto layout monaco editor on window resize --- static/self/monaco-editor.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/static/self/monaco-editor.js b/static/self/monaco-editor.js index 9c0dc20..eb08911 100644 --- a/static/self/monaco-editor.js +++ b/static/self/monaco-editor.js @@ -584,10 +584,16 @@ require(['vs/editor/editor.main'], function () { }); } + function autoLayout(editor) { + window.addEventListener('resize', function () { + editor.layout(); + }); + } + $.getScript(window.pathSelfLib + "monaco-editor-tomorrow.js", function () { window.createCodeEditor = function (editorElement, langauge, content) { editorElement.innerHTML = ''; - return monaco.editor.create(editorElement, { + var editor = monaco.editor.create(editorElement, { value: content, language: langauge, multicursorModifier: 'ctrlCmd', @@ -608,6 +614,9 @@ require(['vs/editor/editor.main'], function () { hideCursorInOverviewRuler: true, contextmenu: false }); + + autoLayout(editor); + return editor; }; window.createMarkdownEditor = function (wrapperElement, content, input) { @@ -653,6 +662,8 @@ require(['vs/editor/editor.main'], function () { input.value = editor.getValue(); }); + autoLayout(editor); + return editor; };