unageanu-jiji 1.1.4 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (233) hide show
  1. data/ChangeLog +24 -1
  2. data/README +0 -0
  3. data/base/shared_lib/moving_average.rb +34 -33
  4. data/base/shared_lib/system/cross.rb +76 -0
  5. data/base/shared_lib/system/position_manager.rb +160 -0
  6. data/base/shared_lib/system/signal.rb +347 -0
  7. data/html/css/datatable.css +4 -4
  8. data/html/css/default.css +57 -5
  9. data/html/css/treeview.css +205 -0
  10. data/html/img/bin_closed.png +0 -0
  11. data/html/img/bin_empty.png +0 -0
  12. data/html/img/button_add_small.gif +0 -0
  13. data/html/img/button_add_small_gray.gif +0 -0
  14. data/html/img/button_add_small_over.gif +0 -0
  15. data/html/img/button_mkcol.gif +0 -0
  16. data/html/img/button_mkcol_gray.gif +0 -0
  17. data/html/img/button_mkcol_over.gif +0 -0
  18. data/html/img/button_remove_small.gif +0 -0
  19. data/html/img/button_remove_small_gray.gif +0 -0
  20. data/html/img/button_remove_small_over.gif +0 -0
  21. data/html/img/button_rename.gif +0 -0
  22. data/html/img/button_rename_gray.gif +0 -0
  23. data/html/img/button_rename_over.gif +0 -0
  24. data/html/img/control_play.png +0 -0
  25. data/html/img/control_play_blue.png +0 -0
  26. data/html/img/folder.png +0 -0
  27. data/html/img/folder_brick.png +0 -0
  28. data/html/img/folder_user.png +0 -0
  29. data/html/{js/codepress/images → img}/line-numbers.png +0 -0
  30. data/html/img/page_white_ruby.png +0 -0
  31. data/html/img/sidebar_agent_edit.png +0 -0
  32. data/html/img/sidebar_agent_edit_over.png +0 -0
  33. data/html/img/sidebar_agent_edit_s.png +0 -0
  34. data/html/img/yui/treeview-sprite.gif +0 -0
  35. data/html/index.html +34 -18
  36. data/html/js/agent-editor/agent-editor-page.js +324 -0
  37. data/html/js/agent-editor/agent-editor.js +363 -0
  38. data/html/js/agent-editor/agent-list-tree.js +251 -0
  39. data/html/js/agent-selector.js +23 -28
  40. data/html/js/app.js +63 -91
  41. data/html/js/bt-create-page.js +25 -19
  42. data/html/js/container-min.js +1 -1
  43. data/html/js/container.js +944 -0
  44. data/html/js/edit_area/autocompletion.js +11 -13
  45. data/html/js/edit_area/edit_area.css +79 -40
  46. data/html/js/edit_area/edit_area.js +255 -226
  47. data/html/js/edit_area/edit_area_compressor.php +4 -4
  48. data/html/js/edit_area/edit_area_full.gz +0 -0
  49. data/html/js/edit_area/edit_area_full.js +31 -31
  50. data/html/js/edit_area/edit_area_full_with_plugins.gz +0 -0
  51. data/html/js/edit_area/edit_area_full_with_plugins.js +31 -31
  52. data/html/js/edit_area/edit_area_functions.js +448 -341
  53. data/html/js/edit_area/edit_area_loader.js +409 -397
  54. data/html/js/edit_area/elements_functions.js +120 -123
  55. data/html/js/edit_area/highlight.js +305 -197
  56. data/html/js/edit_area/images/goto.png +0 -0
  57. data/html/js/edit_area/images/help.png +0 -0
  58. data/html/js/edit_area/images/redo.png +0 -0
  59. data/html/js/edit_area/images/save.png +0 -0
  60. data/html/js/edit_area/images/search.png +0 -0
  61. data/html/js/edit_area/images/undo.png +0 -0
  62. data/html/js/edit_area/images/word_wrap.gif +0 -0
  63. data/html/js/edit_area/keyboard.js +5 -5
  64. data/html/js/edit_area/langs/bg.js +73 -0
  65. data/html/js/edit_area/langs/cs.js +2 -0
  66. data/html/js/edit_area/langs/de.js +2 -0
  67. data/html/js/edit_area/langs/dk.js +2 -0
  68. data/html/js/edit_area/langs/en.js +2 -0
  69. data/html/js/edit_area/langs/eo.js +2 -0
  70. data/html/js/edit_area/langs/es.js +2 -0
  71. data/html/js/edit_area/langs/fi.js +67 -0
  72. data/html/js/edit_area/langs/fr.js +2 -0
  73. data/html/js/edit_area/langs/hr.js +2 -0
  74. data/html/js/edit_area/langs/it.js +2 -0
  75. data/html/js/edit_area/langs/ja.js +2 -0
  76. data/html/js/edit_area/langs/mk.js +2 -0
  77. data/html/js/edit_area/langs/nl.js +2 -0
  78. data/html/js/edit_area/langs/pl.js +2 -0
  79. data/html/js/edit_area/langs/pt.js +2 -0
  80. data/html/js/edit_area/langs/ru.js +2 -0
  81. data/html/js/edit_area/langs/sk.js +2 -0
  82. data/html/js/edit_area/langs/zh.js +67 -0
  83. data/html/js/edit_area/manage_area.js +362 -205
  84. data/html/js/edit_area/plugins/charmap/langs/bg.js +12 -0
  85. data/html/js/edit_area/plugins/charmap/langs/zh.js +6 -0
  86. data/html/js/edit_area/plugins/test/langs/bg.js +10 -0
  87. data/html/js/edit_area/plugins/test/langs/zh.js +4 -0
  88. data/html/js/edit_area/reg_syntax/java.js +56 -0
  89. data/html/js/edit_area/reg_syntax/ruby.js +9 -9
  90. data/html/js/edit_area/reg_syntax.js +15 -13
  91. data/html/js/edit_area/regexp.js +36 -32
  92. data/html/js/edit_area/resize_area.js +43 -47
  93. data/html/js/edit_area/search_replace.js +29 -29
  94. data/html/js/edit_area/template.html +6 -4
  95. data/html/js/json-broker-client.js +23 -17
  96. data/html/js/result-page.js +107 -57
  97. data/html/js/rt-setting-page.js +38 -15
  98. data/html/js/sidebar.js +41 -27
  99. data/html/js/templates.js +167 -32
  100. data/html/js/utils.js +143 -7
  101. data/html/js/yui/treeview.js +3671 -0
  102. data/html/swf/chart.swf +0 -0
  103. data/html/test/agent_editor_spec.js +815 -0
  104. data/html/test/index.html +40 -0
  105. data/html/test/jsspec/JSSpec.css +224 -0
  106. data/html/test/jsspec/JSSpec.js +1549 -0
  107. data/html/test/jsspec/diff_match_patch.js +1 -0
  108. data/html/test/utils_spec.js +111 -0
  109. data/lib/jiji/agent/agent.rb +69 -12
  110. data/lib/jiji/agent/agent_manager.rb +18 -12
  111. data/lib/jiji/agent/agent_registry.rb +35 -121
  112. data/lib/jiji/collector.rb +16 -6
  113. data/lib/jiji/command.rb +46 -5
  114. data/lib/jiji/dao/file_system_dao.rb +158 -0
  115. data/lib/jiji/dao/timed_data_dao.rb +2 -0
  116. data/lib/jiji/dao/trade_result_dao.rb +1 -1
  117. data/lib/jiji/error.rb +24 -8
  118. data/lib/jiji/migration/migrator1_2_0.rb +67 -0
  119. data/lib/jiji/models.rb +82 -24
  120. data/lib/jiji/operator.rb +55 -51
  121. data/lib/jiji/output.rb +85 -29
  122. data/lib/jiji/output_manager.rb +84 -0
  123. data/lib/jiji/plugin/embedded/single_click_client.rb +2 -2
  124. data/lib/jiji/plugin/securities_plugin.rb +0 -1
  125. data/lib/jiji/process.rb +229 -208
  126. data/lib/jiji/process_manager.rb +190 -96
  127. data/lib/jiji/registry.rb +87 -19
  128. data/lib/jiji/server.rb +1 -0
  129. data/lib/jiji/service/agent_service.rb +147 -48
  130. data/lib/jiji/service/output_service.rb +37 -17
  131. data/lib/jiji/service/process_service.rb +3 -5
  132. data/lib/jiji/service/trade_result_service.rb +4 -5
  133. data/lib/jiji/util/file_lock.rb +4 -4
  134. data/lib/jiji/util/include_proxy.rb +17 -0
  135. data/lib/jiji/util/json_broker.rb +6 -4
  136. data/lib/jiji/util/util.rb +1 -1
  137. data/swf/chart/fx/chart/Chart.as +7 -0
  138. data/swf/chart/fx/chart/ui/graph/GraphManager.as +15 -2
  139. data/test/ProcessTest/agents/foo.rb +10 -0
  140. data/test/ProcessTest/conf/configuration.yaml +3 -0
  141. data/test/agent/agent_tests.rb +10 -0
  142. data/test/agent/test_AgentManager.rb +28 -12
  143. data/test/agent/test_AgentRegistry.rb +194 -99
  144. data/test/agent/test_PeriodicallyAgent.rb +1 -2
  145. data/test/agent/test_Permitter.rb +1 -2
  146. data/test/all_tests.rb +7 -19
  147. data/test/dao/dao_tests.rb +9 -0
  148. data/test/dao/test_FileSystemDao.rb +431 -0
  149. data/test/dao/test_RateDao.rb +5 -7
  150. data/test/dao/test_TradeResultDao.rb +1 -2
  151. data/test/migration/migration_tests.rb +10 -0
  152. data/test/migration/migrator1_2_0test_data/basic/out/M2NlOTA2ODEtZDdlNi00NWU1LWIwNDQtMjBmODY2ZGNkNzBj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  153. data/test/migration/migrator1_2_0test_data/basic/out/MDVhYzcxMjYtMGFlMS00Mzk0LWEyNmUtYjVjZjgwNDA0ZmE2/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  154. data/test/migration/migrator1_2_0test_data/basic/out/MzA1YTk0NDgtNzhjNi00NDk3LTk2NTktYzE1ZjBhNzdiYjNj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  155. data/test/migration/migrator1_2_0test_data/basic/out/YjRkOTI1MzEtZTM4MS00YjQwLTg1ZTQtMWFmZDRlNDUwMzBm/56e75YuV5bmz5Z2H57ea/meta.yaml +9 -0
  156. data/test/migration/migrator1_2_0test_data/basic/props.yaml +85 -0
  157. data/test/migration/migrator1_2_0test_data/illegal_props/out/M2NlOTA2ODEtZDdlNi00NWU1LWIwNDQtMjBmODY2ZGNkNzBj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  158. data/test/migration/migrator1_2_0test_data/illegal_props/out/MDVhYzcxMjYtMGFlMS00Mzk0LWEyNmUtYjVjZjgwNDA0ZmE2/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  159. data/test/migration/migrator1_2_0test_data/illegal_props/out/MzA1YTk0NDgtNzhjNi00NDk3LTk2NTktYzE1ZjBhNzdiYjNj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  160. data/test/migration/migrator1_2_0test_data/illegal_props/out/YjRkOTI1MzEtZTM4MS00YjQwLTg1ZTQtMWFmZDRlNDUwMzBm/56e75YuV5bmz5Z2H57ea/meta.yaml +9 -0
  161. data/test/migration/migrator1_2_0test_data/illegal_props/props.yaml +1 -0
  162. data/test/migration/migrator1_2_0test_data/no_outs/props.yaml +85 -0
  163. data/test/migration/migrator1_2_0test_data/no_props/out/M2NlOTA2ODEtZDdlNi00NWU1LWIwNDQtMjBmODY2ZGNkNzBj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  164. data/test/migration/migrator1_2_0test_data/no_props/out/MDVhYzcxMjYtMGFlMS00Mzk0LWEyNmUtYjVjZjgwNDA0ZmE2/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  165. data/test/migration/migrator1_2_0test_data/no_props/out/MzA1YTk0NDgtNzhjNi00NDk3LTk2NTktYzE1ZjBhNzdiYjNj/56e75YuV5bmz5Z2H57ea/meta.yaml +8 -0
  166. data/test/migration/migrator1_2_0test_data/no_props/out/YjRkOTI1MzEtZTM4MS00YjQwLTg1ZTQtMWFmZDRlNDUwMzBm/56e75YuV5bmz5Z2H57ea/meta.yaml +9 -0
  167. data/test/migration/test_Migrator.rb +1 -1
  168. data/test/migration/test_Migrator1_0_3.rb +1 -1
  169. data/test/migration/test_Migrator1_1_0.rb +1 -1
  170. data/test/migration/test_Migrator1_2_0.rb +94 -0
  171. data/test/plugin/embedded/test_SingleClickClient.rb +1 -2
  172. data/test/plugin/plugin_tests.rb +8 -0
  173. data/test/plugin/test_Loader.rb +1 -1
  174. data/test/shared/rate.csv +144 -0
  175. data/test/shared/shared_tests.rb +9 -0
  176. data/test/shared/test_Cross.rb +144 -0
  177. data/test/shared/test_PositionManager.rb +285 -0
  178. data/test/shared/test_Signal.rb +65 -0
  179. data/test/test_Output.rb +28 -21
  180. data/test/test_OutputManager.rb +162 -0
  181. data/test/test_Output_registry.rb +6 -17
  182. data/test/test_Process.rb +434 -222
  183. data/test/test_ProcessManager.rb +458 -101
  184. data/test/test_utils.rb +71 -8
  185. data/test/util/test_BlockToSession.rb +1 -2
  186. data/test/util/test_CSV.rb +1 -2
  187. data/test/util/test_SynchronizeInterceptor.rb +1 -2
  188. data/test/util/util_tests.rb +9 -0
  189. metadata +127 -47
  190. data/html/js/agent-editor-page.js +0 -440
  191. data/html/js/codepress/codepress.css +0 -21
  192. data/html/js/codepress/codepress.html +0 -35
  193. data/html/js/codepress/codepress.js +0 -138
  194. data/html/js/codepress/engines/gecko.js +0 -293
  195. data/html/js/codepress/engines/khtml.js +0 -0
  196. data/html/js/codepress/engines/msie.js +0 -304
  197. data/html/js/codepress/engines/older.js +0 -0
  198. data/html/js/codepress/engines/opera.js +0 -260
  199. data/html/js/codepress/images/line-numbers.gif +0 -0
  200. data/html/js/codepress/index.html +0 -443
  201. data/html/js/codepress/languages/asp.css +0 -71
  202. data/html/js/codepress/languages/asp.js +0 -117
  203. data/html/js/codepress/languages/autoit.css +0 -13
  204. data/html/js/codepress/languages/autoit.js +0 -32
  205. data/html/js/codepress/languages/csharp.css +0 -9
  206. data/html/js/codepress/languages/csharp.js +0 -25
  207. data/html/js/codepress/languages/css.css +0 -10
  208. data/html/js/codepress/languages/css.js +0 -23
  209. data/html/js/codepress/languages/generic.css +0 -9
  210. data/html/js/codepress/languages/generic.js +0 -25
  211. data/html/js/codepress/languages/html.css +0 -13
  212. data/html/js/codepress/languages/html.js +0 -59
  213. data/html/js/codepress/languages/java.css +0 -7
  214. data/html/js/codepress/languages/java.js +0 -24
  215. data/html/js/codepress/languages/javascript.css +0 -8
  216. data/html/js/codepress/languages/javascript.js +0 -30
  217. data/html/js/codepress/languages/perl.css +0 -11
  218. data/html/js/codepress/languages/perl.js +0 -27
  219. data/html/js/codepress/languages/php.css +0 -12
  220. data/html/js/codepress/languages/php.js +0 -61
  221. data/html/js/codepress/languages/ruby.css +0 -10
  222. data/html/js/codepress/languages/ruby.js +0 -26
  223. data/html/js/codepress/languages/sql.css +0 -10
  224. data/html/js/codepress/languages/sql.js +0 -30
  225. data/html/js/codepress/languages/text.css +0 -5
  226. data/html/js/codepress/languages/text.js +0 -9
  227. data/html/js/codepress/languages/vbscript.css +0 -71
  228. data/html/js/codepress/languages/vbscript.js +0 -117
  229. data/html/js/codepress/languages/xsl.css +0 -15
  230. data/html/js/codepress/languages/xsl.js +0 -103
  231. data/html/js/codepress/license.txt +0 -458
  232. data/html/js/edit_area/images/Thumbs.db +0 -0
  233. data/test/plugin/test_gem/a/lib/jiji_plugin_test.rb +0 -6
