!function(e){"object"==typeof exports&&"object"==typeof module?e(require("../../lib/codemirror")):"function"==typeof define&&define.amd?define(["../../lib/codemirror"],e):e(CodeMirror)}(function(r){"use strict";function i(e){e.state.markedSelection&&e.operation(function(){!function(e){if(!e.somethingSelected())return c(e);if(1<e.listSelections().length)return a(e);var t=e.getCursor("start"),n=e.getCursor("end"),o=e.state.markedSelection;if(!o.length)return f(e,t,n);var r=o[0].find(),i=o[o.length-1].find();if(!r||!i||n.line-t.line<=m||0<=S(t,i.to)||S(n,r.from)<=0)return a(e);for(;0<S(t,r.from);)o.shift().clear(),r=o[0].find();S(t,r.from)<0&&(r.to.line-t.line<m?(o.shift().clear(),f(e,t,r.to,0)):f(e,t,r.from,0));for(;S(n,i.to)<0;)o.pop().clear(),i=o[o.length-1].find();0<S(n,i.to)&&(n.line-i.from.line<m?(o.pop().clear(),f(e,i.from,n)):f(e,i.to,n))}(e)})}function l(e){e.state.markedSelection&&e.state.markedSelection.length&&e.operation(function(){c(e)})}r.defineOption("styleSelectedText",!1,function(e,t,n){var o=n&&n!=r.Init;t&&!o?(e.state.markedSelection=[],e.state.markedSelectionStyle="string"==typeof t?t:"CodeMirror-selectedtext",a(e),e.on("cursorActivity",i),e.on("change",l)):!t&&o&&(e.off("cursorActivity",i),e.off("change",l),c(e),e.state.markedSelection=e.state.markedSelectionStyle=null)});var m=8,u=r.Pos,S=r.cmpPos;function f(e,t,n,o){if(0!=S(t,n))for(var r=e.state.markedSelection,i=e.state.markedSelectionStyle,l=t.line;;){var f=l==t.line?t:u(l,0),c=l+m,a=c>=n.line,s=a?n:u(c,0),d=e.markText(f,s,{className:i});if(null==o?r.push(d):r.splice(o++,0,d),a)break;l=c}}function c(e){for(var t=e.state.markedSelection,n=0;n<t.length;++n)t[n].clear();t.length=0}function a(e){c(e);for(var t=e.listSelections(),n=0;n<t.length;n++)f(e,t[n].from(),t[n].to())}});