{"title":"$:/plugins/tiddlywiki/codemirror-closebrackets","name":"CodeMirror Close Brackets","description":"Close brackets for CodeMirror","parent-plugin":"$:/plugins/tiddlywiki/codemirror","list":"readme","version":"5.2.2","plugin-type":"plugin","dependents":"","type":"application/json","tiddlers":{"$:/config/codemirror/autoCloseBrackets":{"title":"$:/config/codemirror/autoCloseBrackets","type":"bool","text":"true"},"$:/config/codemirror/matchBrackets":{"title":"$:/config/codemirror/matchBrackets","type":"bool","text":"true\n"},"$:/plugins/tiddlywiki/codemirror/addon/edit/closebrackets.js":{"text":"// CodeMirror, copyright (c) by Marijn Haverbeke and others\n// Distributed under an MIT license: https://codemirror.net/LICENSE\n!function(e){\"object\"==typeof exports&&\"object\"==typeof module?e(require(\"../../lib/codemirror\")):\"function\"==typeof define&&define.amd?define([\"../../lib/codemirror\"],e):e(CodeMirror)}(function(C){var r={pairs:\"()[]{}''\\\"\\\"\",closeBefore:\")]}'\\\":;>\",triples:\"\",explode:\"[]{}\"},x=C.Pos;function P(e,t){return\"pairs\"==t&&\"string\"==typeof e?e:\"object\"==typeof e&&null!=e[t]?e[t]:r[t]}C.defineOption(\"autoCloseBrackets\",!1,function(e,t,r){r&&r!=C.Init&&(e.removeKeyMap(i),e.state.closeBrackets=null),t&&(n(P(t,\"pairs\")),e.state.closeBrackets=t,e.addKeyMap(i))});var i={Backspace:function(e){var t=k(e);if(!t||e.getOption(\"disableInput\"))return C.Pass;for(var r=P(t,\"pairs\"),n=e.listSelections(),i=0;i<n.length;i++){if(!n[i].empty())return C.Pass;var a=s(e,n[i].head);if(!a||r.indexOf(a)%2!=0)return C.Pass}for(i=n.length-1;0<=i;i--){var o=n[i].head;e.replaceRange(\"\",x(o.line,o.ch-1),x(o.line,o.ch+1),\"+delete\")}},Enter:function(n){var e=k(n),t=e&&P(e,\"explode\");if(!t||n.getOption(\"disableInput\"))return C.Pass;for(var i=n.listSelections(),r=0;r<i.length;r++){if(!i[r].empty())return C.Pass;var a=s(n,i[r].head);if(!a||t.indexOf(a)%2!=0)return C.Pass}n.operation(function(){var e=n.lineSeparator()||\"\\n\";n.replaceSelection(e+e,null),n.execCommand(\"goCharLeft\"),i=n.listSelections();for(var t=0;t<i.length;t++){var r=i[t].head.line;n.indentLine(r,null,!0),n.indentLine(r+1,null,!0)}})}};function n(e){for(var t=0;t<e.length;t++){var r=e.charAt(t),n=\"'\"+r+\"'\";i[n]||(i[n]=function(t){return function(e){return function(i,e){var t=k(i);if(!t||i.getOption(\"disableInput\"))return C.Pass;var r=P(t,\"pairs\"),n=r.indexOf(e);if(-1==n)return C.Pass;for(var a,o=P(t,\"closeBefore\"),s=P(t,\"triples\"),l=r.charAt(n+1)==e,c=i.listSelections(),f=n%2==0,h=0;h<c.length;h++){var u,d=c[h],p=d.head,g=i.getRange(p,x(p.line,p.ch+1));if(f&&!d.empty())u=\"surround\";else if(!l&&f||g!=e)if(l&&1<p.ch&&0<=s.indexOf(e)&&i.getRange(x(p.line,p.ch-2),p)==e+e){if(2<p.ch&&/\\bstring/.test(i.getTokenTypeAt(x(p.line,p.ch-2))))return C.Pass;u=\"addFour\"}else if(l){var v=0==p.ch?\" \":i.getRange(x(p.line,p.ch-1),p);if(C.isWordChar(g)||v==e||C.isWordChar(v))return C.Pass;u=\"both\"}else{if(!f||!(0===g.length||/\\s/.test(g)||-1<o.indexOf(g)))return C.Pass;u=\"both\"}else u=l&&function(e,t){var r=e.getTokenAt(x(t.line,t.ch+1));return/\\bstring/.test(r.type)&&r.start==t.ch&&(0==t.ch||!/\\bstring/.test(e.getTokenTypeAt(t)))}(i,p)?\"both\":0<=s.indexOf(e)&&i.getRange(p,x(p.line,p.ch+3))==e+e+e?\"skipThree\":\"skip\";if(a){if(a!=u)return C.Pass}else a=u}var m=n%2?r.charAt(n-1):e,b=n%2?e:r.charAt(n+1);i.operation(function(){if(\"skip\"==a)i.execCommand(\"goCharRight\");else if(\"skipThree\"==a)for(var e=0;e<3;e++)i.execCommand(\"goCharRight\");else if(\"surround\"==a){for(var t=i.getSelections(),e=0;e<t.length;e++)t[e]=m+t[e]+b;i.replaceSelections(t,\"around\"),t=i.listSelections().slice();for(e=0;e<t.length;e++)t[e]=(r=t[e],n=0<C.cmpPos(r.anchor,r.head),{anchor:new x(r.anchor.line,r.anchor.ch+(n?-1:1)),head:new x(r.head.line,r.head.ch+(n?1:-1))});i.setSelections(t)}else\"both\"==a?(i.replaceSelection(m+b,null),i.triggerElectric(m+b),i.execCommand(\"goCharLeft\")):\"addFour\"==a&&(i.replaceSelection(m+m+m+m,\"before\"),i.execCommand(\"goCharRight\"));var r,n})}(e,t)}}(r))}}function k(e){var t=e.state.closeBrackets;return t&&!t.override&&e.getModeAt(e.getCursor()).closeBrackets||t}function s(e,t){var r=e.getRange(x(t.line,t.ch-1),x(t.line,t.ch+1));return 2==r.length?r:null}n(r.pairs+\"`\")});\n","type":"application/javascript","title":"$:/plugins/tiddlywiki/codemirror/addon/edit/closebrackets.js","module-type":"codemirror"},"$:/plugins/tiddlywiki/codemirror/addon/edit/matchbrackets.js":{"text":"// CodeMirror, copyright (c) by Marijn Haverbeke and others\n// Distributed under an MIT license: https://codemirror.net/LICENSE\n!function(t){\"object\"==typeof exports&&\"object\"==typeof module?t(require(\"../../lib/codemirror\")):\"function\"==typeof define&&define.amd?define([\"../../lib/codemirror\"],t):t(CodeMirror)}(function(i){var h=/MSIE \\d/.test(navigator.userAgent)&&(null==document.documentMode||document.documentMode<8),k=i.Pos,p={\"(\":\")>\",\")\":\"(<\",\"[\":\"]>\",\"]\":\"[<\",\"{\":\"}>\",\"}\":\"{<\",\"<\":\">>\",\">\":\"<<\"};function v(t){return t&&t.bracketRegex||/[(){}[\\]]/}function u(t,e,n){var r=t.getLineHandle(e.line),i=e.ch-1,c=n&&n.afterCursor;null==c&&(c=/(^| )cm-fat-cursor($| )/.test(t.getWrapperElement().className));var a=v(n),o=!c&&0<=i&&a.test(r.text.charAt(i))&&p[r.text.charAt(i)]||a.test(r.text.charAt(i+1))&&p[r.text.charAt(++i)];if(!o)return null;var l=\">\"==o.charAt(1)?1:-1;if(n&&n.strict&&0<l!=(i==e.ch))return null;var s=t.getTokenTypeAt(k(e.line,i+1)),h=f(t,k(e.line,i+(0<l?1:0)),l,s||null,n);return null==h?null:{from:k(e.line,i),to:h&&h.pos,match:h&&h.ch==o.charAt(0),forward:0<l}}function f(t,e,n,r,i){for(var c=i&&i.maxScanLineLength||1e4,a=i&&i.maxScanLines||1e3,o=[],l=v(i),s=0<n?Math.min(e.line+a,t.lastLine()+1):Math.max(t.firstLine()-1,e.line-a),h=e.line;h!=s;h+=n){var u=t.getLine(h);if(u){var f=0<n?0:u.length-1,m=0<n?u.length:-1;if(!(u.length>c))for(h==e.line&&(f=e.ch-(n<0?1:0));f!=m;f+=n){var g=u.charAt(f);if(l.test(g)&&(void 0===r||t.getTokenTypeAt(k(h,f+1))==r)){var d=p[g];if(d&&\">\"==d.charAt(1)==0<n)o.push(g);else{if(!o.length)return{pos:k(h,f),ch:g};o.pop()}}}}}return h-n!=(0<n?t.lastLine():t.firstLine())&&null}function e(t,e,n){for(var r=t.state.matchBrackets.maxHighlightLineLength||1e3,i=[],c=t.listSelections(),a=0;a<c.length;a++){var o,l=c[a].empty()&&u(t,c[a].head,n);l&&t.getLine(l.from.line).length<=r&&(o=l.match?\"CodeMirror-matchingbracket\":\"CodeMirror-nonmatchingbracket\",i.push(t.markText(l.from,k(l.from.line,l.from.ch+1),{className:o})),l.to&&t.getLine(l.to.line).length<=r&&i.push(t.markText(l.to,k(l.to.line,l.to.ch+1),{className:o})))}if(i.length){h&&t.state.focused&&t.focus();function s(){t.operation(function(){for(var t=0;t<i.length;t++)i[t].clear()})}if(!e)return s;setTimeout(s,800)}}function c(t){t.operation(function(){t.state.matchBrackets.currentlyHighlighted&&(t.state.matchBrackets.currentlyHighlighted(),t.state.matchBrackets.currentlyHighlighted=null),t.state.matchBrackets.currentlyHighlighted=e(t,!1,t.state.matchBrackets)})}i.defineOption(\"matchBrackets\",!1,function(t,e,n){function r(t){t.state.matchBrackets&&t.state.matchBrackets.currentlyHighlighted&&(t.state.matchBrackets.currentlyHighlighted(),t.state.matchBrackets.currentlyHighlighted=null)}n&&n!=i.Init&&(t.off(\"cursorActivity\",c),t.off(\"focus\",c),t.off(\"blur\",r),r(t)),e&&(t.state.matchBrackets=\"object\"==typeof e?e:{},t.on(\"cursorActivity\",c),t.on(\"focus\",c),t.on(\"blur\",r))}),i.defineExtension(\"matchBrackets\",function(){e(this,!0)}),i.defineExtension(\"findMatchingBracket\",function(t,e,n){return!n&&\"boolean\"!=typeof e||(e=n?(n.strict=e,n):e?{strict:!0}:null),u(this,t,e)}),i.defineExtension(\"scanForBracket\",function(t,e,n,r){return f(this,t,e,n,r)})});\n","type":"application/javascript","title":"$:/plugins/tiddlywiki/codemirror/addon/edit/matchbrackets.js","module-type":"codemirror"},"$:/plugins/tiddlywiki/codemirror-closebrackets/readme":{"title":"$:/plugins/tiddlywiki/codemirror-closebrackets/readme","text":"This plugin adds the ability to automatically insert the closing brackets when you type an opening bracket.\nAlso enables highlighting of matching brackets.\n\nIt needs the latest [[CodeMirror plugin|$:/plugins/tiddlywiki/codemirror]] to be installed\n\n"}}}