@@ -5,64 +5,90 @@
5
5
 
6
6
 
7
7
  EditArea.prototype.check_line_selection= function(timer_checkup){
8
- //if(do_highlight==false){
9
-
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
10
12
  if(!editAreas[this.id])
11
13
  return false;
12
14
 
13
- //time=new Date;
14
- //t1=t2=t3= time.getTime();
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'] );
15
23
 
16
- if(!this.smooth_selection && !this.do_highlight){
17
- //formatArea();
18
- }else if(this.textareaFocused && editAreas[this.id]["displayed"]==true && this.isResizing==false){
19
- infos= this.get_selection_infos();
20
- // time=new Date;
21
- // t2= time.getTime();
24
+ t2= new Date().getTime();
22
25
 
23
- //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"]){
24
- 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){
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
+ }
26
36
 
27
- new_top=this.lineHeight * (infos["line_start"]-1);
28
- new_height=Math.max(0, this.lineHeight * infos["line_nb"]);
29
- new_width=Math.max(this.textarea.scrollWidth, this.container.clientWidth -50);
30
-
31
- this.selection_field.style.top=new_top+"px";
32
- this.selection_field.style.width=new_width+"px";
33
- this.selection_field.style.height=new_height+"px";
34
- $("cursor_pos").style.top=new_top+"px";
35
-
36
- if(this.do_highlight==true){
37
- var curr_text=infos["full_text"].split("\n");
38
- var content="";
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 = "";
39
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]);
40
- var start=Math.max(0,infos["line_start"]-1);
41
- var end=Math.min(curr_text.length, infos["line_start"]+infos["line_nb"]-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);
42
47
 
