!function(o){"object"==typeof exports&&"object"==typeof module?o(require("../../lib/codemirror"),require("./foldcode")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","./foldcode"],o):o(CodeMirror)}(function(r){"use strict";r.defineOption("foldGutter",!1,function(o,t,e){e&&e!=r.Init&&(o.clearGutter(o.state.foldGutter.options.gutter),o.state.foldGutter=null,o.off("gutterClick",a),o.off("change",d),o.off("viewportChange",p),o.off("fold",s),o.off("unfold",s),o.off("swapDoc",d)),t&&(o.state.foldGutter=new n(function(o){!0===o&&(o={});null==o.gutter&&(o.gutter="CodeMirror-foldgutter");null==o.indicatorOpen&&(o.indicatorOpen="CodeMirror-foldgutter-open");null==o.indicatorFolded&&(o.indicatorFolded="CodeMirror-foldgutter-folded");return o}(t)),f(o),o.on("gutterClick",a),o.on("change",d),o.on("viewportChange",p),o.on("fold",s),o.on("unfold",s),o.on("swapDoc",d))});var u=r.Pos;function n(o){this.options=o,this.from=this.to=0}function l(o,t){for(var e=o.findMarks(u(t,0),u(t+1,0)),r=0;r<e.length;++r)if(e[r].__isFold){var n=e[r].find(-1);if(n&&n.line===t)return e[r]}}function c(o){if("string"!=typeof o)return o.cloneNode(!0);var t=document.createElement("div");return t.className=o+" CodeMirror-guttermarker-subtle",t}function i(n,o,t){var i=n.state.foldGutter.options,f=o,a=n.foldOption(i,"minFoldSize"),d=n.foldOption(i,"rangeFinder");n.eachLine(o,t,function(o){var t=null;if(l(n,f))t=c(i.indicatorFolded);else{var e=u(f,0),r=d&&d(n,e);r&&r.to.line-r.from.line>=a&&(t=c(i.indicatorOpen))}n.setGutterMarker(o,i.gutter,t),++f})}function f(o){var t=o.getViewport(),e=o.state.foldGutter;e&&(o.operation(function(){i(o,t.from,t.to)}),e.from=t.from,e.to=t.to)}function a(o,t,e){var r=o.state.foldGutter;if(r){var n=r.options;if(e==n.gutter){var i=l(o,t);i?i.clear():o.foldCode(u(t,0),n)}}}function d(o){var t=o.state.foldGutter;if(t){var e=t.options;t.from=t.to=0,clearTimeout(t.changeUpdate),t.changeUpdate=setTimeout(function(){f(o)},e.foldOnChangeTimeSpan||600)}}function p(t){var e=t.state.foldGutter;if(e){var o=e.options;clearTimeout(e.changeUpdate),e.changeUpdate=setTimeout(function(){var o=t.getViewport();e.from==e.to||20<o.from-e.to||20<e.from-o.to?f(t):t.operation(function(){o.from<e.from&&(i(t,o.from,e.from),e.from=o.from),o.to>e.to&&(i(t,e.to,o.to),e.to=o.to)})},o.updateViewportTimeSpan||400)}}function s(o,t){var e=o.state.foldGutter;if(e){var r=t.line;r>=e.from&&r<e.to&&i(o,r,r+1)}}});