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