43
48
  //curr_text[start]= curr_text[start].substr(0,infos["curr_pos"]-1) +"¤_overline_¤"+ curr_text[start].substr(infos["curr_pos"]-1);
44
49
  for(i=start; i< end; i++){
45
50
  content+= curr_text[i]+"\n";
46
51
  }
47
52
 
48
- content= content.replace(/&/g,"&amp;");
49
- content= content.replace(/</g,"&lt;");
50
- content= content.replace(/>/g,"&gt;");
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>';
51
57
 
52
- if(this.nav['isIE'] || this.nav['isOpera'] || this.nav['isFirefox'] >= 3)
53
- this.selection_field.innerHTML= "<pre>" + content.replace("\n", "<br/>") + "</pre>";
54
- else
55
- this.selection_field.innerHTML=content;
56
-
57
- 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.last_selection["line_nb"]!=infos["line_nb"] || this.last_selection["nb_line"]!=infos["nb_line"]) ) )
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
+ {
58
68
  this.maj_highlight(infos);
69
+ }
59
70
  }
60
71
  }
61
- // time=new Date;
62
- // t3= time.getTime();
72
+ t3= new Date().getTime();
63
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();
64
89
  // manage bracket finding
65
- 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){
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
+ {
66
92
  // move _cursor_pos
67
93
  var selec_char= infos["curr_line"].charAt(infos["curr_pos"]-1);
68
94
  var no_real_move=true;
@@ -71,17 +97,17 @@
71
97
  no_real_move=false;
72
98
  //findEndBracket(infos["line_start"], infos["curr_pos"], selec_char);
73
99
  if(this.findEndBracket(infos, selec_char) === true){
74
- $("end_bracket").style.visibility="visible";
75
- $("cursor_pos").style.visibility="visible";
76
- $("cursor_pos").innerHTML= selec_char;
77
- $("end_bracket").innerHTML= (this.assocBracket[selec_char] || this.revertAssocBracket[selec_char]);
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]);
78
104
  }else{
79
- $("end_bracket").style.visibility="hidden";
80
- $("cursor_pos").style.visibility="hidden";
105
+ _$("end_bracket").style.visibility ="hidden";
106
+ _$("cursor_pos").style.visibility ="hidden";
81
107
  }
