mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
prevent promise rejection when loading editor
This commit is contained in:
parent
db90e1f801
commit
04d91d1422
@ -737,6 +737,15 @@ RED.editor.codeEditor.monaco = (function() {
|
||||
var editorOptions = $.extend({}, editorSettings.options, options);
|
||||
editorOptions.language = convertAceModeToMonacoLang(options.mode);
|
||||
|
||||
//by default, set javascript editors to text mode.
|
||||
//when element becomes visible, it will be (re) set to javascript mode
|
||||
//this is to ensure multiple editors sharing the model dont present its
|
||||
//consts & lets to each other
|
||||
if(editorOptions.language == "javascript") {
|
||||
editorOptions._language = editorOptions.language;
|
||||
editorOptions.language = "text"
|
||||
}
|
||||
|
||||
//apply defaults
|
||||
if (!editorOptions.minimap) {
|
||||
editorOptions.minimap = {
|
||||
@ -935,7 +944,9 @@ RED.editor.codeEditor.monaco = (function() {
|
||||
var oldSelections = ed.getSelections();
|
||||
var oldPosition = ed.getPosition();
|
||||
oldValue = oldModel.getValue() || "";
|
||||
if(!oldModel.isDisposed()) { oldModel.dispose(); }
|
||||
try {
|
||||
if(!oldModel.isDisposed()) { oldModel.dispose(); }
|
||||
} catch (error) { }
|
||||
ed.setModel(null);
|
||||
newModel = monaco.editor.createModel((oldValue || ""), mode);
|
||||
ed.setModel(newModel);
|
||||
@ -1190,16 +1201,20 @@ RED.editor.codeEditor.monaco = (function() {
|
||||
|
||||
//as models are signleton, consts and let are avialable to other javascript instances
|
||||
//so when not focused, set editor mode to text temporarily to avoid multiple defs
|
||||
|
||||
|
||||
|
||||
if(editorOptions._language) {
|
||||
ed._mode = editorOptions._language;
|
||||
ed._tempMode = editorOptions.language;
|
||||
}
|
||||
|
||||
ed.onDidBlurEditorWidget(function() {
|
||||
if(isVisible(el) == false) {
|
||||
onVisibilityChange(false);
|
||||
onVisibilityChange(false, 0, el);
|
||||
}
|
||||
});
|
||||
|
||||
ed.onDidFocusEditorWidget(function() {
|
||||
onVisibilityChange(true, 10);
|
||||
onVisibilityChange(true, 10, el);
|
||||
});
|
||||
|
||||
function visibilityWatcher(element, callback) {
|
||||
@ -1211,7 +1226,7 @@ RED.editor.codeEditor.monaco = (function() {
|
||||
};
|
||||
var observer = new IntersectionObserver(function(entries, observer) {
|
||||
entries.forEach(function(entry) {
|
||||
callback(entry.intersectionRatio > 0, 5, entry);
|
||||
callback(entry.intersectionRatio > 0, 5, entry.target);
|
||||
});
|
||||
}, options);
|
||||
observer.observe(element);
|
||||
@ -1222,7 +1237,7 @@ RED.editor.codeEditor.monaco = (function() {
|
||||
watchTimer = setInterval(function() {
|
||||
let elVisible = isVisible(el);
|
||||
if(elVisible != elVisibleMem) {
|
||||
callback(elVisible, 100, element);
|
||||
callback(elVisible, 5, element);
|
||||
}
|
||||
elVisibleMem = elVisible;
|
||||
}, 100);
|
||||
@ -1235,13 +1250,13 @@ RED.editor.codeEditor.monaco = (function() {
|
||||
if(ed._mode == "javascript" && ed._tempMode == "text") {
|
||||
ed._tempMode = "";
|
||||
setTimeout(function() {
|
||||
if(el.parentElement) { //ensure el is still in DOM
|
||||
if(element.parentElement) { //ensure el is still in DOM
|
||||
ed.setMode('javascript', undefined, false);
|
||||
}
|
||||
}, delay);
|
||||
}, delay || 50);
|
||||
}
|
||||
} else if(ed._mode == "javascript") {
|
||||
if(el.parentElement) { //ensure el is still in DOM
|
||||
} else if(ed._mode == "javascript" && ed._tempMode != "text") {
|
||||
if(element.parentElement) { //ensure el is still in DOM
|
||||
ed.setMode('text', undefined, false);
|
||||
ed._tempMode = "text";
|
||||
}
|
||||
@ -1250,14 +1265,6 @@ RED.editor.codeEditor.monaco = (function() {
|
||||
|
||||
visibilityWatcher(el, onVisibilityChange);
|
||||
|
||||
//by default, set javascript editors to text mode.
|
||||
//when elemt becomes visible, it will be (re) set to javascript mode
|
||||
//this is to ensure multiple editors sharing the model dont presnet its
|
||||
//consts & lets to each other
|
||||
if(ed._mode == "javascript") {
|
||||
ed.setMode('text', undefined, false);
|
||||
ed._tempMode = "text";
|
||||
}
|
||||
|
||||
if (editorOptions.language === 'markdown') {
|
||||
$(el).addClass("red-ui-editor-text-container-toolbar");
|
||||
|
Loading…
Reference in New Issue
Block a user