import{t as e}from"./chunk-6hGRweTZ.js";import{t}from"./codemirror-mxAyinHX.js";var n=e(((e,n)=>{(function(r){typeof e==`object`&&typeof n==`object`?r(t()):typeof define==`function`&&define.amd?define([`../../lib/codemirror`],r):r(CodeMirror)})(function(e){var t={pairs:`()[]{}''""`,closeBefore:`)]}'":;>`,triples:``,explode:`[]{}`},n=e.Pos;e.defineOption(`autoCloseBrackets`,!1,function(t,n,o){o&&o!=e.Init&&(t.removeKeyMap(i),t.state.closeBrackets=null),n&&(a(r(n,`pairs`)),t.state.closeBrackets=n,t.addKeyMap(i))});function r(e,n){return n==`pairs`&&typeof e==`string`?e:typeof e==`object`&&e[n]!=null?e[n]:t[n]}var i={Backspace:c,Enter:l};function a(e){for(var t=0;t<e.length;t++){var n=e.charAt(t),r=`'`+n+`'`;i[r]||(i[r]=o(n))}}a(t.pairs+"`");function o(e){return function(t){return f(t,e)}}function s(e){var t=e.state.closeBrackets;return!t||t.override?t:e.getModeAt(e.getCursor()).closeBrackets||t}function c(t){var i=s(t);if(!i||t.getOption(`disableInput`))return e.Pass;for(var a=r(i,`pairs`),o=t.listSelections(),c=0;c<o.length;c++){if(!o[c].empty())return e.Pass;var l=p(t,o[c].head);if(!l||a.indexOf(l)%2!=0)return e.Pass}for(var c=o.length-1;c>=0;c--){var u=o[c].head;t.replaceRange(``,n(u.line,u.ch-1),n(u.line,u.ch+1),`+delete`)}}function l(t){var n=s(t),i=n&&r(n,`explode`);if(!i||t.getOption(`disableInput`))return e.Pass;for(var a=t.listSelections(),o=0;o<a.length;o++){if(!a[o].empty())return e.Pass;var c=p(t,a[o].head);if(!c||i.indexOf(c)%2!=0)return e.Pass}t.operation(function(){var e=t.lineSeparator()||`
`;t.replaceSelection(e+e,null),u(t,-1),a=t.listSelections();for(var n=0;n<a.length;n++){var r=a[n].head.line;t.indentLine(r,null,!0),t.indentLine(r+1,null,!0)}})}function u(e,t){for(var n=[],r=e.listSelections(),i=0,a=0;a<r.length;a++){var o=r[a];o.head==e.getCursor()&&(i=a);var s=o.head.ch||t>0?{line:o.head.line,ch:o.head.ch+t}:{line:o.head.line-1};n.push({anchor:s,head:s})}e.setSelections(n,i)}function d(t){var r=e.cmpPos(t.anchor,t.head)>0;return{anchor:new n(t.anchor.line,t.anchor.ch+(r?-1:1)),head:new n(t.head.line,t.head.ch+(r?1:-1))}}function f(t,i){var a=s(t);if(!a||t.getOption(`disableInput`))return e.Pass;var o=r(a,`pairs`),c=o.indexOf(i);if(c==-1)return e.Pass;for(var l=r(a,`closeBefore`),f=r(a,`triples`),p=o.charAt(c+1)==i,h=t.listSelections(),g=c%2==0,_,v=0;v<h.length;v++){var y=h[v],b=y.head,x,S=t.getRange(b,n(b.line,b.ch+1));if(g&&!y.empty())x=`surround`;else if((p||!g)&&S==i)x=p&&m(t,b)?`both`:f.indexOf(i)>=0&&t.getRange(b,n(b.line,b.ch+3))==i+i+i?`skipThree`:`skip`;else if(p&&b.ch>1&&f.indexOf(i)>=0&&t.getRange(n(b.line,b.ch-2),b)==i+i){if(b.ch>2&&/\bstring/.test(t.getTokenTypeAt(n(b.line,b.ch-2))))return e.Pass;x=`addFour`}else if(p){var C=b.ch==0?` `:t.getRange(n(b.line,b.ch-1),b);if(!e.isWordChar(S)&&C!=i&&!e.isWordChar(C))x=`both`;else return e.Pass}else if(g&&(S.length===0||/\s/.test(S)||l.indexOf(S)>-1))x=`both`;else return e.Pass;if(!_)_=x;else if(_!=x)return e.Pass}var w=c%2?o.charAt(c-1):i,T=c%2?i:o.charAt(c+1);t.operation(function(){if(_==`skip`)u(t,1);else if(_==`skipThree`)u(t,3);else if(_==`surround`){for(var e=t.getSelections(),n=0;n<e.length;n++)e[n]=w+e[n]+T;t.replaceSelections(e,`around`),e=t.listSelections().slice();for(var n=0;n<e.length;n++)e[n]=d(e[n]);t.setSelections(e)}else _==`both`?(t.replaceSelection(w+T,null),t.triggerElectric(w+T),u(t,-1)):_==`addFour`&&(t.replaceSelection(w+w+w+w,`before`),u(t,1))})}function p(e,t){var r=e.getRange(n(t.line,t.ch-1),n(t.line,t.ch+1));return r.length==2?r:null}function m(e,t){var r=e.getTokenAt(n(t.line,t.ch+1));return/\bstring/.test(r.type)&&r.start==t.ch&&(t.ch==0||!/\bstring/.test(e.getTokenTypeAt(t)))}})}));export default n();
//# sourceMappingURL=closebrackets-BqajQ2Ab.js.map