82
108
  }else{
83
- $("cursor_pos").style.visibility="hidden";
84
- $("end_bracket").style.visibility="hidden";
109
+ _$("cursor_pos").style.visibility ="hidden";
110
+ _$("end_bracket").style.visibility ="hidden";
85
111
  }
86
112
  //alert("move cursor");
87
113
  this.displayToCursorPosition("cursor_pos", infos["line_start"], infos["curr_pos"]-1, infos["curr_line"], no_real_move);
@@ -90,140 +116,213 @@
90
116
  }
91
117
  this.last_selection=infos;
92
118
  }
93
- // time=new Date;
94
- // tend= time.getTime();
95
- //this.debug.value="tps total: "+ (tend-t1) + " tps get_infos: "+ (t2-t1)+ " tps jaune: "+ (t3-t2) +" tps cursor: "+ (tend-t3)+" "+typeof(infos);
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
+
96
124
 
97
125
  if(timer_checkup){
98
- //if(this.do_highlight==true) //can slow down check speed when highlight mode is on
99
126
  setTimeout("editArea.check_line_selection(true)", this.check_line_selection_timer);
100
127
  }
101
128
  };
102
129
 
103
130
 
104
131
  EditArea.prototype.get_selection_infos= function(){
105
- if(this.nav['isIE'])
106
- this.getIESelection();
107
- start=this.textarea.selectionStart;
108
- end=this.textarea.selectionEnd;
132
+ var sel={}, start, end, len, str;
133
+
134
+ this.getIESelection();
135
+ start = this.textarea.selectionStart;
136
+ end = this.textarea.selectionEnd;
109
137
 
110
- if(this.last_selection["selectionStart"]==start && this.last_selection["selectionEnd"]==end && this.last_selection["full_text"]==this.textarea.value)
138
+ if( this.last_selection["selectionStart"] == start && this.last_selection["selectionEnd"] == end && this.last_selection["full_text"] == this.textarea.value )
139
+ {
111
140
  return this.last_selection;
141
+ }
112
142
 
113
143
  if(this.tabulation!="\t" && this.textarea.value.indexOf("\t")!=-1)
114
144
  { // can append only after copy/paste
115
- var len= this.textarea.value.length;
116
- this.textarea.value=this.replace_tab(this.textarea.value);
117
- start=end= start+(this.textarea.value.length-len);
118
- this.area_select(start, 0);
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 );
119
149
  }
