(function(a){if(typeof exports=="object"&&typeof module=="object"){a(require("../../lib/codemirror"))}else{if(typeof define=="function"&&define.amd){define(["../../lib/codemirror"],a)}else{a(CodeMirror)}}})(function(f){var e={pairs:"()[]{}''\"\"",triples:"",explode:"[]{}"};var p=f.Pos;f.defineOption("autoCloseBrackets",false,function(i,t,s){if(s&&s!=f.Init){i.removeKeyMap(l);i.state.closeBrackets=null}if(t){i.state.closeBrackets=t;i.addKeyMap(l)}});function a(s,i){if(i=="pairs"&&typeof s=="string"){return s}if(typeof s=="object"&&s[i]!=null){return s[i]}return e[i]}var m=e.pairs+"`";var l={Backspace:d,Enter:b};for(var j=0;j<m.length;j++){l["'"+m.charAt(j)+"'"]=r(m.charAt(j))}function r(i){return function(s){return q(s,i)}}function o(i){var t=i.state.closeBrackets;if(!t){return null}var s=i.getModeAt(i.getCursor());return s.closeBrackets||t}function d(s){var u=o(s);if(!u||s.getOption("disableInput")){return f.Pass}var x=a(u,"pairs");var t=s.listSelections();for(var v=0;v<t.length;v++){if(!t[v].empty()){return f.Pass}var w=h(s,t[v].head);if(!w||x.indexOf(w)%2!=0){return f.Pass}}for(var v=t.length-1;v>=0;v--){var y=t[v].head;s.replaceRange("",p(y.line,y.ch-1),p(y.line,y.ch+1),"+delete")}}function b(s){var u=o(s);var w=u&&a(u,"explode");if(!w||s.getOption("disableInput")){return f.Pass}var t=s.listSelections();for(var v=0;v<t.length;v++){if(!t[v].empty()){return f.Pass}var x=h(s,t[v].head);if(!x||w.indexOf(x)%2!=0){return f.Pass}}s.operation(function(){s.replaceSelection("\n\n",null);s.execCommand("goCharLeft");t=s.listSelections();for(var z=0;z<t.length;z++){var y=t[z].head.line;s.indentLine(y,null,true);s.indentLine(y+1,null,true)}})}function g(s){var i=f.cmpPos(s.anchor,s.head)>0;return{anchor:new p(s.anchor.line,s.anchor.ch+(i?-1:1)),head:new p(s.head.line,s.head.ch+(i?1:-1))}}function q(F,s){var A=o(F);if(!A||F.getOption("disableInput")){return f.Pass}var u=a(A,"pairs");var D=u.indexOf(s);if(D==-1){return f.Pass}var I=a(A,"triples");var E=u.charAt(D+1)==s;var t=F.listSelections();var v=D%2==0;var B;for(var x=0;x<t.length;x++){var z=t[x],H=z.head,C;var y=F.getRange(H,p(H.line,H.ch+1));if(v&&!z.empty()){C="surround"}else{if((E||!v)&&y==s){if(E&&k(F,H)){C="both"}else{if(I.indexOf(s)>=0&&F.getRange(H,p(H.line,H.ch+3))==s+s+s){C="skipThree"}else{C="skip"}}}else{if(E&&H.ch>1&&I.indexOf(s)>=0&&F.getRange(p(H.line,H.ch-2),H)==s+s&&(H.ch<=2||F.getRange(p(H.line,H.ch-3),p(H.line,H.ch-2))!=s)){C="addFour"}else{if(E){if(!f.isWordChar(y)&&n(F,H,s)){C="both"}else{return f.Pass}}else{if(v&&(F.getLine(H.line).length==H.ch||c(y,u)||/\s/.test(y))){C="both"}else{return f.Pass}}}}}if(!B){B=C}else{if(B!=C){return f.Pass}}}var w=D%2?u.charAt(D-1):s;var G=D%2?s:u.charAt(D+1);F.operation(function(){if(B=="skip"){F.execCommand("goCharRight")}else{if(B=="skipThree"){for(var K=0;K<3;K++){F.execCommand("goCharRight")}}else{if(B=="surround"){var J=F.getSelections();for(var K=0;K<J.length;K++){J[K]=w+J[K]+G}F.replaceSelections(J,"around");J=F.listSelections().slice();for(var K=0;K<J.length;K++){J[K]=g(J[K])}F.setSelections(J)}else{if(B=="both"){F.replaceSelection(w+G,null);F.triggerElectric(w+G);F.execCommand("goCharLeft")}else{if(B=="addFour"){F.replaceSelection(w+w+w+w,"before");F.execCommand("goCharRight")}}}}}})}function c(i,s){var t=s.lastIndexOf(i);return t>-1&&t%2==1}function h(i,t){var s=i.getRange(p(t.line,t.ch-1),p(t.line,t.ch+1));return s.length==2?s:null}function n(i,x,v){var s=i.getLine(x.line);var u=i.getTokenAt(x);if(/\bstring2?\b/.test(u.type)){return false}var w=new f.StringStream(s.slice(0,x.ch)+v+s.slice(x.ch),4);w.pos=w.start=u.start;for(;;){var t=i.getMode().token(w,u.state);if(w.pos>=x.ch+1){return/\bstring2?\b/.test(t)}w.start=w.pos}}function k(i,t){var s=i.getTokenAt(p(t.line,t.ch+1));return/\bstring/.test(s.type)&&s.start==t.ch}});