+++ /dev/null
- // change_to: "on" or "off"\r
- EditArea.prototype.change_highlight= function(change_to){\r
- if(this.settings["syntax"].length==0 && change_to==false){\r
- this.switchClassSticky(_$("highlight"), 'editAreaButtonDisabled', true);\r
- this.switchClassSticky(_$("reset_highlight"), 'editAreaButtonDisabled', true);\r
- return false;\r
- }\r
- \r
- if(this.do_highlight==change_to)\r
- return false;\r
- \r
- \r
- this.getIESelection();\r
- var pos_start= this.textarea.selectionStart;\r
- var pos_end= this.textarea.selectionEnd;\r
- \r
- if(this.do_highlight===true || change_to==false)\r
- this.disable_highlight();\r
- else\r
- this.enable_highlight();\r
- this.textarea.focus();\r
- this.textarea.selectionStart = pos_start;\r
- this.textarea.selectionEnd = pos_end;\r
- this.setIESelection();\r
- \r
- };\r
- \r
- EditArea.prototype.disable_highlight= function(displayOnly){\r
- var t= this, a=t.textarea, new_Obj, old_class, new_class;\r
- \r
- t.selection_field.innerHTML="";\r
- t.selection_field_text.innerHTML="";\r
- t.content_highlight.style.visibility="hidden";\r
- // replacing the node is far more faster than deleting it's content in firefox\r
- new_Obj= t.content_highlight.cloneNode(false);\r
- new_Obj.innerHTML= ""; \r
- t.content_highlight.parentNode.insertBefore(new_Obj, t.content_highlight);\r
- t.content_highlight.parentNode.removeChild(t.content_highlight); \r
- t.content_highlight= new_Obj;\r
- old_class= parent.getAttribute( a,"class" );\r
- if(old_class){\r
- new_class= old_class.replace( "hidden","" );\r
- parent.setAttribute( a, "class", new_class );\r
- }\r
- \r
- a.style.backgroundColor="transparent"; // needed in order to see the bracket finders\r
- \r
- //var icon= document.getElementById("highlight");\r
- //setAttribute(icon, "class", getAttribute(icon, "class").replace(/ selected/g, "") );\r
- //t.restoreClass(icon);\r
- //t.switchClass(icon,'editAreaButtonNormal');\r
- t.switchClassSticky(_$("highlight"), 'editAreaButtonNormal', true);\r
- t.switchClassSticky(_$("reset_highlight"), 'editAreaButtonDisabled', true);\r
- \r
- t.do_highlight=false;\r
- \r
- t.switchClassSticky(_$("change_smooth_selection"), 'editAreaButtonSelected', true);\r
- if(typeof(t.smooth_selection_before_highlight)!="undefined" && t.smooth_selection_before_highlight===false){\r
- t.change_smooth_selection_mode(false);\r
- }\r
- \r
- // this.textarea.style.backgroundColor="#FFFFFF";\r
- };\r
-\r
- EditArea.prototype.enable_highlight= function(){\r
- var t=this, a=t.textarea, new_class;\r
- t.show_waiting_screen();\r
- \r
- t.content_highlight.style.visibility="visible";\r
- new_class =parent.getAttribute(a,"class")+" hidden";\r
- parent.setAttribute( a, "class", new_class );\r
- \r
- // IE can't manage mouse click outside text range without this\r
- if( t.isIE )\r
- a.style.backgroundColor="#FFFFFF"; \r
-\r
- t.switchClassSticky(_$("highlight"), 'editAreaButtonSelected', false);\r
- t.switchClassSticky(_$("reset_highlight"), 'editAreaButtonNormal', false);\r
- \r
- t.smooth_selection_before_highlight=t.smooth_selection;\r
- if(!t.smooth_selection)\r
- t.change_smooth_selection_mode(true);\r
- t.switchClassSticky(_$("change_smooth_selection"), 'editAreaButtonDisabled', true);\r
- \r
- \r
- t.do_highlight=true;\r
- t.resync_highlight();\r
- \r
- t.hide_waiting_screen(); \r
- };\r
- \r
- /**\r
- * Ask to update highlighted text\r
- * @param Array infos - Array of datas returned by EditArea.get_selection_infos()\r
- */\r
- EditArea.prototype.maj_highlight= function(infos){\r
- // for speed mesure\r
- var debug_opti="",tps_start= new Date().getTime(), tps_middle_opti=new Date().getTime();\r
- var t=this, hightlighted_text, updated_highlight; \r
- var textToHighlight=infos["full_text"], doSyntaxOpti = false, doHtmlOpti = false, stay_begin="", stay_end="", trace_new , trace_last;\r
- \r
- if(t.last_text_to_highlight==infos["full_text"] && t.resync_highlight!==true)\r
- return;\r
- \r
- // OPTIMISATION: will search to update only changed lines\r
- if(t.reload_highlight===true){\r
- t.reload_highlight=false;\r
- }else if(textToHighlight.length==0){\r
- textToHighlight="\n ";\r
- }else{\r
- // get text change datas\r
- changes = t.checkTextEvolution(t.last_text_to_highlight,textToHighlight);\r
- \r
- // check if it can only reparse the changed text\r
- trace_new = t.get_syntax_trace(changes.newTextLine).replace(/\r/g, '');\r
- trace_last = t.get_syntax_trace(changes.lastTextLine).replace(/\r/g, '');\r
- doSyntaxOpti = ( trace_new == trace_last );\r
- \r
- // check if the difference comes only from a new line created \r
- // => we have to remember that the editor can automaticaly add tabulation or space after the new line) \r
- if( !doSyntaxOpti && trace_new == "\n"+trace_last && /^[ \t\s]*\n[ \t\s]*$/.test( changes.newText.replace(/\r/g, '') ) && changes.lastText =="" )\r
- {\r
- doSyntaxOpti = true;\r
- }\r
- \r
- // we do the syntax optimisation\r
- if( doSyntaxOpti ){\r
- \r
- tps_middle_opti=new Date().getTime(); \r
- \r
- stay_begin= t.last_hightlighted_text.split("\n").slice(0, changes.lineStart).join("\n");\r
- if(changes.lineStart>0)\r
- stay_begin+= "\n";\r
- stay_end= t.last_hightlighted_text.split("\n").slice(changes.lineLastEnd+1).join("\n");\r
- if(stay_end.length>0)\r
- stay_end= "\n"+stay_end;\r
- \r
- // Final check to see that we're not in the middle of span tags\r
- if( stay_begin.split('<span').length != stay_begin.split('</span').length \r
- || stay_end.split('<span').length != stay_end.split('</span').length )\r
- {\r
- doSyntaxOpti = false;\r
- stay_end = '';\r
- stay_begin = '';\r
- }\r
- else\r
- {\r
- if(stay_begin.length==0 && changes.posLastEnd==-1)\r
- changes.newTextLine+="\n";\r
- textToHighlight=changes.newTextLine;\r
- }\r
- }\r
- if(t.settings["debug"]){\r
- var ch =changes;\r
- debug_opti= ( doSyntaxOpti?"Optimisation": "No optimisation" )\r
- +" start: "+ch.posStart +"("+ch.lineStart+")"\r
- +" end_new: "+ ch.posNewEnd+"("+ch.lineNewEnd+")"\r
- +" end_last: "+ ch.posLastEnd+"("+ch.lineLastEnd+")"\r
- +"\nchanged_text: "+ch.newText+" => trace: "+trace_new\r
- +"\nchanged_last_text: "+ch.lastText+" => trace: "+trace_last\r
- //debug_opti+= "\nchanged: "+ infos["full_text"].substring(ch.posStart, ch.posNewEnd);\r
- + "\nchanged_line: "+ch.newTextLine\r
- + "\nlast_changed_line: "+ch.lastTextLine\r
- +"\nstay_begin: "+ stay_begin.slice(-100)\r
- +"\nstay_end: "+ stay_end.substr( 0, 100 );\r
- //debug_opti="start: "+stay_begin_len+ "("+nb_line_start_unchanged+") end: "+ (stay_end_len)+ "("+(splited.length-nb_line_end_unchanged)+") ";\r
- //debug_opti+="changed: "+ textToHighlight.substring(stay_begin_len, textToHighlight.length-stay_end_len)+" \n";\r
- \r
- //debug_opti+="changed: "+ stay_begin.substr(stay_begin.length-200)+ "----------"+ textToHighlight+"------------------"+ stay_end.substr(0,200) +"\n";\r
- +"\n";\r
- }\r
- \r
- \r
- // END OPTIMISATION\r
- }\r
-\r
- tps_end_opti = new Date().getTime(); \r
- \r
- // apply highlight\r
- updated_highlight = t.colorize_text(textToHighlight);\r
- tpsAfterReg = new Date().getTime();\r
- \r
- /***\r
- * see if we can optimize for updating only the required part of the HTML code\r
- * \r
- * The goal here will be to find the text node concerned by the modification and to update it\r
- */\r
- //-------------------------------------------\r
- // \r
- if( doSyntaxOpti )\r
- {\r
- try\r
- {\r
- var replacedBloc, i, nbStart = '', nbEnd = '', newHtml, lengthOld, lengthNew;\r
- replacedBloc = t.last_hightlighted_text.substring( stay_begin.length, t.last_hightlighted_text.length - stay_end.length );\r
- \r
- lengthOld = replacedBloc.length;\r
- lengthNew = updated_highlight.length;\r
- \r
- // find the identical caracters at the beginning\r
- for( i=0; i < lengthOld && i < lengthNew && replacedBloc.charAt(i) == updated_highlight.charAt(i) ; i++ )\r
- {\r
- }\r
- nbStart = i;\r
- // find the identical caracters at the end\r
- for( i=0; i + nbStart < lengthOld && i + nbStart < lengthNew && replacedBloc.charAt(lengthOld-i-1) == updated_highlight.charAt(lengthNew-i-1) ; i++ )\r
- {\r
- }\r
- nbEnd = i;\r
- \r
- // get the changes\r
- lastHtml = replacedBloc.substring( nbStart, lengthOld - nbEnd );\r
- newHtml = updated_highlight.substring( nbStart, lengthNew - nbEnd );\r
- \r
- \r
- // We can do the optimisation only if we havn't touch to span elements\r
- if( newHtml.indexOf('<span') == -1 && newHtml.indexOf('</span') == -1 \r
- && lastHtml.indexOf('<span') == -1 && lastHtml.indexOf('</span') == -1 )\r
- {\r
- var beginStr, nbOpendedSpan, nbClosedSpan, nbUnchangedChars, span, textNode;\r
- doHtmlOpti = true;\r
- beginStr = t.last_hightlighted_text.substr( 0, stay_begin.length + nbStart );\r
- \r
- nbOpendedSpan = beginStr.split('<span').length - 1;\r
- nbClosedSpan = beginStr.split('</span').length - 1;\r
- // retrieve the previously opened span (Add 1 for the first level span?)\r
- span = t.content_highlight.getElementsByTagName('span')[ nbOpendedSpan ];\r
- \r
- //--------[\r
- // get the textNode to update\r
- \r
- // if we're inside a span, we'll take the one that is opened (can be a parent of the current span)\r
- parentSpan = span;\r
- maxStartOffset = maxEndOffset = 0;\r
- \r
- // it will be in the child of the root node \r
- if( nbOpendedSpan == nbClosedSpan )\r
- {\r
- while( parentSpan.parentNode != t.content_highlight && parentSpan.parentNode.tagName != 'PRE' )\r
- {\r
- parentSpan = parentSpan.parentNode;\r
- }\r
- }\r
- // get the last opened span\r
- else\r
- {\r
- maxStartOffset = maxEndOffset = beginStr.length + 1;\r
- // move to parent node for each closed span found after the lastest open span\r
- nbClosed = beginStr.substr( Math.max( 0, beginStr.lastIndexOf( '<span', maxStartOffset - 1 ) ) ).split('</span').length - 1;\r
- while( nbClosed > 0 )\r
- {\r
- nbClosed--;\r
- parentSpan = parentSpan.parentNode;\r
- }\r
- \r
- // find the position of the last opended tag\r
- while( parentSpan.parentNode != t.content_highlight && parentSpan.parentNode.tagName != 'PRE' && ( tmpMaxStartOffset = Math.max( 0, beginStr.lastIndexOf( '<span', maxStartOffset - 1 ) ) ) < ( tmpMaxEndOffset = Math.max( 0, beginStr.lastIndexOf( '</span', maxEndOffset - 1 ) ) ) )\r
- {\r
- maxStartOffset = tmpMaxStartOffset;\r
- maxEndOffset = tmpMaxEndOffset;\r
- }\r
- }\r
- // Note: maxEndOffset is no more used but maxStartOffset will be used\r
- \r
- if( parentSpan.parentNode == t.content_highlight || parentSpan.parentNode.tagName == 'PRE' )\r
- {\r
- maxStartOffset = Math.max( 0, beginStr.indexOf( '<span' ) );\r
- }\r
- \r
- // find the matching text node (this will be one that will be at the end of the beginStr\r
- if( maxStartOffset == beginStr.length )\r
- {\r
- nbSubSpanBefore = 0;\r
- }\r
- else\r
- {\r
- lastEndPos = Math.max( 0, beginStr.lastIndexOf( '>', maxStartOffset ) );\r
- \r
- // count the number of sub spans\r
- nbSubSpanBefore = beginStr.substr( lastEndPos ).split('<span').length-1;\r
- }\r
- \r
- // there is no sub-span before\r
- if( nbSubSpanBefore == 0 )\r
- {\r
- textNode = parentSpan.firstChild;\r
- }\r
- // we need to find where is the text node modified\r
- else\r
- {\r
- // take the last direct child (no sub-child)\r
- lastSubSpan = parentSpan.getElementsByTagName('span')[ nbSubSpanBefore - 1 ];\r
- while( lastSubSpan.parentNode != parentSpan )\r
- {\r
- lastSubSpan = lastSubSpan.parentNode;\r
- }\r
-\r
- // associate to next text node following the last sub span\r
- if( lastSubSpan.nextSibling == null || lastSubSpan.nextSibling.nodeType != 3 )\r
- {\r
- textNode = document.createTextNode('');\r
- lastSubSpan.parentNode.insertBefore( textNode, lastSubSpan.nextSibling );\r
- }\r
- else\r
- {\r
- textNode = lastSubSpan.nextSibling;\r
- }\r
- }\r
- //--------]\r
- \r
- \r
- //--------[\r
- // update the textNode content\r
- \r
- // number of caracters after the last opened of closed span\r
- nbUnchangedChars = beginStr.length - Math.max( 0, beginStr.lastIndexOf( '>' ) + 1 );\r
- \r
- // console.log( span, textNode, nbOpendedSpan,nbClosedSpan, span.nextSibling, textNode.length, nbUnchangedChars, lastHtml, lastHtml.length, newHtml, newHtml.length );\r
- // alert( textNode.parentNode.className +'-'+ textNode.parentNode.tagName+"\n"+ textNode.data +"\n"+ nbUnchangedChars +"\n"+ lastHtml.length +"\n"+ newHtml +"\n"+ newHtml.length );\r
- \r
- // IE only manage \r for cariage return in textNode and not \n or \r\n\r
- if( t.isIE )\r
- {\r
- nbUnchangedChars -= ( beginStr.substr( beginStr.length - nbUnchangedChars ).split("\n").length - 1 );\r
- //alert( textNode.data.replace(/\r/g, '_r').replace(/\n/g, '_n')); \r
- textNode.replaceData( nbUnchangedChars, lastHtml.replace(/\n/g, '').length, newHtml.replace(/\n/g, '') );\r
- }\r
- else\r
- {\r
- textNode.replaceData( nbUnchangedChars, lastHtml.length, newHtml );\r
- }\r
- //--------]\r
- }\r
- }\r
- // an exception shouldn't occured but if replaceData failed at least it won't break everything\r
- catch( e )\r
- {\r
- // throw e;\r
- // console.log( e );\r
- doHtmlOpti = false;\r
- }\r
- \r
- }\r
- /*** END HTML update's optimisation ***/\r
- // end test\r
- \r
- // console.log( (TPS6-TPS5), (TPS5-TPS4), (TPS4-TPS3), (TPS3-TPS2), (TPS2-TPS1), _CPT );\r
- // get the new highlight content\r
- tpsAfterOpti2 = new Date().getTime();\r
- hightlighted_text = stay_begin + updated_highlight + stay_end;\r
- if( !doHtmlOpti )\r
- {\r
- // update the content of the highlight div by first updating a clone node (as there is no display in the same time for t node it's quite faster (5*))\r
- var new_Obj= t.content_highlight.cloneNode(false);\r
- if( ( t.isIE && t.isIE < 8 ) || ( t.isOpera && t.isOpera < 9.6 ) )\r
- new_Obj.innerHTML= "<pre><span class='"+ t.settings["syntax"] +"'>" + hightlighted_text + "</span></pre>"; \r
- else\r
- new_Obj.innerHTML= "<span class='"+ t.settings["syntax"] +"'>"+ hightlighted_text +"</span>";\r
- \r
- t.content_highlight.parentNode.replaceChild(new_Obj, t.content_highlight);\r
- \r
- t.content_highlight= new_Obj;\r
- }\r
- \r
- t.last_text_to_highlight= infos["full_text"];\r
- t.last_hightlighted_text= hightlighted_text;\r
- \r
- tps3=new Date().getTime();\r
- \r
- if(t.settings["debug"]){\r
- //lineNumber=tab_text.length;\r
- //t.debug.value+=" \nNB char: "+_$("src").value.length+" Nb line: "+ lineNumber;\r
- \r
- t.debug.value= "Tps optimisation "+(tps_end_opti-tps_start)\r
- +" | tps reg exp: "+ (tpsAfterReg-tps_end_opti)\r
- +" | tps opti HTML : "+ (tpsAfterOpti2-tpsAfterReg) + ' '+ ( doHtmlOpti ? 'yes' : 'no' )\r
- +" | tps update highlight content: "+ (tps3-tpsAfterOpti2)\r
- +" | tpsTotal: "+ (tps3-tps_start)\r
- + "("+tps3+")\n"+ debug_opti;\r
- // t.debug.value+= "highlight\n"+hightlighted_text;*/\r
- }\r
- \r
- };\r
- \r
- EditArea.prototype.resync_highlight= function(reload_now){\r
- this.reload_highlight=true;\r
- this.last_text_to_highlight="";\r
- this.focus(); \r
- if(reload_now)\r
- this.check_line_selection(false); \r
- }; \r