120
- var selections=new Object();
121
- selections["selectionStart"]= start;
122
- selections["selectionEnd"]= end;
123
- selections["full_text"]= this.textarea.value;
124
- selections["line_start"]=1;
125
- selections["line_nb"]=1;
126
- selections["curr_pos"]=0;
127
- selections["curr_line"]="";
128
- selections["indexOfCursor"]=0;
129
- selections["selec_direction"]= this.last_selection["selec_direction"];
130
-
131
- //return selections;
132
-
133
- var splitTab=selections["full_text"].split("\n");
134
- var nbLine=Math.max(0, splitTab.length);
135
- var nbChar=Math.max(0, selections["full_text"].length - (nbLine - 1)); // (remove \n caracters from the count)
136
- if(selections["full_text"].indexOf("\r")!=-1)
137
- nbChar= nbChar - (nbLine -1); // (remove \r caracters from the count)
138
- selections["nb_line"]=nbLine;
139
- selections["nb_char"]=nbChar;
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
+
140
170
  if(start>0){
141
- var str=selections["full_text"].substr(0,start);
142
- selections["curr_pos"]= start - str.lastIndexOf("\n");
143
- selections["line_start"]=Math.max(1, str.split("\n").length);
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);
144
174
  }else{
145
- selections["curr_pos"]=1;
175
+ sel["curr_pos"]=1;
146
176
  }
