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);
|
var editorOptions = $.extend({}, editorSettings.options, options);
|
||||||
editorOptions.language = convertAceModeToMonacoLang(options.mode);
|
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
|
//apply defaults
|
||||||
if (!editorOptions.minimap) {
|
if (!editorOptions.minimap) {
|
||||||
editorOptions.minimap = {
|
editorOptions.minimap = {
|
||||||
@ -935,7 +944,9 @@ RED.editor.codeEditor.monaco = (function() {
|
|||||||
var oldSelections = ed.getSelections();
|
var oldSelections = ed.getSelections();
|
||||||
var oldPosition = ed.getPosition();
|
var oldPosition = ed.getPosition();
|
||||||
oldValue = oldModel.getValue() || "";
|
oldValue = oldModel.getValue() || "";
|
||||||
|
try {
|
||||||
if(!oldModel.isDisposed()) { oldModel.dispose(); }
|
if(!oldModel.isDisposed()) { oldModel.dispose(); }
|
||||||
|
} catch (error) { }
|
||||||
ed.setModel(null);
|
ed.setModel(null);
|
||||||
newModel = monaco.editor.createModel((oldValue || ""), mode);
|
newModel = monaco.editor.createModel((oldValue || ""), mode);
|
||||||
ed.setModel(newModel);
|
ed.setModel(newModel);
|
||||||
@ -1191,15 +1202,19 @@ RED.editor.codeEditor.monaco = (function() {
|
|||||||
//as models are signleton, consts and let are avialable to other javascript instances
|
//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
|
//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() {
|
ed.onDidBlurEditorWidget(function() {
|
||||||
if(isVisible(el) == false) {
|
if(isVisible(el) == false) {
|
||||||
onVisibilityChange(false);
|
onVisibilityChange(false, 0, el);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ed.onDidFocusEditorWidget(function() {
|
ed.onDidFocusEditorWidget(function() {
|
||||||
onVisibilityChange(true, 10);
|
onVisibilityChange(true, 10, el);
|
||||||
});
|
});
|
||||||
|
|
||||||
function visibilityWatcher(element, callback) {
|
function visibilityWatcher(element, callback) {
|
||||||
@ -1211,7 +1226,7 @@ RED.editor.codeEditor.monaco = (function() {
|
|||||||
};
|
};
|
||||||
var observer = new IntersectionObserver(function(entries, observer) {
|
var observer = new IntersectionObserver(function(entries, observer) {
|
||||||
entries.forEach(function(entry) {
|
entries.forEach(function(entry) {
|
||||||
callback(entry.intersectionRatio > 0, 5, entry);
|
callback(entry.intersectionRatio > 0, 5, entry.target);
|
||||||
});
|
});
|
||||||
}, options);
|
}, options);
|
||||||
observer.observe(element);
|
observer.observe(element);
|
||||||
@ -1222,7 +1237,7 @@ RED.editor.codeEditor.monaco = (function() {
|
|||||||
watchTimer = setInterval(function() {
|
watchTimer = setInterval(function() {
|
||||||
let elVisible = isVisible(el);
|
let elVisible = isVisible(el);
|
||||||
if(elVisible != elVisibleMem) {
|
if(elVisible != elVisibleMem) {
|
||||||
callback(elVisible, 100, element);
|
callback(elVisible, 5, element);
|
||||||
}
|
}
|
||||||
elVisibleMem = elVisible;
|
elVisibleMem = elVisible;
|
||||||
}, 100);
|
}, 100);
|
||||||
@ -1235,13 +1250,13 @@ RED.editor.codeEditor.monaco = (function() {
|
|||||||
if(ed._mode == "javascript" && ed._tempMode == "text") {
|
if(ed._mode == "javascript" && ed._tempMode == "text") {
|
||||||
ed._tempMode = "";
|
ed._tempMode = "";
|
||||||
setTimeout(function() {
|
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);
|
ed.setMode('javascript', undefined, false);
|
||||||
}
|
}
|
||||||
}, delay);
|
}, delay || 50);
|
||||||
}
|
}
|
||||||
} else if(ed._mode == "javascript") {
|
} else if(ed._mode == "javascript" && ed._tempMode != "text") {
|
||||||
if(el.parentElement) { //ensure el is still in DOM
|
if(element.parentElement) { //ensure el is still in DOM
|
||||||
ed.setMode('text', undefined, false);
|
ed.setMode('text', undefined, false);
|
||||||
ed._tempMode = "text";
|
ed._tempMode = "text";
|
||||||
}
|
}
|
||||||
@ -1250,14 +1265,6 @@ RED.editor.codeEditor.monaco = (function() {
|
|||||||
|
|
||||||
visibilityWatcher(el, onVisibilityChange);
|
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') {
|
if (editorOptions.language === 'markdown') {
|
||||||
$(el).addClass("red-ui-editor-text-container-toolbar");
|
$(el).addClass("red-ui-editor-text-container-toolbar");
|
||||||
|
Loading…
Reference in New Issue
Block a user