source: trunk/plugins/LocalFilesEditor/editarea/manage_area.js @ 5160

Last change on this file since 5160 was 5160, checked in by patdenice, 14 years ago

Editor
Update editarea to 0.8.2.
Remove CSS tab.
Fix jQuery path.

File size: 23.1 KB
Line 
1        EditArea.prototype.focus = function() {
2                this.textarea.focus();
3                this.textareaFocused=true;
4        };
5
6
7        EditArea.prototype.check_line_selection= function(timer_checkup){
8                var changes, infos, new_top, new_width,i;
9               
10                var t1=t2=t2_1=t3=tLines=tend= new Date().getTime();
11                // l'editeur n'existe plus => on quitte
12                if(!editAreas[this.id])
13                        return false;
14               
15                if(!this.smooth_selection && !this.do_highlight)
16                {
17                        //do nothing
18                }
19                else if(this.textareaFocused && editAreas[this.id]["displayed"]==true && this.isResizing==false)
20                {
21                        infos   = this.get_selection_infos();
22                        changes = this.checkTextEvolution( typeof( this.last_selection['full_text'] ) == 'undefined' ? '' : this.last_selection['full_text'], infos['full_text'] );
23               
24                        t2= new Date().getTime();
25                       
26                        // if selection change
27                        if(this.last_selection["line_start"] != infos["line_start"] || this.last_selection["line_nb"] != infos["line_nb"] || infos["full_text"] != this.last_selection["full_text"] || this.reload_highlight || this.last_selection["selectionStart"] != infos["selectionStart"] || this.last_selection["selectionEnd"] != infos["selectionEnd"] || !timer_checkup )
28                        {
29                                // move and adjust text selection elements
30                                new_top         = this.getLinePosTop( infos["line_start"] );
31                                new_width       = Math.max(this.textarea.scrollWidth, this.container.clientWidth -50);
32                                this.selection_field.style.top=this.selection_field_text.style.top=new_top+"px";
33                                if(!this.settings['word_wrap']){       
34                                        this.selection_field.style.width=this.selection_field_text.style.width=this.test_font_size.style.width=new_width+"px";
35                                }
36                               
37                                // usefull? => _$("cursor_pos").style.top=new_top+"px";
38               
39                                if(this.do_highlight==true)
40                                {
41                                        // fill selection elements
42                                        var curr_text   = infos["full_text"].split("\n");
43                                        var content             = "";
44                                        //alert("length: "+curr_text.length+ " i: "+ Math.max(0,infos["line_start"]-1)+ " end: "+Math.min(curr_text.length, infos["line_start"]+infos["line_nb"]-1)+ " line: "+infos["line_start"]+" [0]: "+curr_text[0]+" [1]: "+curr_text[1]);
45                                        var start               = Math.max(0,infos["line_start"]-1);
46                                        var end                 = Math.min(curr_text.length, infos["line_start"]+infos["line_nb"]-1);
47                                       
48                                        //curr_text[start]= curr_text[start].substr(0,infos["curr_pos"]-1) +"¤_overline_¤"+ curr_text[start].substr(infos["curr_pos"]-1);
49                                        for(i=start; i< end; i++){
50                                                content+= curr_text[i]+"\n";   
51                                        }
52                                       
53                                        // add special chars arround selected characters
54                                        selLength       = infos['selectionEnd'] - infos['selectionStart'];
55                                        content         = content.substr( 0, infos["curr_pos"] - 1 ) + "\r\r" + content.substr( infos["curr_pos"] - 1, selLength ) + "\r\r" + content.substr( infos["curr_pos"] - 1 + selLength );
56                                        content         = '<span>'+ content.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace("\r\r", '</span><strong>').replace("\r\r", '</strong><span>') +'</span>';
57                                       
58                                        if( this.isIE || ( this.isOpera && this.isOpera < 9.6 ) ) {
59                                                this.selection_field.innerHTML= "<pre>" + content.replace(/^\r?\n/, "<br>") + "</pre>";
60                                        } else {
61                                                this.selection_field.innerHTML= content;
62                                        }
63                                        this.selection_field_text.innerHTML = this.selection_field.innerHTML;
64                                        t2_1 = new Date().getTime();
65                                        // check if we need to update the highlighted background
66                                        if(this.reload_highlight || (infos["full_text"] != this.last_text_to_highlight && (this.last_selection["line_start"]!=infos["line_start"] || this.show_line_colors || this.settings['word_wrap'] || this.last_selection["line_nb"]!=infos["line_nb"] || this.last_selection["nb_line"]!=infos["nb_line"]) ) )
67                                        {
68                                                this.maj_highlight(infos);
69                                        }
70                                }               
71                        }
72                        t3= new Date().getTime();
73                       
74                        // manage line heights
75                        if( this.settings['word_wrap'] && infos["full_text"] != this.last_selection["full_text"])
76                        {
77                                // refresh only 1 line if text change concern only one line and that the total line number has not changed
78                                if( changes.newText.split("\n").length == 1 && this.last_selection['nb_line'] && infos['nb_line'] == this.last_selection['nb_line'] )
79                                {
80                                        this.fixLinesHeight( infos['full_text'], changes.lineStart, changes.lineStart );
81                                }
82                                else
83                                {
84                                        this.fixLinesHeight( infos['full_text'], changes.lineStart, -1 );
85                                }
86                        }
87               
88                        tLines= new Date().getTime();
89                        // manage bracket finding
90                        if( infos["line_start"] != this.last_selection["line_start"] || infos["curr_pos"] != this.last_selection["curr_pos"] || infos["full_text"].length!=this.last_selection["full_text"].length || this.reload_highlight || !timer_checkup )
91                        {
92                                // move _cursor_pos
93                                var selec_char= infos["curr_line"].charAt(infos["curr_pos"]-1);
94                                var no_real_move=true;
95                                if(infos["line_nb"]==1 && (this.assocBracket[selec_char] || this.revertAssocBracket[selec_char]) ){
96                                       
97                                        no_real_move=false;                                     
98                                        //findEndBracket(infos["line_start"], infos["curr_pos"], selec_char);
99                                        if(this.findEndBracket(infos, selec_char) === true){
100                                                _$("end_bracket").style.visibility      ="visible";
101                                                _$("cursor_pos").style.visibility       ="visible";
102                                                _$("cursor_pos").innerHTML                      = selec_char;
103                                                _$("end_bracket").innerHTML                     = (this.assocBracket[selec_char] || this.revertAssocBracket[selec_char]);
104                                        }else{
105                                                _$("end_bracket").style.visibility      ="hidden";
106                                                _$("cursor_pos").style.visibility       ="hidden";
107                                        }
108                                }else{
109                                        _$("cursor_pos").style.visibility       ="hidden";
110                                        _$("end_bracket").style.visibility      ="hidden";
111                                }
112                                //alert("move cursor");
113                                this.displayToCursorPosition("cursor_pos", infos["line_start"], infos["curr_pos"]-1, infos["curr_line"], no_real_move);
114                                if(infos["line_nb"]==1 && infos["line_start"]!=this.last_selection["line_start"])
115                                        this.scroll_to_view();
116                        }
117                        this.last_selection=infos;
118                }
119               
120                tend= new Date().getTime();
121                //if( (tend-t1) > 7 )
122                //      console.log( "tps total: "+ (tend-t1) + " tps get_infos: "+ (t2-t1)+ " tps selec: "+ (t2_1-t2)+ " tps highlight: "+ (t3-t2_1) +" tps lines: "+ (tLines-t3) +" tps cursor+lines: "+ (tend-tLines)+" \n" );
123               
124               
125                if(timer_checkup){
126                        setTimeout("editArea.check_line_selection(true)", this.check_line_selection_timer);
127                }
128        };
129
130
131        EditArea.prototype.get_selection_infos= function(){
132                var sel={}, start, end, len, str;
133       
134                this.getIESelection();
135                start   = this.textarea.selectionStart;
136                end             = this.textarea.selectionEnd;           
137               
138                if( this.last_selection["selectionStart"] == start && this.last_selection["selectionEnd"] == end && this.last_selection["full_text"] == this.textarea.value )
139                {       
140                        return this.last_selection;
141                }
142                       
143                if(this.tabulation!="\t" && this.textarea.value.indexOf("\t")!=-1) 
144                {       // can append only after copy/paste
145                        len             = this.textarea.value.length;
146                        this.textarea.value     = this.replace_tab(this.textarea.value);
147                        start   = end   = start+(this.textarea.value.length-len);
148                        this.area_select( start, 0 );
149                }
150               
151                sel["selectionStart"]   = start;
152                sel["selectionEnd"]             = end;         
153                sel["full_text"]                = this.textarea.value;
154                sel["line_start"]               = 1;
155                sel["line_nb"]                  = 1;
156                sel["curr_pos"]                 = 0;
157                sel["curr_line"]                = "";
158                sel["indexOfCursor"]    = 0;
159                sel["selec_direction"]  = this.last_selection["selec_direction"];
160
161                //return sel;   
162                var splitTab= sel["full_text"].split("\n");
163                var nbLine      = Math.max(0, splitTab.length);         
164                var nbChar      = Math.max(0, sel["full_text"].length - (nbLine - 1));  // (remove \n caracters from the count)
165                if( sel["full_text"].indexOf("\r") != -1 )
166                        nbChar  = nbChar - ( nbLine - 1 );              // (remove \r caracters from the count)
167                sel["nb_line"]  = nbLine;               
168                sel["nb_char"]  = nbChar;
169       
170                if(start>0){
171                        str                                     = sel["full_text"].substr(0,start);
172                        sel["curr_pos"]         = start - str.lastIndexOf("\n");
173                        sel["line_start"]       = Math.max(1, str.split("\n").length);
174                }else{
175                        sel["curr_pos"]=1;
176                }
177                if(end>start){
178                        sel["line_nb"]=sel["full_text"].substring(start,end).split("\n").length;
179                }
180                sel["indexOfCursor"]=start;             
181                sel["curr_line"]=splitTab[Math.max(0,sel["line_start"]-1)];
182       
183                // determine in which direction the selection grow
184                if(sel["selectionStart"] == this.last_selection["selectionStart"]){
185                        if(sel["selectionEnd"]>this.last_selection["selectionEnd"])
186                                sel["selec_direction"]= "down";
187                        else if(sel["selectionEnd"] == this.last_selection["selectionStart"])
188                                sel["selec_direction"]= this.last_selection["selec_direction"];
189                }else if(sel["selectionStart"] == this.last_selection["selectionEnd"] && sel["selectionEnd"]>this.last_selection["selectionEnd"]){
190                        sel["selec_direction"]= "down";
191                }else{
192                        sel["selec_direction"]= "up";
193                }
194               
195                _$("nbLine").innerHTML  = nbLine;               
196                _$("nbChar").innerHTML  = nbChar;               
197                _$("linePos").innerHTML = sel["line_start"];
198                _$("currPos").innerHTML = sel["curr_pos"];
199
200                return sel;             
201        };
202       
203        // set IE position in Firefox mode (textarea.selectionStart and textarea.selectionEnd)
204        EditArea.prototype.getIESelection= function(){
205                var selectionStart, selectionEnd, range, stored_range;
206               
207                if( !this.isIE )
208                        return false;
209                       
210                // make it work as nowrap mode (easier for range manipulation with lineHeight)
211                if( this.settings['word_wrap'] )
212                        this.textarea.wrap='off';
213                       
214                try{
215                        range                   = document.selection.createRange();
216                        stored_range    = range.duplicate();
217                        stored_range.moveToElementText( this.textarea );
218                        stored_range.setEndPoint( 'EndToEnd', range );
219                        if( stored_range.parentElement() != this.textarea )
220                                throw "invalid focus";
221                               
222                        // the range don't take care of empty lines in the end of the selection
223                        var scrollTop   = this.result.scrollTop + document.body.scrollTop;
224                        var relative_top= range.offsetTop - parent.calculeOffsetTop(this.textarea) + scrollTop;
225                        var line_start  = Math.round((relative_top / this.lineHeight) +1);
226                        var line_nb             = Math.round( range.boundingHeight / this.lineHeight );
227                                               
228                        selectionStart  = stored_range.text.length - range.text.length;         
229                        selectionStart  += ( line_start - this.textarea.value.substr(0, selectionStart).split("\n").length)*2;          // count missing empty \r to the selection
230                        selectionStart  -= ( line_start - this.textarea.value.substr(0, selectionStart).split("\n").length ) * 2;
231                       
232                        selectionEnd    = selectionStart + range.text.length;           
233                        selectionEnd    += (line_start + line_nb - 1 - this.textarea.value.substr(0, selectionEnd ).split("\n").length)*2;                     
234               
235                        this.textarea.selectionStart    = selectionStart;
236                        this.textarea.selectionEnd              = selectionEnd;
237                }
238                catch(e){}
239               
240                // restore wrap mode
241                if( this.settings['word_wrap'] )
242                        this.textarea.wrap='soft';
243        };
244       
245        // select the text for IE (and take care of \r caracters)
246        EditArea.prototype.setIESelection= function(){
247                var a = this.textarea, nbLineStart, nbLineEnd, range;
248               
249                if( !this.isIE )
250                        return false;
251               
252                nbLineStart     = a.value.substr(0, a.selectionStart).split("\n").length - 1;
253                nbLineEnd       = a.value.substr(0, a.selectionEnd).split("\n").length - 1;
254                range           = document.selection.createRange();
255                range.moveToElementText( a );
256                range.setEndPoint( 'EndToStart', range );
257               
258                range.moveStart('character', a.selectionStart - nbLineStart);
259                range.moveEnd('character', a.selectionEnd - nbLineEnd - (a.selectionStart - nbLineStart)  );
260                range.select();
261        };
262       
263       
264       
265        EditArea.prototype.checkTextEvolution=function(lastText,newText){
266                // ch will contain changes datas
267                var ch={},baseStep=200, cpt=0, end, step,tStart=new Date().getTime();
268       
269                end             = Math.min(newText.length, lastText.length);
270        step    = baseStep;
271        // find how many chars are similar at the begin of the text                                             
272                while( cpt<end && step>=1 ){
273            if(lastText.substr(cpt, step) == newText.substr(cpt, step)){
274                cpt+= step;
275            }else{
276                step= Math.floor(step/2);
277            }
278                }
279               
280                ch.posStart     = cpt;
281                ch.lineStart= newText.substr(0, ch.posStart).split("\n").length -1;                                             
282               
283                cpt_last        = lastText.length;
284        cpt                     = newText.length;
285        step            = baseStep;                     
286        // find how many chars are similar at the end of the text                                               
287                while( cpt>=0 && cpt_last>=0 && step>=1 ){
288            if(lastText.substr(cpt_last-step, step) == newText.substr(cpt-step, step)){
289                cpt-= step;
290                cpt_last-= step;
291            }else{
292                step= Math.floor(step/2);
293            }
294                }
295               
296                ch.posNewEnd    = cpt;
297                ch.posLastEnd   = cpt_last;
298                if(ch.posNewEnd<=ch.posStart){
299                        if(lastText.length < newText.length){
300                                ch.posNewEnd= ch.posStart + newText.length - lastText.length;
301                                ch.posLastEnd= ch.posStart;
302                        }else{
303                                ch.posLastEnd= ch.posStart + lastText.length - newText.length;
304                                ch.posNewEnd= ch.posStart;
305                        }
306                } 
307                ch.newText              = newText.substring(ch.posStart, ch.posNewEnd);
308                ch.lastText             = lastText.substring(ch.posStart, ch.posLastEnd);                                   
309               
310                ch.lineNewEnd   = newText.substr(0, ch.posNewEnd).split("\n").length -1;
311                ch.lineLastEnd  = lastText.substr(0, ch.posLastEnd).split("\n").length -1;
312               
313                ch.newTextLine  = newText.split("\n").slice(ch.lineStart, ch.lineNewEnd+1).join("\n");
314                ch.lastTextLine = lastText.split("\n").slice(ch.lineStart, ch.lineLastEnd+1).join("\n");
315                //console.log( ch );
316                return ch;     
317        };
318       
319        EditArea.prototype.tab_selection= function(){
320                if(this.is_tabbing)
321                        return;
322                this.is_tabbing=true;
323                //infos=getSelectionInfos();
324                //if( document.selection ){
325                this.getIESelection();
326                /* Insertion du code de formatage */
327                var start = this.textarea.selectionStart;
328                var end = this.textarea.selectionEnd;
329                var insText = this.textarea.value.substring(start, end);
330               
331                /* Insert tabulation and ajust cursor position */
332                var pos_start=start;
333                var pos_end=end;
334                if (insText.length == 0) {
335                        // if only one line selected
336                        this.textarea.value = this.textarea.value.substr(0, start) + this.tabulation + this.textarea.value.substr(end);
337                        pos_start = start + this.tabulation.length;
338                        pos_end=pos_start;
339                } else {
340                        start= Math.max(0, this.textarea.value.substr(0, start).lastIndexOf("\n")+1);
341                        endText=this.textarea.value.substr(end);
342                        startText=this.textarea.value.substr(0, start);
343                        tmp= this.textarea.value.substring(start, end).split("\n");
344                        insText= this.tabulation+tmp.join("\n"+this.tabulation);
345                        this.textarea.value = startText + insText + endText;
346                        pos_start = start;
347                        pos_end= this.textarea.value.indexOf("\n", startText.length + insText.length);
348                        if(pos_end==-1)
349                                pos_end=this.textarea.value.length;
350                        //pos = start + repdeb.length + insText.length + ;
351                }
352                this.textarea.selectionStart = pos_start;
353                this.textarea.selectionEnd = pos_end;
354               
355                //if( document.selection ){
356                if(this.isIE)
357                {
358                        this.setIESelection();
359                        setTimeout("editArea.is_tabbing=false;", 100);  // IE can't accept to make 2 tabulation without a little break between both
360                }
361                else
362                { 
363                        this.is_tabbing=false;
364                }       
365               
366        };
367       
368        EditArea.prototype.invert_tab_selection= function(){
369                var t=this, a=this.textarea;
370                if(t.is_tabbing)
371                        return;
372                t.is_tabbing=true;
373                //infos=getSelectionInfos();
374                //if( document.selection ){
375                t.getIESelection();
376               
377                var start       = a.selectionStart;
378                var end         = a.selectionEnd;
379                var insText     = a.value.substring(start, end);
380               
381                /* Tab remove and cursor seleciton adjust */
382                var pos_start=start;
383                var pos_end=end;
384                if (insText.length == 0) {
385                        if(a.value.substring(start-t.tabulation.length, start)==t.tabulation)
386                        {
387                                a.value         = a.value.substr(0, start-t.tabulation.length) + a.value.substr(end);
388                                pos_start       = Math.max(0, start-t.tabulation.length);
389                                pos_end         = pos_start;
390                        }       
391                        /*
392                        a.value = a.value.substr(0, start) + t.tabulation + insText + a.value.substr(end);
393                        pos_start = start + t.tabulation.length;
394                        pos_end=pos_start;*/
395                } else {
396                        start           = a.value.substr(0, start).lastIndexOf("\n")+1;
397                        endText         = a.value.substr(end);
398                        startText       = a.value.substr(0, start);
399                        tmp                     = a.value.substring(start, end).split("\n");
400                        insText         = "";
401                        for(i=0; i<tmp.length; i++){                           
402                                for(j=0; j<t.tab_nb_char; j++){
403                                        if(tmp[i].charAt(0)=="\t"){
404                                                tmp[i]=tmp[i].substr(1);
405                                                j=t.tab_nb_char;
406                                        }else if(tmp[i].charAt(0)==" ")
407                                                tmp[i]=tmp[i].substr(1);
408                                }               
409                                insText+=tmp[i];
410                                if(i<tmp.length-1)
411                                        insText+="\n";
412                        }
413                        //insText+="_";
414                        a.value         = startText + insText + endText;
415                        pos_start       = start;
416                        pos_end         = a.value.indexOf("\n", startText.length + insText.length);
417                        if(pos_end==-1)
418                                pos_end=a.value.length;
419                        //pos = start + repdeb.length + insText.length + ;
420                }
421                a.selectionStart = pos_start;
422                a.selectionEnd = pos_end;
423               
424                //if( document.selection ){
425                if(t.isIE){
426                        // select the text for IE
427                        t.setIESelection();
428                        setTimeout("editArea.is_tabbing=false;", 100);  // IE can accept to make 2 tabulation without a little break between both
429                }else
430                        t.is_tabbing=false;
431        };
432       
433        EditArea.prototype.press_enter= function(){             
434                if(!this.smooth_selection)
435                        return false;
436                this.getIESelection();
437                var scrollTop= this.result.scrollTop;
438                var scrollLeft= this.result.scrollLeft;
439                var start=this.textarea.selectionStart;
440                var end= this.textarea.selectionEnd;
441                var start_last_line= Math.max(0 , this.textarea.value.substring(0, start).lastIndexOf("\n") + 1 );
442                var begin_line= this.textarea.value.substring(start_last_line, start).replace(/^([ \t]*).*/gm, "$1");
443                var lineStart = this.textarea.value.substring(0, start).split("\n").length;
444                if(begin_line=="\n" || begin_line=="\r" || begin_line.length==0)
445                {
446                        return false;
447                }
448                       
449                if(this.isIE || ( this.isOpera && this.isOpera < 9.6 ) ){
450                        begin_line="\r\n"+ begin_line;
451                }else{
452                        begin_line="\n"+ begin_line;
453                }       
454                //alert(start_last_line+" strat: "+start +"\n"+this.textarea.value.substring(start_last_line, start)+"\n_"+begin_line+"_")
455                this.textarea.value= this.textarea.value.substring(0, start) + begin_line + this.textarea.value.substring(end);
456               
457                this.area_select(start+ begin_line.length ,0);
458                // during this process IE scroll back to the top of the textarea
459                if(this.isIE){
460                        this.result.scrollTop   = scrollTop;
461                        this.result.scrollLeft  = scrollLeft;
462                }
463                return true;
464               
465        };
466       
467        EditArea.prototype.findEndBracket= function(infos, bracket){
468                       
469                var start=infos["indexOfCursor"];
470                var normal_order=true;
471                //curr_text=infos["full_text"].split("\n");
472                if(this.assocBracket[bracket])
473                        endBracket=this.assocBracket[bracket];
474                else if(this.revertAssocBracket[bracket]){
475                        endBracket=this.revertAssocBracket[bracket];
476                        normal_order=false;
477                }       
478                var end=-1;
479                var nbBracketOpen=0;
480               
481                for(var i=start; i<infos["full_text"].length && i>=0; ){
482                        if(infos["full_text"].charAt(i)==endBracket){                           
483                                nbBracketOpen--;
484                                if(nbBracketOpen<=0){
485                                        //i=infos["full_text"].length;
486                                        end=i;
487                                        break;
488                                }
489                        }else if(infos["full_text"].charAt(i)==bracket)
490                                nbBracketOpen++;
491                        if(normal_order)
492                                i++;
493                        else
494                                i--;
495                }
496               
497                //end=infos["full_text"].indexOf("}", start);
498                if(end==-1)
499                        return false;   
500                var endLastLine=infos["full_text"].substr(0, end).lastIndexOf("\n");                   
501                if(endLastLine==-1)
502                        line=1;
503                else
504                        line= infos["full_text"].substr(0, endLastLine).split("\n").length + 1;
505                                       
506                var curPos= end - endLastLine - 1;
507                var endLineLength       = infos["full_text"].substring(end).split("\n")[0].length;
508                this.displayToCursorPosition("end_bracket", line, curPos, infos["full_text"].substring(endLastLine +1, end + endLineLength));
509                return true;
510        };
511       
512        EditArea.prototype.displayToCursorPosition= function(id, start_line, cur_pos, lineContent, no_real_move){
513                var elem,dest,content,posLeft=0,posTop,fixPadding,topOffset,endElem;   
514
515                elem            = this.test_font_size;
516                dest            = _$(id);
517                content         = "<span id='test_font_size_inner'>"+lineContent.substr(0, cur_pos).replace(/&/g,"&amp;").replace(/</g,"&lt;")+"</span><span id='endTestFont'>"+lineContent.substr(cur_pos).replace(/&/g,"&amp;").replace(/</g,"&lt;")+"</span>";
518                if( this.isIE || ( this.isOpera && this.isOpera < 9.6 ) ) {
519                        elem.innerHTML= "<pre>" + content.replace(/^\r?\n/, "<br>") + "</pre>";
520                } else {
521                        elem.innerHTML= content;
522                }
523               
524
525                endElem         = _$('endTestFont');
526                topOffset       = endElem.offsetTop;
527                fixPadding      = parseInt( this.content_highlight.style.paddingLeft.replace("px", "") );
528                posLeft         = 45 + endElem.offsetLeft + ( !isNaN( fixPadding ) && topOffset > 0 ? fixPadding : 0 );
529                posTop          = this.getLinePosTop( start_line ) + topOffset;// + Math.floor( ( endElem.offsetHeight - 1 ) / this.lineHeight ) * this.lineHeight;
530       
531                // detect the case where the span start on a line but has no display on it
532                if( this.isIE && cur_pos > 0 && endElem.offsetLeft == 0 )
533                {
534                        posTop  +=      this.lineHeight;
535                }
536                if(no_real_move!=true){ // when the cursor is hidden no need to move him
537                        dest.style.top=posTop+"px";
538                        dest.style.left=posLeft+"px";   
539                }
540                // usefull for smarter scroll
541                dest.cursor_top=posTop;
542                dest.cursor_left=posLeft;       
543        //      _$(id).style.marginLeft=posLeft+"px";
544        };
545       
546        EditArea.prototype.getLinePosTop= function(start_line){
547                var elem= _$('line_'+ start_line), posTop=0;
548                if( elem )
549                        posTop  = elem.offsetTop;
550                else
551                        posTop  = this.lineHeight * (start_line-1);
552                return posTop;
553        };
554       
555       
556        // return the dislpayed height of a text (take word-wrap into account)
557        EditArea.prototype.getTextHeight= function(text){
558                var t=this,elem,height;
559                elem            = t.test_font_size;
560                content         = text.replace(/&/g,"&amp;").replace(/</g,"&lt;");
561                if( t.isIE || ( this.isOpera && this.isOpera < 9.6 ) ) {
562                        elem.innerHTML= "<pre>" + content.replace(/^\r?\n/, "<br>") + "</pre>";
563                } else {
564                        elem.innerHTML= content;
565                }
566                height  = elem.offsetHeight;
567                height  = Math.max( 1, Math.floor( elem.offsetHeight / this.lineHeight ) ) * this.lineHeight;
568                return height;
569        };
570
571        /**
572         * Fix line height for the given lines
573         * @param Integer linestart
574         * @param Integer lineEnd End line or -1 to cover all lines
575         */
576        EditArea.prototype.fixLinesHeight= function( textValue, lineStart,lineEnd ){
577                var aText = textValue.split("\n");
578                if( lineEnd == -1 )
579                        lineEnd = aText.length-1;
580                for( var i = Math.max(0, lineStart); i <= lineEnd; i++ )
581                {
582                        if( elem = _$('line_'+ ( i+1 ) ) )
583                        {
584                                elem.style.height= typeof( aText[i] ) != "undefined" ? this.getTextHeight( aText[i] )+"px" : this.lineHeight;
585                        }
586                }
587        };
588       
589        EditArea.prototype.area_select= function(start, length){
590                this.textarea.focus();
591               
592                start   = Math.max(0, Math.min(this.textarea.value.length, start));
593                end             = Math.max(start, Math.min(this.textarea.value.length, start+length));
594
595                if(this.isIE)
596                {
597                        this.textarea.selectionStart    = start;
598                        this.textarea.selectionEnd              = end;         
599                        this.setIESelection();
600                }
601                else
602                {
603                        // Opera bug when moving selection start and selection end
604                        if(this.isOpera && this.isOpera < 9.6 )
605                        {       
606                                this.textarea.setSelectionRange(0, 0);
607                        }
608                        this.textarea.setSelectionRange(start, end);
609                }
610                this.check_line_selection();
611        };
612       
613       
614        EditArea.prototype.area_get_selection= function(){
615                var text="";
616                if( document.selection ){
617                        var range = document.selection.createRange();
618                        text=range.text;
619                }else{
620                        text= this.textarea.value.substring(this.textarea.selectionStart, this.textarea.selectionEnd);
621                }
622                return text;                   
623        };
Note: See TracBrowser for help on using the repository browser.