147
177
  if(end>start){
148
- selections["line_nb"]=selections["full_text"].substring(start,end).split("\n").length;
178
+ sel["line_nb"]=sel["full_text"].substring(start,end).split("\n").length;
149
179
  }
150
- selections["indexOfCursor"]=this.textarea.selectionStart;
151
- selections["curr_line"]=splitTab[Math.max(0,selections["line_start"]-1)];
152
-
153
-
154
- // determine in with direction the direction grow
155
- if(selections["selectionStart"]==this.last_selection["selectionStart"]){
156
- if(selections["selectionEnd"]>this.last_selection["selectionEnd"])
157
- selections["selec_direction"]= "down";
158
- else if(selections["selectionEnd"] == this.last_selection["selectionStart"])
159
- selections["selec_direction"]= this.last_selection["selec_direction"];
160
- }else if(selections["selectionStart"] == this.last_selection["selectionEnd"] && selections["selectionEnd"]>this.last_selection["selectionEnd"]){
161
- selections["selec_direction"]= "down";
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";
162
191
  }else{
163
- selections["selec_direction"]= "up";
192
+ sel["selec_direction"]= "up";
164
193
  }
165
-
166
- $("nbLine").innerHTML= nbLine;
167
- $("nbChar").innerHTML= nbChar;
168
- $("linePos").innerHTML=selections["line_start"];
169
- $("currPos").innerHTML=selections["curr_pos"];
170
194
 
171
- return selections;
195
+ _$("nbLine").innerHTML = nbLine;
196
+ _$("nbChar").innerHTML = nbChar;
197
+ _$("linePos").innerHTML = sel["line_start"];
198
+ _$("currPos").innerHTML = sel["curr_pos"];
199
+
200
+ return sel;
172
201
  };
173
202
 
174
203
  // set IE position in Firefox mode (textarea.selectionStart and textarea.selectionEnd)
175
- EditArea.prototype.getIESelection= function(){
176
- var range = document.selection.createRange();
177
- var stored_range = range.duplicate();
178
- stored_range.moveToElementText( this.textarea );
179
- stored_range.setEndPoint( 'EndToEnd', range );
180
- if(stored_range.parentElement() !=this.textarea)
181
- return;
182
-
183
- // the range don't take care of empty lines in the end of the selection
184
- var scrollTop= this.result.scrollTop + document.body.scrollTop;
204
+ EditArea.prototype.getIESelection= function(){
205
+ var selectionStart, selectionEnd, range, stored_range;
185
206
 
186
- var relative_top= range.offsetTop - parent.calculeOffsetTop(this.textarea) + scrollTop;
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;
187
234
 
188
- var line_start = Math.round((relative_top / this.lineHeight) +1);
235
+ this.textarea.selectionStart = selectionStart;
236
+ this.textarea.selectionEnd = selectionEnd;
237
+ }
238
+ catch(e){}
189
239
 
190
- var line_nb=Math.round(range.boundingHeight / this.lineHeight);
191
-
192
- var range_start=stored_range.text.length - range.text.length;
193
- var tab=this.textarea.value.substr(0, range_start).split("\n");
194
- range_start+= (line_start - tab.length)*2; // add missing empty lines to the selection
195
- this.textarea.selectionStart = range_start;
196
-
197
- var range_end=this.textarea.selectionStart + range.text.length;
198
- tab=this.textarea.value.substr(0, range_start + range.text.length).split("\n");
199
- range_end+= (line_start + line_nb - 1 - tab.length)*2;
200
-
201
- this.textarea.selectionEnd = range_end;
202
- /*this.textarea.selectionStart = 10;
203
- this.textarea.selectionEnd = 50;*/
240
+ // restore wrap mode
241
+ if( this.settings['word_wrap'] )
242
+ this.textarea.wrap='soft';
204
243
  };
205
244
 
206
245
  // select the text for IE (and take care of \r caracters)
207
246
  EditArea.prototype.setIESelection= function(){
208
- var nbLineStart=this.textarea.value.substr(0, this.textarea.selectionStart).split("\n").length - 1;
209
- var nbLineEnd=this.textarea.value.substr(0, this.textarea.selectionEnd).split("\n").length - 1;
210
- var range = document.selection.createRange();
211
- range.moveToElementText( this.textarea );
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 );
212
256
  range.setEndPoint( 'EndToStart', range );
213
257
 
214
- range.moveStart('character', this.textarea.selectionStart - nbLineStart);
215
- range.moveEnd('character', this.textarea.selectionEnd - nbLineEnd - (this.textarea.selectionStart - nbLineStart) );
258
+ range.moveStart('character', a.selectionStart - nbLineStart);
259
+ range.moveEnd('character', a.selectionEnd - nbLineEnd - (a.selectionStart - nbLineStart) );
216
260
  range.select();
217
261
  };
