1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add insert-function button to expression editor

This commit is contained in:
Nick O'Leary 2016-11-16 14:54:51 +00:00
parent 8caee09ea4
commit eeaff6b553
5 changed files with 21 additions and 7 deletions

View File

@ -167,7 +167,8 @@ module.exports = function(grunt) {
'public/red/main.min.js': 'public/red/main.js', 'public/red/main.min.js': 'public/red/main.js',
'public/vendor/jsonata/jsonata.min.js': 'public/vendor/jsonata/jsonata.js', 'public/vendor/jsonata/jsonata.min.js': 'public/vendor/jsonata/jsonata.js',
'public/vendor/ace/mode-jsonata.js': 'editor/vendor/jsonata/mode-jsonata.js', 'public/vendor/ace/mode-jsonata.js': 'editor/vendor/jsonata/mode-jsonata.js',
'public/vendor/ace/worker-jsonata.js': 'editor/vendor/jsonata/worker-jsonata.js' 'public/vendor/ace/worker-jsonata.js': 'editor/vendor/jsonata/worker-jsonata.js',
'public/vendor/ace/snippets/jsonata.js': 'editor/vendor/jsonata/snippets-jsonata.js'
} }
} }
}, },

View File

@ -1421,7 +1421,7 @@ RED.editor = (function() {
funcSelect.change(function(e) { funcSelect.change(function(e) {
var f = $(this).val(); var f = $(this).val();
var args = RED._('jsonata:'+f+".args",{defaultValue:''}); var args = RED._('jsonata:'+f+".args",{defaultValue:''});
var title = "<h4>"+f+"("+args+")</h4>"; var title = "<h5>"+f+"("+args+")</h5>";
var body = marked(RED._('jsonata:'+f+'.desc',{defaultValue:''})); var body = marked(RED._('jsonata:'+f+'.desc',{defaultValue:''}));
$("#node-input-expression-help").html(title+"<p>"+body+"</p>"); $("#node-input-expression-help").html(title+"<p>"+body+"</p>");
@ -1432,7 +1432,7 @@ RED.editor = (function() {
mode:"ace/mode/jsonata", mode:"ace/mode/jsonata",
options: { options: {
enableBasicAutocompletion:true, enableBasicAutocompletion:true,
enableSnippets:false, enableSnippets:true,
enableLiveAutocompletion: true enableLiveAutocompletion: true
} }
}); });
@ -1441,14 +1441,23 @@ RED.editor = (function() {
expressionEditor.on("changeSelection", function() { expressionEditor.on("changeSelection", function() {
var c = expressionEditor.getCursorPosition(); var c = expressionEditor.getCursorPosition();
var token = expressionEditor.getSession().getTokenAt(c.row,c.column); var token = expressionEditor.getSession().getTokenAt(c.row,c.column);
//console.log(token); // console.log(token);
if (token && token.type === 'keyword') { if (token && token.type === 'keyword') {
funcSelect.val(token.value).change(); funcSelect.val(token.value).change();
} }
}); });
dialogForm.i18n(); dialogForm.i18n();
$("#node-input-expression-func-insert").click(function(e) {
e.preventDefault();
var pos = expressionEditor.getCursorPosition();
var f = funcSelect.val();
var args = RED._('jsonata:'+f+".args",{defaultValue:''});
expressionEditor.insert(f+"("+args+")");
pos.column += f.length+1;
expressionEditor.moveCursorToPosition(pos);
expressionEditor.focus();
})
}, },
close: function() { close: function() {
editStack.pop(); editStack.pop();

View File

@ -166,7 +166,7 @@
<div class="form-row"> <div class="form-row">
<label for="node-input-expression-func" data-i18n="expressionEditor.functions"></label> <label for="node-input-expression-func" data-i18n="expressionEditor.functions"></label>
<select id="node-input-expression-func"></select> <select id="node-input-expression-func"></select>
<button id="node-input-expression-func-insert" class="editor-button" data-i18n="expressionEditor.insert"></button>
<div style="min-height: 200px;" id="node-input-expression-help"></div> <div style="min-height: 200px;" id="node-input-expression-help"></div>
</div> </div>
</script> </script>

View File

@ -2788,6 +2788,9 @@ var jsonata = (function() {
}, },
assign: function (name, value) { assign: function (name, value) {
environment.bind(name, value); environment.bind(name, value);
},
ast: function() {
return ast;
} }
}; };
} }

View File

@ -320,6 +320,7 @@
"empty": "No matches found" "empty": "No matches found"
}, },
"expressionEditor": { "expressionEditor": {
"functions": "Functions" "functions": "Functions",
"insert": "Insert"
} }
} }