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