mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
www/codemirror/fhem.js: Autocomplete fix by papa, forum #20444
git-svn-id: https://svn.fhem.de/fhem/trunk@11276 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
a3adb233c7
commit
8bbbaf0b36
@ -1,5 +1,3 @@
|
|||||||
/* $Id$ */
|
|
||||||
|
|
||||||
CodeMirror.defineMode("fhem",function(){function d(a,c,d,f,b){c.chain=null;c.style=null;c.tail=null;c.tokenize=function(a,c){for(var h=!1,l,k=0;l=a.next();){if(l===d[k]&&!h){void 0!==d[++k]?(c.chain=d[k],c.style=f,c.tail=b):b&&a.eatWhile(b);c.tokenize=n;break}h=!h&&"\\"==l}return f};return c.tokenize(a,c)}function h(a,c,d){c.tokenize=function(a,b){a.string==d&&(b.tokenize=n);a.skipToEnd();return"string"};return c.tokenize(a,c)}function n(a,c){if(a.eatSpace())return null;if(c.chain)return d(a,c,c.chain,
|
CodeMirror.defineMode("fhem",function(){function d(a,c,d,f,b){c.chain=null;c.style=null;c.tail=null;c.tokenize=function(a,c){for(var h=!1,l,k=0;l=a.next();){if(l===d[k]&&!h){void 0!==d[++k]?(c.chain=d[k],c.style=f,c.tail=b):b&&a.eatWhile(b);c.tokenize=n;break}h=!h&&"\\"==l}return f};return c.tokenize(a,c)}function h(a,c,d){c.tokenize=function(a,b){a.string==d&&(b.tokenize=n);a.skipToEnd();return"string"};return c.tokenize(a,c)}function n(a,c){if(a.eatSpace())return null;if(c.chain)return d(a,c,c.chain,
|
||||||
c.style,c.tail);if(a.match(/^\-?[\d\.]/,!1)&&a.match(/^(\-?(\d*\.\d+(e[+-]?\d+)?|\d+\.\d*)|0x[\da-fA-F]+|0b[01]+|\d+(e[+-]?\d+)?)/))return"number";if(a.match(/^<<(?=\w)/))return a.eatWhile(/\w/),h(a,c,a.current().substr(2));if(a.sol()&&a.match(/^\=item(?!\w)/))return h(a,c,"=cut");var g=a.next();if('"'==g||"'"==g){if(a.prefix(3)=="<<"+g){var m=a.pos;a.eatWhile(/\w/);var b=a.current().substr(1);if(b&&a.eat(g))return h(a,c,b);a.pos=m}return d(a,c,[g],"string")}if("q"==g&&(b=a.look(-2),!b||!/\w/.test(b)))if(b=
|
c.style,c.tail);if(a.match(/^\-?[\d\.]/,!1)&&a.match(/^(\-?(\d*\.\d+(e[+-]?\d+)?|\d+\.\d*)|0x[\da-fA-F]+|0b[01]+|\d+(e[+-]?\d+)?)/))return"number";if(a.match(/^<<(?=\w)/))return a.eatWhile(/\w/),h(a,c,a.current().substr(2));if(a.sol()&&a.match(/^\=item(?!\w)/))return h(a,c,"=cut");var g=a.next();if('"'==g||"'"==g){if(a.prefix(3)=="<<"+g){var m=a.pos;a.eatWhile(/\w/);var b=a.current().substr(1);if(b&&a.eat(g))return h(a,c,b);a.pos=m}return d(a,c,[g],"string")}if("q"==g&&(b=a.look(-2),!b||!/\w/.test(b)))if(b=
|
||||||
a.look(0),"x"==b){b=a.look(1);if("("==b)return a.eatSuffix(2),d(a,c,[")"],"string-2",f);if("["==b)return a.eatSuffix(2),d(a,c,["]"],"string-2",f);if("{"==b)return a.eatSuffix(2),d(a,c,["}"],"string-2",f);if("<"==b)return a.eatSuffix(2),d(a,c,[">"],"string-2",f);if(/[\^'"!~\/]/.test(b))return a.eatSuffix(1),d(a,c,[a.eat(b)],"string-2",f)}else if("q"==b){b=a.look(1);if("("==b)return a.eatSuffix(2),d(a,c,[")"],"string");if("["==b)return a.eatSuffix(2),d(a,c,["]"],"string");if("{"==b)return a.eatSuffix(2),
|
a.look(0),"x"==b){b=a.look(1);if("("==b)return a.eatSuffix(2),d(a,c,[")"],"string-2",f);if("["==b)return a.eatSuffix(2),d(a,c,["]"],"string-2",f);if("{"==b)return a.eatSuffix(2),d(a,c,["}"],"string-2",f);if("<"==b)return a.eatSuffix(2),d(a,c,[">"],"string-2",f);if(/[\^'"!~\/]/.test(b))return a.eatSuffix(1),d(a,c,[a.eat(b)],"string-2",f)}else if("q"==b){b=a.look(1);if("("==b)return a.eatSuffix(2),d(a,c,[")"],"string");if("["==b)return a.eatSuffix(2),d(a,c,["]"],"string");if("{"==b)return a.eatSuffix(2),
|
||||||
@ -24,7 +22,7 @@ CodeMirror.StringStream.prototype.nsuffix=function(d){var h=this.pos;d=d||this.s
|
|||||||
var keywords="at attr define delete deleteattr deletereading IF DOIF DOELSEIF DOELSE displayattr fhem get getstate list modify notify set setdefaultattr setreading setstate trigger AttrVal OldTimestamp OldValue ReadingsVal ReadingsTimestamp Value".split(" "),variables="$defs $hms $hour $isdst $mday $min $month $sec $wday $we $yday $year".split(" "),devices=[];
|
var keywords="at attr define delete deleteattr deletereading IF DOIF DOELSEIF DOELSE displayattr fhem get getstate list modify notify set setdefaultattr setreading setstate trigger AttrVal OldTimestamp OldValue ReadingsVal ReadingsTimestamp Value".split(" "),variables="$defs $hms $hour $isdst $mday $min $month $sec $wday $we $yday $year".split(" "),devices=[];
|
||||||
CodeMirror.registerHelper("hint","fhem",function hintfhem(h,n,p){function f(a){var b=[];null!=a&&(a.PossibleAttrs.split(" ").foreach(function(a,c){b.push(c.split(":")[0])}),b.sort(function(a,b){return a.toLowerCase().localeCompare(b.toLowerCase())}));return b}function a(a){var b=[];null!=a&&(a.PossibleSets.split(" ").foreach(function(a,c){b.push(c.split(":")[0])}),b.sort(function(a,b){return a.toLowerCase().localeCompare(b.toLowerCase())}));return b}function c(a){var b=[];if(null!=a){for(var c in a.Readings)b.push(c);
|
CodeMirror.registerHelper("hint","fhem",function hintfhem(h,n,p){function f(a){var b=[];null!=a&&(a.PossibleAttrs.split(" ").foreach(function(a,c){b.push(c.split(":")[0])}),b.sort(function(a,b){return a.toLowerCase().localeCompare(b.toLowerCase())}));return b}function a(a){var b=[];null!=a&&(a.PossibleSets.split(" ").foreach(function(a,c){b.push(c.split(":")[0])}),b.sort(function(a,b){return a.toLowerCase().localeCompare(b.toLowerCase())}));return b}function c(a){var b=[];if(null!=a){for(var c in a.Readings)b.push(c);
|
||||||
b.sort(function(a,b){return a.toLowerCase().localeCompare(b.toLowerCase())})}return b}function g(a,b){var c=0,e=a.length-1,f=Math.floor((e+c)/2),g=null;for(b=b.toLowerCase();(g=a[f].Name.toLowerCase())!=b&&c<e;)b<g?e=f-1:b>g&&(c=f+1),f=Math.floor((e+c)/2);return g!=b?null:a[f]}function m(a,b,c,e){var f=[];a.foreach(function(a,b){0==b.lastIndexOf(e,0)&&f.push({text:b,className:"hintkeyword"})});b.foreach(function(a,b){0==b.Name.lastIndexOf(e,0)&&(b.Attributes&&null!=b.Attributes.alias?f.push({text:b.Name,
|
b.sort(function(a,b){return a.toLowerCase().localeCompare(b.toLowerCase())})}return b}function g(a,b){var c=0,e=a.length-1,f=Math.floor((e+c)/2),g=null;for(b=b.toLowerCase();(g=a[f].Name.toLowerCase())!=b&&c<e;)b<g?e=f-1:b>g&&(c=f+1),f=Math.floor((e+c)/2);return g!=b?null:a[f]}function m(a,b,c,e){var f=[];a.foreach(function(a,b){0==b.lastIndexOf(e,0)&&f.push({text:b,className:"hintkeyword"})});b.foreach(function(a,b){0==b.Name.lastIndexOf(e,0)&&(b.Attributes&&null!=b.Attributes.alias?f.push({text:b.Name,
|
||||||
displayText:b.Name+" # "+b.Attributes.alias}):f.push(b.Name))});c.foreach(function(a,b){0==b.lastIndexOf(e,0)&&f.push({text:b,className:"hintvariable"})});n({list:f,from:CodeMirror.Pos(t.line,u),to:CodeMirror.Pos(t.line,r)})}if(0==devices.length)$.getJSON("/fhem?cmd=jsonlist2&XHR=1",function(a){0==devices.length&&(a.Results.foreach(function(a,b){devices.push(b)}),devices.sort(function(a,b){return a.Name.toLowerCase().localeCompare(b.Name.toLowerCase())}),hintfhem(h,n,p))});else{var b=keywords,e=variables,
|
displayText:b.Name+" # "+b.Attributes.alias}):f.push(b.Name))});c.foreach(function(a,b){0==b.lastIndexOf(e,0)&&f.push({text:b,className:"hintvariable"})});n({list:f,from:CodeMirror.Pos(u.line,t),to:CodeMirror.Pos(u.line,r)})}if(0==devices.length)$.getJSON("/fhem?cmd=jsonlist2&XHR=1",function(a){0==devices.length&&(a.Results.foreach(function(a,b){devices.push(b)}),devices.sort(function(a,b){return a.Name.toLowerCase().localeCompare(b.Name.toLowerCase())}),hintfhem(h,n,p))});else{var b=keywords,e=variables,
|
||||||
q=devices,t=h.getCursor(),l=h.getTokenAt(t),k=l.string,u=l.start,r=l.end;/[^\w$_-]/.test(k)&&(k="",u=r=t.ch);l=h.getLine(t.line).substr(0,r);/^[ \t]*(attr|set|get|delete|deleteattr|deletereading|displayattr|getstate|list|modify|setdefaultattr|setreading|setstate|trigger)[ \t]+([\w]*)$/.test(l)?b=e=[]:/^[ \t]*(attr|deleteattr|displayattr)[ \t]+(\w+)[ \t]+([\w-]*)$/.test(l)?(b=q=e=[],e=RegExp.$2,k=RegExp.$3,e=g(devices,e),e=f(e)):/^[ \t]*(DOIF|DOELSE|DOELSEIF).*\[+\??(\w+):\??([\w-]*)$/.test(l)?(b=
|
q=devices,u=h.getCursor(),l=h.getTokenAt(u),k=l.string,t=l.start,r=l.end;/[^\w$_-]/.test(k)&&(k="",t=r=u.ch);l=h.getLine(u.line).substr(0,r);/([\w_\.]+)$/.test(l)&&(k=RegExp.$1,t=r-k.length);/^[ \t]*(attr|set|get|delete|deleteattr|deletereading|displayattr|getstate|list|modify|setdefaultattr|setreading|setstate|trigger)[ \t]+([\w_\.]+)$/.test(l)?b=e=[]:/^[ \t]*(attr|deleteattr|displayattr)[ \t]+([\w_\.]+)[ \t]+([\w-]*)$/.test(l)?(b=q=e=[],e=RegExp.$2,k=RegExp.$3,e=g(devices,e),e=f(e)):/^[ \t]*(DOIF|DOELSE|DOELSEIF).*\[+\??([\w_\.]+):\??([\w-]*)$/.test(l)?
|
||||||
q=e=[],e=RegExp.$2,k=RegExp.$3,e=g(devices,e),e=c(e)):/^[ \t]*(deletereading|setreading)[ \t]+(\w+)[ \t]+([\w-]*)$/.test(l)?(b=q=e=[],e=RegExp.$2,k=RegExp.$3,e=g(devices,e),e=c(e)):/^[ \t]*(set|get)[ \t]+(\w+)[ \t]+([\w-]*)$/.test(l)?(b=q=e=[],e=RegExp.$2,k=RegExp.$3,e=g(devices,e),e=a(e)):/.*(AttrVal)[ \t]*\([ \t]*\"(\w+)\"[ \t]*,[ \t]*\"([\w-]*)$/.test(l)?(b=q=e=[],e=RegExp.$2,k=RegExp.$3,u=r-k.length,e=g(devices,e),e=f(e)):/.*(ReadingsVal|ReadingsTimestamp)[ \t]*\([ \t]*\"(\w+)\"[ \t]*,[ \t]*\"([\w-]*)$/.test(l)?
|
(b=q=e=[],e=RegExp.$2,k=RegExp.$3,e=g(devices,e),e=c(e)):/^[ \t]*(deletereading|setreading)[ \t]+([\w_\.]+)[ \t]+([\w-]*)$/.test(l)?(b=q=e=[],e=RegExp.$2,k=RegExp.$3,e=g(devices,e),e=c(e)):/^[ \t]*(set|get)[ \t]+([\w_\.]+)[ \t]+([\w-]*)$/.test(l)?(b=q=e=[],e=RegExp.$2,k=RegExp.$3,e=g(devices,e),e=a(e)):/.*(AttrVal)[ \t]*\([ \t]*\"([\w_\.]+)\"[ \t]*,[ \t]*\"([\w-]*)$/.test(l)?(b=q=e=[],e=RegExp.$2,k=RegExp.$3,t=r-k.length,e=g(devices,e),e=f(e)):/.*(ReadingsVal|ReadingsTimestamp)[ \t]*\([ \t]*\"([\w_\.]+)\"[ \t]*,[ \t]*\"([\w-]*)$/.test(l)?
|
||||||
(b=q=e=[],e=RegExp.$2,k=RegExp.$3,u=r-k.length,e=g(devices,e),e=c(e)):/.*(OldTimestamp|OldValue|Value|ReadingsVal|ReadingsTimestamp|AttrVal)[ \t]*\([ \t]*\"(\w*)$/.test(l)&&(b=e=[],k=RegExp.$2,u=r-k.length);m(b,q,e,k)}});
|
(b=q=e=[],e=RegExp.$2,k=RegExp.$3,t=r-k.length,e=g(devices,e),e=c(e)):/.*(OldTimestamp|OldValue|Value|ReadingsVal|ReadingsTimestamp|AttrVal)[ \t]*\([ \t]*\"([\w_\.]+)$/.test(l)&&(b=e=[],k=RegExp.$2,t=r-k.length);m(b,q,e,k)}});
|
@ -877,12 +877,16 @@ CodeMirror.registerHelper("hint", "fhem", function hintfhem(cm, callback, option
|
|||||||
word = ""; start = end = cur.ch;
|
word = ""; start = end = cur.ch;
|
||||||
}
|
}
|
||||||
var line = cm.getLine(cur.line).substr(0,end);
|
var line = cm.getLine(cur.line).substr(0,end);
|
||||||
|
if( /([\w_\.]+)$/.test(line) ) {
|
||||||
|
word = RegExp.$1;
|
||||||
|
start = end - word.length;
|
||||||
|
}
|
||||||
// only device names
|
// only device names
|
||||||
if( /^[ \t]*(attr|set|get|delete|deleteattr|deletereading|displayattr|getstate|list|modify|setdefaultattr|setreading|setstate|trigger)[ \t]+([\w]*)$/.test(line) ) {
|
if( /^[ \t]*(attr|set|get|delete|deleteattr|deletereading|displayattr|getstate|list|modify|setdefaultattr|setreading|setstate|trigger)[ \t]+([\w_\.]+)$/.test(line) ) {
|
||||||
_key = _var = [];
|
_key = _var = [];
|
||||||
}
|
}
|
||||||
// only device attribute names
|
// only device attribute names
|
||||||
else if( /^[ \t]*(attr|deleteattr|displayattr)[ \t]+(\w+)[ \t]+([\w-]*)$/.test(line) ) {
|
else if( /^[ \t]*(attr|deleteattr|displayattr)[ \t]+([\w_\.]+)[ \t]+([\w-]*)$/.test(line) ) {
|
||||||
_key = _dev = _var = [];
|
_key = _dev = _var = [];
|
||||||
var device = RegExp.$2;
|
var device = RegExp.$2;
|
||||||
word = RegExp.$3;
|
word = RegExp.$3;
|
||||||
@ -890,7 +894,7 @@ CodeMirror.registerHelper("hint", "fhem", function hintfhem(cm, callback, option
|
|||||||
_var = getDeviceAttributes(d);
|
_var = getDeviceAttributes(d);
|
||||||
}
|
}
|
||||||
// only device reading names
|
// only device reading names
|
||||||
else if( /^[ \t]*(DOIF|DOELSE|DOELSEIF).*\[+\??(\w+):\??([\w-]*)$/.test(line) ) {
|
else if( /^[ \t]*(DOIF|DOELSE|DOELSEIF).*\[+\??([\w_\.]+):\??([\w-]*)$/.test(line) ) {
|
||||||
_key = _dev = _var = [];
|
_key = _dev = _var = [];
|
||||||
var device = RegExp.$2;
|
var device = RegExp.$2;
|
||||||
word = RegExp.$3;
|
word = RegExp.$3;
|
||||||
@ -898,7 +902,7 @@ CodeMirror.registerHelper("hint", "fhem", function hintfhem(cm, callback, option
|
|||||||
_var = getDeviceReadings(d);
|
_var = getDeviceReadings(d);
|
||||||
}
|
}
|
||||||
// only device reading names
|
// only device reading names
|
||||||
else if( /^[ \t]*(deletereading|setreading)[ \t]+(\w+)[ \t]+([\w-]*)$/.test(line) ) {
|
else if( /^[ \t]*(deletereading|setreading)[ \t]+([\w_\.]+)[ \t]+([\w-]*)$/.test(line) ) {
|
||||||
_key = _dev = _var = [];
|
_key = _dev = _var = [];
|
||||||
var device = RegExp.$2;
|
var device = RegExp.$2;
|
||||||
word = RegExp.$3;
|
word = RegExp.$3;
|
||||||
@ -906,7 +910,7 @@ CodeMirror.registerHelper("hint", "fhem", function hintfhem(cm, callback, option
|
|||||||
_var = getDeviceReadings(d);
|
_var = getDeviceReadings(d);
|
||||||
}
|
}
|
||||||
// only device sets names
|
// only device sets names
|
||||||
else if( /^[ \t]*(set|get)[ \t]+(\w+)[ \t]+([\w-]*)$/.test(line) ) {
|
else if( /^[ \t]*(set|get)[ \t]+([\w_\.]+)[ \t]+([\w-]*)$/.test(line) ) {
|
||||||
_key = _dev = _var = [];
|
_key = _dev = _var = [];
|
||||||
var device = RegExp.$2;
|
var device = RegExp.$2;
|
||||||
word = RegExp.$3;
|
word = RegExp.$3;
|
||||||
@ -914,7 +918,7 @@ CodeMirror.registerHelper("hint", "fhem", function hintfhem(cm, callback, option
|
|||||||
_var = getDeviceSets(d);
|
_var = getDeviceSets(d);
|
||||||
}
|
}
|
||||||
// only device attribute names
|
// only device attribute names
|
||||||
else if( /.*(AttrVal)[ \t]*\([ \t]*\"(\w+)\"[ \t]*,[ \t]*\"([\w-]*)$/.test(line) ) {
|
else if( /.*(AttrVal)[ \t]*\([ \t]*\"([\w_\.]+)\"[ \t]*,[ \t]*\"([\w-]*)$/.test(line) ) {
|
||||||
_key = _dev = _var = [];
|
_key = _dev = _var = [];
|
||||||
var device = RegExp.$2;
|
var device = RegExp.$2;
|
||||||
word = RegExp.$3;
|
word = RegExp.$3;
|
||||||
@ -923,7 +927,7 @@ CodeMirror.registerHelper("hint", "fhem", function hintfhem(cm, callback, option
|
|||||||
_var = getDeviceAttributes(d);
|
_var = getDeviceAttributes(d);
|
||||||
}
|
}
|
||||||
// only device readings names
|
// only device readings names
|
||||||
else if( /.*(ReadingsVal|ReadingsTimestamp)[ \t]*\([ \t]*\"(\w+)\"[ \t]*,[ \t]*\"([\w-]*)$/.test(line) ) {
|
else if( /.*(ReadingsVal|ReadingsTimestamp)[ \t]*\([ \t]*\"([\w_\.]+)\"[ \t]*,[ \t]*\"([\w-]*)$/.test(line) ) {
|
||||||
_key = _dev = _var = [];
|
_key = _dev = _var = [];
|
||||||
var device = RegExp.$2;
|
var device = RegExp.$2;
|
||||||
word = RegExp.$3;
|
word = RegExp.$3;
|
||||||
@ -932,7 +936,7 @@ CodeMirror.registerHelper("hint", "fhem", function hintfhem(cm, callback, option
|
|||||||
_var = getDeviceReadings(d);
|
_var = getDeviceReadings(d);
|
||||||
}
|
}
|
||||||
// only device names
|
// only device names
|
||||||
else if( /.*(OldTimestamp|OldValue|Value|ReadingsVal|ReadingsTimestamp|AttrVal)[ \t]*\([ \t]*\"(\w*)$/.test(line) ) {
|
else if( /.*(OldTimestamp|OldValue|Value|ReadingsVal|ReadingsTimestamp|AttrVal)[ \t]*\([ \t]*\"([\w_\.]+)$/.test(line) ) {
|
||||||
_key = _var = [];
|
_key = _var = [];
|
||||||
word = RegExp.$2;
|
word = RegExp.$2;
|
||||||
start = end - word.length;
|
start = end - word.length;
|
||||||
|
Loading…
Reference in New Issue
Block a user