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

dont tokenise JSONata

- monaco has jsonata tokeniser
This commit is contained in:
Steve-Mcl 2021-04-29 18:11:47 +01:00
parent c475536388
commit df7aa3339b

View File

@ -121,73 +121,75 @@
var currentFunctionMarker = null; var currentFunctionMarker = null;
expressionEditor.getSession().setValue(value||"",-1); expressionEditor.getSession().setValue(value||"",-1);
expressionEditor.on("changeSelection", function() { //ace only (monaco has jsonata tokeniser)
var c = expressionEditor.getCursorPosition(); if(expressionEditor.type == "ace") {
var token = expressionEditor.getSession().getTokenAt(c.row,c.column); expressionEditor.on("changeSelection", function() {
if (token !== currentToken || (token && /paren/.test(token.type) && c.column !== currentTokenPos)) { var c = expressionEditor.getCursorPosition();
currentToken = token; var token = expressionEditor.getSession().getTokenAt(c.row,c.column);
var r,p; if (token !== currentToken || (token && /paren/.test(token.type) && c.column !== currentTokenPos)) {
var scopedFunction = null; currentToken = token;
if (token && token.type === 'keyword') { var r,p;
r = c.row; var scopedFunction = null;
scopedFunction = token; if (token && token.type === 'keyword') {
} else {
var depth = 0;
var next = false;
if (token) {
if (token.type === 'paren.rparen') {
// If this is a block of parens ')))', set
// depth to offset against the cursor position
// within the block
currentTokenPos = c.column;
depth = c.column - (token.start + token.value.length);
}
r = c.row; r = c.row;
p = token.index; scopedFunction = token;
} else { } else {
r = c.row-1; var depth = 0;
p = -1; var next = false;
} if (token) {
while ( scopedFunction === null && r > -1) { if (token.type === 'paren.rparen') {
var rowTokens = expressionEditor.getSession().getTokens(r); // If this is a block of parens ')))', set
if (p === -1) { // depth to offset against the cursor position
p = rowTokens.length-1; // within the block
currentTokenPos = c.column;
depth = c.column - (token.start + token.value.length);
}
r = c.row;
p = token.index;
} else {
r = c.row-1;
p = -1;
} }
while (p > -1) { while ( scopedFunction === null && r > -1) {
var type = rowTokens[p].type; var rowTokens = expressionEditor.getSession().getTokens(r);
if (next) { if (p === -1) {
if (type === 'keyword') { p = rowTokens.length-1;
scopedFunction = rowTokens[p]; }
// console.log("HIT",scopedFunction); while (p > -1) {
break; var type = rowTokens[p].type;
if (next) {
if (type === 'keyword') {
scopedFunction = rowTokens[p];
// console.log("HIT",scopedFunction);
break;
}
next = false;
} }
next = false; if (type === 'paren.lparen') {
depth-=rowTokens[p].value.length;
} else if (type === 'paren.rparen') {
depth+=rowTokens[p].value.length;
}
if (depth < 0) {
next = true;
depth = 0;
}
// console.log(r,p,depth,next,rowTokens[p]);
p--;
} }
if (type === 'paren.lparen') { if (!scopedFunction) {
depth-=rowTokens[p].value.length; r--;
} else if (type === 'paren.rparen') {
depth+=rowTokens[p].value.length;
} }
if (depth < 0) {
next = true;
depth = 0;
}
// console.log(r,p,depth,next,rowTokens[p]);
p--;
}
if (!scopedFunction) {
r--;
} }
} }
expressionEditor.session.removeMarker(currentFunctionMarker);
if (scopedFunction) {
//console.log(token,.map(function(t) { return t.type}));
funcSelect.val(scopedFunction.value).trigger("change");
}
} }
expressionEditor.session.removeMarker(currentFunctionMarker); });
if (scopedFunction) { }
//console.log(token,.map(function(t) { return t.type}));
funcSelect.val(scopedFunction.value).trigger("change");
}
}
});
dialogForm.i18n(); dialogForm.i18n();
$("#red-ui-editor-type-expression-func-insert").on("click", function(e) { $("#red-ui-editor-type-expression-func-insert").on("click", function(e) {
e.preventDefault(); e.preventDefault();