!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(e){function n(e,n){var t=e.getRange(a(n.line,n.ch-1),a(n.line,n.ch+1));return 2==t.length?t:null}function t(n,t,r){var i=n.getLine(t.line),o=n.getTokenAt(t);if(/\bstring2?\b/.test(o.type))return!1;var a=new e.StringStream(i.slice(0,t.ch)+r+i.slice(t.ch),4);for(a.pos=a.start=o.start;;){var l=n.getMode().token(a,o.state);if(a.pos>=t.ch+1)return/\bstring2?\b/.test(l);a.start=a.pos}}function r(r,i){for(var l={name:"autoCloseBrackets",Backspace:function(t){if(t.getOption("disableInput"))return e.Pass;for(var i=t.listSelections(),o=0;o<i.length;o++){if(!i[o].empty())return e.Pass;var l=n(t,i[o].head);if(!l||r.indexOf(l)%2!=0)return e.Pass}for(var o=i.length-1;o>=0;o--){var s=i[o].head;t.replaceRange("",a(s.line,s.ch-1),a(s.line,s.ch+1))}}},s="",c=0;c<r.length;c+=2)!function(n,r){s+=r,l["'"+n+"'"]=function(l){if(l.getOption("disableInput"))return e.Pass;for(var c,f,u=l.listSelections(),h=0;h<u.length;h++){var d,g=u[h],p=g.head,f=l.getRange(p,a(p.line,p.ch+1));if(g.empty())if(n==r&&f==r)d=l.getRange(p,a(p.line,p.ch+3))==n+n+n?"skipThree":"skip";else if(n==r&&p.ch>1&&i.indexOf(n)>=0&&l.getRange(a(p.line,p.ch-2),p)==n+n&&(p.ch<=2||l.getRange(a(p.line,p.ch-3),a(p.line,p.ch-2))!=n))d="addFour";else if('"'==n||"'"==n){if(e.isWordChar(f)||!t(l,p,n))return e.Pass;d="both"}else{if(!(l.getLine(p.line).length==p.ch||s.indexOf(f)>=0||o.test(f)))return e.Pass;d="both"}else d="surround";if(c){if(c!=d)return e.Pass}else c=d}l.operation(function(){if("skip"==c)l.execCommand("goCharRight");else if("skipThree"==c)for(var e=0;e<3;e++)l.execCommand("goCharRight");else if("surround"==c){for(var t=l.getSelections(),e=0;e<t.length;e++)t[e]=n+t[e]+r;l.replaceSelections(t,"around")}else"both"==c?(l.replaceSelection(n+r,null),l.execCommand("goCharLeft")):"addFour"==c&&(l.replaceSelection(n+n+n+n,"before"),l.execCommand("goCharRight"))})},n!=r&&(l["'"+r+"'"]=function(n){for(var t=n.listSelections(),i=0;i<t.length;i++){var o=t[i];if(!o.empty()||n.getRange(o.head,a(o.head.line,o.head.ch+1))!=r)return e.Pass}n.execCommand("goCharRight")})}(r.charAt(c),r.charAt(c+1));return l}function i(t){return function(r){if(r.getOption("disableInput"))return e.Pass;for(var i=r.listSelections(),o=0;o<i.length;o++){if(!i[o].empty())return e.Pass;var a=n(r,i[o].head);if(!a||t.indexOf(a)%2!=0)return e.Pass}r.operation(function(){r.replaceSelection("\n\n",null),r.execCommand("goCharLeft"),i=r.listSelections();for(var e=0;e<i.length;e++){var n=i[e].head.line;r.indentLine(n,null,!0),r.indentLine(n+1,null,!0)}})}}var o=/\s/,a=e.Pos;e.defineOption("autoCloseBrackets",!1,function(n,t,o){if(o!=e.Init&&o&&n.removeKeyMap("autoCloseBrackets"),t){var a="()[]{}''\"\"",l="'\"",s="[]{}";"string"==typeof t?a=t:"object"==typeof t&&(null!=t.pairs&&(a=t.pairs),null!=t.triples&&(l=t.triples),null!=t.explode&&(s=t.explode));var c=r(a,l);s&&(c.Enter=i(s)),n.addKeyMap(c)}})});