ace-builds
Version:
Ace (Ajax.org Cloud9 Editor)
8 lines (7 loc) • 7 kB
JavaScript
define("ace/layer/text_markers",["require","exports","module","ace/layer/text","ace/lib/lang","ace/edit_session","ace/editor","ace/config"],function(e,t,n){var r=e("./text").Text,i=e("../lib/lang"),s={$removeClass:function(e){if(!this.element||!e)return;var t=this.element.querySelectorAll("."+e);for(var n=0;n<t.length;n++){var r=t[n];r.classList.remove(e);if(r.hasAttribute("data-whitespace")){var i=r.getAttribute("data-whitespace"),s=this.dom.createTextNode(i,this.element);s.charCount=r.charCount,r.parentNode.replaceChild(s,r)}}},$applyTextMarkers:function(){var e=this;this.session.$scheduleForRemove&&(this.session.$scheduleForRemove.forEach(function(t){e.$removeClass(t)}),this.session.$scheduleForRemove=new Set);var t=this.session.getTextMarkers();if(t.length===0)return;var n=new Set;t.forEach(function(e){n.add(e.className)}),n.forEach(function(t){e.$removeClass(t)}),t.forEach(function(t){var n=function(n){r=e.$lines.cells.find(function(e){return e.row===n}),r&&e.$modifyDomForMarkers(r.element,n,t)},r;for(var i=t.range.start.row;i<=t.range.end.row;i++)n(i)})},$modifyDomForMarkers:function(e,t,n){var r=this,i=this.session.getLine(t).length,s=t>n.range.start.row?0:n.range.start.column,o=t<n.range.end.row?i:n.range.end.column;if(s===o)return;var u=[];e.classList.contains("ace_line_group")?u=Array.from(e.childNodes):u=[e];var a=0;u.forEach(function(e){var t=Array.from(e.childNodes);for(var i=0;i<t.length;i++){var u=[t[i]],f=e;t[i].childNodes&&t[i].childNodes.length>0&&(u=Array.from(t[i].childNodes),f=t[i]);for(var l=0;l<u.length;l++){var c=u[l],h=c.textContent||"";c.parentNode.charCount&&(c.charCount=c.parentNode.charCount);var p=c.charCount||h.length,d=a,v=a+p;if(c.charCount===0||p===0)continue;if(d<o&&v>s){var m=Math.max(0,s-d),g=Math.max(0,v-o),y=p-m-g;n.type==="invisible"?r.$processInvisibleMarker(c,f,{beforeSelection:m,selectionLength:y,afterSelection:g},n):r.$processRegularMarker(c,f,{beforeSelection:m,selectionLength:y,afterSelection:g},n,d,s,o)}a=v}}})},$processInvisibleMarker:function(e,t,n,r){var s=e.textContent||"";if(e.nodeType===3){var o=this.dom.createFragment(this.element);n.beforeSelection>0&&o.appendChild(this.dom.createTextNode(s.substring(0,n.beforeSelection),this.element));if(n.selectionLength>0){var u=n.beforeSelection===0&&n.afterSelection===0?s:s.substring(n.beforeSelection,n.beforeSelection+n.selectionLength),a=u.match(/\s+|[^\s]+/g)||[];for(var f=0;f<a.length;f++){var l=a[f],c=void 0;if(/^\s+$/.test(l)){c=this.dom.createElement("span"),c.className=r.className;var h=e.charCount?this.TAB_CHAR:this.SPACE_CHAR;c.textContent=i.stringRepeat(h,l.length),c.setAttribute("data-whitespace",l),o.appendChild(c)}else c=this.dom.createElement("span"),c.textContent=l;e.charCount&&a.length===1&&(c.charCount=e.charCount),o.appendChild(c)}}n.afterSelection>0&&o.appendChild(this.dom.createTextNode(s.substring(n.beforeSelection+n.selectionLength),this.element)),t.replaceChild(o,e)}},$processRegularMarker:function(e,t,n,r,i,s,o){var u=e.textContent||"";if(e.nodeType===3)if(n.beforeSelection>0||n.afterSelection>0){var a=this.dom.createFragment(this.element);n.beforeSelection>0&&a.appendChild(this.dom.createTextNode(u.substring(0,n.beforeSelection),this.element));if(n.selectionLength>0){var f=this.dom.createElement("span");f.classList.add(r.className),f.textContent=u.substring(n.beforeSelection,n.beforeSelection+n.selectionLength),a.appendChild(f)}n.afterSelection>0&&a.appendChild(this.dom.createTextNode(u.substring(n.beforeSelection+n.selectionLength),this.element)),t.replaceChild(a,e)}else{var f=this.dom.createElement("span");f.classList.add(r.className),f.textContent=u,f.charCount=e.charCount,t.replaceChild(f,e)}else if(e.nodeType===1)if(i>=s&&i+(u.length||0)<=o)e.classList.add(r.className);else if(n.beforeSelection>0||n.afterSelection>0){var l=e.className,a=this.dom.createFragment(this.element);if(n.beforeSelection>0){var c=this.dom.createElement("span");c.className=l,c.textContent=u.substring(0,n.beforeSelection),a.appendChild(c)}if(n.selectionLength>0){var f=this.dom.createElement("span");f.className=l+" "+r.className,f.textContent=u.substring(n.beforeSelection,n.beforeSelection+n.selectionLength),a.appendChild(f)}if(n.afterSelection>0){var h=this.dom.createElement("span");h.className=l,h.textContent=u.substring(n.beforeSelection+n.selectionLength),a.appendChild(h)}t.replaceChild(a,e)}}};Object.assign(r.prototype,s);var o=e("../edit_session").EditSession,u={addTextMarker:function(e,t,n){this.$textMarkerId=this.$textMarkerId||0,this.$textMarkerId++;var r={range:e,id:this.$textMarkerId,className:t,type:n};return this.$textMarkers||(this.$textMarkers=[]),this.$textMarkers[r.id]=r,r.id},removeTextMarker:function(e){if(!this.$textMarkers)return;var t=this.$textMarkers[e];if(!t)return;this.$scheduleForRemove||(this.$scheduleForRemove=new Set),this.$scheduleForRemove.add(t.className),delete this.$textMarkers[e]},getTextMarkers:function(){return this.$textMarkers||[]}};Object.assign(o.prototype,u);var a=function(e,t){t.$textLayer.$applyTextMarkers()},f=e("../editor").Editor;e("../config").defineOptions(f.prototype,"editor",{enableTextMarkers:{set:function(e){e?this.renderer.on("afterRender",a):this.renderer.off("afterRender",a)},value:!0}}),t.textMarkerMixin=s,t.editSessionTextMarkerMixin=u}),define("ace/ext/whitespaces_in_selection",["require","exports","module","ace/layer/text_markers","ace/editor","ace/config","ace/lib/dom"],function(e,t,n){"use strict";function o(){var e=this.session.$invisibleMarkerId;e&&(this.session.removeTextMarker(e),this.session.$invisibleMarkerId=null);var t=this.selection.getRange();t.isEmpty()||(this.session.$invisibleMarkerId=this.session.addTextMarker(t,"ace_whitespaces_in_selection","invisible"))}e("../layer/text_markers");var r=e("../editor").Editor,i=e("../config"),s=e("../lib/dom");s.importCssString("\n.ace_whitespaces_in_selection {\n color: rgba(0,0,0,0.29);\n}\n\n.ace_dark .ace_whitespaces_in_selection {\n color: rgba(187, 181, 181, 0.5);\n}\n","ace_whitespaces_in_selection",!1),i.defineOptions(r.prototype,"editor",{showWhitespacesInSelection:{set:function(e){this.$showWhitespacesInSelection=e,e?(this.$boundChangeSelectionForWhitespace||(this.$boundChangeSelectionForWhitespace=o.bind(this)),this.on("changeSelection",this.$boundChangeSelectionForWhitespace)):(this.off("changeSelection",this.$boundChangeSelectionForWhitespace),this.session&&this.session.$invisibleMarkerId&&(this.session.removeTextMarker(this.session.$invisibleMarkerId),this.session.$invisibleMarkerId=null),this.$boundChangeSelectionForWhitespace=null)},get:function(){return this.$showWhitespacesInSelection},initialValue:!1}})}); (function() {
window.require(["ace/ext/whitespaces_in_selection"], function(m) {
if (typeof module == "object" && typeof exports == "object" && module) {
module.exports = m;
}
});
})();