Skip to content

Support for monaco in node-red 2.0.0 #15

@Steve-Mcl

Description

@Steve-Mcl

Hi,

node-red 2.0.0 has a new additional editor - see here : https://discourse.nodered.org/t/node-red-2-0-0-beta-1-released/46990

It can be enabled in settings.js as described in the post.

However, as your node does not use the built in API to build the code editor, your node continues to use the ACE editor.

If you wish to support the users choice, you can fix this up be doing the following...

in oneditprepare, replace all of this...

            var langTools = ace.require('ace/ext/language_tools');
            this.editor = ace.edit('node-input-func-editor');
            this.editor.setTheme('ace/theme/tomorrow');
            this.editor.getSession().setMode('ace/mode/python');
            this.editor.setValue($("#node-input-func").val(), -1);
            this.editor.setOptions({
                    enableBasicAutocompletion: true,
                    enableLiveAutocompletion: true,
                    highlightSelectedWord: true,
                    useSoftTabs: true,
                    tabSize: 4,
            });
            var noderedKeywords = [
                'msg', 'msg.payload', 'node', 'node.send',
                'node.log', 'node.warn', 'node.error', 'node.status'
            ];
            this.editor.completers.push({
                getCompletions: function (state, session, pos, prefix, callback) {
                    callback(null, noderedKeywords.map(function (word) {
                        return {
                            name: word,
                            value: word,
                            score: 0,
                            meta: 'Node-RED'
                        };
                    }));
                }
            });
            this.editor = RED.editor.createEditor({
                id: 'node-input-func-editor',
                mode: 'ace/mode/python',
                value: $("#node-input-func").val()
            });

and in oneditsave change the line delete this.editor; to this.editor.destroy();


NOTES:
At present, the Monaco editor only does syntax highlighting for python (same as ACE editor) but I will eventually be adding python snippets like this...
OHlvtdO17c

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions