mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-01-31 12:49:34 +00:00
d618ddc172
- feature: codemirror modules now loaded by default: search.js, comment.js dialog.js, autorefresh.js, searchcursor.js, dialog.css codemirror search & replace is now activated by default. to use this feature now you must only load in fhemweb attribute 'JavaScripts' the codemirror/fhem_codemirror.js file new extraKeys for 'TAB', 'Shift+Tab', 'STRG+Q', 'STRG+UP', and 'STRG+DOWN' are added. codemirror default parameters are now: indentUnit:4, indentWithTabs:false, autoCloseBrackets:false, matchBrackets:true, autofocus:true, theme:"blackboard", lineNumbers:true, autoRefresh:true this can be overwritten with fhemweb attribute 'codemirrorParam' - updated: codemirror version to 5.8 the default codemirror javascript files are now minified git-svn-id: https://svn.fhem.de/fhem/trunk@9668 2b470e98-0d58-463d-a4d8-8e2adae1ed80
7 lines
3.3 KiB
JavaScript
7 lines
3.3 KiB
JavaScript
(function(f){"object"==typeof exports&&"object"==typeof module?f(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],f):f(CodeMirror)})(function(f){function r(b,a){return"pairs"==a&&"string"==typeof b?b:"object"==typeof b&&null!=b[a]?b[a]:w[a]}function z(b){return function(a){return A(a,b)}}function t(b){var a=b.state.closeBrackets;return a?b.getModeAt(b.getCursor()).closeBrackets||a:null}function A(b,a){var c=t(b);if(!c||b.getOption("disableInput"))return f.Pass;
|
|
var e=r(c,"pairs"),d=e.indexOf(a);if(-1==d)return f.Pass;for(var c=r(c,"triples"),u=e.charAt(d+1)==a,x=b.listSelections(),m=0==d%2,l,h,p=0;p<x.length;p++){var q=x[p],g=q.head;h=b.getRange(g,k(g.line,g.ch+1));if(m&&!q.empty())h="surround";else if(!u&&m||h!=a)if(u&&1<g.ch&&0<=c.indexOf(a)&&b.getRange(k(g.line,g.ch-2),g)==a+a&&(2>=g.ch||b.getRange(k(g.line,g.ch-3),k(g.line,g.ch-2))!=a))h="addFour";else if(u)if(!f.isWordChar(h)&&B(b,g,a))h="both";else return f.Pass;else if(m&&(b.getLine(g.line).length==
|
|
g.ch||C(h,e)||/\s/.test(h)))h="both";else return f.Pass;else h=0<=c.indexOf(a)&&b.getRange(g,k(g.line,g.ch+3))==a+a+a?"skipThree":"skip";if(!l)l=h;else if(l!=h)return f.Pass}var n=d%2?e.charAt(d-1):a,v=d%2?a:e.charAt(d+1);b.operation(function(){if("skip"==l)b.execCommand("goCharRight");else if("skipThree"==l)for(var a=0;3>a;a++)b.execCommand("goCharRight");else if("surround"==l){for(var c=b.getSelections(),a=0;a<c.length;a++)c[a]=n+c[a]+v;b.replaceSelections(c,"around");c=b.listSelections().slice();
|
|
for(a=0;a<c.length;a++){var e=c,g=a,d;d=c[a];var h=0<f.cmpPos(d.anchor,d.head);d={anchor:new k(d.anchor.line,d.anchor.ch+(h?-1:1)),head:new k(d.head.line,d.head.ch+(h?1:-1))};e[g]=d}b.setSelections(c)}else"both"==l?(b.replaceSelection(n+v,null),b.triggerElectric(n+v),b.execCommand("goCharLeft")):"addFour"==l&&(b.replaceSelection(n+n+n+n,"before"),b.execCommand("goCharRight"))})}function C(b,a){var c=a.lastIndexOf(b);return-1<c&&1==c%2}function y(b,a){var c=b.getRange(k(a.line,a.ch-1),k(a.line,a.ch+
|
|
1));return 2==c.length?c:null}function B(b,a,c){var e=b.getLine(a.line),d=b.getTokenAt(a);if(/\bstring2?\b/.test(d.type))return!1;c=new f.StringStream(e.slice(0,a.ch)+c+e.slice(a.ch),4);for(c.pos=c.start=d.start;;){e=b.getMode().token(c,d.state);if(c.pos>=a.ch+1)return/\bstring2?\b/.test(e);c.start=c.pos}}var w={pairs:"()[]{}''\"\"",triples:"",explode:"[]{}"},k=f.Pos;f.defineOption("autoCloseBrackets",!1,function(b,a,c){c&&c!=f.Init&&(b.removeKeyMap(p),b.state.closeBrackets=null);a&&(b.state.closeBrackets=
|
|
a,b.addKeyMap(p))});for(var q=w.pairs+"`",p={Backspace:function(b){var a=t(b);if(!a||b.getOption("disableInput"))return f.Pass;for(var c=r(a,"pairs"),a=b.listSelections(),e=0;e<a.length;e++){if(!a[e].empty())return f.Pass;var d=y(b,a[e].head);if(!d||0!=c.indexOf(d)%2)return f.Pass}for(e=a.length-1;0<=e;e--)c=a[e].head,b.replaceRange("",k(c.line,c.ch-1),k(c.line,c.ch+1))},Enter:function(b){var a=t(b),a=a&&r(a,"explode");if(!a||b.getOption("disableInput"))return f.Pass;for(var c=b.listSelections(),
|
|
e=0;e<c.length;e++){if(!c[e].empty())return f.Pass;var d=y(b,c[e].head);if(!d||0!=a.indexOf(d)%2)return f.Pass}b.operation(function(){b.replaceSelection("\n\n",null);b.execCommand("goCharLeft");c=b.listSelections();for(var a=0;a<c.length;a++){var d=c[a].head.line;b.indentLine(d,null,!0);b.indentLine(d+1,null,!0)}})}},m=0;m<q.length;m++)p["'"+q.charAt(m)+"'"]=z(q.charAt(m))}); |