218
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
+
219
319
  EditArea.prototype.tab_selection= function(){
220
320
  if(this.is_tabbing)
221
321
  return;
222
322
  this.is_tabbing=true;
223
323
  //infos=getSelectionInfos();
224
324
  //if( document.selection ){
225
- if( this.nav['isIE'] )
226
- this.getIESelection();
325
+ this.getIESelection();
227
326
  /* Insertion du code de formatage */
228
327
  var start = this.textarea.selectionStart;
229
328
  var end = this.textarea.selectionEnd;
@@ -254,52 +353,56 @@
254
353
  this.textarea.selectionEnd = pos_end;
255
354
 
256
355
  //if( document.selection ){
257
- if(this.nav['isIE']){
356
+ if(this.isIE)
357
+ {
258
358
  this.setIESelection();
259
359
  setTimeout("editArea.is_tabbing=false;", 100); // IE can't accept to make 2 tabulation without a little break between both
260
- }else
261
- this.is_tabbing=false;
360
+ }
361
+ else
362
+ {
363
+ this.is_tabbing=false;
364
+ }
262
365
 
263
366
  };
264
367
 
265
368
  EditArea.prototype.invert_tab_selection= function(){
266
- if(this.is_tabbing)
369
+ var t=this, a=this.textarea;
370
+ if(t.is_tabbing)
267
371
  return;
268
- this.is_tabbing=true;
372
+ t.is_tabbing=true;
269
373
  //infos=getSelectionInfos();
270
374
  //if( document.selection ){
271
- if(this.nav['isIE'])
272
- this.getIESelection();
375
+ t.getIESelection();
273
376
 
274
- var start = this.textarea.selectionStart;
275
- var end = this.textarea.selectionEnd;
276
- var insText = this.textarea.value.substring(start, end);
377
+ var start = a.selectionStart;
378
+ var end = a.selectionEnd;
379
+ var insText = a.value.substring(start, end);
277
380
 
278
381
  /* Tab remove and cursor seleciton adjust */
279
382
  var pos_start=start;
280
383
  var pos_end=end;
281
384
  if (insText.length == 0) {
282
- if(this.textarea.value.substring(start-this.tabulation.length, start)==this.tabulation)
385
+ if(a.value.substring(start-t.tabulation.length, start)==t.tabulation)
283
386
  {
284
- this.textarea.value = this.textarea.value.substr(0, start-this.tabulation.length) + this.textarea.value.substr(end);
285
- pos_start= Math.max(0, start-this.tabulation.length);
286
- pos_end=pos_start;
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;
287
390
  }
288
391
  /*
289
- this.textarea.value = this.textarea.value.substr(0, start) + this.tabulation + insText + this.textarea.value.substr(end);
290
- pos_start = start + this.tabulation.length;
392
+ a.value = a.value.substr(0, start) + t.tabulation + insText + a.value.substr(end);
393
+ pos_start = start + t.tabulation.length;
291
394
  pos_end=pos_start;*/
292
395
  } else {
293
- start= this.textarea.value.substr(0, start).lastIndexOf("\n")+1;
294
- endText=this.textarea.value.substr(end);
295
- startText=this.textarea.value.substr(0, start);
296
- tmp= this.textarea.value.substring(start, end).split("\n");
297
- insText="";
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 = "";
298
401
  for(i=0; i<tmp.length; i++){
299
- for(j=0; j<this.tab_nb_char; j++){
402
+ for(j=0; j<t.tab_nb_char; j++){
300
403
  if(tmp[i].charAt(0)=="\t"){
301
404
  tmp[i]=tmp[i].substr(1);
302
- j=this.tab_nb_char;
405
+ j=t.tab_nb_char;
303
406
  }else if(tmp[i].charAt(0)==" ")
304
407
  tmp[i]=tmp[i].substr(1);
305
408
  }
@@ -308,40 +411,42 @@
308
411
  insText+="\n";
309
412
  }
310
413
  //insText+="_";
311
- this.textarea.value = startText + insText + endText;
312
- pos_start = start;
313
- pos_end= this.textarea.value.indexOf("\n", startText.length + insText.length);
414
+ a.value = startText + insText + endText;
415
+ pos_start = start;
416
+ pos_end = a.value.indexOf("\n", startText.length + insText.length);
314
417
  if(pos_end==-1)
315
- pos_end=this.textarea.value.length;
418
+ pos_end=a.value.length;
316
419
  //pos = start + repdeb.length + insText.length + ;
317
420
  }
318
- this.textarea.selectionStart = pos_start;
319
- this.textarea.selectionEnd = pos_end;
421
+ a.selectionStart = pos_start;
422
+ a.selectionEnd = pos_end;
320
423
 
321
424
  //if( document.selection ){
322
- if(this.nav['isIE']){
425
+ if(t.isIE){
323
426
  // select the text for IE
324
- this.setIESelection();
427
+ t.setIESelection();
325
428
  setTimeout("editArea.is_tabbing=false;", 100); // IE can accept to make 2 tabulation without a little break between both
326
429
  }else
327
- this.is_tabbing=false;
430
+ t.is_tabbing=false;
328
431
  };
329
432
 
330
433
  EditArea.prototype.press_enter= function(){
331
434
  if(!this.smooth_selection)
332
435
  return false;
333
- if(this.nav['isIE'])
334
- this.getIESelection();
436
+ this.getIESelection();
335
437
  var scrollTop= this.result.scrollTop;
336
438
  var scrollLeft= this.result.scrollLeft;
337
439
  var start=this.textarea.selectionStart;
338
440
  var end= this.textarea.selectionEnd;
339
441
  var start_last_line= Math.max(0 , this.textarea.value.substring(0, start).lastIndexOf("\n") + 1 );
340
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;
341
444
  if(begin_line=="\n" || begin_line=="\r" || begin_line.length==0)
445
+ {
342
446
  return false;
447
+ }
343
448
 
344
- if(this.nav['isIE'] || this.nav['isOpera']){
449
+ if(this.isIE || ( this.isOpera && this.isOpera < 9.6 ) ){
345
450
  begin_line="\r\n"+ begin_line;
346
451
  }else{
347
452
  begin_line="\n"+ begin_line;
@@ -351,9 +456,9 @@
351
456
 
352
457
  this.area_select(start+ begin_line.length ,0);
353
458
  // during this process IE scroll back to the top of the textarea
354
- if(this.nav['isIE']){
355
- this.result.scrollTop= scrollTop;
356
- this.result.scrollLeft= scrollLeft;
459
+ if(this.isIE){
460
+ this.result.scrollTop = scrollTop;
461
+ this.result.scrollLeft = scrollLeft;
357
462
  }
358
463
  return true;
359
464
 
@@ -398,54 +503,106 @@
398
503
  else
399
504
  line= infos["full_text"].substr(0, endLastLine).split("\n").length + 1;
400
505
 
401
- var curPos= end - endLastLine;
402
-
403
- this.displayToCursorPosition("end_bracket", line, curPos, infos["full_text"].substring(endLastLine +1, end));
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));
404
509
  return true;
405
510
  };
406
511
 
407
512
  EditArea.prototype.displayToCursorPosition= function(id, start_line, cur_pos, lineContent, no_real_move){
408
- var elem= $("test_font_size");
409
- var dest= $(id);
410
- var postLeft=0;
411
- elem.innerHTML="<pre><span id='test_font_size_inner'>"+lineContent.substr(0, cur_pos).replace(/&/g,"&amp;").replace(/</g,"&lt;")+"</span></pre>";
412
- posLeft= 45 + $('test_font_size_inner').offsetWidth;
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
+
413
524
 
414
- var posTop=this.lineHeight * (start_line-1);
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;
415
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
+ }
416
536
  if(no_real_move!=true){ // when the cursor is hidden no need to move him
417
537
  dest.style.top=posTop+"px";
418
- dest.style.left=posLeft+"px";
538
+ dest.style.left=posLeft+"px";
419
539
  }
420
540
  // usefull for smarter scroll
421
541
  dest.cursor_top=posTop;
422
- dest.cursor_left=posLeft;
423
-
424
- // $(id).style.marginLeft=posLeft+"px";
425
-
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;
426
553
  };
427
554
 
428
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
+
429
589
  EditArea.prototype.area_select= function(start, length){
430
590
  this.textarea.focus();
431
591
 
432
- start= Math.max(0, Math.min(this.textarea.value.length, start));
433
- end= Math.max(start, Math.min(this.textarea.value.length, start+length));
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));
434
594
 
435
- if(this.nav['isIE']){
436
- this.textarea.selectionStart = start;
437
- this.textarea.selectionEnd = end;
595
+ if(this.isIE)
596
+ {
597
+ this.textarea.selectionStart = start;
598
+ this.textarea.selectionEnd = end;
438
599
  this.setIESelection();
439
- }else{
440
- if(this.nav['isOpera']){ // Opera bug when moving selection start and selection end
441
- /*this.textarea.selectionEnd = 1;
442
- this.textarea.selectionStart = 0;
443
- this.textarea.selectionEnd = 1;
444
- this.textarea.selectionStart = 0;
445
- this.textarea.selectionEnd = 0;
446
- this.textarea.selectionStart = 0;
447
- this.textarea.selectionEnd = 0;
448
- this.textarea.selectionStart = 0;*/
600
+ }
601
+ else
602
+ {
603
+ // Opera bug when moving selection start and selection end
604
+ if(this.isOpera && this.isOpera < 9.6 )
605
+ {
449
606
  this.textarea.setSelectionRange(0, 0);
450
607
  }
451
608
  this.textarea.setSelectionRange(start, end);
@@ -463,4 +620,4 @@
463
620
  text= this.textarea.value.substring(this.textarea.selectionStart, this.textarea.selectionEnd);
464
621
  }
465
622
  return text;
466
- };
623
+ };