2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2024-11-22 09:49:50 +00:00

codemirror: update

git-svn-id: https://svn.fhem.de/fhem/trunk@27535 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
betateilchen 2023-05-08 16:47:46 +00:00
parent baccd791f4
commit 1ba6d21ef1
5 changed files with 110 additions and 35 deletions

File diff suppressed because one or more lines are too long

View File

@ -233,6 +233,35 @@ CodeMirror.defineMode("fhem",function(){
'$[' : 5,
'$OLD_PERL_VERSION' : 5,
'$]' : 5,
'$_blockingcalls' : 5,
'$SELF' : 5,
'$cmd' : 5,
'$DEVICE' : 5,
'$device' : 5,
'$EVENT' : 5,
'$event' : 5,
'$EVENTS' : 5,
'$events' : 5,
'$number' : 5,
'$name' : 5,
'$TYPE' : 5,
'$STATE' : 5,
'$room' : 5,
'$group' : 5,
'$week' : 5,
'$hm' : 5,
'$md' : 5,
'$ymd' : 5,
'$twe' : 5,
'$TABLE' : 5,
'$TD' : 5,
'$TR' : 5,
'$TC' : 5,
'$TPL' : 5,
'$ATTRIBUTESFIRST' : 5,
'$SHOWNOSTATE' : 5,
'$SHOWNODEVICELINE' : 5,
'$SHOWNODEVICELINK' : 5,
// PERL blocks
'if' :[1,1],
elsif :[1,1],
@ -471,6 +500,11 @@ CodeMirror.defineMode("fhem",function(){
notify :2,
set :2,
ReadingsVal :1,
OldReadingsVal :1,
ReadingsNum :1,
OldReadingsNum :1,
ReadingsTimestamp :1,
OldReadingsTimestamp :1,
Value :1,
fhem :1,
IF :2,
@ -845,16 +879,26 @@ CodeMirror.commands.autocomplete = function(cm) {
CodeMirror.showHint(cm, CodeMirror.hint.fhem, {async:true});
}
var keywords = ["at","attr","define","defmod","delete","deleteattr","deletereading","IF","DOIF","DOELSEIF","DOELSE","displayattr","fhem","get","getstate",
var keywords = ["at","attr","define","defmod","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"];
var variables = ["$defs","$hms","$hour","$isdst","$mday","$min","$month","$sec","$wday","$we","$yday","$year"];
"AttrVal","OldTimestamp","OldValue","ReadingsVal","ReadingsNum","ReadingsTimestamp",
"Value","set_State","get_State","set_Reading","get_Reading","set_Event","set_Exec",
"get_Exec","del_Exec","fhem_set","set_Event","set_Reading_Begin","set_Reading_Update",
"set_Reading_End","subs","init","WID","STY","PUP","IMPORT"];
var variables = ["$defs","$hms","$hour","$isdst","$mday","$min","$month","$sec","$wday",
"$we","$yday","$year",
"$_blockingcalls","$SELF","$cmd","$DEVICE","$device","$EVENT","$event","$EVENTS",
"$events","$number","$name","$TYPE","$STATE","$room","$group","$week","$hm","$md",
"$ymd","$twe","$TABLE","$TD","$TR","$TC","$TPL","$ATTRIBUTESFIRST","$SHOWNOSTATE",
"$SHOWNODEVICELINE","$SHOWNODEVICELINK"];
var devices = [];
CodeMirror.registerHelper("hint", "fhem", function hintfhem(cm, callback, options) {
if( devices.length == 0 ) {
$.getJSON( '/fhem?cmd=jsonlist2&XHR=1', function ( data ) {
$.getJSON( '/fhem?cmd=jsonlist2$FW_CSRF', function ( data ) {
if( devices.length == 0 ) {
data.Results.foreach( function(k,v) {
devices.push(v);
@ -928,7 +972,7 @@ CodeMirror.registerHelper("hint", "fhem", function hintfhem(cm, callback, option
_var = getDeviceAttributes(d);
}
// only device readings names
else if( /.*(ReadingsVal|ReadingsTimestamp)[ \t]*\([ \t]*\"([\w_\.]+)\"[ \t]*,[ \t]*\"([\w-]*)$/.test(line) ) {
else if( /.*(^OldReadingsVal|^OldReadingsNum|^OldReadingsTimestamp|^ReadingsVal|^ReadingsNum|^ReadingsTimestamp)[ \t]*\([ \t]*\"([\w_\.]+)\"[ \t]*,[ \t]*\"([\w-]*)$/.test(line) ) {
_key = _dev = _var = [];
var device = RegExp.$2;
word = RegExp.$3;
@ -937,7 +981,7 @@ CodeMirror.registerHelper("hint", "fhem", function hintfhem(cm, callback, option
_var = getDeviceReadings(d);
}
// only device names
else if( /.*(OldTimestamp|OldValue|Value|ReadingsVal|ReadingsTimestamp|AttrVal)[ \t]*\([ \t]*\"([\w_\.]+)$/.test(line) ) {
else if( /.*(OldTimestamp|OldValue|Value|^OldReadingsVal|^OldReadingsNum|^OldReadingsTimestamp|^ReadingsVal|^ReadingsNum|ReadingsTimestamp|AttrVal)[ \t]*\([ \t]*\"([\w_\.]+)$/.test(line) ) {
_key = _var = [];
word = RegExp.$2;
start = end - word.length;

View File

@ -6,6 +6,7 @@ var cm_attr = {
matchBrackets: true,
foldGutter: false,
autoRefresh: true,
fullScreen: false,
search: true,
comment: true,
autocomplete: true,
@ -141,7 +142,17 @@ function AddCodeMirror(e, cb) {
$("head").append('<style type="text/css">.CodeMirror {height:' + cm_attr.height + 'px;}');
}
}
if (cm_attr.fullScreen) {
cm_active++;
loadLink("codemirror/fullscreen.css");
loadScript("codemirror/fullscreen.js", function(){cm_loaded++;} );
cm_attr.extraKeys['F10'] = function(cm) {
cm.setOption("fullScreen", !cm.getOption("fullScreen"));
}
cm_attr.extraKeys['Esc'] = function(cm) {
if (cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
}
}
// get the type from hidden filename extension, load the type-file.js, theme.css and call cm_wait
var ltype;
$("input[name=save]").each(function() {

View File

@ -0,0 +1,6 @@
.CodeMirror-fullscreen {
position: fixed;
top: 0; left: 0; right: 0; bottom: 0;
height: auto;
z-index: 9;
}

View File

@ -0,0 +1,41 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: https://codemirror.net/5/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.defineOption("fullScreen", false, function(cm, val, old) {
if (old == CodeMirror.Init) old = false;
if (!old == !val) return;
if (val) setFullscreen(cm);
else setNormal(cm);
});
function setFullscreen(cm) {
var wrap = cm.getWrapperElement();
cm.state.fullScreenRestore = {scrollTop: window.pageYOffset, scrollLeft: window.pageXOffset,
width: wrap.style.width, height: wrap.style.height};
wrap.style.width = "";
wrap.style.height = "auto";
wrap.className += " CodeMirror-fullscreen";
document.documentElement.style.overflow = "hidden";
cm.refresh();
}
function setNormal(cm) {
var wrap = cm.getWrapperElement();
wrap.className = wrap.className.replace(/\s*CodeMirror-fullscreen\b/, "");
document.documentElement.style.overflow = "";
var info = cm.state.fullScreenRestore;
wrap.style.width = info.width; wrap.style.height = info.height;
window.scrollTo(info.scrollLeft, info.scrollTop);
cm.refresh();
}
});