Unlimited Elements For Elementor (Free Widgets, Addons, Templates) - Version 1.4.75

Version Description

Download this release

Release Info

Developer unitecms
Plugin Icon 128x128 Unlimited Elements For Elementor (Free Widgets, Addons, Templates)
Version 1.4.75
Comparing to
See all releases

Code changes from version 1.4.74 to 1.4.75

Files changed (49) hide show
  1. css/unitecreator_styles.css +15 -0
  2. inc_php/framework/functions.class.php +137 -18
  3. inc_php/framework/functions.php +0 -1
  4. inc_php/framework/settings.class.php +6 -2
  5. inc_php/framework/zip.class.php +1 -1
  6. inc_php/layouts/unitecreator_layouts_exporter.class.php +1 -1
  7. inc_php/manager/unitecreator_manager_addons.class.php +1 -1
  8. inc_php/unitecreator_addon.class.php +2 -0
  9. inc_php/unitecreator_addons.class.php +7 -5
  10. inc_php/unitecreator_helper.class.php +1 -1
  11. inc_php/unitecreator_helperhtml.class.php +0 -2
  12. inc_php/unitecreator_output.class.php +35 -5
  13. inc_php/unitecreator_params_processor.class.php +4 -5
  14. includes.php +1 -1
  15. js/codemirror/old/codemirror.css +0 -323
  16. js/codemirror/old/codemirror.js +0 -8658
  17. js/codemirror/old/codemirror.min.js +0 -5
  18. js/unitecreator_assets.js +4 -3
  19. js/unitecreator_includes.js +118 -16
  20. provider/core/plugins/unlimited_elements/copy_paste.class.php +69 -33
  21. provider/core/plugins/unlimited_elements/elementor/assets/uc_editor_admin.css +16 -0
  22. provider/core/plugins/unlimited_elements/elementor/assets/uc_editor_admin.js +92 -8
  23. provider/core/plugins/unlimited_elements/elementor/assets/uc_front_section_paste.css +10 -1
  24. provider/core/plugins/unlimited_elements/elementor/assets/uc_front_section_paste.js +130 -6
  25. provider/core/plugins/unlimited_elements/elementor/elementor_background_widget.class.php +6 -0
  26. provider/core/plugins/unlimited_elements/elementor/elementor_integrate.class.php +10 -9
  27. provider/core/plugins/unlimited_elements/elementor/elementor_layout_exporter.class.php +27 -9
  28. provider/core/plugins/unlimited_elements/elementor/elementor_widget.class.php +58 -18
  29. provider/core/plugins/unlimited_elements/elementor/images/new2.svg +0 -15
  30. provider/core/plugins/unlimited_elements/helper_provider_core.class.php +100 -15
  31. provider/core/plugins/unlimited_elements/settings/general_settings_el.xml +1 -1
  32. provider/core/plugins/unlimited_elements/views/settingselementor.php +1 -1
  33. provider/freemius/README.md +0 -282
  34. provider/freemius/assets/img/unlimited-elements-for-elementor.png +0 -0
  35. provider/freemius/package.json +0 -27
  36. provider/functions_wordpress.class.php +31 -3
  37. provider/provider_front.class.php +21 -0
  38. provider/provider_functions.class.php +2 -2
  39. provider/provider_globals.class.php +3 -0
  40. provider/provider_params_processor.class.php +132 -12
  41. provider/provider_settings.class.php +79 -13
  42. provider/provider_web_api.class.php +2 -2
  43. readme.txt +12 -0
  44. release_log.txt +12 -0
  45. temp/index.html +0 -0
  46. unlimited_elements.php +1 -1
  47. views/objects/addon_view.class.php +27 -5
  48. views/objects/addon_view_childparams.class.php +1 -0
  49. views/troubleshooting-api-access.php +0 -101
css/unitecreator_styles.css CHANGED
@@ -1054,6 +1054,7 @@
1054
  padding-bottom: 0px;
1055
  margin-bottom: 0px;
1056
  }
 
1057
  #uc_table_includes .uc-condition-container {
1058
  font-weight: bold;
1059
  padding-left: 25px;
@@ -1062,6 +1063,11 @@
1062
  #uc_table_includes .uc-condition-container .uc-condition-never {
1063
  color: red;
1064
  }
 
 
 
 
 
1065
  #uc_table_includes tr td {
1066
  vertical-align: top;
1067
  }
@@ -1110,6 +1116,15 @@
1110
  background-color:#f1f1f1;
1111
  }
1112
 
 
 
 
 
 
 
 
 
 
1113
 
1114
  .----------------ASSETS_TAB------------- {}
1115
  .uc-assets-folder-wrapper {
1054
  padding-bottom: 0px;
1055
  margin-bottom: 0px;
1056
  }
1057
+
1058
  #uc_table_includes .uc-condition-container {
1059
  font-weight: bold;
1060
  padding-left: 25px;
1063
  #uc_table_includes .uc-condition-container .uc-condition-never {
1064
  color: red;
1065
  }
1066
+
1067
+ #uc_table_includes .uc-includes-state-text{
1068
+ padding-left:25px;
1069
+ }
1070
+
1071
  #uc_table_includes tr td {
1072
  vertical-align: top;
1073
  }
1116
  background-color:#f1f1f1;
1117
  }
1118
 
1119
+ /* dialog includes */
1120
+
1121
+ .uc-dialog-includes-js{
1122
+ display:none;
1123
+ }
1124
+
1125
+ .uc-include-type-js .uc-dialog-includes-js{
1126
+ display:block;
1127
+ }
1128
 
1129
  .----------------ASSETS_TAB------------- {}
1130
  .uc-assets-folder-wrapper {
inc_php/framework/functions.class.php CHANGED
@@ -565,6 +565,7 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
565
  * add first value to array
566
  */
567
  public static function addArrFirstValue($arr, $text, $value = ""){
 
568
  $arr = array($value => $text) + $arr;
569
 
570
  return($arr);
@@ -666,6 +667,42 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
666
  }
667
 
668
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
669
  public static function z_____________STRINGS_____________(){}
670
 
671
  /**
@@ -921,6 +958,37 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
921
  return($value);
922
  }
923
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
924
 
925
  /**
926
  * check if text is encoded
@@ -1007,7 +1075,7 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
1007
 
1008
  if(empty($content))
1009
  return($content);
1010
-
1011
  $content = rawurldecode(base64_decode($content));
1012
 
1013
  if($convertToArray == true)
@@ -1604,6 +1672,7 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
1604
 
1605
  }
1606
 
 
1607
  /**
1608
  * return if the array is id's array
1609
  */
@@ -1938,12 +2007,25 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
1938
  fclose($fp);
1939
  }
1940
 
 
 
 
 
 
 
 
 
 
1941
  /**
1942
  *
1943
  * recursive delete directory or file
1944
  */
1945
- public static function deleteDir($path,$deleteOriginal = true, $arrNotDeleted = array(),$originalPath = ""){
1946
 
 
 
 
 
1947
 
1948
  if(empty($originalPath))
1949
  $originalPath = $path;
@@ -1951,36 +2033,73 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
1951
  //in case of paths array
1952
  if(getType($path) == "array"){
1953
  $arrPaths = $path;
 
1954
  foreach($path as $singlePath)
1955
- $arrNotDeleted = self::deleteDir($singlePath,$deleteOriginal,$arrNotDeleted,$originalPath);
 
1956
  return($arrNotDeleted);
1957
  }
1958
-
1959
  if(!file_exists($path))
1960
  return($arrNotDeleted);
1961
 
1962
- if(is_file($path)){ // delete file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1963
  $deleted = unlink($path);
1964
  if(!$deleted)
1965
  $arrNotDeleted[] = $path;
 
 
1966
  }
1967
- else{ //delete directory
1968
- $arrPaths = scandir($path);
1969
- foreach($arrPaths as $file){
1970
- if($file == "." || $file == "..")
1971
- continue;
1972
- $filepath = realpath($path."/".$file);
1973
- $arrNotDeleted = self::deleteDir($filepath,$deleteOriginal,$arrNotDeleted,$originalPath);
1974
- }
1975
-
1976
- if($deleteOriginal == true || $originalPath != $path){
1977
- $deleted = @rmdir($path);
1978
- if(!$deleted)
 
 
 
 
 
 
 
 
 
 
1979
  $arrNotDeleted[] = $path;
 
 
 
1980
  }
1981
-
 
 
 
 
1982
  }
1983
 
 
1984
  return($arrNotDeleted);
1985
  }
1986
 
565
  * add first value to array
566
  */
567
  public static function addArrFirstValue($arr, $text, $value = ""){
568
+
569
  $arr = array($value => $text) + $arr;
570
 
571
  return($arr);
667
  }
668
 
669
 
670
+ /**
671
+ * get id's array from any input
672
+ */
673
+ public static function getIDsArray($input){
674
+
675
+ if(empty($input))
676
+ return(array());
677
+
678
+ if(is_array($input))
679
+ $arrInput = $input;
680
+ else
681
+ $arrInput = explode(",", $input);
682
+
683
+ $arrIDs = array();
684
+ foreach($arrInput as $id){
685
+
686
+ if(is_string($id))
687
+ $id = trim($id);
688
+
689
+ if(is_object($id)){
690
+ $arrObj = (array)$id;
691
+ $id = self::getVal($arrObj, "ID");
692
+ }
693
+
694
+ if(is_numeric($id) == false || empty($id))
695
+ continue;
696
+
697
+ $arrIDs[] = $id;
698
+ }
699
+
700
+
701
+ return($arrIDs);
702
+ }
703
+
704
+
705
+
706
  public static function z_____________STRINGS_____________(){}
707
 
708
  /**
958
  return($value);
959
  }
960
 
961
+ /**
962
+ * get size and unit number
963
+ */
964
+ public static function getSizeAndUnit($numSize, $defaultUnit){
965
+
966
+ $size = $numSize;
967
+ $unit = $defaultUnit;
968
+
969
+ if(is_numeric($numSize)){
970
+ $output = array("size"=>$size,"unit"=>$unit);
971
+ return($output);
972
+ }
973
+
974
+ $size = strtolower($size);
975
+
976
+ $arrUnits = array("%","em","px","vh");
977
+
978
+ foreach($arrUnits as $unit){
979
+
980
+ if(strpos($size, $unit) !== false){
981
+ $unit = $unit;
982
+ $size = str_replace($unit, "", $size);
983
+ break;
984
+ }
985
+ }
986
+
987
+ $output = array("size"=>$size,"unit"=>$unit);
988
+
989
+ return($output);
990
+ }
991
+
992
 
993
  /**
994
  * check if text is encoded
1075
 
1076
  if(empty($content))
1077
  return($content);
1078
+
1079
  $content = rawurldecode(base64_decode($content));
1080
 
1081
  if($convertToArray == true)
1672
 
1673
  }
1674
 
1675
+
1676
  /**
1677
  * return if the array is id's array
1678
  */
2007
  fclose($fp);
2008
  }
2009
 
2010
+ /**
2011
+ * delete folder contents that older then some seconds from now
2012
+ */
2013
+ public static function clearDirByTime($path, $olderThenSeconds = 60){
2014
+
2015
+ self::deleteDir($path,false,array(),"",array("olderthen"=>$olderThenSeconds));
2016
+ }
2017
+
2018
+
2019
  /**
2020
  *
2021
  * recursive delete directory or file
2022
  */
2023
+ public static function deleteDir($path,$deleteOriginal = true, $arrNotDeleted = array(),$originalPath = "", $params = array()){
2024
 
2025
+ $olderSec = self::getVal($params, "olderthen");
2026
+
2027
+ if(!empty($olderSec))
2028
+ $currentTime = time();
2029
 
2030
  if(empty($originalPath))
2031
  $originalPath = $path;
2033
  //in case of paths array
2034
  if(getType($path) == "array"){
2035
  $arrPaths = $path;
2036
+
2037
  foreach($path as $singlePath)
2038
+ $arrNotDeleted = self::deleteDir($singlePath,$deleteOriginal,$arrNotDeleted,$originalPath,$params);
2039
+
2040
  return($arrNotDeleted);
2041
  }
2042
+
2043
  if(!file_exists($path))
2044
  return($arrNotDeleted);
2045
 
2046
+ // delete file
2047
+ if(is_file($path)){
2048
+
2049
+ //check by time
2050
+ if(!empty($olderSec)){
2051
+
2052
+ $filetime = filemtime($path);
2053
+ $diff = $currentTime-$filetime;
2054
+
2055
+ //skip if not much time left
2056
+ if($diff < $olderSec){
2057
+ $arrNotDeleted[] = $path;
2058
+ return($arrNotDeleted);
2059
+ }
2060
+ }
2061
+
2062
  $deleted = unlink($path);
2063
  if(!$deleted)
2064
  $arrNotDeleted[] = $path;
2065
+
2066
+ return($arrNotDeleted);
2067
  }
2068
+
2069
+ //delete directory
2070
+
2071
+ $arrPaths = scandir($path);
2072
+
2073
+ foreach($arrPaths as $file){
2074
+ if($file == "." || $file == "..")
2075
+ continue;
2076
+ $filepath = realpath($path."/".$file);
2077
+ $arrNotDeleted = self::deleteDir($filepath,$deleteOriginal,$arrNotDeleted,$originalPath,$params);
2078
+ }
2079
+
2080
+ if($deleteOriginal == true || $originalPath != $path){
2081
+
2082
+ //check by time
2083
+ if(!empty($olderSec)){
2084
+
2085
+ $filetime = filemtime($path);
2086
+ $diff = $currentTime-$filetime;
2087
+
2088
+ //skip if not much time left
2089
+ if($diff < $olderSec){
2090
  $arrNotDeleted[] = $path;
2091
+ return($arrNotDeleted);
2092
+ }
2093
+
2094
  }
2095
+
2096
+
2097
+ $deleted = @rmdir($path);
2098
+ if(!$deleted)
2099
+ $arrNotDeleted[] = $path;
2100
  }
2101
 
2102
+
2103
  return($arrNotDeleted);
2104
  }
2105
 
inc_php/framework/functions.php CHANGED
@@ -22,4 +22,3 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
22
 
23
 
24
 
25
- ?>
22
 
23
 
24
 
 
inc_php/framework/settings.class.php CHANGED
@@ -1168,8 +1168,12 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
1168
  $loadedSettingsType = (string)UniteFunctionsUC::getVal($attribs, "loadtype");
1169
  $nodraw = (string)UniteFunctionsUC::getVal($attribs, "nodraw");
1170
  $visibility = (string)UniteFunctionsUC::getVal($attribs, "visibility");
1171
-
1172
- if($visibility == "dev" && GlobalsUC::$inDev == false)
 
 
 
 
1173
  continue;
1174
 
1175
  $sapParams = array();
1168
  $loadedSettingsType = (string)UniteFunctionsUC::getVal($attribs, "loadtype");
1169
  $nodraw = (string)UniteFunctionsUC::getVal($attribs, "nodraw");
1170
  $visibility = (string)UniteFunctionsUC::getVal($attribs, "visibility");
1171
+
1172
+ $isForceShow = false;
1173
+ if($sapName == "copy_paste_mode" && defined("UC_ENABLE_COPYPASTE"))
1174
+ $isForceShow = true;
1175
+
1176
+ if($visibility == "dev" && GlobalsUC::$inDev == false && $isForceShow == false)
1177
  continue;
1178
 
1179
  $sapParams = array();
inc_php/framework/zip.class.php CHANGED
@@ -149,7 +149,7 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
149
 
150
  @mkdir($dir);
151
  if(is_dir($dir) == false)
152
- UniteFunctionsUC::throwError("Can't create directory: $dir");
153
 
154
  }
155
 
149
 
150
  @mkdir($dir);
151
  if(is_dir($dir) == false)
152
+ UniteFunctionsUC::throwError("Can't create directory: {$dir} maybe zip file is brocken");
153
 
154
  }
155
 
inc_php/layouts/unitecreator_layouts_exporter.class.php CHANGED
@@ -859,12 +859,12 @@ class UniteCreatorLayoutsExporterWork extends UniteCreatorExporterBase{
859
  //create index.html
860
  UniteFunctionsUC::writeFile("", $pathImportBase."index.html");
861
 
862
-
863
  //create layout path
864
 
865
  self::$serial++;
866
 
867
  $this->pathImportLayout = $pathImportBase."layout_".self::$serial."_".UniteFunctionsUC::getRandomString(10)."/";
 
868
  UniteFunctionsUC::mkdirValidate($this->pathImportLayout, "import layout");
869
 
870
  //don't create those paths
859
  //create index.html
860
  UniteFunctionsUC::writeFile("", $pathImportBase."index.html");
861
 
 
862
  //create layout path
863
 
864
  self::$serial++;
865
 
866
  $this->pathImportLayout = $pathImportBase."layout_".self::$serial."_".UniteFunctionsUC::getRandomString(10)."/";
867
+
868
  UniteFunctionsUC::mkdirValidate($this->pathImportLayout, "import layout");
869
 
870
  //don't create those paths
inc_php/manager/unitecreator_manager_addons.class.php CHANGED
@@ -1802,7 +1802,7 @@ class UniteCreatorManagerAddonsWork extends UniteCreatorManager{
1802
 
1803
  if($arrCats === null)
1804
  $arrCats = $this->getArrCats($params);
1805
-
1806
  $htmlCatList = $this->objCats->getHtmlCatList($selectCatID, $this->objAddonType, $arrCats);
1807
 
1808
 
1802
 
1803
  if($arrCats === null)
1804
  $arrCats = $this->getArrCats($params);
1805
+
1806
  $htmlCatList = $this->objCats->getHtmlCatList($selectCatID, $this->objAddonType, $arrCats);
1807
 
1808
 
inc_php/unitecreator_addon.class.php CHANGED
@@ -547,6 +547,8 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
547
  $this->type = UniteFunctionsUC::getVal($record, "addontype");
548
  $this->updateHash = UniteFunctionsUC::getVal($record, "test_slot1");
549
 
 
 
550
 
551
  //get templates
552
  $this->arrTemplates = $this->parseJsonFromRecord($record, "templates");
547
  $this->type = UniteFunctionsUC::getVal($record, "addontype");
548
  $this->updateHash = UniteFunctionsUC::getVal($record, "test_slot1");
549
 
550
+ if(is_string($this->updateHash) == false || strlen($this->updateHash) > 60)
551
+ $this->updateHash = "";
552
 
553
  //get templates
554
  $this->arrTemplates = $this->parseJsonFromRecord($record, "templates");
inc_php/unitecreator_addons.class.php CHANGED
@@ -501,7 +501,7 @@ class UniteCreatorAddons extends UniteElementsBaseUC{
501
  /**
502
  * get addon output, for the editor
503
  */
504
- public function getAddonOutput($objAddon){
505
 
506
  $processType = UniteCreatorParamsProcessor::PROCESS_TYPE_OUTPUT_BACK;
507
 
@@ -509,13 +509,15 @@ class UniteCreatorAddons extends UniteElementsBaseUC{
509
  $objOutput->setProcessType($processType);
510
 
511
  $objOutput->initByAddon($objAddon);
512
-
513
- $params = array("wrap_js_timeout"=> true);
514
-
 
 
 
515
  $htmlAddon = $objOutput->getHtmlBody(true,false,true,$params);
516
 
517
  $arrIncludes = $objOutput->getProcessedIncludes(true);
518
- //$arrConstantData = $objOutput->getConstantData();
519
 
520
  $arr = array();
521
  $arr["html"] = $htmlAddon;
501
  /**
502
  * get addon output, for the editor
503
  */
504
+ public function getAddonOutput($objAddon, $isWrap = true){
505
 
506
  $processType = UniteCreatorParamsProcessor::PROCESS_TYPE_OUTPUT_BACK;
507
 
509
  $objOutput->setProcessType($processType);
510
 
511
  $objOutput->initByAddon($objAddon);
512
+
513
+ if($isWrap == true)
514
+ $params = array("wrap_js_timeout"=> true);
515
+ else
516
+ $params = array();
517
+
518
  $htmlAddon = $objOutput->getHtmlBody(true,false,true,$params);
519
 
520
  $arrIncludes = $objOutput->getProcessedIncludes(true);
 
521
 
522
  $arr = array();
523
  $arr["html"] = $htmlAddon;
inc_php/unitecreator_helper.class.php CHANGED
@@ -455,7 +455,6 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
455
  */
456
  public static function URLtoFull($url, $urlBase = null){
457
 
458
-
459
  if(is_numeric($url)) //protection for image id
460
  return($url);
461
 
@@ -1697,6 +1696,7 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
1697
  if(!empty($mode))
1698
  $outputLayout->setOutputMode($mode);
1699
 
 
1700
  if($getHtml == true){
1701
 
1702
  if($outputFullPage == false)
455
  */
456
  public static function URLtoFull($url, $urlBase = null){
457
 
 
458
  if(is_numeric($url)) //protection for image id
459
  return($url);
460
 
1696
  if(!empty($mode))
1697
  $outputLayout->setOutputMode($mode);
1698
 
1699
+
1700
  if($getHtml == true){
1701
 
1702
  if($outputFullPage == false)
inc_php/unitecreator_helperhtml.class.php CHANGED
@@ -576,8 +576,6 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
576
  }
577
 
578
 
579
-
580
-
581
  /**
582
  * output exception in a box
583
  */
576
  }
577
 
578
 
 
 
579
  /**
580
  * output exception in a box
581
  */
inc_php/unitecreator_output.class.php CHANGED
@@ -210,6 +210,8 @@ class UniteCreatorOutputWork extends HtmlOutputBaseUC{
210
 
211
  $deps = array();
212
 
 
 
213
  //process params
214
  $params = UniteFunctionsUC::getVal($include, "params");
215
  if(!empty($params)){
@@ -218,9 +220,25 @@ class UniteCreatorOutputWork extends HtmlOutputBaseUC{
218
 
219
  if($includeAfterFrontend == true)
220
  $deps[]= "elementor-frontend";
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
  }
222
-
223
-
224
  $arrIncludeNew = array();
225
  $arrIncludeNew["url"] = $urlInclude;
226
  $arrIncludeNew["type"] = $type;
@@ -231,6 +249,10 @@ class UniteCreatorOutputWork extends HtmlOutputBaseUC{
231
  if(!empty($deps))
232
  $arrIncludeNew["deps"] = $deps;
233
 
 
 
 
 
234
  $arrIncludesProcessed[] = $arrIncludeNew;
235
 
236
  }
@@ -344,7 +366,15 @@ class UniteCreatorOutputWork extends HtmlOutputBaseUC{
344
 
345
  switch($type){
346
  case "js":
347
- $html .= self::TAB2."<script type='text/javascript' src='{$url}'></script>".self::BR;
 
 
 
 
 
 
 
 
348
  break;
349
  case "css":
350
  $cssID = "{$handle}-css";
@@ -1019,9 +1049,9 @@ class UniteCreatorOutputWork extends HtmlOutputBaseUC{
1019
  $htmlBody = $this->getHtmlBody(false);
1020
 
1021
  $arrIncludes = $this->getProcessedIncludes(true, false);
1022
-
1023
  $arrIncludes = $this->modifyPreviewIncludes($arrIncludes);
1024
-
1025
  $htmlInlcudesCss = $this->getHtmlIncludes($arrIncludes,"css");
1026
  $htmlInlcudesJS = $this->getHtmlIncludes($arrIncludes,"js");
1027
 
210
 
211
  $deps = array();
212
 
213
+ $includeAsModule = false;
214
+
215
  //process params
216
  $params = UniteFunctionsUC::getVal($include, "params");
217
  if(!empty($params)){
220
 
221
  if($includeAfterFrontend == true)
222
  $deps[]= "elementor-frontend";
223
+
224
+ //include as module handle.
225
+ //add to handles array, and later check if need to add the module addition to output
226
+
227
+ $includeAsModule = UniteFunctionsUC::getVal($params, "include_as_module");
228
+ $includeAsModule = UniteFunctionsUC::strToBool($includeAsModule);
229
+
230
+ if($includeAsModule == true)
231
+ GlobalsProviderUC::$arrJSHandlesModules[$handle] = true;
232
+
233
+ //change the handle
234
+ $customHandle = UniteFunctionsUC::getVal($params, "include_handle");
235
+ $customHandle = trim($customHandle);
236
+
237
+ if(!empty($customHandle))
238
+ $handle = $customHandle;
239
+
240
  }
241
+
 
242
  $arrIncludeNew = array();
243
  $arrIncludeNew["url"] = $urlInclude;
244
  $arrIncludeNew["type"] = $type;
249
  if(!empty($deps))
250
  $arrIncludeNew["deps"] = $deps;
251
 
252
+ if($includeAsModule == true)
253
+ $arrIncludeNew["is_module"] = true;
254
+
255
+
256
  $arrIncludesProcessed[] = $arrIncludeNew;
257
 
258
  }
366
 
367
  switch($type){
368
  case "js":
369
+
370
+ $htmlType = "text/javascript";
371
+ $isModule = UniteFunctionsUC::getVal($include, "is_module");
372
+ $isModule = UniteFunctionsUC::strToBool($isModule);
373
+
374
+ if($isModule == true)
375
+ $htmlType = "module";
376
+
377
+ $html .= self::TAB2."<script type='{$htmlType}' src='{$url}'></script>".self::BR;
378
  break;
379
  case "css":
380
  $cssID = "{$handle}-css";
1049
  $htmlBody = $this->getHtmlBody(false);
1050
 
1051
  $arrIncludes = $this->getProcessedIncludes(true, false);
1052
+
1053
  $arrIncludes = $this->modifyPreviewIncludes($arrIncludes);
1054
+
1055
  $htmlInlcudesCss = $this->getHtmlIncludes($arrIncludes,"css");
1056
  $htmlInlcudesJS = $this->getHtmlIncludes($arrIncludes,"js");
1057
 
inc_php/unitecreator_params_processor.class.php CHANGED
@@ -1114,7 +1114,9 @@ class UniteCreatorParamsProcessorWork{
1114
  foreach($arrParams as $key=>$param){
1115
 
1116
  $type = UniteFunctionsUC::getVal($param, "type");
1117
-
 
 
1118
  if(isset($param["value"]))
1119
  $param["value"] = $this->convertValueByType($param["value"], $type, $param);
1120
 
@@ -1130,7 +1132,6 @@ class UniteCreatorParamsProcessorWork{
1130
  $param["value"] = $this->convertValueFromOptions($param["value"], $param["options"], $param["default_value"]);
1131
  }
1132
 
1133
- $param = apply_filters("unite_creator_process_param_for_output", $param);
1134
 
1135
  $arrParams[$key] = $param;
1136
  }
@@ -1523,8 +1524,7 @@ class UniteCreatorParamsProcessorWork{
1523
  self::validateProcessType($processType);
1524
 
1525
  $arrParams = $this->processParamsForOutput($arrParams);
1526
-
1527
-
1528
  $data = array();
1529
 
1530
  foreach($arrParams as $param){
@@ -1609,7 +1609,6 @@ class UniteCreatorParamsProcessorWork{
1609
 
1610
  $arrParams = $this->getProcessedParamsValues($objParams, $processType);
1611
 
1612
-
1613
  $arrVars = $this->getMainVariablesProcessed($arrParams);
1614
 
1615
  if($this->isOutputProcessType($processType) == true){
1114
  foreach($arrParams as $key=>$param){
1115
 
1116
  $type = UniteFunctionsUC::getVal($param, "type");
1117
+
1118
+ $param = apply_filters("unite_creator_process_param_for_output", $param);
1119
+
1120
  if(isset($param["value"]))
1121
  $param["value"] = $this->convertValueByType($param["value"], $type, $param);
1122
 
1132
  $param["value"] = $this->convertValueFromOptions($param["value"], $param["options"], $param["default_value"]);
1133
  }
1134
 
 
1135
 
1136
  $arrParams[$key] = $param;
1137
  }
1524
  self::validateProcessType($processType);
1525
 
1526
  $arrParams = $this->processParamsForOutput($arrParams);
1527
+
 
1528
  $data = array();
1529
 
1530
  foreach($arrParams as $param){
1609
 
1610
  $arrParams = $this->getProcessedParamsValues($objParams, $processType);
1611
 
 
1612
  $arrVars = $this->getMainVariablesProcessed($arrParams);
1613
 
1614
  if($this->isOutputProcessType($processType) == true){
includes.php CHANGED
@@ -12,7 +12,7 @@ if(!defined('UNLIMITED_ELEMENTS_INC'))
12
  defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
13
 
14
  if(!defined("UNLIMITED_ELEMENTS_VERSION"))
15
- define("UNLIMITED_ELEMENTS_VERSION", "1.4.74");
16
 
17
  $currentFile = __FILE__;
18
  $currentFolder = dirname($currentFile);
12
  defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
13
 
14
  if(!defined("UNLIMITED_ELEMENTS_VERSION"))
15
+ define("UNLIMITED_ELEMENTS_VERSION", "1.4.75");
16
 
17
  $currentFile = __FILE__;
18
  $currentFolder = dirname($currentFile);
js/codemirror/old/codemirror.css DELETED
@@ -1,323 +0,0 @@
1
- /* BASICS */
2
-
3
- .CodeMirror {
4
- /* Set height, width, borders, and global font properties here */
5
- font-family: monospace;
6
- height: 300px;
7
- color: black;
8
- }
9
-
10
- /* PADDING */
11
-
12
- .CodeMirror-lines {
13
- padding: 4px 0; /* Vertical padding around content */
14
- }
15
- .CodeMirror pre {
16
- padding: 0 4px; /* Horizontal padding of content */
17
- }
18
-
19
- .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
20
- background-color: white; /* The little square between H and V scrollbars */
21
- }
22
-
23
- /* GUTTER */
24
-
25
- .CodeMirror-gutters {
26
- border-right: 1px solid #ddd;
27
- background-color: #f7f7f7;
28
- white-space: nowrap;
29
- }
30
- .CodeMirror-linenumbers {}
31
- .CodeMirror-linenumber {
32
- padding: 0 3px 0 5px;
33
- min-width: 20px;
34
- text-align: right;
35
- color: #999;
36
- white-space: nowrap;
37
- }
38
-
39
- .CodeMirror-guttermarker { color: black; }
40
- .CodeMirror-guttermarker-subtle { color: #999; }
41
-
42
- /* CURSOR */
43
-
44
- .CodeMirror div.CodeMirror-cursor {
45
- border-left: 1px solid black;
46
- }
47
- /* Shown when moving in bi-directional text */
48
- .CodeMirror div.CodeMirror-secondarycursor {
49
- border-left: 1px solid silver;
50
- }
51
- .CodeMirror.cm-fat-cursor div.CodeMirror-cursor {
52
- width: auto;
53
- border: 0;
54
- background: #7e7;
55
- }
56
- .CodeMirror.cm-fat-cursor div.CodeMirror-cursors {
57
- z-index: 1;
58
- }
59
-
60
- .cm-animate-fat-cursor {
61
- width: auto;
62
- border: 0;
63
- -webkit-animation: blink 1.06s steps(1) infinite;
64
- -moz-animation: blink 1.06s steps(1) infinite;
65
- animation: blink 1.06s steps(1) infinite;
66
- }
67
- @-moz-keyframes blink {
68
- 0% { background: #7e7; }
69
- 50% { background: none; }
70
- 100% { background: #7e7; }
71
- }
72
- @-webkit-keyframes blink {
73
- 0% { background: #7e7; }
74
- 50% { background: none; }
75
- 100% { background: #7e7; }
76
- }
77
- @keyframes blink {
78
- 0% { background: #7e7; }
79
- 50% { background: none; }
80
- 100% { background: #7e7; }
81
- }
82
-
83
- /* Can style cursor different in overwrite (non-insert) mode */
84
- div.CodeMirror-overwrite div.CodeMirror-cursor {}
85
-
86
- .cm-tab { display: inline-block; text-decoration: inherit; }
87
-
88
- .CodeMirror-ruler {
89
- border-left: 1px solid #ccc;
90
- position: absolute;
91
- }
92
-
93
- /* DEFAULT THEME */
94
-
95
- .cm-s-default .cm-keyword {color: #708;}
96
- .cm-s-default .cm-atom {color: #219;}
97
- .cm-s-default .cm-number {color: #164;}
98
- .cm-s-default .cm-def {color: #00f;}
99
- .cm-s-default .cm-variable,
100
- .cm-s-default .cm-punctuation,
101
- .cm-s-default .cm-property,
102
- .cm-s-default .cm-operator {}
103
- .cm-s-default .cm-variable-2 {color: #05a;}
104
- .cm-s-default .cm-variable-3 {color: #085;}
105
- .cm-s-default .cm-comment {color: #a50;}
106
- .cm-s-default .cm-string {color: #a11;}
107
- .cm-s-default .cm-string-2 {color: #f50;}
108
- .cm-s-default .cm-meta {color: #555;}
109
- .cm-s-default .cm-qualifier {color: #555;}
110
- .cm-s-default .cm-builtin {color: #30a;}
111
- .cm-s-default .cm-bracket {color: #997;}
112
- .cm-s-default .cm-tag {color: #170;}
113
- .cm-s-default .cm-attribute {color: #00c;}
114
- .cm-s-default .cm-header {color: blue;}
115
- .cm-s-default .cm-quote {color: #090;}
116
- .cm-s-default .cm-hr {color: #999;}
117
- .cm-s-default .cm-link {color: #00c;}
118
-
119
- .cm-negative {color: #d44;}
120
- .cm-positive {color: #292;}
121
- .cm-header, .cm-strong {font-weight: bold;}
122
- .cm-em {font-style: italic;}
123
- .cm-link {text-decoration: underline;}
124
- .cm-strikethrough {text-decoration: line-through;}
125
-
126
- .cm-s-default .cm-error {color: #f00;}
127
- .cm-invalidchar {color: #f00;}
128
-
129
- /* Default styles for common addons */
130
-
131
- div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
132
- div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
133
- .CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
134
- .CodeMirror-activeline-background {background: #e8f2ff;}
135
-
136
- /* STOP */
137
-
138
- /* The rest of this file contains styles related to the mechanics of
139
- the editor. You probably shouldn't touch them. */
140
-
141
- .CodeMirror {
142
- position: relative;
143
- overflow: hidden;
144
- background: white;
145
- }
146
-
147
- .CodeMirror-scroll {
148
- overflow: scroll !important; /* Things will break if this is overridden */
149
- /* 30px is the magic margin used to hide the element's real scrollbars */
150
- /* See overflow: hidden in .CodeMirror */
151
- margin-bottom: -30px; margin-right: -30px;
152
- padding-bottom: 30px;
153
- height: 100%;
154
- outline: none; /* Prevent dragging from highlighting the element */
155
- position: relative;
156
- }
157
- .CodeMirror-sizer {
158
- position: relative;
159
- border-right: 30px solid transparent;
160
- }
161
-
162
- /* The fake, visible scrollbars. Used to force redraw during scrolling
163
- before actuall scrolling happens, thus preventing shaking and
164
- flickering artifacts. */
165
- .CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
166
- position: absolute;
167
- z-index: 6;
168
- display: none;
169
- }
170
- .CodeMirror-vscrollbar {
171
- right: 0; top: 0;
172
- overflow-x: hidden;
173
- overflow-y: scroll;
174
- }
175
- .CodeMirror-hscrollbar {
176
- bottom: 0; left: 0;
177
- overflow-y: hidden;
178
- overflow-x: scroll;
179
- }
180
- .CodeMirror-scrollbar-filler {
181
- right: 0; bottom: 0;
182
- }
183
- .CodeMirror-gutter-filler {
184
- left: 0; bottom: 0;
185
- }
186
-
187
- .CodeMirror-gutters {
188
- position: absolute; left: 0; top: 0;
189
- z-index: 3;
190
- }
191
- .CodeMirror-gutter {
192
- white-space: normal;
193
- height: 100%;
194
- display: inline-block;
195
- margin-bottom: -30px;
196
- /* Hack to make IE7 behave */
197
- *zoom:1;
198
- *display:inline;
199
- }
200
- .CodeMirror-gutter-wrapper {
201
- position: absolute;
202
- z-index: 4;
203
- height: 100%;
204
- }
205
- .CodeMirror-gutter-elt {
206
- position: absolute;
207
- cursor: default;
208
- z-index: 4;
209
- }
210
- .CodeMirror-gutter-wrapper {
211
- -webkit-user-select: none;
212
- -moz-user-select: none;
213
- user-select: none;
214
- }
215
-
216
- .CodeMirror-lines {
217
- cursor: text;
218
- min-height: 1px; /* prevents collapsing before first draw */
219
- }
220
- .CodeMirror pre {
221
- /* Reset some styles that the rest of the page might have set */
222
- -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
223
- border-width: 0;
224
- background: transparent;
225
- font-family: inherit;
226
- font-size: inherit;
227
- margin: 0;
228
- white-space: pre;
229
- word-wrap: normal;
230
- line-height: inherit;
231
- color: inherit;
232
- z-index: 2;
233
- position: relative;
234
- overflow: visible;
235
- -webkit-tap-highlight-color: transparent;
236
- }
237
- .CodeMirror-wrap pre {
238
- word-wrap: break-word;
239
- white-space: pre-wrap;
240
- word-break: normal;
241
- }
242
-
243
- .CodeMirror-linebackground {
244
- position: absolute;
245
- left: 0; right: 0; top: 0; bottom: 0;
246
- z-index: 0;
247
- }
248
-
249
- .CodeMirror-linewidget {
250
- position: relative;
251
- z-index: 2;
252
- overflow: auto;
253
- }
254
-
255
- .CodeMirror-widget {}
256
-
257
- .CodeMirror-code {
258
- outline: none;
259
- }
260
-
261
- /* Force content-box sizing for the elements where we expect it */
262
- .CodeMirror-scroll,
263
- .CodeMirror-sizer,
264
- .CodeMirror-gutter,
265
- .CodeMirror-gutters,
266
- .CodeMirror-linenumber {
267
- -moz-box-sizing: content-box;
268
- box-sizing: content-box;
269
- }
270
-
271
- .CodeMirror-measure {
272
- position: absolute;
273
- width: 100%;
274
- height: 0;
275
- overflow: hidden;
276
- visibility: hidden;
277
- }
278
- .CodeMirror-measure pre { position: static; }
279
-
280
- .CodeMirror div.CodeMirror-cursor {
281
- position: absolute;
282
- border-right: none;
283
- width: 0;
284
- }
285
-
286
- div.CodeMirror-cursors {
287
- visibility: hidden;
288
- position: relative;
289
- z-index: 3;
290
- }
291
- .CodeMirror-focused div.CodeMirror-cursors {
292
- visibility: visible;
293
- }
294
-
295
- .CodeMirror-selected { background: #d9d9d9; }
296
- .CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
297
- .CodeMirror-crosshair { cursor: crosshair; }
298
- .CodeMirror ::selection { background: #d7d4f0; }
299
- .CodeMirror ::-moz-selection { background: #d7d4f0; }
300
-
301
- .cm-searching {
302
- background: #ffa;
303
- background: rgba(255, 255, 0, .4);
304
- }
305
-
306
- /* IE7 hack to prevent it from returning funny offsetTops on the spans */
307
- .CodeMirror span { *vertical-align: text-bottom; }
308
-
309
- /* Used to force a border model for a node */
310
- .cm-force-border { padding-right: .1px; }
311
-
312
- @media print {
313
- /* Hide the cursor when printing */
314
- .CodeMirror div.CodeMirror-cursors {
315
- visibility: hidden;
316
- }
317
- }
318
-
319
- /* See issue #2901 */
320
- .cm-tab-wrap-hack:after { content: ''; }
321
-
322
- /* Help users use markselection to safely style text background */
323
- span.CodeMirror-selectedtext { background: none; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/codemirror/old/codemirror.js DELETED
@@ -1,8658 +0,0 @@
1
- // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
- // Distributed under an MIT license: http://codemirror.net/LICENSE
3
-
4
- // This is CodeMirror (http://codemirror.net), a code editor
5
- // implemented in JavaScript on top of the browser's DOM.
6
- //
7
- // You can find some technical background for some of the code below
8
- // at http://marijnhaverbeke.nl/blog/#cm-internals .
9
-
10
- (function(mod) {
11
- if (typeof exports == "object" && typeof module == "object") // CommonJS
12
- module.exports = mod();
13
- else if (typeof define == "function" && define.amd) // AMD
14
- return define([], mod);
15
- else // Plain browser env
16
- this.CodeMirror = mod();
17
- })(function() {
18
- "use strict";
19
-
20
- // BROWSER SNIFFING
21
-
22
- // Kludges for bugs and behavior differences that can't be feature
23
- // detected are enabled based on userAgent etc sniffing.
24
-
25
- var gecko = /gecko\/\d/i.test(navigator.userAgent);
26
- var ie_upto10 = /MSIE \d/.test(navigator.userAgent);
27
- var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
28
- var ie = ie_upto10 || ie_11up;
29
- var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : ie_11up[1]);
30
- var webkit = /WebKit\//.test(navigator.userAgent);
31
- var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(navigator.userAgent);
32
- var chrome = /Chrome\//.test(navigator.userAgent);
33
- var presto = /Opera\//.test(navigator.userAgent);
34
- var safari = /Apple Computer/.test(navigator.vendor);
35
- var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent);
36
- var phantom = /PhantomJS/.test(navigator.userAgent);
37
-
38
- var ios = /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent);
39
- // This is woefully incomplete. Suggestions for alternative methods welcome.
40
- var mobile = ios || /Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent);
41
- var mac = ios || /Mac/.test(navigator.platform);
42
- var windows = /win/i.test(navigator.platform);
43
-
44
- var presto_version = presto && navigator.userAgent.match(/Version\/(\d*\.\d*)/);
45
- if (presto_version) presto_version = Number(presto_version[1]);
46
- if (presto_version && presto_version >= 15) { presto = false; webkit = true; }
47
- // Some browsers use the wrong event properties to signal cmd/ctrl on OS X
48
- var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11));
49
- var captureRightClick = gecko || (ie && ie_version >= 9);
50
-
51
- // Optimize some code when these features are not used.
52
- var sawReadOnlySpans = false, sawCollapsedSpans = false;
53
-
54
- // EDITOR CONSTRUCTOR
55
-
56
- // A CodeMirror instance represents an editor. This is the object
57
- // that user code is usually dealing with.
58
-
59
- function CodeMirror(place, options) {
60
- if (!(this instanceof CodeMirror)) return new CodeMirror(place, options);
61
-
62
- this.options = options = options ? copyObj(options) : {};
63
- // Determine effective options based on given values and defaults.
64
- copyObj(defaults, options, false);
65
- setGuttersForLineNumbers(options);
66
-
67
- var doc = options.value;
68
- if (typeof doc == "string") doc = new Doc(doc, options.mode);
69
- this.doc = doc;
70
-
71
- var input = new CodeMirror.inputStyles[options.inputStyle](this);
72
- var display = this.display = new Display(place, doc, input);
73
- display.wrapper.CodeMirror = this;
74
- updateGutters(this);
75
- themeChanged(this);
76
- if (options.lineWrapping)
77
- this.display.wrapper.className += " CodeMirror-wrap";
78
- if (options.autofocus && !mobile) display.input.focus();
79
- initScrollbars(this);
80
-
81
- this.state = {
82
- keyMaps: [], // stores maps added by addKeyMap
83
- overlays: [], // highlighting overlays, as added by addOverlay
84
- modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
85
- overwrite: false, focused: false,
86
- suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
87
- pasteIncoming: false, cutIncoming: false, // help recognize paste/cut edits in input.poll
88
- draggingText: false,
89
- highlight: new Delayed(), // stores highlight worker timeout
90
- keySeq: null, // Unfinished key sequence
91
- specialChars: null
92
- };
93
-
94
- var cm = this;
95
-
96
- // Override magic textarea content restore that IE sometimes does
97
- // on our hidden textarea on reload
98
- if (ie && ie_version < 11) setTimeout(function() { cm.display.input.reset(true); }, 20);
99
-
100
- registerEventHandlers(this);
101
- ensureGlobalHandlers();
102
-
103
- startOperation(this);
104
- this.curOp.forceUpdate = true;
105
- attachDoc(this, doc);
106
-
107
- if ((options.autofocus && !mobile) || cm.hasFocus())
108
- setTimeout(bind(onFocus, this), 20);
109
- else
110
- onBlur(this);
111
-
112
- for (var opt in optionHandlers) if (optionHandlers.hasOwnProperty(opt))
113
- optionHandlers[opt](this, options[opt], Init);
114
- maybeUpdateLineNumberWidth(this);
115
- if (options.finishInit) options.finishInit(this);
116
- for (var i = 0; i < initHooks.length; ++i) initHooks[i](this);
117
- endOperation(this);
118
- // Suppress optimizelegibility in Webkit, since it breaks text
119
- // measuring on line wrapping boundaries.
120
- if (webkit && options.lineWrapping &&
121
- getComputedStyle(display.lineDiv).textRendering == "optimizelegibility")
122
- display.lineDiv.style.textRendering = "auto";
123
- }
124
-
125
- // DISPLAY CONSTRUCTOR
126
-
127
- // The display handles the DOM integration, both for input reading
128
- // and content drawing. It holds references to DOM nodes and
129
- // display-related state.
130
-
131
- function Display(place, doc, input) {
132
- var d = this;
133
- this.input = input;
134
-
135
- // Covers bottom-right square when both scrollbars are present.
136
- d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
137
- d.scrollbarFiller.setAttribute("cm-not-content", "true");
138
- // Covers bottom of gutter when coverGutterNextToScrollbar is on
139
- // and h scrollbar is present.
140
- d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler");
141
- d.gutterFiller.setAttribute("cm-not-content", "true");
142
- // Will contain the actual code, positioned to cover the viewport.
143
- d.lineDiv = elt("div", null, "CodeMirror-code");
144
- // Elements are added to these to represent selection and cursors.
145
- d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
146
- d.cursorDiv = elt("div", null, "CodeMirror-cursors");
147
- // A visibility: hidden element used to find the size of things.
148
- d.measure = elt("div", null, "CodeMirror-measure");
149
- // When lines outside of the viewport are measured, they are drawn in this.
150
- d.lineMeasure = elt("div", null, "CodeMirror-measure");
151
- // Wraps everything that needs to exist inside the vertically-padded coordinate system
152
- d.lineSpace = elt("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
153
- null, "position: relative; outline: none");
154
- // Moved around its parent to cover visible view.
155
- d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative");
156
- // Set to the height of the document, allowing scrolling.
157
- d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
158
- d.sizerWidth = null;
159
- // Behavior of elts with overflow: auto and padding is
160
- // inconsistent across browsers. This is used to ensure the
161
- // scrollable area is big enough.
162
- d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;");
163
- // Will contain the gutters, if any.
164
- d.gutters = elt("div", null, "CodeMirror-gutters");
165
- d.lineGutter = null;
166
- // Actual scrollable element.
167
- d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll");
168
- d.scroller.setAttribute("tabIndex", "-1");
169
- // The element in which the editor lives.
170
- d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
171
-
172
- // Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
173
- if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; }
174
- if (!webkit && !(gecko && mobile)) d.scroller.draggable = true;
175
-
176
- if (place) {
177
- if (place.appendChild) place.appendChild(d.wrapper);
178
- else place(d.wrapper);
179
- }
180
-
181
- // Current rendered range (may be bigger than the view window).
182
- d.viewFrom = d.viewTo = doc.first;
183
- d.reportedViewFrom = d.reportedViewTo = doc.first;
184
- // Information about the rendered lines.
185
- d.view = [];
186
- d.renderedView = null;
187
- // Holds info about a single rendered line when it was rendered
188
- // for measurement, while not in view.
189
- d.externalMeasured = null;
190
- // Empty space (in pixels) above the view
191
- d.viewOffset = 0;
192
- d.lastWrapHeight = d.lastWrapWidth = 0;
193
- d.updateLineNumbers = null;
194
-
195
- d.nativeBarWidth = d.barHeight = d.barWidth = 0;
196
- d.scrollbarsClipped = false;
197
-
198
- // Used to only resize the line number gutter when necessary (when
199
- // the amount of lines crosses a boundary that makes its width change)
200
- d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
201
- // Set to true when a non-horizontal-scrolling line widget is
202
- // added. As an optimization, line widget aligning is skipped when
203
- // this is false.
204
- d.alignWidgets = false;
205
-
206
- d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
207
-
208
- // Tracks the maximum line length so that the horizontal scrollbar
209
- // can be kept static when scrolling.
210
- d.maxLine = null;
211
- d.maxLineLength = 0;
212
- d.maxLineChanged = false;
213
-
214
- // Used for measuring wheel scrolling granularity
215
- d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null;
216
-
217
- // True when shift is held down.
218
- d.shift = false;
219
-
220
- // Used to track whether anything happened since the context menu
221
- // was opened.
222
- d.selForContextMenu = null;
223
-
224
- d.activeTouch = null;
225
-
226
- input.init(d);
227
- }
228
-
229
- // STATE UPDATES
230
-
231
- // Used to get the editor into a consistent state again when options change.
232
-
233
- function loadMode(cm) {
234
- cm.doc.mode = CodeMirror.getMode(cm.options, cm.doc.modeOption);
235
- resetModeState(cm);
236
- }
237
-
238
- function resetModeState(cm) {
239
- cm.doc.iter(function(line) {
240
- if (line.stateAfter) line.stateAfter = null;
241
- if (line.styles) line.styles = null;
242
- });
243
- cm.doc.frontier = cm.doc.first;
244
- startWorker(cm, 100);
245
- cm.state.modeGen++;
246
- if (cm.curOp) regChange(cm);
247
- }
248
-
249
- function wrappingChanged(cm) {
250
- if (cm.options.lineWrapping) {
251
- addClass(cm.display.wrapper, "CodeMirror-wrap");
252
- cm.display.sizer.style.minWidth = "";
253
- cm.display.sizerWidth = null;
254
- } else {
255
- rmClass(cm.display.wrapper, "CodeMirror-wrap");
256
- findMaxLine(cm);
257
- }
258
- estimateLineHeights(cm);
259
- regChange(cm);
260
- clearCaches(cm);
261
- setTimeout(function(){updateScrollbars(cm);}, 100);
262
- }
263
-
264
- // Returns a function that estimates the height of a line, to use as
265
- // first approximation until the line becomes visible (and is thus
266
- // properly measurable).
267
- function estimateHeight(cm) {
268
- var th = textHeight(cm.display), wrapping = cm.options.lineWrapping;
269
- var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);
270
- return function(line) {
271
- if (lineIsHidden(cm.doc, line)) return 0;
272
-
273
- var widgetsHeight = 0;
274
- if (line.widgets) for (var i = 0; i < line.widgets.length; i++) {
275
- if (line.widgets[i].height) widgetsHeight += line.widgets[i].height;
276
- }
277
-
278
- if (wrapping)
279
- return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th;
280
- else
281
- return widgetsHeight + th;
282
- };
283
- }
284
-
285
- function estimateLineHeights(cm) {
286
- var doc = cm.doc, est = estimateHeight(cm);
287
- doc.iter(function(line) {
288
- var estHeight = est(line);
289
- if (estHeight != line.height) updateLineHeight(line, estHeight);
290
- });
291
- }
292
-
293
- function themeChanged(cm) {
294
- cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
295
- cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
296
- clearCaches(cm);
297
- }
298
-
299
- function guttersChanged(cm) {
300
- updateGutters(cm);
301
- regChange(cm);
302
- setTimeout(function(){alignHorizontally(cm);}, 20);
303
- }
304
-
305
- // Rebuild the gutter elements, ensure the margin to the left of the
306
- // code matches their width.
307
- function updateGutters(cm) {
308
- var gutters = cm.display.gutters, specs = cm.options.gutters;
309
- removeChildren(gutters);
310
- for (var i = 0; i < specs.length; ++i) {
311
- var gutterClass = specs[i];
312
- var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass));
313
- if (gutterClass == "CodeMirror-linenumbers") {
314
- cm.display.lineGutter = gElt;
315
- gElt.style.width = (cm.display.lineNumWidth || 1) + "px";
316
- }
317
- }
318
- gutters.style.display = i ? "" : "none";
319
- updateGutterSpace(cm);
320
- }
321
-
322
- function updateGutterSpace(cm) {
323
- var width = cm.display.gutters.offsetWidth;
324
- cm.display.sizer.style.marginLeft = width + "px";
325
- }
326
-
327
- // Compute the character length of a line, taking into account
328
- // collapsed ranges (see markText) that might hide parts, and join
329
- // other lines onto it.
330
- function lineLength(line) {
331
- if (line.height == 0) return 0;
332
- var len = line.text.length, merged, cur = line;
333
- while (merged = collapsedSpanAtStart(cur)) {
334
- var found = merged.find(0, true);
335
- cur = found.from.line;
336
- len += found.from.ch - found.to.ch;
337
- }
338
- cur = line;
339
- while (merged = collapsedSpanAtEnd(cur)) {
340
- var found = merged.find(0, true);
341
- len -= cur.text.length - found.from.ch;
342
- cur = found.to.line;
343
- len += cur.text.length - found.to.ch;
344
- }
345
- return len;
346
- }
347
-
348
- // Find the longest line in the document.
349
- function findMaxLine(cm) {
350
- var d = cm.display, doc = cm.doc;
351
- d.maxLine = getLine(doc, doc.first);
352
- d.maxLineLength = lineLength(d.maxLine);
353
- d.maxLineChanged = true;
354
- doc.iter(function(line) {
355
- var len = lineLength(line);
356
- if (len > d.maxLineLength) {
357
- d.maxLineLength = len;
358
- d.maxLine = line;
359
- }
360
- });
361
- }
362
-
363
- // Make sure the gutters options contains the element
364
- // "CodeMirror-linenumbers" when the lineNumbers option is true.
365
- function setGuttersForLineNumbers(options) {
366
- var found = indexOf(options.gutters, "CodeMirror-linenumbers");
367
- if (found == -1 && options.lineNumbers) {
368
- options.gutters = options.gutters.concat(["CodeMirror-linenumbers"]);
369
- } else if (found > -1 && !options.lineNumbers) {
370
- options.gutters = options.gutters.slice(0);
371
- options.gutters.splice(found, 1);
372
- }
373
- }
374
-
375
- // SCROLLBARS
376
-
377
- // Prepare DOM reads needed to update the scrollbars. Done in one
378
- // shot to minimize update/measure roundtrips.
379
- function measureForScrollbars(cm) {
380
- var d = cm.display, gutterW = d.gutters.offsetWidth;
381
- var docH = Math.round(cm.doc.height + paddingVert(cm.display));
382
- return {
383
- clientHeight: d.scroller.clientHeight,
384
- viewHeight: d.wrapper.clientHeight,
385
- scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth,
386
- viewWidth: d.wrapper.clientWidth,
387
- barLeft: cm.options.fixedGutter ? gutterW : 0,
388
- docHeight: docH,
389
- scrollHeight: docH + scrollGap(cm) + d.barHeight,
390
- nativeBarWidth: d.nativeBarWidth,
391
- gutterWidth: gutterW
392
- };
393
- }
394
-
395
- function NativeScrollbars(place, scroll, cm) {
396
- this.cm = cm;
397
- var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar");
398
- var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar");
399
- place(vert); place(horiz);
400
-
401
- on(vert, "scroll", function() {
402
- if (vert.clientHeight) scroll(vert.scrollTop, "vertical");
403
- });
404
- on(horiz, "scroll", function() {
405
- if (horiz.clientWidth) scroll(horiz.scrollLeft, "horizontal");
406
- });
407
-
408
- this.checkedOverlay = false;
409
- // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
410
- if (ie && ie_version < 8) this.horiz.style.minHeight = this.vert.style.minWidth = "18px";
411
- }
412
-
413
- NativeScrollbars.prototype = copyObj({
414
- update: function(measure) {
415
- var needsH = measure.scrollWidth > measure.clientWidth + 1;
416
- var needsV = measure.scrollHeight > measure.clientHeight + 1;
417
- var sWidth = measure.nativeBarWidth;
418
-
419
- if (needsV) {
420
- this.vert.style.display = "block";
421
- this.vert.style.bottom = needsH ? sWidth + "px" : "0";
422
- var totalHeight = measure.viewHeight - (needsH ? sWidth : 0);
423
- // A bug in IE8 can cause this value to be negative, so guard it.
424
- this.vert.firstChild.style.height =
425
- Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px";
426
- } else {
427
- this.vert.style.display = "";
428
- this.vert.firstChild.style.height = "0";
429
- }
430
-
431
- if (needsH) {
432
- this.horiz.style.display = "block";
433
- this.horiz.style.right = needsV ? sWidth + "px" : "0";
434
- this.horiz.style.left = measure.barLeft + "px";
435
- var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0);
436
- this.horiz.firstChild.style.width =
437
- (measure.scrollWidth - measure.clientWidth + totalWidth) + "px";
438
- } else {
439
- this.horiz.style.display = "";
440
- this.horiz.firstChild.style.width = "0";
441
- }
442
-
443
- if (!this.checkedOverlay && measure.clientHeight > 0) {
444
- if (sWidth == 0) this.overlayHack();
445
- this.checkedOverlay = true;
446
- }
447
-
448
- return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0};
449
- },
450
- setScrollLeft: function(pos) {
451
- if (this.horiz.scrollLeft != pos) this.horiz.scrollLeft = pos;
452
- },
453
- setScrollTop: function(pos) {
454
- if (this.vert.scrollTop != pos) this.vert.scrollTop = pos;
455
- },
456
- overlayHack: function() {
457
- var w = mac && !mac_geMountainLion ? "12px" : "18px";
458
- this.horiz.style.minHeight = this.vert.style.minWidth = w;
459
- var self = this;
460
- var barMouseDown = function(e) {
461
- if (e_target(e) != self.vert && e_target(e) != self.horiz)
462
- operation(self.cm, onMouseDown)(e);
463
- };
464
- on(this.vert, "mousedown", barMouseDown);
465
- on(this.horiz, "mousedown", barMouseDown);
466
- },
467
- clear: function() {
468
- var parent = this.horiz.parentNode;
469
- parent.removeChild(this.horiz);
470
- parent.removeChild(this.vert);
471
- }
472
- }, NativeScrollbars.prototype);
473
-
474
- function NullScrollbars() {}
475
-
476
- NullScrollbars.prototype = copyObj({
477
- update: function() { return {bottom: 0, right: 0}; },
478
- setScrollLeft: function() {},
479
- setScrollTop: function() {},
480
- clear: function() {}
481
- }, NullScrollbars.prototype);
482
-
483
- CodeMirror.scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars};
484
-
485
- function initScrollbars(cm) {
486
- if (cm.display.scrollbars) {
487
- cm.display.scrollbars.clear();
488
- if (cm.display.scrollbars.addClass)
489
- rmClass(cm.display.wrapper, cm.display.scrollbars.addClass);
490
- }
491
-
492
- cm.display.scrollbars = new CodeMirror.scrollbarModel[cm.options.scrollbarStyle](function(node) {
493
- cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller);
494
- // Prevent clicks in the scrollbars from killing focus
495
- on(node, "mousedown", function() {
496
- if (cm.state.focused) setTimeout(function() { cm.display.input.focus(); }, 0);
497
- });
498
- node.setAttribute("cm-not-content", "true");
499
- }, function(pos, axis) {
500
- if (axis == "horizontal") setScrollLeft(cm, pos);
501
- else setScrollTop(cm, pos);
502
- }, cm);
503
- if (cm.display.scrollbars.addClass)
504
- addClass(cm.display.wrapper, cm.display.scrollbars.addClass);
505
- }
506
-
507
- function updateScrollbars(cm, measure) {
508
- if (!measure) measure = measureForScrollbars(cm);
509
- var startWidth = cm.display.barWidth, startHeight = cm.display.barHeight;
510
- updateScrollbarsInner(cm, measure);
511
- for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) {
512
- if (startWidth != cm.display.barWidth && cm.options.lineWrapping)
513
- updateHeightsInViewport(cm);
514
- updateScrollbarsInner(cm, measureForScrollbars(cm));
515
- startWidth = cm.display.barWidth; startHeight = cm.display.barHeight;
516
- }
517
- }
518
-
519
- // Re-synchronize the fake scrollbars with the actual size of the
520
- // content.
521
- function updateScrollbarsInner(cm, measure) {
522
- var d = cm.display;
523
- var sizes = d.scrollbars.update(measure);
524
-
525
- d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px";
526
- d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px";
527
-
528
- if (sizes.right && sizes.bottom) {
529
- d.scrollbarFiller.style.display = "block";
530
- d.scrollbarFiller.style.height = sizes.bottom + "px";
531
- d.scrollbarFiller.style.width = sizes.right + "px";
532
- } else d.scrollbarFiller.style.display = "";
533
- if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
534
- d.gutterFiller.style.display = "block";
535
- d.gutterFiller.style.height = sizes.bottom + "px";
536
- d.gutterFiller.style.width = measure.gutterWidth + "px";
537
- } else d.gutterFiller.style.display = "";
538
- }
539
-
540
- // Compute the lines that are visible in a given viewport (defaults
541
- // the the current scroll position). viewport may contain top,
542
- // height, and ensure (see op.scrollToPos) properties.
543
- function visibleLines(display, doc, viewport) {
544
- var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop;
545
- top = Math.floor(top - paddingTop(display));
546
- var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight;
547
-
548
- var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom);
549
- // Ensure is a {from: {line, ch}, to: {line, ch}} object, and
550
- // forces those lines into the viewport (if possible).
551
- if (viewport && viewport.ensure) {
552
- var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line;
553
- if (ensureFrom < from) {
554
- from = ensureFrom;
555
- to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight);
556
- } else if (Math.min(ensureTo, doc.lastLine()) >= to) {
557
- from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight);
558
- to = ensureTo;
559
- }
560
- }
561
- return {from: from, to: Math.max(to, from + 1)};
562
- }
563
-
564
- // LINE NUMBERS
565
-
566
- // Re-align line numbers and gutter marks to compensate for
567
- // horizontal scrolling.
568
- function alignHorizontally(cm) {
569
- var display = cm.display, view = display.view;
570
- if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) return;
571
- var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft;
572
- var gutterW = display.gutters.offsetWidth, left = comp + "px";
573
- for (var i = 0; i < view.length; i++) if (!view[i].hidden) {
574
- if (cm.options.fixedGutter && view[i].gutter)
575
- view[i].gutter.style.left = left;
576
- var align = view[i].alignable;
577
- if (align) for (var j = 0; j < align.length; j++)
578
- align[j].style.left = left;
579
- }
580
- if (cm.options.fixedGutter)
581
- display.gutters.style.left = (comp + gutterW) + "px";
582
- }
583
-
584
- // Used to ensure that the line number gutter is still the right
585
- // size for the current document size. Returns true when an update
586
- // is needed.
587
- function maybeUpdateLineNumberWidth(cm) {
588
- if (!cm.options.lineNumbers) return false;
589
- var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display;
590
- if (last.length != display.lineNumChars) {
591
- var test = display.measure.appendChild(elt("div", [elt("div", last)],
592
- "CodeMirror-linenumber CodeMirror-gutter-elt"));
593
- var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
594
- display.lineGutter.style.width = "";
595
- display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1;
596
- display.lineNumWidth = display.lineNumInnerWidth + padding;
597
- display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
598
- display.lineGutter.style.width = display.lineNumWidth + "px";
599
- updateGutterSpace(cm);
600
- return true;
601
- }
602
- return false;
603
- }
604
-
605
- function lineNumberFor(options, i) {
606
- return String(options.lineNumberFormatter(i + options.firstLineNumber));
607
- }
608
-
609
- // Computes display.scroller.scrollLeft + display.gutters.offsetWidth,
610
- // but using getBoundingClientRect to get a sub-pixel-accurate
611
- // result.
612
- function compensateForHScroll(display) {
613
- return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left;
614
- }
615
-
616
- // DISPLAY DRAWING
617
-
618
- function DisplayUpdate(cm, viewport, force) {
619
- var display = cm.display;
620
-
621
- this.viewport = viewport;
622
- // Store some values that we'll need later (but don't want to force a relayout for)
623
- this.visible = visibleLines(display, cm.doc, viewport);
624
- this.editorIsHidden = !display.wrapper.offsetWidth;
625
- this.wrapperHeight = display.wrapper.clientHeight;
626
- this.wrapperWidth = display.wrapper.clientWidth;
627
- this.oldDisplayWidth = displayWidth(cm);
628
- this.force = force;
629
- this.dims = getDimensions(cm);
630
- this.events = [];
631
- }
632
-
633
- DisplayUpdate.prototype.signal = function(emitter, type) {
634
- if (hasHandler(emitter, type))
635
- this.events.push(arguments);
636
- };
637
- DisplayUpdate.prototype.finish = function() {
638
- for (var i = 0; i < this.events.length; i++)
639
- signal.apply(null, this.events[i]);
640
- };
641
-
642
- function maybeClipScrollbars(cm) {
643
- var display = cm.display;
644
- if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
645
- display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth;
646
- display.heightForcer.style.height = scrollGap(cm) + "px";
647
- display.sizer.style.marginBottom = -display.nativeBarWidth + "px";
648
- display.sizer.style.borderRightWidth = scrollGap(cm) + "px";
649
- display.scrollbarsClipped = true;
650
- }
651
- }
652
-
653
- // Does the actual updating of the line display. Bails out
654
- // (returning false) when there is nothing to be done and forced is
655
- // false.
656
- function updateDisplayIfNeeded(cm, update) {
657
- var display = cm.display, doc = cm.doc;
658
-
659
- if (update.editorIsHidden) {
660
- resetView(cm);
661
- return false;
662
- }
663
-
664
- // Bail out if the visible area is already rendered and nothing changed.
665
- if (!update.force &&
666
- update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
667
- (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
668
- display.renderedView == display.view && countDirtyView(cm) == 0)
669
- return false;
670
-
671
- if (maybeUpdateLineNumberWidth(cm)) {
672
- resetView(cm);
673
- update.dims = getDimensions(cm);
674
- }
675
-
676
- // Compute a suitable new viewport (from & to)
677
- var end = doc.first + doc.size;
678
- var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first);
679
- var to = Math.min(end, update.visible.to + cm.options.viewportMargin);
680
- if (display.viewFrom < from && from - display.viewFrom < 20) from = Math.max(doc.first, display.viewFrom);
681
- if (display.viewTo > to && display.viewTo - to < 20) to = Math.min(end, display.viewTo);
682
- if (sawCollapsedSpans) {
683
- from = visualLineNo(cm.doc, from);
684
- to = visualLineEndNo(cm.doc, to);
685
- }
686
-
687
- var different = from != display.viewFrom || to != display.viewTo ||
688
- display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth;
689
- adjustView(cm, from, to);
690
-
691
- display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom));
692
- // Position the mover div to align with the current scroll position
693
- cm.display.mover.style.top = display.viewOffset + "px";
694
-
695
- var toUpdate = countDirtyView(cm);
696
- if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
697
- (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
698
- return false;
699
-
700
- // For big changes, we hide the enclosing element during the
701
- // update, since that speeds up the operations on most browsers.
702
- var focused = activeElt();
703
- if (toUpdate > 4) display.lineDiv.style.display = "none";
704
- patchDisplay(cm, display.updateLineNumbers, update.dims);
705
- if (toUpdate > 4) display.lineDiv.style.display = "";
706
- display.renderedView = display.view;
707
- // There might have been a widget with a focused element that got
708
- // hidden or updated, if so re-focus it.
709
- if (focused && activeElt() != focused && focused.offsetHeight) focused.focus();
710
-
711
- // Prevent selection and cursors from interfering with the scroll
712
- // width and height.
713
- removeChildren(display.cursorDiv);
714
- removeChildren(display.selectionDiv);
715
- display.gutters.style.height = 0;
716
-
717
- if (different) {
718
- display.lastWrapHeight = update.wrapperHeight;
719
- display.lastWrapWidth = update.wrapperWidth;
720
- startWorker(cm, 400);
721
- }
722
-
723
- display.updateLineNumbers = null;
724
-
725
- return true;
726
- }
727
-
728
- function postUpdateDisplay(cm, update) {
729
- var force = update.force, viewport = update.viewport;
730
- for (var first = true;; first = false) {
731
- if (first && cm.options.lineWrapping && update.oldDisplayWidth != displayWidth(cm)) {
732
- force = true;
733
- } else {
734
- force = false;
735
- // Clip forced viewport to actual scrollable area.
736
- if (viewport && viewport.top != null)
737
- viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)};
738
- // Updated line heights might result in the drawn area not
739
- // actually covering the viewport. Keep looping until it does.
740
- update.visible = visibleLines(cm.display, cm.doc, viewport);
741
- if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo)
742
- break;
743
- }
744
- if (!updateDisplayIfNeeded(cm, update)) break;
745
- updateHeightsInViewport(cm);
746
- var barMeasure = measureForScrollbars(cm);
747
- updateSelection(cm);
748
- setDocumentHeight(cm, barMeasure);
749
- updateScrollbars(cm, barMeasure);
750
- }
751
-
752
- update.signal(cm, "update", cm);
753
- if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
754
- update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo);
755
- cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo;
756
- }
757
- }
758
-
759
- function updateDisplaySimple(cm, viewport) {
760
- var update = new DisplayUpdate(cm, viewport);
761
- if (updateDisplayIfNeeded(cm, update)) {
762
- updateHeightsInViewport(cm);
763
- postUpdateDisplay(cm, update);
764
- var barMeasure = measureForScrollbars(cm);
765
- updateSelection(cm);
766
- setDocumentHeight(cm, barMeasure);
767
- updateScrollbars(cm, barMeasure);
768
- update.finish();
769
- }
770
- }
771
-
772
- function setDocumentHeight(cm, measure) {
773
- cm.display.sizer.style.minHeight = measure.docHeight + "px";
774
- var total = measure.docHeight + cm.display.barHeight;
775
- cm.display.heightForcer.style.top = total + "px";
776
- cm.display.gutters.style.height = Math.max(total + scrollGap(cm), measure.clientHeight) + "px";
777
- }
778
-
779
- // Read the actual heights of the rendered lines, and update their
780
- // stored heights to match.
781
- function updateHeightsInViewport(cm) {
782
- var display = cm.display;
783
- var prevBottom = display.lineDiv.offsetTop;
784
- for (var i = 0; i < display.view.length; i++) {
785
- var cur = display.view[i], height;
786
- if (cur.hidden) continue;
787
- if (ie && ie_version < 8) {
788
- var bot = cur.node.offsetTop + cur.node.offsetHeight;
789
- height = bot - prevBottom;
790
- prevBottom = bot;
791
- } else {
792
- var box = cur.node.getBoundingClientRect();
793
- height = box.bottom - box.top;
794
- }
795
- var diff = cur.line.height - height;
796
- if (height < 2) height = textHeight(display);
797
- if (diff > .001 || diff < -.001) {
798
- updateLineHeight(cur.line, height);
799
- updateWidgetHeight(cur.line);
800
- if (cur.rest) for (var j = 0; j < cur.rest.length; j++)
801
- updateWidgetHeight(cur.rest[j]);
802
- }
803
- }
804
- }
805
-
806
- // Read and store the height of line widgets associated with the
807
- // given line.
808
- function updateWidgetHeight(line) {
809
- if (line.widgets) for (var i = 0; i < line.widgets.length; ++i)
810
- line.widgets[i].height = line.widgets[i].node.offsetHeight;
811
- }
812
-
813
- // Do a bulk-read of the DOM positions and sizes needed to draw the
814
- // view, so that we don't interleave reading and writing to the DOM.
815
- function getDimensions(cm) {
816
- var d = cm.display, left = {}, width = {};
817
- var gutterLeft = d.gutters.clientLeft;
818
- for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
819
- left[cm.options.gutters[i]] = n.offsetLeft + n.clientLeft + gutterLeft;
820
- width[cm.options.gutters[i]] = n.clientWidth;
821
- }
822
- return {fixedPos: compensateForHScroll(d),
823
- gutterTotalWidth: d.gutters.offsetWidth,
824
- gutterLeft: left,
825
- gutterWidth: width,
826
- wrapperWidth: d.wrapper.clientWidth};
827
- }
828
-
829
- // Sync the actual display DOM structure with display.view, removing
830
- // nodes for lines that are no longer in view, and creating the ones
831
- // that are not there yet, and updating the ones that are out of
832
- // date.
833
- function patchDisplay(cm, updateNumbersFrom, dims) {
834
- var display = cm.display, lineNumbers = cm.options.lineNumbers;
835
- var container = display.lineDiv, cur = container.firstChild;
836
-
837
- function rm(node) {
838
- var next = node.nextSibling;
839
- // Works around a throw-scroll bug in OS X Webkit
840
- if (webkit && mac && cm.display.currentWheelTarget == node)
841
- node.style.display = "none";
842
- else
843
- node.parentNode.removeChild(node);
844
- return next;
845
- }
846
-
847
- var view = display.view, lineN = display.viewFrom;
848
- // Loop over the elements in the view, syncing cur (the DOM nodes
849
- // in display.lineDiv) with the view as we go.
850
- for (var i = 0; i < view.length; i++) {
851
- var lineView = view[i];
852
- if (lineView.hidden) {
853
- } else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet
854
- var node = buildLineElement(cm, lineView, lineN, dims);
855
- container.insertBefore(node, cur);
856
- } else { // Already drawn
857
- while (cur != lineView.node) cur = rm(cur);
858
- var updateNumber = lineNumbers && updateNumbersFrom != null &&
859
- updateNumbersFrom <= lineN && lineView.lineNumber;
860
- if (lineView.changes) {
861
- if (indexOf(lineView.changes, "gutter") > -1) updateNumber = false;
862
- updateLineForChanges(cm, lineView, lineN, dims);
863
- }
864
- if (updateNumber) {
865
- removeChildren(lineView.lineNumber);
866
- lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)));
867
- }
868
- cur = lineView.node.nextSibling;
869
- }
870
- lineN += lineView.size;
871
- }
872
- while (cur) cur = rm(cur);
873
- }
874
-
875
- // When an aspect of a line changes, a string is added to
876
- // lineView.changes. This updates the relevant part of the line's
877
- // DOM structure.
878
- function updateLineForChanges(cm, lineView, lineN, dims) {
879
- for (var j = 0; j < lineView.changes.length; j++) {
880
- var type = lineView.changes[j];
881
- if (type == "text") updateLineText(cm, lineView);
882
- else if (type == "gutter") updateLineGutter(cm, lineView, lineN, dims);
883
- else if (type == "class") updateLineClasses(lineView);
884
- else if (type == "widget") updateLineWidgets(cm, lineView, dims);
885
- }
886
- lineView.changes = null;
887
- }
888
-
889
- // Lines with gutter elements, widgets or a background class need to
890
- // be wrapped, and have the extra elements added to the wrapper div
891
- function ensureLineWrapped(lineView) {
892
- if (lineView.node == lineView.text) {
893
- lineView.node = elt("div", null, null, "position: relative");
894
- if (lineView.text.parentNode)
895
- lineView.text.parentNode.replaceChild(lineView.node, lineView.text);
896
- lineView.node.appendChild(lineView.text);
897
- if (ie && ie_version < 8) lineView.node.style.zIndex = 2;
898
- }
899
- return lineView.node;
900
- }
901
-
902
- function updateLineBackground(lineView) {
903
- var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass;
904
- if (cls) cls += " CodeMirror-linebackground";
905
- if (lineView.background) {
906
- if (cls) lineView.background.className = cls;
907
- else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null; }
908
- } else if (cls) {
909
- var wrap = ensureLineWrapped(lineView);
910
- lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild);
911
- }
912
- }
913
-
914
- // Wrapper around buildLineContent which will reuse the structure
915
- // in display.externalMeasured when possible.
916
- function getLineContent(cm, lineView) {
917
- var ext = cm.display.externalMeasured;
918
- if (ext && ext.line == lineView.line) {
919
- cm.display.externalMeasured = null;
920
- lineView.measure = ext.measure;
921
- return ext.built;
922
- }
923
- return buildLineContent(cm, lineView);
924
- }
925
-
926
- // Redraw the line's text. Interacts with the background and text
927
- // classes because the mode may output tokens that influence these
928
- // classes.
929
- function updateLineText(cm, lineView) {
930
- var cls = lineView.text.className;
931
- var built = getLineContent(cm, lineView);
932
- if (lineView.text == lineView.node) lineView.node = built.pre;
933
- lineView.text.parentNode.replaceChild(built.pre, lineView.text);
934
- lineView.text = built.pre;
935
- if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
936
- lineView.bgClass = built.bgClass;
937
- lineView.textClass = built.textClass;
938
- updateLineClasses(lineView);
939
- } else if (cls) {
940
- lineView.text.className = cls;
941
- }
942
- }
943
-
944
- function updateLineClasses(lineView) {
945
- updateLineBackground(lineView);
946
- if (lineView.line.wrapClass)
947
- ensureLineWrapped(lineView).className = lineView.line.wrapClass;
948
- else if (lineView.node != lineView.text)
949
- lineView.node.className = "";
950
- var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass;
951
- lineView.text.className = textClass || "";
952
- }
953
-
954
- function updateLineGutter(cm, lineView, lineN, dims) {
955
- if (lineView.gutter) {
956
- lineView.node.removeChild(lineView.gutter);
957
- lineView.gutter = null;
958
- }
959
- var markers = lineView.line.gutterMarkers;
960
- if (cm.options.lineNumbers || markers) {
961
- var wrap = ensureLineWrapped(lineView);
962
- var gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", "left: " +
963
- (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) +
964
- "px; width: " + dims.gutterTotalWidth + "px");
965
- cm.display.input.setUneditable(gutterWrap);
966
- wrap.insertBefore(gutterWrap, lineView.text);
967
- if (lineView.line.gutterClass)
968
- gutterWrap.className += " " + lineView.line.gutterClass;
969
- if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
970
- lineView.lineNumber = gutterWrap.appendChild(
971
- elt("div", lineNumberFor(cm.options, lineN),
972
- "CodeMirror-linenumber CodeMirror-gutter-elt",
973
- "left: " + dims.gutterLeft["CodeMirror-linenumbers"] + "px; width: "
974
- + cm.display.lineNumInnerWidth + "px"));
975
- if (markers) for (var k = 0; k < cm.options.gutters.length; ++k) {
976
- var id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id];
977
- if (found)
978
- gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt", "left: " +
979
- dims.gutterLeft[id] + "px; width: " + dims.gutterWidth[id] + "px"));
980
- }
981
- }
982
- }
983
-
984
- function updateLineWidgets(cm, lineView, dims) {
985
- if (lineView.alignable) lineView.alignable = null;
986
- for (var node = lineView.node.firstChild, next; node; node = next) {
987
- var next = node.nextSibling;
988
- if (node.className == "CodeMirror-linewidget")
989
- lineView.node.removeChild(node);
990
- }
991
- insertLineWidgets(cm, lineView, dims);
992
- }
993
-
994
- // Build a line's DOM representation from scratch
995
- function buildLineElement(cm, lineView, lineN, dims) {
996
- var built = getLineContent(cm, lineView);
997
- lineView.text = lineView.node = built.pre;
998
- if (built.bgClass) lineView.bgClass = built.bgClass;
999
- if (built.textClass) lineView.textClass = built.textClass;
1000
-
1001
- updateLineClasses(lineView);
1002
- updateLineGutter(cm, lineView, lineN, dims);
1003
- insertLineWidgets(cm, lineView, dims);
1004
- return lineView.node;
1005
- }
1006
-
1007
- // A lineView may contain multiple logical lines (when merged by
1008
- // collapsed spans). The widgets for all of them need to be drawn.
1009
- function insertLineWidgets(cm, lineView, dims) {
1010
- insertLineWidgetsFor(cm, lineView.line, lineView, dims, true);
1011
- if (lineView.rest) for (var i = 0; i < lineView.rest.length; i++)
1012
- insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false);
1013
- }
1014
-
1015
- function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
1016
- if (!line.widgets) return;
1017
- var wrap = ensureLineWrapped(lineView);
1018
- for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
1019
- var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget");
1020
- if (!widget.handleMouseEvents) node.setAttribute("cm-ignore-events", "true");
1021
- positionLineWidget(widget, node, lineView, dims);
1022
- cm.display.input.setUneditable(node);
1023
- if (allowAbove && widget.above)
1024
- wrap.insertBefore(node, lineView.gutter || lineView.text);
1025
- else
1026
- wrap.appendChild(node);
1027
- signalLater(widget, "redraw");
1028
- }
1029
- }
1030
-
1031
- function positionLineWidget(widget, node, lineView, dims) {
1032
- if (widget.noHScroll) {
1033
- (lineView.alignable || (lineView.alignable = [])).push(node);
1034
- var width = dims.wrapperWidth;
1035
- node.style.left = dims.fixedPos + "px";
1036
- if (!widget.coverGutter) {
1037
- width -= dims.gutterTotalWidth;
1038
- node.style.paddingLeft = dims.gutterTotalWidth + "px";
1039
- }
1040
- node.style.width = width + "px";
1041
- }
1042
- if (widget.coverGutter) {
1043
- node.style.zIndex = 5;
1044
- node.style.position = "relative";
1045
- if (!widget.noHScroll) node.style.marginLeft = -dims.gutterTotalWidth + "px";
1046
- }
1047
- }
1048
-
1049
- // POSITION OBJECT
1050
-
1051
- // A Pos instance represents a position within the text.
1052
- var Pos = CodeMirror.Pos = function(line, ch) {
1053
- if (!(this instanceof Pos)) return new Pos(line, ch);
1054
- this.line = line; this.ch = ch;
1055
- };
1056
-
1057
- // Compare two positions, return 0 if they are the same, a negative
1058
- // number when a is less, and a positive number otherwise.
1059
- var cmp = CodeMirror.cmpPos = function(a, b) { return a.line - b.line || a.ch - b.ch; };
1060
-
1061
- function copyPos(x) {return Pos(x.line, x.ch);}
1062
- function maxPos(a, b) { return cmp(a, b) < 0 ? b : a; }
1063
- function minPos(a, b) { return cmp(a, b) < 0 ? a : b; }
1064
-
1065
- // INPUT HANDLING
1066
-
1067
- function ensureFocus(cm) {
1068
- if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm); }
1069
- }
1070
-
1071
- function isReadOnly(cm) {
1072
- return cm.options.readOnly || cm.doc.cantEdit;
1073
- }
1074
-
1075
- // This will be set to an array of strings when copying, so that,
1076
- // when pasting, we know what kind of selections the copied text
1077
- // was made out of.
1078
- var lastCopied = null;
1079
-
1080
- function applyTextInput(cm, inserted, deleted, sel) {
1081
- var doc = cm.doc;
1082
- cm.display.shift = false;
1083
- if (!sel) sel = doc.sel;
1084
-
1085
- var textLines = splitLines(inserted), multiPaste = null;
1086
- // When pasing N lines into N selections, insert one line per selection
1087
- if (cm.state.pasteIncoming && sel.ranges.length > 1) {
1088
- if (lastCopied && lastCopied.join("\n") == inserted)
1089
- multiPaste = sel.ranges.length % lastCopied.length == 0 && map(lastCopied, splitLines);
1090
- else if (textLines.length == sel.ranges.length)
1091
- multiPaste = map(textLines, function(l) { return [l]; });
1092
- }
1093
-
1094
- // Normal behavior is to insert the new text into every selection
1095
- for (var i = sel.ranges.length - 1; i >= 0; i--) {
1096
- var range = sel.ranges[i];
1097
- var from = range.from(), to = range.to();
1098
- if (range.empty()) {
1099
- if (deleted && deleted > 0) // Handle deletion
1100
- from = Pos(from.line, from.ch - deleted);
1101
- else if (cm.state.overwrite && !cm.state.pasteIncoming) // Handle overwrite
1102
- to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length));
1103
- }
1104
- var updateInput = cm.curOp.updateInput;
1105
- var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i % multiPaste.length] : textLines,
1106
- origin: cm.state.pasteIncoming ? "paste" : cm.state.cutIncoming ? "cut" : "+input"};
1107
- makeChange(cm.doc, changeEvent);
1108
- signalLater(cm, "inputRead", cm, changeEvent);
1109
- // When an 'electric' character is inserted, immediately trigger a reindent
1110
- if (inserted && !cm.state.pasteIncoming && cm.options.electricChars &&
1111
- cm.options.smartIndent && range.head.ch < 100 &&
1112
- (!i || sel.ranges[i - 1].head.line != range.head.line)) {
1113
- var mode = cm.getModeAt(range.head);
1114
- var end = changeEnd(changeEvent);
1115
- if (mode.electricChars) {
1116
- for (var j = 0; j < mode.electricChars.length; j++)
1117
- if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
1118
- indentLine(cm, end.line, "smart");
1119
- break;
1120
- }
1121
- } else if (mode.electricInput) {
1122
- if (mode.electricInput.test(getLine(doc, end.line).text.slice(0, end.ch)))
1123
- indentLine(cm, end.line, "smart");
1124
- }
1125
- }
1126
- }
1127
- ensureCursorVisible(cm);
1128
- cm.curOp.updateInput = updateInput;
1129
- cm.curOp.typing = true;
1130
- cm.state.pasteIncoming = cm.state.cutIncoming = false;
1131
- }
1132
-
1133
- function copyableRanges(cm) {
1134
- var text = [], ranges = [];
1135
- for (var i = 0; i < cm.doc.sel.ranges.length; i++) {
1136
- var line = cm.doc.sel.ranges[i].head.line;
1137
- var lineRange = {anchor: Pos(line, 0), head: Pos(line + 1, 0)};
1138
- ranges.push(lineRange);
1139
- text.push(cm.getRange(lineRange.anchor, lineRange.head));
1140
- }
1141
- return {text: text, ranges: ranges};
1142
- }
1143
-
1144
- function disableBrowserMagic(field) {
1145
- field.setAttribute("autocorrect", "off");
1146
- field.setAttribute("autocapitalize", "off");
1147
- field.setAttribute("spellcheck", "false");
1148
- }
1149
-
1150
- // TEXTAREA INPUT STYLE
1151
-
1152
- function TextareaInput(cm) {
1153
- this.cm = cm;
1154
- // See input.poll and input.reset
1155
- this.prevInput = "";
1156
-
1157
- // Flag that indicates whether we expect input to appear real soon
1158
- // now (after some event like 'keypress' or 'input') and are
1159
- // polling intensively.
1160
- this.pollingFast = false;
1161
- // Self-resetting timeout for the poller
1162
- this.polling = new Delayed();
1163
- // Tracks when input.reset has punted to just putting a short
1164
- // string into the textarea instead of the full selection.
1165
- this.inaccurateSelection = false;
1166
- // Used to work around IE issue with selection being forgotten when focus moves away from textarea
1167
- this.hasSelection = false;
1168
- };
1169
-
1170
- function hiddenTextarea() {
1171
- var te = elt("textarea", null, null, "position: absolute; padding: 0; width: 1px; height: 1em; outline: none");
1172
- var div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
1173
- // The textarea is kept positioned near the cursor to prevent the
1174
- // fact that it'll be scrolled into view on input from scrolling
1175
- // our fake cursor out of view. On webkit, when wrap=off, paste is
1176
- // very slow. So make the area wide instead.
1177
- if (webkit) te.style.width = "1000px";
1178
- else te.setAttribute("wrap", "off");
1179
- // If border: 0; -- iOS fails to open keyboard (issue #1287)
1180
- if (ios) te.style.border = "1px solid black";
1181
- disableBrowserMagic(te);
1182
- return div;
1183
- }
1184
-
1185
- TextareaInput.prototype = copyObj({
1186
- init: function(display) {
1187
- var input = this, cm = this.cm;
1188
-
1189
- // Wraps and hides input textarea
1190
- var div = this.wrapper = hiddenTextarea();
1191
- // The semihidden textarea that is focused when the editor is
1192
- // focused, and receives input.
1193
- var te = this.textarea = div.firstChild;
1194
- display.wrapper.insertBefore(div, display.wrapper.firstChild);
1195
-
1196
- // Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore)
1197
- if (ios) te.style.width = "0px";
1198
-
1199
- on(te, "input", function() {
1200
- if (ie && ie_version >= 9 && input.hasSelection) input.hasSelection = null;
1201
- input.poll();
1202
- });
1203
-
1204
- on(te, "paste", function() {
1205
- // Workaround for webkit bug https://bugs.webkit.org/show_bug.cgi?id=90206
1206
- // Add a char to the end of textarea before paste occur so that
1207
- // selection doesn't span to the end of textarea.
1208
- if (webkit && !cm.state.fakedLastChar && !(new Date - cm.state.lastMiddleDown < 200)) {
1209
- var start = te.selectionStart, end = te.selectionEnd;
1210
- te.value += "$";
1211
- // The selection end needs to be set before the start, otherwise there
1212
- // can be an intermediate non-empty selection between the two, which
1213
- // can override the middle-click paste buffer on linux and cause the
1214
- // wrong thing to get pasted.
1215
- te.selectionEnd = end;
1216
- te.selectionStart = start;
1217
- cm.state.fakedLastChar = true;
1218
- }
1219
- cm.state.pasteIncoming = true;
1220
- input.fastPoll();
1221
- });
1222
-
1223
- function prepareCopyCut(e) {
1224
- if (cm.somethingSelected()) {
1225
- lastCopied = cm.getSelections();
1226
- if (input.inaccurateSelection) {
1227
- input.prevInput = "";
1228
- input.inaccurateSelection = false;
1229
- te.value = lastCopied.join("\n");
1230
- selectInput(te);
1231
- }
1232
- } else {
1233
- var ranges = copyableRanges(cm);
1234
- lastCopied = ranges.text;
1235
- if (e.type == "cut") {
1236
- cm.setSelections(ranges.ranges, null, sel_dontScroll);
1237
- } else {
1238
- input.prevInput = "";
1239
- te.value = ranges.text.join("\n");
1240
- selectInput(te);
1241
- }
1242
- }
1243
- if (e.type == "cut") cm.state.cutIncoming = true;
1244
- }
1245
- on(te, "cut", prepareCopyCut);
1246
- on(te, "copy", prepareCopyCut);
1247
-
1248
- on(display.scroller, "paste", function(e) {
1249
- if (eventInWidget(display, e)) return;
1250
- cm.state.pasteIncoming = true;
1251
- input.focus();
1252
- });
1253
-
1254
- // Prevent normal selection in the editor (we handle our own)
1255
- on(display.lineSpace, "selectstart", function(e) {
1256
- if (!eventInWidget(display, e)) e_preventDefault(e);
1257
- });
1258
- },
1259
-
1260
- prepareSelection: function() {
1261
- // Redraw the selection and/or cursor
1262
- var cm = this.cm, display = cm.display, doc = cm.doc;
1263
- var result = prepareSelection(cm);
1264
-
1265
- // Move the hidden textarea near the cursor to prevent scrolling artifacts
1266
- if (cm.options.moveInputWithCursor) {
1267
- var headPos = cursorCoords(cm, doc.sel.primary().head, "div");
1268
- var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect();
1269
- result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
1270
- headPos.top + lineOff.top - wrapOff.top));
1271
- result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
1272
- headPos.left + lineOff.left - wrapOff.left));
1273
- }
1274
-
1275
- return result;
1276
- },
1277
-
1278
- showSelection: function(drawn) {
1279
- var cm = this.cm, display = cm.display;
1280
- removeChildrenAndAdd(display.cursorDiv, drawn.cursors);
1281
- removeChildrenAndAdd(display.selectionDiv, drawn.selection);
1282
- if (drawn.teTop != null) {
1283
- this.wrapper.style.top = drawn.teTop + "px";
1284
- this.wrapper.style.left = drawn.teLeft + "px";
1285
- }
1286
- },
1287
-
1288
- // Reset the input to correspond to the selection (or to be empty,
1289
- // when not typing and nothing is selected)
1290
- reset: function(typing) {
1291
- if (this.contextMenuPending) return;
1292
- var minimal, selected, cm = this.cm, doc = cm.doc;
1293
- if (cm.somethingSelected()) {
1294
- this.prevInput = "";
1295
- var range = doc.sel.primary();
1296
- minimal = hasCopyEvent &&
1297
- (range.to().line - range.from().line > 100 || (selected = cm.getSelection()).length > 1000);
1298
- var content = minimal ? "-" : selected || cm.getSelection();
1299
- this.textarea.value = content;
1300
- if (cm.state.focused) selectInput(this.textarea);
1301
- if (ie && ie_version >= 9) this.hasSelection = content;
1302
- } else if (!typing) {
1303
- this.prevInput = this.textarea.value = "";
1304
- if (ie && ie_version >= 9) this.hasSelection = null;
1305
- }
1306
- this.inaccurateSelection = minimal;
1307
- },
1308
-
1309
- getField: function() { return this.textarea; },
1310
-
1311
- supportsTouch: function() { return false; },
1312
-
1313
- focus: function() {
1314
- if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt() != this.textarea)) {
1315
- try { this.textarea.focus(); }
1316
- catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM
1317
- }
1318
- },
1319
-
1320
- blur: function() { this.textarea.blur(); },
1321
-
1322
- resetPosition: function() {
1323
- this.wrapper.style.top = this.wrapper.style.left = 0;
1324
- },
1325
-
1326
- receivedFocus: function() { this.slowPoll(); },
1327
-
1328
- // Poll for input changes, using the normal rate of polling. This
1329
- // runs as long as the editor is focused.
1330
- slowPoll: function() {
1331
- var input = this;
1332
- if (input.pollingFast) return;
1333
- input.polling.set(this.cm.options.pollInterval, function() {
1334
- input.poll();
1335
- if (input.cm.state.focused) input.slowPoll();
1336
- });
1337
- },
1338
-
1339
- // When an event has just come in that is likely to add or change
1340
- // something in the input textarea, we poll faster, to ensure that
1341
- // the change appears on the screen quickly.
1342
- fastPoll: function() {
1343
- var missed = false, input = this;
1344
- input.pollingFast = true;
1345
- function p() {
1346
- var changed = input.poll();
1347
- if (!changed && !missed) {missed = true; input.polling.set(60, p);}
1348
- else {input.pollingFast = false; input.slowPoll();}
1349
- }
1350
- input.polling.set(20, p);
1351
- },
1352
-
1353
- // Read input from the textarea, and update the document to match.
1354
- // When something is selected, it is present in the textarea, and
1355
- // selected (unless it is huge, in which case a placeholder is
1356
- // used). When nothing is selected, the cursor sits after previously
1357
- // seen text (can be empty), which is stored in prevInput (we must
1358
- // not reset the textarea when typing, because that breaks IME).
1359
- poll: function() {
1360
- var cm = this.cm, input = this.textarea, prevInput = this.prevInput;
1361
- // Since this is called a *lot*, try to bail out as cheaply as
1362
- // possible when it is clear that nothing happened. hasSelection
1363
- // will be the case when there is a lot of text in the textarea,
1364
- // in which case reading its value would be expensive.
1365
- if (!cm.state.focused || (hasSelection(input) && !prevInput) ||
1366
- isReadOnly(cm) || cm.options.disableInput || cm.state.keySeq)
1367
- return false;
1368
- // See paste handler for more on the fakedLastChar kludge
1369
- if (cm.state.pasteIncoming && cm.state.fakedLastChar) {
1370
- input.value = input.value.substring(0, input.value.length - 1);
1371
- cm.state.fakedLastChar = false;
1372
- }
1373
- var text = input.value;
1374
- // If nothing changed, bail.
1375
- if (text == prevInput && !cm.somethingSelected()) return false;
1376
- // Work around nonsensical selection resetting in IE9/10, and
1377
- // inexplicable appearance of private area unicode characters on
1378
- // some key combos in Mac (#2689).
1379
- if (ie && ie_version >= 9 && this.hasSelection === text ||
1380
- mac && /[\uf700-\uf7ff]/.test(text)) {
1381
- cm.display.input.reset();
1382
- return false;
1383
- }
1384
-
1385
- if (text.charCodeAt(0) == 0x200b && cm.doc.sel == cm.display.selForContextMenu && !prevInput)
1386
- prevInput = "\u200b";
1387
- // Find the part of the input that is actually new
1388
- var same = 0, l = Math.min(prevInput.length, text.length);
1389
- while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) ++same;
1390
-
1391
- var self = this;
1392
- runInOp(cm, function() {
1393
- applyTextInput(cm, text.slice(same), prevInput.length - same);
1394
-
1395
- // Don't leave long text in the textarea, since it makes further polling slow
1396
- if (text.length > 1000 || text.indexOf("\n") > -1) input.value = self.prevInput = "";
1397
- else self.prevInput = text;
1398
- });
1399
- return true;
1400
- },
1401
-
1402
- ensurePolled: function() {
1403
- if (this.pollingFast && this.poll()) this.pollingFast = false;
1404
- },
1405
-
1406
- onKeyPress: function() {
1407
- if (ie && ie_version >= 9) this.hasSelection = null;
1408
- this.fastPoll();
1409
- },
1410
-
1411
- onContextMenu: function(e) {
1412
- var input = this, cm = input.cm, display = cm.display, te = input.textarea;
1413
- var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
1414
- if (!pos || presto) return; // Opera is difficult.
1415
-
1416
- // Reset the current text selection only if the click is done outside of the selection
1417
- // and 'resetSelectionOnContextMenu' option is true.
1418
- var reset = cm.options.resetSelectionOnContextMenu;
1419
- if (reset && cm.doc.sel.contains(pos) == -1)
1420
- operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll);
1421
-
1422
- var oldCSS = te.style.cssText;
1423
- input.wrapper.style.position = "absolute";
1424
- te.style.cssText = "position: fixed; width: 30px; height: 30px; top: " + (e.clientY - 5) +
1425
- "px; left: " + (e.clientX - 5) + "px; z-index: 1000; background: " +
1426
- (ie ? "rgba(255, 255, 255, .05)" : "transparent") +
1427
- "; outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";
1428
- if (webkit) var oldScrollY = window.scrollY; // Work around Chrome issue (#2712)
1429
- display.input.focus();
1430
- if (webkit) window.scrollTo(null, oldScrollY);
1431
- display.input.reset();
1432
- // Adds "Select all" to context menu in FF
1433
- if (!cm.somethingSelected()) te.value = input.prevInput = " ";
1434
- input.contextMenuPending = true;
1435
- display.selForContextMenu = cm.doc.sel;
1436
- clearTimeout(display.detectingSelectAll);
1437
-
1438
- // Select-all will be greyed out if there's nothing to select, so
1439
- // this adds a zero-width space so that we can later check whether
1440
- // it got selected.
1441
- function prepareSelectAllHack() {
1442
- if (te.selectionStart != null) {
1443
- var selected = cm.somethingSelected();
1444
- var extval = te.value = "\u200b" + (selected ? te.value : "");
1445
- input.prevInput = selected ? "" : "\u200b";
1446
- te.selectionStart = 1; te.selectionEnd = extval.length;
1447
- // Re-set this, in case some other handler touched the
1448
- // selection in the meantime.
1449
- display.selForContextMenu = cm.doc.sel;
1450
- }
1451
- }
1452
- function rehide() {
1453
- input.contextMenuPending = false;
1454
- input.wrapper.style.position = "relative";
1455
- te.style.cssText = oldCSS;
1456
- if (ie && ie_version < 9) display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos);
1457
-
1458
- // Try to detect the user choosing select-all
1459
- if (te.selectionStart != null) {
1460
- if (!ie || (ie && ie_version < 9)) prepareSelectAllHack();
1461
- var i = 0, poll = function() {
1462
- if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0)
1463
- operation(cm, commands.selectAll)(cm);
1464
- else if (i++ < 10) display.detectingSelectAll = setTimeout(poll, 500);
1465
- else display.input.reset();
1466
- };
1467
- display.detectingSelectAll = setTimeout(poll, 200);
1468
- }
1469
- }
1470
-
1471
- if (ie && ie_version >= 9) prepareSelectAllHack();
1472
- if (captureRightClick) {
1473
- e_stop(e);
1474
- var mouseup = function() {
1475
- off(window, "mouseup", mouseup);
1476
- setTimeout(rehide, 20);
1477
- };
1478
- on(window, "mouseup", mouseup);
1479
- } else {
1480
- setTimeout(rehide, 50);
1481
- }
1482
- },
1483
-
1484
- setUneditable: nothing,
1485
-
1486
- needsContentAttribute: false
1487
- }, TextareaInput.prototype);
1488
-
1489
- // CONTENTEDITABLE INPUT STYLE
1490
-
1491
- function ContentEditableInput(cm) {
1492
- this.cm = cm;
1493
- this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null;
1494
- this.polling = new Delayed();
1495
- this.gracePeriod = false;
1496
- }
1497
-
1498
- ContentEditableInput.prototype = copyObj({
1499
- init: function(display) {
1500
- var input = this, cm = input.cm;
1501
- var div = input.div = display.lineDiv;
1502
- div.contentEditable = "true";
1503
- disableBrowserMagic(div);
1504
-
1505
- on(div, "paste", function(e) {
1506
- var pasted = e.clipboardData && e.clipboardData.getData("text/plain");
1507
- if (pasted) {
1508
- e.preventDefault();
1509
- cm.replaceSelection(pasted, null, "paste");
1510
- }
1511
- });
1512
-
1513
- on(div, "compositionstart", function(e) {
1514
- var data = e.data;
1515
- input.composing = {sel: cm.doc.sel, data: data, startData: data};
1516
- if (!data) return;
1517
- var prim = cm.doc.sel.primary();
1518
- var line = cm.getLine(prim.head.line);
1519
- var found = line.indexOf(data, Math.max(0, prim.head.ch - data.length));
1520
- if (found > -1 && found <= prim.head.ch)
1521
- input.composing.sel = simpleSelection(Pos(prim.head.line, found),
1522
- Pos(prim.head.line, found + data.length));
1523
- });
1524
- on(div, "compositionupdate", function(e) {
1525
- input.composing.data = e.data;
1526
- });
1527
- on(div, "compositionend", function(e) {
1528
- var ours = input.composing;
1529
- if (!ours) return;
1530
- if (e.data != ours.startData && !/\u200b/.test(e.data))
1531
- ours.data = e.data;
1532
- // Need a small delay to prevent other code (input event,
1533
- // selection polling) from doing damage when fired right after
1534
- // compositionend.
1535
- setTimeout(function() {
1536
- if (!ours.handled)
1537
- input.applyComposition(ours);
1538
- if (input.composing == ours)
1539
- input.composing = null;
1540
- }, 50);
1541
- });
1542
-
1543
- on(div, "touchstart", function() {
1544
- input.forceCompositionEnd();
1545
- });
1546
-
1547
- on(div, "input", function() {
1548
- if (input.composing) return;
1549
- if (!input.pollContent())
1550
- runInOp(input.cm, function() {regChange(cm);});
1551
- });
1552
-
1553
- function onCopyCut(e) {
1554
- if (cm.somethingSelected()) {
1555
- lastCopied = cm.getSelections();
1556
- if (e.type == "cut") cm.replaceSelection("", null, "cut");
1557
- } else {
1558
- var ranges = copyableRanges(cm);
1559
- lastCopied = ranges.text;
1560
- if (e.type == "cut") {
1561
- cm.operation(function() {
1562
- cm.setSelections(ranges.ranges, 0, sel_dontScroll);
1563
- cm.replaceSelection("", null, "cut");
1564
- });
1565
- }
1566
- }
1567
- // iOS exposes the clipboard API, but seems to discard content inserted into it
1568
- if (e.clipboardData && !ios) {
1569
- e.preventDefault();
1570
- e.clipboardData.clearData();
1571
- e.clipboardData.setData("text/plain", lastCopied.join("\n"));
1572
- } else {
1573
- // Old-fashioned briefly-focus-a-textarea hack
1574
- var kludge = hiddenTextarea(), te = kludge.firstChild;
1575
- cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild);
1576
- te.value = lastCopied.join("\n");
1577
- var hadFocus = document.activeElement;
1578
- selectInput(te);
1579
- setTimeout(function() {
1580
- cm.display.lineSpace.removeChild(kludge);
1581
- hadFocus.focus();
1582
- }, 50);
1583
- }
1584
- }
1585
- on(div, "copy", onCopyCut);
1586
- on(div, "cut", onCopyCut);
1587
- },
1588
-
1589
- prepareSelection: function() {
1590
- var result = prepareSelection(this.cm, false);
1591
- result.focus = this.cm.state.focused;
1592
- return result;
1593
- },
1594
-
1595
- showSelection: function(info) {
1596
- if (!info || !this.cm.display.view.length) return;
1597
- if (info.focus) this.showPrimarySelection();
1598
- this.showMultipleSelections(info);
1599
- },
1600
-
1601
- showPrimarySelection: function() {
1602
- var sel = window.getSelection(), prim = this.cm.doc.sel.primary();
1603
- var curAnchor = domToPos(this.cm, sel.anchorNode, sel.anchorOffset);
1604
- var curFocus = domToPos(this.cm, sel.focusNode, sel.focusOffset);
1605
- if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad &&
1606
- cmp(minPos(curAnchor, curFocus), prim.from()) == 0 &&
1607
- cmp(maxPos(curAnchor, curFocus), prim.to()) == 0)
1608
- return;
1609
-
1610
- var start = posToDOM(this.cm, prim.from());
1611
- var end = posToDOM(this.cm, prim.to());
1612
- if (!start && !end) return;
1613
-
1614
- var view = this.cm.display.view;
1615
- var old = sel.rangeCount && sel.getRangeAt(0);
1616
- if (!start) {
1617
- start = {node: view[0].measure.map[2], offset: 0};
1618
- } else if (!end) { // FIXME dangerously hacky
1619
- var measure = view[view.length - 1].measure;
1620
- var map = measure.maps ? measure.maps[measure.maps.length - 1] : measure.map;
1621
- end = {node: map[map.length - 1], offset: map[map.length - 2] - map[map.length - 3]};
1622
- }
1623
-
1624
- try { var rng = range(start.node, start.offset, end.offset, end.node); }
1625
- catch(e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible
1626
- if (rng) {
1627
- sel.removeAllRanges();
1628
- sel.addRange(rng);
1629
- if (old && sel.anchorNode == null) sel.addRange(old);
1630
- else if (gecko) this.startGracePeriod();
1631
- }
1632
- this.rememberSelection();
1633
- },
1634
-
1635
- startGracePeriod: function() {
1636
- var input = this;
1637
- clearTimeout(this.gracePeriod);
1638
- this.gracePeriod = setTimeout(function() {
1639
- input.gracePeriod = false;
1640
- if (input.selectionChanged())
1641
- input.cm.operation(function() { input.cm.curOp.selectionChanged = true; });
1642
- }, 20);
1643
- },
1644
-
1645
- showMultipleSelections: function(info) {
1646
- removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors);
1647
- removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection);
1648
- },
1649
-
1650
- rememberSelection: function() {
1651
- var sel = window.getSelection();
1652
- this.lastAnchorNode = sel.anchorNode; this.lastAnchorOffset = sel.anchorOffset;
1653
- this.lastFocusNode = sel.focusNode; this.lastFocusOffset = sel.focusOffset;
1654
- },
1655
-
1656
- selectionInEditor: function() {
1657
- var sel = window.getSelection();
1658
- if (!sel.rangeCount) return false;
1659
- var node = sel.getRangeAt(0).commonAncestorContainer;
1660
- return contains(this.div, node);
1661
- },
1662
-
1663
- focus: function() {
1664
- if (this.cm.options.readOnly != "nocursor") this.div.focus();
1665
- },
1666
- blur: function() { this.div.blur(); },
1667
- getField: function() { return this.div; },
1668
-
1669
- supportsTouch: function() { return true; },
1670
-
1671
- receivedFocus: function() {
1672
- var input = this;
1673
- if (this.selectionInEditor())
1674
- this.pollSelection();
1675
- else
1676
- runInOp(this.cm, function() { input.cm.curOp.selectionChanged = true; });
1677
-
1678
- function poll() {
1679
- if (input.cm.state.focused) {
1680
- input.pollSelection();
1681
- input.polling.set(input.cm.options.pollInterval, poll);
1682
- }
1683
- }
1684
- this.polling.set(this.cm.options.pollInterval, poll);
1685
- },
1686
-
1687
- selectionChanged: function() {
1688
- var sel = window.getSelection();
1689
- return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset ||
1690
- sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset;
1691
- },
1692
-
1693
- pollSelection: function() {
1694
- if (!this.composing && !this.gracePeriod && this.selectionChanged()) {
1695
- var sel = window.getSelection(), cm = this.cm;
1696
- this.rememberSelection();
1697
- var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
1698
- var head = domToPos(cm, sel.focusNode, sel.focusOffset);
1699
- if (anchor && head) runInOp(cm, function() {
1700
- setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll);
1701
- if (anchor.bad || head.bad) cm.curOp.selectionChanged = true;
1702
- });
1703
- }
1704
- },
1705
-
1706
- pollContent: function() {
1707
- var cm = this.cm, display = cm.display, sel = cm.doc.sel.primary();
1708
- var from = sel.from(), to = sel.to();
1709
- if (from.line < display.viewFrom || to.line > display.viewTo - 1) return false;
1710
-
1711
- var fromIndex;
1712
- if (from.line == display.viewFrom || (fromIndex = findViewIndex(cm, from.line)) == 0) {
1713
- var fromLine = lineNo(display.view[0].line);
1714
- var fromNode = display.view[0].node;
1715
- } else {
1716
- var fromLine = lineNo(display.view[fromIndex].line);
1717
- var fromNode = display.view[fromIndex - 1].node.nextSibling;
1718
- }
1719
- var toIndex = findViewIndex(cm, to.line);
1720
- if (toIndex == display.view.length - 1) {
1721
- var toLine = display.viewTo - 1;
1722
- var toNode = display.view[toIndex].node;
1723
- } else {
1724
- var toLine = lineNo(display.view[toIndex + 1].line) - 1;
1725
- var toNode = display.view[toIndex + 1].node.previousSibling;
1726
- }
1727
-
1728
- var newText = splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine));
1729
- var oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length));
1730
- while (newText.length > 1 && oldText.length > 1) {
1731
- if (lst(newText) == lst(oldText)) { newText.pop(); oldText.pop(); toLine--; }
1732
- else if (newText[0] == oldText[0]) { newText.shift(); oldText.shift(); fromLine++; }
1733
- else break;
1734
- }
1735
-
1736
- var cutFront = 0, cutEnd = 0;
1737
- var newTop = newText[0], oldTop = oldText[0], maxCutFront = Math.min(newTop.length, oldTop.length);
1738
- while (cutFront < maxCutFront && newTop.charCodeAt(cutFront) == oldTop.charCodeAt(cutFront))
1739
- ++cutFront;
1740
- var newBot = lst(newText), oldBot = lst(oldText);
1741
- var maxCutEnd = Math.min(newBot.length - (newText.length == 1 ? cutFront : 0),
1742
- oldBot.length - (oldText.length == 1 ? cutFront : 0));
1743
- while (cutEnd < maxCutEnd &&
1744
- newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1))
1745
- ++cutEnd;
1746
-
1747
- newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd);
1748
- newText[0] = newText[0].slice(cutFront);
1749
-
1750
- var chFrom = Pos(fromLine, cutFront);
1751
- var chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0);
1752
- if (newText.length > 1 || newText[0] || cmp(chFrom, chTo)) {
1753
- replaceRange(cm.doc, newText, chFrom, chTo, "+input");
1754
- return true;
1755
- }
1756
- },
1757
-
1758
- ensurePolled: function() {
1759
- this.forceCompositionEnd();
1760
- },
1761
- reset: function() {
1762
- this.forceCompositionEnd();
1763
- },
1764
- forceCompositionEnd: function() {
1765
- if (!this.composing || this.composing.handled) return;
1766
- this.applyComposition(this.composing);
1767
- this.composing.handled = true;
1768
- this.div.blur();
1769
- this.div.focus();
1770
- },
1771
- applyComposition: function(composing) {
1772
- if (composing.data && composing.data != composing.startData)
1773
- operation(this.cm, applyTextInput)(this.cm, composing.data, 0, composing.sel);
1774
- },
1775
-
1776
- setUneditable: function(node) {
1777
- node.setAttribute("contenteditable", "false");
1778
- },
1779
-
1780
- onKeyPress: function(e) {
1781
- e.preventDefault();
1782
- operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0);
1783
- },
1784
-
1785
- onContextMenu: nothing,
1786
- resetPosition: nothing,
1787
-
1788
- needsContentAttribute: true
1789
- }, ContentEditableInput.prototype);
1790
-
1791
- function posToDOM(cm, pos) {
1792
- var view = findViewForLine(cm, pos.line);
1793
- if (!view || view.hidden) return null;
1794
- var line = getLine(cm.doc, pos.line);
1795
- var info = mapFromLineView(view, line, pos.line);
1796
-
1797
- var order = getOrder(line), side = "left";
1798
- if (order) {
1799
- var partPos = getBidiPartAt(order, pos.ch);
1800
- side = partPos % 2 ? "right" : "left";
1801
- }
1802
- var result = nodeAndOffsetInLineMap(info.map, pos.ch, "left");
1803
- result.offset = result.collapse == "right" ? result.end : result.start;
1804
- return result;
1805
- }
1806
-
1807
- function badPos(pos, bad) { if (bad) pos.bad = true; return pos; }
1808
-
1809
- function domToPos(cm, node, offset) {
1810
- var lineNode;
1811
- if (node == cm.display.lineDiv) {
1812
- lineNode = cm.display.lineDiv.childNodes[offset];
1813
- if (!lineNode) return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true);
1814
- node = null; offset = 0;
1815
- } else {
1816
- for (lineNode = node;; lineNode = lineNode.parentNode) {
1817
- if (!lineNode || lineNode == cm.display.lineDiv) return null;
1818
- if (lineNode.parentNode && lineNode.parentNode == cm.display.lineDiv) break;
1819
- }
1820
- }
1821
- for (var i = 0; i < cm.display.view.length; i++) {
1822
- var lineView = cm.display.view[i];
1823
- if (lineView.node == lineNode)
1824
- return locateNodeInLineView(lineView, node, offset);
1825
- }
1826
- }
1827
-
1828
- function locateNodeInLineView(lineView, node, offset) {
1829
- var wrapper = lineView.text.firstChild, bad = false;
1830
- if (!node || !contains(wrapper, node)) return badPos(Pos(lineNo(lineView.line), 0), true);
1831
- if (node == wrapper) {
1832
- bad = true;
1833
- node = wrapper.childNodes[offset];
1834
- offset = 0;
1835
- if (!node) {
1836
- var line = lineView.rest ? lst(lineView.rest) : lineView.line;
1837
- return badPos(Pos(lineNo(line), line.text.length), bad);
1838
- }
1839
- }
1840
-
1841
- var textNode = node.nodeType == 3 ? node : null, topNode = node;
1842
- if (!textNode && node.childNodes.length == 1 && node.firstChild.nodeType == 3) {
1843
- textNode = node.firstChild;
1844
- if (offset) offset = textNode.nodeValue.length;
1845
- }
1846
- while (topNode.parentNode != wrapper) topNode = topNode.parentNode;
1847
- var measure = lineView.measure, maps = measure.maps;
1848
-
1849
- function find(textNode, topNode, offset) {
1850
- for (var i = -1; i < (maps ? maps.length : 0); i++) {
1851
- var map = i < 0 ? measure.map : maps[i];
1852
- for (var j = 0; j < map.length; j += 3) {
1853
- var curNode = map[j + 2];
1854
- if (curNode == textNode || curNode == topNode) {
1855
- var line = lineNo(i < 0 ? lineView.line : lineView.rest[i]);
1856
- var ch = map[j] + offset;
1857
- if (offset < 0 || curNode != textNode) ch = map[j + (offset ? 1 : 0)];
1858
- return Pos(line, ch);
1859
- }
1860
- }
1861
- }
1862
- }
1863
- var found = find(textNode, topNode, offset);
1864
- if (found) return badPos(found, bad);
1865
-
1866
- // FIXME this is all really shaky. might handle the few cases it needs to handle, but likely to cause problems
1867
- for (var after = topNode.nextSibling, dist = textNode ? textNode.nodeValue.length - offset : 0; after; after = after.nextSibling) {
1868
- found = find(after, after.firstChild, 0);
1869
- if (found)
1870
- return badPos(Pos(found.line, found.ch - dist), bad);
1871
- else
1872
- dist += after.textContent.length;
1873
- }
1874
- for (var before = topNode.previousSibling, dist = offset; before; before = before.previousSibling) {
1875
- found = find(before, before.firstChild, -1);
1876
- if (found)
1877
- return badPos(Pos(found.line, found.ch + dist), bad);
1878
- else
1879
- dist += after.textContent.length;
1880
- }
1881
- }
1882
-
1883
- function domTextBetween(cm, from, to, fromLine, toLine) {
1884
- var text = "", closing = false;
1885
- function recognizeMarker(id) { return function(marker) { return marker.id == id; }; }
1886
- function walk(node) {
1887
- if (node.nodeType == 1) {
1888
- var cmText = node.getAttribute("cm-text");
1889
- if (cmText != null) {
1890
- if (cmText == "") cmText = node.textContent.replace(/\u200b/g, "");
1891
- text += cmText;
1892
- return;
1893
- }
1894
- var markerID = node.getAttribute("cm-marker"), range;
1895
- if (markerID) {
1896
- var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID));
1897
- if (found.length && (range = found[0].find()))
1898
- text += getBetween(cm.doc, range.from, range.to).join("\n");
1899
- return;
1900
- }
1901
- if (node.getAttribute("contenteditable") == "false") return;
1902
- for (var i = 0; i < node.childNodes.length; i++)
1903
- walk(node.childNodes[i]);
1904
- if (/^(pre|div|p)$/i.test(node.nodeName))
1905
- closing = true;
1906
- } else if (node.nodeType == 3) {
1907
- var val = node.nodeValue;
1908
- if (!val) return;
1909
- if (closing) {
1910
- text += "\n";
1911
- closing = false;
1912
- }
1913
- text += val;
1914
- }
1915
- }
1916
- for (;;) {
1917
- walk(from);
1918
- if (from == to) break;
1919
- from = from.nextSibling;
1920
- }
1921
- return text;
1922
- }
1923
-
1924
- CodeMirror.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput};
1925
-
1926
- // SELECTION / CURSOR
1927
-
1928
- // Selection objects are immutable. A new one is created every time
1929
- // the selection changes. A selection is one or more non-overlapping
1930
- // (and non-touching) ranges, sorted, and an integer that indicates
1931
- // which one is the primary selection (the one that's scrolled into
1932
- // view, that getCursor returns, etc).
1933
- function Selection(ranges, primIndex) {
1934
- this.ranges = ranges;
1935
- this.primIndex = primIndex;
1936
- }
1937
-
1938
- Selection.prototype = {
1939
- primary: function() { return this.ranges[this.primIndex]; },
1940
- equals: function(other) {
1941
- if (other == this) return true;
1942
- if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) return false;
1943
- for (var i = 0; i < this.ranges.length; i++) {
1944
- var here = this.ranges[i], there = other.ranges[i];
1945
- if (cmp(here.anchor, there.anchor) != 0 || cmp(here.head, there.head) != 0) return false;
1946
- }
1947
- return true;
1948
- },
1949
- deepCopy: function() {
1950
- for (var out = [], i = 0; i < this.ranges.length; i++)
1951
- out[i] = new Range(copyPos(this.ranges[i].anchor), copyPos(this.ranges[i].head));
1952
- return new Selection(out, this.primIndex);
1953
- },
1954
- somethingSelected: function() {
1955
- for (var i = 0; i < this.ranges.length; i++)
1956
- if (!this.ranges[i].empty()) return true;
1957
- return false;
1958
- },
1959
- contains: function(pos, end) {
1960
- if (!end) end = pos;
1961
- for (var i = 0; i < this.ranges.length; i++) {
1962
- var range = this.ranges[i];
1963
- if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0)
1964
- return i;
1965
- }
1966
- return -1;
1967
- }
1968
- };
1969
-
1970
- function Range(anchor, head) {
1971
- this.anchor = anchor; this.head = head;
1972
- }
1973
-
1974
- Range.prototype = {
1975
- from: function() { return minPos(this.anchor, this.head); },
1976
- to: function() { return maxPos(this.anchor, this.head); },
1977
- empty: function() {
1978
- return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch;
1979
- }
1980
- };
1981
-
1982
- // Take an unsorted, potentially overlapping set of ranges, and
1983
- // build a selection out of it. 'Consumes' ranges array (modifying
1984
- // it).
1985
- function normalizeSelection(ranges, primIndex) {
1986
- var prim = ranges[primIndex];
1987
- ranges.sort(function(a, b) { return cmp(a.from(), b.from()); });
1988
- primIndex = indexOf(ranges, prim);
1989
- for (var i = 1; i < ranges.length; i++) {
1990
- var cur = ranges[i], prev = ranges[i - 1];
1991
- if (cmp(prev.to(), cur.from()) >= 0) {
1992
- var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to());
1993
- var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head;
1994
- if (i <= primIndex) --primIndex;
1995
- ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to));
1996
- }
1997
- }
1998
- return new Selection(ranges, primIndex);
1999
- }
2000
-
2001
- function simpleSelection(anchor, head) {
2002
- return new Selection([new Range(anchor, head || anchor)], 0);
2003
- }
2004
-
2005
- // Most of the external API clips given positions to make sure they
2006
- // actually exist within the document.
2007
- function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1));}
2008
- function clipPos(doc, pos) {
2009
- if (pos.line < doc.first) return Pos(doc.first, 0);
2010
- var last = doc.first + doc.size - 1;
2011
- if (pos.line > last) return Pos(last, getLine(doc, last).text.length);
2012
- return clipToLen(pos, getLine(doc, pos.line).text.length);
2013
- }
2014
- function clipToLen(pos, linelen) {
2015
- var ch = pos.ch;
2016
- if (ch == null || ch > linelen) return Pos(pos.line, linelen);
2017
- else if (ch < 0) return Pos(pos.line, 0);
2018
- else return pos;
2019
- }
2020
- function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size;}
2021
- function clipPosArray(doc, array) {
2022
- for (var out = [], i = 0; i < array.length; i++) out[i] = clipPos(doc, array[i]);
2023
- return out;
2024
- }
2025
-
2026
- // SELECTION UPDATES
2027
-
2028
- // The 'scroll' parameter given to many of these indicated whether
2029
- // the new cursor position should be scrolled into view after
2030
- // modifying the selection.
2031
-
2032
- // If shift is held or the extend flag is set, extends a range to
2033
- // include a given position (and optionally a second position).
2034
- // Otherwise, simply returns the range between the given positions.
2035
- // Used for cursor motion and such.
2036
- function extendRange(doc, range, head, other) {
2037
- if (doc.cm && doc.cm.display.shift || doc.extend) {
2038
- var anchor = range.anchor;
2039
- if (other) {
2040
- var posBefore = cmp(head, anchor) < 0;
2041
- if (posBefore != (cmp(other, anchor) < 0)) {
2042
- anchor = head;
2043
- head = other;
2044
- } else if (posBefore != (cmp(head, other) < 0)) {
2045
- head = other;
2046
- }
2047
- }
2048
- return new Range(anchor, head);
2049
- } else {
2050
- return new Range(other || head, head);
2051
- }
2052
- }
2053
-
2054
- // Extend the primary selection range, discard the rest.
2055
- function extendSelection(doc, head, other, options) {
2056
- setSelection(doc, new Selection([extendRange(doc, doc.sel.primary(), head, other)], 0), options);
2057
- }
2058
-
2059
- // Extend all selections (pos is an array of selections with length
2060
- // equal the number of selections)
2061
- function extendSelections(doc, heads, options) {
2062
- for (var out = [], i = 0; i < doc.sel.ranges.length; i++)
2063
- out[i] = extendRange(doc, doc.sel.ranges[i], heads[i], null);
2064
- var newSel = normalizeSelection(out, doc.sel.primIndex);
2065
- setSelection(doc, newSel, options);
2066
- }
2067
-
2068
- // Updates a single range in the selection.
2069
- function replaceOneSelection(doc, i, range, options) {
2070
- var ranges = doc.sel.ranges.slice(0);
2071
- ranges[i] = range;
2072
- setSelection(doc, normalizeSelection(ranges, doc.sel.primIndex), options);
2073
- }
2074
-
2075
- // Reset the selection to a single range.
2076
- function setSimpleSelection(doc, anchor, head, options) {
2077
- setSelection(doc, simpleSelection(anchor, head), options);
2078
- }
2079
-
2080
- // Give beforeSelectionChange handlers a change to influence a
2081
- // selection update.
2082
- function filterSelectionChange(doc, sel) {
2083
- var obj = {
2084
- ranges: sel.ranges,
2085
- update: function(ranges) {
2086
- this.ranges = [];
2087
- for (var i = 0; i < ranges.length; i++)
2088
- this.ranges[i] = new Range(clipPos(doc, ranges[i].anchor),
2089
- clipPos(doc, ranges[i].head));
2090
- }
2091
- };
2092
- signal(doc, "beforeSelectionChange", doc, obj);
2093
- if (doc.cm) signal(doc.cm, "beforeSelectionChange", doc.cm, obj);
2094
- if (obj.ranges != sel.ranges) return normalizeSelection(obj.ranges, obj.ranges.length - 1);
2095
- else return sel;
2096
- }
2097
-
2098
- function setSelectionReplaceHistory(doc, sel, options) {
2099
- var done = doc.history.done, last = lst(done);
2100
- if (last && last.ranges) {
2101
- done[done.length - 1] = sel;
2102
- setSelectionNoUndo(doc, sel, options);
2103
- } else {
2104
- setSelection(doc, sel, options);
2105
- }
2106
- }
2107
-
2108
- // Set a new selection.
2109
- function setSelection(doc, sel, options) {
2110
- setSelectionNoUndo(doc, sel, options);
2111
- addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options);
2112
- }
2113
-
2114
- function setSelectionNoUndo(doc, sel, options) {
2115
- if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange"))
2116
- sel = filterSelectionChange(doc, sel);
2117
-
2118
- var bias = options && options.bias ||
2119
- (cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1);
2120
- setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true));
2121
-
2122
- if (!(options && options.scroll === false) && doc.cm)
2123
- ensureCursorVisible(doc.cm);
2124
- }
2125
-
2126
- function setSelectionInner(doc, sel) {
2127
- if (sel.equals(doc.sel)) return;
2128
-
2129
- doc.sel = sel;
2130
-
2131
- if (doc.cm) {
2132
- doc.cm.curOp.updateInput = doc.cm.curOp.selectionChanged = true;
2133
- signalCursorActivity(doc.cm);
2134
- }
2135
- signalLater(doc, "cursorActivity", doc);
2136
- }
2137
-
2138
- // Verify that the selection does not partially select any atomic
2139
- // marked ranges.
2140
- function reCheckSelection(doc) {
2141
- setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false), sel_dontScroll);
2142
- }
2143
-
2144
- // Return a selection that does not partially select any atomic
2145
- // ranges.
2146
- function skipAtomicInSelection(doc, sel, bias, mayClear) {
2147
- var out;
2148
- for (var i = 0; i < sel.ranges.length; i++) {
2149
- var range = sel.ranges[i];
2150
- var newAnchor = skipAtomic(doc, range.anchor, bias, mayClear);
2151
- var newHead = skipAtomic(doc, range.head, bias, mayClear);
2152
- if (out || newAnchor != range.anchor || newHead != range.head) {
2153
- if (!out) out = sel.ranges.slice(0, i);
2154
- out[i] = new Range(newAnchor, newHead);
2155
- }
2156
- }
2157
- return out ? normalizeSelection(out, sel.primIndex) : sel;
2158
- }
2159
-
2160
- // Ensure a given position is not inside an atomic range.
2161
- function skipAtomic(doc, pos, bias, mayClear) {
2162
- var flipped = false, curPos = pos;
2163
- var dir = bias || 1;
2164
- doc.cantEdit = false;
2165
- search: for (;;) {
2166
- var line = getLine(doc, curPos.line);
2167
- if (line.markedSpans) {
2168
- for (var i = 0; i < line.markedSpans.length; ++i) {
2169
- var sp = line.markedSpans[i], m = sp.marker;
2170
- if ((sp.from == null || (m.inclusiveLeft ? sp.from <= curPos.ch : sp.from < curPos.ch)) &&
2171
- (sp.to == null || (m.inclusiveRight ? sp.to >= curPos.ch : sp.to > curPos.ch))) {
2172
- if (mayClear) {
2173
- signal(m, "beforeCursorEnter");
2174
- if (m.explicitlyCleared) {
2175
- if (!line.markedSpans) break;
2176
- else {--i; continue;}
2177
- }
2178
- }
2179
- if (!m.atomic) continue;
2180
- var newPos = m.find(dir < 0 ? -1 : 1);
2181
- if (cmp(newPos, curPos) == 0) {
2182
- newPos.ch += dir;
2183
- if (newPos.ch < 0) {
2184
- if (newPos.line > doc.first) newPos = clipPos(doc, Pos(newPos.line - 1));
2185
- else newPos = null;
2186
- } else if (newPos.ch > line.text.length) {
2187
- if (newPos.line < doc.first + doc.size - 1) newPos = Pos(newPos.line + 1, 0);
2188
- else newPos = null;
2189
- }
2190
- if (!newPos) {
2191
- if (flipped) {
2192
- // Driven in a corner -- no valid cursor position found at all
2193
- // -- try again *with* clearing, if we didn't already
2194
- if (!mayClear) return skipAtomic(doc, pos, bias, true);
2195
- // Otherwise, turn off editing until further notice, and return the start of the doc
2196
- doc.cantEdit = true;
2197
- return Pos(doc.first, 0);
2198
- }
2199
- flipped = true; newPos = pos; dir = -dir;
2200
- }
2201
- }
2202
- curPos = newPos;
2203
- continue search;
2204
- }
2205
- }
2206
- }
2207
- return curPos;
2208
- }
2209
- }
2210
-
2211
- // SELECTION DRAWING
2212
-
2213
- function updateSelection(cm) {
2214
- cm.display.input.showSelection(cm.display.input.prepareSelection());
2215
- }
2216
-
2217
- function prepareSelection(cm, primary) {
2218
- var doc = cm.doc, result = {};
2219
- var curFragment = result.cursors = document.createDocumentFragment();
2220
- var selFragment = result.selection = document.createDocumentFragment();
2221
-
2222
- for (var i = 0; i < doc.sel.ranges.length; i++) {
2223
- if (primary === false && i == doc.sel.primIndex) continue;
2224
- var range = doc.sel.ranges[i];
2225
- var collapsed = range.empty();
2226
- if (collapsed || cm.options.showCursorWhenSelecting)
2227
- drawSelectionCursor(cm, range, curFragment);
2228
- if (!collapsed)
2229
- drawSelectionRange(cm, range, selFragment);
2230
- }
2231
- return result;
2232
- }
2233
-
2234
- // Draws a cursor for the given range
2235
- function drawSelectionCursor(cm, range, output) {
2236
- var pos = cursorCoords(cm, range.head, "div", null, null, !cm.options.singleCursorHeightPerLine);
2237
-
2238
- var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"));
2239
- cursor.style.left = pos.left + "px";
2240
- cursor.style.top = pos.top + "px";
2241
- cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
2242
-
2243
- if (pos.other) {
2244
- // Secondary cursor, shown when on a 'jump' in bi-directional text
2245
- var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"));
2246
- otherCursor.style.display = "";
2247
- otherCursor.style.left = pos.other.left + "px";
2248
- otherCursor.style.top = pos.other.top + "px";
2249
- otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px";
2250
- }
2251
- }
2252
-
2253
- // Draws the given range as a highlighted selection
2254
- function drawSelectionRange(cm, range, output) {
2255
- var display = cm.display, doc = cm.doc;
2256
- var fragment = document.createDocumentFragment();
2257
- var padding = paddingH(cm.display), leftSide = padding.left;
2258
- var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right;
2259
-
2260
- function add(left, top, width, bottom) {
2261
- if (top < 0) top = 0;
2262
- top = Math.round(top);
2263
- bottom = Math.round(bottom);
2264
- fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left +
2265
- "px; top: " + top + "px; width: " + (width == null ? rightSide - left : width) +
2266
- "px; height: " + (bottom - top) + "px"));
2267
- }
2268
-
2269
- function drawForLine(line, fromArg, toArg) {
2270
- var lineObj = getLine(doc, line);
2271
- var lineLen = lineObj.text.length;
2272
- var start, end;
2273
- function coords(ch, bias) {
2274
- return charCoords(cm, Pos(line, ch), "div", lineObj, bias);
2275
- }
2276
-
2277
- iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) {
2278
- var leftPos = coords(from, "left"), rightPos, left, right;
2279
- if (from == to) {
2280
- rightPos = leftPos;
2281
- left = right = leftPos.left;
2282
- } else {
2283
- rightPos = coords(to - 1, "right");
2284
- if (dir == "rtl") { var tmp = leftPos; leftPos = rightPos; rightPos = tmp; }
2285
- left = leftPos.left;
2286
- right = rightPos.right;
2287
- }
2288
- if (fromArg == null && from == 0) left = leftSide;
2289
- if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
2290
- add(left, leftPos.top, null, leftPos.bottom);
2291
- left = leftSide;
2292
- if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top);
2293
- }
2294
- if (toArg == null && to == lineLen) right = rightSide;
2295
- if (!start || leftPos.top < start.top || leftPos.top == start.top && leftPos.left < start.left)
2296
- start = leftPos;
2297
- if (!end || rightPos.bottom > end.bottom || rightPos.bottom == end.bottom && rightPos.right > end.right)
2298
- end = rightPos;
2299
- if (left < leftSide + 1) left = leftSide;
2300
- add(left, rightPos.top, right - left, rightPos.bottom);
2301
- });
2302
- return {start: start, end: end};
2303
- }
2304
-
2305
- var sFrom = range.from(), sTo = range.to();
2306
- if (sFrom.line == sTo.line) {
2307
- drawForLine(sFrom.line, sFrom.ch, sTo.ch);
2308
- } else {
2309
- var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line);
2310
- var singleVLine = visualLine(fromLine) == visualLine(toLine);
2311
- var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end;
2312
- var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start;
2313
- if (singleVLine) {
2314
- if (leftEnd.top < rightStart.top - 2) {
2315
- add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
2316
- add(leftSide, rightStart.top, rightStart.left, rightStart.bottom);
2317
- } else {
2318
- add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
2319
- }
2320
- }
2321
- if (leftEnd.bottom < rightStart.top)
2322
- add(leftSide, leftEnd.bottom, null, rightStart.top);
2323
- }
2324
-
2325
- output.appendChild(fragment);
2326
- }
2327
-
2328
- // Cursor-blinking
2329
- function restartBlink(cm) {
2330
- if (!cm.state.focused) return;
2331
- var display = cm.display;
2332
- clearInterval(display.blinker);
2333
- var on = true;
2334
- display.cursorDiv.style.visibility = "";
2335
- if (cm.options.cursorBlinkRate > 0)
2336
- display.blinker = setInterval(function() {
2337
- display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden";
2338
- }, cm.options.cursorBlinkRate);
2339
- else if (cm.options.cursorBlinkRate < 0)
2340
- display.cursorDiv.style.visibility = "hidden";
2341
- }
2342
-
2343
- // HIGHLIGHT WORKER
2344
-
2345
- function startWorker(cm, time) {
2346
- if (cm.doc.mode.startState && cm.doc.frontier < cm.display.viewTo)
2347
- cm.state.highlight.set(time, bind(highlightWorker, cm));
2348
- }
2349
-
2350
- function highlightWorker(cm) {
2351
- var doc = cm.doc;
2352
- if (doc.frontier < doc.first) doc.frontier = doc.first;
2353
- if (doc.frontier >= cm.display.viewTo) return;
2354
- var end = +new Date + cm.options.workTime;
2355
- var state = copyState(doc.mode, getStateBefore(cm, doc.frontier));
2356
- var changedLines = [];
2357
-
2358
- doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function(line) {
2359
- if (doc.frontier >= cm.display.viewFrom) { // Visible
2360
- var oldStyles = line.styles;
2361
- var highlighted = highlightLine(cm, line, state, true);
2362
- line.styles = highlighted.styles;
2363
- var oldCls = line.styleClasses, newCls = highlighted.classes;
2364
- if (newCls) line.styleClasses = newCls;
2365
- else if (oldCls) line.styleClasses = null;
2366
- var ischange = !oldStyles || oldStyles.length != line.styles.length ||
2367
- oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass);
2368
- for (var i = 0; !ischange && i < oldStyles.length; ++i) ischange = oldStyles[i] != line.styles[i];
2369
- if (ischange) changedLines.push(doc.frontier);
2370
- line.stateAfter = copyState(doc.mode, state);
2371
- } else {
2372
- processLine(cm, line.text, state);
2373
- line.stateAfter = doc.frontier % 5 == 0 ? copyState(doc.mode, state) : null;
2374
- }
2375
- ++doc.frontier;
2376
- if (+new Date > end) {
2377
- startWorker(cm, cm.options.workDelay);
2378
- return true;
2379
- }
2380
- });
2381
- if (changedLines.length) runInOp(cm, function() {
2382
- for (var i = 0; i < changedLines.length; i++)
2383
- regLineChange(cm, changedLines[i], "text");
2384
- });
2385
- }
2386
-
2387
- // Finds the line to start with when starting a parse. Tries to
2388
- // find a line with a stateAfter, so that it can start with a
2389
- // valid state. If that fails, it returns the line with the
2390
- // smallest indentation, which tends to need the least context to
2391
- // parse correctly.
2392
- function findStartLine(cm, n, precise) {
2393
- var minindent, minline, doc = cm.doc;
2394
- var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100);
2395
- for (var search = n; search > lim; --search) {
2396
- if (search <= doc.first) return doc.first;
2397
- var line = getLine(doc, search - 1);
2398
- if (line.stateAfter && (!precise || search <= doc.frontier)) return search;
2399
- var indented = countColumn(line.text, null, cm.options.tabSize);
2400
- if (minline == null || minindent > indented) {
2401
- minline = search - 1;
2402
- minindent = indented;
2403
- }
2404
- }
2405
- return minline;
2406
- }
2407
-
2408
- function getStateBefore(cm, n, precise) {
2409
- var doc = cm.doc, display = cm.display;
2410
- if (!doc.mode.startState) return true;
2411
- var pos = findStartLine(cm, n, precise), state = pos > doc.first && getLine(doc, pos-1).stateAfter;
2412
- if (!state) state = startState(doc.mode);
2413
- else state = copyState(doc.mode, state);
2414
- doc.iter(pos, n, function(line) {
2415
- processLine(cm, line.text, state);
2416
- var save = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo;
2417
- line.stateAfter = save ? copyState(doc.mode, state) : null;
2418
- ++pos;
2419
- });
2420
- if (precise) doc.frontier = pos;
2421
- return state;
2422
- }
2423
-
2424
- // POSITION MEASUREMENT
2425
-
2426
- function paddingTop(display) {return display.lineSpace.offsetTop;}
2427
- function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight;}
2428
- function paddingH(display) {
2429
- if (display.cachedPaddingH) return display.cachedPaddingH;
2430
- var e = removeChildrenAndAdd(display.measure, elt("pre", "x"));
2431
- var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle;
2432
- var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)};
2433
- if (!isNaN(data.left) && !isNaN(data.right)) display.cachedPaddingH = data;
2434
- return data;
2435
- }
2436
-
2437
- function scrollGap(cm) { return scrollerGap - cm.display.nativeBarWidth; }
2438
- function displayWidth(cm) {
2439
- return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth;
2440
- }
2441
- function displayHeight(cm) {
2442
- return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight;
2443
- }
2444
-
2445
- // Ensure the lineView.wrapping.heights array is populated. This is
2446
- // an array of bottom offsets for the lines that make up a drawn
2447
- // line. When lineWrapping is on, there might be more than one
2448
- // height.
2449
- function ensureLineHeights(cm, lineView, rect) {
2450
- var wrapping = cm.options.lineWrapping;
2451
- var curWidth = wrapping && displayWidth(cm);
2452
- if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
2453
- var heights = lineView.measure.heights = [];
2454
- if (wrapping) {
2455
- lineView.measure.width = curWidth;
2456
- var rects = lineView.text.firstChild.getClientRects();
2457
- for (var i = 0; i < rects.length - 1; i++) {
2458
- var cur = rects[i], next = rects[i + 1];
2459
- if (Math.abs(cur.bottom - next.bottom) > 2)
2460
- heights.push((cur.bottom + next.top) / 2 - rect.top);
2461
- }
2462
- }
2463
- heights.push(rect.bottom - rect.top);
2464
- }
2465
- }
2466
-
2467
- // Find a line map (mapping character offsets to text nodes) and a
2468
- // measurement cache for the given line number. (A line view might
2469
- // contain multiple lines when collapsed ranges are present.)
2470
- function mapFromLineView(lineView, line, lineN) {
2471
- if (lineView.line == line)
2472
- return {map: lineView.measure.map, cache: lineView.measure.cache};
2473
- for (var i = 0; i < lineView.rest.length; i++)
2474
- if (lineView.rest[i] == line)
2475
- return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i]};
2476
- for (var i = 0; i < lineView.rest.length; i++)
2477
- if (lineNo(lineView.rest[i]) > lineN)
2478
- return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i], before: true};
2479
- }
2480
-
2481
- // Render a line into the hidden node display.externalMeasured. Used
2482
- // when measurement is needed for a line that's not in the viewport.
2483
- function updateExternalMeasurement(cm, line) {
2484
- line = visualLine(line);
2485
- var lineN = lineNo(line);
2486
- var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN);
2487
- view.lineN = lineN;
2488
- var built = view.built = buildLineContent(cm, view);
2489
- view.text = built.pre;
2490
- removeChildrenAndAdd(cm.display.lineMeasure, built.pre);
2491
- return view;
2492
- }
2493
-
2494
- // Get a {top, bottom, left, right} box (in line-local coordinates)
2495
- // for a given character.
2496
- function measureChar(cm, line, ch, bias) {
2497
- return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias);
2498
- }
2499
-
2500
- // Find a line view that corresponds to the given line number.
2501
- function findViewForLine(cm, lineN) {
2502
- if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo)
2503
- return cm.display.view[findViewIndex(cm, lineN)];
2504
- var ext = cm.display.externalMeasured;
2505
- if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size)
2506
- return ext;
2507
- }
2508
-
2509
- // Measurement can be split in two steps, the set-up work that
2510
- // applies to the whole line, and the measurement of the actual
2511
- // character. Functions like coordsChar, that need to do a lot of
2512
- // measurements in a row, can thus ensure that the set-up work is
2513
- // only done once.
2514
- function prepareMeasureForLine(cm, line) {
2515
- var lineN = lineNo(line);
2516
- var view = findViewForLine(cm, lineN);
2517
- if (view && !view.text)
2518
- view = null;
2519
- else if (view && view.changes)
2520
- updateLineForChanges(cm, view, lineN, getDimensions(cm));
2521
- if (!view)
2522
- view = updateExternalMeasurement(cm, line);
2523
-
2524
- var info = mapFromLineView(view, line, lineN);
2525
- return {
2526
- line: line, view: view, rect: null,
2527
- map: info.map, cache: info.cache, before: info.before,
2528
- hasHeights: false
2529
- };
2530
- }
2531
-
2532
- // Given a prepared measurement object, measures the position of an
2533
- // actual character (or fetches it from the cache).
2534
- function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
2535
- if (prepared.before) ch = -1;
2536
- var key = ch + (bias || ""), found;
2537
- if (prepared.cache.hasOwnProperty(key)) {
2538
- found = prepared.cache[key];
2539
- } else {
2540
- if (!prepared.rect)
2541
- prepared.rect = prepared.view.text.getBoundingClientRect();
2542
- if (!prepared.hasHeights) {
2543
- ensureLineHeights(cm, prepared.view, prepared.rect);
2544
- prepared.hasHeights = true;
2545
- }
2546
- found = measureCharInner(cm, prepared, ch, bias);
2547
- if (!found.bogus) prepared.cache[key] = found;
2548
- }
2549
- return {left: found.left, right: found.right,
2550
- top: varHeight ? found.rtop : found.top,
2551
- bottom: varHeight ? found.rbottom : found.bottom};
2552
- }
2553
-
2554
- var nullRect = {left: 0, right: 0, top: 0, bottom: 0};
2555
-
2556
- function nodeAndOffsetInLineMap(map, ch, bias) {
2557
- var node, start, end, collapse;
2558
- // First, search the line map for the text node corresponding to,
2559
- // or closest to, the target character.
2560
- for (var i = 0; i < map.length; i += 3) {
2561
- var mStart = map[i], mEnd = map[i + 1];
2562
- if (ch < mStart) {
2563
- start = 0; end = 1;
2564
- collapse = "left";
2565
- } else if (ch < mEnd) {
2566
- start = ch - mStart;
2567
- end = start + 1;
2568
- } else if (i == map.length - 3 || ch == mEnd && map[i + 3] > ch) {
2569
- end = mEnd - mStart;
2570
- start = end - 1;
2571
- if (ch >= mEnd) collapse = "right";
2572
- }
2573
- if (start != null) {
2574
- node = map[i + 2];
2575
- if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
2576
- collapse = bias;
2577
- if (bias == "left" && start == 0)
2578
- while (i && map[i - 2] == map[i - 3] && map[i - 1].insertLeft) {
2579
- node = map[(i -= 3) + 2];
2580
- collapse = "left";
2581
- }
2582
- if (bias == "right" && start == mEnd - mStart)
2583
- while (i < map.length - 3 && map[i + 3] == map[i + 4] && !map[i + 5].insertLeft) {
2584
- node = map[(i += 3) + 2];
2585
- collapse = "right";
2586
- }
2587
- break;
2588
- }
2589
- }
2590
- return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd};
2591
- }
2592
-
2593
- function measureCharInner(cm, prepared, ch, bias) {
2594
- var place = nodeAndOffsetInLineMap(prepared.map, ch, bias);
2595
- var node = place.node, start = place.start, end = place.end, collapse = place.collapse;
2596
-
2597
- var rect;
2598
- if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates.
2599
- for (var i = 0; i < 4; i++) { // Retry a maximum of 4 times when nonsense rectangles are returned
2600
- while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) --start;
2601
- while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) ++end;
2602
- if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart) {
2603
- rect = node.parentNode.getBoundingClientRect();
2604
- } else if (ie && cm.options.lineWrapping) {
2605
- var rects = range(node, start, end).getClientRects();
2606
- if (rects.length)
2607
- rect = rects[bias == "right" ? rects.length - 1 : 0];
2608
- else
2609
- rect = nullRect;
2610
- } else {
2611
- rect = range(node, start, end).getBoundingClientRect() || nullRect;
2612
- }
2613
- if (rect.left || rect.right || start == 0) break;
2614
- end = start;
2615
- start = start - 1;
2616
- collapse = "right";
2617
- }
2618
- if (ie && ie_version < 11) rect = maybeUpdateRectForZooming(cm.display.measure, rect);
2619
- } else { // If it is a widget, simply get the box for the whole widget.
2620
- if (start > 0) collapse = bias = "right";
2621
- var rects;
2622
- if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1)
2623
- rect = rects[bias == "right" ? rects.length - 1 : 0];
2624
- else
2625
- rect = node.getBoundingClientRect();
2626
- }
2627
- if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
2628
- var rSpan = node.parentNode.getClientRects()[0];
2629
- if (rSpan)
2630
- rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom};
2631
- else
2632
- rect = nullRect;
2633
- }
2634
-
2635
- var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top;
2636
- var mid = (rtop + rbot) / 2;
2637
- var heights = prepared.view.measure.heights;
2638
- for (var i = 0; i < heights.length - 1; i++)
2639
- if (mid < heights[i]) break;
2640
- var top = i ? heights[i - 1] : 0, bot = heights[i];
2641
- var result = {left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left,
2642
- right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left,
2643
- top: top, bottom: bot};
2644
- if (!rect.left && !rect.right) result.bogus = true;
2645
- if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot; }
2646
-
2647
- return result;
2648
- }
2649
-
2650
- // Work around problem with bounding client rects on ranges being
2651
- // returned incorrectly when zoomed on IE10 and below.
2652
- function maybeUpdateRectForZooming(measure, rect) {
2653
- if (!window.screen || screen.logicalXDPI == null ||
2654
- screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure))
2655
- return rect;
2656
- var scaleX = screen.logicalXDPI / screen.deviceXDPI;
2657
- var scaleY = screen.logicalYDPI / screen.deviceYDPI;
2658
- return {left: rect.left * scaleX, right: rect.right * scaleX,
2659
- top: rect.top * scaleY, bottom: rect.bottom * scaleY};
2660
- }
2661
-
2662
- function clearLineMeasurementCacheFor(lineView) {
2663
- if (lineView.measure) {
2664
- lineView.measure.cache = {};
2665
- lineView.measure.heights = null;
2666
- if (lineView.rest) for (var i = 0; i < lineView.rest.length; i++)
2667
- lineView.measure.caches[i] = {};
2668
- }
2669
- }
2670
-
2671
- function clearLineMeasurementCache(cm) {
2672
- cm.display.externalMeasure = null;
2673
- removeChildren(cm.display.lineMeasure);
2674
- for (var i = 0; i < cm.display.view.length; i++)
2675
- clearLineMeasurementCacheFor(cm.display.view[i]);
2676
- }
2677
-
2678
- function clearCaches(cm) {
2679
- clearLineMeasurementCache(cm);
2680
- cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null;
2681
- if (!cm.options.lineWrapping) cm.display.maxLineChanged = true;
2682
- cm.display.lineNumChars = null;
2683
- }
2684
-
2685
- function pageScrollX() { return window.pageXOffset || (document.documentElement || document.body).scrollLeft; }
2686
- function pageScrollY() { return window.pageYOffset || (document.documentElement || document.body).scrollTop; }
2687
-
2688
- // Converts a {top, bottom, left, right} box from line-local
2689
- // coordinates into another coordinate system. Context may be one of
2690
- // "line", "div" (display.lineDiv), "local"/null (editor), "window",
2691
- // or "page".
2692
- function intoCoordSystem(cm, lineObj, rect, context) {
2693
- if (lineObj.widgets) for (var i = 0; i < lineObj.widgets.length; ++i) if (lineObj.widgets[i].above) {
2694
- var size = widgetHeight(lineObj.widgets[i]);
2695
- rect.top += size; rect.bottom += size;
2696
- }
2697
- if (context == "line") return rect;
2698
- if (!context) context = "local";
2699
- var yOff = heightAtLine(lineObj);
2700
- if (context == "local") yOff += paddingTop(cm.display);
2701
- else yOff -= cm.display.viewOffset;
2702
- if (context == "page" || context == "window") {
2703
- var lOff = cm.display.lineSpace.getBoundingClientRect();
2704
- yOff += lOff.top + (context == "window" ? 0 : pageScrollY());
2705
- var xOff = lOff.left + (context == "window" ? 0 : pageScrollX());
2706
- rect.left += xOff; rect.right += xOff;
2707
- }
2708
- rect.top += yOff; rect.bottom += yOff;
2709
- return rect;
2710
- }
2711
-
2712
- // Coverts a box from "div" coords to another coordinate system.
2713
- // Context may be "window", "page", "div", or "local"/null.
2714
- function fromCoordSystem(cm, coords, context) {
2715
- if (context == "div") return coords;
2716
- var left = coords.left, top = coords.top;
2717
- // First move into "page" coordinate system
2718
- if (context == "page") {
2719
- left -= pageScrollX();
2720
- top -= pageScrollY();
2721
- } else if (context == "local" || !context) {
2722
- var localBox = cm.display.sizer.getBoundingClientRect();
2723
- left += localBox.left;
2724
- top += localBox.top;
2725
- }
2726
-
2727
- var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect();
2728
- return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top};
2729
- }
2730
-
2731
- function charCoords(cm, pos, context, lineObj, bias) {
2732
- if (!lineObj) lineObj = getLine(cm.doc, pos.line);
2733
- return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context);
2734
- }
2735
-
2736
- // Returns a box for a given cursor position, which may have an
2737
- // 'other' property containing the position of the secondary cursor
2738
- // on a bidi boundary.
2739
- function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
2740
- lineObj = lineObj || getLine(cm.doc, pos.line);
2741
- if (!preparedMeasure) preparedMeasure = prepareMeasureForLine(cm, lineObj);
2742
- function get(ch, right) {
2743
- var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight);
2744
- if (right) m.left = m.right; else m.right = m.left;
2745
- return intoCoordSystem(cm, lineObj, m, context);
2746
- }
2747
- function getBidi(ch, partPos) {
2748
- var part = order[partPos], right = part.level % 2;
2749
- if (ch == bidiLeft(part) && partPos && part.level < order[partPos - 1].level) {
2750
- part = order[--partPos];
2751
- ch = bidiRight(part) - (part.level % 2 ? 0 : 1);
2752
- right = true;
2753
- } else if (ch == bidiRight(part) && partPos < order.length - 1 && part.level < order[partPos + 1].level) {
2754
- part = order[++partPos];
2755
- ch = bidiLeft(part) - part.level % 2;
2756
- right = false;
2757
- }
2758
- if (right && ch == part.to && ch > part.from) return get(ch - 1);
2759
- return get(ch, right);
2760
- }
2761
- var order = getOrder(lineObj), ch = pos.ch;
2762
- if (!order) return get(ch);
2763
- var partPos = getBidiPartAt(order, ch);
2764
- var val = getBidi(ch, partPos);
2765
- if (bidiOther != null) val.other = getBidi(ch, bidiOther);
2766
- return val;
2767
- }
2768
-
2769
- // Used to cheaply estimate the coordinates for a position. Used for
2770
- // intermediate scroll updates.
2771
- function estimateCoords(cm, pos) {
2772
- var left = 0, pos = clipPos(cm.doc, pos);
2773
- if (!cm.options.lineWrapping) left = charWidth(cm.display) * pos.ch;
2774
- var lineObj = getLine(cm.doc, pos.line);
2775
- var top = heightAtLine(lineObj) + paddingTop(cm.display);
2776
- return {left: left, right: left, top: top, bottom: top + lineObj.height};
2777
- }
2778
-
2779
- // Positions returned by coordsChar contain some extra information.
2780
- // xRel is the relative x position of the input coordinates compared
2781
- // to the found position (so xRel > 0 means the coordinates are to
2782
- // the right of the character position, for example). When outside
2783
- // is true, that means the coordinates lie outside the line's
2784
- // vertical range.
2785
- function PosWithInfo(line, ch, outside, xRel) {
2786
- var pos = Pos(line, ch);
2787
- pos.xRel = xRel;
2788
- if (outside) pos.outside = true;
2789
- return pos;
2790
- }
2791
-
2792
- // Compute the character position closest to the given coordinates.
2793
- // Input must be lineSpace-local ("div" coordinate system).
2794
- function coordsChar(cm, x, y) {
2795
- var doc = cm.doc;
2796
- y += cm.display.viewOffset;
2797
- if (y < 0) return PosWithInfo(doc.first, 0, true, -1);
2798
- var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1;
2799
- if (lineN > last)
2800
- return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, true, 1);
2801
- if (x < 0) x = 0;
2802
-
2803
- var lineObj = getLine(doc, lineN);
2804
- for (;;) {
2805
- var found = coordsCharInner(cm, lineObj, lineN, x, y);
2806
- var merged = collapsedSpanAtEnd(lineObj);
2807
- var mergedPos = merged && merged.find(0, true);
2808
- if (merged && (found.ch > mergedPos.from.ch || found.ch == mergedPos.from.ch && found.xRel > 0))
2809
- lineN = lineNo(lineObj = mergedPos.to.line);
2810
- else
2811
- return found;
2812
- }
2813
- }
2814
-
2815
- function coordsCharInner(cm, lineObj, lineNo, x, y) {
2816
- var innerOff = y - heightAtLine(lineObj);
2817
- var wrongLine = false, adjust = 2 * cm.display.wrapper.clientWidth;
2818
- var preparedMeasure = prepareMeasureForLine(cm, lineObj);
2819
-
2820
- function getX(ch) {
2821
- var sp = cursorCoords(cm, Pos(lineNo, ch), "line", lineObj, preparedMeasure);
2822
- wrongLine = true;
2823
- if (innerOff > sp.bottom) return sp.left - adjust;
2824
- else if (innerOff < sp.top) return sp.left + adjust;
2825
- else wrongLine = false;
2826
- return sp.left;
2827
- }
2828
-
2829
- var bidi = getOrder(lineObj), dist = lineObj.text.length;
2830
- var from = lineLeft(lineObj), to = lineRight(lineObj);
2831
- var fromX = getX(from), fromOutside = wrongLine, toX = getX(to), toOutside = wrongLine;
2832
-
2833
- if (x > toX) return PosWithInfo(lineNo, to, toOutside, 1);
2834
- // Do a binary search between these bounds.
2835
- for (;;) {
2836
- if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) {
2837
- var ch = x < fromX || x - fromX <= toX - x ? from : to;
2838
- var xDiff = x - (ch == from ? fromX : toX);
2839
- while (isExtendingChar(lineObj.text.charAt(ch))) ++ch;
2840
- var pos = PosWithInfo(lineNo, ch, ch == from ? fromOutside : toOutside,
2841
- xDiff < -1 ? -1 : xDiff > 1 ? 1 : 0);
2842
- return pos;
2843
- }
2844
- var step = Math.ceil(dist / 2), middle = from + step;
2845
- if (bidi) {
2846
- middle = from;
2847
- for (var i = 0; i < step; ++i) middle = moveVisually(lineObj, middle, 1);
2848
- }
2849
- var middleX = getX(middle);
2850
- if (middleX > x) {to = middle; toX = middleX; if (toOutside = wrongLine) toX += 1000; dist = step;}
2851
- else {from = middle; fromX = middleX; fromOutside = wrongLine; dist -= step;}
2852
- }
2853
- }
2854
-
2855
- var measureText;
2856
- // Compute the default text height.
2857
- function textHeight(display) {
2858
- if (display.cachedTextHeight != null) return display.cachedTextHeight;
2859
- if (measureText == null) {
2860
- measureText = elt("pre");
2861
- // Measure a bunch of lines, for browsers that compute
2862
- // fractional heights.
2863
- for (var i = 0; i < 49; ++i) {
2864
- measureText.appendChild(document.createTextNode("x"));
2865
- measureText.appendChild(elt("br"));
2866
- }
2867
- measureText.appendChild(document.createTextNode("x"));
2868
- }
2869
- removeChildrenAndAdd(display.measure, measureText);
2870
- var height = measureText.offsetHeight / 50;
2871
- if (height > 3) display.cachedTextHeight = height;
2872
- removeChildren(display.measure);
2873
- return height || 1;
2874
- }
2875
-
2876
- // Compute the default character width.
2877
- function charWidth(display) {
2878
- if (display.cachedCharWidth != null) return display.cachedCharWidth;
2879
- var anchor = elt("span", "xxxxxxxxxx");
2880
- var pre = elt("pre", [anchor]);
2881
- removeChildrenAndAdd(display.measure, pre);
2882
- var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10;
2883
- if (width > 2) display.cachedCharWidth = width;
2884
- return width || 10;
2885
- }
2886
-
2887
- // OPERATIONS
2888
-
2889
- // Operations are used to wrap a series of changes to the editor
2890
- // state in such a way that each change won't have to update the
2891
- // cursor and display (which would be awkward, slow, and
2892
- // error-prone). Instead, display updates are batched and then all
2893
- // combined and executed at once.
2894
-
2895
- var operationGroup = null;
2896
-
2897
- var nextOpId = 0;
2898
- // Start a new operation.
2899
- function startOperation(cm) {
2900
- cm.curOp = {
2901
- cm: cm,
2902
- viewChanged: false, // Flag that indicates that lines might need to be redrawn
2903
- startHeight: cm.doc.height, // Used to detect need to update scrollbar
2904
- forceUpdate: false, // Used to force a redraw
2905
- updateInput: null, // Whether to reset the input textarea
2906
- typing: false, // Whether this reset should be careful to leave existing text (for compositing)
2907
- changeObjs: null, // Accumulated changes, for firing change events
2908
- cursorActivityHandlers: null, // Set of handlers to fire cursorActivity on
2909
- cursorActivityCalled: 0, // Tracks which cursorActivity handlers have been called already
2910
- selectionChanged: false, // Whether the selection needs to be redrawn
2911
- updateMaxLine: false, // Set when the widest line needs to be determined anew
2912
- scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet
2913
- scrollToPos: null, // Used to scroll to a specific position
2914
- id: ++nextOpId // Unique ID
2915
- };
2916
- if (operationGroup) {
2917
- operationGroup.ops.push(cm.curOp);
2918
- } else {
2919
- cm.curOp.ownsGroup = operationGroup = {
2920
- ops: [cm.curOp],
2921
- delayedCallbacks: []
2922
- };
2923
- }
2924
- }
2925
-
2926
- function fireCallbacksForOps(group) {
2927
- // Calls delayed callbacks and cursorActivity handlers until no
2928
- // new ones appear
2929
- var callbacks = group.delayedCallbacks, i = 0;
2930
- do {
2931
- for (; i < callbacks.length; i++)
2932
- callbacks[i]();
2933
- for (var j = 0; j < group.ops.length; j++) {
2934
- var op = group.ops[j];
2935
- if (op.cursorActivityHandlers)
2936
- while (op.cursorActivityCalled < op.cursorActivityHandlers.length)
2937
- op.cursorActivityHandlers[op.cursorActivityCalled++](op.cm);
2938
- }
2939
- } while (i < callbacks.length);
2940
- }
2941
-
2942
- // Finish an operation, updating the display and signalling delayed events
2943
- function endOperation(cm) {
2944
- var op = cm.curOp, group = op.ownsGroup;
2945
- if (!group) return;
2946
-
2947
- try { fireCallbacksForOps(group); }
2948
- finally {
2949
- operationGroup = null;
2950
- for (var i = 0; i < group.ops.length; i++)
2951
- group.ops[i].cm.curOp = null;
2952
- endOperations(group);
2953
- }
2954
- }
2955
-
2956
- // The DOM updates done when an operation finishes are batched so
2957
- // that the minimum number of relayouts are required.
2958
- function endOperations(group) {
2959
- var ops = group.ops;
2960
- for (var i = 0; i < ops.length; i++) // Read DOM
2961
- endOperation_R1(ops[i]);
2962
- for (var i = 0; i < ops.length; i++) // Write DOM (maybe)
2963
- endOperation_W1(ops[i]);
2964
- for (var i = 0; i < ops.length; i++) // Read DOM
2965
- endOperation_R2(ops[i]);
2966
- for (var i = 0; i < ops.length; i++) // Write DOM (maybe)
2967
- endOperation_W2(ops[i]);
2968
- for (var i = 0; i < ops.length; i++) // Read DOM
2969
- endOperation_finish(ops[i]);
2970
- }
2971
-
2972
- function endOperation_R1(op) {
2973
- var cm = op.cm, display = cm.display;
2974
- maybeClipScrollbars(cm);
2975
- if (op.updateMaxLine) findMaxLine(cm);
2976
-
2977
- op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null ||
2978
- op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom ||
2979
- op.scrollToPos.to.line >= display.viewTo) ||
2980
- display.maxLineChanged && cm.options.lineWrapping;
2981
- op.update = op.mustUpdate &&
2982
- new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate);
2983
- }
2984
-
2985
- function endOperation_W1(op) {
2986
- op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update);
2987
- }
2988
-
2989
- function endOperation_R2(op) {
2990
- var cm = op.cm, display = cm.display;
2991
- if (op.updatedDisplay) updateHeightsInViewport(cm);
2992
-
2993
- op.barMeasure = measureForScrollbars(cm);
2994
-
2995
- // If the max line changed since it was last measured, measure it,
2996
- // and ensure the document's width matches it.
2997
- // updateDisplay_W2 will use these properties to do the actual resizing
2998
- if (display.maxLineChanged && !cm.options.lineWrapping) {
2999
- op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3;
3000
- cm.display.sizerWidth = op.adjustWidthTo;
3001
- op.barMeasure.scrollWidth =
3002
- Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth);
3003
- op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm));
3004
- }
3005
-
3006
- if (op.updatedDisplay || op.selectionChanged)
3007
- op.preparedSelection = display.input.prepareSelection();
3008
- }
3009
-
3010
- function endOperation_W2(op) {
3011
- var cm = op.cm;
3012
-
3013
- if (op.adjustWidthTo != null) {
3014
- cm.display.sizer.style.minWidth = op.adjustWidthTo + "px";
3015
- if (op.maxScrollLeft < cm.doc.scrollLeft)
3016
- setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true);
3017
- cm.display.maxLineChanged = false;
3018
- }
3019
-
3020
- if (op.preparedSelection)
3021
- cm.display.input.showSelection(op.preparedSelection);
3022
- if (op.updatedDisplay)
3023
- setDocumentHeight(cm, op.barMeasure);
3024
- if (op.updatedDisplay || op.startHeight != cm.doc.height)
3025
- updateScrollbars(cm, op.barMeasure);
3026
-
3027
- if (op.selectionChanged) restartBlink(cm);
3028
-
3029
- if (cm.state.focused && op.updateInput)
3030
- cm.display.input.reset(op.typing);
3031
- }
3032
-
3033
- function endOperation_finish(op) {
3034
- var cm = op.cm, display = cm.display, doc = cm.doc;
3035
-
3036
- if (op.updatedDisplay) postUpdateDisplay(cm, op.update);
3037
-
3038
- // Abort mouse wheel delta measurement, when scrolling explicitly
3039
- if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos))
3040
- display.wheelStartX = display.wheelStartY = null;
3041
-
3042
- // Propagate the scroll position to the actual DOM scroller
3043
- if (op.scrollTop != null && (display.scroller.scrollTop != op.scrollTop || op.forceScroll)) {
3044
- doc.scrollTop = Math.max(0, Math.min(display.scroller.scrollHeight - display.scroller.clientHeight, op.scrollTop));
3045
- display.scrollbars.setScrollTop(doc.scrollTop);
3046
- display.scroller.scrollTop = doc.scrollTop;
3047
- }
3048
- if (op.scrollLeft != null && (display.scroller.scrollLeft != op.scrollLeft || op.forceScroll)) {
3049
- doc.scrollLeft = Math.max(0, Math.min(display.scroller.scrollWidth - displayWidth(cm), op.scrollLeft));
3050
- display.scrollbars.setScrollLeft(doc.scrollLeft);
3051
- display.scroller.scrollLeft = doc.scrollLeft;
3052
- alignHorizontally(cm);
3053
- }
3054
- // If we need to scroll a specific position into view, do so.
3055
- if (op.scrollToPos) {
3056
- var coords = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
3057
- clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin);
3058
- if (op.scrollToPos.isCursor && cm.state.focused) maybeScrollWindow(cm, coords);
3059
- }
3060
-
3061
- // Fire events for markers that are hidden/unidden by editing or
3062
- // undoing
3063
- var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers;
3064
- if (hidden) for (var i = 0; i < hidden.length; ++i)
3065
- if (!hidden[i].lines.length) signal(hidden[i], "hide");
3066
- if (unhidden) for (var i = 0; i < unhidden.length; ++i)
3067
- if (unhidden[i].lines.length) signal(unhidden[i], "unhide");
3068
-
3069
- if (display.wrapper.offsetHeight)
3070
- doc.scrollTop = cm.display.scroller.scrollTop;
3071
-
3072
- // Fire change events, and delayed event handlers
3073
- if (op.changeObjs)
3074
- signal(cm, "changes", cm, op.changeObjs);
3075
- if (op.update)
3076
- op.update.finish();
3077
- }
3078
-
3079
- // Run the given function in an operation
3080
- function runInOp(cm, f) {
3081
- if (cm.curOp) return f();
3082
- startOperation(cm);
3083
- try { return f(); }
3084
- finally { endOperation(cm); }
3085
- }
3086
- // Wraps a function in an operation. Returns the wrapped function.
3087
- function operation(cm, f) {
3088
- return function() {
3089
- if (cm.curOp) return f.apply(cm, arguments);
3090
- startOperation(cm);
3091
- try { return f.apply(cm, arguments); }
3092
- finally { endOperation(cm); }
3093
- };
3094
- }
3095
- // Used to add methods to editor and doc instances, wrapping them in
3096
- // operations.
3097
- function methodOp(f) {
3098
- return function() {
3099
- if (this.curOp) return f.apply(this, arguments);
3100
- startOperation(this);
3101
- try { return f.apply(this, arguments); }
3102
- finally { endOperation(this); }
3103
- };
3104
- }
3105
- function docMethodOp(f) {
3106
- return function() {
3107
- var cm = this.cm;
3108
- if (!cm || cm.curOp) return f.apply(this, arguments);
3109
- startOperation(cm);
3110
- try { return f.apply(this, arguments); }
3111
- finally { endOperation(cm); }
3112
- };
3113
- }
3114
-
3115
- // VIEW TRACKING
3116
-
3117
- // These objects are used to represent the visible (currently drawn)
3118
- // part of the document. A LineView may correspond to multiple
3119
- // logical lines, if those are connected by collapsed ranges.
3120
- function LineView(doc, line, lineN) {
3121
- // The starting line
3122
- this.line = line;
3123
- // Continuing lines, if any
3124
- this.rest = visualLineContinued(line);
3125
- // Number of logical lines in this visual line
3126
- this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1;
3127
- this.node = this.text = null;
3128
- this.hidden = lineIsHidden(doc, line);
3129
- }
3130
-
3131
- // Create a range of LineView objects for the given lines.
3132
- function buildViewArray(cm, from, to) {
3133
- var array = [], nextPos;
3134
- for (var pos = from; pos < to; pos = nextPos) {
3135
- var view = new LineView(cm.doc, getLine(cm.doc, pos), pos);
3136
- nextPos = pos + view.size;
3137
- array.push(view);
3138
- }
3139
- return array;
3140
- }
3141
-
3142
- // Updates the display.view data structure for a given change to the
3143
- // document. From and to are in pre-change coordinates. Lendiff is
3144
- // the amount of lines added or subtracted by the change. This is
3145
- // used for changes that span multiple lines, or change the way
3146
- // lines are divided into visual lines. regLineChange (below)
3147
- // registers single-line changes.
3148
- function regChange(cm, from, to, lendiff) {
3149
- if (from == null) from = cm.doc.first;
3150
- if (to == null) to = cm.doc.first + cm.doc.size;
3151
- if (!lendiff) lendiff = 0;
3152
-
3153
- var display = cm.display;
3154
- if (lendiff && to < display.viewTo &&
3155
- (display.updateLineNumbers == null || display.updateLineNumbers > from))
3156
- display.updateLineNumbers = from;
3157
-
3158
- cm.curOp.viewChanged = true;
3159
-
3160
- if (from >= display.viewTo) { // Change after
3161
- if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo)
3162
- resetView(cm);
3163
- } else if (to <= display.viewFrom) { // Change before
3164
- if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
3165
- resetView(cm);
3166
- } else {
3167
- display.viewFrom += lendiff;
3168
- display.viewTo += lendiff;
3169
- }
3170
- } else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap
3171
- resetView(cm);
3172
- } else if (from <= display.viewFrom) { // Top overlap
3173
- var cut = viewCuttingPoint(cm, to, to + lendiff, 1);
3174
- if (cut) {
3175
- display.view = display.view.slice(cut.index);
3176
- display.viewFrom = cut.lineN;
3177
- display.viewTo += lendiff;
3178
- } else {
3179
- resetView(cm);
3180
- }
3181
- } else if (to >= display.viewTo) { // Bottom overlap
3182
- var cut = viewCuttingPoint(cm, from, from, -1);
3183
- if (cut) {
3184
- display.view = display.view.slice(0, cut.index);
3185
- display.viewTo = cut.lineN;
3186
- } else {
3187
- resetView(cm);
3188
- }
3189
- } else { // Gap in the middle
3190
- var cutTop = viewCuttingPoint(cm, from, from, -1);
3191
- var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1);
3192
- if (cutTop && cutBot) {
3193
- display.view = display.view.slice(0, cutTop.index)
3194
- .concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
3195
- .concat(display.view.slice(cutBot.index));
3196
- display.viewTo += lendiff;
3197
- } else {
3198
- resetView(cm);
3199
- }
3200
- }
3201
-
3202
- var ext = display.externalMeasured;
3203
- if (ext) {
3204
- if (to < ext.lineN)
3205
- ext.lineN += lendiff;
3206
- else if (from < ext.lineN + ext.size)
3207
- display.externalMeasured = null;
3208
- }
3209
- }
3210
-
3211
- // Register a change to a single line. Type must be one of "text",
3212
- // "gutter", "class", "widget"
3213
- function regLineChange(cm, line, type) {
3214
- cm.curOp.viewChanged = true;
3215
- var display = cm.display, ext = cm.display.externalMeasured;
3216
- if (ext && line >= ext.lineN && line < ext.lineN + ext.size)
3217
- display.externalMeasured = null;
3218
-
3219
- if (line < display.viewFrom || line >= display.viewTo) return;
3220
- var lineView = display.view[findViewIndex(cm, line)];
3221
- if (lineView.node == null) return;
3222
- var arr = lineView.changes || (lineView.changes = []);
3223
- if (indexOf(arr, type) == -1) arr.push(type);
3224
- }
3225
-
3226
- // Clear the view.
3227
- function resetView(cm) {
3228
- cm.display.viewFrom = cm.display.viewTo = cm.doc.first;
3229
- cm.display.view = [];
3230
- cm.display.viewOffset = 0;
3231
- }
3232
-
3233
- // Find the view element corresponding to a given line. Return null
3234
- // when the line isn't visible.
3235
- function findViewIndex(cm, n) {
3236
- if (n >= cm.display.viewTo) return null;
3237
- n -= cm.display.viewFrom;
3238
- if (n < 0) return null;
3239
- var view = cm.display.view;
3240
- for (var i = 0; i < view.length; i++) {
3241
- n -= view[i].size;
3242
- if (n < 0) return i;
3243
- }
3244
- }
3245
-
3246
- function viewCuttingPoint(cm, oldN, newN, dir) {
3247
- var index = findViewIndex(cm, oldN), diff, view = cm.display.view;
3248
- if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
3249
- return {index: index, lineN: newN};
3250
- for (var i = 0, n = cm.display.viewFrom; i < index; i++)
3251
- n += view[i].size;
3252
- if (n != oldN) {
3253
- if (dir > 0) {
3254
- if (index == view.length - 1) return null;
3255
- diff = (n + view[index].size) - oldN;
3256
- index++;
3257
- } else {
3258
- diff = n - oldN;
3259
- }
3260
- oldN += diff; newN += diff;
3261
- }
3262
- while (visualLineNo(cm.doc, newN) != newN) {
3263
- if (index == (dir < 0 ? 0 : view.length - 1)) return null;
3264
- newN += dir * view[index - (dir < 0 ? 1 : 0)].size;
3265
- index += dir;
3266
- }
3267
- return {index: index, lineN: newN};
3268
- }
3269
-
3270
- // Force the view to cover a given range, adding empty view element
3271
- // or clipping off existing ones as needed.
3272
- function adjustView(cm, from, to) {
3273
- var display = cm.display, view = display.view;
3274
- if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
3275
- display.view = buildViewArray(cm, from, to);
3276
- display.viewFrom = from;
3277
- } else {
3278
- if (display.viewFrom > from)
3279
- display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view);
3280
- else if (display.viewFrom < from)
3281
- display.view = display.view.slice(findViewIndex(cm, from));
3282
- display.viewFrom = from;
3283
- if (display.viewTo < to)
3284
- display.view = display.view.concat(buildViewArray(cm, display.viewTo, to));
3285
- else if (display.viewTo > to)
3286
- display.view = display.view.slice(0, findViewIndex(cm, to));
3287
- }
3288
- display.viewTo = to;
3289
- }
3290
-
3291
- // Count the number of lines in the view whose DOM representation is
3292
- // out of date (or nonexistent).
3293
- function countDirtyView(cm) {
3294
- var view = cm.display.view, dirty = 0;
3295
- for (var i = 0; i < view.length; i++) {
3296
- var lineView = view[i];
3297
- if (!lineView.hidden && (!lineView.node || lineView.changes)) ++dirty;
3298
- }
3299
- return dirty;
3300
- }
3301
-
3302
- // EVENT HANDLERS
3303
-
3304
- // Attach the necessary event handlers when initializing the editor
3305
- function registerEventHandlers(cm) {
3306
- var d = cm.display;
3307
- on(d.scroller, "mousedown", operation(cm, onMouseDown));
3308
- // Older IE's will not fire a second mousedown for a double click
3309
- if (ie && ie_version < 11)
3310
- on(d.scroller, "dblclick", operation(cm, function(e) {
3311
- if (signalDOMEvent(cm, e)) return;
3312
- var pos = posFromMouse(cm, e);
3313
- if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) return;
3314
- e_preventDefault(e);
3315
- var word = cm.findWordAt(pos);
3316
- extendSelection(cm.doc, word.anchor, word.head);
3317
- }));
3318
- else
3319
- on(d.scroller, "dblclick", function(e) { signalDOMEvent(cm, e) || e_preventDefault(e); });
3320
- // Some browsers fire contextmenu *after* opening the menu, at
3321
- // which point we can't mess with it anymore. Context menu is
3322
- // handled in onMouseDown for these browsers.
3323
- if (!captureRightClick) on(d.scroller, "contextmenu", function(e) {onContextMenu(cm, e);});
3324
-
3325
- // Used to suppress mouse event handling when a touch happens
3326
- var touchFinished, prevTouch = {end: 0};
3327
- function finishTouch() {
3328
- if (d.activeTouch) {
3329
- touchFinished = setTimeout(function() {d.activeTouch = null;}, 1000);
3330
- prevTouch = d.activeTouch;
3331
- prevTouch.end = +new Date;
3332
- }
3333
- };
3334
- function isMouseLikeTouchEvent(e) {
3335
- if (e.touches.length != 1) return false;
3336
- var touch = e.touches[0];
3337
- return touch.radiusX <= 1 && touch.radiusY <= 1;
3338
- }
3339
- function farAway(touch, other) {
3340
- if (other.left == null) return true;
3341
- var dx = other.left - touch.left, dy = other.top - touch.top;
3342
- return dx * dx + dy * dy > 20 * 20;
3343
- }
3344
- on(d.scroller, "touchstart", function(e) {
3345
- if (!isMouseLikeTouchEvent(e)) {
3346
- clearTimeout(touchFinished);
3347
- var now = +new Date;
3348
- d.activeTouch = {start: now, moved: false,
3349
- prev: now - prevTouch.end <= 300 ? prevTouch : null};
3350
- if (e.touches.length == 1) {
3351
- d.activeTouch.left = e.touches[0].pageX;
3352
- d.activeTouch.top = e.touches[0].pageY;
3353
- }
3354
- }
3355
- });
3356
- on(d.scroller, "touchmove", function() {
3357
- if (d.activeTouch) d.activeTouch.moved = true;
3358
- });
3359
- on(d.scroller, "touchend", function(e) {
3360
- var touch = d.activeTouch;
3361
- if (touch && !eventInWidget(d, e) && touch.left != null &&
3362
- !touch.moved && new Date - touch.start < 300) {
3363
- var pos = cm.coordsChar(d.activeTouch, "page"), range;
3364
- if (!touch.prev || farAway(touch, touch.prev)) // Single tap
3365
- range = new Range(pos, pos);
3366
- else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap
3367
- range = cm.findWordAt(pos);
3368
- else // Triple tap
3369
- range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0)));
3370
- cm.setSelection(range.anchor, range.head);
3371
- cm.focus();
3372
- e_preventDefault(e);
3373
- }
3374
- finishTouch();
3375
- });
3376
- on(d.scroller, "touchcancel", finishTouch);
3377
-
3378
- // Sync scrolling between fake scrollbars and real scrollable
3379
- // area, ensure viewport is updated when scrolling.
3380
- on(d.scroller, "scroll", function() {
3381
- if (d.scroller.clientHeight) {
3382
- setScrollTop(cm, d.scroller.scrollTop);
3383
- setScrollLeft(cm, d.scroller.scrollLeft, true);
3384
- signal(cm, "scroll", cm);
3385
- }
3386
- });
3387
-
3388
- // Listen to wheel events in order to try and update the viewport on time.
3389
- on(d.scroller, "mousewheel", function(e){onScrollWheel(cm, e);});
3390
- on(d.scroller, "DOMMouseScroll", function(e){onScrollWheel(cm, e);});
3391
-
3392
- // Prevent wrapper from ever scrolling
3393
- on(d.wrapper, "scroll", function() { d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; });
3394
-
3395
- function drag_(e) {
3396
- if (!signalDOMEvent(cm, e)) e_stop(e);
3397
- }
3398
- if (cm.options.dragDrop) {
3399
- on(d.scroller, "dragstart", function(e){onDragStart(cm, e);});
3400
- on(d.scroller, "dragenter", drag_);
3401
- on(d.scroller, "dragover", drag_);
3402
- on(d.scroller, "drop", operation(cm, onDrop));
3403
- }
3404
-
3405
- var inp = d.input.getField();
3406
- on(inp, "keyup", function(e) { onKeyUp.call(cm, e); });
3407
- on(inp, "keydown", operation(cm, onKeyDown));
3408
- on(inp, "keypress", operation(cm, onKeyPress));
3409
- on(inp, "focus", bind(onFocus, cm));
3410
- on(inp, "blur", bind(onBlur, cm));
3411
- }
3412
-
3413
- // Called when the window resizes
3414
- function onResize(cm) {
3415
- var d = cm.display;
3416
- if (d.lastWrapHeight == d.wrapper.clientHeight && d.lastWrapWidth == d.wrapper.clientWidth)
3417
- return;
3418
- // Might be a text scaling operation, clear size caches.
3419
- d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
3420
- d.scrollbarsClipped = false;
3421
- cm.setSize();
3422
- }
3423
-
3424
- // MOUSE EVENTS
3425
-
3426
- // Return true when the given mouse event happened in a widget
3427
- function eventInWidget(display, e) {
3428
- for (var n = e_target(e); n != display.wrapper; n = n.parentNode) {
3429
- if (!n || (n.nodeType == 1 && n.getAttribute("cm-ignore-events") == "true") ||
3430
- (n.parentNode == display.sizer && n != display.mover))
3431
- return true;
3432
- }
3433
- }
3434
-
3435
- // Given a mouse event, find the corresponding position. If liberal
3436
- // is false, it checks whether a gutter or scrollbar was clicked,
3437
- // and returns null if it was. forRect is used by rectangular
3438
- // selections, and tries to estimate a character position even for
3439
- // coordinates beyond the right of the text.
3440
- function posFromMouse(cm, e, liberal, forRect) {
3441
- var display = cm.display;
3442
- if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") return null;
3443
-
3444
- var x, y, space = display.lineSpace.getBoundingClientRect();
3445
- // Fails unpredictably on IE[67] when mouse is dragged around quickly.
3446
- try { x = e.clientX - space.left; y = e.clientY - space.top; }
3447
- catch (e) { return null; }
3448
- var coords = coordsChar(cm, x, y), line;
3449
- if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
3450
- var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;
3451
- coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff));
3452
- }
3453
- return coords;
3454
- }
3455
-
3456
- // A mouse down can be a single click, double click, triple click,
3457
- // start of selection drag, start of text drag, new cursor
3458
- // (ctrl-click), rectangle drag (alt-drag), or xwin
3459
- // middle-click-paste. Or it might be a click on something we should
3460
- // not interfere with, such as a scrollbar or widget.
3461
- function onMouseDown(e) {
3462
- var cm = this, display = cm.display;
3463
- if (display.activeTouch && display.input.supportsTouch() || signalDOMEvent(cm, e)) return;
3464
- display.shift = e.shiftKey;
3465
-
3466
- if (eventInWidget(display, e)) {
3467
- if (!webkit) {
3468
- // Briefly turn off draggability, to allow widgets to do
3469
- // normal dragging things.
3470
- display.scroller.draggable = false;
3471
- setTimeout(function(){display.scroller.draggable = true;}, 100);
3472
- }
3473
- return;
3474
- }
3475
- if (clickInGutter(cm, e)) return;
3476
- var start = posFromMouse(cm, e);
3477
- window.focus();
3478
-
3479
- switch (e_button(e)) {
3480
- case 1:
3481
- if (start)
3482
- leftButtonDown(cm, e, start);
3483
- else if (e_target(e) == display.scroller)
3484
- e_preventDefault(e);
3485
- break;
3486
- case 2:
3487
- if (webkit) cm.state.lastMiddleDown = +new Date;
3488
- if (start) extendSelection(cm.doc, start);
3489
- setTimeout(function() {display.input.focus();}, 20);
3490
- e_preventDefault(e);
3491
- break;
3492
- case 3:
3493
- if (captureRightClick) onContextMenu(cm, e);
3494
- break;
3495
- }
3496
- }
3497
-
3498
- var lastClick, lastDoubleClick;
3499
- function leftButtonDown(cm, e, start) {
3500
- if (ie) setTimeout(bind(ensureFocus, cm), 0);
3501
- else ensureFocus(cm);
3502
-
3503
- var now = +new Date, type;
3504
- if (lastDoubleClick && lastDoubleClick.time > now - 400 && cmp(lastDoubleClick.pos, start) == 0) {
3505
- type = "triple";
3506
- } else if (lastClick && lastClick.time > now - 400 && cmp(lastClick.pos, start) == 0) {
3507
- type = "double";
3508
- lastDoubleClick = {time: now, pos: start};
3509
- } else {
3510
- type = "single";
3511
- lastClick = {time: now, pos: start};
3512
- }
3513
-
3514
- var sel = cm.doc.sel, modifier = mac ? e.metaKey : e.ctrlKey, contained;
3515
- if (cm.options.dragDrop && dragAndDrop && !isReadOnly(cm) &&
3516
- type == "single" && (contained = sel.contains(start)) > -1 &&
3517
- !sel.ranges[contained].empty())
3518
- leftButtonStartDrag(cm, e, start, modifier);
3519
- else
3520
- leftButtonSelect(cm, e, start, type, modifier);
3521
- }
3522
-
3523
- // Start a text drag. When it ends, see if any dragging actually
3524
- // happen, and treat as a click if it didn't.
3525
- function leftButtonStartDrag(cm, e, start, modifier) {
3526
- var display = cm.display;
3527
- var dragEnd = operation(cm, function(e2) {
3528
- if (webkit) display.scroller.draggable = false;
3529
- cm.state.draggingText = false;
3530
- off(document, "mouseup", dragEnd);
3531
- off(display.scroller, "drop", dragEnd);
3532
- if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) {
3533
- e_preventDefault(e2);
3534
- if (!modifier)
3535
- extendSelection(cm.doc, start);
3536
- // Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
3537
- if (webkit || ie && ie_version == 9)
3538
- setTimeout(function() {document.body.focus(); display.input.focus();}, 20);
3539
- else
3540
- display.input.focus();
3541
- }
3542
- });
3543
- // Let the drag handler handle this.
3544
- if (webkit) display.scroller.draggable = true;
3545
- cm.state.draggingText = dragEnd;
3546
- // IE's approach to draggable
3547
- if (display.scroller.dragDrop) display.scroller.dragDrop();
3548
- on(document, "mouseup", dragEnd);
3549
- on(display.scroller, "drop", dragEnd);
3550
- }
3551
-
3552
- // Normal selection, as opposed to text dragging.
3553
- function leftButtonSelect(cm, e, start, type, addNew) {
3554
- var display = cm.display, doc = cm.doc;
3555
- e_preventDefault(e);
3556
-
3557
- var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges;
3558
- if (addNew && !e.shiftKey) {
3559
- ourIndex = doc.sel.contains(start);
3560
- if (ourIndex > -1)
3561
- ourRange = ranges[ourIndex];
3562
- else
3563
- ourRange = new Range(start, start);
3564
- } else {
3565
- ourRange = doc.sel.primary();
3566
- }
3567
-
3568
- if (e.altKey) {
3569
- type = "rect";
3570
- if (!addNew) ourRange = new Range(start, start);
3571
- start = posFromMouse(cm, e, true, true);
3572
- ourIndex = -1;
3573
- } else if (type == "double") {
3574
- var word = cm.findWordAt(start);
3575
- if (cm.display.shift || doc.extend)
3576
- ourRange = extendRange(doc, ourRange, word.anchor, word.head);
3577
- else
3578
- ourRange = word;
3579
- } else if (type == "triple") {
3580
- var line = new Range(Pos(start.line, 0), clipPos(doc, Pos(start.line + 1, 0)));
3581
- if (cm.display.shift || doc.extend)
3582
- ourRange = extendRange(doc, ourRange, line.anchor, line.head);
3583
- else
3584
- ourRange = line;
3585
- } else {
3586
- ourRange = extendRange(doc, ourRange, start);
3587
- }
3588
-
3589
- if (!addNew) {
3590
- ourIndex = 0;
3591
- setSelection(doc, new Selection([ourRange], 0), sel_mouse);
3592
- startSel = doc.sel;
3593
- } else if (ourIndex == -1) {
3594
- ourIndex = ranges.length;
3595
- setSelection(doc, normalizeSelection(ranges.concat([ourRange]), ourIndex),
3596
- {scroll: false, origin: "*mouse"});
3597
- } else if (ranges.length > 1 && ranges[ourIndex].empty() && type == "single") {
3598
- setSelection(doc, normalizeSelection(ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0));
3599
- startSel = doc.sel;
3600
- } else {
3601
- replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);
3602
- }
3603
-
3604
- var lastPos = start;
3605
- function extendTo(pos) {
3606
- if (cmp(lastPos, pos) == 0) return;
3607
- lastPos = pos;
3608
-
3609
- if (type == "rect") {
3610
- var ranges = [], tabSize = cm.options.tabSize;
3611
- var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
3612
- var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
3613
- var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);
3614
- for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
3615
- line <= end; line++) {
3616
- var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize);
3617
- if (left == right)
3618
- ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos)));
3619
- else if (text.length > leftPos)
3620
- ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize))));
3621
- }
3622
- if (!ranges.length) ranges.push(new Range(start, start));
3623
- setSelection(doc, normalizeSelection(startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
3624
- {origin: "*mouse", scroll: false});
3625
- cm.scrollIntoView(pos);
3626
- } else {
3627
- var oldRange = ourRange;
3628
- var anchor = oldRange.anchor, head = pos;
3629
- if (type != "single") {
3630
- if (type == "double")
3631
- var range = cm.findWordAt(pos);
3632
- else
3633
- var range = new Range(Pos(pos.line, 0), clipPos(doc, Pos(pos.line + 1, 0)));
3634
- if (cmp(range.anchor, anchor) > 0) {
3635
- head = range.head;
3636
- anchor = minPos(oldRange.from(), range.anchor);
3637
- } else {
3638
- head = range.anchor;
3639
- anchor = maxPos(oldRange.to(), range.head);
3640
- }
3641
- }
3642
- var ranges = startSel.ranges.slice(0);
3643
- ranges[ourIndex] = new Range(clipPos(doc, anchor), head);
3644
- setSelection(doc, normalizeSelection(ranges, ourIndex), sel_mouse);
3645
- }
3646
- }
3647
-
3648
- var editorSize = display.wrapper.getBoundingClientRect();
3649
- // Used to ensure timeout re-tries don't fire when another extend
3650
- // happened in the meantime (clearTimeout isn't reliable -- at
3651
- // least on Chrome, the timeouts still happen even when cleared,
3652
- // if the clear happens after their scheduled firing time).
3653
- var counter = 0;
3654
-
3655
- function extend(e) {
3656
- var curCount = ++counter;
3657
- var cur = posFromMouse(cm, e, true, type == "rect");
3658
- if (!cur) return;
3659
- if (cmp(cur, lastPos) != 0) {
3660
- ensureFocus(cm);
3661
- extendTo(cur);
3662
- var visible = visibleLines(display, doc);
3663
- if (cur.line >= visible.to || cur.line < visible.from)
3664
- setTimeout(operation(cm, function(){if (counter == curCount) extend(e);}), 150);
3665
- } else {
3666
- var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;
3667
- if (outside) setTimeout(operation(cm, function() {
3668
- if (counter != curCount) return;
3669
- display.scroller.scrollTop += outside;
3670
- extend(e);
3671
- }), 50);
3672
- }
3673
- }
3674
-
3675
- function done(e) {
3676
- counter = Infinity;
3677
- e_preventDefault(e);
3678
- display.input.focus();
3679
- off(document, "mousemove", move);
3680
- off(document, "mouseup", up);
3681
- doc.history.lastSelOrigin = null;
3682
- }
3683
-
3684
- var move = operation(cm, function(e) {
3685
- if (!e_button(e)) done(e);
3686
- else extend(e);
3687
- });
3688
- var up = operation(cm, done);
3689
- on(document, "mousemove", move);
3690
- on(document, "mouseup", up);
3691
- }
3692
-
3693
- // Determines whether an event happened in the gutter, and fires the
3694
- // handlers for the corresponding event.
3695
- function gutterEvent(cm, e, type, prevent, signalfn) {
3696
- try { var mX = e.clientX, mY = e.clientY; }
3697
- catch(e) { return false; }
3698
- if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) return false;
3699
- if (prevent) e_preventDefault(e);
3700
-
3701
- var display = cm.display;
3702
- var lineBox = display.lineDiv.getBoundingClientRect();
3703
-
3704
- if (mY > lineBox.bottom || !hasHandler(cm, type)) return e_defaultPrevented(e);
3705
- mY -= lineBox.top - display.viewOffset;
3706
-
3707
- for (var i = 0; i < cm.options.gutters.length; ++i) {
3708
- var g = display.gutters.childNodes[i];
3709
- if (g && g.getBoundingClientRect().right >= mX) {
3710
- var line = lineAtHeight(cm.doc, mY);
3711
- var gutter = cm.options.gutters[i];
3712
- signalfn(cm, type, cm, line, gutter, e);
3713
- return e_defaultPrevented(e);
3714
- }
3715
- }
3716
- }
3717
-
3718
- function clickInGutter(cm, e) {
3719
- return gutterEvent(cm, e, "gutterClick", true, signalLater);
3720
- }
3721
-
3722
- // Kludge to work around strange IE behavior where it'll sometimes
3723
- // re-fire a series of drag-related events right after the drop (#1551)
3724
- var lastDrop = 0;
3725
-
3726
- function onDrop(e) {
3727
- var cm = this;
3728
- if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
3729
- return;
3730
- e_preventDefault(e);
3731
- if (ie) lastDrop = +new Date;
3732
- var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
3733
- if (!pos || isReadOnly(cm)) return;
3734
- // Might be a file drop, in which case we simply extract the text
3735
- // and insert it.
3736
- if (files && files.length && window.FileReader && window.File) {
3737
- var n = files.length, text = Array(n), read = 0;
3738
- var loadFile = function(file, i) {
3739
- var reader = new FileReader;
3740
- reader.onload = operation(cm, function() {
3741
- text[i] = reader.result;
3742
- if (++read == n) {
3743
- pos = clipPos(cm.doc, pos);
3744
- var change = {from: pos, to: pos, text: splitLines(text.join("\n")), origin: "paste"};
3745
- makeChange(cm.doc, change);
3746
- setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change)));
3747
- }
3748
- });
3749
- reader.readAsText(file);
3750
- };
3751
- for (var i = 0; i < n; ++i) loadFile(files[i], i);
3752
- } else { // Normal drop
3753
- // Don't do a replace if the drop happened inside of the selected text.
3754
- if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
3755
- cm.state.draggingText(e);
3756
- // Ensure the editor is re-focused
3757
- setTimeout(function() {cm.display.input.focus();}, 20);
3758
- return;
3759
- }
3760
- try {
3761
- var text = e.dataTransfer.getData("Text");
3762
- if (text) {
3763
- if (cm.state.draggingText && !(mac ? e.metaKey : e.ctrlKey))
3764
- var selected = cm.listSelections();
3765
- setSelectionNoUndo(cm.doc, simpleSelection(pos, pos));
3766
- if (selected) for (var i = 0; i < selected.length; ++i)
3767
- replaceRange(cm.doc, "", selected[i].anchor, selected[i].head, "drag");
3768
- cm.replaceSelection(text, "around", "paste");
3769
- cm.display.input.focus();
3770
- }
3771
- }
3772
- catch(e){}
3773
- }
3774
- }
3775
-
3776
- function onDragStart(cm, e) {
3777
- if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return; }
3778
- if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) return;
3779
-
3780
- e.dataTransfer.setData("Text", cm.getSelection());
3781
-
3782
- // Use dummy image instead of default browsers image.
3783
- // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
3784
- if (e.dataTransfer.setDragImage && !safari) {
3785
- var img = elt("img", null, null, "position: fixed; left: 0; top: 0;");
3786
- img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
3787
- if (presto) {
3788
- img.width = img.height = 1;
3789
- cm.display.wrapper.appendChild(img);
3790
- // Force a relayout, or Opera won't use our image for some obscure reason
3791
- img._top = img.offsetTop;
3792
- }
3793
- e.dataTransfer.setDragImage(img, 0, 0);
3794
- if (presto) img.parentNode.removeChild(img);
3795
- }
3796
- }
3797
-
3798
- // SCROLL EVENTS
3799
-
3800
- // Sync the scrollable area and scrollbars, ensure the viewport
3801
- // covers the visible area.
3802
- function setScrollTop(cm, val) {
3803
- if (Math.abs(cm.doc.scrollTop - val) < 2) return;
3804
- cm.doc.scrollTop = val;
3805
- if (!gecko) updateDisplaySimple(cm, {top: val});
3806
- if (cm.display.scroller.scrollTop != val) cm.display.scroller.scrollTop = val;
3807
- cm.display.scrollbars.setScrollTop(val);
3808
- if (gecko) updateDisplaySimple(cm);
3809
- startWorker(cm, 100);
3810
- }
3811
- // Sync scroller and scrollbar, ensure the gutter elements are
3812
- // aligned.
3813
- function setScrollLeft(cm, val, isScroller) {
3814
- if (isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) return;
3815
- val = Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth);
3816
- cm.doc.scrollLeft = val;
3817
- alignHorizontally(cm);
3818
- if (cm.display.scroller.scrollLeft != val) cm.display.scroller.scrollLeft = val;
3819
- cm.display.scrollbars.setScrollLeft(val);
3820
- }
3821
-
3822
- // Since the delta values reported on mouse wheel events are
3823
- // unstandardized between browsers and even browser versions, and
3824
- // generally horribly unpredictable, this code starts by measuring
3825
- // the scroll effect that the first few mouse wheel events have,
3826
- // and, from that, detects the way it can convert deltas to pixel
3827
- // offsets afterwards.
3828
- //
3829
- // The reason we want to know the amount a wheel event will scroll
3830
- // is that it gives us a chance to update the display before the
3831
- // actual scrolling happens, reducing flickering.
3832
-
3833
- var wheelSamples = 0, wheelPixelsPerUnit = null;
3834
- // Fill in a browser-detected starting value on browsers where we
3835
- // know one. These don't have to be accurate -- the result of them
3836
- // being wrong would just be a slight flicker on the first wheel
3837
- // scroll (if it is large enough).
3838
- if (ie) wheelPixelsPerUnit = -.53;
3839
- else if (gecko) wheelPixelsPerUnit = 15;
3840
- else if (chrome) wheelPixelsPerUnit = -.7;
3841
- else if (safari) wheelPixelsPerUnit = -1/3;
3842
-
3843
- var wheelEventDelta = function(e) {
3844
- var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
3845
- if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) dx = e.detail;
3846
- if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) dy = e.detail;
3847
- else if (dy == null) dy = e.wheelDelta;
3848
- return {x: dx, y: dy};
3849
- };
3850
- CodeMirror.wheelEventPixels = function(e) {
3851
- var delta = wheelEventDelta(e);
3852
- delta.x *= wheelPixelsPerUnit;
3853
- delta.y *= wheelPixelsPerUnit;
3854
- return delta;
3855
- };
3856
-
3857
- function onScrollWheel(cm, e) {
3858
- var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y;
3859
-
3860
- var display = cm.display, scroll = display.scroller;
3861
- // Quit if there's nothing to scroll here
3862
- if (!(dx && scroll.scrollWidth > scroll.clientWidth ||
3863
- dy && scroll.scrollHeight > scroll.clientHeight)) return;
3864
-
3865
- // Webkit browsers on OS X abort momentum scrolls when the target
3866
- // of the scroll event is removed from the scrollable element.
3867
- // This hack (see related code in patchDisplay) makes sure the
3868
- // element is kept around.
3869
- if (dy && mac && webkit) {
3870
- outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
3871
- for (var i = 0; i < view.length; i++) {
3872
- if (view[i].node == cur) {
3873
- cm.display.currentWheelTarget = cur;
3874
- break outer;
3875
- }
3876
- }
3877
- }
3878
- }
3879
-
3880
- // On some browsers, horizontal scrolling will cause redraws to
3881
- // happen before the gutter has been realigned, causing it to
3882
- // wriggle around in a most unseemly way. When we have an
3883
- // estimated pixels/delta value, we just handle horizontal
3884
- // scrolling entirely here. It'll be slightly off from native, but
3885
- // better than glitching out.
3886
- if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
3887
- if (dy)
3888
- setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight)));
3889
- setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth)));
3890
- e_preventDefault(e);
3891
- display.wheelStartX = null; // Abort measurement, if in progress
3892
- return;
3893
- }
3894
-
3895
- // 'Project' the visible viewport to cover the area that is being
3896
- // scrolled into view (if we know enough to estimate it).
3897
- if (dy && wheelPixelsPerUnit != null) {
3898
- var pixels = dy * wheelPixelsPerUnit;
3899
- var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight;
3900
- if (pixels < 0) top = Math.max(0, top + pixels - 50);
3901
- else bot = Math.min(cm.doc.height, bot + pixels + 50);
3902
- updateDisplaySimple(cm, {top: top, bottom: bot});
3903
- }
3904
-
3905
- if (wheelSamples < 20) {
3906
- if (display.wheelStartX == null) {
3907
- display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop;
3908
- display.wheelDX = dx; display.wheelDY = dy;
3909
- setTimeout(function() {
3910
- if (display.wheelStartX == null) return;
3911
- var movedX = scroll.scrollLeft - display.wheelStartX;
3912
- var movedY = scroll.scrollTop - display.wheelStartY;
3913
- var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
3914
- (movedX && display.wheelDX && movedX / display.wheelDX);
3915
- display.wheelStartX = display.wheelStartY = null;
3916
- if (!sample) return;
3917
- wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
3918
- ++wheelSamples;
3919
- }, 200);
3920
- } else {
3921
- display.wheelDX += dx; display.wheelDY += dy;
3922
- }
3923
- }
3924
- }
3925
-
3926
- // KEY EVENTS
3927
-
3928
- // Run a handler that was bound to a key.
3929
- function doHandleBinding(cm, bound, dropShift) {
3930
- if (typeof bound == "string") {
3931
- bound = commands[bound];
3932
- if (!bound) return false;
3933
- }
3934
- // Ensure previous input has been read, so that the handler sees a
3935
- // consistent view of the document
3936
- cm.display.input.ensurePolled();
3937
- var prevShift = cm.display.shift, done = false;
3938
- try {
3939
- if (isReadOnly(cm)) cm.state.suppressEdits = true;
3940
- if (dropShift) cm.display.shift = false;
3941
- done = bound(cm) != Pass;
3942
- } finally {
3943
- cm.display.shift = prevShift;
3944
- cm.state.suppressEdits = false;
3945
- }
3946
- return done;
3947
- }
3948
-
3949
- function lookupKeyForEditor(cm, name, handle) {
3950
- for (var i = 0; i < cm.state.keyMaps.length; i++) {
3951
- var result = lookupKey(name, cm.state.keyMaps[i], handle, cm);
3952
- if (result) return result;
3953
- }
3954
- return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm))
3955
- || lookupKey(name, cm.options.keyMap, handle, cm);
3956
- }
3957
-
3958
- var stopSeq = new Delayed;
3959
- function dispatchKey(cm, name, e, handle) {
3960
- var seq = cm.state.keySeq;
3961
- if (seq) {
3962
- if (isModifierKey(name)) return "handled";
3963
- stopSeq.set(50, function() {
3964
- if (cm.state.keySeq == seq) {
3965
- cm.state.keySeq = null;
3966
- cm.display.input.reset();
3967
- }
3968
- });
3969
- name = seq + " " + name;
3970
- }
3971
- var result = lookupKeyForEditor(cm, name, handle);
3972
-
3973
- if (result == "multi")
3974
- cm.state.keySeq = name;
3975
- if (result == "handled")
3976
- signalLater(cm, "keyHandled", cm, name, e);
3977
-
3978
- if (result == "handled" || result == "multi") {
3979
- e_preventDefault(e);
3980
- restartBlink(cm);
3981
- }
3982
-
3983
- if (seq && !result && /\'$/.test(name)) {
3984
- e_preventDefault(e);
3985
- return true;
3986
- }
3987
- return !!result;
3988
- }
3989
-
3990
- // Handle a key from the keydown event.
3991
- function handleKeyBinding(cm, e) {
3992
- var name = keyName(e, true);
3993
- if (!name) return false;
3994
-
3995
- if (e.shiftKey && !cm.state.keySeq) {
3996
- // First try to resolve full name (including 'Shift-'). Failing
3997
- // that, see if there is a cursor-motion command (starting with
3998
- // 'go') bound to the keyname without 'Shift-'.
3999
- return dispatchKey(cm, "Shift-" + name, e, function(b) {return doHandleBinding(cm, b, true);})
4000
- || dispatchKey(cm, name, e, function(b) {
4001
- if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
4002
- return doHandleBinding(cm, b);
4003
- });
4004
- } else {
4005
- return dispatchKey(cm, name, e, function(b) { return doHandleBinding(cm, b); });
4006
- }
4007
- }
4008
-
4009
- // Handle a key from the keypress event
4010
- function handleCharBinding(cm, e, ch) {
4011
- return dispatchKey(cm, "'" + ch + "'", e,
4012
- function(b) { return doHandleBinding(cm, b, true); });
4013
- }
4014
-
4015
- var lastStoppedKey = null;
4016
- function onKeyDown(e) {
4017
- var cm = this;
4018
- ensureFocus(cm);
4019
- if (signalDOMEvent(cm, e)) return;
4020
- // IE does strange things with escape.
4021
- if (ie && ie_version < 11 && e.keyCode == 27) e.returnValue = false;
4022
- var code = e.keyCode;
4023
- cm.display.shift = code == 16 || e.shiftKey;
4024
- var handled = handleKeyBinding(cm, e);
4025
- if (presto) {
4026
- lastStoppedKey = handled ? code : null;
4027
- // Opera has no cut event... we try to at least catch the key combo
4028
- if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
4029
- cm.replaceSelection("", null, "cut");
4030
- }
4031
-
4032
- // Turn mouse into crosshair when Alt is held on Mac.
4033
- if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className))
4034
- showCrossHair(cm);
4035
- }
4036
-
4037
- function showCrossHair(cm) {
4038
- var lineDiv = cm.display.lineDiv;
4039
- addClass(lineDiv, "CodeMirror-crosshair");
4040
-
4041
- function up(e) {
4042
- if (e.keyCode == 18 || !e.altKey) {
4043
- rmClass(lineDiv, "CodeMirror-crosshair");
4044
- off(document, "keyup", up);
4045
- off(document, "mouseover", up);
4046
- }
4047
- }
4048
- on(document, "keyup", up);
4049
- on(document, "mouseover", up);
4050
- }
4051
-
4052
- function onKeyUp(e) {
4053
- if (e.keyCode == 16) this.doc.sel.shift = false;
4054
- signalDOMEvent(this, e);
4055
- }
4056
-
4057
- function onKeyPress(e) {
4058
- var cm = this;
4059
- if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) return;
4060
- var keyCode = e.keyCode, charCode = e.charCode;
4061
- if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return;}
4062
- if ((presto && (!e.which || e.which < 10)) && handleKeyBinding(cm, e)) return;
4063
- var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
4064
- if (handleCharBinding(cm, e, ch)) return;
4065
- cm.display.input.onKeyPress(e);
4066
- }
4067
-
4068
- // FOCUS/BLUR EVENTS
4069
-
4070
- function onFocus(cm) {
4071
- if (cm.options.readOnly == "nocursor") return;
4072
- if (!cm.state.focused) {
4073
- signal(cm, "focus", cm);
4074
- cm.state.focused = true;
4075
- addClass(cm.display.wrapper, "CodeMirror-focused");
4076
- // This test prevents this from firing when a context
4077
- // menu is closed (since the input reset would kill the
4078
- // select-all detection hack)
4079
- if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
4080
- cm.display.input.reset();
4081
- if (webkit) setTimeout(function() { cm.display.input.reset(true); }, 20); // Issue #1730
4082
- }
4083
- cm.display.input.receivedFocus();
4084
- }
4085
- restartBlink(cm);
4086
- }
4087
- function onBlur(cm) {
4088
- if (cm.state.focused) {
4089
- signal(cm, "blur", cm);
4090
- cm.state.focused = false;
4091
- rmClass(cm.display.wrapper, "CodeMirror-focused");
4092
- }
4093
- clearInterval(cm.display.blinker);
4094
- setTimeout(function() {if (!cm.state.focused) cm.display.shift = false;}, 150);
4095
- }
4096
-
4097
- // CONTEXT MENU HANDLING
4098
-
4099
- // To make the context menu work, we need to briefly unhide the
4100
- // textarea (making it as unobtrusive as possible) to let the
4101
- // right-click take effect on it.
4102
- function onContextMenu(cm, e) {
4103
- if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) return;
4104
- cm.display.input.onContextMenu(e);
4105
- }
4106
-
4107
- function contextMenuInGutter(cm, e) {
4108
- if (!hasHandler(cm, "gutterContextMenu")) return false;
4109
- return gutterEvent(cm, e, "gutterContextMenu", false, signal);
4110
- }
4111
-
4112
- // UPDATING
4113
-
4114
- // Compute the position of the end of a change (its 'to' property
4115
- // refers to the pre-change end).
4116
- var changeEnd = CodeMirror.changeEnd = function(change) {
4117
- if (!change.text) return change.to;
4118
- return Pos(change.from.line + change.text.length - 1,
4119
- lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0));
4120
- };
4121
-
4122
- // Adjust a position to refer to the post-change position of the
4123
- // same text, or the end of the change if the change covers it.
4124
- function adjustForChange(pos, change) {
4125
- if (cmp(pos, change.from) < 0) return pos;
4126
- if (cmp(pos, change.to) <= 0) return changeEnd(change);
4127
-
4128
- var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch;
4129
- if (pos.line == change.to.line) ch += changeEnd(change).ch - change.to.ch;
4130
- return Pos(line, ch);
4131
- }
4132
-
4133
- function computeSelAfterChange(doc, change) {
4134
- var out = [];
4135
- for (var i = 0; i < doc.sel.ranges.length; i++) {
4136
- var range = doc.sel.ranges[i];
4137
- out.push(new Range(adjustForChange(range.anchor, change),
4138
- adjustForChange(range.head, change)));
4139
- }
4140
- return normalizeSelection(out, doc.sel.primIndex);
4141
- }
4142
-
4143
- function offsetPos(pos, old, nw) {
4144
- if (pos.line == old.line)
4145
- return Pos(nw.line, pos.ch - old.ch + nw.ch);
4146
- else
4147
- return Pos(nw.line + (pos.line - old.line), pos.ch);
4148
- }
4149
-
4150
- // Used by replaceSelections to allow moving the selection to the
4151
- // start or around the replaced test. Hint may be "start" or "around".
4152
- function computeReplacedSel(doc, changes, hint) {
4153
- var out = [];
4154
- var oldPrev = Pos(doc.first, 0), newPrev = oldPrev;
4155
- for (var i = 0; i < changes.length; i++) {
4156
- var change = changes[i];
4157
- var from = offsetPos(change.from, oldPrev, newPrev);
4158
- var to = offsetPos(changeEnd(change), oldPrev, newPrev);
4159
- oldPrev = change.to;
4160
- newPrev = to;
4161
- if (hint == "around") {
4162
- var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0;
4163
- out[i] = new Range(inv ? to : from, inv ? from : to);
4164
- } else {
4165
- out[i] = new Range(from, from);
4166
- }
4167
- }
4168
- return new Selection(out, doc.sel.primIndex);
4169
- }
4170
-
4171
- // Allow "beforeChange" event handlers to influence a change
4172
- function filterChange(doc, change, update) {
4173
- var obj = {
4174
- canceled: false,
4175
- from: change.from,
4176
- to: change.to,
4177
- text: change.text,
4178
- origin: change.origin,
4179
- cancel: function() { this.canceled = true; }
4180
- };
4181
- if (update) obj.update = function(from, to, text, origin) {
4182
- if (from) this.from = clipPos(doc, from);
4183
- if (to) this.to = clipPos(doc, to);
4184
- if (text) this.text = text;
4185
- if (origin !== undefined) this.origin = origin;
4186
- };
4187
- signal(doc, "beforeChange", doc, obj);
4188
- if (doc.cm) signal(doc.cm, "beforeChange", doc.cm, obj);
4189
-
4190
- if (obj.canceled) return null;
4191
- return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin};
4192
- }
4193
-
4194
- // Apply a change to a document, and add it to the document's
4195
- // history, and propagating it to all linked documents.
4196
- function makeChange(doc, change, ignoreReadOnly) {
4197
- if (doc.cm) {
4198
- if (!doc.cm.curOp) return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly);
4199
- if (doc.cm.state.suppressEdits) return;
4200
- }
4201
-
4202
- if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
4203
- change = filterChange(doc, change, true);
4204
- if (!change) return;
4205
- }
4206
-
4207
- // Possibly split or suppress the update based on the presence
4208
- // of read-only spans in its range.
4209
- var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to);
4210
- if (split) {
4211
- for (var i = split.length - 1; i >= 0; --i)
4212
- makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text});
4213
- } else {
4214
- makeChangeInner(doc, change);
4215
- }
4216
- }
4217
-
4218
- function makeChangeInner(doc, change) {
4219
- if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) return;
4220
- var selAfter = computeSelAfterChange(doc, change);
4221
- addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN);
4222
-
4223
- makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change));
4224
- var rebased = [];
4225
-
4226
- linkedDocs(doc, function(doc, sharedHist) {
4227
- if (!sharedHist && indexOf(rebased, doc.history) == -1) {
4228
- rebaseHist(doc.history, change);
4229
- rebased.push(doc.history);
4230
- }
4231
- makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change));
4232
- });
4233
- }
4234
-
4235
- // Revert a change stored in a document's history.
4236
- function makeChangeFromHistory(doc, type, allowSelectionOnly) {
4237
- if (doc.cm && doc.cm.state.suppressEdits) return;
4238
-
4239
- var hist = doc.history, event, selAfter = doc.sel;
4240
- var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done;
4241
-
4242
- // Verify that there is a useable event (so that ctrl-z won't
4243
- // needlessly clear selection events)
4244
- for (var i = 0; i < source.length; i++) {
4245
- event = source[i];
4246
- if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges)
4247
- break;
4248
- }
4249
- if (i == source.length) return;
4250
- hist.lastOrigin = hist.lastSelOrigin = null;
4251
-
4252
- for (;;) {
4253
- event = source.pop();
4254
- if (event.ranges) {
4255
- pushSelectionToHistory(event, dest);
4256
- if (allowSelectionOnly && !event.equals(doc.sel)) {
4257
- setSelection(doc, event, {clearRedo: false});
4258
- return;
4259
- }
4260
- selAfter = event;
4261
- }
4262
- else break;
4263
- }
4264
-
4265
- // Build up a reverse change object to add to the opposite history
4266
- // stack (redo when undoing, and vice versa).
4267
- var antiChanges = [];
4268
- pushSelectionToHistory(selAfter, dest);
4269
- dest.push({changes: antiChanges, generation: hist.generation});
4270
- hist.generation = event.generation || ++hist.maxGeneration;
4271
-
4272
- var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange");
4273
-
4274
- for (var i = event.changes.length - 1; i >= 0; --i) {
4275
- var change = event.changes[i];
4276
- change.origin = type;
4277
- if (filter && !filterChange(doc, change, false)) {
4278
- source.length = 0;
4279
- return;
4280
- }
4281
-
4282
- antiChanges.push(historyChangeFromChange(doc, change));
4283
-
4284
- var after = i ? computeSelAfterChange(doc, change) : lst(source);
4285
- makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change));
4286
- if (!i && doc.cm) doc.cm.scrollIntoView({from: change.from, to: changeEnd(change)});
4287
- var rebased = [];
4288
-
4289
- // Propagate to the linked documents
4290
- linkedDocs(doc, function(doc, sharedHist) {
4291
- if (!sharedHist && indexOf(rebased, doc.history) == -1) {
4292
- rebaseHist(doc.history, change);
4293
- rebased.push(doc.history);
4294
- }
4295
- makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change));
4296
- });
4297
- }
4298
- }
4299
-
4300
- // Sub-views need their line numbers shifted when text is added
4301
- // above or below them in the parent document.
4302
- function shiftDoc(doc, distance) {
4303
- if (distance == 0) return;
4304
- doc.first += distance;
4305
- doc.sel = new Selection(map(doc.sel.ranges, function(range) {
4306
- return new Range(Pos(range.anchor.line + distance, range.anchor.ch),
4307
- Pos(range.head.line + distance, range.head.ch));
4308
- }), doc.sel.primIndex);
4309
- if (doc.cm) {
4310
- regChange(doc.cm, doc.first, doc.first - distance, distance);
4311
- for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++)
4312
- regLineChange(doc.cm, l, "gutter");
4313
- }
4314
- }
4315
-
4316
- // More lower-level change function, handling only a single document
4317
- // (not linked ones).
4318
- function makeChangeSingleDoc(doc, change, selAfter, spans) {
4319
- if (doc.cm && !doc.cm.curOp)
4320
- return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans);
4321
-
4322
- if (change.to.line < doc.first) {
4323
- shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line));
4324
- return;
4325
- }
4326
- if (change.from.line > doc.lastLine()) return;
4327
-
4328
- // Clip the change to the size of this doc
4329
- if (change.from.line < doc.first) {
4330
- var shift = change.text.length - 1 - (doc.first - change.from.line);
4331
- shiftDoc(doc, shift);
4332
- change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
4333
- text: [lst(change.text)], origin: change.origin};
4334
- }
4335
- var last = doc.lastLine();
4336
- if (change.to.line > last) {
4337
- change = {from: change.from, to: Pos(last, getLine(doc, last).text.length),
4338
- text: [change.text[0]], origin: change.origin};
4339
- }
4340
-
4341
- change.removed = getBetween(doc, change.from, change.to);
4342
-
4343
- if (!selAfter) selAfter = computeSelAfterChange(doc, change);
4344
- if (doc.cm) makeChangeSingleDocInEditor(doc.cm, change, spans);
4345
- else updateDoc(doc, change, spans);
4346
- setSelectionNoUndo(doc, selAfter, sel_dontScroll);
4347
- }
4348
-
4349
- // Handle the interaction of a change to a document with the editor
4350
- // that this document is part of.
4351
- function makeChangeSingleDocInEditor(cm, change, spans) {
4352
- var doc = cm.doc, display = cm.display, from = change.from, to = change.to;
4353
-
4354
- var recomputeMaxLength = false, checkWidthStart = from.line;
4355
- if (!cm.options.lineWrapping) {
4356
- checkWidthStart = lineNo(visualLine(getLine(doc, from.line)));
4357
- doc.iter(checkWidthStart, to.line + 1, function(line) {
4358
- if (line == display.maxLine) {
4359
- recomputeMaxLength = true;
4360
- return true;
4361
- }
4362
- });
4363
- }
4364
-
4365
- if (doc.sel.contains(change.from, change.to) > -1)
4366
- signalCursorActivity(cm);
4367
-
4368
- updateDoc(doc, change, spans, estimateHeight(cm));
4369
-
4370
- if (!cm.options.lineWrapping) {
4371
- doc.iter(checkWidthStart, from.line + change.text.length, function(line) {
4372
- var len = lineLength(line);
4373
- if (len > display.maxLineLength) {
4374
- display.maxLine = line;
4375
- display.maxLineLength = len;
4376
- display.maxLineChanged = true;
4377
- recomputeMaxLength = false;
4378
- }
4379
- });
4380
- if (recomputeMaxLength) cm.curOp.updateMaxLine = true;
4381
- }
4382
-
4383
- // Adjust frontier, schedule worker
4384
- doc.frontier = Math.min(doc.frontier, from.line);
4385
- startWorker(cm, 400);
4386
-
4387
- var lendiff = change.text.length - (to.line - from.line) - 1;
4388
- // Remember that these lines changed, for updating the display
4389
- if (change.full)
4390
- regChange(cm);
4391
- else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change))
4392
- regLineChange(cm, from.line, "text");
4393
- else
4394
- regChange(cm, from.line, to.line + 1, lendiff);
4395
-
4396
- var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change");
4397
- if (changeHandler || changesHandler) {
4398
- var obj = {
4399
- from: from, to: to,
4400
- text: change.text,
4401
- removed: change.removed,
4402
- origin: change.origin
4403
- };
4404
- if (changeHandler) signalLater(cm, "change", cm, obj);
4405
- if (changesHandler) (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj);
4406
- }
4407
- cm.display.selForContextMenu = null;
4408
- }
4409
-
4410
- function replaceRange(doc, code, from, to, origin) {
4411
- if (!to) to = from;
4412
- if (cmp(to, from) < 0) { var tmp = to; to = from; from = tmp; }
4413
- if (typeof code == "string") code = splitLines(code);
4414
- makeChange(doc, {from: from, to: to, text: code, origin: origin});
4415
- }
4416
-
4417
- // SCROLLING THINGS INTO VIEW
4418
-
4419
- // If an editor sits on the top or bottom of the window, partially
4420
- // scrolled out of view, this ensures that the cursor is visible.
4421
- function maybeScrollWindow(cm, coords) {
4422
- if (signalDOMEvent(cm, "scrollCursorIntoView")) return;
4423
-
4424
- var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null;
4425
- if (coords.top + box.top < 0) doScroll = true;
4426
- else if (coords.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) doScroll = false;
4427
- if (doScroll != null && !phantom) {
4428
- var scrollNode = elt("div", "\u200b", null, "position: absolute; top: " +
4429
- (coords.top - display.viewOffset - paddingTop(cm.display)) + "px; height: " +
4430
- (coords.bottom - coords.top + scrollGap(cm) + display.barHeight) + "px; left: " +
4431
- coords.left + "px; width: 2px;");
4432
- cm.display.lineSpace.appendChild(scrollNode);
4433
- scrollNode.scrollIntoView(doScroll);
4434
- cm.display.lineSpace.removeChild(scrollNode);
4435
- }
4436
- }
4437
-
4438
- // Scroll a given position into view (immediately), verifying that
4439
- // it actually became visible (as line heights are accurately
4440
- // measured, the position of something may 'drift' during drawing).
4441
- function scrollPosIntoView(cm, pos, end, margin) {
4442
- if (margin == null) margin = 0;
4443
- for (var limit = 0; limit < 5; limit++) {
4444
- var changed = false, coords = cursorCoords(cm, pos);
4445
- var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
4446
- var scrollPos = calculateScrollPos(cm, Math.min(coords.left, endCoords.left),
4447
- Math.min(coords.top, endCoords.top) - margin,
4448
- Math.max(coords.left, endCoords.left),
4449
- Math.max(coords.bottom, endCoords.bottom) + margin);
4450
- var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft;
4451
- if (scrollPos.scrollTop != null) {
4452
- setScrollTop(cm, scrollPos.scrollTop);
4453
- if (Math.abs(cm.doc.scrollTop - startTop) > 1) changed = true;
4454
- }
4455
- if (scrollPos.scrollLeft != null) {
4456
- setScrollLeft(cm, scrollPos.scrollLeft);
4457
- if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) changed = true;
4458
- }
4459
- if (!changed) break;
4460
- }
4461
- return coords;
4462
- }
4463
-
4464
- // Scroll a given set of coordinates into view (immediately).
4465
- function scrollIntoView(cm, x1, y1, x2, y2) {
4466
- var scrollPos = calculateScrollPos(cm, x1, y1, x2, y2);
4467
- if (scrollPos.scrollTop != null) setScrollTop(cm, scrollPos.scrollTop);
4468
- if (scrollPos.scrollLeft != null) setScrollLeft(cm, scrollPos.scrollLeft);
4469
- }
4470
-
4471
- // Calculate a new scroll position needed to scroll the given
4472
- // rectangle into view. Returns an object with scrollTop and
4473
- // scrollLeft properties. When these are undefined, the
4474
- // vertical/horizontal position does not need to be adjusted.
4475
- function calculateScrollPos(cm, x1, y1, x2, y2) {
4476
- var display = cm.display, snapMargin = textHeight(cm.display);
4477
- if (y1 < 0) y1 = 0;
4478
- var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop;
4479
- var screen = displayHeight(cm), result = {};
4480
- if (y2 - y1 > screen) y2 = y1 + screen;
4481
- var docBottom = cm.doc.height + paddingVert(display);
4482
- var atTop = y1 < snapMargin, atBottom = y2 > docBottom - snapMargin;
4483
- if (y1 < screentop) {
4484
- result.scrollTop = atTop ? 0 : y1;
4485
- } else if (y2 > screentop + screen) {
4486
- var newTop = Math.min(y1, (atBottom ? docBottom : y2) - screen);
4487
- if (newTop != screentop) result.scrollTop = newTop;
4488
- }
4489
-
4490
- var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft;
4491
- var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0);
4492
- var tooWide = x2 - x1 > screenw;
4493
- if (tooWide) x2 = x1 + screenw;
4494
- if (x1 < 10)
4495
- result.scrollLeft = 0;
4496
- else if (x1 < screenleft)
4497
- result.scrollLeft = Math.max(0, x1 - (tooWide ? 0 : 10));
4498
- else if (x2 > screenw + screenleft - 3)
4499
- result.scrollLeft = x2 + (tooWide ? 0 : 10) - screenw;
4500
- return result;
4501
- }
4502
-
4503
- // Store a relative adjustment to the scroll position in the current
4504
- // operation (to be applied when the operation finishes).
4505
- function addToScrollPos(cm, left, top) {
4506
- if (left != null || top != null) resolveScrollToPos(cm);
4507
- if (left != null)
4508
- cm.curOp.scrollLeft = (cm.curOp.scrollLeft == null ? cm.doc.scrollLeft : cm.curOp.scrollLeft) + left;
4509
- if (top != null)
4510
- cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top;
4511
- }
4512
-
4513
- // Make sure that at the end of the operation the current cursor is
4514
- // shown.
4515
- function ensureCursorVisible(cm) {
4516
- resolveScrollToPos(cm);
4517
- var cur = cm.getCursor(), from = cur, to = cur;
4518
- if (!cm.options.lineWrapping) {
4519
- from = cur.ch ? Pos(cur.line, cur.ch - 1) : cur;
4520
- to = Pos(cur.line, cur.ch + 1);
4521
- }
4522
- cm.curOp.scrollToPos = {from: from, to: to, margin: cm.options.cursorScrollMargin, isCursor: true};
4523
- }
4524
-
4525
- // When an operation has its scrollToPos property set, and another
4526
- // scroll action is applied before the end of the operation, this
4527
- // 'simulates' scrolling that position into view in a cheap way, so
4528
- // that the effect of intermediate scroll commands is not ignored.
4529
- function resolveScrollToPos(cm) {
4530
- var range = cm.curOp.scrollToPos;
4531
- if (range) {
4532
- cm.curOp.scrollToPos = null;
4533
- var from = estimateCoords(cm, range.from), to = estimateCoords(cm, range.to);
4534
- var sPos = calculateScrollPos(cm, Math.min(from.left, to.left),
4535
- Math.min(from.top, to.top) - range.margin,
4536
- Math.max(from.right, to.right),
4537
- Math.max(from.bottom, to.bottom) + range.margin);
4538
- cm.scrollTo(sPos.scrollLeft, sPos.scrollTop);
4539
- }
4540
- }
4541
-
4542
- // API UTILITIES
4543
-
4544
- // Indent the given line. The how parameter can be "smart",
4545
- // "add"/null, "subtract", or "prev". When aggressive is false
4546
- // (typically set to true for forced single-line indents), empty
4547
- // lines are not indented, and places where the mode returns Pass
4548
- // are left alone.
4549
- function indentLine(cm, n, how, aggressive) {
4550
- var doc = cm.doc, state;
4551
- if (how == null) how = "add";
4552
- if (how == "smart") {
4553
- // Fall back to "prev" when the mode doesn't have an indentation
4554
- // method.
4555
- if (!doc.mode.indent) how = "prev";
4556
- else state = getStateBefore(cm, n);
4557
- }
4558
-
4559
- var tabSize = cm.options.tabSize;
4560
- var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
4561
- if (line.stateAfter) line.stateAfter = null;
4562
- var curSpaceString = line.text.match(/^\s*/)[0], indentation;
4563
- if (!aggressive && !/\S/.test(line.text)) {
4564
- indentation = 0;
4565
- how = "not";
4566
- } else if (how == "smart") {
4567
- indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
4568
- if (indentation == Pass || indentation > 150) {
4569
- if (!aggressive) return;
4570
- how = "prev";
4571
- }
4572
- }
4573
- if (how == "prev") {
4574
- if (n > doc.first) indentation = countColumn(getLine(doc, n-1).text, null, tabSize);
4575
- else indentation = 0;
4576
- } else if (how == "add") {
4577
- indentation = curSpace + cm.options.indentUnit;
4578
- } else if (how == "subtract") {
4579
- indentation = curSpace - cm.options.indentUnit;
4580
- } else if (typeof how == "number") {
4581
- indentation = curSpace + how;
4582
- }
4583
- indentation = Math.max(0, indentation);
4584
-
4585
- var indentString = "", pos = 0;
4586
- if (cm.options.indentWithTabs)
4587
- for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";}
4588
- if (pos < indentation) indentString += spaceStr(indentation - pos);
4589
-
4590
- if (indentString != curSpaceString) {
4591
- replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input");
4592
- } else {
4593
- // Ensure that, if the cursor was in the whitespace at the start
4594
- // of the line, it is moved to the end of that space.
4595
- for (var i = 0; i < doc.sel.ranges.length; i++) {
4596
- var range = doc.sel.ranges[i];
4597
- if (range.head.line == n && range.head.ch < curSpaceString.length) {
4598
- var pos = Pos(n, curSpaceString.length);
4599
- replaceOneSelection(doc, i, new Range(pos, pos));
4600
- break;
4601
- }
4602
- }
4603
- }
4604
- line.stateAfter = null;
4605
- }
4606
-
4607
- // Utility for applying a change to a line by handle or number,
4608
- // returning the number and optionally registering the line as
4609
- // changed.
4610
- function changeLine(doc, handle, changeType, op) {
4611
- var no = handle, line = handle;
4612
- if (typeof handle == "number") line = getLine(doc, clipLine(doc, handle));
4613
- else no = lineNo(handle);
4614
- if (no == null) return null;
4615
- if (op(line, no) && doc.cm) regLineChange(doc.cm, no, changeType);
4616
- return line;
4617
- }
4618
-
4619
- // Helper for deleting text near the selection(s), used to implement
4620
- // backspace, delete, and similar functionality.
4621
- function deleteNearSelection(cm, compute) {
4622
- var ranges = cm.doc.sel.ranges, kill = [];
4623
- // Build up a set of ranges to kill first, merging overlapping
4624
- // ranges.
4625
- for (var i = 0; i < ranges.length; i++) {
4626
- var toKill = compute(ranges[i]);
4627
- while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
4628
- var replaced = kill.pop();
4629
- if (cmp(replaced.from, toKill.from) < 0) {
4630
- toKill.from = replaced.from;
4631
- break;
4632
- }
4633
- }
4634
- kill.push(toKill);
4635
- }
4636
- // Next, remove those actual ranges.
4637
- runInOp(cm, function() {
4638
- for (var i = kill.length - 1; i >= 0; i--)
4639
- replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete");
4640
- ensureCursorVisible(cm);
4641
- });
4642
- }
4643
-
4644
- // Used for horizontal relative motion. Dir is -1 or 1 (left or
4645
- // right), unit can be "char", "column" (like char, but doesn't
4646
- // cross line boundaries), "word" (across next word), or "group" (to
4647
- // the start of next group of word or non-word-non-whitespace
4648
- // chars). The visually param controls whether, in right-to-left
4649
- // text, direction 1 means to move towards the next index in the
4650
- // string, or towards the character to the right of the current
4651
- // position. The resulting position will have a hitSide=true
4652
- // property if it reached the end of the document.
4653
- function findPosH(doc, pos, dir, unit, visually) {
4654
- var line = pos.line, ch = pos.ch, origDir = dir;
4655
- var lineObj = getLine(doc, line);
4656
- var possible = true;
4657
- function findNextLine() {
4658
- var l = line + dir;
4659
- if (l < doc.first || l >= doc.first + doc.size) return (possible = false);
4660
- line = l;
4661
- return lineObj = getLine(doc, l);
4662
- }
4663
- function moveOnce(boundToLine) {
4664
- var next = (visually ? moveVisually : moveLogically)(lineObj, ch, dir, true);
4665
- if (next == null) {
4666
- if (!boundToLine && findNextLine()) {
4667
- if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj);
4668
- else ch = dir < 0 ? lineObj.text.length : 0;
4669
- } else return (possible = false);
4670
- } else ch = next;
4671
- return true;
4672
- }
4673
-
4674
- if (unit == "char") moveOnce();
4675
- else if (unit == "column") moveOnce(true);
4676
- else if (unit == "word" || unit == "group") {
4677
- var sawType = null, group = unit == "group";
4678
- var helper = doc.cm && doc.cm.getHelper(pos, "wordChars");
4679
- for (var first = true;; first = false) {
4680
- if (dir < 0 && !moveOnce(!first)) break;
4681
- var cur = lineObj.text.charAt(ch) || "\n";
4682
- var type = isWordChar(cur, helper) ? "w"
4683
- : group && cur == "\n" ? "n"
4684
- : !group || /\s/.test(cur) ? null
4685
- : "p";
4686
- if (group && !first && !type) type = "s";
4687
- if (sawType && sawType != type) {
4688
- if (dir < 0) {dir = 1; moveOnce();}
4689
- break;
4690
- }
4691
-
4692
- if (type) sawType = type;
4693
- if (dir > 0 && !moveOnce(!first)) break;
4694
- }
4695
- }
4696
- var result = skipAtomic(doc, Pos(line, ch), origDir, true);
4697
- if (!possible) result.hitSide = true;
4698
- return result;
4699
- }
4700
-
4701
- // For relative vertical movement. Dir may be -1 or 1. Unit can be
4702
- // "page" or "line". The resulting position will have a hitSide=true
4703
- // property if it reached the end of the document.
4704
- function findPosV(cm, pos, dir, unit) {
4705
- var doc = cm.doc, x = pos.left, y;
4706
- if (unit == "page") {
4707
- var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
4708
- y = pos.top + dir * (pageSize - (dir < 0 ? 1.5 : .5) * textHeight(cm.display));
4709
- } else if (unit == "line") {
4710
- y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
4711
- }
4712
- for (;;) {
4713
- var target = coordsChar(cm, x, y);
4714
- if (!target.outside) break;
4715
- if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break; }
4716
- y += dir * 5;
4717
- }
4718
- return target;
4719
- }
4720
-
4721
- // EDITOR METHODS
4722
-
4723
- // The publicly visible API. Note that methodOp(f) means
4724
- // 'wrap f in an operation, performed on its `this` parameter'.
4725
-
4726
- // This is not the complete set of editor methods. Most of the
4727
- // methods defined on the Doc type are also injected into
4728
- // CodeMirror.prototype, for backwards compatibility and
4729
- // convenience.
4730
-
4731
- CodeMirror.prototype = {
4732
- constructor: CodeMirror,
4733
- focus: function(){window.focus(); this.display.input.focus();},
4734
-
4735
- setOption: function(option, value) {
4736
- var options = this.options, old = options[option];
4737
- if (options[option] == value && option != "mode") return;
4738
- options[option] = value;
4739
- if (optionHandlers.hasOwnProperty(option))
4740
- operation(this, optionHandlers[option])(this, value, old);
4741
- },
4742
-
4743
- getOption: function(option) {return this.options[option];},
4744
- getDoc: function() {return this.doc;},
4745
-
4746
- addKeyMap: function(map, bottom) {
4747
- this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map));
4748
- },
4749
- removeKeyMap: function(map) {
4750
- var maps = this.state.keyMaps;
4751
- for (var i = 0; i < maps.length; ++i)
4752
- if (maps[i] == map || maps[i].name == map) {
4753
- maps.splice(i, 1);
4754
- return true;
4755
- }
4756
- },
4757
-
4758
- addOverlay: methodOp(function(spec, options) {
4759
- var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec);
4760
- if (mode.startState) throw new Error("Overlays may not be stateful.");
4761
- this.state.overlays.push({mode: mode, modeSpec: spec, opaque: options && options.opaque});
4762
- this.state.modeGen++;
4763
- regChange(this);
4764
- }),
4765
- removeOverlay: methodOp(function(spec) {
4766
- var overlays = this.state.overlays;
4767
- for (var i = 0; i < overlays.length; ++i) {
4768
- var cur = overlays[i].modeSpec;
4769
- if (cur == spec || typeof spec == "string" && cur.name == spec) {
4770
- overlays.splice(i, 1);
4771
- this.state.modeGen++;
4772
- regChange(this);
4773
- return;
4774
- }
4775
- }
4776
- }),
4777
-
4778
- indentLine: methodOp(function(n, dir, aggressive) {
4779
- if (typeof dir != "string" && typeof dir != "number") {
4780
- if (dir == null) dir = this.options.smartIndent ? "smart" : "prev";
4781
- else dir = dir ? "add" : "subtract";
4782
- }
4783
- if (isLine(this.doc, n)) indentLine(this, n, dir, aggressive);
4784
- }),
4785
- indentSelection: methodOp(function(how) {
4786
- var ranges = this.doc.sel.ranges, end = -1;
4787
- for (var i = 0; i < ranges.length; i++) {
4788
- var range = ranges[i];
4789
- if (!range.empty()) {
4790
- var from = range.from(), to = range.to();
4791
- var start = Math.max(end, from.line);
4792
- end = Math.min(this.lastLine(), to.line - (to.ch ? 0 : 1)) + 1;
4793
- for (var j = start; j < end; ++j)
4794
- indentLine(this, j, how);
4795
- var newRanges = this.doc.sel.ranges;
4796
- if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i].from().ch > 0)
4797
- replaceOneSelection(this.doc, i, new Range(from, newRanges[i].to()), sel_dontScroll);
4798
- } else if (range.head.line > end) {
4799
- indentLine(this, range.head.line, how, true);
4800
- end = range.head.line;
4801
- if (i == this.doc.sel.primIndex) ensureCursorVisible(this);
4802
- }
4803
- }
4804
- }),
4805
-
4806
- // Fetch the parser token for a given character. Useful for hacks
4807
- // that want to inspect the mode state (say, for completion).
4808
- getTokenAt: function(pos, precise) {
4809
- return takeToken(this, pos, precise);
4810
- },
4811
-
4812
- getLineTokens: function(line, precise) {
4813
- return takeToken(this, Pos(line), precise, true);
4814
- },
4815
-
4816
- getTokenTypeAt: function(pos) {
4817
- pos = clipPos(this.doc, pos);
4818
- var styles = getLineStyles(this, getLine(this.doc, pos.line));
4819
- var before = 0, after = (styles.length - 1) / 2, ch = pos.ch;
4820
- var type;
4821
- if (ch == 0) type = styles[2];
4822
- else for (;;) {
4823
- var mid = (before + after) >> 1;
4824
- if ((mid ? styles[mid * 2 - 1] : 0) >= ch) after = mid;
4825
- else if (styles[mid * 2 + 1] < ch) before = mid + 1;
4826
- else { type = styles[mid * 2 + 2]; break; }
4827
- }
4828
- var cut = type ? type.indexOf("cm-overlay ") : -1;
4829
- return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1);
4830
- },
4831
-
4832
- getModeAt: function(pos) {
4833
- var mode = this.doc.mode;
4834
- if (!mode.innerMode) return mode;
4835
- return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode;
4836
- },
4837
-
4838
- getHelper: function(pos, type) {
4839
- return this.getHelpers(pos, type)[0];
4840
- },
4841
-
4842
- getHelpers: function(pos, type) {
4843
- var found = [];
4844
- if (!helpers.hasOwnProperty(type)) return found;
4845
- var help = helpers[type], mode = this.getModeAt(pos);
4846
- if (typeof mode[type] == "string") {
4847
- if (help[mode[type]]) found.push(help[mode[type]]);
4848
- } else if (mode[type]) {
4849
- for (var i = 0; i < mode[type].length; i++) {
4850
- var val = help[mode[type][i]];
4851
- if (val) found.push(val);
4852
- }
4853
- } else if (mode.helperType && help[mode.helperType]) {
4854
- found.push(help[mode.helperType]);
4855
- } else if (help[mode.name]) {
4856
- found.push(help[mode.name]);
4857
- }
4858
- for (var i = 0; i < help._global.length; i++) {
4859
- var cur = help._global[i];
4860
- if (cur.pred(mode, this) && indexOf(found, cur.val) == -1)
4861
- found.push(cur.val);
4862
- }
4863
- return found;
4864
- },
4865
-
4866
- getStateAfter: function(line, precise) {
4867
- var doc = this.doc;
4868
- line = clipLine(doc, line == null ? doc.first + doc.size - 1: line);
4869
- return getStateBefore(this, line + 1, precise);
4870
- },
4871
-
4872
- cursorCoords: function(start, mode) {
4873
- var pos, range = this.doc.sel.primary();
4874
- if (start == null) pos = range.head;
4875
- else if (typeof start == "object") pos = clipPos(this.doc, start);
4876
- else pos = start ? range.from() : range.to();
4877
- return cursorCoords(this, pos, mode || "page");
4878
- },
4879
-
4880
- charCoords: function(pos, mode) {
4881
- return charCoords(this, clipPos(this.doc, pos), mode || "page");
4882
- },
4883
-
4884
- coordsChar: function(coords, mode) {
4885
- coords = fromCoordSystem(this, coords, mode || "page");
4886
- return coordsChar(this, coords.left, coords.top);
4887
- },
4888
-
4889
- lineAtHeight: function(height, mode) {
4890
- height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top;
4891
- return lineAtHeight(this.doc, height + this.display.viewOffset);
4892
- },
4893
- heightAtLine: function(line, mode) {
4894
- var end = false, last = this.doc.first + this.doc.size - 1;
4895
- if (line < this.doc.first) line = this.doc.first;
4896
- else if (line > last) { line = last; end = true; }
4897
- var lineObj = getLine(this.doc, line);
4898
- return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page").top +
4899
- (end ? this.doc.height - heightAtLine(lineObj) : 0);
4900
- },
4901
-
4902
- defaultTextHeight: function() { return textHeight(this.display); },
4903
- defaultCharWidth: function() { return charWidth(this.display); },
4904
-
4905
- setGutterMarker: methodOp(function(line, gutterID, value) {
4906
- return changeLine(this.doc, line, "gutter", function(line) {
4907
- var markers = line.gutterMarkers || (line.gutterMarkers = {});
4908
- markers[gutterID] = value;
4909
- if (!value && isEmpty(markers)) line.gutterMarkers = null;
4910
- return true;
4911
- });
4912
- }),
4913
-
4914
- clearGutter: methodOp(function(gutterID) {
4915
- var cm = this, doc = cm.doc, i = doc.first;
4916
- doc.iter(function(line) {
4917
- if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
4918
- line.gutterMarkers[gutterID] = null;
4919
- regLineChange(cm, i, "gutter");
4920
- if (isEmpty(line.gutterMarkers)) line.gutterMarkers = null;
4921
- }
4922
- ++i;
4923
- });
4924
- }),
4925
-
4926
- addLineWidget: methodOp(function(handle, node, options) {
4927
- return addLineWidget(this, handle, node, options);
4928
- }),
4929
-
4930
- removeLineWidget: function(widget) { widget.clear(); },
4931
-
4932
- lineInfo: function(line) {
4933
- if (typeof line == "number") {
4934
- if (!isLine(this.doc, line)) return null;
4935
- var n = line;
4936
- line = getLine(this.doc, line);
4937
- if (!line) return null;
4938
- } else {
4939
- var n = lineNo(line);
4940
- if (n == null) return null;
4941
- }
4942
- return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
4943
- textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
4944
- widgets: line.widgets};
4945
- },
4946
-
4947
- getViewport: function() { return {from: this.display.viewFrom, to: this.display.viewTo};},
4948
-
4949
- addWidget: function(pos, node, scroll, vert, horiz) {
4950
- var display = this.display;
4951
- pos = cursorCoords(this, clipPos(this.doc, pos));
4952
- var top = pos.bottom, left = pos.left;
4953
- node.style.position = "absolute";
4954
- node.setAttribute("cm-ignore-events", "true");
4955
- this.display.input.setUneditable(node);
4956
- display.sizer.appendChild(node);
4957
- if (vert == "over") {
4958
- top = pos.top;
4959
- } else if (vert == "above" || vert == "near") {
4960
- var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),
4961
- hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth);
4962
- // Default to positioning above (if specified and possible); otherwise default to positioning below
4963
- if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight)
4964
- top = pos.top - node.offsetHeight;
4965
- else if (pos.bottom + node.offsetHeight <= vspace)
4966
- top = pos.bottom;
4967
- if (left + node.offsetWidth > hspace)
4968
- left = hspace - node.offsetWidth;
4969
- }
4970
- node.style.top = top + "px";
4971
- node.style.left = node.style.right = "";
4972
- if (horiz == "right") {
4973
- left = display.sizer.clientWidth - node.offsetWidth;
4974
- node.style.right = "0px";
4975
- } else {
4976
- if (horiz == "left") left = 0;
4977
- else if (horiz == "middle") left = (display.sizer.clientWidth - node.offsetWidth) / 2;
4978
- node.style.left = left + "px";
4979
- }
4980
- if (scroll)
4981
- scrollIntoView(this, left, top, left + node.offsetWidth, top + node.offsetHeight);
4982
- },
4983
-
4984
- triggerOnKeyDown: methodOp(onKeyDown),
4985
- triggerOnKeyPress: methodOp(onKeyPress),
4986
- triggerOnKeyUp: onKeyUp,
4987
-
4988
- execCommand: function(cmd) {
4989
- if (commands.hasOwnProperty(cmd))
4990
- return commands[cmd](this);
4991
- },
4992
-
4993
- findPosH: function(from, amount, unit, visually) {
4994
- var dir = 1;
4995
- if (amount < 0) { dir = -1; amount = -amount; }
4996
- for (var i = 0, cur = clipPos(this.doc, from); i < amount; ++i) {
4997
- cur = findPosH(this.doc, cur, dir, unit, visually);
4998
- if (cur.hitSide) break;
4999
- }
5000
- return cur;
5001
- },
5002
-
5003
- moveH: methodOp(function(dir, unit) {
5004
- var cm = this;
5005
- cm.extendSelectionsBy(function(range) {
5006
- if (cm.display.shift || cm.doc.extend || range.empty())
5007
- return findPosH(cm.doc, range.head, dir, unit, cm.options.rtlMoveVisually);
5008
- else
5009
- return dir < 0 ? range.from() : range.to();
5010
- }, sel_move);
5011
- }),
5012
-
5013
- deleteH: methodOp(function(dir, unit) {
5014
- var sel = this.doc.sel, doc = this.doc;
5015
- if (sel.somethingSelected())
5016
- doc.replaceSelection("", null, "+delete");
5017
- else
5018
- deleteNearSelection(this, function(range) {
5019
- var other = findPosH(doc, range.head, dir, unit, false);
5020
- return dir < 0 ? {from: other, to: range.head} : {from: range.head, to: other};
5021
- });
5022
- }),
5023
-
5024
- findPosV: function(from, amount, unit, goalColumn) {
5025
- var dir = 1, x = goalColumn;
5026
- if (amount < 0) { dir = -1; amount = -amount; }
5027
- for (var i = 0, cur = clipPos(this.doc, from); i < amount; ++i) {
5028
- var coords = cursorCoords(this, cur, "div");
5029
- if (x == null) x = coords.left;
5030
- else coords.left = x;
5031
- cur = findPosV(this, coords, dir, unit);
5032
- if (cur.hitSide) break;
5033
- }
5034
- return cur;
5035
- },
5036
-
5037
- moveV: methodOp(function(dir, unit) {
5038
- var cm = this, doc = this.doc, goals = [];
5039
- var collapse = !cm.display.shift && !doc.extend && doc.sel.somethingSelected();
5040
- doc.extendSelectionsBy(function(range) {
5041
- if (collapse)
5042
- return dir < 0 ? range.from() : range.to();
5043
- var headPos = cursorCoords(cm, range.head, "div");
5044
- if (range.goalColumn != null) headPos.left = range.goalColumn;
5045
- goals.push(headPos.left);
5046
- var pos = findPosV(cm, headPos, dir, unit);
5047
- if (unit == "page" && range == doc.sel.primary())
5048
- addToScrollPos(cm, null, charCoords(cm, pos, "div").top - headPos.top);
5049
- return pos;
5050
- }, sel_move);
5051
- if (goals.length) for (var i = 0; i < doc.sel.ranges.length; i++)
5052
- doc.sel.ranges[i].goalColumn = goals[i];
5053
- }),
5054
-
5055
- // Find the word at the given position (as returned by coordsChar).
5056
- findWordAt: function(pos) {
5057
- var doc = this.doc, line = getLine(doc, pos.line).text;
5058
- var start = pos.ch, end = pos.ch;
5059
- if (line) {
5060
- var helper = this.getHelper(pos, "wordChars");
5061
- if ((pos.xRel < 0 || end == line.length) && start) --start; else ++end;
5062
- var startChar = line.charAt(start);
5063
- var check = isWordChar(startChar, helper)
5064
- ? function(ch) { return isWordChar(ch, helper); }
5065
- : /\s/.test(startChar) ? function(ch) {return /\s/.test(ch);}
5066
- : function(ch) {return !/\s/.test(ch) && !isWordChar(ch);};
5067
- while (start > 0 && check(line.charAt(start - 1))) --start;
5068
- while (end < line.length && check(line.charAt(end))) ++end;
5069
- }
5070
- return new Range(Pos(pos.line, start), Pos(pos.line, end));
5071
- },
5072
-
5073
- toggleOverwrite: function(value) {
5074
- if (value != null && value == this.state.overwrite) return;
5075
- if (this.state.overwrite = !this.state.overwrite)
5076
- addClass(this.display.cursorDiv, "CodeMirror-overwrite");
5077
- else
5078
- rmClass(this.display.cursorDiv, "CodeMirror-overwrite");
5079
-
5080
- signal(this, "overwriteToggle", this, this.state.overwrite);
5081
- },
5082
- hasFocus: function() { return this.display.input.getField() == activeElt(); },
5083
-
5084
- scrollTo: methodOp(function(x, y) {
5085
- if (x != null || y != null) resolveScrollToPos(this);
5086
- if (x != null) this.curOp.scrollLeft = x;
5087
- if (y != null) this.curOp.scrollTop = y;
5088
- }),
5089
- getScrollInfo: function() {
5090
- var scroller = this.display.scroller;
5091
- return {left: scroller.scrollLeft, top: scroller.scrollTop,
5092
- height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight,
5093
- width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth,
5094
- clientHeight: displayHeight(this), clientWidth: displayWidth(this)};
5095
- },
5096
-
5097
- scrollIntoView: methodOp(function(range, margin) {
5098
- if (range == null) {
5099
- range = {from: this.doc.sel.primary().head, to: null};
5100
- if (margin == null) margin = this.options.cursorScrollMargin;
5101
- } else if (typeof range == "number") {
5102
- range = {from: Pos(range, 0), to: null};
5103
- } else if (range.from == null) {
5104
- range = {from: range, to: null};
5105
- }
5106
- if (!range.to) range.to = range.from;
5107
- range.margin = margin || 0;
5108
-
5109
- if (range.from.line != null) {
5110
- resolveScrollToPos(this);
5111
- this.curOp.scrollToPos = range;
5112
- } else {
5113
- var sPos = calculateScrollPos(this, Math.min(range.from.left, range.to.left),
5114
- Math.min(range.from.top, range.to.top) - range.margin,
5115
- Math.max(range.from.right, range.to.right),
5116
- Math.max(range.from.bottom, range.to.bottom) + range.margin);
5117
- this.scrollTo(sPos.scrollLeft, sPos.scrollTop);
5118
- }
5119
- }),
5120
-
5121
- setSize: methodOp(function(width, height) {
5122
- var cm = this;
5123
- function interpret(val) {
5124
- return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val;
5125
- }
5126
- if (width != null) cm.display.wrapper.style.width = interpret(width);
5127
- if (height != null) cm.display.wrapper.style.height = interpret(height);
5128
- if (cm.options.lineWrapping) clearLineMeasurementCache(this);
5129
- var lineNo = cm.display.viewFrom;
5130
- cm.doc.iter(lineNo, cm.display.viewTo, function(line) {
5131
- if (line.widgets) for (var i = 0; i < line.widgets.length; i++)
5132
- if (line.widgets[i].noHScroll) { regLineChange(cm, lineNo, "widget"); break; }
5133
- ++lineNo;
5134
- });
5135
- cm.curOp.forceUpdate = true;
5136
- signal(cm, "refresh", this);
5137
- }),
5138
-
5139
- operation: function(f){return runInOp(this, f);},
5140
-
5141
- refresh: methodOp(function() {
5142
- var oldHeight = this.display.cachedTextHeight;
5143
- regChange(this);
5144
- this.curOp.forceUpdate = true;
5145
- clearCaches(this);
5146
- this.scrollTo(this.doc.scrollLeft, this.doc.scrollTop);
5147
- updateGutterSpace(this);
5148
- if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5)
5149
- estimateLineHeights(this);
5150
- signal(this, "refresh", this);
5151
- }),
5152
-
5153
- swapDoc: methodOp(function(doc) {
5154
- var old = this.doc;
5155
- old.cm = null;
5156
- attachDoc(this, doc);
5157
- clearCaches(this);
5158
- this.display.input.reset();
5159
- this.scrollTo(doc.scrollLeft, doc.scrollTop);
5160
- this.curOp.forceScroll = true;
5161
- signalLater(this, "swapDoc", this, old);
5162
- return old;
5163
- }),
5164
-
5165
- getInputField: function(){return this.display.input.getField();},
5166
- getWrapperElement: function(){return this.display.wrapper;},
5167
- getScrollerElement: function(){return this.display.scroller;},
5168
- getGutterElement: function(){return this.display.gutters;}
5169
- };
5170
- eventMixin(CodeMirror);
5171
-
5172
- // OPTION DEFAULTS
5173
-
5174
- // The default configuration options.
5175
- var defaults = CodeMirror.defaults = {};
5176
- // Functions to run when options are changed.
5177
- var optionHandlers = CodeMirror.optionHandlers = {};
5178
-
5179
- function option(name, deflt, handle, notOnInit) {
5180
- CodeMirror.defaults[name] = deflt;
5181
- if (handle) optionHandlers[name] =
5182
- notOnInit ? function(cm, val, old) {if (old != Init) handle(cm, val, old);} : handle;
5183
- }
5184
-
5185
- // Passed to option handlers when there is no old value.
5186
- var Init = CodeMirror.Init = {toString: function(){return "CodeMirror.Init";}};
5187
-
5188
- // These two are, on init, called from the constructor because they
5189
- // have to be initialized before the editor can start at all.
5190
- option("value", "", function(cm, val) {
5191
- cm.setValue(val);
5192
- }, true);
5193
- option("mode", null, function(cm, val) {
5194
- cm.doc.modeOption = val;
5195
- loadMode(cm);
5196
- }, true);
5197
-
5198
- option("indentUnit", 2, loadMode, true);
5199
- option("indentWithTabs", false);
5200
- option("smartIndent", true);
5201
- option("tabSize", 4, function(cm) {
5202
- resetModeState(cm);
5203
- clearCaches(cm);
5204
- regChange(cm);
5205
- }, true);
5206
- option("specialChars", /[\t\u0000-\u0019\u00ad\u200b-\u200f\u2028\u2029\ufeff]/g, function(cm, val, old) {
5207
- cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g");
5208
- if (old != CodeMirror.Init) cm.refresh();
5209
- });
5210
- option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function(cm) {cm.refresh();}, true);
5211
- option("electricChars", true);
5212
- option("inputStyle", mobile ? "contenteditable" : "textarea", function() {
5213
- throw new Error("inputStyle can not (yet) be changed in a running editor"); // FIXME
5214
- }, true);
5215
- option("rtlMoveVisually", !windows);
5216
- option("wholeLineUpdateBefore", true);
5217
-
5218
- option("theme", "default", function(cm) {
5219
- themeChanged(cm);
5220
- guttersChanged(cm);
5221
- }, true);
5222
- option("keyMap", "default", function(cm, val, old) {
5223
- var next = getKeyMap(val);
5224
- var prev = old != CodeMirror.Init && getKeyMap(old);
5225
- if (prev && prev.detach) prev.detach(cm, next);
5226
- if (next.attach) next.attach(cm, prev || null);
5227
- });
5228
- option("extraKeys", null);
5229
-
5230
- option("lineWrapping", false, wrappingChanged, true);
5231
- option("gutters", [], function(cm) {
5232
- setGuttersForLineNumbers(cm.options);
5233
- guttersChanged(cm);
5234
- }, true);
5235
- option("fixedGutter", true, function(cm, val) {
5236
- cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0";
5237
- cm.refresh();
5238
- }, true);
5239
- option("coverGutterNextToScrollbar", false, function(cm) {updateScrollbars(cm);}, true);
5240
- option("scrollbarStyle", "native", function(cm) {
5241
- initScrollbars(cm);
5242
- updateScrollbars(cm);
5243
- cm.display.scrollbars.setScrollTop(cm.doc.scrollTop);
5244
- cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft);
5245
- }, true);
5246
- option("lineNumbers", false, function(cm) {
5247
- setGuttersForLineNumbers(cm.options);
5248
- guttersChanged(cm);
5249
- }, true);
5250
- option("firstLineNumber", 1, guttersChanged, true);
5251
- option("lineNumberFormatter", function(integer) {return integer;}, guttersChanged, true);
5252
- option("showCursorWhenSelecting", false, updateSelection, true);
5253
-
5254
- option("resetSelectionOnContextMenu", true);
5255
-
5256
- option("readOnly", false, function(cm, val) {
5257
- if (val == "nocursor") {
5258
- onBlur(cm);
5259
- cm.display.input.blur();
5260
- cm.display.disabled = true;
5261
- } else {
5262
- cm.display.disabled = false;
5263
- if (!val) cm.display.input.reset();
5264
- }
5265
- });
5266
- option("disableInput", false, function(cm, val) {if (!val) cm.display.input.reset();}, true);
5267
- option("dragDrop", true);
5268
-
5269
- option("cursorBlinkRate", 530);
5270
- option("cursorScrollMargin", 0);
5271
- option("cursorHeight", 1, updateSelection, true);
5272
- option("singleCursorHeightPerLine", true, updateSelection, true);
5273
- option("workTime", 100);
5274
- option("workDelay", 100);
5275
- option("flattenSpans", true, resetModeState, true);
5276
- option("addModeClass", false, resetModeState, true);
5277
- option("pollInterval", 100);
5278
- option("undoDepth", 200, function(cm, val){cm.doc.history.undoDepth = val;});
5279
- option("historyEventDelay", 1250);
5280
- option("viewportMargin", 10, function(cm){cm.refresh();}, true);
5281
- option("maxHighlightLength", 10000, resetModeState, true);
5282
- option("moveInputWithCursor", true, function(cm, val) {
5283
- if (!val) cm.display.input.resetPosition();
5284
- });
5285
-
5286
- option("tabindex", null, function(cm, val) {
5287
- cm.display.input.getField().tabIndex = val || "";
5288
- });
5289
- option("autofocus", null);
5290
-
5291
- // MODE DEFINITION AND QUERYING
5292
-
5293
- // Known modes, by name and by MIME
5294
- var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {};
5295
-
5296
- // Extra arguments are stored as the mode's dependencies, which is
5297
- // used by (legacy) mechanisms like loadmode.js to automatically
5298
- // load a mode. (Preferred mechanism is the require/define calls.)
5299
- CodeMirror.defineMode = function(name, mode) {
5300
- if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name;
5301
- if (arguments.length > 2)
5302
- mode.dependencies = Array.prototype.slice.call(arguments, 2);
5303
- modes[name] = mode;
5304
- };
5305
-
5306
- CodeMirror.defineMIME = function(mime, spec) {
5307
- mimeModes[mime] = spec;
5308
- };
5309
-
5310
- // Given a MIME type, a {name, ...options} config object, or a name
5311
- // string, return a mode config object.
5312
- CodeMirror.resolveMode = function(spec) {
5313
- if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
5314
- spec = mimeModes[spec];
5315
- } else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
5316
- var found = mimeModes[spec.name];
5317
- if (typeof found == "string") found = {name: found};
5318
- spec = createObj(found, spec);
5319
- spec.name = found.name;
5320
- } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
5321
- return CodeMirror.resolveMode("application/xml");
5322
- }
5323
- if (typeof spec == "string") return {name: spec};
5324
- else return spec || {name: "null"};
5325
- };
5326
-
5327
- // Given a mode spec (anything that resolveMode accepts), find and
5328
- // initialize an actual mode object.
5329
- CodeMirror.getMode = function(options, spec) {
5330
- var spec = CodeMirror.resolveMode(spec);
5331
- var mfactory = modes[spec.name];
5332
- if (!mfactory) return CodeMirror.getMode(options, "text/plain");
5333
- var modeObj = mfactory(options, spec);
5334
- if (modeExtensions.hasOwnProperty(spec.name)) {
5335
- var exts = modeExtensions[spec.name];
5336
- for (var prop in exts) {
5337
- if (!exts.hasOwnProperty(prop)) continue;
5338
- if (modeObj.hasOwnProperty(prop)) modeObj["_" + prop] = modeObj[prop];
5339
- modeObj[prop] = exts[prop];
5340
- }
5341
- }
5342
- modeObj.name = spec.name;
5343
- if (spec.helperType) modeObj.helperType = spec.helperType;
5344
- if (spec.modeProps) for (var prop in spec.modeProps)
5345
- modeObj[prop] = spec.modeProps[prop];
5346
-
5347
- return modeObj;
5348
- };
5349
-
5350
- // Minimal default mode.
5351
- CodeMirror.defineMode("null", function() {
5352
- return {token: function(stream) {stream.skipToEnd();}};
5353
- });
5354
- CodeMirror.defineMIME("text/plain", "null");
5355
-
5356
- // This can be used to attach properties to mode objects from
5357
- // outside the actual mode definition.
5358
- var modeExtensions = CodeMirror.modeExtensions = {};
5359
- CodeMirror.extendMode = function(mode, properties) {
5360
- var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
5361
- copyObj(properties, exts);
5362
- };
5363
-
5364
- // EXTENSIONS
5365
-
5366
- CodeMirror.defineExtension = function(name, func) {
5367
- CodeMirror.prototype[name] = func;
5368
- };
5369
- CodeMirror.defineDocExtension = function(name, func) {
5370
- Doc.prototype[name] = func;
5371
- };
5372
- CodeMirror.defineOption = option;
5373
-
5374
- var initHooks = [];
5375
- CodeMirror.defineInitHook = function(f) {initHooks.push(f);};
5376
-
5377
- var helpers = CodeMirror.helpers = {};
5378
- CodeMirror.registerHelper = function(type, name, value) {
5379
- if (!helpers.hasOwnProperty(type)) helpers[type] = CodeMirror[type] = {_global: []};
5380
- helpers[type][name] = value;
5381
- };
5382
- CodeMirror.registerGlobalHelper = function(type, name, predicate, value) {
5383
- CodeMirror.registerHelper(type, name, value);
5384
- helpers[type]._global.push({pred: predicate, val: value});
5385
- };
5386
-
5387
- // MODE STATE HANDLING
5388
-
5389
- // Utility functions for working with state. Exported because nested
5390
- // modes need to do this for their inner modes.
5391
-
5392
- var copyState = CodeMirror.copyState = function(mode, state) {
5393
- if (state === true) return state;
5394
- if (mode.copyState) return mode.copyState(state);
5395
- var nstate = {};
5396
- for (var n in state) {
5397
- var val = state[n];
5398
- if (val instanceof Array) val = val.concat([]);
5399
- nstate[n] = val;
5400
- }
5401
- return nstate;
5402
- };
5403
-
5404
- var startState = CodeMirror.startState = function(mode, a1, a2) {
5405
- return mode.startState ? mode.startState(a1, a2) : true;
5406
- };
5407
-
5408
- // Given a mode and a state (for that mode), find the inner mode and
5409
- // state at the position that the state refers to.
5410
- CodeMirror.innerMode = function(mode, state) {
5411
- while (mode.innerMode) {
5412
- var info = mode.innerMode(state);
5413
- if (!info || info.mode == mode) break;
5414
- state = info.state;
5415
- mode = info.mode;
5416
- }
5417
- return info || {mode: mode, state: state};
5418
- };
5419
-
5420
- // STANDARD COMMANDS
5421
-
5422
- // Commands are parameter-less actions that can be performed on an
5423
- // editor, mostly used for keybindings.
5424
- var commands = CodeMirror.commands = {
5425
- selectAll: function(cm) {cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll);},
5426
- singleSelection: function(cm) {
5427
- cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll);
5428
- },
5429
- killLine: function(cm) {
5430
- deleteNearSelection(cm, function(range) {
5431
- if (range.empty()) {
5432
- var len = getLine(cm.doc, range.head.line).text.length;
5433
- if (range.head.ch == len && range.head.line < cm.lastLine())
5434
- return {from: range.head, to: Pos(range.head.line + 1, 0)};
5435
- else
5436
- return {from: range.head, to: Pos(range.head.line, len)};
5437
- } else {
5438
- return {from: range.from(), to: range.to()};
5439
- }
5440
- });
5441
- },
5442
- deleteLine: function(cm) {
5443
- deleteNearSelection(cm, function(range) {
5444
- return {from: Pos(range.from().line, 0),
5445
- to: clipPos(cm.doc, Pos(range.to().line + 1, 0))};
5446
- });
5447
- },
5448
- delLineLeft: function(cm) {
5449
- deleteNearSelection(cm, function(range) {
5450
- return {from: Pos(range.from().line, 0), to: range.from()};
5451
- });
5452
- },
5453
- delWrappedLineLeft: function(cm) {
5454
- deleteNearSelection(cm, function(range) {
5455
- var top = cm.charCoords(range.head, "div").top + 5;
5456
- var leftPos = cm.coordsChar({left: 0, top: top}, "div");
5457
- return {from: leftPos, to: range.from()};
5458
- });
5459
- },
5460
- delWrappedLineRight: function(cm) {
5461
- deleteNearSelection(cm, function(range) {
5462
- var top = cm.charCoords(range.head, "div").top + 5;
5463
- var rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div");
5464
- return {from: range.from(), to: rightPos };
5465
- });
5466
- },
5467
- undo: function(cm) {cm.undo();},
5468
- redo: function(cm) {cm.redo();},
5469
- undoSelection: function(cm) {cm.undoSelection();},
5470
- redoSelection: function(cm) {cm.redoSelection();},
5471
- goDocStart: function(cm) {cm.extendSelection(Pos(cm.firstLine(), 0));},
5472
- goDocEnd: function(cm) {cm.extendSelection(Pos(cm.lastLine()));},
5473
- goLineStart: function(cm) {
5474
- cm.extendSelectionsBy(function(range) { return lineStart(cm, range.head.line); },
5475
- {origin: "+move", bias: 1});
5476
- },
5477
- goLineStartSmart: function(cm) {
5478
- cm.extendSelectionsBy(function(range) {
5479
- return lineStartSmart(cm, range.head);
5480
- }, {origin: "+move", bias: 1});
5481
- },
5482
- goLineEnd: function(cm) {
5483
- cm.extendSelectionsBy(function(range) { return lineEnd(cm, range.head.line); },
5484
- {origin: "+move", bias: -1});
5485
- },
5486
- goLineRight: function(cm) {
5487
- cm.extendSelectionsBy(function(range) {
5488
- var top = cm.charCoords(range.head, "div").top + 5;
5489
- return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div");
5490
- }, sel_move);
5491
- },
5492
- goLineLeft: function(cm) {
5493
- cm.extendSelectionsBy(function(range) {
5494
- var top = cm.charCoords(range.head, "div").top + 5;
5495
- return cm.coordsChar({left: 0, top: top}, "div");
5496
- }, sel_move);
5497
- },
5498
- goLineLeftSmart: function(cm) {
5499
- cm.extendSelectionsBy(function(range) {
5500
- var top = cm.charCoords(range.head, "div").top + 5;
5501
- var pos = cm.coordsChar({left: 0, top: top}, "div");
5502
- if (pos.ch < cm.getLine(pos.line).search(/\S/)) return lineStartSmart(cm, range.head);
5503
- return pos;
5504
- }, sel_move);
5505
- },
5506
- goLineUp: function(cm) {cm.moveV(-1, "line");},
5507
- goLineDown: function(cm) {cm.moveV(1, "line");},
5508
- goPageUp: function(cm) {cm.moveV(-1, "page");},
5509
- goPageDown: function(cm) {cm.moveV(1, "page");},
5510
- goCharLeft: function(cm) {cm.moveH(-1, "char");},
5511
- goCharRight: function(cm) {cm.moveH(1, "char");},
5512
- goColumnLeft: function(cm) {cm.moveH(-1, "column");},
5513
- goColumnRight: function(cm) {cm.moveH(1, "column");},
5514
- goWordLeft: function(cm) {cm.moveH(-1, "word");},
5515
- goGroupRight: function(cm) {cm.moveH(1, "group");},
5516
- goGroupLeft: function(cm) {cm.moveH(-1, "group");},
5517
- goWordRight: function(cm) {cm.moveH(1, "word");},
5518
- delCharBefore: function(cm) {cm.deleteH(-1, "char");},
5519
- delCharAfter: function(cm) {cm.deleteH(1, "char");},
5520
- delWordBefore: function(cm) {cm.deleteH(-1, "word");},
5521
- delWordAfter: function(cm) {cm.deleteH(1, "word");},
5522
- delGroupBefore: function(cm) {cm.deleteH(-1, "group");},
5523
- delGroupAfter: function(cm) {cm.deleteH(1, "group");},
5524
- indentAuto: function(cm) {cm.indentSelection("smart");},
5525
- indentMore: function(cm) {cm.indentSelection("add");},
5526
- indentLess: function(cm) {cm.indentSelection("subtract");},
5527
- insertTab: function(cm) {cm.replaceSelection("\t");},
5528
- insertSoftTab: function(cm) {
5529
- var spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize;
5530
- for (var i = 0; i < ranges.length; i++) {
5531
- var pos = ranges[i].from();
5532
- var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize);
5533
- spaces.push(new Array(tabSize - col % tabSize + 1).join(" "));
5534
- }
5535
- cm.replaceSelections(spaces);
5536
- },
5537
- defaultTab: function(cm) {
5538
- if (cm.somethingSelected()) cm.indentSelection("add");
5539
- else cm.execCommand("insertTab");
5540
- },
5541
- transposeChars: function(cm) {
5542
- runInOp(cm, function() {
5543
- var ranges = cm.listSelections(), newSel = [];
5544
- for (var i = 0; i < ranges.length; i++) {
5545
- var cur = ranges[i].head, line = getLine(cm.doc, cur.line).text;
5546
- if (line) {
5547
- if (cur.ch == line.length) cur = new Pos(cur.line, cur.ch - 1);
5548
- if (cur.ch > 0) {
5549
- cur = new Pos(cur.line, cur.ch + 1);
5550
- cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
5551
- Pos(cur.line, cur.ch - 2), cur, "+transpose");
5552
- } else if (cur.line > cm.doc.first) {
5553
- var prev = getLine(cm.doc, cur.line - 1).text;
5554
- if (prev)
5555
- cm.replaceRange(line.charAt(0) + "\n" + prev.charAt(prev.length - 1),
5556
- Pos(cur.line - 1, prev.length - 1), Pos(cur.line, 1), "+transpose");
5557
- }
5558
- }
5559
- newSel.push(new Range(cur, cur));
5560
- }
5561
- cm.setSelections(newSel);
5562
- });
5563
- },
5564
- newlineAndIndent: function(cm) {
5565
- runInOp(cm, function() {
5566
- var len = cm.listSelections().length;
5567
- for (var i = 0; i < len; i++) {
5568
- var range = cm.listSelections()[i];
5569
- cm.replaceRange("\n", range.anchor, range.head, "+input");
5570
- cm.indentLine(range.from().line + 1, null, true);
5571
- ensureCursorVisible(cm);
5572
- }
5573
- });
5574
- },
5575
- toggleOverwrite: function(cm) {cm.toggleOverwrite();}
5576
- };
5577
-
5578
-
5579
- // STANDARD KEYMAPS
5580
-
5581
- var keyMap = CodeMirror.keyMap = {};
5582
-
5583
- keyMap.basic = {
5584
- "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
5585
- "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
5586
- "Delete": "delCharAfter", "Backspace": "delCharBefore", "Shift-Backspace": "delCharBefore",
5587
- "Tab": "defaultTab", "Shift-Tab": "indentAuto",
5588
- "Enter": "newlineAndIndent", "Insert": "toggleOverwrite",
5589
- "Esc": "singleSelection"
5590
- };
5591
- // Note that the save and find-related commands aren't defined by
5592
- // default. User code or addons can define them. Unknown commands
5593
- // are simply ignored.
5594
- keyMap.pcDefault = {
5595
- "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
5596
- "Ctrl-Home": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Up": "goLineUp", "Ctrl-Down": "goLineDown",
5597
- "Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
5598
- "Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find",
5599
- "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
5600
- "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
5601
- "Ctrl-U": "undoSelection", "Shift-Ctrl-U": "redoSelection", "Alt-U": "redoSelection",
5602
- fallthrough: "basic"
5603
- };
5604
- // Very basic readline/emacs-style bindings, which are standard on Mac.
5605
- keyMap.emacsy = {
5606
- "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
5607
- "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
5608
- "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
5609
- "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars"
5610
- };
5611
- keyMap.macDefault = {
5612
- "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
5613
- "Cmd-Home": "goDocStart", "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
5614
- "Alt-Right": "goGroupRight", "Cmd-Left": "goLineLeft", "Cmd-Right": "goLineRight", "Alt-Backspace": "delGroupBefore",
5615
- "Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find",
5616
- "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
5617
- "Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight",
5618
- "Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Ctrl-Up": "goDocStart", "Ctrl-Down": "goDocEnd",
5619
- fallthrough: ["basic", "emacsy"]
5620
- };
5621
- keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
5622
-
5623
- // KEYMAP DISPATCH
5624
-
5625
- function normalizeKeyName(name) {
5626
- var parts = name.split(/-(?!$)/), name = parts[parts.length - 1];
5627
- var alt, ctrl, shift, cmd;
5628
- for (var i = 0; i < parts.length - 1; i++) {
5629
- var mod = parts[i];
5630
- if (/^(cmd|meta|m)$/i.test(mod)) cmd = true;
5631
- else if (/^a(lt)?$/i.test(mod)) alt = true;
5632
- else if (/^(c|ctrl|control)$/i.test(mod)) ctrl = true;
5633
- else if (/^s(hift)$/i.test(mod)) shift = true;
5634
- else throw new Error("Unrecognized modifier name: " + mod);
5635
- }
5636
- if (alt) name = "Alt-" + name;
5637
- if (ctrl) name = "Ctrl-" + name;
5638
- if (cmd) name = "Cmd-" + name;
5639
- if (shift) name = "Shift-" + name;
5640
- return name;
5641
- }
5642
-
5643
- // This is a kludge to keep keymaps mostly working as raw objects
5644
- // (backwards compatibility) while at the same time support features
5645
- // like normalization and multi-stroke key bindings. It compiles a
5646
- // new normalized keymap, and then updates the old object to reflect
5647
- // this.
5648
- CodeMirror.normalizeKeyMap = function(keymap) {
5649
- var copy = {};
5650
- for (var keyname in keymap) if (keymap.hasOwnProperty(keyname)) {
5651
- var value = keymap[keyname];
5652
- if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) continue;
5653
- if (value == "...") { delete keymap[keyname]; continue; }
5654
-
5655
- var keys = map(keyname.split(" "), normalizeKeyName);
5656
- for (var i = 0; i < keys.length; i++) {
5657
- var val, name;
5658
- if (i == keys.length - 1) {
5659
- name = keyname;
5660
- val = value;
5661
- } else {
5662
- name = keys.slice(0, i + 1).join(" ");
5663
- val = "...";
5664
- }
5665
- var prev = copy[name];
5666
- if (!prev) copy[name] = val;
5667
- else if (prev != val) throw new Error("Inconsistent bindings for " + name);
5668
- }
5669
- delete keymap[keyname];
5670
- }
5671
- for (var prop in copy) keymap[prop] = copy[prop];
5672
- return keymap;
5673
- };
5674
-
5675
- var lookupKey = CodeMirror.lookupKey = function(key, map, handle, context) {
5676
- map = getKeyMap(map);
5677
- var found = map.call ? map.call(key, context) : map[key];
5678
- if (found === false) return "nothing";
5679
- if (found === "...") return "multi";
5680
- if (found != null && handle(found)) return "handled";
5681
-
5682
- if (map.fallthrough) {
5683
- if (Object.prototype.toString.call(map.fallthrough) != "[object Array]")
5684
- return lookupKey(key, map.fallthrough, handle, context);
5685
- for (var i = 0; i < map.fallthrough.length; i++) {
5686
- var result = lookupKey(key, map.fallthrough[i], handle, context);
5687
- if (result) return result;
5688
- }
5689
- }
5690
- };
5691
-
5692
- // Modifier key presses don't count as 'real' key presses for the
5693
- // purpose of keymap fallthrough.
5694
- var isModifierKey = CodeMirror.isModifierKey = function(value) {
5695
- var name = typeof value == "string" ? value : keyNames[value.keyCode];
5696
- return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod";
5697
- };
5698
-
5699
- // Look up the name of a key as indicated by an event object.
5700
- var keyName = CodeMirror.keyName = function(event, noShift) {
5701
- if (presto && event.keyCode == 34 && event["char"]) return false;
5702
- var base = keyNames[event.keyCode], name = base;
5703
- if (name == null || event.altGraphKey) return false;
5704
- if (event.altKey && base != "Alt") name = "Alt-" + name;
5705
- if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") name = "Ctrl-" + name;
5706
- if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Cmd") name = "Cmd-" + name;
5707
- if (!noShift && event.shiftKey && base != "Shift") name = "Shift-" + name;
5708
- return name;
5709
- };
5710
-
5711
- function getKeyMap(val) {
5712
- return typeof val == "string" ? keyMap[val] : val;
5713
- }
5714
-
5715
- // FROMTEXTAREA
5716
-
5717
- CodeMirror.fromTextArea = function(textarea, options) {
5718
- options = options ? copyObj(options) : {};
5719
- options.value = textarea.value;
5720
- if (!options.tabindex && textarea.tabIndex)
5721
- options.tabindex = textarea.tabIndex;
5722
- if (!options.placeholder && textarea.placeholder)
5723
- options.placeholder = textarea.placeholder;
5724
- // Set autofocus to true if this textarea is focused, or if it has
5725
- // autofocus and no other element is focused.
5726
- if (options.autofocus == null) {
5727
- var hasFocus = activeElt();
5728
- options.autofocus = hasFocus == textarea ||
5729
- textarea.getAttribute("autofocus") != null && hasFocus == document.body;
5730
- }
5731
-
5732
- function save() {textarea.value = cm.getValue();}
5733
- if (textarea.form) {
5734
- on(textarea.form, "submit", save);
5735
- // Deplorable hack to make the submit method do the right thing.
5736
- if (!options.leaveSubmitMethodAlone) {
5737
- var form = textarea.form, realSubmit = form.submit;
5738
- try {
5739
- var wrappedSubmit = form.submit = function() {
5740
- save();
5741
- form.submit = realSubmit;
5742
- form.submit();
5743
- form.submit = wrappedSubmit;
5744
- };
5745
- } catch(e) {}
5746
- }
5747
- }
5748
-
5749
- options.finishInit = function(cm) {
5750
- cm.save = save;
5751
- cm.getTextArea = function() { return textarea; };
5752
- cm.toTextArea = function() {
5753
- cm.toTextArea = isNaN; // Prevent this from being ran twice
5754
- save();
5755
- textarea.parentNode.removeChild(cm.getWrapperElement());
5756
- textarea.style.display = "";
5757
- if (textarea.form) {
5758
- off(textarea.form, "submit", save);
5759
- if (typeof textarea.form.submit == "function")
5760
- textarea.form.submit = realSubmit;
5761
- }
5762
- };
5763
- };
5764
-
5765
- textarea.style.display = "none";
5766
- var cm = CodeMirror(function(node) {
5767
- textarea.parentNode.insertBefore(node, textarea.nextSibling);
5768
- }, options);
5769
- return cm;
5770
- };
5771
-
5772
- // STRING STREAM
5773
-
5774
- // Fed to the mode parsers, provides helper functions to make
5775
- // parsers more succinct.
5776
-
5777
- var StringStream = CodeMirror.StringStream = function(string, tabSize) {
5778
- this.pos = this.start = 0;
5779
- this.string = string;
5780
- this.tabSize = tabSize || 8;
5781
- this.lastColumnPos = this.lastColumnValue = 0;
5782
- this.lineStart = 0;
5783
- };
5784
-
5785
- StringStream.prototype = {
5786
- eol: function() {return this.pos >= this.string.length;},
5787
- sol: function() {return this.pos == this.lineStart;},
5788
- peek: function() {return this.string.charAt(this.pos) || undefined;},
5789
- next: function() {
5790
- if (this.pos < this.string.length)
5791
- return this.string.charAt(this.pos++);
5792
- },
5793
- eat: function(match) {
5794
- var ch = this.string.charAt(this.pos);
5795
- if (typeof match == "string") var ok = ch == match;
5796
- else var ok = ch && (match.test ? match.test(ch) : match(ch));
5797
- if (ok) {++this.pos; return ch;}
5798
- },
5799
- eatWhile: function(match) {
5800
- var start = this.pos;
5801
- while (this.eat(match)){}
5802
- return this.pos > start;
5803
- },
5804
- eatSpace: function() {
5805
- var start = this.pos;
5806
- while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
5807
- return this.pos > start;
5808
- },
5809
- skipToEnd: function() {this.pos = this.string.length;},
5810
- skipTo: function(ch) {
5811
- var found = this.string.indexOf(ch, this.pos);
5812
- if (found > -1) {this.pos = found; return true;}
5813
- },
5814
- backUp: function(n) {this.pos -= n;},
5815
- column: function() {
5816
- if (this.lastColumnPos < this.start) {
5817
- this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);
5818
- this.lastColumnPos = this.start;
5819
- }
5820
- return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0);
5821
- },
5822
- indentation: function() {
5823
- return countColumn(this.string, null, this.tabSize) -
5824
- (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0);
5825
- },
5826
- match: function(pattern, consume, caseInsensitive) {
5827
- if (typeof pattern == "string") {
5828
- var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
5829
- var substr = this.string.substr(this.pos, pattern.length);
5830
- if (cased(substr) == cased(pattern)) {
5831
- if (consume !== false) this.pos += pattern.length;
5832
- return true;
5833
- }
5834
- } else {
5835
- var match = this.string.slice(this.pos).match(pattern);
5836
- if (match && match.index > 0) return null;
5837
- if (match && consume !== false) this.pos += match[0].length;
5838
- return match;
5839
- }
5840
- },
5841
- current: function(){return this.string.slice(this.start, this.pos);},
5842
- hideFirstChars: function(n, inner) {
5843
- this.lineStart += n;
5844
- try { return inner(); }
5845
- finally { this.lineStart -= n; }
5846
- }
5847
- };
5848
-
5849
- // TEXTMARKERS
5850
-
5851
- // Created with markText and setBookmark methods. A TextMarker is a
5852
- // handle that can be used to clear or find a marked position in the
5853
- // document. Line objects hold arrays (markedSpans) containing
5854
- // {from, to, marker} object pointing to such marker objects, and
5855
- // indicating that such a marker is present on that line. Multiple
5856
- // lines may point to the same marker when it spans across lines.
5857
- // The spans will have null for their from/to properties when the
5858
- // marker continues beyond the start/end of the line. Markers have
5859
- // links back to the lines they currently touch.
5860
-
5861
- var nextMarkerId = 0;
5862
-
5863
- var TextMarker = CodeMirror.TextMarker = function(doc, type) {
5864
- this.lines = [];
5865
- this.type = type;
5866
- this.doc = doc;
5867
- this.id = ++nextMarkerId;
5868
- };
5869
- eventMixin(TextMarker);
5870
-
5871
- // Clear the marker.
5872
- TextMarker.prototype.clear = function() {
5873
- if (this.explicitlyCleared) return;
5874
- var cm = this.doc.cm, withOp = cm && !cm.curOp;
5875
- if (withOp) startOperation(cm);
5876
- if (hasHandler(this, "clear")) {
5877
- var found = this.find();
5878
- if (found) signalLater(this, "clear", found.from, found.to);
5879
- }
5880
- var min = null, max = null;
5881
- for (var i = 0; i < this.lines.length; ++i) {
5882
- var line = this.lines[i];
5883
- var span = getMarkedSpanFor(line.markedSpans, this);
5884
- if (cm && !this.collapsed) regLineChange(cm, lineNo(line), "text");
5885
- else if (cm) {
5886
- if (span.to != null) max = lineNo(line);
5887
- if (span.from != null) min = lineNo(line);
5888
- }
5889
- line.markedSpans = removeMarkedSpan(line.markedSpans, span);
5890
- if (span.from == null && this.collapsed && !lineIsHidden(this.doc, line) && cm)
5891
- updateLineHeight(line, textHeight(cm.display));
5892
- }
5893
- if (cm && this.collapsed && !cm.options.lineWrapping) for (var i = 0; i < this.lines.length; ++i) {
5894
- var visual = visualLine(this.lines[i]), len = lineLength(visual);
5895
- if (len > cm.display.maxLineLength) {
5896
- cm.display.maxLine = visual;
5897
- cm.display.maxLineLength = len;
5898
- cm.display.maxLineChanged = true;
5899
- }
5900
- }
5901
-
5902
- if (min != null && cm && this.collapsed) regChange(cm, min, max + 1);
5903
- this.lines.length = 0;
5904
- this.explicitlyCleared = true;
5905
- if (this.atomic && this.doc.cantEdit) {
5906
- this.doc.cantEdit = false;
5907
- if (cm) reCheckSelection(cm.doc);
5908
- }
5909
- if (cm) signalLater(cm, "markerCleared", cm, this);
5910
- if (withOp) endOperation(cm);
5911
- if (this.parent) this.parent.clear();
5912
- };
5913
-
5914
- // Find the position of the marker in the document. Returns a {from,
5915
- // to} object by default. Side can be passed to get a specific side
5916
- // -- 0 (both), -1 (left), or 1 (right). When lineObj is true, the
5917
- // Pos objects returned contain a line object, rather than a line
5918
- // number (used to prevent looking up the same line twice).
5919
- TextMarker.prototype.find = function(side, lineObj) {
5920
- if (side == null && this.type == "bookmark") side = 1;
5921
- var from, to;
5922
- for (var i = 0; i < this.lines.length; ++i) {
5923
- var line = this.lines[i];
5924
- var span = getMarkedSpanFor(line.markedSpans, this);
5925
- if (span.from != null) {
5926
- from = Pos(lineObj ? line : lineNo(line), span.from);
5927
- if (side == -1) return from;
5928
- }
5929
- if (span.to != null) {
5930
- to = Pos(lineObj ? line : lineNo(line), span.to);
5931
- if (side == 1) return to;
5932
- }
5933
- }
5934
- return from && {from: from, to: to};
5935
- };
5936
-
5937
- // Signals that the marker's widget changed, and surrounding layout
5938
- // should be recomputed.
5939
- TextMarker.prototype.changed = function() {
5940
- var pos = this.find(-1, true), widget = this, cm = this.doc.cm;
5941
- if (!pos || !cm) return;
5942
- runInOp(cm, function() {
5943
- var line = pos.line, lineN = lineNo(pos.line);
5944
- var view = findViewForLine(cm, lineN);
5945
- if (view) {
5946
- clearLineMeasurementCacheFor(view);
5947
- cm.curOp.selectionChanged = cm.curOp.forceUpdate = true;
5948
- }
5949
- cm.curOp.updateMaxLine = true;
5950
- if (!lineIsHidden(widget.doc, line) && widget.height != null) {
5951
- var oldHeight = widget.height;
5952
- widget.height = null;
5953
- var dHeight = widgetHeight(widget) - oldHeight;
5954
- if (dHeight)
5955
- updateLineHeight(line, line.height + dHeight);
5956
- }
5957
- });
5958
- };
5959
-
5960
- TextMarker.prototype.attachLine = function(line) {
5961
- if (!this.lines.length && this.doc.cm) {
5962
- var op = this.doc.cm.curOp;
5963
- if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1)
5964
- (op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this);
5965
- }
5966
- this.lines.push(line);
5967
- };
5968
- TextMarker.prototype.detachLine = function(line) {
5969
- this.lines.splice(indexOf(this.lines, line), 1);
5970
- if (!this.lines.length && this.doc.cm) {
5971
- var op = this.doc.cm.curOp;
5972
- (op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this);
5973
- }
5974
- };
5975
-
5976
- // Collapsed markers have unique ids, in order to be able to order
5977
- // them, which is needed for uniquely determining an outer marker
5978
- // when they overlap (they may nest, but not partially overlap).
5979
- var nextMarkerId = 0;
5980
-
5981
- // Create a marker, wire it up to the right lines, and
5982
- function markText(doc, from, to, options, type) {
5983
- // Shared markers (across linked documents) are handled separately
5984
- // (markTextShared will call out to this again, once per
5985
- // document).
5986
- if (options && options.shared) return markTextShared(doc, from, to, options, type);
5987
- // Ensure we are in an operation.
5988
- if (doc.cm && !doc.cm.curOp) return operation(doc.cm, markText)(doc, from, to, options, type);
5989
-
5990
- var marker = new TextMarker(doc, type), diff = cmp(from, to);
5991
- if (options) copyObj(options, marker, false);
5992
- // Don't connect empty markers unless clearWhenEmpty is false
5993
- if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
5994
- return marker;
5995
- if (marker.replacedWith) {
5996
- // Showing up as a widget implies collapsed (widget replaces text)
5997
- marker.collapsed = true;
5998
- marker.widgetNode = elt("span", [marker.replacedWith], "CodeMirror-widget");
5999
- if (!options.handleMouseEvents) marker.widgetNode.setAttribute("cm-ignore-events", "true");
6000
- if (options.insertLeft) marker.widgetNode.insertLeft = true;
6001
- }
6002
- if (marker.collapsed) {
6003
- if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
6004
- from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
6005
- throw new Error("Inserting collapsed marker partially overlapping an existing one");
6006
- sawCollapsedSpans = true;
6007
- }
6008
-
6009
- if (marker.addToHistory)
6010
- addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN);
6011
-
6012
- var curLine = from.line, cm = doc.cm, updateMaxLine;
6013
- doc.iter(curLine, to.line + 1, function(line) {
6014
- if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
6015
- updateMaxLine = true;
6016
- if (marker.collapsed && curLine != from.line) updateLineHeight(line, 0);
6017
- addMarkedSpan(line, new MarkedSpan(marker,
6018
- curLine == from.line ? from.ch : null,
6019
- curLine == to.line ? to.ch : null));
6020
- ++curLine;
6021
- });
6022
- // lineIsHidden depends on the presence of the spans, so needs a second pass
6023
- if (marker.collapsed) doc.iter(from.line, to.line + 1, function(line) {
6024
- if (lineIsHidden(doc, line)) updateLineHeight(line, 0);
6025
- });
6026
-
6027
- if (marker.clearOnEnter) on(marker, "beforeCursorEnter", function() { marker.clear(); });
6028
-
6029
- if (marker.readOnly) {
6030
- sawReadOnlySpans = true;
6031
- if (doc.history.done.length || doc.history.undone.length)
6032
- doc.clearHistory();
6033
- }
6034
- if (marker.collapsed) {
6035
- marker.id = ++nextMarkerId;
6036
- marker.atomic = true;
6037
- }
6038
- if (cm) {
6039
- // Sync editor state
6040
- if (updateMaxLine) cm.curOp.updateMaxLine = true;
6041
- if (marker.collapsed)
6042
- regChange(cm, from.line, to.line + 1);
6043
- else if (marker.className || marker.title || marker.startStyle || marker.endStyle || marker.css)
6044
- for (var i = from.line; i <= to.line; i++) regLineChange(cm, i, "text");
6045
- if (marker.atomic) reCheckSelection(cm.doc);
6046
- signalLater(cm, "markerAdded", cm, marker);
6047
- }
6048
- return marker;
6049
- }
6050
-
6051
- // SHARED TEXTMARKERS
6052
-
6053
- // A shared marker spans multiple linked documents. It is
6054
- // implemented as a meta-marker-object controlling multiple normal
6055
- // markers.
6056
- var SharedTextMarker = CodeMirror.SharedTextMarker = function(markers, primary) {
6057
- this.markers = markers;
6058
- this.primary = primary;
6059
- for (var i = 0; i < markers.length; ++i)
6060
- markers[i].parent = this;
6061
- };
6062
- eventMixin(SharedTextMarker);
6063
-
6064
- SharedTextMarker.prototype.clear = function() {
6065
- if (this.explicitlyCleared) return;
6066
- this.explicitlyCleared = true;
6067
- for (var i = 0; i < this.markers.length; ++i)
6068
- this.markers[i].clear();
6069
- signalLater(this, "clear");
6070
- };
6071
- SharedTextMarker.prototype.find = function(side, lineObj) {
6072
- return this.primary.find(side, lineObj);
6073
- };
6074
-
6075
- function markTextShared(doc, from, to, options, type) {
6076
- options = copyObj(options);
6077
- options.shared = false;
6078
- var markers = [markText(doc, from, to, options, type)], primary = markers[0];
6079
- var widget = options.widgetNode;
6080
- linkedDocs(doc, function(doc) {
6081
- if (widget) options.widgetNode = widget.cloneNode(true);
6082
- markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type));
6083
- for (var i = 0; i < doc.linked.length; ++i)
6084
- if (doc.linked[i].isParent) return;
6085
- primary = lst(markers);
6086
- });
6087
- return new SharedTextMarker(markers, primary);
6088
- }
6089
-
6090
- function findSharedMarkers(doc) {
6091
- return doc.findMarks(Pos(doc.first, 0), doc.clipPos(Pos(doc.lastLine())),
6092
- function(m) { return m.parent; });
6093
- }
6094
-
6095
- function copySharedMarkers(doc, markers) {
6096
- for (var i = 0; i < markers.length; i++) {
6097
- var marker = markers[i], pos = marker.find();
6098
- var mFrom = doc.clipPos(pos.from), mTo = doc.clipPos(pos.to);
6099
- if (cmp(mFrom, mTo)) {
6100
- var subMark = markText(doc, mFrom, mTo, marker.primary, marker.primary.type);
6101
- marker.markers.push(subMark);
6102
- subMark.parent = marker;
6103
- }
6104
- }
6105
- }
6106
-
6107
- function detachSharedMarkers(markers) {
6108
- for (var i = 0; i < markers.length; i++) {
6109
- var marker = markers[i], linked = [marker.primary.doc];;
6110
- linkedDocs(marker.primary.doc, function(d) { linked.push(d); });
6111
- for (var j = 0; j < marker.markers.length; j++) {
6112
- var subMarker = marker.markers[j];
6113
- if (indexOf(linked, subMarker.doc) == -1) {
6114
- subMarker.parent = null;
6115
- marker.markers.splice(j--, 1);
6116
- }
6117
- }
6118
- }
6119
- }
6120
-
6121
- // TEXTMARKER SPANS
6122
-
6123
- function MarkedSpan(marker, from, to) {
6124
- this.marker = marker;
6125
- this.from = from; this.to = to;
6126
- }
6127
-
6128
- // Search an array of spans for a span matching the given marker.
6129
- function getMarkedSpanFor(spans, marker) {
6130
- if (spans) for (var i = 0; i < spans.length; ++i) {
6131
- var span = spans[i];
6132
- if (span.marker == marker) return span;
6133
- }
6134
- }
6135
- // Remove a span from an array, returning undefined if no spans are
6136
- // left (we don't store arrays for lines without spans).
6137
- function removeMarkedSpan(spans, span) {
6138
- for (var r, i = 0; i < spans.length; ++i)
6139
- if (spans[i] != span) (r || (r = [])).push(spans[i]);
6140
- return r;
6141
- }
6142
- // Add a span to a line.
6143
- function addMarkedSpan(line, span) {
6144
- line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];
6145
- span.marker.attachLine(line);
6146
- }
6147
-
6148
- // Used for the algorithm that adjusts markers for a change in the
6149
- // document. These functions cut an array of spans at a given
6150
- // character position, returning an array of remaining chunks (or
6151
- // undefined if nothing remains).
6152
- function markedSpansBefore(old, startCh, isInsert) {
6153
- if (old) for (var i = 0, nw; i < old.length; ++i) {
6154
- var span = old[i], marker = span.marker;
6155
- var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
6156
- if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
6157
- var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh);
6158
- (nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to));
6159
- }
6160
- }
6161
- return nw;
6162
- }
6163
- function markedSpansAfter(old, endCh, isInsert) {
6164
- if (old) for (var i = 0, nw; i < old.length; ++i) {
6165
- var span = old[i], marker = span.marker;
6166
- var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
6167
- if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
6168
- var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh);
6169
- (nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh,
6170
- span.to == null ? null : span.to - endCh));
6171
- }
6172
- }
6173
- return nw;
6174
- }
6175
-
6176
- // Given a change object, compute the new set of marker spans that
6177
- // cover the line in which the change took place. Removes spans
6178
- // entirely within the change, reconnects spans belonging to the
6179
- // same marker that appear on both sides of the change, and cuts off
6180
- // spans partially within the change. Returns an array of span
6181
- // arrays with one element for each line in (after) the change.
6182
- function stretchSpansOverChange(doc, change) {
6183
- if (change.full) return null;
6184
- var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;
6185
- var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;
6186
- if (!oldFirst && !oldLast) return null;
6187
-
6188
- var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0;
6189
- // Get the spans that 'stick out' on both sides
6190
- var first = markedSpansBefore(oldFirst, startCh, isInsert);
6191
- var last = markedSpansAfter(oldLast, endCh, isInsert);
6192
-
6193
- // Next, merge those two ends
6194
- var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0);
6195
- if (first) {
6196
- // Fix up .to properties of first
6197
- for (var i = 0; i < first.length; ++i) {
6198
- var span = first[i];
6199
- if (span.to == null) {
6200
- var found = getMarkedSpanFor(last, span.marker);
6201
- if (!found) span.to = startCh;
6202
- else if (sameLine) span.to = found.to == null ? null : found.to + offset;
6203
- }
6204
- }
6205
- }
6206
- if (last) {
6207
- // Fix up .from in last (or move them into first in case of sameLine)
6208
- for (var i = 0; i < last.length; ++i) {
6209
- var span = last[i];
6210
- if (span.to != null) span.to += offset;
6211
- if (span.from == null) {
6212
- var found = getMarkedSpanFor(first, span.marker);
6213
- if (!found) {
6214
- span.from = offset;
6215
- if (sameLine) (first || (first = [])).push(span);
6216
- }
6217
- } else {
6218
- span.from += offset;
6219
- if (sameLine) (first || (first = [])).push(span);
6220
- }
6221
- }
6222
- }
6223
- // Make sure we didn't create any zero-length spans
6224
- if (first) first = clearEmptySpans(first);
6225
- if (last && last != first) last = clearEmptySpans(last);
6226
-
6227
- var newMarkers = [first];
6228
- if (!sameLine) {
6229
- // Fill gap with whole-line-spans
6230
- var gap = change.text.length - 2, gapMarkers;
6231
- if (gap > 0 && first)
6232
- for (var i = 0; i < first.length; ++i)
6233
- if (first[i].to == null)
6234
- (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i].marker, null, null));
6235
- for (var i = 0; i < gap; ++i)
6236
- newMarkers.push(gapMarkers);
6237
- newMarkers.push(last);
6238
- }
6239
- return newMarkers;
6240
- }
6241
-
6242
- // Remove spans that are empty and don't have a clearWhenEmpty
6243
- // option of false.
6244
- function clearEmptySpans(spans) {
6245
- for (var i = 0; i < spans.length; ++i) {
6246
- var span = spans[i];
6247
- if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false)
6248
- spans.splice(i--, 1);
6249
- }
6250
- if (!spans.length) return null;
6251
- return spans;
6252
- }
6253
-
6254
- // Used for un/re-doing changes from the history. Combines the
6255
- // result of computing the existing spans with the set of spans that
6256
- // existed in the history (so that deleting around a span and then
6257
- // undoing brings back the span).
6258
- function mergeOldSpans(doc, change) {
6259
- var old = getOldSpans(doc, change);
6260
- var stretched = stretchSpansOverChange(doc, change);
6261
- if (!old) return stretched;
6262
- if (!stretched) return old;
6263
-
6264
- for (var i = 0; i < old.length; ++i) {
6265
- var oldCur = old[i], stretchCur = stretched[i];
6266
- if (oldCur && stretchCur) {
6267
- spans: for (var j = 0; j < stretchCur.length; ++j) {
6268
- var span = stretchCur[j];
6269
- for (var k = 0; k < oldCur.length; ++k)
6270
- if (oldCur[k].marker == span.marker) continue spans;
6271
- oldCur.push(span);
6272
- }
6273
- } else if (stretchCur) {
6274
- old[i] = stretchCur;
6275
- }
6276
- }
6277
- return old;
6278
- }
6279
-
6280
- // Used to 'clip' out readOnly ranges when making a change.
6281
- function removeReadOnlyRanges(doc, from, to) {
6282
- var markers = null;
6283
- doc.iter(from.line, to.line + 1, function(line) {
6284
- if (line.markedSpans) for (var i = 0; i < line.markedSpans.length; ++i) {
6285
- var mark = line.markedSpans[i].marker;
6286
- if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
6287
- (markers || (markers = [])).push(mark);
6288
- }
6289
- });
6290
- if (!markers) return null;
6291
- var parts = [{from: from, to: to}];
6292
- for (var i = 0; i < markers.length; ++i) {
6293
- var mk = markers[i], m = mk.find(0);
6294
- for (var j = 0; j < parts.length; ++j) {
6295
- var p = parts[j];
6296
- if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) continue;
6297
- var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to);
6298
- if (dfrom < 0 || !mk.inclusiveLeft && !dfrom)
6299
- newParts.push({from: p.from, to: m.from});
6300
- if (dto > 0 || !mk.inclusiveRight && !dto)
6301
- newParts.push({from: m.to, to: p.to});
6302
- parts.splice.apply(parts, newParts);
6303
- j += newParts.length - 1;
6304
- }
6305
- }
6306
- return parts;
6307
- }
6308
-
6309
- // Connect or disconnect spans from a line.
6310
- function detachMarkedSpans(line) {
6311
- var spans = line.markedSpans;
6312
- if (!spans) return;
6313
- for (var i = 0; i < spans.length; ++i)
6314
- spans[i].marker.detachLine(line);
6315
- line.markedSpans = null;
6316
- }
6317
- function attachMarkedSpans(line, spans) {
6318
- if (!spans) return;
6319
- for (var i = 0; i < spans.length; ++i)
6320
- spans[i].marker.attachLine(line);
6321
- line.markedSpans = spans;
6322
- }
6323
-
6324
- // Helpers used when computing which overlapping collapsed span
6325
- // counts as the larger one.
6326
- function extraLeft(marker) { return marker.inclusiveLeft ? -1 : 0; }
6327
- function extraRight(marker) { return marker.inclusiveRight ? 1 : 0; }
6328
-
6329
- // Returns a number indicating which of two overlapping collapsed
6330
- // spans is larger (and thus includes the other). Falls back to
6331
- // comparing ids when the spans cover exactly the same range.
6332
- function compareCollapsedMarkers(a, b) {
6333
- var lenDiff = a.lines.length - b.lines.length;
6334
- if (lenDiff != 0) return lenDiff;
6335
- var aPos = a.find(), bPos = b.find();
6336
- var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b);
6337
- if (fromCmp) return -fromCmp;
6338
- var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b);
6339
- if (toCmp) return toCmp;
6340
- return b.id - a.id;
6341
- }
6342
-
6343
- // Find out whether a line ends or starts in a collapsed span. If
6344
- // so, return the marker for that span.
6345
- function collapsedSpanAtSide(line, start) {
6346
- var sps = sawCollapsedSpans && line.markedSpans, found;
6347
- if (sps) for (var sp, i = 0; i < sps.length; ++i) {
6348
- sp = sps[i];
6349
- if (sp.marker.collapsed && (start ? sp.from : sp.to) == null &&
6350
- (!found || compareCollapsedMarkers(found, sp.marker) < 0))
6351
- found = sp.marker;
6352
- }
6353
- return found;
6354
- }
6355
- function collapsedSpanAtStart(line) { return collapsedSpanAtSide(line, true); }
6356
- function collapsedSpanAtEnd(line) { return collapsedSpanAtSide(line, false); }
6357
-
6358
- // Test whether there exists a collapsed span that partially
6359
- // overlaps (covers the start or end, but not both) of a new span.
6360
- // Such overlap is not allowed.
6361
- function conflictingCollapsedRange(doc, lineNo, from, to, marker) {
6362
- var line = getLine(doc, lineNo);
6363
- var sps = sawCollapsedSpans && line.markedSpans;
6364
- if (sps) for (var i = 0; i < sps.length; ++i) {
6365
- var sp = sps[i];
6366
- if (!sp.marker.collapsed) continue;
6367
- var found = sp.marker.find(0);
6368
- var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker);
6369
- var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker);
6370
- if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) continue;
6371
- if (fromCmp <= 0 && (cmp(found.to, from) > 0 || (sp.marker.inclusiveRight && marker.inclusiveLeft)) ||
6372
- fromCmp >= 0 && (cmp(found.from, to) < 0 || (sp.marker.inclusiveLeft && marker.inclusiveRight)))
6373
- return true;
6374
- }
6375
- }
6376
-
6377
- // A visual line is a line as drawn on the screen. Folding, for
6378
- // example, can cause multiple logical lines to appear on the same
6379
- // visual line. This finds the start of the visual line that the
6380
- // given line is part of (usually that is the line itself).
6381
- function visualLine(line) {
6382
- var merged;
6383
- while (merged = collapsedSpanAtStart(line))
6384
- line = merged.find(-1, true).line;
6385
- return line;
6386
- }
6387
-
6388
- // Returns an array of logical lines that continue the visual line
6389
- // started by the argument, or undefined if there are no such lines.
6390
- function visualLineContinued(line) {
6391
- var merged, lines;
6392
- while (merged = collapsedSpanAtEnd(line)) {
6393
- line = merged.find(1, true).line;
6394
- (lines || (lines = [])).push(line);
6395
- }
6396
- return lines;
6397
- }
6398
-
6399
- // Get the line number of the start of the visual line that the
6400
- // given line number is part of.
6401
- function visualLineNo(doc, lineN) {
6402
- var line = getLine(doc, lineN), vis = visualLine(line);
6403
- if (line == vis) return lineN;
6404
- return lineNo(vis);
6405
- }
6406
- // Get the line number of the start of the next visual line after
6407
- // the given line.
6408
- function visualLineEndNo(doc, lineN) {
6409
- if (lineN > doc.lastLine()) return lineN;
6410
- var line = getLine(doc, lineN), merged;
6411
- if (!lineIsHidden(doc, line)) return lineN;
6412
- while (merged = collapsedSpanAtEnd(line))
6413
- line = merged.find(1, true).line;
6414
- return lineNo(line) + 1;
6415
- }
6416
-
6417
- // Compute whether a line is hidden. Lines count as hidden when they
6418
- // are part of a visual line that starts with another line, or when
6419
- // they are entirely covered by collapsed, non-widget span.
6420
- function lineIsHidden(doc, line) {
6421
- var sps = sawCollapsedSpans && line.markedSpans;
6422
- if (sps) for (var sp, i = 0; i < sps.length; ++i) {
6423
- sp = sps[i];
6424
- if (!sp.marker.collapsed) continue;
6425
- if (sp.from == null) return true;
6426
- if (sp.marker.widgetNode) continue;
6427
- if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp))
6428
- return true;
6429
- }
6430
- }
6431
- function lineIsHiddenInner(doc, line, span) {
6432
- if (span.to == null) {
6433
- var end = span.marker.find(1, true);
6434
- return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker));
6435
- }
6436
- if (span.marker.inclusiveRight && span.to == line.text.length)
6437
- return true;
6438
- for (var sp, i = 0; i < line.markedSpans.length; ++i) {
6439
- sp = line.markedSpans[i];
6440
- if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to &&
6441
- (sp.to == null || sp.to != span.from) &&
6442
- (sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
6443
- lineIsHiddenInner(doc, line, sp)) return true;
6444
- }
6445
- }
6446
-
6447
- // LINE WIDGETS
6448
-
6449
- // Line widgets are block elements displayed above or below a line.
6450
-
6451
- var LineWidget = CodeMirror.LineWidget = function(cm, node, options) {
6452
- if (options) for (var opt in options) if (options.hasOwnProperty(opt))
6453
- this[opt] = options[opt];
6454
- this.cm = cm;
6455
- this.node = node;
6456
- };
6457
- eventMixin(LineWidget);
6458
-
6459
- function adjustScrollWhenAboveVisible(cm, line, diff) {
6460
- if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop))
6461
- addToScrollPos(cm, null, diff);
6462
- }
6463
-
6464
- LineWidget.prototype.clear = function() {
6465
- var cm = this.cm, ws = this.line.widgets, line = this.line, no = lineNo(line);
6466
- if (no == null || !ws) return;
6467
- for (var i = 0; i < ws.length; ++i) if (ws[i] == this) ws.splice(i--, 1);
6468
- if (!ws.length) line.widgets = null;
6469
- var height = widgetHeight(this);
6470
- runInOp(cm, function() {
6471
- adjustScrollWhenAboveVisible(cm, line, -height);
6472
- regLineChange(cm, no, "widget");
6473
- updateLineHeight(line, Math.max(0, line.height - height));
6474
- });
6475
- };
6476
- LineWidget.prototype.changed = function() {
6477
- var oldH = this.height, cm = this.cm, line = this.line;
6478
- this.height = null;
6479
- var diff = widgetHeight(this) - oldH;
6480
- if (!diff) return;
6481
- runInOp(cm, function() {
6482
- cm.curOp.forceUpdate = true;
6483
- adjustScrollWhenAboveVisible(cm, line, diff);
6484
- updateLineHeight(line, line.height + diff);
6485
- });
6486
- };
6487
-
6488
- function widgetHeight(widget) {
6489
- if (widget.height != null) return widget.height;
6490
- if (!contains(document.body, widget.node)) {
6491
- var parentStyle = "position: relative;";
6492
- if (widget.coverGutter)
6493
- parentStyle += "margin-left: -" + widget.cm.display.gutters.offsetWidth + "px;";
6494
- if (widget.noHScroll)
6495
- parentStyle += "width: " + widget.cm.display.wrapper.clientWidth + "px;";
6496
- removeChildrenAndAdd(widget.cm.display.measure, elt("div", [widget.node], null, parentStyle));
6497
- }
6498
- return widget.height = widget.node.offsetHeight;
6499
- }
6500
-
6501
- function addLineWidget(cm, handle, node, options) {
6502
- var widget = new LineWidget(cm, node, options);
6503
- if (widget.noHScroll) cm.display.alignWidgets = true;
6504
- changeLine(cm.doc, handle, "widget", function(line) {
6505
- var widgets = line.widgets || (line.widgets = []);
6506
- if (widget.insertAt == null) widgets.push(widget);
6507
- else widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget);
6508
- widget.line = line;
6509
- if (!lineIsHidden(cm.doc, line)) {
6510
- var aboveVisible = heightAtLine(line) < cm.doc.scrollTop;
6511
- updateLineHeight(line, line.height + widgetHeight(widget));
6512
- if (aboveVisible) addToScrollPos(cm, null, widget.height);
6513
- cm.curOp.forceUpdate = true;
6514
- }
6515
- return true;
6516
- });
6517
- return widget;
6518
- }
6519
-
6520
- // LINE DATA STRUCTURE
6521
-
6522
- // Line objects. These hold state related to a line, including
6523
- // highlighting info (the styles array).
6524
- var Line = CodeMirror.Line = function(text, markedSpans, estimateHeight) {
6525
- this.text = text;
6526
- attachMarkedSpans(this, markedSpans);
6527
- this.height = estimateHeight ? estimateHeight(this) : 1;
6528
- };
6529
- eventMixin(Line);
6530
- Line.prototype.lineNo = function() { return lineNo(this); };
6531
-
6532
- // Change the content (text, markers) of a line. Automatically
6533
- // invalidates cached information and tries to re-estimate the
6534
- // line's height.
6535
- function updateLine(line, text, markedSpans, estimateHeight) {
6536
- line.text = text;
6537
- if (line.stateAfter) line.stateAfter = null;
6538
- if (line.styles) line.styles = null;
6539
- if (line.order != null) line.order = null;
6540
- detachMarkedSpans(line);
6541
- attachMarkedSpans(line, markedSpans);
6542
- var estHeight = estimateHeight ? estimateHeight(line) : 1;
6543
- if (estHeight != line.height) updateLineHeight(line, estHeight);
6544
- }
6545
-
6546
- // Detach a line from the document tree and its markers.
6547
- function cleanUpLine(line) {
6548
- line.parent = null;
6549
- detachMarkedSpans(line);
6550
- }
6551
-
6552
- function extractLineClasses(type, output) {
6553
- if (type) for (;;) {
6554
- var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/);
6555
- if (!lineClass) break;
6556
- type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length);
6557
- var prop = lineClass[1] ? "bgClass" : "textClass";
6558
- if (output[prop] == null)
6559
- output[prop] = lineClass[2];
6560
- else if (!(new RegExp("(?:^|\s)" + lineClass[2] + "(?:$|\s)")).test(output[prop]))
6561
- output[prop] += " " + lineClass[2];
6562
- }
6563
- return type;
6564
- }
6565
-
6566
- function callBlankLine(mode, state) {
6567
- if (mode.blankLine) return mode.blankLine(state);
6568
- if (!mode.innerMode) return;
6569
- var inner = CodeMirror.innerMode(mode, state);
6570
- if (inner.mode.blankLine) return inner.mode.blankLine(inner.state);
6571
- }
6572
-
6573
- function readToken(mode, stream, state, inner) {
6574
- for (var i = 0; i < 10; i++) {
6575
- if (inner) inner[0] = CodeMirror.innerMode(mode, state).mode;
6576
- var style = mode.token(stream, state);
6577
- if (stream.pos > stream.start) return style;
6578
- }
6579
- throw new Error("Mode " + mode.name + " failed to advance stream.");
6580
- }
6581
-
6582
- // Utility for getTokenAt and getLineTokens
6583
- function takeToken(cm, pos, precise, asArray) {
6584
- function getObj(copy) {
6585
- return {start: stream.start, end: stream.pos,
6586
- string: stream.current(),
6587
- type: style || null,
6588
- state: copy ? copyState(doc.mode, state) : state};
6589
- }
6590
-
6591
- var doc = cm.doc, mode = doc.mode, style;
6592
- pos = clipPos(doc, pos);
6593
- var line = getLine(doc, pos.line), state = getStateBefore(cm, pos.line, precise);
6594
- var stream = new StringStream(line.text, cm.options.tabSize), tokens;
6595
- if (asArray) tokens = [];
6596
- while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
6597
- stream.start = stream.pos;
6598
- style = readToken(mode, stream, state);
6599
- if (asArray) tokens.push(getObj(true));
6600
- }
6601
- return asArray ? tokens : getObj();
6602
- }
6603
-
6604
- // Run the given mode's parser over a line, calling f for each token.
6605
- function runMode(cm, text, mode, state, f, lineClasses, forceToEnd) {
6606
- var flattenSpans = mode.flattenSpans;
6607
- if (flattenSpans == null) flattenSpans = cm.options.flattenSpans;
6608
- var curStart = 0, curStyle = null;
6609
- var stream = new StringStream(text, cm.options.tabSize), style;
6610
- var inner = cm.options.addModeClass && [null];
6611
- if (text == "") extractLineClasses(callBlankLine(mode, state), lineClasses);
6612
- while (!stream.eol()) {
6613
- if (stream.pos > cm.options.maxHighlightLength) {
6614
- flattenSpans = false;
6615
- if (forceToEnd) processLine(cm, text, state, stream.pos);
6616
- stream.pos = text.length;
6617
- style = null;
6618
- } else {
6619
- style = extractLineClasses(readToken(mode, stream, state, inner), lineClasses);
6620
- }
6621
- if (inner) {
6622
- var mName = inner[0].name;
6623
- if (mName) style = "m-" + (style ? mName + " " + style : mName);
6624
- }
6625
- if (!flattenSpans || curStyle != style) {
6626
- while (curStart < stream.start) {
6627
- curStart = Math.min(stream.start, curStart + 50000);
6628
- f(curStart, curStyle);
6629
- }
6630
- curStyle = style;
6631
- }
6632
- stream.start = stream.pos;
6633
- }
6634
- while (curStart < stream.pos) {
6635
- // Webkit seems to refuse to render text nodes longer than 57444 characters
6636
- var pos = Math.min(stream.pos, curStart + 50000);
6637
- f(pos, curStyle);
6638
- curStart = pos;
6639
- }
6640
- }
6641
-
6642
- // Compute a style array (an array starting with a mode generation
6643
- // -- for invalidation -- followed by pairs of end positions and
6644
- // style strings), which is used to highlight the tokens on the
6645
- // line.
6646
- function highlightLine(cm, line, state, forceToEnd) {
6647
- // A styles array always starts with a number identifying the
6648
- // mode/overlays that it is based on (for easy invalidation).
6649
- var st = [cm.state.modeGen], lineClasses = {};
6650
- // Compute the base array of styles
6651
- runMode(cm, line.text, cm.doc.mode, state, function(end, style) {
6652
- st.push(end, style);
6653
- }, lineClasses, forceToEnd);
6654
-
6655
- // Run overlays, adjust style array.
6656
- for (var o = 0; o < cm.state.overlays.length; ++o) {
6657
- var overlay = cm.state.overlays[o], i = 1, at = 0;
6658
- runMode(cm, line.text, overlay.mode, true, function(end, style) {
6659
- var start = i;
6660
- // Ensure there's a token end at the current position, and that i points at it
6661
- while (at < end) {
6662
- var i_end = st[i];
6663
- if (i_end > end)
6664
- st.splice(i, 1, end, st[i+1], i_end);
6665
- i += 2;
6666
- at = Math.min(end, i_end);
6667
- }
6668
- if (!style) return;
6669
- if (overlay.opaque) {
6670
- st.splice(start, i - start, end, "cm-overlay " + style);
6671
- i = start + 2;
6672
- } else {
6673
- for (; start < i; start += 2) {
6674
- var cur = st[start+1];
6675
- st[start+1] = (cur ? cur + " " : "") + "cm-overlay " + style;
6676
- }
6677
- }
6678
- }, lineClasses);
6679
- }
6680
-
6681
- return {styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null};
6682
- }
6683
-
6684
- function getLineStyles(cm, line, updateFrontier) {
6685
- if (!line.styles || line.styles[0] != cm.state.modeGen) {
6686
- var result = highlightLine(cm, line, line.stateAfter = getStateBefore(cm, lineNo(line)));
6687
- line.styles = result.styles;
6688
- if (result.classes) line.styleClasses = result.classes;
6689
- else if (line.styleClasses) line.styleClasses = null;
6690
- if (updateFrontier === cm.doc.frontier) cm.doc.frontier++;
6691
- }
6692
- return line.styles;
6693
- }
6694
-
6695
- // Lightweight form of highlight -- proceed over this line and
6696
- // update state, but don't save a style array. Used for lines that
6697
- // aren't currently visible.
6698
- function processLine(cm, text, state, startAt) {
6699
- var mode = cm.doc.mode;
6700
- var stream = new StringStream(text, cm.options.tabSize);
6701
- stream.start = stream.pos = startAt || 0;
6702
- if (text == "") callBlankLine(mode, state);
6703
- while (!stream.eol() && stream.pos <= cm.options.maxHighlightLength) {
6704
- readToken(mode, stream, state);
6705
- stream.start = stream.pos;
6706
- }
6707
- }
6708
-
6709
- // Convert a style as returned by a mode (either null, or a string
6710
- // containing one or more styles) to a CSS style. This is cached,
6711
- // and also looks for line-wide styles.
6712
- var styleToClassCache = {}, styleToClassCacheWithMode = {};
6713
- function interpretTokenStyle(style, options) {
6714
- if (!style || /^\s*$/.test(style)) return null;
6715
- var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache;
6716
- return cache[style] ||
6717
- (cache[style] = style.replace(/\S+/g, "cm-$&"));
6718
- }
6719
-
6720
- // Render the DOM representation of the text of a line. Also builds
6721
- // up a 'line map', which points at the DOM nodes that represent
6722
- // specific stretches of text, and is used by the measuring code.
6723
- // The returned object contains the DOM node, this map, and
6724
- // information about line-wide styles that were set by the mode.
6725
- function buildLineContent(cm, lineView) {
6726
- // The padding-right forces the element to have a 'border', which
6727
- // is needed on Webkit to be able to get line-level bounding
6728
- // rectangles for it (in measureChar).
6729
- var content = elt("span", null, null, webkit ? "padding-right: .1px" : null);
6730
- var builder = {pre: elt("pre", [content]), content: content,
6731
- col: 0, pos: 0, cm: cm,
6732
- splitSpaces: (ie || webkit) && cm.getOption("lineWrapping")};
6733
- lineView.measure = {};
6734
-
6735
- // Iterate over the logical lines that make up this visual line.
6736
- for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {
6737
- var line = i ? lineView.rest[i - 1] : lineView.line, order;
6738
- builder.pos = 0;
6739
- builder.addToken = buildToken;
6740
- // Optionally wire in some hacks into the token-rendering
6741
- // algorithm, to deal with browser quirks.
6742
- if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line)))
6743
- builder.addToken = buildTokenBadBidi(builder.addToken, order);
6744
- builder.map = [];
6745
- var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line);
6746
- insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate));
6747
- if (line.styleClasses) {
6748
- if (line.styleClasses.bgClass)
6749
- builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || "");
6750
- if (line.styleClasses.textClass)
6751
- builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || "");
6752
- }
6753
-
6754
- // Ensure at least a single node is present, for measuring.
6755
- if (builder.map.length == 0)
6756
- builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure)));
6757
-
6758
- // Store the map and a cache object for the current logical line
6759
- if (i == 0) {
6760
- lineView.measure.map = builder.map;
6761
- lineView.measure.cache = {};
6762
- } else {
6763
- (lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map);
6764
- (lineView.measure.caches || (lineView.measure.caches = [])).push({});
6765
- }
6766
- }
6767
-
6768
- // See issue #2901
6769
- if (webkit && /\bcm-tab\b/.test(builder.content.lastChild.className))
6770
- builder.content.className = "cm-tab-wrap-hack";
6771
-
6772
- signal(cm, "renderLine", cm, lineView.line, builder.pre);
6773
- if (builder.pre.className)
6774
- builder.textClass = joinClasses(builder.pre.className, builder.textClass || "");
6775
-
6776
- return builder;
6777
- }
6778
-
6779
- function defaultSpecialCharPlaceholder(ch) {
6780
- var token = elt("span", "\u2022", "cm-invalidchar");
6781
- token.title = "\\u" + ch.charCodeAt(0).toString(16);
6782
- token.setAttribute("aria-label", token.title);
6783
- return token;
6784
- }
6785
-
6786
- // Build up the DOM representation for a single token, and add it to
6787
- // the line map. Takes care to render special characters separately.
6788
- function buildToken(builder, text, style, startStyle, endStyle, title, css) {
6789
- if (!text) return;
6790
- var displayText = builder.splitSpaces ? text.replace(/ {3,}/g, splitSpaces) : text;
6791
- var special = builder.cm.state.specialChars, mustWrap = false;
6792
- if (!special.test(text)) {
6793
- builder.col += text.length;
6794
- var content = document.createTextNode(displayText);
6795
- builder.map.push(builder.pos, builder.pos + text.length, content);
6796
- if (ie && ie_version < 9) mustWrap = true;
6797
- builder.pos += text.length;
6798
- } else {
6799
- var content = document.createDocumentFragment(), pos = 0;
6800
- while (true) {
6801
- special.lastIndex = pos;
6802
- var m = special.exec(text);
6803
- var skipped = m ? m.index - pos : text.length - pos;
6804
- if (skipped) {
6805
- var txt = document.createTextNode(displayText.slice(pos, pos + skipped));
6806
- if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
6807
- else content.appendChild(txt);
6808
- builder.map.push(builder.pos, builder.pos + skipped, txt);
6809
- builder.col += skipped;
6810
- builder.pos += skipped;
6811
- }
6812
- if (!m) break;
6813
- pos += skipped + 1;
6814
- if (m[0] == "\t") {
6815
- var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
6816
- var txt = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
6817
- txt.setAttribute("role", "presentation");
6818
- txt.setAttribute("cm-text", "\t");
6819
- builder.col += tabWidth;
6820
- } else {
6821
- var txt = builder.cm.options.specialCharPlaceholder(m[0]);
6822
- txt.setAttribute("cm-text", m[0]);
6823
- if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
6824
- else content.appendChild(txt);
6825
- builder.col += 1;
6826
- }
6827
- builder.map.push(builder.pos, builder.pos + 1, txt);
6828
- builder.pos++;
6829
- }
6830
- }
6831
- if (style || startStyle || endStyle || mustWrap || css) {
6832
- var fullStyle = style || "";
6833
- if (startStyle) fullStyle += startStyle;
6834
- if (endStyle) fullStyle += endStyle;
6835
- var token = elt("span", [content], fullStyle, css);
6836
- if (title) token.title = title;
6837
- return builder.content.appendChild(token);
6838
- }
6839
- builder.content.appendChild(content);
6840
- }
6841
-
6842
- function splitSpaces(old) {
6843
- var out = " ";
6844
- for (var i = 0; i < old.length - 2; ++i) out += i % 2 ? " " : "\u00a0";
6845
- out += " ";
6846
- return out;
6847
- }
6848
-
6849
- // Work around nonsense dimensions being reported for stretches of
6850
- // right-to-left text.
6851
- function buildTokenBadBidi(inner, order) {
6852
- return function(builder, text, style, startStyle, endStyle, title, css) {
6853
- style = style ? style + " cm-force-border" : "cm-force-border";
6854
- var start = builder.pos, end = start + text.length;
6855
- for (;;) {
6856
- // Find the part that overlaps with the start of this text
6857
- for (var i = 0; i < order.length; i++) {
6858
- var part = order[i];
6859
- if (part.to > start && part.from <= start) break;
6860
- }
6861
- if (part.to >= end) return inner(builder, text, style, startStyle, endStyle, title, css);
6862
- inner(builder, text.slice(0, part.to - start), style, startStyle, null, title, css);
6863
- startStyle = null;
6864
- text = text.slice(part.to - start);
6865
- start = part.to;
6866
- }
6867
- };
6868
- }
6869
-
6870
- function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
6871
- var widget = !ignoreWidget && marker.widgetNode;
6872
- if (widget) builder.map.push(builder.pos, builder.pos + size, widget);
6873
- if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) {
6874
- if (!widget)
6875
- widget = builder.content.appendChild(document.createElement("span"));
6876
- widget.setAttribute("cm-marker", marker.id);
6877
- }
6878
- if (widget) {
6879
- builder.cm.display.input.setUneditable(widget);
6880
- builder.content.appendChild(widget);
6881
- }
6882
- builder.pos += size;
6883
- }
6884
-
6885
- // Outputs a number of spans to make up a line, taking highlighting
6886
- // and marked text into account.
6887
- function insertLineContent(line, builder, styles) {
6888
- var spans = line.markedSpans, allText = line.text, at = 0;
6889
- if (!spans) {
6890
- for (var i = 1; i < styles.length; i+=2)
6891
- builder.addToken(builder, allText.slice(at, at = styles[i]), interpretTokenStyle(styles[i+1], builder.cm.options));
6892
- return;
6893
- }
6894
-
6895
- var len = allText.length, pos = 0, i = 1, text = "", style, css;
6896
- var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, title, collapsed;
6897
- for (;;) {
6898
- if (nextChange == pos) { // Update current marker set
6899
- spanStyle = spanEndStyle = spanStartStyle = title = css = "";
6900
- collapsed = null; nextChange = Infinity;
6901
- var foundBookmarks = [];
6902
- for (var j = 0; j < spans.length; ++j) {
6903
- var sp = spans[j], m = sp.marker;
6904
- if (sp.from <= pos && (sp.to == null || sp.to > pos)) {
6905
- if (sp.to != null && nextChange > sp.to) { nextChange = sp.to; spanEndStyle = ""; }
6906
- if (m.className) spanStyle += " " + m.className;
6907
- if (m.css) css = m.css;
6908
- if (m.startStyle && sp.from == pos) spanStartStyle += " " + m.startStyle;
6909
- if (m.endStyle && sp.to == nextChange) spanEndStyle += " " + m.endStyle;
6910
- if (m.title && !title) title = m.title;
6911
- if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0))
6912
- collapsed = sp;
6913
- } else if (sp.from > pos && nextChange > sp.from) {
6914
- nextChange = sp.from;
6915
- }
6916
- if (m.type == "bookmark" && sp.from == pos && m.widgetNode) foundBookmarks.push(m);
6917
- }
6918
- if (collapsed && (collapsed.from || 0) == pos) {
6919
- buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos,
6920
- collapsed.marker, collapsed.from == null);
6921
- if (collapsed.to == null) return;
6922
- }
6923
- if (!collapsed && foundBookmarks.length) for (var j = 0; j < foundBookmarks.length; ++j)
6924
- buildCollapsedSpan(builder, 0, foundBookmarks[j]);
6925
- }
6926
- if (pos >= len) break;
6927
-
6928
- var upto = Math.min(len, nextChange);
6929
- while (true) {
6930
- if (text) {
6931
- var end = pos + text.length;
6932
- if (!collapsed) {
6933
- var tokenText = end > upto ? text.slice(0, upto - pos) : text;
6934
- builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
6935
- spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title, css);
6936
- }
6937
- if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;}
6938
- pos = end;
6939
- spanStartStyle = "";
6940
- }
6941
- text = allText.slice(at, at = styles[i++]);
6942
- style = interpretTokenStyle(styles[i++], builder.cm.options);
6943
- }
6944
- }
6945
- }
6946
-
6947
- // DOCUMENT DATA STRUCTURE
6948
-
6949
- // By default, updates that start and end at the beginning of a line
6950
- // are treated specially, in order to make the association of line
6951
- // widgets and marker elements with the text behave more intuitive.
6952
- function isWholeLineUpdate(doc, change) {
6953
- return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" &&
6954
- (!doc.cm || doc.cm.options.wholeLineUpdateBefore);
6955
- }
6956
-
6957
- // Perform a change on the document data structure.
6958
- function updateDoc(doc, change, markedSpans, estimateHeight) {
6959
- function spansFor(n) {return markedSpans ? markedSpans[n] : null;}
6960
- function update(line, text, spans) {
6961
- updateLine(line, text, spans, estimateHeight);
6962
- signalLater(line, "change", line, change);
6963
- }
6964
- function linesFor(start, end) {
6965
- for (var i = start, result = []; i < end; ++i)
6966
- result.push(new Line(text[i], spansFor(i), estimateHeight));
6967
- return result;
6968
- }
6969
-
6970
- var from = change.from, to = change.to, text = change.text;
6971
- var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line);
6972
- var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line;
6973
-
6974
- // Adjust the line structure
6975
- if (change.full) {
6976
- doc.insert(0, linesFor(0, text.length));
6977
- doc.remove(text.length, doc.size - text.length);
6978
- } else if (isWholeLineUpdate(doc, change)) {
6979
- // This is a whole-line replace. Treated specially to make
6980
- // sure line objects move the way they are supposed to.
6981
- var added = linesFor(0, text.length - 1);
6982
- update(lastLine, lastLine.text, lastSpans);
6983
- if (nlines) doc.remove(from.line, nlines);
6984
- if (added.length) doc.insert(from.line, added);
6985
- } else if (firstLine == lastLine) {
6986
- if (text.length == 1) {
6987
- update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans);
6988
- } else {
6989
- var added = linesFor(1, text.length - 1);
6990
- added.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight));
6991
- update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
6992
- doc.insert(from.line + 1, added);
6993
- }
6994
- } else if (text.length == 1) {
6995
- update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0));
6996
- doc.remove(from.line + 1, nlines);
6997
- } else {
6998
- update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
6999
- update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans);
7000
- var added = linesFor(1, text.length - 1);
7001
- if (nlines > 1) doc.remove(from.line + 1, nlines - 1);
7002
- doc.insert(from.line + 1, added);
7003
- }
7004
-
7005
- signalLater(doc, "change", doc, change);
7006
- }
7007
-
7008
- // The document is represented as a BTree consisting of leaves, with
7009
- // chunk of lines in them, and branches, with up to ten leaves or
7010
- // other branch nodes below them. The top node is always a branch
7011
- // node, and is the document object itself (meaning it has
7012
- // additional methods and properties).
7013
- //
7014
- // All nodes have parent links. The tree is used both to go from
7015
- // line numbers to line objects, and to go from objects to numbers.
7016
- // It also indexes by height, and is used to convert between height
7017
- // and line object, and to find the total height of the document.
7018
- //
7019
- // See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html
7020
-
7021
- function LeafChunk(lines) {
7022
- this.lines = lines;
7023
- this.parent = null;
7024
- for (var i = 0, height = 0; i < lines.length; ++i) {
7025
- lines[i].parent = this;
7026
- height += lines[i].height;
7027
- }
7028
- this.height = height;
7029
- }
7030
-
7031
- LeafChunk.prototype = {
7032
- chunkSize: function() { return this.lines.length; },
7033
- // Remove the n lines at offset 'at'.
7034
- removeInner: function(at, n) {
7035
- for (var i = at, e = at + n; i < e; ++i) {
7036
- var line = this.lines[i];
7037
- this.height -= line.height;
7038
- cleanUpLine(line);
7039
- signalLater(line, "delete");
7040
- }
7041
- this.lines.splice(at, n);
7042
- },
7043
- // Helper used to collapse a small branch into a single leaf.
7044
- collapse: function(lines) {
7045
- lines.push.apply(lines, this.lines);
7046
- },
7047
- // Insert the given array of lines at offset 'at', count them as
7048
- // having the given height.
7049
- insertInner: function(at, lines, height) {
7050
- this.height += height;
7051
- this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
7052
- for (var i = 0; i < lines.length; ++i) lines[i].parent = this;
7053
- },
7054
- // Used to iterate over a part of the tree.
7055
- iterN: function(at, n, op) {
7056
- for (var e = at + n; at < e; ++at)
7057
- if (op(this.lines[at])) return true;
7058
- }
7059
- };
7060
-
7061
- function BranchChunk(children) {
7062
- this.children = children;
7063
- var size = 0, height = 0;
7064
- for (var i = 0; i < children.length; ++i) {
7065
- var ch = children[i];
7066
- size += ch.chunkSize(); height += ch.height;
7067
- ch.parent = this;
7068
- }
7069
- this.size = size;
7070
- this.height = height;
7071
- this.parent = null;
7072
- }
7073
-
7074
- BranchChunk.prototype = {
7075
- chunkSize: function() { return this.size; },
7076
- removeInner: function(at, n) {
7077
- this.size -= n;
7078
- for (var i = 0; i < this.children.length; ++i) {
7079
- var child = this.children[i], sz = child.chunkSize();
7080
- if (at < sz) {
7081
- var rm = Math.min(n, sz - at), oldHeight = child.height;
7082
- child.removeInner(at, rm);
7083
- this.height -= oldHeight - child.height;
7084
- if (sz == rm) { this.children.splice(i--, 1); child.parent = null; }
7085
- if ((n -= rm) == 0) break;
7086
- at = 0;
7087
- } else at -= sz;
7088
- }
7089
- // If the result is smaller than 25 lines, ensure that it is a
7090
- // single leaf node.
7091
- if (this.size - n < 25 &&
7092
- (this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {
7093
- var lines = [];
7094
- this.collapse(lines);
7095
- this.children = [new LeafChunk(lines)];
7096
- this.children[0].parent = this;
7097
- }
7098
- },
7099
- collapse: function(lines) {
7100
- for (var i = 0; i < this.children.length; ++i) this.children[i].collapse(lines);
7101
- },
7102
- insertInner: function(at, lines, height) {
7103
- this.size += lines.length;
7104
- this.height += height;
7105
- for (var i = 0; i < this.children.length; ++i) {
7106
- var child = this.children[i], sz = child.chunkSize();
7107
- if (at <= sz) {
7108
- child.insertInner(at, lines, height);
7109
- if (child.lines && child.lines.length > 50) {
7110
- while (child.lines.length > 50) {
7111
- var spilled = child.lines.splice(child.lines.length - 25, 25);
7112
- var newleaf = new LeafChunk(spilled);
7113
- child.height -= newleaf.height;
7114
- this.children.splice(i + 1, 0, newleaf);
7115
- newleaf.parent = this;
7116
- }
7117
- this.maybeSpill();
7118
- }
7119
- break;
7120
- }
7121
- at -= sz;
7122
- }
7123
- },
7124
- // When a node has grown, check whether it should be split.
7125
- maybeSpill: function() {
7126
- if (this.children.length <= 10) return;
7127
- var me = this;
7128
- do {
7129
- var spilled = me.children.splice(me.children.length - 5, 5);
7130
- var sibling = new BranchChunk(spilled);
7131
- if (!me.parent) { // Become the parent node
7132
- var copy = new BranchChunk(me.children);
7133
- copy.parent = me;
7134
- me.children = [copy, sibling];
7135
- me = copy;
7136
- } else {
7137
- me.size -= sibling.size;
7138
- me.height -= sibling.height;
7139
- var myIndex = indexOf(me.parent.children, me);
7140
- me.parent.children.splice(myIndex + 1, 0, sibling);
7141
- }
7142
- sibling.parent = me.parent;
7143
- } while (me.children.length > 10);
7144
- me.parent.maybeSpill();
7145
- },
7146
- iterN: function(at, n, op) {
7147
- for (var i = 0; i < this.children.length; ++i) {
7148
- var child = this.children[i], sz = child.chunkSize();
7149
- if (at < sz) {
7150
- var used = Math.min(n, sz - at);
7151
- if (child.iterN(at, used, op)) return true;
7152
- if ((n -= used) == 0) break;
7153
- at = 0;
7154
- } else at -= sz;
7155
- }
7156
- }
7157
- };
7158
-
7159
- var nextDocId = 0;
7160
- var Doc = CodeMirror.Doc = function(text, mode, firstLine) {
7161
- if (!(this instanceof Doc)) return new Doc(text, mode, firstLine);
7162
- if (firstLine == null) firstLine = 0;
7163
-
7164
- BranchChunk.call(this, [new LeafChunk([new Line("", null)])]);
7165
- this.first = firstLine;
7166
- this.scrollTop = this.scrollLeft = 0;
7167
- this.cantEdit = false;
7168
- this.cleanGeneration = 1;
7169
- this.frontier = firstLine;
7170
- var start = Pos(firstLine, 0);
7171
- this.sel = simpleSelection(start);
7172
- this.history = new History(null);
7173
- this.id = ++nextDocId;
7174
- this.modeOption = mode;
7175
-
7176
- if (typeof text == "string") text = splitLines(text);
7177
- updateDoc(this, {from: start, to: start, text: text});
7178
- setSelection(this, simpleSelection(start), sel_dontScroll);
7179
- };
7180
-
7181
- Doc.prototype = createObj(BranchChunk.prototype, {
7182
- constructor: Doc,
7183
- // Iterate over the document. Supports two forms -- with only one
7184
- // argument, it calls that for each line in the document. With
7185
- // three, it iterates over the range given by the first two (with
7186
- // the second being non-inclusive).
7187
- iter: function(from, to, op) {
7188
- if (op) this.iterN(from - this.first, to - from, op);
7189
- else this.iterN(this.first, this.first + this.size, from);
7190
- },
7191
-
7192
- // Non-public interface for adding and removing lines.
7193
- insert: function(at, lines) {
7194
- var height = 0;
7195
- for (var i = 0; i < lines.length; ++i) height += lines[i].height;
7196
- this.insertInner(at - this.first, lines, height);
7197
- },
7198
- remove: function(at, n) { this.removeInner(at - this.first, n); },
7199
-
7200
- // From here, the methods are part of the public interface. Most
7201
- // are also available from CodeMirror (editor) instances.
7202
-
7203
- getValue: function(lineSep) {
7204
- var lines = getLines(this, this.first, this.first + this.size);
7205
- if (lineSep === false) return lines;
7206
- return lines.join(lineSep || "\n");
7207
- },
7208
- setValue: docMethodOp(function(code) {
7209
- var top = Pos(this.first, 0), last = this.first + this.size - 1;
7210
- makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length),
7211
- text: splitLines(code), origin: "setValue", full: true}, true);
7212
- setSelection(this, simpleSelection(top));
7213
- }),
7214
- replaceRange: function(code, from, to, origin) {
7215
- from = clipPos(this, from);
7216
- to = to ? clipPos(this, to) : from;
7217
- replaceRange(this, code, from, to, origin);
7218
- },
7219
- getRange: function(from, to, lineSep) {
7220
- var lines = getBetween(this, clipPos(this, from), clipPos(this, to));
7221
- if (lineSep === false) return lines;
7222
- return lines.join(lineSep || "\n");
7223
- },
7224
-
7225
- getLine: function(line) {var l = this.getLineHandle(line); return l && l.text;},
7226
-
7227
- getLineHandle: function(line) {if (isLine(this, line)) return getLine(this, line);},
7228
- getLineNumber: function(line) {return lineNo(line);},
7229
-
7230
- getLineHandleVisualStart: function(line) {
7231
- if (typeof line == "number") line = getLine(this, line);
7232
- return visualLine(line);
7233
- },
7234
-
7235
- lineCount: function() {return this.size;},
7236
- firstLine: function() {return this.first;},
7237
- lastLine: function() {return this.first + this.size - 1;},
7238
-
7239
- clipPos: function(pos) {return clipPos(this, pos);},
7240
-
7241
- getCursor: function(start) {
7242
- var range = this.sel.primary(), pos;
7243
- if (start == null || start == "head") pos = range.head;
7244
- else if (start == "anchor") pos = range.anchor;
7245
- else if (start == "end" || start == "to" || start === false) pos = range.to();
7246
- else pos = range.from();
7247
- return pos;
7248
- },
7249
- listSelections: function() { return this.sel.ranges; },
7250
- somethingSelected: function() {return this.sel.somethingSelected();},
7251
-
7252
- setCursor: docMethodOp(function(line, ch, options) {
7253
- setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options);
7254
- }),
7255
- setSelection: docMethodOp(function(anchor, head, options) {
7256
- setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options);
7257
- }),
7258
- extendSelection: docMethodOp(function(head, other, options) {
7259
- extendSelection(this, clipPos(this, head), other && clipPos(this, other), options);
7260
- }),
7261
- extendSelections: docMethodOp(function(heads, options) {
7262
- extendSelections(this, clipPosArray(this, heads, options));
7263
- }),
7264
- extendSelectionsBy: docMethodOp(function(f, options) {
7265
- extendSelections(this, map(this.sel.ranges, f), options);
7266
- }),
7267
- setSelections: docMethodOp(function(ranges, primary, options) {
7268
- if (!ranges.length) return;
7269
- for (var i = 0, out = []; i < ranges.length; i++)
7270
- out[i] = new Range(clipPos(this, ranges[i].anchor),
7271
- clipPos(this, ranges[i].head));
7272
- if (primary == null) primary = Math.min(ranges.length - 1, this.sel.primIndex);
7273
- setSelection(this, normalizeSelection(out, primary), options);
7274
- }),
7275
- addSelection: docMethodOp(function(anchor, head, options) {
7276
- var ranges = this.sel.ranges.slice(0);
7277
- ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor)));
7278
- setSelection(this, normalizeSelection(ranges, ranges.length - 1), options);
7279
- }),
7280
-
7281
- getSelection: function(lineSep) {
7282
- var ranges = this.sel.ranges, lines;
7283
- for (var i = 0; i < ranges.length; i++) {
7284
- var sel = getBetween(this, ranges[i].from(), ranges[i].to());
7285
- lines = lines ? lines.concat(sel) : sel;
7286
- }
7287
- if (lineSep === false) return lines;
7288
- else return lines.join(lineSep || "\n");
7289
- },
7290
- getSelections: function(lineSep) {
7291
- var parts = [], ranges = this.sel.ranges;
7292
- for (var i = 0; i < ranges.length; i++) {
7293
- var sel = getBetween(this, ranges[i].from(), ranges[i].to());
7294
- if (lineSep !== false) sel = sel.join(lineSep || "\n");
7295
- parts[i] = sel;
7296
- }
7297
- return parts;
7298
- },
7299
- replaceSelection: function(code, collapse, origin) {
7300
- var dup = [];
7301
- for (var i = 0; i < this.sel.ranges.length; i++)
7302
- dup[i] = code;
7303
- this.replaceSelections(dup, collapse, origin || "+input");
7304
- },
7305
- replaceSelections: docMethodOp(function(code, collapse, origin) {
7306
- var changes = [], sel = this.sel;
7307
- for (var i = 0; i < sel.ranges.length; i++) {
7308
- var range = sel.ranges[i];
7309
- changes[i] = {from: range.from(), to: range.to(), text: splitLines(code[i]), origin: origin};
7310
- }
7311
- var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse);
7312
- for (var i = changes.length - 1; i >= 0; i--)
7313
- makeChange(this, changes[i]);
7314
- if (newSel) setSelectionReplaceHistory(this, newSel);
7315
- else if (this.cm) ensureCursorVisible(this.cm);
7316
- }),
7317
- undo: docMethodOp(function() {makeChangeFromHistory(this, "undo");}),
7318
- redo: docMethodOp(function() {makeChangeFromHistory(this, "redo");}),
7319
- undoSelection: docMethodOp(function() {makeChangeFromHistory(this, "undo", true);}),
7320
- redoSelection: docMethodOp(function() {makeChangeFromHistory(this, "redo", true);}),
7321
-
7322
- setExtending: function(val) {this.extend = val;},
7323
- getExtending: function() {return this.extend;},
7324
-
7325
- historySize: function() {
7326
- var hist = this.history, done = 0, undone = 0;
7327
- for (var i = 0; i < hist.done.length; i++) if (!hist.done[i].ranges) ++done;
7328
- for (var i = 0; i < hist.undone.length; i++) if (!hist.undone[i].ranges) ++undone;
7329
- return {undo: done, redo: undone};
7330
- },
7331
- clearHistory: function() {this.history = new History(this.history.maxGeneration);},
7332
-
7333
- markClean: function() {
7334
- this.cleanGeneration = this.changeGeneration(true);
7335
- },
7336
- changeGeneration: function(forceSplit) {
7337
- if (forceSplit)
7338
- this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null;
7339
- return this.history.generation;
7340
- },
7341
- isClean: function (gen) {
7342
- return this.history.generation == (gen || this.cleanGeneration);
7343
- },
7344
-
7345
- getHistory: function() {
7346
- return {done: copyHistoryArray(this.history.done),
7347
- undone: copyHistoryArray(this.history.undone)};
7348
- },
7349
- setHistory: function(histData) {
7350
- var hist = this.history = new History(this.history.maxGeneration);
7351
- hist.done = copyHistoryArray(histData.done.slice(0), null, true);
7352
- hist.undone = copyHistoryArray(histData.undone.slice(0), null, true);
7353
- },
7354
-
7355
- addLineClass: docMethodOp(function(handle, where, cls) {
7356
- return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function(line) {
7357
- var prop = where == "text" ? "textClass"
7358
- : where == "background" ? "bgClass"
7359
- : where == "gutter" ? "gutterClass" : "wrapClass";
7360
- if (!line[prop]) line[prop] = cls;
7361
- else if (classTest(cls).test(line[prop])) return false;
7362
- else line[prop] += " " + cls;
7363
- return true;
7364
- });
7365
- }),
7366
- removeLineClass: docMethodOp(function(handle, where, cls) {
7367
- return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function(line) {
7368
- var prop = where == "text" ? "textClass"
7369
- : where == "background" ? "bgClass"
7370
- : where == "gutter" ? "gutterClass" : "wrapClass";
7371
- var cur = line[prop];
7372
- if (!cur) return false;
7373
- else if (cls == null) line[prop] = null;
7374
- else {
7375
- var found = cur.match(classTest(cls));
7376
- if (!found) return false;
7377
- var end = found.index + found[0].length;
7378
- line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null;
7379
- }
7380
- return true;
7381
- });
7382
- }),
7383
-
7384
- markText: function(from, to, options) {
7385
- return markText(this, clipPos(this, from), clipPos(this, to), options, "range");
7386
- },
7387
- setBookmark: function(pos, options) {
7388
- var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options),
7389
- insertLeft: options && options.insertLeft,
7390
- clearWhenEmpty: false, shared: options && options.shared};
7391
- pos = clipPos(this, pos);
7392
- return markText(this, pos, pos, realOpts, "bookmark");
7393
- },
7394
- findMarksAt: function(pos) {
7395
- pos = clipPos(this, pos);
7396
- var markers = [], spans = getLine(this, pos.line).markedSpans;
7397
- if (spans) for (var i = 0; i < spans.length; ++i) {
7398
- var span = spans[i];
7399
- if ((span.from == null || span.from <= pos.ch) &&
7400
- (span.to == null || span.to >= pos.ch))
7401
- markers.push(span.marker.parent || span.marker);
7402
- }
7403
- return markers;
7404
- },
7405
- findMarks: function(from, to, filter) {
7406
- from = clipPos(this, from); to = clipPos(this, to);
7407
- var found = [], lineNo = from.line;
7408
- this.iter(from.line, to.line + 1, function(line) {
7409
- var spans = line.markedSpans;
7410
- if (spans) for (var i = 0; i < spans.length; i++) {
7411
- var span = spans[i];
7412
- if (!(lineNo == from.line && from.ch > span.to ||
7413
- span.from == null && lineNo != from.line||
7414
- lineNo == to.line && span.from > to.ch) &&
7415
- (!filter || filter(span.marker)))
7416
- found.push(span.marker.parent || span.marker);
7417
- }
7418
- ++lineNo;
7419
- });
7420
- return found;
7421
- },
7422
- getAllMarks: function() {
7423
- var markers = [];
7424
- this.iter(function(line) {
7425
- var sps = line.markedSpans;
7426
- if (sps) for (var i = 0; i < sps.length; ++i)
7427
- if (sps[i].from != null) markers.push(sps[i].marker);
7428
- });
7429
- return markers;
7430
- },
7431
-
7432
- posFromIndex: function(off) {
7433
- var ch, lineNo = this.first;
7434
- this.iter(function(line) {
7435
- var sz = line.text.length + 1;
7436
- if (sz > off) { ch = off; return true; }
7437
- off -= sz;
7438
- ++lineNo;
7439
- });
7440
- return clipPos(this, Pos(lineNo, ch));
7441
- },
7442
- indexFromPos: function (coords) {
7443
- coords = clipPos(this, coords);
7444
- var index = coords.ch;
7445
- if (coords.line < this.first || coords.ch < 0) return 0;
7446
- this.iter(this.first, coords.line, function (line) {
7447
- index += line.text.length + 1;
7448
- });
7449
- return index;
7450
- },
7451
-
7452
- copy: function(copyHistory) {
7453
- var doc = new Doc(getLines(this, this.first, this.first + this.size), this.modeOption, this.first);
7454
- doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft;
7455
- doc.sel = this.sel;
7456
- doc.extend = false;
7457
- if (copyHistory) {
7458
- doc.history.undoDepth = this.history.undoDepth;
7459
- doc.setHistory(this.getHistory());
7460
- }
7461
- return doc;
7462
- },
7463
-
7464
- linkedDoc: function(options) {
7465
- if (!options) options = {};
7466
- var from = this.first, to = this.first + this.size;
7467
- if (options.from != null && options.from > from) from = options.from;
7468
- if (options.to != null && options.to < to) to = options.to;
7469
- var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from);
7470
- if (options.sharedHist) copy.history = this.history;
7471
- (this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist});
7472
- copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}];
7473
- copySharedMarkers(copy, findSharedMarkers(this));
7474
- return copy;
7475
- },
7476
- unlinkDoc: function(other) {
7477
- if (other instanceof CodeMirror) other = other.doc;
7478
- if (this.linked) for (var i = 0; i < this.linked.length; ++i) {
7479
- var link = this.linked[i];
7480
- if (link.doc != other) continue;
7481
- this.linked.splice(i, 1);
7482
- other.unlinkDoc(this);
7483
- detachSharedMarkers(findSharedMarkers(this));
7484
- break;
7485
- }
7486
- // If the histories were shared, split them again
7487
- if (other.history == this.history) {
7488
- var splitIds = [other.id];
7489
- linkedDocs(other, function(doc) {splitIds.push(doc.id);}, true);
7490
- other.history = new History(null);
7491
- other.history.done = copyHistoryArray(this.history.done, splitIds);
7492
- other.history.undone = copyHistoryArray(this.history.undone, splitIds);
7493
- }
7494
- },
7495
- iterLinkedDocs: function(f) {linkedDocs(this, f);},
7496
-
7497
- getMode: function() {return this.mode;},
7498
- getEditor: function() {return this.cm;}
7499
- });
7500
-
7501
- // Public alias.
7502
- Doc.prototype.eachLine = Doc.prototype.iter;
7503
-
7504
- // Set up methods on CodeMirror's prototype to redirect to the editor's document.
7505
- var dontDelegate = "iter insert remove copy getEditor".split(" ");
7506
- for (var prop in Doc.prototype) if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0)
7507
- CodeMirror.prototype[prop] = (function(method) {
7508
- return function() {return method.apply(this.doc, arguments);};
7509
- })(Doc.prototype[prop]);
7510
-
7511
- eventMixin(Doc);
7512
-
7513
- // Call f for all linked documents.
7514
- function linkedDocs(doc, f, sharedHistOnly) {
7515
- function propagate(doc, skip, sharedHist) {
7516
- if (doc.linked) for (var i = 0; i < doc.linked.length; ++i) {
7517
- var rel = doc.linked[i];
7518
- if (rel.doc == skip) continue;
7519
- var shared = sharedHist && rel.sharedHist;
7520
- if (sharedHistOnly && !shared) continue;
7521
- f(rel.doc, shared);
7522
- propagate(rel.doc, doc, shared);
7523
- }
7524
- }
7525
- propagate(doc, null, true);
7526
- }
7527
-
7528
- // Attach a document to an editor.
7529
- function attachDoc(cm, doc) {
7530
- if (doc.cm) throw new Error("This document is already in use.");
7531
- cm.doc = doc;
7532
- doc.cm = cm;
7533
- estimateLineHeights(cm);
7534
- loadMode(cm);
7535
- if (!cm.options.lineWrapping) findMaxLine(cm);
7536
- cm.options.mode = doc.modeOption;
7537
- regChange(cm);
7538
- }
7539
-
7540
- // LINE UTILITIES
7541
-
7542
- // Find the line object corresponding to the given line number.
7543
- function getLine(doc, n) {
7544
- n -= doc.first;
7545
- if (n < 0 || n >= doc.size) throw new Error("There is no line " + (n + doc.first) + " in the document.");
7546
- for (var chunk = doc; !chunk.lines;) {
7547
- for (var i = 0;; ++i) {
7548
- var child = chunk.children[i], sz = child.chunkSize();
7549
- if (n < sz) { chunk = child; break; }
7550
- n -= sz;
7551
- }
7552
- }
7553
- return chunk.lines[n];
7554
- }
7555
-
7556
- // Get the part of a document between two positions, as an array of
7557
- // strings.
7558
- function getBetween(doc, start, end) {
7559
- var out = [], n = start.line;
7560
- doc.iter(start.line, end.line + 1, function(line) {
7561
- var text = line.text;
7562
- if (n == end.line) text = text.slice(0, end.ch);
7563
- if (n == start.line) text = text.slice(start.ch);
7564
- out.push(text);
7565
- ++n;
7566
- });
7567
- return out;
7568
- }
7569
- // Get the lines between from and to, as array of strings.
7570
- function getLines(doc, from, to) {
7571
- var out = [];
7572
- doc.iter(from, to, function(line) { out.push(line.text); });
7573
- return out;
7574
- }
7575
-
7576
- // Update the height of a line, propagating the height change
7577
- // upwards to parent nodes.
7578
- function updateLineHeight(line, height) {
7579
- var diff = height - line.height;
7580
- if (diff) for (var n = line; n; n = n.parent) n.height += diff;
7581
- }
7582
-
7583
- // Given a line object, find its line number by walking up through
7584
- // its parent links.
7585
- function lineNo(line) {
7586
- if (line.parent == null) return null;
7587
- var cur = line.parent, no = indexOf(cur.lines, line);
7588
- for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
7589
- for (var i = 0;; ++i) {
7590
- if (chunk.children[i] == cur) break;
7591
- no += chunk.children[i].chunkSize();
7592
- }
7593
- }
7594
- return no + cur.first;
7595
- }
7596
-
7597
- // Find the line at the given vertical position, using the height
7598
- // information in the document tree.
7599
- function lineAtHeight(chunk, h) {
7600
- var n = chunk.first;
7601
- outer: do {
7602
- for (var i = 0; i < chunk.children.length; ++i) {
7603
- var child = chunk.children[i], ch = child.height;
7604
- if (h < ch) { chunk = child; continue outer; }
7605
- h -= ch;
7606
- n += child.chunkSize();
7607
- }
7608
- return n;
7609
- } while (!chunk.lines);
7610
- for (var i = 0; i < chunk.lines.length; ++i) {
7611
- var line = chunk.lines[i], lh = line.height;
7612
- if (h < lh) break;
7613
- h -= lh;
7614
- }
7615
- return n + i;
7616
- }
7617
-
7618
-
7619
- // Find the height above the given line.
7620
- function heightAtLine(lineObj) {
7621
- lineObj = visualLine(lineObj);
7622
-
7623
- var h = 0, chunk = lineObj.parent;
7624
- for (var i = 0; i < chunk.lines.length; ++i) {
7625
- var line = chunk.lines[i];
7626
- if (line == lineObj) break;
7627
- else h += line.height;
7628
- }
7629
- for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
7630
- for (var i = 0; i < p.children.length; ++i) {
7631
- var cur = p.children[i];
7632
- if (cur == chunk) break;
7633
- else h += cur.height;
7634
- }
7635
- }
7636
- return h;
7637
- }
7638
-
7639
- // Get the bidi ordering for the given line (and cache it). Returns
7640
- // false for lines that are fully left-to-right, and an array of
7641
- // BidiSpan objects otherwise.
7642
- function getOrder(line) {
7643
- var order = line.order;
7644
- if (order == null) order = line.order = bidiOrdering(line.text);
7645
- return order;
7646
- }
7647
-
7648
- // HISTORY
7649
-
7650
- function History(startGen) {
7651
- // Arrays of change events and selections. Doing something adds an
7652
- // event to done and clears undo. Undoing moves events from done
7653
- // to undone, redoing moves them in the other direction.
7654
- this.done = []; this.undone = [];
7655
- this.undoDepth = Infinity;
7656
- // Used to track when changes can be merged into a single undo
7657
- // event
7658
- this.lastModTime = this.lastSelTime = 0;
7659
- this.lastOp = this.lastSelOp = null;
7660
- this.lastOrigin = this.lastSelOrigin = null;
7661
- // Used by the isClean() method
7662
- this.generation = this.maxGeneration = startGen || 1;
7663
- }
7664
-
7665
- // Create a history change event from an updateDoc-style change
7666
- // object.
7667
- function historyChangeFromChange(doc, change) {
7668
- var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)};
7669
- attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);
7670
- linkedDocs(doc, function(doc) {attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);}, true);
7671
- return histChange;
7672
- }
7673
-
7674
- // Pop all selection events off the end of a history array. Stop at
7675
- // a change event.
7676
- function clearSelectionEvents(array) {
7677
- while (array.length) {
7678
- var last = lst(array);
7679
- if (last.ranges) array.pop();
7680
- else break;
7681
- }
7682
- }
7683
-
7684
- // Find the top change event in the history. Pop off selection
7685
- // events that are in the way.
7686
- function lastChangeEvent(hist, force) {
7687
- if (force) {
7688
- clearSelectionEvents(hist.done);
7689
- return lst(hist.done);
7690
- } else if (hist.done.length && !lst(hist.done).ranges) {
7691
- return lst(hist.done);
7692
- } else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
7693
- hist.done.pop();
7694
- return lst(hist.done);
7695
- }
7696
- }
7697
-
7698
- // Register a change in the history. Merges changes that are within
7699
- // a single operation, ore are close together with an origin that
7700
- // allows merging (starting with "+") into a single event.
7701
- function addChangeToHistory(doc, change, selAfter, opId) {
7702
- var hist = doc.history;
7703
- hist.undone.length = 0;
7704
- var time = +new Date, cur;
7705
-
7706
- if ((hist.lastOp == opId ||
7707
- hist.lastOrigin == change.origin && change.origin &&
7708
- ((change.origin.charAt(0) == "+" && doc.cm && hist.lastModTime > time - doc.cm.options.historyEventDelay) ||
7709
- change.origin.charAt(0) == "*")) &&
7710
- (cur = lastChangeEvent(hist, hist.lastOp == opId))) {
7711
- // Merge this change into the last event
7712
- var last = lst(cur.changes);
7713
- if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
7714
- // Optimized case for simple insertion -- don't want to add
7715
- // new changesets for every character typed
7716
- last.to = changeEnd(change);
7717
- } else {
7718
- // Add new sub-event
7719
- cur.changes.push(historyChangeFromChange(doc, change));
7720
- }
7721
- } else {
7722
- // Can not be merged, start a new event.
7723
- var before = lst(hist.done);
7724
- if (!before || !before.ranges)
7725
- pushSelectionToHistory(doc.sel, hist.done);
7726
- cur = {changes: [historyChangeFromChange(doc, change)],
7727
- generation: hist.generation};
7728
- hist.done.push(cur);
7729
- while (hist.done.length > hist.undoDepth) {
7730
- hist.done.shift();
7731
- if (!hist.done[0].ranges) hist.done.shift();
7732
- }
7733
- }
7734
- hist.done.push(selAfter);
7735
- hist.generation = ++hist.maxGeneration;
7736
- hist.lastModTime = hist.lastSelTime = time;
7737
- hist.lastOp = hist.lastSelOp = opId;
7738
- hist.lastOrigin = hist.lastSelOrigin = change.origin;
7739
-
7740
- if (!last) signal(doc, "historyAdded");
7741
- }
7742
-
7743
- function selectionEventCanBeMerged(doc, origin, prev, sel) {
7744
- var ch = origin.charAt(0);
7745
- return ch == "*" ||
7746
- ch == "+" &&
7747
- prev.ranges.length == sel.ranges.length &&
7748
- prev.somethingSelected() == sel.somethingSelected() &&
7749
- new Date - doc.history.lastSelTime <= (doc.cm ? doc.cm.options.historyEventDelay : 500);
7750
- }
7751
-
7752
- // Called whenever the selection changes, sets the new selection as
7753
- // the pending selection in the history, and pushes the old pending
7754
- // selection into the 'done' array when it was significantly
7755
- // different (in number of selected ranges, emptiness, or time).
7756
- function addSelectionToHistory(doc, sel, opId, options) {
7757
- var hist = doc.history, origin = options && options.origin;
7758
-
7759
- // A new event is started when the previous origin does not match
7760
- // the current, or the origins don't allow matching. Origins
7761
- // starting with * are always merged, those starting with + are
7762
- // merged when similar and close together in time.
7763
- if (opId == hist.lastSelOp ||
7764
- (origin && hist.lastSelOrigin == origin &&
7765
- (hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin ||
7766
- selectionEventCanBeMerged(doc, origin, lst(hist.done), sel))))
7767
- hist.done[hist.done.length - 1] = sel;
7768
- else
7769
- pushSelectionToHistory(sel, hist.done);
7770
-
7771
- hist.lastSelTime = +new Date;
7772
- hist.lastSelOrigin = origin;
7773
- hist.lastSelOp = opId;
7774
- if (options && options.clearRedo !== false)
7775
- clearSelectionEvents(hist.undone);
7776
- }
7777
-
7778
- function pushSelectionToHistory(sel, dest) {
7779
- var top = lst(dest);
7780
- if (!(top && top.ranges && top.equals(sel)))
7781
- dest.push(sel);
7782
- }
7783
-
7784
- // Used to store marked span information in the history.
7785
- function attachLocalSpans(doc, change, from, to) {
7786
- var existing = change["spans_" + doc.id], n = 0;
7787
- doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function(line) {
7788
- if (line.markedSpans)
7789
- (existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans;
7790
- ++n;
7791
- });
7792
- }
7793
-
7794
- // When un/re-doing restores text containing marked spans, those
7795
- // that have been explicitly cleared should not be restored.
7796
- function removeClearedSpans(spans) {
7797
- if (!spans) return null;
7798
- for (var i = 0, out; i < spans.length; ++i) {
7799
- if (spans[i].marker.explicitlyCleared) { if (!out) out = spans.slice(0, i); }
7800
- else if (out) out.push(spans[i]);
7801
- }
7802
- return !out ? spans : out.length ? out : null;
7803
- }
7804
-
7805
- // Retrieve and filter the old marked spans stored in a change event.
7806
- function getOldSpans(doc, change) {
7807
- var found = change["spans_" + doc.id];
7808
- if (!found) return null;
7809
- for (var i = 0, nw = []; i < change.text.length; ++i)
7810
- nw.push(removeClearedSpans(found[i]));
7811
- return nw;
7812
- }
7813
-
7814
- // Used both to provide a JSON-safe object in .getHistory, and, when
7815
- // detaching a document, to split the history in two
7816
- function copyHistoryArray(events, newGroup, instantiateSel) {
7817
- for (var i = 0, copy = []; i < events.length; ++i) {
7818
- var event = events[i];
7819
- if (event.ranges) {
7820
- copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event);
7821
- continue;
7822
- }
7823
- var changes = event.changes, newChanges = [];
7824
- copy.push({changes: newChanges});
7825
- for (var j = 0; j < changes.length; ++j) {
7826
- var change = changes[j], m;
7827
- newChanges.push({from: change.from, to: change.to, text: change.text});
7828
- if (newGroup) for (var prop in change) if (m = prop.match(/^spans_(\d+)$/)) {
7829
- if (indexOf(newGroup, Number(m[1])) > -1) {
7830
- lst(newChanges)[prop] = change[prop];
7831
- delete change[prop];
7832
- }
7833
- }
7834
- }
7835
- }
7836
- return copy;
7837
- }
7838
-
7839
- // Rebasing/resetting history to deal with externally-sourced changes
7840
-
7841
- function rebaseHistSelSingle(pos, from, to, diff) {
7842
- if (to < pos.line) {
7843
- pos.line += diff;
7844
- } else if (from < pos.line) {
7845
- pos.line = from;
7846
- pos.ch = 0;
7847
- }
7848
- }
7849
-
7850
- // Tries to rebase an array of history events given a change in the
7851
- // document. If the change touches the same lines as the event, the
7852
- // event, and everything 'behind' it, is discarded. If the change is
7853
- // before the event, the event's positions are updated. Uses a
7854
- // copy-on-write scheme for the positions, to avoid having to
7855
- // reallocate them all on every rebase, but also avoid problems with
7856
- // shared position objects being unsafely updated.
7857
- function rebaseHistArray(array, from, to, diff) {
7858
- for (var i = 0; i < array.length; ++i) {
7859
- var sub = array[i], ok = true;
7860
- if (sub.ranges) {
7861
- if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true; }
7862
- for (var j = 0; j < sub.ranges.length; j++) {
7863
- rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff);
7864
- rebaseHistSelSingle(sub.ranges[j].head, from, to, diff);
7865
- }
7866
- continue;
7867
- }
7868
- for (var j = 0; j < sub.changes.length; ++j) {
7869
- var cur = sub.changes[j];
7870
- if (to < cur.from.line) {
7871
- cur.from = Pos(cur.from.line + diff, cur.from.ch);
7872
- cur.to = Pos(cur.to.line + diff, cur.to.ch);
7873
- } else if (from <= cur.to.line) {
7874
- ok = false;
7875
- break;
7876
- }
7877
- }
7878
- if (!ok) {
7879
- array.splice(0, i + 1);
7880
- i = 0;
7881
- }
7882
- }
7883
- }
7884
-
7885
- function rebaseHist(hist, change) {
7886
- var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1;
7887
- rebaseHistArray(hist.done, from, to, diff);
7888
- rebaseHistArray(hist.undone, from, to, diff);
7889
- }
7890
-
7891
- // EVENT UTILITIES
7892
-
7893
- // Due to the fact that we still support jurassic IE versions, some
7894
- // compatibility wrappers are needed.
7895
-
7896
- var e_preventDefault = CodeMirror.e_preventDefault = function(e) {
7897
- if (e.preventDefault) e.preventDefault();
7898
- else e.returnValue = false;
7899
- };
7900
- var e_stopPropagation = CodeMirror.e_stopPropagation = function(e) {
7901
- if (e.stopPropagation) e.stopPropagation();
7902
- else e.cancelBubble = true;
7903
- };
7904
- function e_defaultPrevented(e) {
7905
- return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false;
7906
- }
7907
- var e_stop = CodeMirror.e_stop = function(e) {e_preventDefault(e); e_stopPropagation(e);};
7908
-
7909
- function e_target(e) {return e.target || e.srcElement;}
7910
- function e_button(e) {
7911
- var b = e.which;
7912
- if (b == null) {
7913
- if (e.button & 1) b = 1;
7914
- else if (e.button & 2) b = 3;
7915
- else if (e.button & 4) b = 2;
7916
- }
7917
- if (mac && e.ctrlKey && b == 1) b = 3;
7918
- return b;
7919
- }
7920
-
7921
- // EVENT HANDLING
7922
-
7923
- // Lightweight event framework. on/off also work on DOM nodes,
7924
- // registering native DOM handlers.
7925
-
7926
- var on = CodeMirror.on = function(emitter, type, f) {
7927
- if (emitter.addEventListener)
7928
- emitter.addEventListener(type, f, false);
7929
- else if (emitter.attachEvent)
7930
- emitter.attachEvent("on" + type, f);
7931
- else {
7932
- var map = emitter._handlers || (emitter._handlers = {});
7933
- var arr = map[type] || (map[type] = []);
7934
- arr.push(f);
7935
- }
7936
- };
7937
-
7938
- var off = CodeMirror.off = function(emitter, type, f) {
7939
- if (emitter.removeEventListener)
7940
- emitter.removeEventListener(type, f, false);
7941
- else if (emitter.detachEvent)
7942
- emitter.detachEvent("on" + type, f);
7943
- else {
7944
- var arr = emitter._handlers && emitter._handlers[type];
7945
- if (!arr) return;
7946
- for (var i = 0; i < arr.length; ++i)
7947
- if (arr[i] == f) { arr.splice(i, 1); break; }
7948
- }
7949
- };
7950
-
7951
- var signal = CodeMirror.signal = function(emitter, type /*, values...*/) {
7952
- var arr = emitter._handlers && emitter._handlers[type];
7953
- if (!arr) return;
7954
- var args = Array.prototype.slice.call(arguments, 2);
7955
- for (var i = 0; i < arr.length; ++i) arr[i].apply(null, args);
7956
- };
7957
-
7958
- var orphanDelayedCallbacks = null;
7959
-
7960
- // Often, we want to signal events at a point where we are in the
7961
- // middle of some work, but don't want the handler to start calling
7962
- // other methods on the editor, which might be in an inconsistent
7963
- // state or simply not expect any other events to happen.
7964
- // signalLater looks whether there are any handlers, and schedules
7965
- // them to be executed when the last operation ends, or, if no
7966
- // operation is active, when a timeout fires.
7967
- function signalLater(emitter, type /*, values...*/) {
7968
- var arr = emitter._handlers && emitter._handlers[type];
7969
- if (!arr) return;
7970
- var args = Array.prototype.slice.call(arguments, 2), list;
7971
- if (operationGroup) {
7972
- list = operationGroup.delayedCallbacks;
7973
- } else if (orphanDelayedCallbacks) {
7974
- list = orphanDelayedCallbacks;
7975
- } else {
7976
- list = orphanDelayedCallbacks = [];
7977
- setTimeout(fireOrphanDelayed, 0);
7978
- }
7979
- function bnd(f) {return function(){f.apply(null, args);};};
7980
- for (var i = 0; i < arr.length; ++i)
7981
- list.push(bnd(arr[i]));
7982
- }
7983
-
7984
- function fireOrphanDelayed() {
7985
- var delayed = orphanDelayedCallbacks;
7986
- orphanDelayedCallbacks = null;
7987
- for (var i = 0; i < delayed.length; ++i) delayed[i]();
7988
- }
7989
-
7990
- // The DOM events that CodeMirror handles can be overridden by
7991
- // registering a (non-DOM) handler on the editor for the event name,
7992
- // and preventDefault-ing the event in that handler.
7993
- function signalDOMEvent(cm, e, override) {
7994
- if (typeof e == "string")
7995
- e = {type: e, preventDefault: function() { this.defaultPrevented = true; }};
7996
- signal(cm, override || e.type, cm, e);
7997
- return e_defaultPrevented(e) || e.codemirrorIgnore;
7998
- }
7999
-
8000
- function signalCursorActivity(cm) {
8001
- var arr = cm._handlers && cm._handlers.cursorActivity;
8002
- if (!arr) return;
8003
- var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = []);
8004
- for (var i = 0; i < arr.length; ++i) if (indexOf(set, arr[i]) == -1)
8005
- set.push(arr[i]);
8006
- }
8007
-
8008
- function hasHandler(emitter, type) {
8009
- var arr = emitter._handlers && emitter._handlers[type];
8010
- return arr && arr.length > 0;
8011
- }
8012
-
8013
- // Add on and off methods to a constructor's prototype, to make
8014
- // registering events on such objects more convenient.
8015
- function eventMixin(ctor) {
8016
- ctor.prototype.on = function(type, f) {on(this, type, f);};
8017
- ctor.prototype.off = function(type, f) {off(this, type, f);};
8018
- }
8019
-
8020
- // MISC UTILITIES
8021
-
8022
- // Number of pixels added to scroller and sizer to hide scrollbar
8023
- var scrollerGap = 30;
8024
-
8025
- // Returned or thrown by various protocols to signal 'I'm not
8026
- // handling this'.
8027
- var Pass = CodeMirror.Pass = {toString: function(){return "CodeMirror.Pass";}};
8028
-
8029
- // Reused option objects for setSelection & friends
8030
- var sel_dontScroll = {scroll: false}, sel_mouse = {origin: "*mouse"}, sel_move = {origin: "+move"};
8031
-
8032
- function Delayed() {this.id = null;}
8033
- Delayed.prototype.set = function(ms, f) {
8034
- clearTimeout(this.id);
8035
- this.id = setTimeout(f, ms);
8036
- };
8037
-
8038
- // Counts the column offset in a string, taking tabs into account.
8039
- // Used mostly to find indentation.
8040
- var countColumn = CodeMirror.countColumn = function(string, end, tabSize, startIndex, startValue) {
8041
- if (end == null) {
8042
- end = string.search(/[^\s\u00a0]/);
8043
- if (end == -1) end = string.length;
8044
- }
8045
- for (var i = startIndex || 0, n = startValue || 0;;) {
8046
- var nextTab = string.indexOf("\t", i);
8047
- if (nextTab < 0 || nextTab >= end)
8048
- return n + (end - i);
8049
- n += nextTab - i;
8050
- n += tabSize - (n % tabSize);
8051
- i = nextTab + 1;
8052
- }
8053
- };
8054
-
8055
- // The inverse of countColumn -- find the offset that corresponds to
8056
- // a particular column.
8057
- function findColumn(string, goal, tabSize) {
8058
- for (var pos = 0, col = 0;;) {
8059
- var nextTab = string.indexOf("\t", pos);
8060
- if (nextTab == -1) nextTab = string.length;
8061
- var skipped = nextTab - pos;
8062
- if (nextTab == string.length || col + skipped >= goal)
8063
- return pos + Math.min(skipped, goal - col);
8064
- col += nextTab - pos;
8065
- col += tabSize - (col % tabSize);
8066
- pos = nextTab + 1;
8067
- if (col >= goal) return pos;
8068
- }
8069
- }
8070
-
8071
- var spaceStrs = [""];
8072
- function spaceStr(n) {
8073
- while (spaceStrs.length <= n)
8074
- spaceStrs.push(lst(spaceStrs) + " ");
8075
- return spaceStrs[n];
8076
- }
8077
-
8078
- function lst(arr) { return arr[arr.length-1]; }
8079
-
8080
- var selectInput = function(node) { node.select(); };
8081
- if (ios) // Mobile Safari apparently has a bug where select() is broken.
8082
- selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length; };
8083
- else if (ie) // Suppress mysterious IE10 errors
8084
- selectInput = function(node) { try { node.select(); } catch(_e) {} };
8085
-
8086
- function indexOf(array, elt) {
8087
- for (var i = 0; i < array.length; ++i)
8088
- if (array[i] == elt) return i;
8089
- return -1;
8090
- }
8091
- function map(array, f) {
8092
- var out = [];
8093
- for (var i = 0; i < array.length; i++) out[i] = f(array[i], i);
8094
- return out;
8095
- }
8096
-
8097
- function nothing() {}
8098
-
8099
- function createObj(base, props) {
8100
- var inst;
8101
- if (Object.create) {
8102
- inst = Object.create(base);
8103
- } else {
8104
- nothing.prototype = base;
8105
- inst = new nothing();
8106
- }
8107
- if (props) copyObj(props, inst);
8108
- return inst;
8109
- };
8110
-
8111
- function copyObj(obj, target, overwrite) {
8112
- if (!target) target = {};
8113
- for (var prop in obj)
8114
- if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))
8115
- target[prop] = obj[prop];
8116
- return target;
8117
- }
8118
-
8119
- function bind(f) {
8120
- var args = Array.prototype.slice.call(arguments, 1);
8121
- return function(){return f.apply(null, args);};
8122
- }
8123
-
8124
- var nonASCIISingleCaseWordChar = /[\u00df\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
8125
- var isWordCharBasic = CodeMirror.isWordChar = function(ch) {
8126
- return /\w/.test(ch) || ch > "\x80" &&
8127
- (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch));
8128
- };
8129
- function isWordChar(ch, helper) {
8130
- if (!helper) return isWordCharBasic(ch);
8131
- if (helper.source.indexOf("\\w") > -1 && isWordCharBasic(ch)) return true;
8132
- return helper.test(ch);
8133
- }
8134
-
8135
- function isEmpty(obj) {
8136
- for (var n in obj) if (obj.hasOwnProperty(n) && obj[n]) return false;
8137
- return true;
8138
- }
8139
-
8140
- // Extending unicode characters. A series of a non-extending char +
8141
- // any number of extending chars is treated as a single unit as far
8142
- // as editing and measuring is concerned. This is not fully correct,
8143
- // since some scripts/fonts/browsers also treat other configurations
8144
- // of code points as a group.
8145
- var extendingChars = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;
8146
- function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch); }
8147
-
8148
- // DOM UTILITIES
8149
-
8150
- function elt(tag, content, className, style) {
8151
- var e = document.createElement(tag);
8152
- if (className) e.className = className;
8153
- if (style) e.style.cssText = style;
8154
- if (typeof content == "string") e.appendChild(document.createTextNode(content));
8155
- else if (content) for (var i = 0; i < content.length; ++i) e.appendChild(content[i]);
8156
- return e;
8157
- }
8158
-
8159
- var range;
8160
- if (document.createRange) range = function(node, start, end, endNode) {
8161
- var r = document.createRange();
8162
- r.setEnd(endNode || node, end);
8163
- r.setStart(node, start);
8164
- return r;
8165
- };
8166
- else range = function(node, start, end) {
8167
- var r = document.body.createTextRange();
8168
- try { r.moveToElementText(node.parentNode); }
8169
- catch(e) { return r; }
8170
- r.collapse(true);
8171
- r.moveEnd("character", end);
8172
- r.moveStart("character", start);
8173
- return r;
8174
- };
8175
-
8176
- function removeChildren(e) {
8177
- for (var count = e.childNodes.length; count > 0; --count)
8178
- e.removeChild(e.firstChild);
8179
- return e;
8180
- }
8181
-
8182
- function removeChildrenAndAdd(parent, e) {
8183
- return removeChildren(parent).appendChild(e);
8184
- }
8185
-
8186
- var contains = CodeMirror.contains = function(parent, child) {
8187
- if (child.nodeType == 3) // Android browser always returns false when child is a textnode
8188
- child = child.parentNode;
8189
- if (parent.contains)
8190
- return parent.contains(child);
8191
- do {
8192
- if (child.nodeType == 11) child = child.host;
8193
- if (child == parent) return true;
8194
- } while (child = child.parentNode);
8195
- };
8196
-
8197
- function activeElt() { return document.activeElement; }
8198
- // Older versions of IE throws unspecified error when touching
8199
- // document.activeElement in some cases (during loading, in iframe)
8200
- if (ie && ie_version < 11) activeElt = function() {
8201
- try { return document.activeElement; }
8202
- catch(e) { return document.body; }
8203
- };
8204
-
8205
- function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*"); }
8206
- var rmClass = CodeMirror.rmClass = function(node, cls) {
8207
- var current = node.className;
8208
- var match = classTest(cls).exec(current);
8209
- if (match) {
8210
- var after = current.slice(match.index + match[0].length);
8211
- node.className = current.slice(0, match.index) + (after ? match[1] + after : "");
8212
- }
8213
- };
8214
- var addClass = CodeMirror.addClass = function(node, cls) {
8215
- var current = node.className;
8216
- if (!classTest(cls).test(current)) node.className += (current ? " " : "") + cls;
8217
- };
8218
- function joinClasses(a, b) {
8219
- var as = a.split(" ");
8220
- for (var i = 0; i < as.length; i++)
8221
- if (as[i] && !classTest(as[i]).test(b)) b += " " + as[i];
8222
- return b;
8223
- }
8224
-
8225
- // WINDOW-WIDE EVENTS
8226
-
8227
- // These must be handled carefully, because naively registering a
8228
- // handler for each editor will cause the editors to never be
8229
- // garbage collected.
8230
-
8231
- function forEachCodeMirror(f) {
8232
- if (!document.body.getElementsByClassName) return;
8233
- var byClass = document.body.getElementsByClassName("CodeMirror");
8234
- for (var i = 0; i < byClass.length; i++) {
8235
- var cm = byClass[i].CodeMirror;
8236
- if (cm) f(cm);
8237
- }
8238
- }
8239
-
8240
- var globalsRegistered = false;
8241
- function ensureGlobalHandlers() {
8242
- if (globalsRegistered) return;
8243
- registerGlobalHandlers();
8244
- globalsRegistered = true;
8245
- }
8246
- function registerGlobalHandlers() {
8247
- // When the window resizes, we need to refresh active editors.
8248
- var resizeTimer;
8249
- on(window, "resize", function() {
8250
- if (resizeTimer == null) resizeTimer = setTimeout(function() {
8251
- resizeTimer = null;
8252
- forEachCodeMirror(onResize);
8253
- }, 100);
8254
- });
8255
- // When the window loses focus, we want to show the editor as blurred
8256
- on(window, "blur", function() {
8257
- forEachCodeMirror(onBlur);
8258
- });
8259
- }
8260
-
8261
- // FEATURE DETECTION
8262
-
8263
- // Detect drag-and-drop
8264
- var dragAndDrop = function() {
8265
- // There is *some* kind of drag-and-drop support in IE6-8, but I
8266
- // couldn't get it to work yet.
8267
- if (ie && ie_version < 9) return false;
8268
- var div = elt('div');
8269
- return "draggable" in div || "dragDrop" in div;
8270
- }();
8271
-
8272
- var zwspSupported;
8273
- function zeroWidthElement(measure) {
8274
- if (zwspSupported == null) {
8275
- var test = elt("span", "\u200b");
8276
- removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]));
8277
- if (measure.firstChild.offsetHeight != 0)
8278
- zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8);
8279
- }
8280
- var node = zwspSupported ? elt("span", "\u200b") :
8281
- elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px");
8282
- node.setAttribute("cm-text", "");
8283
- return node;
8284
- }
8285
-
8286
- // Feature-detect IE's crummy client rect reporting for bidi text
8287
- var badBidiRects;
8288
- function hasBadBidiRects(measure) {
8289
- if (badBidiRects != null) return badBidiRects;
8290
- var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA"));
8291
- var r0 = range(txt, 0, 1).getBoundingClientRect();
8292
- if (!r0 || r0.left == r0.right) return false; // Safari returns null in some cases (#2780)
8293
- var r1 = range(txt, 1, 2).getBoundingClientRect();
8294
- return badBidiRects = (r1.right - r0.right < 3);
8295
- }
8296
-
8297
- // See if "".split is the broken IE version, if so, provide an
8298
- // alternative way to split lines.
8299
- var splitLines = CodeMirror.splitLines = "\n\nb".split(/\n/).length != 3 ? function(string) {
8300
- var pos = 0, result = [], l = string.length;
8301
- while (pos <= l) {
8302
- var nl = string.indexOf("\n", pos);
8303
- if (nl == -1) nl = string.length;
8304
- var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
8305
- var rt = line.indexOf("\r");
8306
- if (rt != -1) {
8307
- result.push(line.slice(0, rt));
8308
- pos += rt + 1;
8309
- } else {
8310
- result.push(line);
8311
- pos = nl + 1;
8312
- }
8313
- }
8314
- return result;
8315
- } : function(string){return string.split(/\r\n?|\n/);};
8316
-
8317
- var hasSelection = window.getSelection ? function(te) {
8318
- try { return te.selectionStart != te.selectionEnd; }
8319
- catch(e) { return false; }
8320
- } : function(te) {
8321
- try {var range = te.ownerDocument.selection.createRange();}
8322
- catch(e) {}
8323
- if (!range || range.parentElement() != te) return false;
8324
- return range.compareEndPoints("StartToEnd", range) != 0;
8325
- };
8326
-
8327
- var hasCopyEvent = (function() {
8328
- var e = elt("div");
8329
- if ("oncopy" in e) return true;
8330
- e.setAttribute("oncopy", "return;");
8331
- return typeof e.oncopy == "function";
8332
- })();
8333
-
8334
- var badZoomedRects = null;
8335
- function hasBadZoomedRects(measure) {
8336
- if (badZoomedRects != null) return badZoomedRects;
8337
- var node = removeChildrenAndAdd(measure, elt("span", "x"));
8338
- var normal = node.getBoundingClientRect();
8339
- var fromRange = range(node, 0, 1).getBoundingClientRect();
8340
- return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1;
8341
- }
8342
-
8343
- // KEY NAMES
8344
-
8345
- var keyNames = {3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
8346
- 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
8347
- 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
8348
- 46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod", 107: "=", 109: "-", 127: "Delete",
8349
- 173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
8350
- 221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete",
8351
- 63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"};
8352
- CodeMirror.keyNames = keyNames;
8353
- (function() {
8354
- // Number keys
8355
- for (var i = 0; i < 10; i++) keyNames[i + 48] = keyNames[i + 96] = String(i);
8356
- // Alphabetic keys
8357
- for (var i = 65; i <= 90; i++) keyNames[i] = String.fromCharCode(i);
8358
- // Function keys
8359
- for (var i = 1; i <= 12; i++) keyNames[i + 111] = keyNames[i + 63235] = "F" + i;
8360
- })();
8361
-
8362
- // BIDI HELPERS
8363
-
8364
- function iterateBidiSections(order, from, to, f) {
8365
- if (!order) return f(from, to, "ltr");
8366
- var found = false;
8367
- for (var i = 0; i < order.length; ++i) {
8368
- var part = order[i];
8369
- if (part.from < to && part.to > from || from == to && part.to == from) {
8370
- f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr");
8371
- found = true;
8372
- }
8373
- }
8374
- if (!found) f(from, to, "ltr");
8375
- }
8376
-
8377
- function bidiLeft(part) { return part.level % 2 ? part.to : part.from; }
8378
- function bidiRight(part) { return part.level % 2 ? part.from : part.to; }
8379
-
8380
- function lineLeft(line) { var order = getOrder(line); return order ? bidiLeft(order[0]) : 0; }
8381
- function lineRight(line) {
8382
- var order = getOrder(line);
8383
- if (!order) return line.text.length;
8384
- return bidiRight(lst(order));
8385
- }
8386
-
8387
- function lineStart(cm, lineN) {
8388
- var line = getLine(cm.doc, lineN);
8389
- var visual = visualLine(line);
8390
- if (visual != line) lineN = lineNo(visual);
8391
- var order = getOrder(visual);
8392
- var ch = !order ? 0 : order[0].level % 2 ? lineRight(visual) : lineLeft(visual);
8393
- return Pos(lineN, ch);
8394
- }
8395
- function lineEnd(cm, lineN) {
8396
- var merged, line = getLine(cm.doc, lineN);
8397
- while (merged = collapsedSpanAtEnd(line)) {
8398
- line = merged.find(1, true).line;
8399
- lineN = null;
8400
- }
8401
- var order = getOrder(line);
8402
- var ch = !order ? line.text.length : order[0].level % 2 ? lineLeft(line) : lineRight(line);
8403
- return Pos(lineN == null ? lineNo(line) : lineN, ch);
8404
- }
8405
- function lineStartSmart(cm, pos) {
8406
- var start = lineStart(cm, pos.line);
8407
- var line = getLine(cm.doc, start.line);
8408
- var order = getOrder(line);
8409
- if (!order || order[0].level == 0) {
8410
- var firstNonWS = Math.max(0, line.text.search(/\S/));
8411
- var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch;
8412
- return Pos(start.line, inWS ? 0 : firstNonWS);
8413
- }
8414
- return start;
8415
- }
8416
-
8417
- function compareBidiLevel(order, a, b) {
8418
- var linedir = order[0].level;
8419
- if (a == linedir) return true;
8420
- if (b == linedir) return false;
8421
- return a < b;
8422
- }
8423
- var bidiOther;
8424
- function getBidiPartAt(order, pos) {
8425
- bidiOther = null;
8426
- for (var i = 0, found; i < order.length; ++i) {
8427
- var cur = order[i];
8428
- if (cur.from < pos && cur.to > pos) return i;
8429
- if ((cur.from == pos || cur.to == pos)) {
8430
- if (found == null) {
8431
- found = i;
8432
- } else if (compareBidiLevel(order, cur.level, order[found].level)) {
8433
- if (cur.from != cur.to) bidiOther = found;
8434
- return i;
8435
- } else {
8436
- if (cur.from != cur.to) bidiOther = i;
8437
- return found;
8438
- }
8439
- }
8440
- }
8441
- return found;
8442
- }
8443
-
8444
- function moveInLine(line, pos, dir, byUnit) {
8445
- if (!byUnit) return pos + dir;
8446
- do pos += dir;
8447
- while (pos > 0 && isExtendingChar(line.text.charAt(pos)));
8448
- return pos;
8449
- }
8450
-
8451
- // This is needed in order to move 'visually' through bi-directional
8452
- // text -- i.e., pressing left should make the cursor go left, even
8453
- // when in RTL text. The tricky part is the 'jumps', where RTL and
8454
- // LTR text touch each other. This often requires the cursor offset
8455
- // to move more than one unit, in order to visually move one unit.
8456
- function moveVisually(line, start, dir, byUnit) {
8457
- var bidi = getOrder(line);
8458
- if (!bidi) return moveLogically(line, start, dir, byUnit);
8459
- var pos = getBidiPartAt(bidi, start), part = bidi[pos];
8460
- var target = moveInLine(line, start, part.level % 2 ? -dir : dir, byUnit);
8461
-
8462
- for (;;) {
8463
- if (target > part.from && target < part.to) return target;
8464
- if (target == part.from || target == part.to) {
8465
- if (getBidiPartAt(bidi, target) == pos) return target;
8466
- part = bidi[pos += dir];
8467
- return (dir > 0) == part.level % 2 ? part.to : part.from;
8468
- } else {
8469
- part = bidi[pos += dir];
8470
- if (!part) return null;
8471
- if ((dir > 0) == part.level % 2)
8472
- target = moveInLine(line, part.to, -1, byUnit);
8473
- else
8474
- target = moveInLine(line, part.from, 1, byUnit);
8475
- }
8476
- }
8477
- }
8478
-
8479
- function moveLogically(line, start, dir, byUnit) {
8480
- var target = start + dir;
8481
- if (byUnit) while (target > 0 && isExtendingChar(line.text.charAt(target))) target += dir;
8482
- return target < 0 || target > line.text.length ? null : target;
8483
- }
8484
-
8485
- // Bidirectional ordering algorithm
8486
- // See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
8487
- // that this (partially) implements.
8488
-
8489
- // One-char codes used for character types:
8490
- // L (L): Left-to-Right
8491
- // R (R): Right-to-Left
8492
- // r (AL): Right-to-Left Arabic
8493
- // 1 (EN): European Number
8494
- // + (ES): European Number Separator
8495
- // % (ET): European Number Terminator
8496
- // n (AN): Arabic Number
8497
- // , (CS): Common Number Separator
8498
- // m (NSM): Non-Spacing Mark
8499
- // b (BN): Boundary Neutral
8500
- // s (B): Paragraph Separator
8501
- // t (S): Segment Separator
8502
- // w (WS): Whitespace
8503
- // N (ON): Other Neutrals
8504
-
8505
- // Returns null if characters are ordered as they appear
8506
- // (left-to-right), or an array of sections ({from, to, level}
8507
- // objects) in the order in which they occur visually.
8508
- var bidiOrdering = (function() {
8509
- // Character types for codepoints 0 to 0xff
8510
- var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN";
8511
- // Character types for codepoints 0x600 to 0x6ff
8512
- var arabicTypes = "rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmm";
8513
- function charType(code) {
8514
- if (code <= 0xf7) return lowTypes.charAt(code);
8515
- else if (0x590 <= code && code <= 0x5f4) return "R";
8516
- else if (0x600 <= code && code <= 0x6ed) return arabicTypes.charAt(code - 0x600);
8517
- else if (0x6ee <= code && code <= 0x8ac) return "r";
8518
- else if (0x2000 <= code && code <= 0x200b) return "w";
8519
- else if (code == 0x200c) return "b";
8520
- else return "L";
8521
- }
8522
-
8523
- var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
8524
- var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/;
8525
- // Browsers seem to always treat the boundaries of block elements as being L.
8526
- var outerType = "L";
8527
-
8528
- function BidiSpan(level, from, to) {
8529
- this.level = level;
8530
- this.from = from; this.to = to;
8531
- }
8532
-
8533
- return function(str) {
8534
- if (!bidiRE.test(str)) return false;
8535
- var len = str.length, types = [];
8536
- for (var i = 0, type; i < len; ++i)
8537
- types.push(type = charType(str.charCodeAt(i)));
8538
-
8539
- // W1. Examine each non-spacing mark (NSM) in the level run, and
8540
- // change the type of the NSM to the type of the previous
8541
- // character. If the NSM is at the start of the level run, it will
8542
- // get the type of sor.
8543
- for (var i = 0, prev = outerType; i < len; ++i) {
8544
- var type = types[i];
8545
- if (type == "m") types[i] = prev;
8546
- else prev = type;
8547
- }
8548
-
8549
- // W2. Search backwards from each instance of a European number
8550
- // until the first strong type (R, L, AL, or sor) is found. If an
8551
- // AL is found, change the type of the European number to Arabic
8552
- // number.
8553
- // W3. Change all ALs to R.
8554
- for (var i = 0, cur = outerType; i < len; ++i) {
8555
- var type = types[i];
8556
- if (type == "1" && cur == "r") types[i] = "n";
8557
- else if (isStrong.test(type)) { cur = type; if (type == "r") types[i] = "R"; }
8558
- }
8559
-
8560
- // W4. A single European separator between two European numbers
8561
- // changes to a European number. A single common separator between
8562
- // two numbers of the same type changes to that type.
8563
- for (var i = 1, prev = types[0]; i < len - 1; ++i) {
8564
- var type = types[i];
8565
- if (type == "+" && prev == "1" && types[i+1] == "1") types[i] = "1";
8566
- else if (type == "," && prev == types[i+1] &&
8567
- (prev == "1" || prev == "n")) types[i] = prev;
8568
- prev = type;
8569
- }
8570
-
8571
- // W5. A sequence of European terminators adjacent to European
8572
- // numbers changes to all European numbers.
8573
- // W6. Otherwise, separators and terminators change to Other
8574
- // Neutral.
8575
- for (var i = 0; i < len; ++i) {
8576
- var type = types[i];
8577
- if (type == ",") types[i] = "N";
8578
- else if (type == "%") {
8579
- for (var end = i + 1; end < len && types[end] == "%"; ++end) {}
8580
- var replace = (i && types[i-1] == "!") || (end < len && types[end] == "1") ? "1" : "N";
8581
- for (var j = i; j < end; ++j) types[j] = replace;
8582
- i = end - 1;
8583
- }
8584
- }
8585
-
8586
- // W7. Search backwards from each instance of a European number
8587
- // until the first strong type (R, L, or sor) is found. If an L is
8588
- // found, then change the type of the European number to L.
8589
- for (var i = 0, cur = outerType; i < len; ++i) {
8590
- var type = types[i];
8591
- if (cur == "L" && type == "1") types[i] = "L";
8592
- else if (isStrong.test(type)) cur = type;
8593
- }
8594
-
8595
- // N1. A sequence of neutrals takes the direction of the
8596
- // surrounding strong text if the text on both sides has the same
8597
- // direction. European and Arabic numbers act as if they were R in
8598
- // terms of their influence on neutrals. Start-of-level-run (sor)
8599
- // and end-of-level-run (eor) are used at level run boundaries.
8600
- // N2. Any remaining neutrals take the embedding direction.
8601
- for (var i = 0; i < len; ++i) {
8602
- if (isNeutral.test(types[i])) {
8603
- for (var end = i + 1; end < len && isNeutral.test(types[end]); ++end) {}
8604
- var before = (i ? types[i-1] : outerType) == "L";
8605
- var after = (end < len ? types[end] : outerType) == "L";
8606
- var replace = before || after ? "L" : "R";
8607
- for (var j = i; j < end; ++j) types[j] = replace;
8608
- i = end - 1;
8609
- }
8610
- }
8611
-
8612
- // Here we depart from the documented algorithm, in order to avoid
8613
- // building up an actual levels array. Since there are only three
8614
- // levels (0, 1, 2) in an implementation that doesn't take
8615
- // explicit embedding into account, we can build up the order on
8616
- // the fly, without following the level-based algorithm.
8617
- var order = [], m;
8618
- for (var i = 0; i < len;) {
8619
- if (countsAsLeft.test(types[i])) {
8620
- var start = i;
8621
- for (++i; i < len && countsAsLeft.test(types[i]); ++i) {}
8622
- order.push(new BidiSpan(0, start, i));
8623
- } else {
8624
- var pos = i, at = order.length;
8625
- for (++i; i < len && types[i] != "L"; ++i) {}
8626
- for (var j = pos; j < i;) {
8627
- if (countsAsNum.test(types[j])) {
8628
- if (pos < j) order.splice(at, 0, new BidiSpan(1, pos, j));
8629
- var nstart = j;
8630
- for (++j; j < i && countsAsNum.test(types[j]); ++j) {}
8631
- order.splice(at, 0, new BidiSpan(2, nstart, j));
8632
- pos = j;
8633
- } else ++j;
8634
- }
8635
- if (pos < i) order.splice(at, 0, new BidiSpan(1, pos, i));
8636
- }
8637
- }
8638
- if (order[0].level == 1 && (m = str.match(/^\s+/))) {
8639
- order[0].from = m[0].length;
8640
- order.unshift(new BidiSpan(0, 0, m[0].length));
8641
- }
8642
- if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
8643
- lst(order).to -= m[0].length;
8644
- order.push(new BidiSpan(0, len - m[0].length, len));
8645
- }
8646
- if (order[0].level != lst(order).level)
8647
- order.push(new BidiSpan(order[0].level, len, len));
8648
-
8649
- return order;
8650
- };
8651
- })();
8652
-
8653
- // THE END
8654
-
8655
- CodeMirror.version = "5.0.1";
8656
-
8657
- return CodeMirror;
8658
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
js/codemirror/old/codemirror.min.js DELETED
@@ -1,5 +0,0 @@
1
- !function(e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else{if("function"==typeof define&&define.amd)return define([],e);this.CodeMirror=e()}}(function(){"use strict";function e(r,n){if(!(this instanceof e))return new e(r,n);this.options=n=n?Oo(n):{},Oo(Kl,n,!1),d(n);var i=n.value;"string"==typeof i&&(i=new ps(i,n.mode)),this.doc=i;var o=new e.inputStyles[n.inputStyle](this),l=this.display=new t(r,i,o);l.wrapper.CodeMirror=this,u(this),s(this),n.lineWrapping&&(this.display.wrapper.className+=" CodeMirror-wrap"),n.autofocus&&!wl&&l.input.focus(),m(this),this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,focused:!1,suppressEdits:!1,pasteIncoming:!1,cutIncoming:!1,draggingText:!1,highlight:new So,keySeq:null,specialChars:null};var a=this;cl&&11>fl&&setTimeout(function(){a.display.input.reset(!0)},20),Rr(this),Vo(),mr(this),this.curOp.forceUpdate=!0,Vi(this,i),n.autofocus&&!wl||a.hasFocus()?setTimeout(Do(cn,this),20):fn(this);for(var c in jl)jl.hasOwnProperty(c)&&jl[c](this,n[c],Xl);C(this),n.finishInit&&n.finishInit(this);for(var f=0;f<ql.length;++f)ql[f](this);br(this),hl&&n.lineWrapping&&"optimizelegibility"==getComputedStyle(l.lineDiv).textRendering&&(l.lineDiv.style.textRendering="auto")}function t(e,t,r){var n=this;this.input=r,n.scrollbarFiller=zo("div",null,"CodeMirror-scrollbar-filler"),n.scrollbarFiller.setAttribute("cm-not-content","true"),n.gutterFiller=zo("div",null,"CodeMirror-gutter-filler"),n.gutterFiller.setAttribute("cm-not-content","true"),n.lineDiv=zo("div",null,"CodeMirror-code"),n.selectionDiv=zo("div",null,null,"position: relative; z-index: 1"),n.cursorDiv=zo("div",null,"CodeMirror-cursors"),n.measure=zo("div",null,"CodeMirror-measure"),n.lineMeasure=zo("div",null,"CodeMirror-measure"),n.lineSpace=zo("div",[n.measure,n.lineMeasure,n.selectionDiv,n.cursorDiv,n.lineDiv],null,"position: relative; outline: none"),n.mover=zo("div",[zo("div",[n.lineSpace],"CodeMirror-lines")],null,"position: relative"),n.sizer=zo("div",[n.mover],"CodeMirror-sizer"),n.sizerWidth=null,n.heightForcer=zo("div",null,null,"position: absolute; height: "+Ls+"px; width: 1px;"),n.gutters=zo("div",null,"CodeMirror-gutters"),n.lineGutter=null,n.scroller=zo("div",[n.sizer,n.heightForcer,n.gutters],"CodeMirror-scroll"),n.scroller.setAttribute("tabIndex","-1"),n.wrapper=zo("div",[n.scrollbarFiller,n.gutterFiller,n.scroller],"CodeMirror"),cl&&8>fl&&(n.gutters.style.zIndex=-1,n.scroller.style.paddingRight=0),hl||sl&&wl||(n.scroller.draggable=!0),e&&(e.appendChild?e.appendChild(n.wrapper):e(n.wrapper)),n.viewFrom=n.viewTo=t.first,n.reportedViewFrom=n.reportedViewTo=t.first,n.view=[],n.renderedView=null,n.externalMeasured=null,n.viewOffset=0,n.lastWrapHeight=n.lastWrapWidth=0,n.updateLineNumbers=null,n.nativeBarWidth=n.barHeight=n.barWidth=0,n.scrollbarsClipped=!1,n.lineNumWidth=n.lineNumInnerWidth=n.lineNumChars=null,n.alignWidgets=!1,n.cachedCharWidth=n.cachedTextHeight=n.cachedPaddingH=null,n.maxLine=null,n.maxLineLength=0,n.maxLineChanged=!1,n.wheelDX=n.wheelDY=n.wheelStartX=n.wheelStartY=null,n.shift=!1,n.selForContextMenu=null,n.activeTouch=null,r.init(n)}function r(t){t.doc.mode=e.getMode(t.options,t.doc.modeOption),n(t)}function n(e){e.doc.iter(function(e){e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null)}),e.doc.frontier=e.doc.first,zt(e,100),e.state.modeGen++,e.curOp&&Dr(e)}function i(e){e.options.lineWrapping?(Bs(e.display.wrapper,"CodeMirror-wrap"),e.display.sizer.style.minWidth="",e.display.sizerWidth=null):(Rs(e.display.wrapper,"CodeMirror-wrap"),h(e)),l(e),Dr(e),ir(e),setTimeout(function(){y(e)},100)}function o(e){var t=gr(e.display),r=e.options.lineWrapping,n=r&&Math.max(5,e.display.scroller.clientWidth/vr(e.display)-3);return function(i){if(gi(e.doc,i))return 0;var o=0;if(i.widgets)for(var l=0;l<i.widgets.length;l++)i.widgets[l].height&&(o+=i.widgets[l].height);return r?o+(Math.ceil(i.text.length/n)||1)*t:o+t}}function l(e){var t=e.doc,r=o(e);t.iter(function(e){var t=r(e);t!=e.height&&_i(e,t)})}function s(e){e.display.wrapper.className=e.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+e.options.theme.replace(/(^|\s)\s*/g," cm-s-"),ir(e)}function a(e){u(e),Dr(e),setTimeout(function(){x(e)},20)}function u(e){var t=e.display.gutters,r=e.options.gutters;Eo(t);for(var n=0;n<r.length;++n){var i=r[n],o=t.appendChild(zo("div",null,"CodeMirror-gutter "+i));"CodeMirror-linenumbers"==i&&(e.display.lineGutter=o,o.style.width=(e.display.lineNumWidth||1)+"px")}t.style.display=n?"":"none",c(e)}function c(e){var t=e.display.gutters.offsetWidth;e.display.sizer.style.marginLeft=t+"px"}function f(e){if(0==e.height)return 0;for(var t,r=e.text.length,n=e;t=ai(n);){var i=t.find(0,!0);n=i.from.line,r+=i.from.ch-i.to.ch}for(n=e;t=ui(n);){var i=t.find(0,!0);r-=n.text.length-i.from.ch,n=i.to.line,r+=n.text.length-i.to.ch}return r}function h(e){var t=e.display,r=e.doc;t.maxLine=Ki(r,r.first),t.maxLineLength=f(t.maxLine),t.maxLineChanged=!0,r.iter(function(e){var r=f(e);r>t.maxLineLength&&(t.maxLineLength=r,t.maxLine=e)})}function d(e){var t=Mo(e.gutters,"CodeMirror-linenumbers");-1==t&&e.lineNumbers?e.gutters=e.gutters.concat(["CodeMirror-linenumbers"]):t>-1&&!e.lineNumbers&&(e.gutters=e.gutters.slice(0),e.gutters.splice(t,1))}function p(e){var t=e.display,r=t.gutters.offsetWidth,n=Math.round(e.doc.height+Gt(e.display));return{clientHeight:t.scroller.clientHeight,viewHeight:t.wrapper.clientHeight,scrollWidth:t.scroller.scrollWidth,clientWidth:t.scroller.clientWidth,viewWidth:t.wrapper.clientWidth,barLeft:e.options.fixedGutter?r:0,docHeight:n,scrollHeight:n+Vt(e)+t.barHeight,nativeBarWidth:t.nativeBarWidth,gutterWidth:r}}function g(e,t,r){this.cm=r;var n=this.vert=zo("div",[zo("div",null,null,"min-width: 1px")],"CodeMirror-vscrollbar"),i=this.horiz=zo("div",[zo("div",null,null,"height: 100%; min-height: 1px")],"CodeMirror-hscrollbar");e(n),e(i),ws(n,"scroll",function(){n.clientHeight&&t(n.scrollTop,"vertical")}),ws(i,"scroll",function(){i.clientWidth&&t(i.scrollLeft,"horizontal")}),this.checkedOverlay=!1,cl&&8>fl&&(this.horiz.style.minHeight=this.vert.style.minWidth="18px")}function v(){}function m(t){t.display.scrollbars&&(t.display.scrollbars.clear(),t.display.scrollbars.addClass&&Rs(t.display.wrapper,t.display.scrollbars.addClass)),t.display.scrollbars=new e.scrollbarModel[t.options.scrollbarStyle](function(e){t.display.wrapper.insertBefore(e,t.display.scrollbarFiller),ws(e,"mousedown",function(){t.state.focused&&setTimeout(function(){t.display.input.focus()},0)}),e.setAttribute("cm-not-content","true")},function(e,r){"horizontal"==r?Qr(t,e):Zr(t,e)},t),t.display.scrollbars.addClass&&Bs(t.display.wrapper,t.display.scrollbars.addClass)}function y(e,t){t||(t=p(e));var r=e.display.barWidth,n=e.display.barHeight;b(e,t);for(var i=0;4>i&&r!=e.display.barWidth||n!=e.display.barHeight;i++)r!=e.display.barWidth&&e.options.lineWrapping&&O(e),b(e,p(e)),r=e.display.barWidth,n=e.display.barHeight}function b(e,t){var r=e.display,n=r.scrollbars.update(t);r.sizer.style.paddingRight=(r.barWidth=n.right)+"px",r.sizer.style.paddingBottom=(r.barHeight=n.bottom)+"px",n.right&&n.bottom?(r.scrollbarFiller.style.display="block",r.scrollbarFiller.style.height=n.bottom+"px",r.scrollbarFiller.style.width=n.right+"px"):r.scrollbarFiller.style.display="",n.bottom&&e.options.coverGutterNextToScrollbar&&e.options.fixedGutter?(r.gutterFiller.style.display="block",r.gutterFiller.style.height=n.bottom+"px",r.gutterFiller.style.width=t.gutterWidth+"px"):r.gutterFiller.style.display=""}function w(e,t,r){var n=r&&null!=r.top?Math.max(0,r.top):e.scroller.scrollTop;n=Math.floor(n-Bt(e));var i=r&&null!=r.bottom?r.bottom:n+e.wrapper.clientHeight,o=$i(t,n),l=$i(t,i);if(r&&r.ensure){var s=r.ensure.from.line,a=r.ensure.to.line;o>s?(o=s,l=$i(t,qi(Ki(t,s))+e.wrapper.clientHeight)):Math.min(a,t.lastLine())>=l&&(o=$i(t,qi(Ki(t,a))-e.wrapper.clientHeight),l=a)}return{from:o,to:Math.max(l,o+1)}}function x(e){var t=e.display,r=t.view;if(t.alignWidgets||t.gutters.firstChild&&e.options.fixedGutter){for(var n=L(t)-t.scroller.scrollLeft+e.doc.scrollLeft,i=t.gutters.offsetWidth,o=n+"px",l=0;l<r.length;l++)if(!r[l].hidden){e.options.fixedGutter&&r[l].gutter&&(r[l].gutter.style.left=o);var s=r[l].alignable;if(s)for(var a=0;a<s.length;a++)s[a].style.left=o}e.options.fixedGutter&&(t.gutters.style.left=n+i+"px")}}function C(e){if(!e.options.lineNumbers)return!1;var t=e.doc,r=S(e.options,t.first+t.size-1),n=e.display;if(r.length!=n.lineNumChars){var i=n.measure.appendChild(zo("div",[zo("div",r)],"CodeMirror-linenumber CodeMirror-gutter-elt")),o=i.firstChild.offsetWidth,l=i.offsetWidth-o;return n.lineGutter.style.width="",n.lineNumInnerWidth=Math.max(o,n.lineGutter.offsetWidth-l)+1,n.lineNumWidth=n.lineNumInnerWidth+l,n.lineNumChars=n.lineNumInnerWidth?r.length:-1,n.lineGutter.style.width=n.lineNumWidth+"px",c(e),!0}return!1}function S(e,t){return String(e.lineNumberFormatter(t+e.firstLineNumber))}function L(e){return e.scroller.getBoundingClientRect().left-e.sizer.getBoundingClientRect().left}function k(e,t,r){var n=e.display;this.viewport=t,this.visible=w(n,e.doc,t),this.editorIsHidden=!n.wrapper.offsetWidth,this.wrapperHeight=n.wrapper.clientHeight,this.wrapperWidth=n.wrapper.clientWidth,this.oldDisplayWidth=Kt(e),this.force=r,this.dims=H(e),this.events=[]}function T(e){var t=e.display;!t.scrollbarsClipped&&t.scroller.offsetWidth&&(t.nativeBarWidth=t.scroller.offsetWidth-t.scroller.clientWidth,t.heightForcer.style.height=Vt(e)+"px",t.sizer.style.marginBottom=-t.nativeBarWidth+"px",t.sizer.style.borderRightWidth=Vt(e)+"px",t.scrollbarsClipped=!0)}function M(e,t){var r=e.display,n=e.doc;if(t.editorIsHidden)return Pr(e),!1;if(!t.force&&t.visible.from>=r.viewFrom&&t.visible.to<=r.viewTo&&(null==r.updateLineNumbers||r.updateLineNumbers>=r.viewTo)&&r.renderedView==r.view&&0==Fr(e))return!1;C(e)&&(Pr(e),t.dims=H(e));var i=n.first+n.size,o=Math.max(t.visible.from-e.options.viewportMargin,n.first),l=Math.min(i,t.visible.to+e.options.viewportMargin);r.viewFrom<o&&o-r.viewFrom<20&&(o=Math.max(n.first,r.viewFrom)),r.viewTo>l&&r.viewTo-l<20&&(l=Math.min(i,r.viewTo)),Ml&&(o=di(e.doc,o),l=pi(e.doc,l));var s=o!=r.viewFrom||l!=r.viewTo||r.lastWrapHeight!=t.wrapperHeight||r.lastWrapWidth!=t.wrapperWidth;Er(e,o,l),r.viewOffset=qi(Ki(e.doc,r.viewFrom)),e.display.mover.style.top=r.viewOffset+"px";var a=Fr(e);if(!s&&0==a&&!t.force&&r.renderedView==r.view&&(null==r.updateLineNumbers||r.updateLineNumbers>=r.viewTo))return!1;var u=Ro();return a>4&&(r.lineDiv.style.display="none"),P(e,r.updateLineNumbers,t.dims),a>4&&(r.lineDiv.style.display=""),r.renderedView=r.view,u&&Ro()!=u&&u.offsetHeight&&u.focus(),Eo(r.cursorDiv),Eo(r.selectionDiv),r.gutters.style.height=0,s&&(r.lastWrapHeight=t.wrapperHeight,r.lastWrapWidth=t.wrapperWidth,zt(e,400)),r.updateLineNumbers=null,!0}function A(e,t){for(var r=t.force,n=t.viewport,i=!0;;i=!1){if(i&&e.options.lineWrapping&&t.oldDisplayWidth!=Kt(e))r=!0;else if(r=!1,n&&null!=n.top&&(n={top:Math.min(e.doc.height+Gt(e.display)-jt(e),n.top)}),t.visible=w(e.display,e.doc,n),t.visible.from>=e.display.viewFrom&&t.visible.to<=e.display.viewTo)break;if(!M(e,t))break;O(e);var o=p(e);Ot(e),W(e,o),y(e,o)}t.signal(e,"update",e),(e.display.viewFrom!=e.display.reportedViewFrom||e.display.viewTo!=e.display.reportedViewTo)&&(t.signal(e,"viewportChange",e,e.display.viewFrom,e.display.viewTo),e.display.reportedViewFrom=e.display.viewFrom,e.display.reportedViewTo=e.display.viewTo)}function N(e,t){var r=new k(e,t);if(M(e,r)){O(e),A(e,r);var n=p(e);Ot(e),W(e,n),y(e,n),r.finish()}}function W(e,t){e.display.sizer.style.minHeight=t.docHeight+"px";var r=t.docHeight+e.display.barHeight;e.display.heightForcer.style.top=r+"px",e.display.gutters.style.height=Math.max(r+Vt(e),t.clientHeight)+"px"}function O(e){for(var t=e.display,r=t.lineDiv.offsetTop,n=0;n<t.view.length;n++){var i,o=t.view[n];if(!o.hidden){if(cl&&8>fl){var l=o.node.offsetTop+o.node.offsetHeight;i=l-r,r=l}else{var s=o.node.getBoundingClientRect();i=s.bottom-s.top}var a=o.line.height-i;if(2>i&&(i=gr(t)),(a>.001||-.001>a)&&(_i(o.line,i),D(o.line),o.rest))for(var u=0;u<o.rest.length;u++)D(o.rest[u])}}}function D(e){if(e.widgets)for(var t=0;t<e.widgets.length;++t)e.widgets[t].height=e.widgets[t].node.offsetHeight}function H(e){for(var t=e.display,r={},n={},i=t.gutters.clientLeft,o=t.gutters.firstChild,l=0;o;o=o.nextSibling,++l)r[e.options.gutters[l]]=o.offsetLeft+o.clientLeft+i,n[e.options.gutters[l]]=o.clientWidth;return{fixedPos:L(t),gutterTotalWidth:t.gutters.offsetWidth,gutterLeft:r,gutterWidth:n,wrapperWidth:t.wrapper.clientWidth}}function P(e,t,r){function n(t){var r=t.nextSibling;return hl&&xl&&e.display.currentWheelTarget==t?t.style.display="none":t.parentNode.removeChild(t),r}for(var i=e.display,o=e.options.lineNumbers,l=i.lineDiv,s=l.firstChild,a=i.view,u=i.viewFrom,c=0;c<a.length;c++){var f=a[c];if(f.hidden);else if(f.node&&f.node.parentNode==l){for(;s!=f.node;)s=n(s);var h=o&&null!=t&&u>=t&&f.lineNumber;f.changes&&(Mo(f.changes,"gutter")>-1&&(h=!1),I(e,f,u,r)),h&&(Eo(f.lineNumber),f.lineNumber.appendChild(document.createTextNode(S(e.options,u)))),s=f.node.nextSibling}else{var d=V(e,f,u,r);l.insertBefore(d,s)}u+=f.size}for(;s;)s=n(s)}function I(e,t,r,n){for(var i=0;i<t.changes.length;i++){var o=t.changes[i];"text"==o?R(e,t):"gutter"==o?G(e,t,r,n):"class"==o?B(t):"widget"==o&&U(e,t,n)}t.changes=null}function z(e){return e.node==e.text&&(e.node=zo("div",null,null,"position: relative"),e.text.parentNode&&e.text.parentNode.replaceChild(e.node,e.text),e.node.appendChild(e.text),cl&&8>fl&&(e.node.style.zIndex=2)),e.node}function E(e){var t=e.bgClass?e.bgClass+" "+(e.line.bgClass||""):e.line.bgClass;if(t&&(t+=" CodeMirror-linebackground"),e.background)t?e.background.className=t:(e.background.parentNode.removeChild(e.background),e.background=null);else if(t){var r=z(e);e.background=r.insertBefore(zo("div",null,t),r.firstChild)}}function F(e,t){var r=e.display.externalMeasured;return r&&r.line==t.line?(e.display.externalMeasured=null,t.measure=r.measure,r.built):Oi(e,t)}function R(e,t){var r=t.text.className,n=F(e,t);t.text==t.node&&(t.node=n.pre),t.text.parentNode.replaceChild(n.pre,t.text),t.text=n.pre,n.bgClass!=t.bgClass||n.textClass!=t.textClass?(t.bgClass=n.bgClass,t.textClass=n.textClass,B(t)):r&&(t.text.className=r)}function B(e){E(e),e.line.wrapClass?z(e).className=e.line.wrapClass:e.node!=e.text&&(e.node.className="");var t=e.textClass?e.textClass+" "+(e.line.textClass||""):e.line.textClass;e.text.className=t||""}function G(e,t,r,n){t.gutter&&(t.node.removeChild(t.gutter),t.gutter=null);var i=t.line.gutterMarkers;if(e.options.lineNumbers||i){var o=z(t),l=t.gutter=zo("div",null,"CodeMirror-gutter-wrapper","left: "+(e.options.fixedGutter?n.fixedPos:-n.gutterTotalWidth)+"px; width: "+n.gutterTotalWidth+"px");if(e.display.input.setUneditable(l),o.insertBefore(l,t.text),t.line.gutterClass&&(l.className+=" "+t.line.gutterClass),!e.options.lineNumbers||i&&i["CodeMirror-linenumbers"]||(t.lineNumber=l.appendChild(zo("div",S(e.options,r),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+n.gutterLeft["CodeMirror-linenumbers"]+"px; width: "+e.display.lineNumInnerWidth+"px"))),i)for(var s=0;s<e.options.gutters.length;++s){var a=e.options.gutters[s],u=i.hasOwnProperty(a)&&i[a];u&&l.appendChild(zo("div",[u],"CodeMirror-gutter-elt","left: "+n.gutterLeft[a]+"px; width: "+n.gutterWidth[a]+"px"))}}}function U(e,t,r){t.alignable&&(t.alignable=null);for(var n,i=t.node.firstChild;i;i=n){var n=i.nextSibling;"CodeMirror-linewidget"==i.className&&t.node.removeChild(i)}K(e,t,r)}function V(e,t,r,n){var i=F(e,t);return t.text=t.node=i.pre,i.bgClass&&(t.bgClass=i.bgClass),i.textClass&&(t.textClass=i.textClass),B(t),G(e,t,r,n),K(e,t,n),t.node}function K(e,t,r){if(j(e,t.line,t,r,!0),t.rest)for(var n=0;n<t.rest.length;n++)j(e,t.rest[n],t,r,!1)}function j(e,t,r,n,i){if(t.widgets)for(var o=z(r),l=0,s=t.widgets;l<s.length;++l){var a=s[l],u=zo("div",[a.node],"CodeMirror-linewidget");a.handleMouseEvents||u.setAttribute("cm-ignore-events","true"),X(a,u,r,n),e.display.input.setUneditable(u),i&&a.above?o.insertBefore(u,r.gutter||r.text):o.appendChild(u),mo(a,"redraw")}}function X(e,t,r,n){if(e.noHScroll){(r.alignable||(r.alignable=[])).push(t);var i=n.wrapperWidth;t.style.left=n.fixedPos+"px",e.coverGutter||(i-=n.gutterTotalWidth,t.style.paddingLeft=n.gutterTotalWidth+"px"),t.style.width=i+"px"}e.coverGutter&&(t.style.zIndex=5,t.style.position="relative",e.noHScroll||(t.style.marginLeft=-n.gutterTotalWidth+"px"))}function _(e){return Al(e.line,e.ch)}function Y(e,t){return Nl(e,t)<0?t:e}function $(e,t){return Nl(e,t)<0?e:t}function q(e){e.state.focused||(e.display.input.focus(),cn(e))}function Z(e){return e.options.readOnly||e.doc.cantEdit}function Q(e,t,r,n){var i=e.doc;e.display.shift=!1,n||(n=i.sel);var o=Vs(t),l=null;e.state.pasteIncoming&&n.ranges.length>1&&(Wl&&Wl.join("\n")==t?l=n.ranges.length%Wl.length==0&&Ao(Wl,Vs):o.length==n.ranges.length&&(l=Ao(o,function(e){return[e]})));for(var s=n.ranges.length-1;s>=0;s--){var a=n.ranges[s],u=a.from(),c=a.to();a.empty()&&(r&&r>0?u=Al(u.line,u.ch-r):e.state.overwrite&&!e.state.pasteIncoming&&(c=Al(c.line,Math.min(Ki(i,c.line).text.length,c.ch+To(o).length))));var f=e.curOp.updateInput,h={from:u,to:c,text:l?l[s%l.length]:o,origin:e.state.pasteIncoming?"paste":e.state.cutIncoming?"cut":"+input"};if(bn(e.doc,h),mo(e,"inputRead",e,h),t&&!e.state.pasteIncoming&&e.options.electricChars&&e.options.smartIndent&&a.head.ch<100&&(!s||n.ranges[s-1].head.line!=a.head.line)){var d=e.getModeAt(a.head),p=Vl(h);if(d.electricChars){for(var g=0;g<d.electricChars.length;g++)if(t.indexOf(d.electricChars.charAt(g))>-1){Hn(e,p.line,"smart");break}}else d.electricInput&&d.electricInput.test(Ki(i,p.line).text.slice(0,p.ch))&&Hn(e,p.line,"smart")}}On(e),e.curOp.updateInput=f,e.curOp.typing=!0,e.state.pasteIncoming=e.state.cutIncoming=!1}function J(e){for(var t=[],r=[],n=0;n<e.doc.sel.ranges.length;n++){var i=e.doc.sel.ranges[n].head.line,o={anchor:Al(i,0),head:Al(i+1,0)};r.push(o),t.push(e.getRange(o.anchor,o.head))}return{text:t,ranges:r}}function et(e){e.setAttribute("autocorrect","off"),e.setAttribute("autocapitalize","off"),e.setAttribute("spellcheck","false")}function tt(e){this.cm=e,this.prevInput="",this.pollingFast=!1,this.polling=new So,this.inaccurateSelection=!1,this.hasSelection=!1}function rt(){var e=zo("textarea",null,null,"position: absolute; padding: 0; width: 1px; height: 1em; outline: none"),t=zo("div",[e],null,"overflow: hidden; position: relative; width: 3px; height: 0px;");return hl?e.style.width="1000px":e.setAttribute("wrap","off"),bl&&(e.style.border="1px solid black"),et(e),t}function nt(e){this.cm=e,this.lastAnchorNode=this.lastAnchorOffset=this.lastFocusNode=this.lastFocusOffset=null,this.polling=new So,this.gracePeriod=!1}function it(e,t){var r=qt(e,t.line);if(!r||r.hidden)return null;var n=Ki(e.doc,t.line),i=_t(r,n,t.line),o=Zi(n),l="left";if(o){var s=nl(o,t.ch);l=s%2?"right":"left"}var a=Jt(i.map,t.ch,"left");return a.offset="right"==a.collapse?a.end:a.start,a}function ot(e,t){return t&&(e.bad=!0),e}function lt(e,t,r){var n;if(t==e.display.lineDiv){if(n=e.display.lineDiv.childNodes[r],!n)return ot(e.clipPos(Al(e.display.viewTo-1)),!0);t=null,r=0}else for(n=t;;n=n.parentNode){if(!n||n==e.display.lineDiv)return null;if(n.parentNode&&n.parentNode==e.display.lineDiv)break}for(var i=0;i<e.display.view.length;i++){var o=e.display.view[i];if(o.node==n)return st(o,t,r)}}function st(e,t,r){function n(t,r,n){for(var i=-1;i<(c?c.length:0);i++)for(var o=0>i?u.map:c[i],l=0;l<o.length;l+=3){var s=o[l+2];if(s==t||s==r){var a=Yi(0>i?e.line:e.rest[i]),f=o[l]+n;return(0>n||s!=t)&&(f=o[l+(n?1:0)]),Al(a,f)}}}var i=e.text.firstChild,o=!1;if(!t||!zs(i,t))return ot(Al(Yi(e.line),0),!0);if(t==i&&(o=!0,t=i.childNodes[r],r=0,!t)){var l=e.rest?To(e.rest):e.line;return ot(Al(Yi(l),l.text.length),o)}var s=3==t.nodeType?t:null,a=t;for(s||1!=t.childNodes.length||3!=t.firstChild.nodeType||(s=t.firstChild,r&&(r=s.nodeValue.length));a.parentNode!=i;)a=a.parentNode;var u=e.measure,c=u.maps,f=n(s,a,r);if(f)return ot(f,o);for(var h=a.nextSibling,d=s?s.nodeValue.length-r:0;h;h=h.nextSibling){if(f=n(h,h.firstChild,0))return ot(Al(f.line,f.ch-d),o);d+=h.textContent.length}for(var p=a.previousSibling,d=r;p;p=p.previousSibling){if(f=n(p,p.firstChild,-1))return ot(Al(f.line,f.ch+d),o);d+=h.textContent.length}}function at(e,t,r,n,i){function o(e){return function(t){return t.id==e}}function l(t){if(1==t.nodeType){var r=t.getAttribute("cm-text");if(null!=r)return""==r&&(r=t.textContent.replace(/\u200b/g,"")),void(s+=r);var u,c=t.getAttribute("cm-marker");if(c){var f=e.findMarks(Al(n,0),Al(i+1,0),o(+c));return void(f.length&&(u=f[0].find())&&(s+=ji(e.doc,u.from,u.to).join("\n")))}if("false"==t.getAttribute("contenteditable"))return;for(var h=0;h<t.childNodes.length;h++)l(t.childNodes[h]);/^(pre|div|p)$/i.test(t.nodeName)&&(a=!0)}else if(3==t.nodeType){var d=t.nodeValue;if(!d)return;a&&(s+="\n",a=!1),s+=d}}for(var s="",a=!1;l(t),t!=r;)t=t.nextSibling;return s}function ut(e,t){this.ranges=e,this.primIndex=t}function ct(e,t){this.anchor=e,this.head=t}function ft(e,t){var r=e[t];e.sort(function(e,t){return Nl(e.from(),t.from())}),t=Mo(e,r);for(var n=1;n<e.length;n++){var i=e[n],o=e[n-1];if(Nl(o.to(),i.from())>=0){var l=$(o.from(),i.from()),s=Y(o.to(),i.to()),a=o.empty()?i.from()==i.head:o.from()==o.head;t>=n&&--t,e.splice(--n,2,new ct(a?s:l,a?l:s))}}return new ut(e,t)}function ht(e,t){return new ut([new ct(e,t||e)],0)}function dt(e,t){return Math.max(e.first,Math.min(t,e.first+e.size-1))}function pt(e,t){if(t.line<e.first)return Al(e.first,0);var r=e.first+e.size-1;return t.line>r?Al(r,Ki(e,r).text.length):gt(t,Ki(e,t.line).text.length)}function gt(e,t){var r=e.ch;return null==r||r>t?Al(e.line,t):0>r?Al(e.line,0):e}function vt(e,t){return t>=e.first&&t<e.first+e.size}function mt(e,t){for(var r=[],n=0;n<t.length;n++)r[n]=pt(e,t[n]);return r}function yt(e,t,r,n){if(e.cm&&e.cm.display.shift||e.extend){var i=t.anchor;if(n){var o=Nl(r,i)<0;o!=Nl(n,i)<0?(i=r,r=n):o!=Nl(r,n)<0&&(r=n)}return new ct(i,r)}return new ct(n||r,r)}function bt(e,t,r,n){kt(e,new ut([yt(e,e.sel.primary(),t,r)],0),n)}function wt(e,t,r){for(var n=[],i=0;i<e.sel.ranges.length;i++)n[i]=yt(e,e.sel.ranges[i],t[i],null);var o=ft(n,e.sel.primIndex);kt(e,o,r)}function xt(e,t,r,n){var i=e.sel.ranges.slice(0);i[t]=r,kt(e,ft(i,e.sel.primIndex),n)}function Ct(e,t,r,n){kt(e,ht(t,r),n)}function St(e,t){var r={ranges:t.ranges,update:function(t){this.ranges=[];for(var r=0;r<t.length;r++)this.ranges[r]=new ct(pt(e,t[r].anchor),pt(e,t[r].head))}};return Cs(e,"beforeSelectionChange",e,r),e.cm&&Cs(e.cm,"beforeSelectionChange",e.cm,r),r.ranges!=t.ranges?ft(r.ranges,r.ranges.length-1):t}function Lt(e,t,r){var n=e.history.done,i=To(n);i&&i.ranges?(n[n.length-1]=t,Tt(e,t,r)):kt(e,t,r)}function kt(e,t,r){Tt(e,t,r),io(e,e.sel,e.cm?e.cm.curOp.id:0/0,r)}function Tt(e,t,r){(xo(e,"beforeSelectionChange")||e.cm&&xo(e.cm,"beforeSelectionChange"))&&(t=St(e,t));var n=r&&r.bias||(Nl(t.primary().head,e.sel.primary().head)<0?-1:1);Mt(e,Nt(e,t,n,!0)),r&&r.scroll===!1||!e.cm||On(e.cm)}function Mt(e,t){t.equals(e.sel)||(e.sel=t,e.cm&&(e.cm.curOp.updateInput=e.cm.curOp.selectionChanged=!0,wo(e.cm)),mo(e,"cursorActivity",e))}function At(e){Mt(e,Nt(e,e.sel,null,!1),Ts)}function Nt(e,t,r,n){for(var i,o=0;o<t.ranges.length;o++){var l=t.ranges[o],s=Wt(e,l.anchor,r,n),a=Wt(e,l.head,r,n);(i||s!=l.anchor||a!=l.head)&&(i||(i=t.ranges.slice(0,o)),i[o]=new ct(s,a))}return i?ft(i,t.primIndex):t}function Wt(e,t,r,n){var i=!1,o=t,l=r||1;e.cantEdit=!1;e:for(;;){var s=Ki(e,o.line);if(s.markedSpans)for(var a=0;a<s.markedSpans.length;++a){var u=s.markedSpans[a],c=u.marker;if((null==u.from||(c.inclusiveLeft?u.from<=o.ch:u.from<o.ch))&&(null==u.to||(c.inclusiveRight?u.to>=o.ch:u.to>o.ch))){if(n&&(Cs(c,"beforeCursorEnter"),c.explicitlyCleared)){if(s.markedSpans){--a;continue}break}if(!c.atomic)continue;var f=c.find(0>l?-1:1);if(0==Nl(f,o)&&(f.ch+=l,f.ch<0?f=f.line>e.first?pt(e,Al(f.line-1)):null:f.ch>s.text.length&&(f=f.line<e.first+e.size-1?Al(f.line+1,0):null),!f)){if(i)return n?(e.cantEdit=!0,Al(e.first,0)):Wt(e,t,r,!0);i=!0,f=t,l=-l}o=f;continue e}}return o}}function Ot(e){e.display.input.showSelection(e.display.input.prepareSelection())}function Dt(e,t){for(var r=e.doc,n={},i=n.cursors=document.createDocumentFragment(),o=n.selection=document.createDocumentFragment(),l=0;l<r.sel.ranges.length;l++)if(t!==!1||l!=r.sel.primIndex){var s=r.sel.ranges[l],a=s.empty();(a||e.options.showCursorWhenSelecting)&&Ht(e,s,i),a||Pt(e,s,o)}return n}function Ht(e,t,r){var n=cr(e,t.head,"div",null,null,!e.options.singleCursorHeightPerLine),i=r.appendChild(zo("div"," ","CodeMirror-cursor"));if(i.style.left=n.left+"px",i.style.top=n.top+"px",i.style.height=Math.max(0,n.bottom-n.top)*e.options.cursorHeight+"px",n.other){var o=r.appendChild(zo("div"," ","CodeMirror-cursor CodeMirror-secondarycursor"));o.style.display="",o.style.left=n.other.left+"px",o.style.top=n.other.top+"px",o.style.height=.85*(n.other.bottom-n.other.top)+"px"}}function Pt(e,t,r){function n(e,t,r,n){0>t&&(t=0),t=Math.round(t),n=Math.round(n),s.appendChild(zo("div",null,"CodeMirror-selected","position: absolute; left: "+e+"px; top: "+t+"px; width: "+(null==r?c-e:r)+"px; height: "+(n-t)+"px"))}function i(t,r,i){function o(r,n){return ur(e,Al(t,r),"div",f,n)}var s,a,f=Ki(l,t),h=f.text.length;return Yo(Zi(f),r||0,null==i?h:i,function(e,t,l){var f,d,p,g=o(e,"left");if(e==t)f=g,d=p=g.left;else{if(f=o(t-1,"right"),"rtl"==l){var v=g;g=f,f=v}d=g.left,p=f.right}null==r&&0==e&&(d=u),f.top-g.top>3&&(n(d,g.top,null,g.bottom),d=u,g.bottom<f.top&&n(d,g.bottom,null,f.top)),null==i&&t==h&&(p=c),(!s||g.top<s.top||g.top==s.top&&g.left<s.left)&&(s=g),(!a||f.bottom>a.bottom||f.bottom==a.bottom&&f.right>a.right)&&(a=f),u+1>d&&(d=u),n(d,f.top,p-d,f.bottom)}),{start:s,end:a}}var o=e.display,l=e.doc,s=document.createDocumentFragment(),a=Ut(e.display),u=a.left,c=Math.max(o.sizerWidth,Kt(e)-o.sizer.offsetLeft)-a.right,f=t.from(),h=t.to();if(f.line==h.line)i(f.line,f.ch,h.ch);else{var d=Ki(l,f.line),p=Ki(l,h.line),g=fi(d)==fi(p),v=i(f.line,f.ch,g?d.text.length+1:null).end,m=i(h.line,g?0:null,h.ch).start;g&&(v.top<m.top-2?(n(v.right,v.top,null,v.bottom),n(u,m.top,m.left,m.bottom)):n(v.right,v.top,m.left-v.right,v.bottom)),v.bottom<m.top&&n(u,v.bottom,null,m.top)}r.appendChild(s)}function It(e){if(e.state.focused){var t=e.display;clearInterval(t.blinker);var r=!0;t.cursorDiv.style.visibility="",e.options.cursorBlinkRate>0?t.blinker=setInterval(function(){t.cursorDiv.style.visibility=(r=!r)?"":"hidden"},e.options.cursorBlinkRate):e.options.cursorBlinkRate<0&&(t.cursorDiv.style.visibility="hidden")}}function zt(e,t){e.doc.mode.startState&&e.doc.frontier<e.display.viewTo&&e.state.highlight.set(t,Do(Et,e))}function Et(e){var t=e.doc;if(t.frontier<t.first&&(t.frontier=t.first),!(t.frontier>=e.display.viewTo)){var r=+new Date+e.options.workTime,n=Ql(t.mode,Rt(e,t.frontier)),i=[];t.iter(t.frontier,Math.min(t.first+t.size,e.display.viewTo+500),function(o){if(t.frontier>=e.display.viewFrom){var l=o.styles,s=Mi(e,o,n,!0);o.styles=s.styles;var a=o.styleClasses,u=s.classes;u?o.styleClasses=u:a&&(o.styleClasses=null);for(var c=!l||l.length!=o.styles.length||a!=u&&(!a||!u||a.bgClass!=u.bgClass||a.textClass!=u.textClass),f=0;!c&&f<l.length;++f)c=l[f]!=o.styles[f];c&&i.push(t.frontier),o.stateAfter=Ql(t.mode,n)}else Ni(e,o.text,n),o.stateAfter=t.frontier%5==0?Ql(t.mode,n):null;return++t.frontier,+new Date>r?(zt(e,e.options.workDelay),!0):void 0}),i.length&&Tr(e,function(){for(var t=0;t<i.length;t++)Hr(e,i[t],"text")})}}function Ft(e,t,r){for(var n,i,o=e.doc,l=r?-1:t-(e.doc.mode.innerMode?1e3:100),s=t;s>l;--s){if(s<=o.first)return o.first;var a=Ki(o,s-1);if(a.stateAfter&&(!r||s<=o.frontier))return s;var u=Ns(a.text,null,e.options.tabSize);(null==i||n>u)&&(i=s-1,n=u)}return i}function Rt(e,t,r){var n=e.doc,i=e.display;if(!n.mode.startState)return!0;var o=Ft(e,t,r),l=o>n.first&&Ki(n,o-1).stateAfter;return l=l?Ql(n.mode,l):Jl(n.mode),n.iter(o,t,function(r){Ni(e,r.text,l);var s=o==t-1||o%5==0||o>=i.viewFrom&&o<i.viewTo;r.stateAfter=s?Ql(n.mode,l):null,++o}),r&&(n.frontier=o),l}function Bt(e){return e.lineSpace.offsetTop}function Gt(e){return e.mover.offsetHeight-e.lineSpace.offsetHeight}function Ut(e){if(e.cachedPaddingH)return e.cachedPaddingH;var t=Fo(e.measure,zo("pre","x")),r=window.getComputedStyle?window.getComputedStyle(t):t.currentStyle,n={left:parseInt(r.paddingLeft),right:parseInt(r.paddingRight)};return isNaN(n.left)||isNaN(n.right)||(e.cachedPaddingH=n),n}function Vt(e){return Ls-e.display.nativeBarWidth}function Kt(e){return e.display.scroller.clientWidth-Vt(e)-e.display.barWidth}function jt(e){return e.display.scroller.clientHeight-Vt(e)-e.display.barHeight}function Xt(e,t,r){var n=e.options.lineWrapping,i=n&&Kt(e);if(!t.measure.heights||n&&t.measure.width!=i){var o=t.measure.heights=[];if(n){t.measure.width=i;for(var l=t.text.firstChild.getClientRects(),s=0;s<l.length-1;s++){var a=l[s],u=l[s+1];Math.abs(a.bottom-u.bottom)>2&&o.push((a.bottom+u.top)/2-r.top)}}o.push(r.bottom-r.top)}}function _t(e,t,r){if(e.line==t)return{map:e.measure.map,cache:e.measure.cache};for(var n=0;n<e.rest.length;n++)if(e.rest[n]==t)return{map:e.measure.maps[n],cache:e.measure.caches[n]};for(var n=0;n<e.rest.length;n++)if(Yi(e.rest[n])>r)return{map:e.measure.maps[n],cache:e.measure.caches[n],before:!0}}function Yt(e,t){t=fi(t);var r=Yi(t),n=e.display.externalMeasured=new Wr(e.doc,t,r);n.lineN=r;var i=n.built=Oi(e,n);return n.text=i.pre,Fo(e.display.lineMeasure,i.pre),n}function $t(e,t,r,n){return Qt(e,Zt(e,t),r,n)}function qt(e,t){if(t>=e.display.viewFrom&&t<e.display.viewTo)return e.display.view[Ir(e,t)];var r=e.display.externalMeasured;return r&&t>=r.lineN&&t<r.lineN+r.size?r:void 0}function Zt(e,t){var r=Yi(t),n=qt(e,r);n&&!n.text?n=null:n&&n.changes&&I(e,n,r,H(e)),n||(n=Yt(e,t));var i=_t(n,t,r);return{line:t,view:n,rect:null,map:i.map,cache:i.cache,before:i.before,hasHeights:!1}}function Qt(e,t,r,n,i){t.before&&(r=-1);var o,l=r+(n||"");return t.cache.hasOwnProperty(l)?o=t.cache[l]:(t.rect||(t.rect=t.view.text.getBoundingClientRect()),t.hasHeights||(Xt(e,t.view,t.rect),t.hasHeights=!0),o=er(e,t,r,n),o.bogus||(t.cache[l]=o)),{left:o.left,right:o.right,top:i?o.rtop:o.top,bottom:i?o.rbottom:o.bottom}}function Jt(e,t,r){for(var n,i,o,l,s=0;s<e.length;s+=3){var a=e[s],u=e[s+1];if(a>t?(i=0,o=1,l="left"):u>t?(i=t-a,o=i+1):(s==e.length-3||t==u&&e[s+3]>t)&&(o=u-a,i=o-1,t>=u&&(l="right")),null!=i){if(n=e[s+2],a==u&&r==(n.insertLeft?"left":"right")&&(l=r),"left"==r&&0==i)for(;s&&e[s-2]==e[s-3]&&e[s-1].insertLeft;)n=e[(s-=3)+2],l="left";if("right"==r&&i==u-a)for(;s<e.length-3&&e[s+3]==e[s+4]&&!e[s+5].insertLeft;)n=e[(s+=3)+2],l="right";break}}return{node:n,start:i,end:o,collapse:l,coverStart:a,coverEnd:u}}function er(e,t,r,n){var i,o=Jt(t.map,r,n),l=o.node,s=o.start,a=o.end,u=o.collapse;if(3==l.nodeType){for(var c=0;4>c;c++){for(;s&&Io(t.line.text.charAt(o.coverStart+s));)--s;for(;o.coverStart+a<o.coverEnd&&Io(t.line.text.charAt(o.coverStart+a));)++a;if(cl&&9>fl&&0==s&&a==o.coverEnd-o.coverStart)i=l.parentNode.getBoundingClientRect();else if(cl&&e.options.lineWrapping){var f=Ds(l,s,a).getClientRects();i=f.length?f["right"==n?f.length-1:0]:Pl}else i=Ds(l,s,a).getBoundingClientRect()||Pl;if(i.left||i.right||0==s)break;a=s,s-=1,u="right"}cl&&11>fl&&(i=tr(e.display.measure,i))}else{s>0&&(u=n="right");var f;i=e.options.lineWrapping&&(f=l.getClientRects()).length>1?f["right"==n?f.length-1:0]:l.getBoundingClientRect()}if(cl&&9>fl&&!s&&(!i||!i.left&&!i.right)){var h=l.parentNode.getClientRects()[0];i=h?{left:h.left,right:h.left+vr(e.display),top:h.top,bottom:h.bottom}:Pl}for(var d=i.top-t.rect.top,p=i.bottom-t.rect.top,g=(d+p)/2,v=t.view.measure.heights,c=0;c<v.length-1&&!(g<v[c]);c++);var m=c?v[c-1]:0,y=v[c],b={left:("right"==u?i.right:i.left)-t.rect.left,right:("left"==u?i.left:i.right)-t.rect.left,top:m,bottom:y};return i.left||i.right||(b.bogus=!0),e.options.singleCursorHeightPerLine||(b.rtop=d,b.rbottom=p),b
2
- }function tr(e,t){if(!window.screen||null==screen.logicalXDPI||screen.logicalXDPI==screen.deviceXDPI||!_o(e))return t;var r=screen.logicalXDPI/screen.deviceXDPI,n=screen.logicalYDPI/screen.deviceYDPI;return{left:t.left*r,right:t.right*r,top:t.top*n,bottom:t.bottom*n}}function rr(e){if(e.measure&&(e.measure.cache={},e.measure.heights=null,e.rest))for(var t=0;t<e.rest.length;t++)e.measure.caches[t]={}}function nr(e){e.display.externalMeasure=null,Eo(e.display.lineMeasure);for(var t=0;t<e.display.view.length;t++)rr(e.display.view[t])}function ir(e){nr(e),e.display.cachedCharWidth=e.display.cachedTextHeight=e.display.cachedPaddingH=null,e.options.lineWrapping||(e.display.maxLineChanged=!0),e.display.lineNumChars=null}function or(){return window.pageXOffset||(document.documentElement||document.body).scrollLeft}function lr(){return window.pageYOffset||(document.documentElement||document.body).scrollTop}function sr(e,t,r,n){if(t.widgets)for(var i=0;i<t.widgets.length;++i)if(t.widgets[i].above){var o=yi(t.widgets[i]);r.top+=o,r.bottom+=o}if("line"==n)return r;n||(n="local");var l=qi(t);if("local"==n?l+=Bt(e.display):l-=e.display.viewOffset,"page"==n||"window"==n){var s=e.display.lineSpace.getBoundingClientRect();l+=s.top+("window"==n?0:lr());var a=s.left+("window"==n?0:or());r.left+=a,r.right+=a}return r.top+=l,r.bottom+=l,r}function ar(e,t,r){if("div"==r)return t;var n=t.left,i=t.top;if("page"==r)n-=or(),i-=lr();else if("local"==r||!r){var o=e.display.sizer.getBoundingClientRect();n+=o.left,i+=o.top}var l=e.display.lineSpace.getBoundingClientRect();return{left:n-l.left,top:i-l.top}}function ur(e,t,r,n,i){return n||(n=Ki(e.doc,t.line)),sr(e,n,$t(e,n,t.ch,i),r)}function cr(e,t,r,n,i,o){function l(t,l){var s=Qt(e,i,t,l?"right":"left",o);return l?s.left=s.right:s.right=s.left,sr(e,n,s,r)}function s(e,t){var r=a[t],n=r.level%2;return e==$o(r)&&t&&r.level<a[t-1].level?(r=a[--t],e=qo(r)-(r.level%2?0:1),n=!0):e==qo(r)&&t<a.length-1&&r.level<a[t+1].level&&(r=a[++t],e=$o(r)-r.level%2,n=!1),n&&e==r.to&&e>r.from?l(e-1):l(e,n)}n=n||Ki(e.doc,t.line),i||(i=Zt(e,n));var a=Zi(n),u=t.ch;if(!a)return l(u);var c=nl(a,u),f=s(u,c);return null!=Ys&&(f.other=s(u,Ys)),f}function fr(e,t){var r=0,t=pt(e.doc,t);e.options.lineWrapping||(r=vr(e.display)*t.ch);var n=Ki(e.doc,t.line),i=qi(n)+Bt(e.display);return{left:r,right:r,top:i,bottom:i+n.height}}function hr(e,t,r,n){var i=Al(e,t);return i.xRel=n,r&&(i.outside=!0),i}function dr(e,t,r){var n=e.doc;if(r+=e.display.viewOffset,0>r)return hr(n.first,0,!0,-1);var i=$i(n,r),o=n.first+n.size-1;if(i>o)return hr(n.first+n.size-1,Ki(n,o).text.length,!0,1);0>t&&(t=0);for(var l=Ki(n,i);;){var s=pr(e,l,i,t,r),a=ui(l),u=a&&a.find(0,!0);if(!a||!(s.ch>u.from.ch||s.ch==u.from.ch&&s.xRel>0))return s;i=Yi(l=u.to.line)}}function pr(e,t,r,n,i){function o(n){var i=cr(e,Al(r,n),"line",t,u);return s=!0,l>i.bottom?i.left-a:l<i.top?i.left+a:(s=!1,i.left)}var l=i-qi(t),s=!1,a=2*e.display.wrapper.clientWidth,u=Zt(e,t),c=Zi(t),f=t.text.length,h=Zo(t),d=Qo(t),p=o(h),g=s,v=o(d),m=s;if(n>v)return hr(r,d,m,1);for(;;){if(c?d==h||d==ol(t,h,1):1>=d-h){for(var y=p>n||v-n>=n-p?h:d,b=n-(y==h?p:v);Io(t.text.charAt(y));)++y;var w=hr(r,y,y==h?g:m,-1>b?-1:b>1?1:0);return w}var x=Math.ceil(f/2),C=h+x;if(c){C=h;for(var S=0;x>S;++S)C=ol(t,C,1)}var L=o(C);L>n?(d=C,v=L,(m=s)&&(v+=1e3),f=x):(h=C,p=L,g=s,f-=x)}}function gr(e){if(null!=e.cachedTextHeight)return e.cachedTextHeight;if(null==Ol){Ol=zo("pre");for(var t=0;49>t;++t)Ol.appendChild(document.createTextNode("x")),Ol.appendChild(zo("br"));Ol.appendChild(document.createTextNode("x"))}Fo(e.measure,Ol);var r=Ol.offsetHeight/50;return r>3&&(e.cachedTextHeight=r),Eo(e.measure),r||1}function vr(e){if(null!=e.cachedCharWidth)return e.cachedCharWidth;var t=zo("span","xxxxxxxxxx"),r=zo("pre",[t]);Fo(e.measure,r);var n=t.getBoundingClientRect(),i=(n.right-n.left)/10;return i>2&&(e.cachedCharWidth=i),i||10}function mr(e){e.curOp={cm:e,viewChanged:!1,startHeight:e.doc.height,forceUpdate:!1,updateInput:null,typing:!1,changeObjs:null,cursorActivityHandlers:null,cursorActivityCalled:0,selectionChanged:!1,updateMaxLine:!1,scrollLeft:null,scrollTop:null,scrollToPos:null,id:++zl},Il?Il.ops.push(e.curOp):e.curOp.ownsGroup=Il={ops:[e.curOp],delayedCallbacks:[]}}function yr(e){var t=e.delayedCallbacks,r=0;do{for(;r<t.length;r++)t[r]();for(var n=0;n<e.ops.length;n++){var i=e.ops[n];if(i.cursorActivityHandlers)for(;i.cursorActivityCalled<i.cursorActivityHandlers.length;)i.cursorActivityHandlers[i.cursorActivityCalled++](i.cm)}}while(r<t.length)}function br(e){var t=e.curOp,r=t.ownsGroup;if(r)try{yr(r)}finally{Il=null;for(var n=0;n<r.ops.length;n++)r.ops[n].cm.curOp=null;wr(r)}}function wr(e){for(var t=e.ops,r=0;r<t.length;r++)xr(t[r]);for(var r=0;r<t.length;r++)Cr(t[r]);for(var r=0;r<t.length;r++)Sr(t[r]);for(var r=0;r<t.length;r++)Lr(t[r]);for(var r=0;r<t.length;r++)kr(t[r])}function xr(e){var t=e.cm,r=t.display;T(t),e.updateMaxLine&&h(t),e.mustUpdate=e.viewChanged||e.forceUpdate||null!=e.scrollTop||e.scrollToPos&&(e.scrollToPos.from.line<r.viewFrom||e.scrollToPos.to.line>=r.viewTo)||r.maxLineChanged&&t.options.lineWrapping,e.update=e.mustUpdate&&new k(t,e.mustUpdate&&{top:e.scrollTop,ensure:e.scrollToPos},e.forceUpdate)}function Cr(e){e.updatedDisplay=e.mustUpdate&&M(e.cm,e.update)}function Sr(e){var t=e.cm,r=t.display;e.updatedDisplay&&O(t),e.barMeasure=p(t),r.maxLineChanged&&!t.options.lineWrapping&&(e.adjustWidthTo=$t(t,r.maxLine,r.maxLine.text.length).left+3,t.display.sizerWidth=e.adjustWidthTo,e.barMeasure.scrollWidth=Math.max(r.scroller.clientWidth,r.sizer.offsetLeft+e.adjustWidthTo+Vt(t)+t.display.barWidth),e.maxScrollLeft=Math.max(0,r.sizer.offsetLeft+e.adjustWidthTo-Kt(t))),(e.updatedDisplay||e.selectionChanged)&&(e.preparedSelection=r.input.prepareSelection())}function Lr(e){var t=e.cm;null!=e.adjustWidthTo&&(t.display.sizer.style.minWidth=e.adjustWidthTo+"px",e.maxScrollLeft<t.doc.scrollLeft&&Qr(t,Math.min(t.display.scroller.scrollLeft,e.maxScrollLeft),!0),t.display.maxLineChanged=!1),e.preparedSelection&&t.display.input.showSelection(e.preparedSelection),e.updatedDisplay&&W(t,e.barMeasure),(e.updatedDisplay||e.startHeight!=t.doc.height)&&y(t,e.barMeasure),e.selectionChanged&&It(t),t.state.focused&&e.updateInput&&t.display.input.reset(e.typing)}function kr(e){var t=e.cm,r=t.display,n=t.doc;if(e.updatedDisplay&&A(t,e.update),null==r.wheelStartX||null==e.scrollTop&&null==e.scrollLeft&&!e.scrollToPos||(r.wheelStartX=r.wheelStartY=null),null==e.scrollTop||r.scroller.scrollTop==e.scrollTop&&!e.forceScroll||(n.scrollTop=Math.max(0,Math.min(r.scroller.scrollHeight-r.scroller.clientHeight,e.scrollTop)),r.scrollbars.setScrollTop(n.scrollTop),r.scroller.scrollTop=n.scrollTop),null==e.scrollLeft||r.scroller.scrollLeft==e.scrollLeft&&!e.forceScroll||(n.scrollLeft=Math.max(0,Math.min(r.scroller.scrollWidth-Kt(t),e.scrollLeft)),r.scrollbars.setScrollLeft(n.scrollLeft),r.scroller.scrollLeft=n.scrollLeft,x(t)),e.scrollToPos){var i=Mn(t,pt(n,e.scrollToPos.from),pt(n,e.scrollToPos.to),e.scrollToPos.margin);e.scrollToPos.isCursor&&t.state.focused&&Tn(t,i)}var o=e.maybeHiddenMarkers,l=e.maybeUnhiddenMarkers;if(o)for(var s=0;s<o.length;++s)o[s].lines.length||Cs(o[s],"hide");if(l)for(var s=0;s<l.length;++s)l[s].lines.length&&Cs(l[s],"unhide");r.wrapper.offsetHeight&&(n.scrollTop=t.display.scroller.scrollTop),e.changeObjs&&Cs(t,"changes",t,e.changeObjs),e.update&&e.update.finish()}function Tr(e,t){if(e.curOp)return t();mr(e);try{return t()}finally{br(e)}}function Mr(e,t){return function(){if(e.curOp)return t.apply(e,arguments);mr(e);try{return t.apply(e,arguments)}finally{br(e)}}}function Ar(e){return function(){if(this.curOp)return e.apply(this,arguments);mr(this);try{return e.apply(this,arguments)}finally{br(this)}}}function Nr(e){return function(){var t=this.cm;if(!t||t.curOp)return e.apply(this,arguments);mr(t);try{return e.apply(this,arguments)}finally{br(t)}}}function Wr(e,t,r){this.line=t,this.rest=hi(t),this.size=this.rest?Yi(To(this.rest))-r+1:1,this.node=this.text=null,this.hidden=gi(e,t)}function Or(e,t,r){for(var n,i=[],o=t;r>o;o=n){var l=new Wr(e.doc,Ki(e.doc,o),o);n=o+l.size,i.push(l)}return i}function Dr(e,t,r,n){null==t&&(t=e.doc.first),null==r&&(r=e.doc.first+e.doc.size),n||(n=0);var i=e.display;if(n&&r<i.viewTo&&(null==i.updateLineNumbers||i.updateLineNumbers>t)&&(i.updateLineNumbers=t),e.curOp.viewChanged=!0,t>=i.viewTo)Ml&&di(e.doc,t)<i.viewTo&&Pr(e);else if(r<=i.viewFrom)Ml&&pi(e.doc,r+n)>i.viewFrom?Pr(e):(i.viewFrom+=n,i.viewTo+=n);else if(t<=i.viewFrom&&r>=i.viewTo)Pr(e);else if(t<=i.viewFrom){var o=zr(e,r,r+n,1);o?(i.view=i.view.slice(o.index),i.viewFrom=o.lineN,i.viewTo+=n):Pr(e)}else if(r>=i.viewTo){var o=zr(e,t,t,-1);o?(i.view=i.view.slice(0,o.index),i.viewTo=o.lineN):Pr(e)}else{var l=zr(e,t,t,-1),s=zr(e,r,r+n,1);l&&s?(i.view=i.view.slice(0,l.index).concat(Or(e,l.lineN,s.lineN)).concat(i.view.slice(s.index)),i.viewTo+=n):Pr(e)}var a=i.externalMeasured;a&&(r<a.lineN?a.lineN+=n:t<a.lineN+a.size&&(i.externalMeasured=null))}function Hr(e,t,r){e.curOp.viewChanged=!0;var n=e.display,i=e.display.externalMeasured;if(i&&t>=i.lineN&&t<i.lineN+i.size&&(n.externalMeasured=null),!(t<n.viewFrom||t>=n.viewTo)){var o=n.view[Ir(e,t)];if(null!=o.node){var l=o.changes||(o.changes=[]);-1==Mo(l,r)&&l.push(r)}}}function Pr(e){e.display.viewFrom=e.display.viewTo=e.doc.first,e.display.view=[],e.display.viewOffset=0}function Ir(e,t){if(t>=e.display.viewTo)return null;if(t-=e.display.viewFrom,0>t)return null;for(var r=e.display.view,n=0;n<r.length;n++)if(t-=r[n].size,0>t)return n}function zr(e,t,r,n){var i,o=Ir(e,t),l=e.display.view;if(!Ml||r==e.doc.first+e.doc.size)return{index:o,lineN:r};for(var s=0,a=e.display.viewFrom;o>s;s++)a+=l[s].size;if(a!=t){if(n>0){if(o==l.length-1)return null;i=a+l[o].size-t,o++}else i=a-t;t+=i,r+=i}for(;di(e.doc,r)!=r;){if(o==(0>n?0:l.length-1))return null;r+=n*l[o-(0>n?1:0)].size,o+=n}return{index:o,lineN:r}}function Er(e,t,r){var n=e.display,i=n.view;0==i.length||t>=n.viewTo||r<=n.viewFrom?(n.view=Or(e,t,r),n.viewFrom=t):(n.viewFrom>t?n.view=Or(e,t,n.viewFrom).concat(n.view):n.viewFrom<t&&(n.view=n.view.slice(Ir(e,t))),n.viewFrom=t,n.viewTo<r?n.view=n.view.concat(Or(e,n.viewTo,r)):n.viewTo>r&&(n.view=n.view.slice(0,Ir(e,r)))),n.viewTo=r}function Fr(e){for(var t=e.display.view,r=0,n=0;n<t.length;n++){var i=t[n];i.hidden||i.node&&!i.changes||++r}return r}function Rr(e){function t(){o.activeTouch&&(l=setTimeout(function(){o.activeTouch=null},1e3),s=o.activeTouch,s.end=+new Date)}function r(e){if(1!=e.touches.length)return!1;var t=e.touches[0];return t.radiusX<=1&&t.radiusY<=1}function n(e,t){if(null==t.left)return!0;var r=t.left-e.left,n=t.top-e.top;return r*r+n*n>400}function i(t){bo(e,t)||bs(t)}var o=e.display;ws(o.scroller,"mousedown",Mr(e,Vr)),cl&&11>fl?ws(o.scroller,"dblclick",Mr(e,function(t){if(!bo(e,t)){var r=Ur(e,t);if(r&&!Yr(e,t)&&!Gr(e.display,t)){ms(t);var n=e.findWordAt(r);bt(e.doc,n.anchor,n.head)}}})):ws(o.scroller,"dblclick",function(t){bo(e,t)||ms(t)}),kl||ws(o.scroller,"contextmenu",function(t){hn(e,t)});var l,s={end:0};ws(o.scroller,"touchstart",function(e){if(!r(e)){clearTimeout(l);var t=+new Date;o.activeTouch={start:t,moved:!1,prev:t-s.end<=300?s:null},1==e.touches.length&&(o.activeTouch.left=e.touches[0].pageX,o.activeTouch.top=e.touches[0].pageY)}}),ws(o.scroller,"touchmove",function(){o.activeTouch&&(o.activeTouch.moved=!0)}),ws(o.scroller,"touchend",function(r){var i=o.activeTouch;if(i&&!Gr(o,r)&&null!=i.left&&!i.moved&&new Date-i.start<300){var l,s=e.coordsChar(o.activeTouch,"page");l=!i.prev||n(i,i.prev)?new ct(s,s):!i.prev.prev||n(i,i.prev.prev)?e.findWordAt(s):new ct(Al(s.line,0),pt(e.doc,Al(s.line+1,0))),e.setSelection(l.anchor,l.head),e.focus(),ms(r)}t()}),ws(o.scroller,"touchcancel",t),ws(o.scroller,"scroll",function(){o.scroller.clientHeight&&(Zr(e,o.scroller.scrollTop),Qr(e,o.scroller.scrollLeft,!0),Cs(e,"scroll",e))}),ws(o.scroller,"mousewheel",function(t){Jr(e,t)}),ws(o.scroller,"DOMMouseScroll",function(t){Jr(e,t)}),ws(o.wrapper,"scroll",function(){o.wrapper.scrollTop=o.wrapper.scrollLeft=0}),e.options.dragDrop&&(ws(o.scroller,"dragstart",function(t){qr(e,t)}),ws(o.scroller,"dragenter",i),ws(o.scroller,"dragover",i),ws(o.scroller,"drop",Mr(e,$r)));var a=o.input.getField();ws(a,"keyup",function(t){an.call(e,t)}),ws(a,"keydown",Mr(e,ln)),ws(a,"keypress",Mr(e,un)),ws(a,"focus",Do(cn,e)),ws(a,"blur",Do(fn,e))}function Br(e){var t=e.display;(t.lastWrapHeight!=t.wrapper.clientHeight||t.lastWrapWidth!=t.wrapper.clientWidth)&&(t.cachedCharWidth=t.cachedTextHeight=t.cachedPaddingH=null,t.scrollbarsClipped=!1,e.setSize())}function Gr(e,t){for(var r=go(t);r!=e.wrapper;r=r.parentNode)if(!r||1==r.nodeType&&"true"==r.getAttribute("cm-ignore-events")||r.parentNode==e.sizer&&r!=e.mover)return!0}function Ur(e,t,r,n){var i=e.display;if(!r&&"true"==go(t).getAttribute("cm-not-content"))return null;var o,l,s=i.lineSpace.getBoundingClientRect();try{o=t.clientX-s.left,l=t.clientY-s.top}catch(t){return null}var a,u=dr(e,o,l);if(n&&1==u.xRel&&(a=Ki(e.doc,u.line).text).length==u.ch){var c=Ns(a,a.length,e.options.tabSize)-a.length;u=Al(u.line,Math.max(0,Math.round((o-Ut(e.display).left)/vr(e.display))-c))}return u}function Vr(e){var t=this,r=t.display;if(!(r.activeTouch&&r.input.supportsTouch()||bo(t,e))){if(r.shift=e.shiftKey,Gr(r,e))return void(hl||(r.scroller.draggable=!1,setTimeout(function(){r.scroller.draggable=!0},100)));if(!Yr(t,e)){var n=Ur(t,e);switch(window.focus(),vo(e)){case 1:n?Kr(t,e,n):go(e)==r.scroller&&ms(e);break;case 2:hl&&(t.state.lastMiddleDown=+new Date),n&&bt(t.doc,n),setTimeout(function(){r.input.focus()},20),ms(e);break;case 3:kl&&hn(t,e)}}}}function Kr(e,t,r){cl?setTimeout(Do(q,e),0):q(e);var n,i=+new Date;Hl&&Hl.time>i-400&&0==Nl(Hl.pos,r)?n="triple":Dl&&Dl.time>i-400&&0==Nl(Dl.pos,r)?(n="double",Hl={time:i,pos:r}):(n="single",Dl={time:i,pos:r});var o,l=e.doc.sel,s=xl?t.metaKey:t.ctrlKey;e.options.dragDrop&&Us&&!Z(e)&&"single"==n&&(o=l.contains(r))>-1&&!l.ranges[o].empty()?jr(e,t,r,s):Xr(e,t,r,n,s)}function jr(e,t,r,n){var i=e.display,o=Mr(e,function(l){hl&&(i.scroller.draggable=!1),e.state.draggingText=!1,xs(document,"mouseup",o),xs(i.scroller,"drop",o),Math.abs(t.clientX-l.clientX)+Math.abs(t.clientY-l.clientY)<10&&(ms(l),n||bt(e.doc,r),hl||cl&&9==fl?setTimeout(function(){document.body.focus(),i.input.focus()},20):i.input.focus())});hl&&(i.scroller.draggable=!0),e.state.draggingText=o,i.scroller.dragDrop&&i.scroller.dragDrop(),ws(document,"mouseup",o),ws(i.scroller,"drop",o)}function Xr(e,t,r,n,i){function o(t){if(0!=Nl(v,t))if(v=t,"rect"==n){for(var i=[],o=e.options.tabSize,l=Ns(Ki(u,r.line).text,r.ch,o),s=Ns(Ki(u,t.line).text,t.ch,o),a=Math.min(l,s),d=Math.max(l,s),p=Math.min(r.line,t.line),g=Math.min(e.lastLine(),Math.max(r.line,t.line));g>=p;p++){var m=Ki(u,p).text,y=Lo(m,a,o);a==d?i.push(new ct(Al(p,y),Al(p,y))):m.length>y&&i.push(new ct(Al(p,y),Al(p,Lo(m,d,o))))}i.length||i.push(new ct(r,r)),kt(u,ft(h.ranges.slice(0,f).concat(i),f),{origin:"*mouse",scroll:!1}),e.scrollIntoView(t)}else{var b=c,w=b.anchor,x=t;if("single"!=n){if("double"==n)var C=e.findWordAt(t);else var C=new ct(Al(t.line,0),pt(u,Al(t.line+1,0)));Nl(C.anchor,w)>0?(x=C.head,w=$(b.from(),C.anchor)):(x=C.anchor,w=Y(b.to(),C.head))}var i=h.ranges.slice(0);i[f]=new ct(pt(u,w),x),kt(u,ft(i,f),Ms)}}function l(t){var r=++y,i=Ur(e,t,!0,"rect"==n);if(i)if(0!=Nl(i,v)){q(e),o(i);var s=w(a,u);(i.line>=s.to||i.line<s.from)&&setTimeout(Mr(e,function(){y==r&&l(t)}),150)}else{var c=t.clientY<m.top?-20:t.clientY>m.bottom?20:0;c&&setTimeout(Mr(e,function(){y==r&&(a.scroller.scrollTop+=c,l(t))}),50)}}function s(e){y=1/0,ms(e),a.input.focus(),xs(document,"mousemove",b),xs(document,"mouseup",x),u.history.lastSelOrigin=null}var a=e.display,u=e.doc;ms(t);var c,f,h=u.sel,d=h.ranges;if(i&&!t.shiftKey?(f=u.sel.contains(r),c=f>-1?d[f]:new ct(r,r)):c=u.sel.primary(),t.altKey)n="rect",i||(c=new ct(r,r)),r=Ur(e,t,!0,!0),f=-1;else if("double"==n){var p=e.findWordAt(r);c=e.display.shift||u.extend?yt(u,c,p.anchor,p.head):p}else if("triple"==n){var g=new ct(Al(r.line,0),pt(u,Al(r.line+1,0)));c=e.display.shift||u.extend?yt(u,c,g.anchor,g.head):g}else c=yt(u,c,r);i?-1==f?(f=d.length,kt(u,ft(d.concat([c]),f),{scroll:!1,origin:"*mouse"})):d.length>1&&d[f].empty()&&"single"==n?(kt(u,ft(d.slice(0,f).concat(d.slice(f+1)),0)),h=u.sel):xt(u,f,c,Ms):(f=0,kt(u,new ut([c],0),Ms),h=u.sel);var v=r,m=a.wrapper.getBoundingClientRect(),y=0,b=Mr(e,function(e){vo(e)?l(e):s(e)}),x=Mr(e,s);ws(document,"mousemove",b),ws(document,"mouseup",x)}function _r(e,t,r,n,i){try{var o=t.clientX,l=t.clientY}catch(t){return!1}if(o>=Math.floor(e.display.gutters.getBoundingClientRect().right))return!1;n&&ms(t);var s=e.display,a=s.lineDiv.getBoundingClientRect();if(l>a.bottom||!xo(e,r))return po(t);l-=a.top-s.viewOffset;for(var u=0;u<e.options.gutters.length;++u){var c=s.gutters.childNodes[u];if(c&&c.getBoundingClientRect().right>=o){var f=$i(e.doc,l),h=e.options.gutters[u];return i(e,r,e,f,h,t),po(t)}}}function Yr(e,t){return _r(e,t,"gutterClick",!0,mo)}function $r(e){var t=this;if(!bo(t,e)&&!Gr(t.display,e)){ms(e),cl&&(El=+new Date);var r=Ur(t,e,!0),n=e.dataTransfer.files;if(r&&!Z(t))if(n&&n.length&&window.FileReader&&window.File)for(var i=n.length,o=Array(i),l=0,s=function(e,n){var s=new FileReader;s.onload=Mr(t,function(){if(o[n]=s.result,++l==i){r=pt(t.doc,r);var e={from:r,to:r,text:Vs(o.join("\n")),origin:"paste"};bn(t.doc,e),Lt(t.doc,ht(r,Vl(e)))}}),s.readAsText(e)},a=0;i>a;++a)s(n[a],a);else{if(t.state.draggingText&&t.doc.sel.contains(r)>-1)return t.state.draggingText(e),void setTimeout(function(){t.display.input.focus()},20);try{var o=e.dataTransfer.getData("Text");if(o){if(t.state.draggingText&&!(xl?e.metaKey:e.ctrlKey))var u=t.listSelections();if(Tt(t.doc,ht(r,r)),u)for(var a=0;a<u.length;++a)kn(t.doc,"",u[a].anchor,u[a].head,"drag");t.replaceSelection(o,"around","paste"),t.display.input.focus()}}catch(e){}}}}function qr(e,t){if(cl&&(!e.state.draggingText||+new Date-El<100))return void bs(t);if(!bo(e,t)&&!Gr(e.display,t)&&(t.dataTransfer.setData("Text",e.getSelection()),t.dataTransfer.setDragImage&&!vl)){var r=zo("img",null,null,"position: fixed; left: 0; top: 0;");r.src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==",gl&&(r.width=r.height=1,e.display.wrapper.appendChild(r),r._top=r.offsetTop),t.dataTransfer.setDragImage(r,0,0),gl&&r.parentNode.removeChild(r)}}function Zr(e,t){Math.abs(e.doc.scrollTop-t)<2||(e.doc.scrollTop=t,sl||N(e,{top:t}),e.display.scroller.scrollTop!=t&&(e.display.scroller.scrollTop=t),e.display.scrollbars.setScrollTop(t),sl&&N(e),zt(e,100))}function Qr(e,t,r){(r?t==e.doc.scrollLeft:Math.abs(e.doc.scrollLeft-t)<2)||(t=Math.min(t,e.display.scroller.scrollWidth-e.display.scroller.clientWidth),e.doc.scrollLeft=t,x(e),e.display.scroller.scrollLeft!=t&&(e.display.scroller.scrollLeft=t),e.display.scrollbars.setScrollLeft(t))}function Jr(e,t){var r=Bl(t),n=r.x,i=r.y,o=e.display,l=o.scroller;if(n&&l.scrollWidth>l.clientWidth||i&&l.scrollHeight>l.clientHeight){if(i&&xl&&hl)e:for(var s=t.target,a=o.view;s!=l;s=s.parentNode)for(var u=0;u<a.length;u++)if(a[u].node==s){e.display.currentWheelTarget=s;break e}if(n&&!sl&&!gl&&null!=Rl)return i&&Zr(e,Math.max(0,Math.min(l.scrollTop+i*Rl,l.scrollHeight-l.clientHeight))),Qr(e,Math.max(0,Math.min(l.scrollLeft+n*Rl,l.scrollWidth-l.clientWidth))),ms(t),void(o.wheelStartX=null);if(i&&null!=Rl){var c=i*Rl,f=e.doc.scrollTop,h=f+o.wrapper.clientHeight;0>c?f=Math.max(0,f+c-50):h=Math.min(e.doc.height,h+c+50),N(e,{top:f,bottom:h})}20>Fl&&(null==o.wheelStartX?(o.wheelStartX=l.scrollLeft,o.wheelStartY=l.scrollTop,o.wheelDX=n,o.wheelDY=i,setTimeout(function(){if(null!=o.wheelStartX){var e=l.scrollLeft-o.wheelStartX,t=l.scrollTop-o.wheelStartY,r=t&&o.wheelDY&&t/o.wheelDY||e&&o.wheelDX&&e/o.wheelDX;o.wheelStartX=o.wheelStartY=null,r&&(Rl=(Rl*Fl+r)/(Fl+1),++Fl)}},200)):(o.wheelDX+=n,o.wheelDY+=i))}}function en(e,t,r){if("string"==typeof t&&(t=es[t],!t))return!1;e.display.input.ensurePolled();var n=e.display.shift,i=!1;try{Z(e)&&(e.state.suppressEdits=!0),r&&(e.display.shift=!1),i=t(e)!=ks}finally{e.display.shift=n,e.state.suppressEdits=!1}return i}function tn(e,t,r){for(var n=0;n<e.state.keyMaps.length;n++){var i=rs(t,e.state.keyMaps[n],r,e);if(i)return i}return e.options.extraKeys&&rs(t,e.options.extraKeys,r,e)||rs(t,e.options.keyMap,r,e)}function rn(e,t,r,n){var i=e.state.keySeq;if(i){if(ns(t))return"handled";Gl.set(50,function(){e.state.keySeq==i&&(e.state.keySeq=null,e.display.input.reset())}),t=i+" "+t}var o=tn(e,t,n);return"multi"==o&&(e.state.keySeq=t),"handled"==o&&mo(e,"keyHandled",e,t,r),("handled"==o||"multi"==o)&&(ms(r),It(e)),i&&!o&&/\'$/.test(t)?(ms(r),!0):!!o}function nn(e,t){var r=is(t,!0);return r?t.shiftKey&&!e.state.keySeq?rn(e,"Shift-"+r,t,function(t){return en(e,t,!0)})||rn(e,r,t,function(t){return("string"==typeof t?/^go[A-Z]/.test(t):t.motion)?en(e,t):void 0}):rn(e,r,t,function(t){return en(e,t)}):!1}function on(e,t,r){return rn(e,"'"+r+"'",t,function(t){return en(e,t,!0)})}function ln(e){var t=this;if(q(t),!bo(t,e)){cl&&11>fl&&27==e.keyCode&&(e.returnValue=!1);var r=e.keyCode;t.display.shift=16==r||e.shiftKey;var n=nn(t,e);gl&&(Ul=n?r:null,!n&&88==r&&!js&&(xl?e.metaKey:e.ctrlKey)&&t.replaceSelection("",null,"cut")),18!=r||/\bCodeMirror-crosshair\b/.test(t.display.lineDiv.className)||sn(t)}}function sn(e){function t(e){18!=e.keyCode&&e.altKey||(Rs(r,"CodeMirror-crosshair"),xs(document,"keyup",t),xs(document,"mouseover",t))}var r=e.display.lineDiv;Bs(r,"CodeMirror-crosshair"),ws(document,"keyup",t),ws(document,"mouseover",t)}function an(e){16==e.keyCode&&(this.doc.sel.shift=!1),bo(this,e)}function un(e){var t=this;if(!(Gr(t.display,e)||bo(t,e)||e.ctrlKey&&!e.altKey||xl&&e.metaKey)){var r=e.keyCode,n=e.charCode;if(gl&&r==Ul)return Ul=null,void ms(e);if(!gl||e.which&&!(e.which<10)||!nn(t,e)){var i=String.fromCharCode(null==n?r:n);on(t,e,i)||t.display.input.onKeyPress(e)}}}function cn(e){"nocursor"!=e.options.readOnly&&(e.state.focused||(Cs(e,"focus",e),e.state.focused=!0,Bs(e.display.wrapper,"CodeMirror-focused"),e.curOp||e.display.selForContextMenu==e.doc.sel||(e.display.input.reset(),hl&&setTimeout(function(){e.display.input.reset(!0)},20)),e.display.input.receivedFocus()),It(e))}function fn(e){e.state.focused&&(Cs(e,"blur",e),e.state.focused=!1,Rs(e.display.wrapper,"CodeMirror-focused")),clearInterval(e.display.blinker),setTimeout(function(){e.state.focused||(e.display.shift=!1)},150)}function hn(e,t){Gr(e.display,t)||dn(e,t)||e.display.input.onContextMenu(t)}function dn(e,t){return xo(e,"gutterContextMenu")?_r(e,t,"gutterContextMenu",!1,Cs):!1}function pn(e,t){if(Nl(e,t.from)<0)return e;if(Nl(e,t.to)<=0)return Vl(t);var r=e.line+t.text.length-(t.to.line-t.from.line)-1,n=e.ch;return e.line==t.to.line&&(n+=Vl(t).ch-t.to.ch),Al(r,n)}function gn(e,t){for(var r=[],n=0;n<e.sel.ranges.length;n++){var i=e.sel.ranges[n];r.push(new ct(pn(i.anchor,t),pn(i.head,t)))}return ft(r,e.sel.primIndex)}function vn(e,t,r){return e.line==t.line?Al(r.line,e.ch-t.ch+r.ch):Al(r.line+(e.line-t.line),e.ch)}function mn(e,t,r){for(var n=[],i=Al(e.first,0),o=i,l=0;l<t.length;l++){var s=t[l],a=vn(s.from,i,o),u=vn(Vl(s),i,o);if(i=s.to,o=u,"around"==r){var c=e.sel.ranges[l],f=Nl(c.head,c.anchor)<0;n[l]=new ct(f?u:a,f?a:u)}else n[l]=new ct(a,a)}return new ut(n,e.sel.primIndex)}function yn(e,t,r){var n={canceled:!1,from:t.from,to:t.to,text:t.text,origin:t.origin,cancel:function(){this.canceled=!0}};return r&&(n.update=function(t,r,n,i){t&&(this.from=pt(e,t)),r&&(this.to=pt(e,r)),n&&(this.text=n),void 0!==i&&(this.origin=i)}),Cs(e,"beforeChange",e,n),e.cm&&Cs(e.cm,"beforeChange",e.cm,n),n.canceled?null:{from:n.from,to:n.to,text:n.text,origin:n.origin}}function bn(e,t,r){if(e.cm){if(!e.cm.curOp)return Mr(e.cm,bn)(e,t,r);if(e.cm.state.suppressEdits)return}if(!(xo(e,"beforeChange")||e.cm&&xo(e.cm,"beforeChange"))||(t=yn(e,t,!0))){var n=Tl&&!r&&ti(e,t.from,t.to);if(n)for(var i=n.length-1;i>=0;--i)wn(e,{from:n[i].from,to:n[i].to,text:i?[""]:t.text});else wn(e,t)}}function wn(e,t){if(1!=t.text.length||""!=t.text[0]||0!=Nl(t.from,t.to)){var r=gn(e,t);ro(e,t,r,e.cm?e.cm.curOp.id:0/0),Sn(e,t,r,Qn(e,t));var n=[];Ui(e,function(e,r){r||-1!=Mo(n,e.history)||(ho(e.history,t),n.push(e.history)),Sn(e,t,null,Qn(e,t))})}}function xn(e,t,r){if(!e.cm||!e.cm.state.suppressEdits){for(var n,i=e.history,o=e.sel,l="undo"==t?i.done:i.undone,s="undo"==t?i.undone:i.done,a=0;a<l.length&&(n=l[a],r?!n.ranges||n.equals(e.sel):n.ranges);a++);if(a!=l.length){for(i.lastOrigin=i.lastSelOrigin=null;n=l.pop(),n.ranges;){if(oo(n,s),r&&!n.equals(e.sel))return void kt(e,n,{clearRedo:!1});o=n}var u=[];oo(o,s),s.push({changes:u,generation:i.generation}),i.generation=n.generation||++i.maxGeneration;for(var c=xo(e,"beforeChange")||e.cm&&xo(e.cm,"beforeChange"),a=n.changes.length-1;a>=0;--a){var f=n.changes[a];if(f.origin=t,c&&!yn(e,f,!1))return void(l.length=0);u.push(Ji(e,f));var h=a?gn(e,f):To(l);Sn(e,f,h,ei(e,f)),!a&&e.cm&&e.cm.scrollIntoView({from:f.from,to:Vl(f)});var d=[];Ui(e,function(e,t){t||-1!=Mo(d,e.history)||(ho(e.history,f),d.push(e.history)),Sn(e,f,null,ei(e,f))})}}}}function Cn(e,t){if(0!=t&&(e.first+=t,e.sel=new ut(Ao(e.sel.ranges,function(e){return new ct(Al(e.anchor.line+t,e.anchor.ch),Al(e.head.line+t,e.head.ch))}),e.sel.primIndex),e.cm)){Dr(e.cm,e.first,e.first-t,t);for(var r=e.cm.display,n=r.viewFrom;n<r.viewTo;n++)Hr(e.cm,n,"gutter")}}function Sn(e,t,r,n){if(e.cm&&!e.cm.curOp)return Mr(e.cm,Sn)(e,t,r,n);if(t.to.line<e.first)return void Cn(e,t.text.length-1-(t.to.line-t.from.line));if(!(t.from.line>e.lastLine())){if(t.from.line<e.first){var i=t.text.length-1-(e.first-t.from.line);Cn(e,i),t={from:Al(e.first,0),to:Al(t.to.line+i,t.to.ch),text:[To(t.text)],origin:t.origin}}var o=e.lastLine();t.to.line>o&&(t={from:t.from,to:Al(o,Ki(e,o).text.length),text:[t.text[0]],origin:t.origin}),t.removed=ji(e,t.from,t.to),r||(r=gn(e,t)),e.cm?Ln(e.cm,t,n):Ri(e,t,n),Tt(e,r,Ts)}}function Ln(e,t,r){var n=e.doc,i=e.display,l=t.from,s=t.to,a=!1,u=l.line;e.options.lineWrapping||(u=Yi(fi(Ki(n,l.line))),n.iter(u,s.line+1,function(e){return e==i.maxLine?(a=!0,!0):void 0})),n.sel.contains(t.from,t.to)>-1&&wo(e),Ri(n,t,r,o(e)),e.options.lineWrapping||(n.iter(u,l.line+t.text.length,function(e){var t=f(e);t>i.maxLineLength&&(i.maxLine=e,i.maxLineLength=t,i.maxLineChanged=!0,a=!1)}),a&&(e.curOp.updateMaxLine=!0)),n.frontier=Math.min(n.frontier,l.line),zt(e,400);var c=t.text.length-(s.line-l.line)-1;t.full?Dr(e):l.line!=s.line||1!=t.text.length||Fi(e.doc,t)?Dr(e,l.line,s.line+1,c):Hr(e,l.line,"text");var h=xo(e,"changes"),d=xo(e,"change");if(d||h){var p={from:l,to:s,text:t.text,removed:t.removed,origin:t.origin};d&&mo(e,"change",e,p),h&&(e.curOp.changeObjs||(e.curOp.changeObjs=[])).push(p)}e.display.selForContextMenu=null}function kn(e,t,r,n,i){if(n||(n=r),Nl(n,r)<0){var o=n;n=r,r=o}"string"==typeof t&&(t=Vs(t)),bn(e,{from:r,to:n,text:t,origin:i})}function Tn(e,t){if(!bo(e,"scrollCursorIntoView")){var r=e.display,n=r.sizer.getBoundingClientRect(),i=null;if(t.top+n.top<0?i=!0:t.bottom+n.top>(window.innerHeight||document.documentElement.clientHeight)&&(i=!1),null!=i&&!yl){var o=zo("div","​",null,"position: absolute; top: "+(t.top-r.viewOffset-Bt(e.display))+"px; height: "+(t.bottom-t.top+Vt(e)+r.barHeight)+"px; left: "+t.left+"px; width: 2px;");e.display.lineSpace.appendChild(o),o.scrollIntoView(i),e.display.lineSpace.removeChild(o)}}}function Mn(e,t,r,n){null==n&&(n=0);for(var i=0;5>i;i++){var o=!1,l=cr(e,t),s=r&&r!=t?cr(e,r):l,a=Nn(e,Math.min(l.left,s.left),Math.min(l.top,s.top)-n,Math.max(l.left,s.left),Math.max(l.bottom,s.bottom)+n),u=e.doc.scrollTop,c=e.doc.scrollLeft;if(null!=a.scrollTop&&(Zr(e,a.scrollTop),Math.abs(e.doc.scrollTop-u)>1&&(o=!0)),null!=a.scrollLeft&&(Qr(e,a.scrollLeft),Math.abs(e.doc.scrollLeft-c)>1&&(o=!0)),!o)break}return l}function An(e,t,r,n,i){var o=Nn(e,t,r,n,i);null!=o.scrollTop&&Zr(e,o.scrollTop),null!=o.scrollLeft&&Qr(e,o.scrollLeft)}function Nn(e,t,r,n,i){var o=e.display,l=gr(e.display);0>r&&(r=0);var s=e.curOp&&null!=e.curOp.scrollTop?e.curOp.scrollTop:o.scroller.scrollTop,a=jt(e),u={};i-r>a&&(i=r+a);var c=e.doc.height+Gt(o),f=l>r,h=i>c-l;if(s>r)u.scrollTop=f?0:r;else if(i>s+a){var d=Math.min(r,(h?c:i)-a);d!=s&&(u.scrollTop=d)}var p=e.curOp&&null!=e.curOp.scrollLeft?e.curOp.scrollLeft:o.scroller.scrollLeft,g=Kt(e)-(e.options.fixedGutter?o.gutters.offsetWidth:0),v=n-t>g;return v&&(n=t+g),10>t?u.scrollLeft=0:p>t?u.scrollLeft=Math.max(0,t-(v?0:10)):n>g+p-3&&(u.scrollLeft=n+(v?0:10)-g),u}function Wn(e,t,r){(null!=t||null!=r)&&Dn(e),null!=t&&(e.curOp.scrollLeft=(null==e.curOp.scrollLeft?e.doc.scrollLeft:e.curOp.scrollLeft)+t),null!=r&&(e.curOp.scrollTop=(null==e.curOp.scrollTop?e.doc.scrollTop:e.curOp.scrollTop)+r)}function On(e){Dn(e);var t=e.getCursor(),r=t,n=t;e.options.lineWrapping||(r=t.ch?Al(t.line,t.ch-1):t,n=Al(t.line,t.ch+1)),e.curOp.scrollToPos={from:r,to:n,margin:e.options.cursorScrollMargin,isCursor:!0}}function Dn(e){var t=e.curOp.scrollToPos;if(t){e.curOp.scrollToPos=null;var r=fr(e,t.from),n=fr(e,t.to),i=Nn(e,Math.min(r.left,n.left),Math.min(r.top,n.top)-t.margin,Math.max(r.right,n.right),Math.max(r.bottom,n.bottom)+t.margin);e.scrollTo(i.scrollLeft,i.scrollTop)}}function Hn(e,t,r,n){var i,o=e.doc;null==r&&(r="add"),"smart"==r&&(o.mode.indent?i=Rt(e,t):r="prev");var l=e.options.tabSize,s=Ki(o,t),a=Ns(s.text,null,l);s.stateAfter&&(s.stateAfter=null);var u,c=s.text.match(/^\s*/)[0];if(n||/\S/.test(s.text)){if("smart"==r&&(u=o.mode.indent(i,s.text.slice(c.length),s.text),u==ks||u>150)){if(!n)return;r="prev"}}else u=0,r="not";"prev"==r?u=t>o.first?Ns(Ki(o,t-1).text,null,l):0:"add"==r?u=a+e.options.indentUnit:"subtract"==r?u=a-e.options.indentUnit:"number"==typeof r&&(u=a+r),u=Math.max(0,u);var f="",h=0;if(e.options.indentWithTabs)for(var d=Math.floor(u/l);d;--d)h+=l,f+=" ";if(u>h&&(f+=ko(u-h)),f!=c)kn(o,f,Al(t,0),Al(t,c.length),"+input");else for(var d=0;d<o.sel.ranges.length;d++){var p=o.sel.ranges[d];if(p.head.line==t&&p.head.ch<c.length){var h=Al(t,c.length);xt(o,d,new ct(h,h));break}}s.stateAfter=null}function Pn(e,t,r,n){var i=t,o=t;return"number"==typeof t?o=Ki(e,dt(e,t)):i=Yi(t),null==i?null:(n(o,i)&&e.cm&&Hr(e.cm,i,r),o)}function In(e,t){for(var r=e.doc.sel.ranges,n=[],i=0;i<r.length;i++){for(var o=t(r[i]);n.length&&Nl(o.from,To(n).to)<=0;){var l=n.pop();if(Nl(l.from,o.from)<0){o.from=l.from;break}}n.push(o)}Tr(e,function(){for(var t=n.length-1;t>=0;t--)kn(e.doc,"",n[t].from,n[t].to,"+delete");On(e)})}function zn(e,t,r,n,i){function o(){var t=s+r;return t<e.first||t>=e.first+e.size?f=!1:(s=t,c=Ki(e,t))}function l(e){var t=(i?ol:ll)(c,a,r,!0);if(null==t){if(e||!o())return f=!1;a=i?(0>r?Qo:Zo)(c):0>r?c.text.length:0}else a=t;return!0}var s=t.line,a=t.ch,u=r,c=Ki(e,s),f=!0;if("char"==n)l();else if("column"==n)l(!0);else if("word"==n||"group"==n)for(var h=null,d="group"==n,p=e.cm&&e.cm.getHelper(t,"wordChars"),g=!0;!(0>r)||l(!g);g=!1){var v=c.text.charAt(a)||"\n",m=Ho(v,p)?"w":d&&"\n"==v?"n":!d||/\s/.test(v)?null:"p";if(!d||g||m||(m="s"),h&&h!=m){0>r&&(r=1,l());break}if(m&&(h=m),r>0&&!l(!g))break}var y=Wt(e,Al(s,a),u,!0);return f||(y.hitSide=!0),y}function En(e,t,r,n){var i,o=e.doc,l=t.left;if("page"==n){var s=Math.min(e.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight);i=t.top+r*(s-(0>r?1.5:.5)*gr(e.display))}else"line"==n&&(i=r>0?t.bottom+3:t.top-3);for(;;){var a=dr(e,l,i);if(!a.outside)break;if(0>r?0>=i:i>=o.height){a.hitSide=!0;break}i+=5*r}return a}function Fn(t,r,n,i){e.defaults[t]=r,n&&(jl[t]=i?function(e,t,r){r!=Xl&&n(e,t,r)}:n)}function Rn(e){for(var t,r,n,i,o=e.split(/-(?!$)/),e=o[o.length-1],l=0;l<o.length-1;l++){var s=o[l];if(/^(cmd|meta|m)$/i.test(s))i=!0;else if(/^a(lt)?$/i.test(s))t=!0;else if(/^(c|ctrl|control)$/i.test(s))r=!0;else{if(!/^s(hift)$/i.test(s))throw new Error("Unrecognized modifier name: "+s);n=!0}}return t&&(e="Alt-"+e),r&&(e="Ctrl-"+e),i&&(e="Cmd-"+e),n&&(e="Shift-"+e),e}function Bn(e){return"string"==typeof e?ts[e]:e
3
- }function Gn(e,t,r,n,i){if(n&&n.shared)return Un(e,t,r,n,i);if(e.cm&&!e.cm.curOp)return Mr(e.cm,Gn)(e,t,r,n,i);var o=new ss(e,i),l=Nl(t,r);if(n&&Oo(n,o,!1),l>0||0==l&&o.clearWhenEmpty!==!1)return o;if(o.replacedWith&&(o.collapsed=!0,o.widgetNode=zo("span",[o.replacedWith],"CodeMirror-widget"),n.handleMouseEvents||o.widgetNode.setAttribute("cm-ignore-events","true"),n.insertLeft&&(o.widgetNode.insertLeft=!0)),o.collapsed){if(ci(e,t.line,t,r,o)||t.line!=r.line&&ci(e,r.line,t,r,o))throw new Error("Inserting collapsed marker partially overlapping an existing one");Ml=!0}o.addToHistory&&ro(e,{from:t,to:r,origin:"markText"},e.sel,0/0);var s,a=t.line,u=e.cm;if(e.iter(a,r.line+1,function(e){u&&o.collapsed&&!u.options.lineWrapping&&fi(e)==u.display.maxLine&&(s=!0),o.collapsed&&a!=t.line&&_i(e,0),$n(e,new Xn(o,a==t.line?t.ch:null,a==r.line?r.ch:null)),++a}),o.collapsed&&e.iter(t.line,r.line+1,function(t){gi(e,t)&&_i(t,0)}),o.clearOnEnter&&ws(o,"beforeCursorEnter",function(){o.clear()}),o.readOnly&&(Tl=!0,(e.history.done.length||e.history.undone.length)&&e.clearHistory()),o.collapsed&&(o.id=++ls,o.atomic=!0),u){if(s&&(u.curOp.updateMaxLine=!0),o.collapsed)Dr(u,t.line,r.line+1);else if(o.className||o.title||o.startStyle||o.endStyle||o.css)for(var c=t.line;c<=r.line;c++)Hr(u,c,"text");o.atomic&&At(u.doc),mo(u,"markerAdded",u,o)}return o}function Un(e,t,r,n,i){n=Oo(n),n.shared=!1;var o=[Gn(e,t,r,n,i)],l=o[0],s=n.widgetNode;return Ui(e,function(e){s&&(n.widgetNode=s.cloneNode(!0)),o.push(Gn(e,pt(e,t),pt(e,r),n,i));for(var a=0;a<e.linked.length;++a)if(e.linked[a].isParent)return;l=To(o)}),new as(o,l)}function Vn(e){return e.findMarks(Al(e.first,0),e.clipPos(Al(e.lastLine())),function(e){return e.parent})}function Kn(e,t){for(var r=0;r<t.length;r++){var n=t[r],i=n.find(),o=e.clipPos(i.from),l=e.clipPos(i.to);if(Nl(o,l)){var s=Gn(e,o,l,n.primary,n.primary.type);n.markers.push(s),s.parent=n}}}function jn(e){for(var t=0;t<e.length;t++){var r=e[t],n=[r.primary.doc];Ui(r.primary.doc,function(e){n.push(e)});for(var i=0;i<r.markers.length;i++){var o=r.markers[i];-1==Mo(n,o.doc)&&(o.parent=null,r.markers.splice(i--,1))}}}function Xn(e,t,r){this.marker=e,this.from=t,this.to=r}function _n(e,t){if(e)for(var r=0;r<e.length;++r){var n=e[r];if(n.marker==t)return n}}function Yn(e,t){for(var r,n=0;n<e.length;++n)e[n]!=t&&(r||(r=[])).push(e[n]);return r}function $n(e,t){e.markedSpans=e.markedSpans?e.markedSpans.concat([t]):[t],t.marker.attachLine(e)}function qn(e,t,r){if(e)for(var n,i=0;i<e.length;++i){var o=e[i],l=o.marker,s=null==o.from||(l.inclusiveLeft?o.from<=t:o.from<t);if(s||o.from==t&&"bookmark"==l.type&&(!r||!o.marker.insertLeft)){var a=null==o.to||(l.inclusiveRight?o.to>=t:o.to>t);(n||(n=[])).push(new Xn(l,o.from,a?null:o.to))}}return n}function Zn(e,t,r){if(e)for(var n,i=0;i<e.length;++i){var o=e[i],l=o.marker,s=null==o.to||(l.inclusiveRight?o.to>=t:o.to>t);if(s||o.from==t&&"bookmark"==l.type&&(!r||o.marker.insertLeft)){var a=null==o.from||(l.inclusiveLeft?o.from<=t:o.from<t);(n||(n=[])).push(new Xn(l,a?null:o.from-t,null==o.to?null:o.to-t))}}return n}function Qn(e,t){if(t.full)return null;var r=vt(e,t.from.line)&&Ki(e,t.from.line).markedSpans,n=vt(e,t.to.line)&&Ki(e,t.to.line).markedSpans;if(!r&&!n)return null;var i=t.from.ch,o=t.to.ch,l=0==Nl(t.from,t.to),s=qn(r,i,l),a=Zn(n,o,l),u=1==t.text.length,c=To(t.text).length+(u?i:0);if(s)for(var f=0;f<s.length;++f){var h=s[f];if(null==h.to){var d=_n(a,h.marker);d?u&&(h.to=null==d.to?null:d.to+c):h.to=i}}if(a)for(var f=0;f<a.length;++f){var h=a[f];if(null!=h.to&&(h.to+=c),null==h.from){var d=_n(s,h.marker);d||(h.from=c,u&&(s||(s=[])).push(h))}else h.from+=c,u&&(s||(s=[])).push(h)}s&&(s=Jn(s)),a&&a!=s&&(a=Jn(a));var p=[s];if(!u){var g,v=t.text.length-2;if(v>0&&s)for(var f=0;f<s.length;++f)null==s[f].to&&(g||(g=[])).push(new Xn(s[f].marker,null,null));for(var f=0;v>f;++f)p.push(g);p.push(a)}return p}function Jn(e){for(var t=0;t<e.length;++t){var r=e[t];null!=r.from&&r.from==r.to&&r.marker.clearWhenEmpty!==!1&&e.splice(t--,1)}return e.length?e:null}function ei(e,t){var r=ao(e,t),n=Qn(e,t);if(!r)return n;if(!n)return r;for(var i=0;i<r.length;++i){var o=r[i],l=n[i];if(o&&l)e:for(var s=0;s<l.length;++s){for(var a=l[s],u=0;u<o.length;++u)if(o[u].marker==a.marker)continue e;o.push(a)}else l&&(r[i]=l)}return r}function ti(e,t,r){var n=null;if(e.iter(t.line,r.line+1,function(e){if(e.markedSpans)for(var t=0;t<e.markedSpans.length;++t){var r=e.markedSpans[t].marker;!r.readOnly||n&&-1!=Mo(n,r)||(n||(n=[])).push(r)}}),!n)return null;for(var i=[{from:t,to:r}],o=0;o<n.length;++o)for(var l=n[o],s=l.find(0),a=0;a<i.length;++a){var u=i[a];if(!(Nl(u.to,s.from)<0||Nl(u.from,s.to)>0)){var c=[a,1],f=Nl(u.from,s.from),h=Nl(u.to,s.to);(0>f||!l.inclusiveLeft&&!f)&&c.push({from:u.from,to:s.from}),(h>0||!l.inclusiveRight&&!h)&&c.push({from:s.to,to:u.to}),i.splice.apply(i,c),a+=c.length-1}}return i}function ri(e){var t=e.markedSpans;if(t){for(var r=0;r<t.length;++r)t[r].marker.detachLine(e);e.markedSpans=null}}function ni(e,t){if(t){for(var r=0;r<t.length;++r)t[r].marker.attachLine(e);e.markedSpans=t}}function ii(e){return e.inclusiveLeft?-1:0}function oi(e){return e.inclusiveRight?1:0}function li(e,t){var r=e.lines.length-t.lines.length;if(0!=r)return r;var n=e.find(),i=t.find(),o=Nl(n.from,i.from)||ii(e)-ii(t);if(o)return-o;var l=Nl(n.to,i.to)||oi(e)-oi(t);return l?l:t.id-e.id}function si(e,t){var r,n=Ml&&e.markedSpans;if(n)for(var i,o=0;o<n.length;++o)i=n[o],i.marker.collapsed&&null==(t?i.from:i.to)&&(!r||li(r,i.marker)<0)&&(r=i.marker);return r}function ai(e){return si(e,!0)}function ui(e){return si(e,!1)}function ci(e,t,r,n,i){var o=Ki(e,t),l=Ml&&o.markedSpans;if(l)for(var s=0;s<l.length;++s){var a=l[s];if(a.marker.collapsed){var u=a.marker.find(0),c=Nl(u.from,r)||ii(a.marker)-ii(i),f=Nl(u.to,n)||oi(a.marker)-oi(i);if(!(c>=0&&0>=f||0>=c&&f>=0)&&(0>=c&&(Nl(u.to,r)>0||a.marker.inclusiveRight&&i.inclusiveLeft)||c>=0&&(Nl(u.from,n)<0||a.marker.inclusiveLeft&&i.inclusiveRight)))return!0}}}function fi(e){for(var t;t=ai(e);)e=t.find(-1,!0).line;return e}function hi(e){for(var t,r;t=ui(e);)e=t.find(1,!0).line,(r||(r=[])).push(e);return r}function di(e,t){var r=Ki(e,t),n=fi(r);return r==n?t:Yi(n)}function pi(e,t){if(t>e.lastLine())return t;var r,n=Ki(e,t);if(!gi(e,n))return t;for(;r=ui(n);)n=r.find(1,!0).line;return Yi(n)+1}function gi(e,t){var r=Ml&&t.markedSpans;if(r)for(var n,i=0;i<r.length;++i)if(n=r[i],n.marker.collapsed){if(null==n.from)return!0;if(!n.marker.widgetNode&&0==n.from&&n.marker.inclusiveLeft&&vi(e,t,n))return!0}}function vi(e,t,r){if(null==r.to){var n=r.marker.find(1,!0);return vi(e,n.line,_n(n.line.markedSpans,r.marker))}if(r.marker.inclusiveRight&&r.to==t.text.length)return!0;for(var i,o=0;o<t.markedSpans.length;++o)if(i=t.markedSpans[o],i.marker.collapsed&&!i.marker.widgetNode&&i.from==r.to&&(null==i.to||i.to!=r.from)&&(i.marker.inclusiveLeft||r.marker.inclusiveRight)&&vi(e,t,i))return!0}function mi(e,t,r){qi(t)<(e.curOp&&e.curOp.scrollTop||e.doc.scrollTop)&&Wn(e,null,r)}function yi(e){if(null!=e.height)return e.height;if(!zs(document.body,e.node)){var t="position: relative;";e.coverGutter&&(t+="margin-left: -"+e.cm.display.gutters.offsetWidth+"px;"),e.noHScroll&&(t+="width: "+e.cm.display.wrapper.clientWidth+"px;"),Fo(e.cm.display.measure,zo("div",[e.node],null,t))}return e.height=e.node.offsetHeight}function bi(e,t,r,n){var i=new us(e,r,n);return i.noHScroll&&(e.display.alignWidgets=!0),Pn(e.doc,t,"widget",function(t){var r=t.widgets||(t.widgets=[]);if(null==i.insertAt?r.push(i):r.splice(Math.min(r.length-1,Math.max(0,i.insertAt)),0,i),i.line=t,!gi(e.doc,t)){var n=qi(t)<e.doc.scrollTop;_i(t,t.height+yi(i)),n&&Wn(e,null,i.height),e.curOp.forceUpdate=!0}return!0}),i}function wi(e,t,r,n){e.text=t,e.stateAfter&&(e.stateAfter=null),e.styles&&(e.styles=null),null!=e.order&&(e.order=null),ri(e),ni(e,r);var i=n?n(e):1;i!=e.height&&_i(e,i)}function xi(e){e.parent=null,ri(e)}function Ci(e,t){if(e)for(;;){var r=e.match(/(?:^|\s+)line-(background-)?(\S+)/);if(!r)break;e=e.slice(0,r.index)+e.slice(r.index+r[0].length);var n=r[1]?"bgClass":"textClass";null==t[n]?t[n]=r[2]:new RegExp("(?:^|s)"+r[2]+"(?:$|s)").test(t[n])||(t[n]+=" "+r[2])}return e}function Si(t,r){if(t.blankLine)return t.blankLine(r);if(t.innerMode){var n=e.innerMode(t,r);return n.mode.blankLine?n.mode.blankLine(n.state):void 0}}function Li(t,r,n,i){for(var o=0;10>o;o++){i&&(i[0]=e.innerMode(t,n).mode);var l=t.token(r,n);if(r.pos>r.start)return l}throw new Error("Mode "+t.name+" failed to advance stream.")}function ki(e,t,r,n){function i(e){return{start:f.start,end:f.pos,string:f.current(),type:o||null,state:e?Ql(l.mode,c):c}}var o,l=e.doc,s=l.mode;t=pt(l,t);var a,u=Ki(l,t.line),c=Rt(e,t.line,r),f=new os(u.text,e.options.tabSize);for(n&&(a=[]);(n||f.pos<t.ch)&&!f.eol();)f.start=f.pos,o=Li(s,f,c),n&&a.push(i(!0));return n?a:i()}function Ti(e,t,r,n,i,o,l){var s=r.flattenSpans;null==s&&(s=e.options.flattenSpans);var a,u=0,c=null,f=new os(t,e.options.tabSize),h=e.options.addModeClass&&[null];for(""==t&&Ci(Si(r,n),o);!f.eol();){if(f.pos>e.options.maxHighlightLength?(s=!1,l&&Ni(e,t,n,f.pos),f.pos=t.length,a=null):a=Ci(Li(r,f,n,h),o),h){var d=h[0].name;d&&(a="m-"+(a?d+" "+a:d))}if(!s||c!=a){for(;u<f.start;)u=Math.min(f.start,u+5e4),i(u,c);c=a}f.start=f.pos}for(;u<f.pos;){var p=Math.min(f.pos,u+5e4);i(p,c),u=p}}function Mi(e,t,r,n){var i=[e.state.modeGen],o={};Ti(e,t.text,e.doc.mode,r,function(e,t){i.push(e,t)},o,n);for(var l=0;l<e.state.overlays.length;++l){var s=e.state.overlays[l],a=1,u=0;Ti(e,t.text,s.mode,!0,function(e,t){for(var r=a;e>u;){var n=i[a];n>e&&i.splice(a,1,e,i[a+1],n),a+=2,u=Math.min(e,n)}if(t)if(s.opaque)i.splice(r,a-r,e,"cm-overlay "+t),a=r+2;else for(;a>r;r+=2){var o=i[r+1];i[r+1]=(o?o+" ":"")+"cm-overlay "+t}},o)}return{styles:i,classes:o.bgClass||o.textClass?o:null}}function Ai(e,t,r){if(!t.styles||t.styles[0]!=e.state.modeGen){var n=Mi(e,t,t.stateAfter=Rt(e,Yi(t)));t.styles=n.styles,n.classes?t.styleClasses=n.classes:t.styleClasses&&(t.styleClasses=null),r===e.doc.frontier&&e.doc.frontier++}return t.styles}function Ni(e,t,r,n){var i=e.doc.mode,o=new os(t,e.options.tabSize);for(o.start=o.pos=n||0,""==t&&Si(i,r);!o.eol()&&o.pos<=e.options.maxHighlightLength;)Li(i,o,r),o.start=o.pos}function Wi(e,t){if(!e||/^\s*$/.test(e))return null;var r=t.addModeClass?hs:fs;return r[e]||(r[e]=e.replace(/\S+/g,"cm-$&"))}function Oi(e,t){var r=zo("span",null,null,hl?"padding-right: .1px":null),n={pre:zo("pre",[r]),content:r,col:0,pos:0,cm:e,splitSpaces:(cl||hl)&&e.getOption("lineWrapping")};t.measure={};for(var i=0;i<=(t.rest?t.rest.length:0);i++){var o,l=i?t.rest[i-1]:t.line;n.pos=0,n.addToken=Hi,Xo(e.display.measure)&&(o=Zi(l))&&(n.addToken=Ii(n.addToken,o)),n.map=[];var s=t!=e.display.externalMeasured&&Yi(l);Ei(l,n,Ai(e,l,s)),l.styleClasses&&(l.styleClasses.bgClass&&(n.bgClass=Go(l.styleClasses.bgClass,n.bgClass||"")),l.styleClasses.textClass&&(n.textClass=Go(l.styleClasses.textClass,n.textClass||""))),0==n.map.length&&n.map.push(0,0,n.content.appendChild(jo(e.display.measure))),0==i?(t.measure.map=n.map,t.measure.cache={}):((t.measure.maps||(t.measure.maps=[])).push(n.map),(t.measure.caches||(t.measure.caches=[])).push({}))}return hl&&/\bcm-tab\b/.test(n.content.lastChild.className)&&(n.content.className="cm-tab-wrap-hack"),Cs(e,"renderLine",e,t.line,n.pre),n.pre.className&&(n.textClass=Go(n.pre.className,n.textClass||"")),n}function Di(e){var t=zo("span","•","cm-invalidchar");return t.title="\\u"+e.charCodeAt(0).toString(16),t.setAttribute("aria-label",t.title),t}function Hi(e,t,r,n,i,o,l){if(t){var s=e.splitSpaces?t.replace(/ {3,}/g,Pi):t,a=e.cm.state.specialChars,u=!1;if(a.test(t))for(var c=document.createDocumentFragment(),f=0;;){a.lastIndex=f;var h=a.exec(t),d=h?h.index-f:t.length-f;if(d){var p=document.createTextNode(s.slice(f,f+d));c.appendChild(cl&&9>fl?zo("span",[p]):p),e.map.push(e.pos,e.pos+d,p),e.col+=d,e.pos+=d}if(!h)break;if(f+=d+1," "==h[0]){var g=e.cm.options.tabSize,v=g-e.col%g,p=c.appendChild(zo("span",ko(v),"cm-tab"));p.setAttribute("role","presentation"),p.setAttribute("cm-text"," "),e.col+=v}else{var p=e.cm.options.specialCharPlaceholder(h[0]);p.setAttribute("cm-text",h[0]),c.appendChild(cl&&9>fl?zo("span",[p]):p),e.col+=1}e.map.push(e.pos,e.pos+1,p),e.pos++}else{e.col+=t.length;var c=document.createTextNode(s);e.map.push(e.pos,e.pos+t.length,c),cl&&9>fl&&(u=!0),e.pos+=t.length}if(r||n||i||u||l){var m=r||"";n&&(m+=n),i&&(m+=i);var y=zo("span",[c],m,l);return o&&(y.title=o),e.content.appendChild(y)}e.content.appendChild(c)}}function Pi(e){for(var t=" ",r=0;r<e.length-2;++r)t+=r%2?" ":" ";return t+=" "}function Ii(e,t){return function(r,n,i,o,l,s,a){i=i?i+" cm-force-border":"cm-force-border";for(var u=r.pos,c=u+n.length;;){for(var f=0;f<t.length;f++){var h=t[f];if(h.to>u&&h.from<=u)break}if(h.to>=c)return e(r,n,i,o,l,s,a);e(r,n.slice(0,h.to-u),i,o,null,s,a),o=null,n=n.slice(h.to-u),u=h.to}}}function zi(e,t,r,n){var i=!n&&r.widgetNode;i&&e.map.push(e.pos,e.pos+t,i),!n&&e.cm.display.input.needsContentAttribute&&(i||(i=e.content.appendChild(document.createElement("span"))),i.setAttribute("cm-marker",r.id)),i&&(e.cm.display.input.setUneditable(i),e.content.appendChild(i)),e.pos+=t}function Ei(e,t,r){var n=e.markedSpans,i=e.text,o=0;if(n)for(var l,s,a,u,c,f,h,d=i.length,p=0,g=1,v="",m=0;;){if(m==p){a=u=c=f=s="",h=null,m=1/0;for(var y=[],b=0;b<n.length;++b){var w=n[b],x=w.marker;w.from<=p&&(null==w.to||w.to>p)?(null!=w.to&&m>w.to&&(m=w.to,u=""),x.className&&(a+=" "+x.className),x.css&&(s=x.css),x.startStyle&&w.from==p&&(c+=" "+x.startStyle),x.endStyle&&w.to==m&&(u+=" "+x.endStyle),x.title&&!f&&(f=x.title),x.collapsed&&(!h||li(h.marker,x)<0)&&(h=w)):w.from>p&&m>w.from&&(m=w.from),"bookmark"==x.type&&w.from==p&&x.widgetNode&&y.push(x)}if(h&&(h.from||0)==p&&(zi(t,(null==h.to?d+1:h.to)-p,h.marker,null==h.from),null==h.to))return;if(!h&&y.length)for(var b=0;b<y.length;++b)zi(t,0,y[b])}if(p>=d)break;for(var C=Math.min(d,m);;){if(v){var S=p+v.length;if(!h){var L=S>C?v.slice(0,C-p):v;t.addToken(t,L,l?l+a:a,c,p+L.length==m?u:"",f,s)}if(S>=C){v=v.slice(C-p),p=C;break}p=S,c=""}v=i.slice(o,o=r[g++]),l=Wi(r[g++],t.cm.options)}}else for(var g=1;g<r.length;g+=2)t.addToken(t,i.slice(o,o=r[g]),Wi(r[g+1],t.cm.options))}function Fi(e,t){return 0==t.from.ch&&0==t.to.ch&&""==To(t.text)&&(!e.cm||e.cm.options.wholeLineUpdateBefore)}function Ri(e,t,r,n){function i(e){return r?r[e]:null}function o(e,r,i){wi(e,r,i,n),mo(e,"change",e,t)}function l(e,t){for(var r=e,o=[];t>r;++r)o.push(new cs(u[r],i(r),n));return o}var s=t.from,a=t.to,u=t.text,c=Ki(e,s.line),f=Ki(e,a.line),h=To(u),d=i(u.length-1),p=a.line-s.line;if(t.full)e.insert(0,l(0,u.length)),e.remove(u.length,e.size-u.length);else if(Fi(e,t)){var g=l(0,u.length-1);o(f,f.text,d),p&&e.remove(s.line,p),g.length&&e.insert(s.line,g)}else if(c==f)if(1==u.length)o(c,c.text.slice(0,s.ch)+h+c.text.slice(a.ch),d);else{var g=l(1,u.length-1);g.push(new cs(h+c.text.slice(a.ch),d,n)),o(c,c.text.slice(0,s.ch)+u[0],i(0)),e.insert(s.line+1,g)}else if(1==u.length)o(c,c.text.slice(0,s.ch)+u[0]+f.text.slice(a.ch),i(0)),e.remove(s.line+1,p);else{o(c,c.text.slice(0,s.ch)+u[0],i(0)),o(f,h+f.text.slice(a.ch),d);var g=l(1,u.length-1);p>1&&e.remove(s.line+1,p-1),e.insert(s.line+1,g)}mo(e,"change",e,t)}function Bi(e){this.lines=e,this.parent=null;for(var t=0,r=0;t<e.length;++t)e[t].parent=this,r+=e[t].height;this.height=r}function Gi(e){this.children=e;for(var t=0,r=0,n=0;n<e.length;++n){var i=e[n];t+=i.chunkSize(),r+=i.height,i.parent=this}this.size=t,this.height=r,this.parent=null}function Ui(e,t,r){function n(e,i,o){if(e.linked)for(var l=0;l<e.linked.length;++l){var s=e.linked[l];if(s.doc!=i){var a=o&&s.sharedHist;(!r||a)&&(t(s.doc,a),n(s.doc,e,a))}}}n(e,null,!0)}function Vi(e,t){if(t.cm)throw new Error("This document is already in use.");e.doc=t,t.cm=e,l(e),r(e),e.options.lineWrapping||h(e),e.options.mode=t.modeOption,Dr(e)}function Ki(e,t){if(t-=e.first,0>t||t>=e.size)throw new Error("There is no line "+(t+e.first)+" in the document.");for(var r=e;!r.lines;)for(var n=0;;++n){var i=r.children[n],o=i.chunkSize();if(o>t){r=i;break}t-=o}return r.lines[t]}function ji(e,t,r){var n=[],i=t.line;return e.iter(t.line,r.line+1,function(e){var o=e.text;i==r.line&&(o=o.slice(0,r.ch)),i==t.line&&(o=o.slice(t.ch)),n.push(o),++i}),n}function Xi(e,t,r){var n=[];return e.iter(t,r,function(e){n.push(e.text)}),n}function _i(e,t){var r=t-e.height;if(r)for(var n=e;n;n=n.parent)n.height+=r}function Yi(e){if(null==e.parent)return null;for(var t=e.parent,r=Mo(t.lines,e),n=t.parent;n;t=n,n=n.parent)for(var i=0;n.children[i]!=t;++i)r+=n.children[i].chunkSize();return r+t.first}function $i(e,t){var r=e.first;e:do{for(var n=0;n<e.children.length;++n){var i=e.children[n],o=i.height;if(o>t){e=i;continue e}t-=o,r+=i.chunkSize()}return r}while(!e.lines);for(var n=0;n<e.lines.length;++n){var l=e.lines[n],s=l.height;if(s>t)break;t-=s}return r+n}function qi(e){e=fi(e);for(var t=0,r=e.parent,n=0;n<r.lines.length;++n){var i=r.lines[n];if(i==e)break;t+=i.height}for(var o=r.parent;o;r=o,o=r.parent)for(var n=0;n<o.children.length;++n){var l=o.children[n];if(l==r)break;t+=l.height}return t}function Zi(e){var t=e.order;return null==t&&(t=e.order=$s(e.text)),t}function Qi(e){this.done=[],this.undone=[],this.undoDepth=1/0,this.lastModTime=this.lastSelTime=0,this.lastOp=this.lastSelOp=null,this.lastOrigin=this.lastSelOrigin=null,this.generation=this.maxGeneration=e||1}function Ji(e,t){var r={from:_(t.from),to:Vl(t),text:ji(e,t.from,t.to)};return lo(e,r,t.from.line,t.to.line+1),Ui(e,function(e){lo(e,r,t.from.line,t.to.line+1)},!0),r}function eo(e){for(;e.length;){var t=To(e);if(!t.ranges)break;e.pop()}}function to(e,t){return t?(eo(e.done),To(e.done)):e.done.length&&!To(e.done).ranges?To(e.done):e.done.length>1&&!e.done[e.done.length-2].ranges?(e.done.pop(),To(e.done)):void 0}function ro(e,t,r,n){var i=e.history;i.undone.length=0;var o,l=+new Date;if((i.lastOp==n||i.lastOrigin==t.origin&&t.origin&&("+"==t.origin.charAt(0)&&e.cm&&i.lastModTime>l-e.cm.options.historyEventDelay||"*"==t.origin.charAt(0)))&&(o=to(i,i.lastOp==n))){var s=To(o.changes);0==Nl(t.from,t.to)&&0==Nl(t.from,s.to)?s.to=Vl(t):o.changes.push(Ji(e,t))}else{var a=To(i.done);for(a&&a.ranges||oo(e.sel,i.done),o={changes:[Ji(e,t)],generation:i.generation},i.done.push(o);i.done.length>i.undoDepth;)i.done.shift(),i.done[0].ranges||i.done.shift()}i.done.push(r),i.generation=++i.maxGeneration,i.lastModTime=i.lastSelTime=l,i.lastOp=i.lastSelOp=n,i.lastOrigin=i.lastSelOrigin=t.origin,s||Cs(e,"historyAdded")}function no(e,t,r,n){var i=t.charAt(0);return"*"==i||"+"==i&&r.ranges.length==n.ranges.length&&r.somethingSelected()==n.somethingSelected()&&new Date-e.history.lastSelTime<=(e.cm?e.cm.options.historyEventDelay:500)}function io(e,t,r,n){var i=e.history,o=n&&n.origin;r==i.lastSelOp||o&&i.lastSelOrigin==o&&(i.lastModTime==i.lastSelTime&&i.lastOrigin==o||no(e,o,To(i.done),t))?i.done[i.done.length-1]=t:oo(t,i.done),i.lastSelTime=+new Date,i.lastSelOrigin=o,i.lastSelOp=r,n&&n.clearRedo!==!1&&eo(i.undone)}function oo(e,t){var r=To(t);r&&r.ranges&&r.equals(e)||t.push(e)}function lo(e,t,r,n){var i=t["spans_"+e.id],o=0;e.iter(Math.max(e.first,r),Math.min(e.first+e.size,n),function(r){r.markedSpans&&((i||(i=t["spans_"+e.id]={}))[o]=r.markedSpans),++o})}function so(e){if(!e)return null;for(var t,r=0;r<e.length;++r)e[r].marker.explicitlyCleared?t||(t=e.slice(0,r)):t&&t.push(e[r]);return t?t.length?t:null:e}function ao(e,t){var r=t["spans_"+e.id];if(!r)return null;for(var n=0,i=[];n<t.text.length;++n)i.push(so(r[n]));return i}function uo(e,t,r){for(var n=0,i=[];n<e.length;++n){var o=e[n];if(o.ranges)i.push(r?ut.prototype.deepCopy.call(o):o);else{var l=o.changes,s=[];i.push({changes:s});for(var a=0;a<l.length;++a){var u,c=l[a];if(s.push({from:c.from,to:c.to,text:c.text}),t)for(var f in c)(u=f.match(/^spans_(\d+)$/))&&Mo(t,Number(u[1]))>-1&&(To(s)[f]=c[f],delete c[f])}}}return i}function co(e,t,r,n){r<e.line?e.line+=n:t<e.line&&(e.line=t,e.ch=0)}function fo(e,t,r,n){for(var i=0;i<e.length;++i){var o=e[i],l=!0;if(o.ranges){o.copied||(o=e[i]=o.deepCopy(),o.copied=!0);for(var s=0;s<o.ranges.length;s++)co(o.ranges[s].anchor,t,r,n),co(o.ranges[s].head,t,r,n)}else{for(var s=0;s<o.changes.length;++s){var a=o.changes[s];if(r<a.from.line)a.from=Al(a.from.line+n,a.from.ch),a.to=Al(a.to.line+n,a.to.ch);else if(t<=a.to.line){l=!1;break}}l||(e.splice(0,i+1),i=0)}}}function ho(e,t){var r=t.from.line,n=t.to.line,i=t.text.length-(n-r)-1;fo(e.done,r,n,i),fo(e.undone,r,n,i)}function po(e){return null!=e.defaultPrevented?e.defaultPrevented:0==e.returnValue}function go(e){return e.target||e.srcElement}function vo(e){var t=e.which;return null==t&&(1&e.button?t=1:2&e.button?t=3:4&e.button&&(t=2)),xl&&e.ctrlKey&&1==t&&(t=3),t}function mo(e,t){function r(e){return function(){e.apply(null,o)}}var n=e._handlers&&e._handlers[t];if(n){var i,o=Array.prototype.slice.call(arguments,2);Il?i=Il.delayedCallbacks:Ss?i=Ss:(i=Ss=[],setTimeout(yo,0));for(var l=0;l<n.length;++l)i.push(r(n[l]))}}function yo(){var e=Ss;Ss=null;for(var t=0;t<e.length;++t)e[t]()}function bo(e,t,r){return"string"==typeof t&&(t={type:t,preventDefault:function(){this.defaultPrevented=!0}}),Cs(e,r||t.type,e,t),po(t)||t.codemirrorIgnore}function wo(e){var t=e._handlers&&e._handlers.cursorActivity;if(t)for(var r=e.curOp.cursorActivityHandlers||(e.curOp.cursorActivityHandlers=[]),n=0;n<t.length;++n)-1==Mo(r,t[n])&&r.push(t[n])}function xo(e,t){var r=e._handlers&&e._handlers[t];return r&&r.length>0}function Co(e){e.prototype.on=function(e,t){ws(this,e,t)},e.prototype.off=function(e,t){xs(this,e,t)}}function So(){this.id=null}function Lo(e,t,r){for(var n=0,i=0;;){var o=e.indexOf(" ",n);-1==o&&(o=e.length);var l=o-n;if(o==e.length||i+l>=t)return n+Math.min(l,t-i);if(i+=o-n,i+=r-i%r,n=o+1,i>=t)return n}}function ko(e){for(;Ws.length<=e;)Ws.push(To(Ws)+" ");return Ws[e]}function To(e){return e[e.length-1]}function Mo(e,t){for(var r=0;r<e.length;++r)if(e[r]==t)return r;return-1}function Ao(e,t){for(var r=[],n=0;n<e.length;n++)r[n]=t(e[n],n);return r}function No(){}function Wo(e,t){var r;return Object.create?r=Object.create(e):(No.prototype=e,r=new No),t&&Oo(t,r),r}function Oo(e,t,r){t||(t={});for(var n in e)!e.hasOwnProperty(n)||r===!1&&t.hasOwnProperty(n)||(t[n]=e[n]);return t}function Do(e){var t=Array.prototype.slice.call(arguments,1);return function(){return e.apply(null,t)}}function Ho(e,t){return t?t.source.indexOf("\\w")>-1&&Ps(e)?!0:t.test(e):Ps(e)}function Po(e){for(var t in e)if(e.hasOwnProperty(t)&&e[t])return!1;return!0}function Io(e){return e.charCodeAt(0)>=768&&Is.test(e)}function zo(e,t,r,n){var i=document.createElement(e);if(r&&(i.className=r),n&&(i.style.cssText=n),"string"==typeof t)i.appendChild(document.createTextNode(t));else if(t)for(var o=0;o<t.length;++o)i.appendChild(t[o]);return i}function Eo(e){for(var t=e.childNodes.length;t>0;--t)e.removeChild(e.firstChild);return e}function Fo(e,t){return Eo(e).appendChild(t)}function Ro(){return document.activeElement}function Bo(e){return new RegExp("(^|\\s)"+e+"(?:$|\\s)\\s*")}function Go(e,t){for(var r=e.split(" "),n=0;n<r.length;n++)r[n]&&!Bo(r[n]).test(t)&&(t+=" "+r[n]);return t}function Uo(e){if(document.body.getElementsByClassName)for(var t=document.body.getElementsByClassName("CodeMirror"),r=0;r<t.length;r++){var n=t[r].CodeMirror;n&&e(n)}}function Vo(){Gs||(Ko(),Gs=!0)}function Ko(){var e;ws(window,"resize",function(){null==e&&(e=setTimeout(function(){e=null,Uo(Br)},100))}),ws(window,"blur",function(){Uo(fn)})}function jo(e){if(null==Es){var t=zo("span","​");Fo(e,zo("span",[t,document.createTextNode("x")])),0!=e.firstChild.offsetHeight&&(Es=t.offsetWidth<=1&&t.offsetHeight>2&&!(cl&&8>fl))}var r=Es?zo("span","​"):zo("span"," ",null,"display: inline-block; width: 1px; margin-right: -1px");return r.setAttribute("cm-text",""),r}function Xo(e){if(null!=Fs)return Fs;var t=Fo(e,document.createTextNode("AخA")),r=Ds(t,0,1).getBoundingClientRect();if(!r||r.left==r.right)return!1;var n=Ds(t,1,2).getBoundingClientRect();return Fs=n.right-r.right<3}function _o(e){if(null!=Xs)return Xs;var t=Fo(e,zo("span","x")),r=t.getBoundingClientRect(),n=Ds(t,0,1).getBoundingClientRect();return Xs=Math.abs(r.left-n.left)>1}function Yo(e,t,r,n){if(!e)return n(t,r,"ltr");for(var i=!1,o=0;o<e.length;++o){var l=e[o];(l.from<r&&l.to>t||t==r&&l.to==t)&&(n(Math.max(l.from,t),Math.min(l.to,r),1==l.level?"rtl":"ltr"),i=!0)}i||n(t,r,"ltr")}function $o(e){return e.level%2?e.to:e.from}function qo(e){return e.level%2?e.from:e.to}function Zo(e){var t=Zi(e);return t?$o(t[0]):0}function Qo(e){var t=Zi(e);return t?qo(To(t)):e.text.length}function Jo(e,t){var r=Ki(e.doc,t),n=fi(r);n!=r&&(t=Yi(n));var i=Zi(n),o=i?i[0].level%2?Qo(n):Zo(n):0;return Al(t,o)}function el(e,t){for(var r,n=Ki(e.doc,t);r=ui(n);)n=r.find(1,!0).line,t=null;var i=Zi(n),o=i?i[0].level%2?Zo(n):Qo(n):n.text.length;return Al(null==t?Yi(n):t,o)}function tl(e,t){var r=Jo(e,t.line),n=Ki(e.doc,r.line),i=Zi(n);if(!i||0==i[0].level){var o=Math.max(0,n.text.search(/\S/)),l=t.line==r.line&&t.ch<=o&&t.ch;return Al(r.line,l?0:o)}return r}function rl(e,t,r){var n=e[0].level;return t==n?!0:r==n?!1:r>t}function nl(e,t){Ys=null;for(var r,n=0;n<e.length;++n){var i=e[n];if(i.from<t&&i.to>t)return n;if(i.from==t||i.to==t){if(null!=r)return rl(e,i.level,e[r].level)?(i.from!=i.to&&(Ys=r),n):(i.from!=i.to&&(Ys=n),r);r=n}}return r}function il(e,t,r,n){if(!n)return t+r;do t+=r;while(t>0&&Io(e.text.charAt(t)));return t}function ol(e,t,r,n){var i=Zi(e);if(!i)return ll(e,t,r,n);for(var o=nl(i,t),l=i[o],s=il(e,t,l.level%2?-r:r,n);;){if(s>l.from&&s<l.to)return s;if(s==l.from||s==l.to)return nl(i,s)==o?s:(l=i[o+=r],r>0==l.level%2?l.to:l.from);if(l=i[o+=r],!l)return null;s=r>0==l.level%2?il(e,l.to,-1,n):il(e,l.from,1,n)}}function ll(e,t,r,n){var i=t+r;if(n)for(;i>0&&Io(e.text.charAt(i));)i+=r;return 0>i||i>e.text.length?null:i}var sl=/gecko\/\d/i.test(navigator.userAgent),al=/MSIE \d/.test(navigator.userAgent),ul=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),cl=al||ul,fl=cl&&(al?document.documentMode||6:ul[1]),hl=/WebKit\//.test(navigator.userAgent),dl=hl&&/Qt\/\d+\.\d+/.test(navigator.userAgent),pl=/Chrome\//.test(navigator.userAgent),gl=/Opera\//.test(navigator.userAgent),vl=/Apple Computer/.test(navigator.vendor),ml=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent),yl=/PhantomJS/.test(navigator.userAgent),bl=/AppleWebKit/.test(navigator.userAgent)&&/Mobile\/\w+/.test(navigator.userAgent),wl=bl||/Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent),xl=bl||/Mac/.test(navigator.platform),Cl=/win/i.test(navigator.platform),Sl=gl&&navigator.userAgent.match(/Version\/(\d*\.\d*)/);Sl&&(Sl=Number(Sl[1])),Sl&&Sl>=15&&(gl=!1,hl=!0);var Ll=xl&&(dl||gl&&(null==Sl||12.11>Sl)),kl=sl||cl&&fl>=9,Tl=!1,Ml=!1;g.prototype=Oo({update:function(e){var t=e.scrollWidth>e.clientWidth+1,r=e.scrollHeight>e.clientHeight+1,n=e.nativeBarWidth;if(r){this.vert.style.display="block",this.vert.style.bottom=t?n+"px":"0";var i=e.viewHeight-(t?n:0);this.vert.firstChild.style.height=Math.max(0,e.scrollHeight-e.clientHeight+i)+"px"}else this.vert.style.display="",this.vert.firstChild.style.height="0";if(t){this.horiz.style.display="block",this.horiz.style.right=r?n+"px":"0",this.horiz.style.left=e.barLeft+"px";var o=e.viewWidth-e.barLeft-(r?n:0);this.horiz.firstChild.style.width=e.scrollWidth-e.clientWidth+o+"px"}else this.horiz.style.display="",this.horiz.firstChild.style.width="0";return!this.checkedOverlay&&e.clientHeight>0&&(0==n&&this.overlayHack(),this.checkedOverlay=!0),{right:r?n:0,bottom:t?n:0}},setScrollLeft:function(e){this.horiz.scrollLeft!=e&&(this.horiz.scrollLeft=e)},setScrollTop:function(e){this.vert.scrollTop!=e&&(this.vert.scrollTop=e)},overlayHack:function(){var e=xl&&!ml?"12px":"18px";this.horiz.style.minHeight=this.vert.style.minWidth=e;var t=this,r=function(e){go(e)!=t.vert&&go(e)!=t.horiz&&Mr(t.cm,Vr)(e)};ws(this.vert,"mousedown",r),ws(this.horiz,"mousedown",r)},clear:function(){var e=this.horiz.parentNode;e.removeChild(this.horiz),e.removeChild(this.vert)}},g.prototype),v.prototype=Oo({update:function(){return{bottom:0,right:0}},setScrollLeft:function(){},setScrollTop:function(){},clear:function(){}},v.prototype),e.scrollbarModel={"native":g,"null":v},k.prototype.signal=function(e,t){xo(e,t)&&this.events.push(arguments)},k.prototype.finish=function(){for(var e=0;e<this.events.length;e++)Cs.apply(null,this.events[e])};var Al=e.Pos=function(e,t){return this instanceof Al?(this.line=e,void(this.ch=t)):new Al(e,t)},Nl=e.cmpPos=function(e,t){return e.line-t.line||e.ch-t.ch},Wl=null;tt.prototype=Oo({init:function(e){function t(e){if(n.somethingSelected())Wl=n.getSelections(),r.inaccurateSelection&&(r.prevInput="",r.inaccurateSelection=!1,o.value=Wl.join("\n"),Os(o));else{var t=J(n);Wl=t.text,"cut"==e.type?n.setSelections(t.ranges,null,Ts):(r.prevInput="",o.value=t.text.join("\n"),Os(o))}"cut"==e.type&&(n.state.cutIncoming=!0)}var r=this,n=this.cm,i=this.wrapper=rt(),o=this.textarea=i.firstChild;e.wrapper.insertBefore(i,e.wrapper.firstChild),bl&&(o.style.width="0px"),ws(o,"input",function(){cl&&fl>=9&&r.hasSelection&&(r.hasSelection=null),r.poll()}),ws(o,"paste",function(){if(hl&&!n.state.fakedLastChar&&!(new Date-n.state.lastMiddleDown<200)){var e=o.selectionStart,t=o.selectionEnd;o.value+="$",o.selectionEnd=t,o.selectionStart=e,n.state.fakedLastChar=!0}n.state.pasteIncoming=!0,r.fastPoll()}),ws(o,"cut",t),ws(o,"copy",t),ws(e.scroller,"paste",function(t){Gr(e,t)||(n.state.pasteIncoming=!0,r.focus())}),ws(e.lineSpace,"selectstart",function(t){Gr(e,t)||ms(t)})},prepareSelection:function(){var e=this.cm,t=e.display,r=e.doc,n=Dt(e);if(e.options.moveInputWithCursor){var i=cr(e,r.sel.primary().head,"div"),o=t.wrapper.getBoundingClientRect(),l=t.lineDiv.getBoundingClientRect();n.teTop=Math.max(0,Math.min(t.wrapper.clientHeight-10,i.top+l.top-o.top)),n.teLeft=Math.max(0,Math.min(t.wrapper.clientWidth-10,i.left+l.left-o.left))}return n},showSelection:function(e){var t=this.cm,r=t.display;Fo(r.cursorDiv,e.cursors),Fo(r.selectionDiv,e.selection),null!=e.teTop&&(this.wrapper.style.top=e.teTop+"px",this.wrapper.style.left=e.teLeft+"px")},reset:function(e){if(!this.contextMenuPending){var t,r,n=this.cm,i=n.doc;if(n.somethingSelected()){this.prevInput="";var o=i.sel.primary();t=js&&(o.to().line-o.from().line>100||(r=n.getSelection()).length>1e3);var l=t?"-":r||n.getSelection();this.textarea.value=l,n.state.focused&&Os(this.textarea),cl&&fl>=9&&(this.hasSelection=l)}else e||(this.prevInput=this.textarea.value="",cl&&fl>=9&&(this.hasSelection=null));this.inaccurateSelection=t}},getField:function(){return this.textarea},supportsTouch:function(){return!1},focus:function(){if("nocursor"!=this.cm.options.readOnly&&(!wl||Ro()!=this.textarea))try{this.textarea.focus()}catch(e){}},blur:function(){this.textarea.blur()},resetPosition:function(){this.wrapper.style.top=this.wrapper.style.left=0},receivedFocus:function(){this.slowPoll()},slowPoll:function(){var e=this;e.pollingFast||e.polling.set(this.cm.options.pollInterval,function(){e.poll(),e.cm.state.focused&&e.slowPoll()})},fastPoll:function(){function e(){var n=r.poll();n||t?(r.pollingFast=!1,r.slowPoll()):(t=!0,r.polling.set(60,e))}var t=!1,r=this;r.pollingFast=!0,r.polling.set(20,e)},poll:function(){var e=this.cm,t=this.textarea,r=this.prevInput;if(!e.state.focused||Ks(t)&&!r||Z(e)||e.options.disableInput||e.state.keySeq)return!1;e.state.pasteIncoming&&e.state.fakedLastChar&&(t.value=t.value.substring(0,t.value.length-1),e.state.fakedLastChar=!1);var n=t.value;if(n==r&&!e.somethingSelected())return!1;if(cl&&fl>=9&&this.hasSelection===n||xl&&/[\uf700-\uf7ff]/.test(n))return e.display.input.reset(),!1;8203!=n.charCodeAt(0)||e.doc.sel!=e.display.selForContextMenu||r||(r="​");for(var i=0,o=Math.min(r.length,n.length);o>i&&r.charCodeAt(i)==n.charCodeAt(i);)++i;var l=this;return Tr(e,function(){Q(e,n.slice(i),r.length-i),n.length>1e3||n.indexOf("\n")>-1?t.value=l.prevInput="":l.prevInput=n
4
- }),!0},ensurePolled:function(){this.pollingFast&&this.poll()&&(this.pollingFast=!1)},onKeyPress:function(){cl&&fl>=9&&(this.hasSelection=null),this.fastPoll()},onContextMenu:function(e){function t(){if(null!=l.selectionStart){var e=i.somethingSelected(),t=l.value="​"+(e?l.value:"");n.prevInput=e?"":"​",l.selectionStart=1,l.selectionEnd=t.length,o.selForContextMenu=i.doc.sel}}function r(){if(n.contextMenuPending=!1,n.wrapper.style.position="relative",l.style.cssText=c,cl&&9>fl&&o.scrollbars.setScrollTop(o.scroller.scrollTop=a),null!=l.selectionStart){(!cl||cl&&9>fl)&&t();var e=0,r=function(){o.selForContextMenu==i.doc.sel&&0==l.selectionStart?Mr(i,es.selectAll)(i):e++<10?o.detectingSelectAll=setTimeout(r,500):o.input.reset()};o.detectingSelectAll=setTimeout(r,200)}}var n=this,i=n.cm,o=i.display,l=n.textarea,s=Ur(i,e),a=o.scroller.scrollTop;if(s&&!gl){var u=i.options.resetSelectionOnContextMenu;u&&-1==i.doc.sel.contains(s)&&Mr(i,kt)(i.doc,ht(s),Ts);var c=l.style.cssText;if(n.wrapper.style.position="absolute",l.style.cssText="position: fixed; width: 30px; height: 30px; top: "+(e.clientY-5)+"px; left: "+(e.clientX-5)+"px; z-index: 1000; background: "+(cl?"rgba(255, 255, 255, .05)":"transparent")+"; outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);",hl)var f=window.scrollY;if(o.input.focus(),hl&&window.scrollTo(null,f),o.input.reset(),i.somethingSelected()||(l.value=n.prevInput=" "),n.contextMenuPending=!0,o.selForContextMenu=i.doc.sel,clearTimeout(o.detectingSelectAll),cl&&fl>=9&&t(),kl){bs(e);var h=function(){xs(window,"mouseup",h),setTimeout(r,20)};ws(window,"mouseup",h)}else setTimeout(r,50)}},setUneditable:No,needsContentAttribute:!1},tt.prototype),nt.prototype=Oo({init:function(e){function t(e){if(n.somethingSelected())Wl=n.getSelections(),"cut"==e.type&&n.replaceSelection("",null,"cut");else{var t=J(n);Wl=t.text,"cut"==e.type&&n.operation(function(){n.setSelections(t.ranges,0,Ts),n.replaceSelection("",null,"cut")})}if(e.clipboardData&&!bl)e.preventDefault(),e.clipboardData.clearData(),e.clipboardData.setData("text/plain",Wl.join("\n"));else{var r=rt(),i=r.firstChild;n.display.lineSpace.insertBefore(r,n.display.lineSpace.firstChild),i.value=Wl.join("\n");var o=document.activeElement;Os(i),setTimeout(function(){n.display.lineSpace.removeChild(r),o.focus()},50)}}var r=this,n=r.cm,i=r.div=e.lineDiv;i.contentEditable="true",et(i),ws(i,"paste",function(e){var t=e.clipboardData&&e.clipboardData.getData("text/plain");t&&(e.preventDefault(),n.replaceSelection(t,null,"paste"))}),ws(i,"compositionstart",function(e){var t=e.data;if(r.composing={sel:n.doc.sel,data:t,startData:t},t){var i=n.doc.sel.primary(),o=n.getLine(i.head.line),l=o.indexOf(t,Math.max(0,i.head.ch-t.length));l>-1&&l<=i.head.ch&&(r.composing.sel=ht(Al(i.head.line,l),Al(i.head.line,l+t.length)))}}),ws(i,"compositionupdate",function(e){r.composing.data=e.data}),ws(i,"compositionend",function(e){var t=r.composing;t&&(e.data==t.startData||/\u200b/.test(e.data)||(t.data=e.data),setTimeout(function(){t.handled||r.applyComposition(t),r.composing==t&&(r.composing=null)},50))}),ws(i,"touchstart",function(){r.forceCompositionEnd()}),ws(i,"input",function(){r.composing||r.pollContent()||Tr(r.cm,function(){Dr(n)})}),ws(i,"copy",t),ws(i,"cut",t)},prepareSelection:function(){var e=Dt(this.cm,!1);return e.focus=this.cm.state.focused,e},showSelection:function(e){e&&this.cm.display.view.length&&(e.focus&&this.showPrimarySelection(),this.showMultipleSelections(e))},showPrimarySelection:function(){var e=window.getSelection(),t=this.cm.doc.sel.primary(),r=lt(this.cm,e.anchorNode,e.anchorOffset),n=lt(this.cm,e.focusNode,e.focusOffset);if(!r||r.bad||!n||n.bad||0!=Nl($(r,n),t.from())||0!=Nl(Y(r,n),t.to())){var i=it(this.cm,t.from()),o=it(this.cm,t.to());if(i||o){var l=this.cm.display.view,s=e.rangeCount&&e.getRangeAt(0);if(i){if(!o){var a=l[l.length-1].measure,u=a.maps?a.maps[a.maps.length-1]:a.map;o={node:u[u.length-1],offset:u[u.length-2]-u[u.length-3]}}}else i={node:l[0].measure.map[2],offset:0};try{var c=Ds(i.node,i.offset,o.offset,o.node)}catch(f){}c&&(e.removeAllRanges(),e.addRange(c),s&&null==e.anchorNode?e.addRange(s):sl&&this.startGracePeriod()),this.rememberSelection()}}},startGracePeriod:function(){var e=this;clearTimeout(this.gracePeriod),this.gracePeriod=setTimeout(function(){e.gracePeriod=!1,e.selectionChanged()&&e.cm.operation(function(){e.cm.curOp.selectionChanged=!0})},20)},showMultipleSelections:function(e){Fo(this.cm.display.cursorDiv,e.cursors),Fo(this.cm.display.selectionDiv,e.selection)},rememberSelection:function(){var e=window.getSelection();this.lastAnchorNode=e.anchorNode,this.lastAnchorOffset=e.anchorOffset,this.lastFocusNode=e.focusNode,this.lastFocusOffset=e.focusOffset},selectionInEditor:function(){var e=window.getSelection();if(!e.rangeCount)return!1;var t=e.getRangeAt(0).commonAncestorContainer;return zs(this.div,t)},focus:function(){"nocursor"!=this.cm.options.readOnly&&this.div.focus()},blur:function(){this.div.blur()},getField:function(){return this.div},supportsTouch:function(){return!0},receivedFocus:function(){function e(){t.cm.state.focused&&(t.pollSelection(),t.polling.set(t.cm.options.pollInterval,e))}var t=this;this.selectionInEditor()?this.pollSelection():Tr(this.cm,function(){t.cm.curOp.selectionChanged=!0}),this.polling.set(this.cm.options.pollInterval,e)},selectionChanged:function(){var e=window.getSelection();return e.anchorNode!=this.lastAnchorNode||e.anchorOffset!=this.lastAnchorOffset||e.focusNode!=this.lastFocusNode||e.focusOffset!=this.lastFocusOffset},pollSelection:function(){if(!this.composing&&!this.gracePeriod&&this.selectionChanged()){var e=window.getSelection(),t=this.cm;this.rememberSelection();var r=lt(t,e.anchorNode,e.anchorOffset),n=lt(t,e.focusNode,e.focusOffset);r&&n&&Tr(t,function(){kt(t.doc,ht(r,n),Ts),(r.bad||n.bad)&&(t.curOp.selectionChanged=!0)})}},pollContent:function(){var e=this.cm,t=e.display,r=e.doc.sel.primary(),n=r.from(),i=r.to();if(n.line<t.viewFrom||i.line>t.viewTo-1)return!1;var o;if(n.line==t.viewFrom||0==(o=Ir(e,n.line)))var l=Yi(t.view[0].line),s=t.view[0].node;else var l=Yi(t.view[o].line),s=t.view[o-1].node.nextSibling;var a=Ir(e,i.line);if(a==t.view.length-1)var u=t.viewTo-1,c=t.view[a].node;else var u=Yi(t.view[a+1].line)-1,c=t.view[a+1].node.previousSibling;for(var f=Vs(at(e,s,c,l,u)),h=ji(e.doc,Al(l,0),Al(u,Ki(e.doc,u).text.length));f.length>1&&h.length>1;)if(To(f)==To(h))f.pop(),h.pop(),u--;else{if(f[0]!=h[0])break;f.shift(),h.shift(),l++}for(var d=0,p=0,g=f[0],v=h[0],m=Math.min(g.length,v.length);m>d&&g.charCodeAt(d)==v.charCodeAt(d);)++d;for(var y=To(f),b=To(h),w=Math.min(y.length-(1==f.length?d:0),b.length-(1==h.length?d:0));w>p&&y.charCodeAt(y.length-p-1)==b.charCodeAt(b.length-p-1);)++p;f[f.length-1]=y.slice(0,y.length-p),f[0]=f[0].slice(d);var x=Al(l,d),C=Al(u,h.length?To(h).length-p:0);return f.length>1||f[0]||Nl(x,C)?(kn(e.doc,f,x,C,"+input"),!0):void 0},ensurePolled:function(){this.forceCompositionEnd()},reset:function(){this.forceCompositionEnd()},forceCompositionEnd:function(){this.composing&&!this.composing.handled&&(this.applyComposition(this.composing),this.composing.handled=!0,this.div.blur(),this.div.focus())},applyComposition:function(e){e.data&&e.data!=e.startData&&Mr(this.cm,Q)(this.cm,e.data,0,e.sel)},setUneditable:function(e){e.setAttribute("contenteditable","false")},onKeyPress:function(e){e.preventDefault(),Mr(this.cm,Q)(this.cm,String.fromCharCode(null==e.charCode?e.keyCode:e.charCode),0)},onContextMenu:No,resetPosition:No,needsContentAttribute:!0},nt.prototype),e.inputStyles={textarea:tt,contenteditable:nt},ut.prototype={primary:function(){return this.ranges[this.primIndex]},equals:function(e){if(e==this)return!0;if(e.primIndex!=this.primIndex||e.ranges.length!=this.ranges.length)return!1;for(var t=0;t<this.ranges.length;t++){var r=this.ranges[t],n=e.ranges[t];if(0!=Nl(r.anchor,n.anchor)||0!=Nl(r.head,n.head))return!1}return!0},deepCopy:function(){for(var e=[],t=0;t<this.ranges.length;t++)e[t]=new ct(_(this.ranges[t].anchor),_(this.ranges[t].head));return new ut(e,this.primIndex)},somethingSelected:function(){for(var e=0;e<this.ranges.length;e++)if(!this.ranges[e].empty())return!0;return!1},contains:function(e,t){t||(t=e);for(var r=0;r<this.ranges.length;r++){var n=this.ranges[r];if(Nl(t,n.from())>=0&&Nl(e,n.to())<=0)return r}return-1}},ct.prototype={from:function(){return $(this.anchor,this.head)},to:function(){return Y(this.anchor,this.head)},empty:function(){return this.head.line==this.anchor.line&&this.head.ch==this.anchor.ch}};var Ol,Dl,Hl,Pl={left:0,right:0,top:0,bottom:0},Il=null,zl=0,El=0,Fl=0,Rl=null;cl?Rl=-.53:sl?Rl=15:pl?Rl=-.7:vl&&(Rl=-1/3);var Bl=function(e){var t=e.wheelDeltaX,r=e.wheelDeltaY;return null==t&&e.detail&&e.axis==e.HORIZONTAL_AXIS&&(t=e.detail),null==r&&e.detail&&e.axis==e.VERTICAL_AXIS?r=e.detail:null==r&&(r=e.wheelDelta),{x:t,y:r}};e.wheelEventPixels=function(e){var t=Bl(e);return t.x*=Rl,t.y*=Rl,t};var Gl=new So,Ul=null,Vl=e.changeEnd=function(e){return e.text?Al(e.from.line+e.text.length-1,To(e.text).length+(1==e.text.length?e.from.ch:0)):e.to};e.prototype={constructor:e,focus:function(){window.focus(),this.display.input.focus()},setOption:function(e,t){var r=this.options,n=r[e];(r[e]!=t||"mode"==e)&&(r[e]=t,jl.hasOwnProperty(e)&&Mr(this,jl[e])(this,t,n))},getOption:function(e){return this.options[e]},getDoc:function(){return this.doc},addKeyMap:function(e,t){this.state.keyMaps[t?"push":"unshift"](Bn(e))},removeKeyMap:function(e){for(var t=this.state.keyMaps,r=0;r<t.length;++r)if(t[r]==e||t[r].name==e)return t.splice(r,1),!0},addOverlay:Ar(function(t,r){var n=t.token?t:e.getMode(this.options,t);if(n.startState)throw new Error("Overlays may not be stateful.");this.state.overlays.push({mode:n,modeSpec:t,opaque:r&&r.opaque}),this.state.modeGen++,Dr(this)}),removeOverlay:Ar(function(e){for(var t=this.state.overlays,r=0;r<t.length;++r){var n=t[r].modeSpec;if(n==e||"string"==typeof e&&n.name==e)return t.splice(r,1),this.state.modeGen++,void Dr(this)}}),indentLine:Ar(function(e,t,r){"string"!=typeof t&&"number"!=typeof t&&(t=null==t?this.options.smartIndent?"smart":"prev":t?"add":"subtract"),vt(this.doc,e)&&Hn(this,e,t,r)}),indentSelection:Ar(function(e){for(var t=this.doc.sel.ranges,r=-1,n=0;n<t.length;n++){var i=t[n];if(i.empty())i.head.line>r&&(Hn(this,i.head.line,e,!0),r=i.head.line,n==this.doc.sel.primIndex&&On(this));else{var o=i.from(),l=i.to(),s=Math.max(r,o.line);r=Math.min(this.lastLine(),l.line-(l.ch?0:1))+1;for(var a=s;r>a;++a)Hn(this,a,e);var u=this.doc.sel.ranges;0==o.ch&&t.length==u.length&&u[n].from().ch>0&&xt(this.doc,n,new ct(o,u[n].to()),Ts)}}}),getTokenAt:function(e,t){return ki(this,e,t)},getLineTokens:function(e,t){return ki(this,Al(e),t,!0)},getTokenTypeAt:function(e){e=pt(this.doc,e);var t,r=Ai(this,Ki(this.doc,e.line)),n=0,i=(r.length-1)/2,o=e.ch;if(0==o)t=r[2];else for(;;){var l=n+i>>1;if((l?r[2*l-1]:0)>=o)i=l;else{if(!(r[2*l+1]<o)){t=r[2*l+2];break}n=l+1}}var s=t?t.indexOf("cm-overlay "):-1;return 0>s?t:0==s?null:t.slice(0,s-1)},getModeAt:function(t){var r=this.doc.mode;return r.innerMode?e.innerMode(r,this.getTokenAt(t).state).mode:r},getHelper:function(e,t){return this.getHelpers(e,t)[0]},getHelpers:function(e,t){var r=[];if(!Zl.hasOwnProperty(t))return r;var n=Zl[t],i=this.getModeAt(e);if("string"==typeof i[t])n[i[t]]&&r.push(n[i[t]]);else if(i[t])for(var o=0;o<i[t].length;o++){var l=n[i[t][o]];l&&r.push(l)}else i.helperType&&n[i.helperType]?r.push(n[i.helperType]):n[i.name]&&r.push(n[i.name]);for(var o=0;o<n._global.length;o++){var s=n._global[o];s.pred(i,this)&&-1==Mo(r,s.val)&&r.push(s.val)}return r},getStateAfter:function(e,t){var r=this.doc;return e=dt(r,null==e?r.first+r.size-1:e),Rt(this,e+1,t)},cursorCoords:function(e,t){var r,n=this.doc.sel.primary();return r=null==e?n.head:"object"==typeof e?pt(this.doc,e):e?n.from():n.to(),cr(this,r,t||"page")},charCoords:function(e,t){return ur(this,pt(this.doc,e),t||"page")},coordsChar:function(e,t){return e=ar(this,e,t||"page"),dr(this,e.left,e.top)},lineAtHeight:function(e,t){return e=ar(this,{top:e,left:0},t||"page").top,$i(this.doc,e+this.display.viewOffset)},heightAtLine:function(e,t){var r=!1,n=this.doc.first+this.doc.size-1;e<this.doc.first?e=this.doc.first:e>n&&(e=n,r=!0);var i=Ki(this.doc,e);return sr(this,i,{top:0,left:0},t||"page").top+(r?this.doc.height-qi(i):0)},defaultTextHeight:function(){return gr(this.display)},defaultCharWidth:function(){return vr(this.display)},setGutterMarker:Ar(function(e,t,r){return Pn(this.doc,e,"gutter",function(e){var n=e.gutterMarkers||(e.gutterMarkers={});return n[t]=r,!r&&Po(n)&&(e.gutterMarkers=null),!0})}),clearGutter:Ar(function(e){var t=this,r=t.doc,n=r.first;r.iter(function(r){r.gutterMarkers&&r.gutterMarkers[e]&&(r.gutterMarkers[e]=null,Hr(t,n,"gutter"),Po(r.gutterMarkers)&&(r.gutterMarkers=null)),++n})}),addLineWidget:Ar(function(e,t,r){return bi(this,e,t,r)}),removeLineWidget:function(e){e.clear()},lineInfo:function(e){if("number"==typeof e){if(!vt(this.doc,e))return null;var t=e;if(e=Ki(this.doc,e),!e)return null}else{var t=Yi(e);if(null==t)return null}return{line:t,handle:e,text:e.text,gutterMarkers:e.gutterMarkers,textClass:e.textClass,bgClass:e.bgClass,wrapClass:e.wrapClass,widgets:e.widgets}},getViewport:function(){return{from:this.display.viewFrom,to:this.display.viewTo}},addWidget:function(e,t,r,n,i){var o=this.display;e=cr(this,pt(this.doc,e));var l=e.bottom,s=e.left;if(t.style.position="absolute",t.setAttribute("cm-ignore-events","true"),this.display.input.setUneditable(t),o.sizer.appendChild(t),"over"==n)l=e.top;else if("above"==n||"near"==n){var a=Math.max(o.wrapper.clientHeight,this.doc.height),u=Math.max(o.sizer.clientWidth,o.lineSpace.clientWidth);("above"==n||e.bottom+t.offsetHeight>a)&&e.top>t.offsetHeight?l=e.top-t.offsetHeight:e.bottom+t.offsetHeight<=a&&(l=e.bottom),s+t.offsetWidth>u&&(s=u-t.offsetWidth)}t.style.top=l+"px",t.style.left=t.style.right="","right"==i?(s=o.sizer.clientWidth-t.offsetWidth,t.style.right="0px"):("left"==i?s=0:"middle"==i&&(s=(o.sizer.clientWidth-t.offsetWidth)/2),t.style.left=s+"px"),r&&An(this,s,l,s+t.offsetWidth,l+t.offsetHeight)},triggerOnKeyDown:Ar(ln),triggerOnKeyPress:Ar(un),triggerOnKeyUp:an,execCommand:function(e){return es.hasOwnProperty(e)?es[e](this):void 0},findPosH:function(e,t,r,n){var i=1;0>t&&(i=-1,t=-t);for(var o=0,l=pt(this.doc,e);t>o&&(l=zn(this.doc,l,i,r,n),!l.hitSide);++o);return l},moveH:Ar(function(e,t){var r=this;r.extendSelectionsBy(function(n){return r.display.shift||r.doc.extend||n.empty()?zn(r.doc,n.head,e,t,r.options.rtlMoveVisually):0>e?n.from():n.to()},As)}),deleteH:Ar(function(e,t){var r=this.doc.sel,n=this.doc;r.somethingSelected()?n.replaceSelection("",null,"+delete"):In(this,function(r){var i=zn(n,r.head,e,t,!1);return 0>e?{from:i,to:r.head}:{from:r.head,to:i}})}),findPosV:function(e,t,r,n){var i=1,o=n;0>t&&(i=-1,t=-t);for(var l=0,s=pt(this.doc,e);t>l;++l){var a=cr(this,s,"div");if(null==o?o=a.left:a.left=o,s=En(this,a,i,r),s.hitSide)break}return s},moveV:Ar(function(e,t){var r=this,n=this.doc,i=[],o=!r.display.shift&&!n.extend&&n.sel.somethingSelected();if(n.extendSelectionsBy(function(l){if(o)return 0>e?l.from():l.to();var s=cr(r,l.head,"div");null!=l.goalColumn&&(s.left=l.goalColumn),i.push(s.left);var a=En(r,s,e,t);return"page"==t&&l==n.sel.primary()&&Wn(r,null,ur(r,a,"div").top-s.top),a},As),i.length)for(var l=0;l<n.sel.ranges.length;l++)n.sel.ranges[l].goalColumn=i[l]}),findWordAt:function(e){var t=this.doc,r=Ki(t,e.line).text,n=e.ch,i=e.ch;if(r){var o=this.getHelper(e,"wordChars");(e.xRel<0||i==r.length)&&n?--n:++i;for(var l=r.charAt(n),s=Ho(l,o)?function(e){return Ho(e,o)}:/\s/.test(l)?function(e){return/\s/.test(e)}:function(e){return!/\s/.test(e)&&!Ho(e)};n>0&&s(r.charAt(n-1));)--n;for(;i<r.length&&s(r.charAt(i));)++i}return new ct(Al(e.line,n),Al(e.line,i))},toggleOverwrite:function(e){(null==e||e!=this.state.overwrite)&&((this.state.overwrite=!this.state.overwrite)?Bs(this.display.cursorDiv,"CodeMirror-overwrite"):Rs(this.display.cursorDiv,"CodeMirror-overwrite"),Cs(this,"overwriteToggle",this,this.state.overwrite))},hasFocus:function(){return this.display.input.getField()==Ro()},scrollTo:Ar(function(e,t){(null!=e||null!=t)&&Dn(this),null!=e&&(this.curOp.scrollLeft=e),null!=t&&(this.curOp.scrollTop=t)}),getScrollInfo:function(){var e=this.display.scroller;return{left:e.scrollLeft,top:e.scrollTop,height:e.scrollHeight-Vt(this)-this.display.barHeight,width:e.scrollWidth-Vt(this)-this.display.barWidth,clientHeight:jt(this),clientWidth:Kt(this)}},scrollIntoView:Ar(function(e,t){if(null==e?(e={from:this.doc.sel.primary().head,to:null},null==t&&(t=this.options.cursorScrollMargin)):"number"==typeof e?e={from:Al(e,0),to:null}:null==e.from&&(e={from:e,to:null}),e.to||(e.to=e.from),e.margin=t||0,null!=e.from.line)Dn(this),this.curOp.scrollToPos=e;else{var r=Nn(this,Math.min(e.from.left,e.to.left),Math.min(e.from.top,e.to.top)-e.margin,Math.max(e.from.right,e.to.right),Math.max(e.from.bottom,e.to.bottom)+e.margin);this.scrollTo(r.scrollLeft,r.scrollTop)}}),setSize:Ar(function(e,t){function r(e){return"number"==typeof e||/^\d+$/.test(String(e))?e+"px":e}var n=this;null!=e&&(n.display.wrapper.style.width=r(e)),null!=t&&(n.display.wrapper.style.height=r(t)),n.options.lineWrapping&&nr(this);var i=n.display.viewFrom;n.doc.iter(i,n.display.viewTo,function(e){if(e.widgets)for(var t=0;t<e.widgets.length;t++)if(e.widgets[t].noHScroll){Hr(n,i,"widget");break}++i}),n.curOp.forceUpdate=!0,Cs(n,"refresh",this)}),operation:function(e){return Tr(this,e)},refresh:Ar(function(){var e=this.display.cachedTextHeight;Dr(this),this.curOp.forceUpdate=!0,ir(this),this.scrollTo(this.doc.scrollLeft,this.doc.scrollTop),c(this),(null==e||Math.abs(e-gr(this.display))>.5)&&l(this),Cs(this,"refresh",this)}),swapDoc:Ar(function(e){var t=this.doc;return t.cm=null,Vi(this,e),ir(this),this.display.input.reset(),this.scrollTo(e.scrollLeft,e.scrollTop),this.curOp.forceScroll=!0,mo(this,"swapDoc",this,t),t}),getInputField:function(){return this.display.input.getField()},getWrapperElement:function(){return this.display.wrapper},getScrollerElement:function(){return this.display.scroller},getGutterElement:function(){return this.display.gutters}},Co(e);var Kl=e.defaults={},jl=e.optionHandlers={},Xl=e.Init={toString:function(){return"CodeMirror.Init"}};Fn("value","",function(e,t){e.setValue(t)},!0),Fn("mode",null,function(e,t){e.doc.modeOption=t,r(e)},!0),Fn("indentUnit",2,r,!0),Fn("indentWithTabs",!1),Fn("smartIndent",!0),Fn("tabSize",4,function(e){n(e),ir(e),Dr(e)},!0),Fn("specialChars",/[\t\u0000-\u0019\u00ad\u200b-\u200f\u2028\u2029\ufeff]/g,function(t,r,n){t.state.specialChars=new RegExp(r.source+(r.test(" ")?"":"| "),"g"),n!=e.Init&&t.refresh()}),Fn("specialCharPlaceholder",Di,function(e){e.refresh()},!0),Fn("electricChars",!0),Fn("inputStyle",wl?"contenteditable":"textarea",function(){throw new Error("inputStyle can not (yet) be changed in a running editor")},!0),Fn("rtlMoveVisually",!Cl),Fn("wholeLineUpdateBefore",!0),Fn("theme","default",function(e){s(e),a(e)},!0),Fn("keyMap","default",function(t,r,n){var i=Bn(r),o=n!=e.Init&&Bn(n);o&&o.detach&&o.detach(t,i),i.attach&&i.attach(t,o||null)}),Fn("extraKeys",null),Fn("lineWrapping",!1,i,!0),Fn("gutters",[],function(e){d(e.options),a(e)},!0),Fn("fixedGutter",!0,function(e,t){e.display.gutters.style.left=t?L(e.display)+"px":"0",e.refresh()},!0),Fn("coverGutterNextToScrollbar",!1,function(e){y(e)},!0),Fn("scrollbarStyle","native",function(e){m(e),y(e),e.display.scrollbars.setScrollTop(e.doc.scrollTop),e.display.scrollbars.setScrollLeft(e.doc.scrollLeft)},!0),Fn("lineNumbers",!1,function(e){d(e.options),a(e)},!0),Fn("firstLineNumber",1,a,!0),Fn("lineNumberFormatter",function(e){return e},a,!0),Fn("showCursorWhenSelecting",!1,Ot,!0),Fn("resetSelectionOnContextMenu",!0),Fn("readOnly",!1,function(e,t){"nocursor"==t?(fn(e),e.display.input.blur(),e.display.disabled=!0):(e.display.disabled=!1,t||e.display.input.reset())}),Fn("disableInput",!1,function(e,t){t||e.display.input.reset()},!0),Fn("dragDrop",!0),Fn("cursorBlinkRate",530),Fn("cursorScrollMargin",0),Fn("cursorHeight",1,Ot,!0),Fn("singleCursorHeightPerLine",!0,Ot,!0),Fn("workTime",100),Fn("workDelay",100),Fn("flattenSpans",!0,n,!0),Fn("addModeClass",!1,n,!0),Fn("pollInterval",100),Fn("undoDepth",200,function(e,t){e.doc.history.undoDepth=t}),Fn("historyEventDelay",1250),Fn("viewportMargin",10,function(e){e.refresh()},!0),Fn("maxHighlightLength",1e4,n,!0),Fn("moveInputWithCursor",!0,function(e,t){t||e.display.input.resetPosition()}),Fn("tabindex",null,function(e,t){e.display.input.getField().tabIndex=t||""}),Fn("autofocus",null);var _l=e.modes={},Yl=e.mimeModes={};e.defineMode=function(t,r){e.defaults.mode||"null"==t||(e.defaults.mode=t),arguments.length>2&&(r.dependencies=Array.prototype.slice.call(arguments,2)),_l[t]=r},e.defineMIME=function(e,t){Yl[e]=t},e.resolveMode=function(t){if("string"==typeof t&&Yl.hasOwnProperty(t))t=Yl[t];else if(t&&"string"==typeof t.name&&Yl.hasOwnProperty(t.name)){var r=Yl[t.name];"string"==typeof r&&(r={name:r}),t=Wo(r,t),t.name=r.name}else if("string"==typeof t&&/^[\w\-]+\/[\w\-]+\+xml$/.test(t))return e.resolveMode("application/xml");return"string"==typeof t?{name:t}:t||{name:"null"}},e.getMode=function(t,r){var r=e.resolveMode(r),n=_l[r.name];if(!n)return e.getMode(t,"text/plain");var i=n(t,r);if($l.hasOwnProperty(r.name)){var o=$l[r.name];for(var l in o)o.hasOwnProperty(l)&&(i.hasOwnProperty(l)&&(i["_"+l]=i[l]),i[l]=o[l])}if(i.name=r.name,r.helperType&&(i.helperType=r.helperType),r.modeProps)for(var l in r.modeProps)i[l]=r.modeProps[l];return i},e.defineMode("null",function(){return{token:function(e){e.skipToEnd()}}}),e.defineMIME("text/plain","null");var $l=e.modeExtensions={};e.extendMode=function(e,t){var r=$l.hasOwnProperty(e)?$l[e]:$l[e]={};Oo(t,r)},e.defineExtension=function(t,r){e.prototype[t]=r},e.defineDocExtension=function(e,t){ps.prototype[e]=t},e.defineOption=Fn;var ql=[];e.defineInitHook=function(e){ql.push(e)};var Zl=e.helpers={};e.registerHelper=function(t,r,n){Zl.hasOwnProperty(t)||(Zl[t]=e[t]={_global:[]}),Zl[t][r]=n},e.registerGlobalHelper=function(t,r,n,i){e.registerHelper(t,r,i),Zl[t]._global.push({pred:n,val:i})};var Ql=e.copyState=function(e,t){if(t===!0)return t;if(e.copyState)return e.copyState(t);var r={};for(var n in t){var i=t[n];i instanceof Array&&(i=i.concat([])),r[n]=i}return r},Jl=e.startState=function(e,t,r){return e.startState?e.startState(t,r):!0};e.innerMode=function(e,t){for(;e.innerMode;){var r=e.innerMode(t);if(!r||r.mode==e)break;t=r.state,e=r.mode}return r||{mode:e,state:t}};var es=e.commands={selectAll:function(e){e.setSelection(Al(e.firstLine(),0),Al(e.lastLine()),Ts)},singleSelection:function(e){e.setSelection(e.getCursor("anchor"),e.getCursor("head"),Ts)},killLine:function(e){In(e,function(t){if(t.empty()){var r=Ki(e.doc,t.head.line).text.length;return t.head.ch==r&&t.head.line<e.lastLine()?{from:t.head,to:Al(t.head.line+1,0)}:{from:t.head,to:Al(t.head.line,r)}}return{from:t.from(),to:t.to()}})},deleteLine:function(e){In(e,function(t){return{from:Al(t.from().line,0),to:pt(e.doc,Al(t.to().line+1,0))}})},delLineLeft:function(e){In(e,function(e){return{from:Al(e.from().line,0),to:e.from()}})},delWrappedLineLeft:function(e){In(e,function(t){var r=e.charCoords(t.head,"div").top+5,n=e.coordsChar({left:0,top:r},"div");return{from:n,to:t.from()}})},delWrappedLineRight:function(e){In(e,function(t){var r=e.charCoords(t.head,"div").top+5,n=e.coordsChar({left:e.display.lineDiv.offsetWidth+100,top:r},"div");return{from:t.from(),to:n}})},undo:function(e){e.undo()},redo:function(e){e.redo()},undoSelection:function(e){e.undoSelection()},redoSelection:function(e){e.redoSelection()},goDocStart:function(e){e.extendSelection(Al(e.firstLine(),0))},goDocEnd:function(e){e.extendSelection(Al(e.lastLine()))},goLineStart:function(e){e.extendSelectionsBy(function(t){return Jo(e,t.head.line)},{origin:"+move",bias:1})},goLineStartSmart:function(e){e.extendSelectionsBy(function(t){return tl(e,t.head)},{origin:"+move",bias:1})},goLineEnd:function(e){e.extendSelectionsBy(function(t){return el(e,t.head.line)},{origin:"+move",bias:-1})},goLineRight:function(e){e.extendSelectionsBy(function(t){var r=e.charCoords(t.head,"div").top+5;return e.coordsChar({left:e.display.lineDiv.offsetWidth+100,top:r},"div")},As)},goLineLeft:function(e){e.extendSelectionsBy(function(t){var r=e.charCoords(t.head,"div").top+5;return e.coordsChar({left:0,top:r},"div")},As)},goLineLeftSmart:function(e){e.extendSelectionsBy(function(t){var r=e.charCoords(t.head,"div").top+5,n=e.coordsChar({left:0,top:r},"div");return n.ch<e.getLine(n.line).search(/\S/)?tl(e,t.head):n},As)},goLineUp:function(e){e.moveV(-1,"line")},goLineDown:function(e){e.moveV(1,"line")},goPageUp:function(e){e.moveV(-1,"page")},goPageDown:function(e){e.moveV(1,"page")},goCharLeft:function(e){e.moveH(-1,"char")},goCharRight:function(e){e.moveH(1,"char")},goColumnLeft:function(e){e.moveH(-1,"column")},goColumnRight:function(e){e.moveH(1,"column")},goWordLeft:function(e){e.moveH(-1,"word")},goGroupRight:function(e){e.moveH(1,"group")},goGroupLeft:function(e){e.moveH(-1,"group")},goWordRight:function(e){e.moveH(1,"word")},delCharBefore:function(e){e.deleteH(-1,"char")},delCharAfter:function(e){e.deleteH(1,"char")},delWordBefore:function(e){e.deleteH(-1,"word")},delWordAfter:function(e){e.deleteH(1,"word")},delGroupBefore:function(e){e.deleteH(-1,"group")},delGroupAfter:function(e){e.deleteH(1,"group")},indentAuto:function(e){e.indentSelection("smart")},indentMore:function(e){e.indentSelection("add")},indentLess:function(e){e.indentSelection("subtract")},insertTab:function(e){e.replaceSelection(" ")},insertSoftTab:function(e){for(var t=[],r=e.listSelections(),n=e.options.tabSize,i=0;i<r.length;i++){var o=r[i].from(),l=Ns(e.getLine(o.line),o.ch,n);t.push(new Array(n-l%n+1).join(" "))}e.replaceSelections(t)},defaultTab:function(e){e.somethingSelected()?e.indentSelection("add"):e.execCommand("insertTab")},transposeChars:function(e){Tr(e,function(){for(var t=e.listSelections(),r=[],n=0;n<t.length;n++){var i=t[n].head,o=Ki(e.doc,i.line).text;if(o)if(i.ch==o.length&&(i=new Al(i.line,i.ch-1)),i.ch>0)i=new Al(i.line,i.ch+1),e.replaceRange(o.charAt(i.ch-1)+o.charAt(i.ch-2),Al(i.line,i.ch-2),i,"+transpose");else if(i.line>e.doc.first){var l=Ki(e.doc,i.line-1).text;l&&e.replaceRange(o.charAt(0)+"\n"+l.charAt(l.length-1),Al(i.line-1,l.length-1),Al(i.line,1),"+transpose")}r.push(new ct(i,i))}e.setSelections(r)})},newlineAndIndent:function(e){Tr(e,function(){for(var t=e.listSelections().length,r=0;t>r;r++){var n=e.listSelections()[r];e.replaceRange("\n",n.anchor,n.head,"+input"),e.indentLine(n.from().line+1,null,!0),On(e)}})},toggleOverwrite:function(e){e.toggleOverwrite()}},ts=e.keyMap={};ts.basic={Left:"goCharLeft",Right:"goCharRight",Up:"goLineUp",Down:"goLineDown",End:"goLineEnd",Home:"goLineStartSmart",PageUp:"goPageUp",PageDown:"goPageDown",Delete:"delCharAfter",Backspace:"delCharBefore","Shift-Backspace":"delCharBefore",Tab:"defaultTab","Shift-Tab":"indentAuto",Enter:"newlineAndIndent",Insert:"toggleOverwrite",Esc:"singleSelection"},ts.pcDefault={"Ctrl-A":"selectAll","Ctrl-D":"deleteLine","Ctrl-Z":"undo","Shift-Ctrl-Z":"redo","Ctrl-Y":"redo","Ctrl-Home":"goDocStart","Ctrl-End":"goDocEnd","Ctrl-Up":"goLineUp","Ctrl-Down":"goLineDown","Ctrl-Left":"goGroupLeft","Ctrl-Right":"goGroupRight","Alt-Left":"goLineStart","Alt-Right":"goLineEnd","Ctrl-Backspace":"delGroupBefore","Ctrl-Delete":"delGroupAfter","Ctrl-S":"save","Ctrl-F":"find","Ctrl-G":"findNext","Shift-Ctrl-G":"findPrev","Shift-Ctrl-F":"replace","Shift-Ctrl-R":"replaceAll","Ctrl-[":"indentLess","Ctrl-]":"indentMore","Ctrl-U":"undoSelection","Shift-Ctrl-U":"redoSelection","Alt-U":"redoSelection",fallthrough:"basic"},ts.emacsy={"Ctrl-F":"goCharRight","Ctrl-B":"goCharLeft","Ctrl-P":"goLineUp","Ctrl-N":"goLineDown","Alt-F":"goWordRight","Alt-B":"goWordLeft","Ctrl-A":"goLineStart","Ctrl-E":"goLineEnd","Ctrl-V":"goPageDown","Shift-Ctrl-V":"goPageUp","Ctrl-D":"delCharAfter","Ctrl-H":"delCharBefore","Alt-D":"delWordAfter","Alt-Backspace":"delWordBefore","Ctrl-K":"killLine","Ctrl-T":"transposeChars"},ts.macDefault={"Cmd-A":"selectAll","Cmd-D":"deleteLine","Cmd-Z":"undo","Shift-Cmd-Z":"redo","Cmd-Y":"redo","Cmd-Home":"goDocStart","Cmd-Up":"goDocStart","Cmd-End":"goDocEnd","Cmd-Down":"goDocEnd","Alt-Left":"goGroupLeft","Alt-Right":"goGroupRight","Cmd-Left":"goLineLeft","Cmd-Right":"goLineRight","Alt-Backspace":"delGroupBefore","Ctrl-Alt-Backspace":"delGroupAfter","Alt-Delete":"delGroupAfter","Cmd-S":"save","Cmd-F":"find","Cmd-G":"findNext","Shift-Cmd-G":"findPrev","Cmd-Alt-F":"replace","Shift-Cmd-Alt-F":"replaceAll","Cmd-[":"indentLess","Cmd-]":"indentMore","Cmd-Backspace":"delWrappedLineLeft","Cmd-Delete":"delWrappedLineRight","Cmd-U":"undoSelection","Shift-Cmd-U":"redoSelection","Ctrl-Up":"goDocStart","Ctrl-Down":"goDocEnd",fallthrough:["basic","emacsy"]},ts["default"]=xl?ts.macDefault:ts.pcDefault,e.normalizeKeyMap=function(e){var t={};for(var r in e)if(e.hasOwnProperty(r)){var n=e[r];if(/^(name|fallthrough|(de|at)tach)$/.test(r))continue;if("..."==n){delete e[r];continue}for(var i=Ao(r.split(" "),Rn),o=0;o<i.length;o++){var l,s;o==i.length-1?(s=r,l=n):(s=i.slice(0,o+1).join(" "),l="...");var a=t[s];if(a){if(a!=l)throw new Error("Inconsistent bindings for "+s)}else t[s]=l}delete e[r]}for(var u in t)e[u]=t[u];return e};var rs=e.lookupKey=function(e,t,r,n){t=Bn(t);var i=t.call?t.call(e,n):t[e];if(i===!1)return"nothing";if("..."===i)return"multi";if(null!=i&&r(i))return"handled";if(t.fallthrough){if("[object Array]"!=Object.prototype.toString.call(t.fallthrough))return rs(e,t.fallthrough,r,n);for(var o=0;o<t.fallthrough.length;o++){var l=rs(e,t.fallthrough[o],r,n);if(l)return l}}},ns=e.isModifierKey=function(e){var t="string"==typeof e?e:_s[e.keyCode];return"Ctrl"==t||"Alt"==t||"Shift"==t||"Mod"==t},is=e.keyName=function(e,t){if(gl&&34==e.keyCode&&e["char"])return!1;var r=_s[e.keyCode],n=r;return null==n||e.altGraphKey?!1:(e.altKey&&"Alt"!=r&&(n="Alt-"+n),(Ll?e.metaKey:e.ctrlKey)&&"Ctrl"!=r&&(n="Ctrl-"+n),(Ll?e.ctrlKey:e.metaKey)&&"Cmd"!=r&&(n="Cmd-"+n),!t&&e.shiftKey&&"Shift"!=r&&(n="Shift-"+n),n)};e.fromTextArea=function(t,r){function n(){t.value=u.getValue()}if(r=r?Oo(r):{},r.value=t.value,!r.tabindex&&t.tabIndex&&(r.tabindex=t.tabIndex),!r.placeholder&&t.placeholder&&(r.placeholder=t.placeholder),null==r.autofocus){var i=Ro();r.autofocus=i==t||null!=t.getAttribute("autofocus")&&i==document.body}if(t.form&&(ws(t.form,"submit",n),!r.leaveSubmitMethodAlone)){var o=t.form,l=o.submit;try{var s=o.submit=function(){n(),o.submit=l,o.submit(),o.submit=s}}catch(a){}}r.finishInit=function(e){e.save=n,e.getTextArea=function(){return t},e.toTextArea=function(){e.toTextArea=isNaN,n(),t.parentNode.removeChild(e.getWrapperElement()),t.style.display="",t.form&&(xs(t.form,"submit",n),"function"==typeof t.form.submit&&(t.form.submit=l))}},t.style.display="none";var u=e(function(e){t.parentNode.insertBefore(e,t.nextSibling)},r);return u};var os=e.StringStream=function(e,t){this.pos=this.start=0,this.string=e,this.tabSize=t||8,this.lastColumnPos=this.lastColumnValue=0,this.lineStart=0};os.prototype={eol:function(){return this.pos>=this.string.length},sol:function(){return this.pos==this.lineStart},peek:function(){return this.string.charAt(this.pos)||void 0},next:function(){return this.pos<this.string.length?this.string.charAt(this.pos++):void 0},eat:function(e){var t=this.string.charAt(this.pos);if("string"==typeof e)var r=t==e;else var r=t&&(e.test?e.test(t):e(t));return r?(++this.pos,t):void 0},eatWhile:function(e){for(var t=this.pos;this.eat(e););return this.pos>t},eatSpace:function(){for(var e=this.pos;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>e},skipToEnd:function(){this.pos=this.string.length},skipTo:function(e){var t=this.string.indexOf(e,this.pos);
5
- return t>-1?(this.pos=t,!0):void 0},backUp:function(e){this.pos-=e},column:function(){return this.lastColumnPos<this.start&&(this.lastColumnValue=Ns(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start),this.lastColumnValue-(this.lineStart?Ns(this.string,this.lineStart,this.tabSize):0)},indentation:function(){return Ns(this.string,null,this.tabSize)-(this.lineStart?Ns(this.string,this.lineStart,this.tabSize):0)},match:function(e,t,r){if("string"!=typeof e){var n=this.string.slice(this.pos).match(e);return n&&n.index>0?null:(n&&t!==!1&&(this.pos+=n[0].length),n)}var i=function(e){return r?e.toLowerCase():e},o=this.string.substr(this.pos,e.length);return i(o)==i(e)?(t!==!1&&(this.pos+=e.length),!0):void 0},current:function(){return this.string.slice(this.start,this.pos)},hideFirstChars:function(e,t){this.lineStart+=e;try{return t()}finally{this.lineStart-=e}}};var ls=0,ss=e.TextMarker=function(e,t){this.lines=[],this.type=t,this.doc=e,this.id=++ls};Co(ss),ss.prototype.clear=function(){if(!this.explicitlyCleared){var e=this.doc.cm,t=e&&!e.curOp;if(t&&mr(e),xo(this,"clear")){var r=this.find();r&&mo(this,"clear",r.from,r.to)}for(var n=null,i=null,o=0;o<this.lines.length;++o){var l=this.lines[o],s=_n(l.markedSpans,this);e&&!this.collapsed?Hr(e,Yi(l),"text"):e&&(null!=s.to&&(i=Yi(l)),null!=s.from&&(n=Yi(l))),l.markedSpans=Yn(l.markedSpans,s),null==s.from&&this.collapsed&&!gi(this.doc,l)&&e&&_i(l,gr(e.display))}if(e&&this.collapsed&&!e.options.lineWrapping)for(var o=0;o<this.lines.length;++o){var a=fi(this.lines[o]),u=f(a);u>e.display.maxLineLength&&(e.display.maxLine=a,e.display.maxLineLength=u,e.display.maxLineChanged=!0)}null!=n&&e&&this.collapsed&&Dr(e,n,i+1),this.lines.length=0,this.explicitlyCleared=!0,this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,e&&At(e.doc)),e&&mo(e,"markerCleared",e,this),t&&br(e),this.parent&&this.parent.clear()}},ss.prototype.find=function(e,t){null==e&&"bookmark"==this.type&&(e=1);for(var r,n,i=0;i<this.lines.length;++i){var o=this.lines[i],l=_n(o.markedSpans,this);if(null!=l.from&&(r=Al(t?o:Yi(o),l.from),-1==e))return r;if(null!=l.to&&(n=Al(t?o:Yi(o),l.to),1==e))return n}return r&&{from:r,to:n}},ss.prototype.changed=function(){var e=this.find(-1,!0),t=this,r=this.doc.cm;e&&r&&Tr(r,function(){var n=e.line,i=Yi(e.line),o=qt(r,i);if(o&&(rr(o),r.curOp.selectionChanged=r.curOp.forceUpdate=!0),r.curOp.updateMaxLine=!0,!gi(t.doc,n)&&null!=t.height){var l=t.height;t.height=null;var s=yi(t)-l;s&&_i(n,n.height+s)}})},ss.prototype.attachLine=function(e){if(!this.lines.length&&this.doc.cm){var t=this.doc.cm.curOp;t.maybeHiddenMarkers&&-1!=Mo(t.maybeHiddenMarkers,this)||(t.maybeUnhiddenMarkers||(t.maybeUnhiddenMarkers=[])).push(this)}this.lines.push(e)},ss.prototype.detachLine=function(e){if(this.lines.splice(Mo(this.lines,e),1),!this.lines.length&&this.doc.cm){var t=this.doc.cm.curOp;(t.maybeHiddenMarkers||(t.maybeHiddenMarkers=[])).push(this)}};var ls=0,as=e.SharedTextMarker=function(e,t){this.markers=e,this.primary=t;for(var r=0;r<e.length;++r)e[r].parent=this};Co(as),as.prototype.clear=function(){if(!this.explicitlyCleared){this.explicitlyCleared=!0;for(var e=0;e<this.markers.length;++e)this.markers[e].clear();mo(this,"clear")}},as.prototype.find=function(e,t){return this.primary.find(e,t)};var us=e.LineWidget=function(e,t,r){if(r)for(var n in r)r.hasOwnProperty(n)&&(this[n]=r[n]);this.cm=e,this.node=t};Co(us),us.prototype.clear=function(){var e=this.cm,t=this.line.widgets,r=this.line,n=Yi(r);if(null!=n&&t){for(var i=0;i<t.length;++i)t[i]==this&&t.splice(i--,1);t.length||(r.widgets=null);var o=yi(this);Tr(e,function(){mi(e,r,-o),Hr(e,n,"widget"),_i(r,Math.max(0,r.height-o))})}},us.prototype.changed=function(){var e=this.height,t=this.cm,r=this.line;this.height=null;var n=yi(this)-e;n&&Tr(t,function(){t.curOp.forceUpdate=!0,mi(t,r,n),_i(r,r.height+n)})};var cs=e.Line=function(e,t,r){this.text=e,ni(this,t),this.height=r?r(this):1};Co(cs),cs.prototype.lineNo=function(){return Yi(this)};var fs={},hs={};Bi.prototype={chunkSize:function(){return this.lines.length},removeInner:function(e,t){for(var r=e,n=e+t;n>r;++r){var i=this.lines[r];this.height-=i.height,xi(i),mo(i,"delete")}this.lines.splice(e,t)},collapse:function(e){e.push.apply(e,this.lines)},insertInner:function(e,t,r){this.height+=r,this.lines=this.lines.slice(0,e).concat(t).concat(this.lines.slice(e));for(var n=0;n<t.length;++n)t[n].parent=this},iterN:function(e,t,r){for(var n=e+t;n>e;++e)if(r(this.lines[e]))return!0}},Gi.prototype={chunkSize:function(){return this.size},removeInner:function(e,t){this.size-=t;for(var r=0;r<this.children.length;++r){var n=this.children[r],i=n.chunkSize();if(i>e){var o=Math.min(t,i-e),l=n.height;if(n.removeInner(e,o),this.height-=l-n.height,i==o&&(this.children.splice(r--,1),n.parent=null),0==(t-=o))break;e=0}else e-=i}if(this.size-t<25&&(this.children.length>1||!(this.children[0]instanceof Bi))){var s=[];this.collapse(s),this.children=[new Bi(s)],this.children[0].parent=this}},collapse:function(e){for(var t=0;t<this.children.length;++t)this.children[t].collapse(e)},insertInner:function(e,t,r){this.size+=t.length,this.height+=r;for(var n=0;n<this.children.length;++n){var i=this.children[n],o=i.chunkSize();if(o>=e){if(i.insertInner(e,t,r),i.lines&&i.lines.length>50){for(;i.lines.length>50;){var l=i.lines.splice(i.lines.length-25,25),s=new Bi(l);i.height-=s.height,this.children.splice(n+1,0,s),s.parent=this}this.maybeSpill()}break}e-=o}},maybeSpill:function(){if(!(this.children.length<=10)){var e=this;do{var t=e.children.splice(e.children.length-5,5),r=new Gi(t);if(e.parent){e.size-=r.size,e.height-=r.height;var n=Mo(e.parent.children,e);e.parent.children.splice(n+1,0,r)}else{var i=new Gi(e.children);i.parent=e,e.children=[i,r],e=i}r.parent=e.parent}while(e.children.length>10);e.parent.maybeSpill()}},iterN:function(e,t,r){for(var n=0;n<this.children.length;++n){var i=this.children[n],o=i.chunkSize();if(o>e){var l=Math.min(t,o-e);if(i.iterN(e,l,r))return!0;if(0==(t-=l))break;e=0}else e-=o}}};var ds=0,ps=e.Doc=function(e,t,r){if(!(this instanceof ps))return new ps(e,t,r);null==r&&(r=0),Gi.call(this,[new Bi([new cs("",null)])]),this.first=r,this.scrollTop=this.scrollLeft=0,this.cantEdit=!1,this.cleanGeneration=1,this.frontier=r;var n=Al(r,0);this.sel=ht(n),this.history=new Qi(null),this.id=++ds,this.modeOption=t,"string"==typeof e&&(e=Vs(e)),Ri(this,{from:n,to:n,text:e}),kt(this,ht(n),Ts)};ps.prototype=Wo(Gi.prototype,{constructor:ps,iter:function(e,t,r){r?this.iterN(e-this.first,t-e,r):this.iterN(this.first,this.first+this.size,e)},insert:function(e,t){for(var r=0,n=0;n<t.length;++n)r+=t[n].height;this.insertInner(e-this.first,t,r)},remove:function(e,t){this.removeInner(e-this.first,t)},getValue:function(e){var t=Xi(this,this.first,this.first+this.size);return e===!1?t:t.join(e||"\n")},setValue:Nr(function(e){var t=Al(this.first,0),r=this.first+this.size-1;bn(this,{from:t,to:Al(r,Ki(this,r).text.length),text:Vs(e),origin:"setValue",full:!0},!0),kt(this,ht(t))}),replaceRange:function(e,t,r,n){t=pt(this,t),r=r?pt(this,r):t,kn(this,e,t,r,n)},getRange:function(e,t,r){var n=ji(this,pt(this,e),pt(this,t));return r===!1?n:n.join(r||"\n")},getLine:function(e){var t=this.getLineHandle(e);return t&&t.text},getLineHandle:function(e){return vt(this,e)?Ki(this,e):void 0},getLineNumber:function(e){return Yi(e)},getLineHandleVisualStart:function(e){return"number"==typeof e&&(e=Ki(this,e)),fi(e)},lineCount:function(){return this.size},firstLine:function(){return this.first},lastLine:function(){return this.first+this.size-1},clipPos:function(e){return pt(this,e)},getCursor:function(e){var t,r=this.sel.primary();return t=null==e||"head"==e?r.head:"anchor"==e?r.anchor:"end"==e||"to"==e||e===!1?r.to():r.from()},listSelections:function(){return this.sel.ranges},somethingSelected:function(){return this.sel.somethingSelected()},setCursor:Nr(function(e,t,r){Ct(this,pt(this,"number"==typeof e?Al(e,t||0):e),null,r)}),setSelection:Nr(function(e,t,r){Ct(this,pt(this,e),pt(this,t||e),r)}),extendSelection:Nr(function(e,t,r){bt(this,pt(this,e),t&&pt(this,t),r)}),extendSelections:Nr(function(e,t){wt(this,mt(this,e,t))}),extendSelectionsBy:Nr(function(e,t){wt(this,Ao(this.sel.ranges,e),t)}),setSelections:Nr(function(e,t,r){if(e.length){for(var n=0,i=[];n<e.length;n++)i[n]=new ct(pt(this,e[n].anchor),pt(this,e[n].head));null==t&&(t=Math.min(e.length-1,this.sel.primIndex)),kt(this,ft(i,t),r)}}),addSelection:Nr(function(e,t,r){var n=this.sel.ranges.slice(0);n.push(new ct(pt(this,e),pt(this,t||e))),kt(this,ft(n,n.length-1),r)}),getSelection:function(e){for(var t,r=this.sel.ranges,n=0;n<r.length;n++){var i=ji(this,r[n].from(),r[n].to());t=t?t.concat(i):i}return e===!1?t:t.join(e||"\n")},getSelections:function(e){for(var t=[],r=this.sel.ranges,n=0;n<r.length;n++){var i=ji(this,r[n].from(),r[n].to());e!==!1&&(i=i.join(e||"\n")),t[n]=i}return t},replaceSelection:function(e,t,r){for(var n=[],i=0;i<this.sel.ranges.length;i++)n[i]=e;this.replaceSelections(n,t,r||"+input")},replaceSelections:Nr(function(e,t,r){for(var n=[],i=this.sel,o=0;o<i.ranges.length;o++){var l=i.ranges[o];n[o]={from:l.from(),to:l.to(),text:Vs(e[o]),origin:r}}for(var s=t&&"end"!=t&&mn(this,n,t),o=n.length-1;o>=0;o--)bn(this,n[o]);s?Lt(this,s):this.cm&&On(this.cm)}),undo:Nr(function(){xn(this,"undo")}),redo:Nr(function(){xn(this,"redo")}),undoSelection:Nr(function(){xn(this,"undo",!0)}),redoSelection:Nr(function(){xn(this,"redo",!0)}),setExtending:function(e){this.extend=e},getExtending:function(){return this.extend},historySize:function(){for(var e=this.history,t=0,r=0,n=0;n<e.done.length;n++)e.done[n].ranges||++t;for(var n=0;n<e.undone.length;n++)e.undone[n].ranges||++r;return{undo:t,redo:r}},clearHistory:function(){this.history=new Qi(this.history.maxGeneration)},markClean:function(){this.cleanGeneration=this.changeGeneration(!0)},changeGeneration:function(e){return e&&(this.history.lastOp=this.history.lastSelOp=this.history.lastOrigin=null),this.history.generation},isClean:function(e){return this.history.generation==(e||this.cleanGeneration)},getHistory:function(){return{done:uo(this.history.done),undone:uo(this.history.undone)}},setHistory:function(e){var t=this.history=new Qi(this.history.maxGeneration);t.done=uo(e.done.slice(0),null,!0),t.undone=uo(e.undone.slice(0),null,!0)},addLineClass:Nr(function(e,t,r){return Pn(this,e,"gutter"==t?"gutter":"class",function(e){var n="text"==t?"textClass":"background"==t?"bgClass":"gutter"==t?"gutterClass":"wrapClass";if(e[n]){if(Bo(r).test(e[n]))return!1;e[n]+=" "+r}else e[n]=r;return!0})}),removeLineClass:Nr(function(e,t,r){return Pn(this,e,"gutter"==t?"gutter":"class",function(e){var n="text"==t?"textClass":"background"==t?"bgClass":"gutter"==t?"gutterClass":"wrapClass",i=e[n];if(!i)return!1;if(null==r)e[n]=null;else{var o=i.match(Bo(r));if(!o)return!1;var l=o.index+o[0].length;e[n]=i.slice(0,o.index)+(o.index&&l!=i.length?" ":"")+i.slice(l)||null}return!0})}),markText:function(e,t,r){return Gn(this,pt(this,e),pt(this,t),r,"range")},setBookmark:function(e,t){var r={replacedWith:t&&(null==t.nodeType?t.widget:t),insertLeft:t&&t.insertLeft,clearWhenEmpty:!1,shared:t&&t.shared};return e=pt(this,e),Gn(this,e,e,r,"bookmark")},findMarksAt:function(e){e=pt(this,e);var t=[],r=Ki(this,e.line).markedSpans;if(r)for(var n=0;n<r.length;++n){var i=r[n];(null==i.from||i.from<=e.ch)&&(null==i.to||i.to>=e.ch)&&t.push(i.marker.parent||i.marker)}return t},findMarks:function(e,t,r){e=pt(this,e),t=pt(this,t);var n=[],i=e.line;return this.iter(e.line,t.line+1,function(o){var l=o.markedSpans;if(l)for(var s=0;s<l.length;s++){var a=l[s];i==e.line&&e.ch>a.to||null==a.from&&i!=e.line||i==t.line&&a.from>t.ch||r&&!r(a.marker)||n.push(a.marker.parent||a.marker)}++i}),n},getAllMarks:function(){var e=[];return this.iter(function(t){var r=t.markedSpans;if(r)for(var n=0;n<r.length;++n)null!=r[n].from&&e.push(r[n].marker)}),e},posFromIndex:function(e){var t,r=this.first;return this.iter(function(n){var i=n.text.length+1;return i>e?(t=e,!0):(e-=i,void++r)}),pt(this,Al(r,t))},indexFromPos:function(e){e=pt(this,e);var t=e.ch;return e.line<this.first||e.ch<0?0:(this.iter(this.first,e.line,function(e){t+=e.text.length+1}),t)},copy:function(e){var t=new ps(Xi(this,this.first,this.first+this.size),this.modeOption,this.first);return t.scrollTop=this.scrollTop,t.scrollLeft=this.scrollLeft,t.sel=this.sel,t.extend=!1,e&&(t.history.undoDepth=this.history.undoDepth,t.setHistory(this.getHistory())),t},linkedDoc:function(e){e||(e={});var t=this.first,r=this.first+this.size;null!=e.from&&e.from>t&&(t=e.from),null!=e.to&&e.to<r&&(r=e.to);var n=new ps(Xi(this,t,r),e.mode||this.modeOption,t);return e.sharedHist&&(n.history=this.history),(this.linked||(this.linked=[])).push({doc:n,sharedHist:e.sharedHist}),n.linked=[{doc:this,isParent:!0,sharedHist:e.sharedHist}],Kn(n,Vn(this)),n},unlinkDoc:function(t){if(t instanceof e&&(t=t.doc),this.linked)for(var r=0;r<this.linked.length;++r){var n=this.linked[r];if(n.doc==t){this.linked.splice(r,1),t.unlinkDoc(this),jn(Vn(this));break}}if(t.history==this.history){var i=[t.id];Ui(t,function(e){i.push(e.id)},!0),t.history=new Qi(null),t.history.done=uo(this.history.done,i),t.history.undone=uo(this.history.undone,i)}},iterLinkedDocs:function(e){Ui(this,e)},getMode:function(){return this.mode},getEditor:function(){return this.cm}}),ps.prototype.eachLine=ps.prototype.iter;var gs="iter insert remove copy getEditor".split(" ");for(var vs in ps.prototype)ps.prototype.hasOwnProperty(vs)&&Mo(gs,vs)<0&&(e.prototype[vs]=function(e){return function(){return e.apply(this.doc,arguments)}}(ps.prototype[vs]));Co(ps);var ms=e.e_preventDefault=function(e){e.preventDefault?e.preventDefault():e.returnValue=!1},ys=e.e_stopPropagation=function(e){e.stopPropagation?e.stopPropagation():e.cancelBubble=!0},bs=e.e_stop=function(e){ms(e),ys(e)},ws=e.on=function(e,t,r){if(e.addEventListener)e.addEventListener(t,r,!1);else if(e.attachEvent)e.attachEvent("on"+t,r);else{var n=e._handlers||(e._handlers={}),i=n[t]||(n[t]=[]);i.push(r)}},xs=e.off=function(e,t,r){if(e.removeEventListener)e.removeEventListener(t,r,!1);else if(e.detachEvent)e.detachEvent("on"+t,r);else{var n=e._handlers&&e._handlers[t];if(!n)return;for(var i=0;i<n.length;++i)if(n[i]==r){n.splice(i,1);break}}},Cs=e.signal=function(e,t){var r=e._handlers&&e._handlers[t];if(r)for(var n=Array.prototype.slice.call(arguments,2),i=0;i<r.length;++i)r[i].apply(null,n)},Ss=null,Ls=30,ks=e.Pass={toString:function(){return"CodeMirror.Pass"}},Ts={scroll:!1},Ms={origin:"*mouse"},As={origin:"+move"};So.prototype.set=function(e,t){clearTimeout(this.id),this.id=setTimeout(t,e)};var Ns=e.countColumn=function(e,t,r,n,i){null==t&&(t=e.search(/[^\s\u00a0]/),-1==t&&(t=e.length));for(var o=n||0,l=i||0;;){var s=e.indexOf(" ",o);if(0>s||s>=t)return l+(t-o);l+=s-o,l+=r-l%r,o=s+1}},Ws=[""],Os=function(e){e.select()};bl?Os=function(e){e.selectionStart=0,e.selectionEnd=e.value.length}:cl&&(Os=function(e){try{e.select()}catch(t){}});var Ds,Hs=/[\u00df\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,Ps=e.isWordChar=function(e){return/\w/.test(e)||e>"€"&&(e.toUpperCase()!=e.toLowerCase()||Hs.test(e))},Is=/[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;Ds=document.createRange?function(e,t,r,n){var i=document.createRange();return i.setEnd(n||e,r),i.setStart(e,t),i}:function(e,t,r){var n=document.body.createTextRange();try{n.moveToElementText(e.parentNode)}catch(i){return n}return n.collapse(!0),n.moveEnd("character",r),n.moveStart("character",t),n};var zs=e.contains=function(e,t){if(3==t.nodeType&&(t=t.parentNode),e.contains)return e.contains(t);do if(11==t.nodeType&&(t=t.host),t==e)return!0;while(t=t.parentNode)};cl&&11>fl&&(Ro=function(){try{return document.activeElement}catch(e){return document.body}});var Es,Fs,Rs=e.rmClass=function(e,t){var r=e.className,n=Bo(t).exec(r);if(n){var i=r.slice(n.index+n[0].length);e.className=r.slice(0,n.index)+(i?n[1]+i:"")}},Bs=e.addClass=function(e,t){var r=e.className;Bo(t).test(r)||(e.className+=(r?" ":"")+t)},Gs=!1,Us=function(){if(cl&&9>fl)return!1;var e=zo("div");return"draggable"in e||"dragDrop"in e}(),Vs=e.splitLines=3!="\n\nb".split(/\n/).length?function(e){for(var t=0,r=[],n=e.length;n>=t;){var i=e.indexOf("\n",t);-1==i&&(i=e.length);var o=e.slice(t,"\r"==e.charAt(i-1)?i-1:i),l=o.indexOf("\r");-1!=l?(r.push(o.slice(0,l)),t+=l+1):(r.push(o),t=i+1)}return r}:function(e){return e.split(/\r\n?|\n/)},Ks=window.getSelection?function(e){try{return e.selectionStart!=e.selectionEnd}catch(t){return!1}}:function(e){try{var t=e.ownerDocument.selection.createRange()}catch(r){}return t&&t.parentElement()==e?0!=t.compareEndPoints("StartToEnd",t):!1},js=function(){var e=zo("div");return"oncopy"in e?!0:(e.setAttribute("oncopy","return;"),"function"==typeof e.oncopy)}(),Xs=null,_s={3:"Enter",8:"Backspace",9:"Tab",13:"Enter",16:"Shift",17:"Ctrl",18:"Alt",19:"Pause",20:"CapsLock",27:"Esc",32:"Space",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"Left",38:"Up",39:"Right",40:"Down",44:"PrintScrn",45:"Insert",46:"Delete",59:";",61:"=",91:"Mod",92:"Mod",93:"Mod",107:"=",109:"-",127:"Delete",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",63232:"Up",63233:"Down",63234:"Left",63235:"Right",63272:"Delete",63273:"Home",63275:"End",63276:"PageUp",63277:"PageDown",63302:"Insert"};e.keyNames=_s,function(){for(var e=0;10>e;e++)_s[e+48]=_s[e+96]=String(e);for(var e=65;90>=e;e++)_s[e]=String.fromCharCode(e);for(var e=1;12>=e;e++)_s[e+111]=_s[e+63235]="F"+e}();var Ys,$s=function(){function e(e){return 247>=e?r.charAt(e):e>=1424&&1524>=e?"R":e>=1536&&1773>=e?n.charAt(e-1536):e>=1774&&2220>=e?"r":e>=8192&&8203>=e?"w":8204==e?"b":"L"}function t(e,t,r){this.level=e,this.from=t,this.to=r}var r="bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN",n="rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmm",i=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,o=/[stwN]/,l=/[LRr]/,s=/[Lb1n]/,a=/[1n]/,u="L";return function(r){if(!i.test(r))return!1;for(var n,c=r.length,f=[],h=0;c>h;++h)f.push(n=e(r.charCodeAt(h)));for(var h=0,d=u;c>h;++h){var n=f[h];"m"==n?f[h]=d:d=n}for(var h=0,p=u;c>h;++h){var n=f[h];"1"==n&&"r"==p?f[h]="n":l.test(n)&&(p=n,"r"==n&&(f[h]="R"))}for(var h=1,d=f[0];c-1>h;++h){var n=f[h];"+"==n&&"1"==d&&"1"==f[h+1]?f[h]="1":","!=n||d!=f[h+1]||"1"!=d&&"n"!=d||(f[h]=d),d=n}for(var h=0;c>h;++h){var n=f[h];if(","==n)f[h]="N";else if("%"==n){for(var g=h+1;c>g&&"%"==f[g];++g);for(var v=h&&"!"==f[h-1]||c>g&&"1"==f[g]?"1":"N",m=h;g>m;++m)f[m]=v;h=g-1}}for(var h=0,p=u;c>h;++h){var n=f[h];"L"==p&&"1"==n?f[h]="L":l.test(n)&&(p=n)}for(var h=0;c>h;++h)if(o.test(f[h])){for(var g=h+1;c>g&&o.test(f[g]);++g);for(var y="L"==(h?f[h-1]:u),b="L"==(c>g?f[g]:u),v=y||b?"L":"R",m=h;g>m;++m)f[m]=v;h=g-1}for(var w,x=[],h=0;c>h;)if(s.test(f[h])){var C=h;for(++h;c>h&&s.test(f[h]);++h);x.push(new t(0,C,h))}else{var S=h,L=x.length;for(++h;c>h&&"L"!=f[h];++h);for(var m=S;h>m;)if(a.test(f[m])){m>S&&x.splice(L,0,new t(1,S,m));var k=m;for(++m;h>m&&a.test(f[m]);++m);x.splice(L,0,new t(2,k,m)),S=m}else++m;h>S&&x.splice(L,0,new t(1,S,h))}return 1==x[0].level&&(w=r.match(/^\s+/))&&(x[0].from=w[0].length,x.unshift(new t(0,0,w[0].length))),1==To(x).level&&(w=r.match(/\s+$/))&&(To(x).to-=w[0].length,x.push(new t(0,c-w[0].length,c))),x[0].level!=To(x).level&&x.push(new t(x[0].level,c,c)),x}}();return e.version="5.0.1",e});
 
 
 
 
 
js/unitecreator_assets.js CHANGED
@@ -236,7 +236,7 @@ function UCAssetsManager(){
236
 
237
  if(lastSap == -1)
238
  return(path);
239
-
240
  path = path.substring(0, lastSap);
241
  return(path);
242
  }
@@ -301,6 +301,7 @@ function UCAssetsManager(){
301
 
302
  triggerEvent(events.SELECT_ITEM, [objItem, isCheck]);
303
 
 
304
  }
305
 
306
 
@@ -315,13 +316,13 @@ function UCAssetsManager(){
315
  unselectAllItems(objItem);
316
  selectItem(objItem, true);
317
  }
318
-
319
 
320
  /**
321
  * toggle item selection
322
  */
323
  function toggleItemSelection(objItem){
324
-
325
  var isSelected = isItemSelected(objItem);
326
 
327
  if(isSelected == false)
236
 
237
  if(lastSap == -1)
238
  return(path);
239
+
240
  path = path.substring(0, lastSap);
241
  return(path);
242
  }
301
 
302
  triggerEvent(events.SELECT_ITEM, [objItem, isCheck]);
303
 
304
+
305
  }
306
 
307
 
316
  unselectAllItems(objItem);
317
  selectItem(objItem, true);
318
  }
319
+
320
 
321
  /**
322
  * toggle item selection
323
  */
324
  function toggleItemSelection(objItem){
325
+
326
  var isSelected = isItemSelected(objItem);
327
 
328
  if(isSelected == false)
js/unitecreator_includes.js CHANGED
@@ -113,6 +113,67 @@ function UniteCreatorIncludes(){
113
  return(html);
114
  }
115
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
  /**
118
  * get include item html
@@ -150,6 +211,12 @@ function UniteCreatorIncludes(){
150
  conditionStyle = "";
151
  }
152
 
 
 
 
 
 
 
153
  var html = '<li>';
154
  html += '<div class="uc-includes-handle"></div>';
155
  html += '<input type="text" class="uc-includes-url" value="'+url+'">';
@@ -160,6 +227,7 @@ function UniteCreatorIncludes(){
160
 
161
  html += '<div class="unite-clear"></div>';
162
  html += '<div class="uc-condition-container" '+conditionStyle+'>'+htmlCondition+'</div>';
 
163
  html += '</li>';
164
 
165
  var objHtml = jQuery(html);
@@ -470,25 +538,41 @@ function UniteCreatorIncludes(){
470
  }
471
 
472
  //checkboxes
473
- var objCheckboxes = objDialog.find("input[type='checkbox']");
474
 
475
  var objParams = g_ucAdmin.getVal(objData, "params");
476
  if(!objParams)
477
  objParams = null;
478
 
479
- jQuery.each(objCheckboxes,function(index, checkbox){
480
-
481
- var objCheckbox = jQuery(checkbox);
482
 
483
- var name = objCheckbox.prop("name");
484
 
 
 
485
  var value = g_ucAdmin.getVal(objParams, name);
486
- value = g_ucAdmin.strToBool(value);
487
 
488
- objCheckbox.prop("checked", value);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
489
 
490
  });
491
 
 
 
492
  }
493
 
494
 
@@ -530,6 +614,7 @@ function UniteCreatorIncludes(){
530
  }
531
 
532
 
 
533
  /**
534
  * update the condition of the input
535
  */
@@ -542,7 +627,7 @@ function UniteCreatorIncludes(){
542
  objRow.removeData("condition");
543
  }
544
  else{
545
-
546
  var data = {name: paramName, value: paramValue};
547
  objRow.data("condition", data);
548
 
@@ -585,18 +670,35 @@ function UniteCreatorIncludes(){
585
  var paramValue = jQuery("#uc_dialog_include_values").val();
586
 
587
  updateInputCondition(objRow, paramName, paramValue);
588
-
589
  var rowParams = {};
590
- var objCheckboxes = objDialog.find("input[type='checkbox']");
591
- jQuery.each(objCheckboxes,function(index, checkbox){
592
- var objCheckbox = jQuery(checkbox);
593
- var name = objCheckbox.prop("name");
594
- var isChecked = objCheckbox.is(":checked");
 
595
 
596
- if(isChecked == true)
597
- rowParams[name] = true;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
598
  });
599
 
 
 
600
  objRow.data("params", rowParams);
601
 
602
  objDialog.dialog("close");
113
  return(html);
114
  }
115
 
116
+ /**
117
+ * get state text
118
+ */
119
+ function getHtmlStateText(item){
120
+
121
+ if(!item)
122
+ return(null);
123
+
124
+ var text = "";
125
+ var params = g_ucAdmin.getVal(item, "params");
126
+
127
+ //include_after_elementor_frontend
128
+ var includeAfterFrontend = g_ucAdmin.getVal(params, "include_after_elementor_frontend");
129
+ includeAfterFrontend = g_ucAdmin.strToBool(includeAfterFrontend);
130
+
131
+ if(includeAfterFrontend == true)
132
+ text += "include after <b>elementor-frontend.js</b>";
133
+
134
+ //handle:
135
+
136
+ var includeHandle = g_ucAdmin.getVal(params, "include_handle");
137
+
138
+ if(includeHandle){
139
+
140
+ if(text)
141
+ text += ", ";
142
+
143
+ text += "handle: <b>" + includeHandle+"</b>";
144
+ }
145
+
146
+ //module:
147
+ var module = g_ucAdmin.getVal(params, "include_as_module");
148
+
149
+ if(module){
150
+
151
+ if(text)
152
+ text += ", ";
153
+
154
+ text += " type: <b>module</b>";
155
+ }
156
+
157
+
158
+ return(text);
159
+ }
160
+
161
+
162
+ /**
163
+ * update the row extra html
164
+ */
165
+ function updateInputExtraHTML(objRow, rowParams){
166
+
167
+ var objText = objRow.find(".uc-includes-state-text");
168
+
169
+ var item = {params: rowParams};
170
+ var html = getHtmlStateText(item);
171
+
172
+ objText.show();
173
+ objText.html(html);
174
+
175
+ }
176
+
177
 
178
  /**
179
  * get include item html
211
  conditionStyle = "";
212
  }
213
 
214
+ var htmlStateText = getHtmlStateText(item);
215
+ var attributesStyle = " style='display:none'";
216
+
217
+ if(htmlStateText)
218
+ attributesStyle = "";
219
+
220
  var html = '<li>';
221
  html += '<div class="uc-includes-handle"></div>';
222
  html += '<input type="text" class="uc-includes-url" value="'+url+'">';
227
 
228
  html += '<div class="unite-clear"></div>';
229
  html += '<div class="uc-condition-container" '+conditionStyle+'>'+htmlCondition+'</div>';
230
+ html += '<div class="uc-includes-state-text" '+attributesStyle+'>'+htmlStateText+'</div>';
231
  html += '</li>';
232
 
233
  var objHtml = jQuery(html);
538
  }
539
 
540
  //checkboxes
541
+ var objInputs = objDialog.find("input[type='checkbox'],input[type='text']");
542
 
543
  var objParams = g_ucAdmin.getVal(objData, "params");
544
  if(!objParams)
545
  objParams = null;
546
 
547
+ jQuery.each(objInputs,function(index, input){
 
 
548
 
549
+ var type = input.type.toLowerCase();
550
 
551
+ var objInput = jQuery(input);
552
+ var name = objInput.prop("name");
553
  var value = g_ucAdmin.getVal(objParams, name);
 
554
 
555
+ switch(type){
556
+ default:
557
+ case "text":
558
+
559
+ objInput.val(value);
560
+
561
+ break;
562
+ case "checkbox":
563
+
564
+ value = g_ucAdmin.strToBool(value);
565
+
566
+ objInput.prop("checked", value);
567
+
568
+ break;
569
+ }
570
+
571
 
572
  });
573
 
574
+
575
+
576
  }
577
 
578
 
614
  }
615
 
616
 
617
+
618
  /**
619
  * update the condition of the input
620
  */
627
  objRow.removeData("condition");
628
  }
629
  else{
630
+
631
  var data = {name: paramName, value: paramValue};
632
  objRow.data("condition", data);
633
 
670
  var paramValue = jQuery("#uc_dialog_include_values").val();
671
 
672
  updateInputCondition(objRow, paramName, paramValue);
673
+
674
  var rowParams = {};
675
+ var objInputs = objDialog.find("input[type='checkbox'],input[type='text']");
676
+
677
+ jQuery.each(objInputs, function(index, input){
678
+
679
+ var type = input.type.toLowerCase();
680
+ var name = input.name;
681
 
682
+ switch(type){
683
+ case "checkbox":
684
+
685
+ var objCheckbox = jQuery(input);
686
+ var isChecked = objCheckbox.is(":checked");
687
+
688
+ if(isChecked == true)
689
+ rowParams[name] = true;
690
+
691
+ break;
692
+ default:
693
+ case "text":
694
+ rowParams[name] = input.value;
695
+ break;
696
+ }
697
+
698
  });
699
 
700
+ updateInputExtraHTML(objRow, rowParams);
701
+
702
  objRow.data("params", rowParams);
703
 
704
  objDialog.dialog("close");
provider/core/plugins/unlimited_elements/copy_paste.class.php CHANGED
@@ -38,9 +38,17 @@ class UniteCreatorElementorCopyPaste{
38
  */
39
  public function onPrintFooterHtml_paste(){
40
 
41
- $config = array();
42
- $config["ajax_url"] = HelperUC::URLtoFull(GlobalsUC::$url_ajax_front);;
 
 
 
 
43
 
 
 
 
 
44
  $jsonConfig = UniteFunctionsUC::jsonEncodeForClientSide($config);
45
 
46
  ?>
@@ -58,7 +66,7 @@ class UniteCreatorElementorCopyPaste{
58
  public function onPrintFooterHtml_copy(){
59
 
60
  $config = array();
61
- $config["ajax_url"] = HelperUC::URLtoFull(GlobalsUC::$url_ajax_front);;
62
 
63
  $jsonConfig = UniteFunctionsUC::jsonEncodeForClientSide($config);
64
 
@@ -75,38 +83,25 @@ class UniteCreatorElementorCopyPaste{
75
  /**
76
  * get remote section zip from params
77
  */
78
- private function pasteSection_getRemoteZip($params){
79
-
80
- if(is_string($params) == false)
81
- return(false);
82
-
83
- if(empty($params))
84
- return(false);
85
-
86
- if(strpos($params, "---uc-section-copy") !== 0)
87
- return(false);
88
 
89
- $arrParams = explode("~", $params);
90
-
91
- if(count($arrParams) != 4)
92
- return(false);
93
-
94
- $postID = $arrParams[1];
95
- $sectionID = $arrParams[2];
96
- $urlWebsite = $arrParams[3];
97
-
98
- $urlAjax = $urlWebsite."wp-admin/admin-ajax.php";
99
 
100
  $data = array();
101
  $data["action"] = "unlimitedelements_ajax_action";
102
  $data["client_action"] = "get_section_zip";
103
  $data["postid"] = $postID;
104
  $data["sectionid"] = $sectionID;
105
-
106
  try{
107
 
108
  $contentZIP = UniteFunctionsUC::getUrlContents($urlAjax, $data);
109
 
 
 
 
110
  }catch(Exception $e){
111
 
112
  UniteFunctionsUC::throwError("Failed to paste section from remote site");
@@ -115,29 +110,70 @@ class UniteCreatorElementorCopyPaste{
115
  return($contentZIP);
116
  }
117
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
  /**
120
  * on paste section ajax action
121
  */
122
  public function pasteSectionAjaxAction($data){
123
 
124
- if(GlobalsUC::$inDev == false)
125
  return(false);
 
 
 
 
 
 
126
 
127
- $params = UniteFunctionsUC::getVal($data, "params");
128
- $targetPostID = UniteFunctionsUC::getVal($data, "topostid");
 
 
 
 
 
 
129
 
130
- if(empty($targetPostID))
131
- UniteFunctionsUC::throwError("no target page selected");
132
 
133
- $contentZip = $this->pasteSection_getRemoteZip($params);
134
 
135
  if(empty($contentZip) || strlen($contentZip) == 0)
136
  UniteFunctionsUC::throwError("Failed to paste section");
137
 
138
  $objExporter = new UniteCreatorLayoutsExporterElementor();
139
-
140
- $objExporter->importElementorZipContentSection($contentZip, $targetPostID);
141
 
142
  return(true);
143
  }
@@ -148,7 +184,7 @@ class UniteCreatorElementorCopyPaste{
148
  */
149
  public function getSectionZipFromData($data){
150
 
151
- if(GlobalsUC::$inDev == false)
152
  return(null);
153
  try{
154
 
38
  */
39
  public function onPrintFooterHtml_paste(){
40
 
41
+ $currentPost = get_post();
42
+
43
+ if(empty($currentPost))
44
+ return(false);
45
+
46
+ $postID = $currentPost->ID;
47
 
48
+ $config = array();
49
+ $config["ajax_url"] = GlobalsUC::$url_ajax_full;
50
+ $config["post_id"] = $postID;
51
+
52
  $jsonConfig = UniteFunctionsUC::jsonEncodeForClientSide($config);
53
 
54
  ?>
66
  public function onPrintFooterHtml_copy(){
67
 
68
  $config = array();
69
+ $config["ajax_url"] = HelperUC::URLtoFull(GlobalsUC::$url_ajax_full);
70
 
71
  $jsonConfig = UniteFunctionsUC::jsonEncodeForClientSide($config);
72
 
83
  /**
84
  * get remote section zip from params
85
  */
86
+ private function pasteSection_getRemoteZip($arrParams){
 
 
 
 
 
 
 
 
 
87
 
88
+ $postID = UniteFunctionsUC::getVal($arrParams, "post_id");
89
+ $sectionID = UniteFunctionsUC::getVal($arrParams, "section_id");
90
+ $urlAjax = UniteFunctionsUC::getVal($arrParams, "remote_ajax_url");
 
 
 
 
 
 
 
91
 
92
  $data = array();
93
  $data["action"] = "unlimitedelements_ajax_action";
94
  $data["client_action"] = "get_section_zip";
95
  $data["postid"] = $postID;
96
  $data["sectionid"] = $sectionID;
97
+
98
  try{
99
 
100
  $contentZIP = UniteFunctionsUC::getUrlContents($urlAjax, $data);
101
 
102
+ if(strpos($contentZIP, "<!doctype html>") === 0)
103
+ UniteFunctionsUC::throwError("Wrong return content");
104
+
105
  }catch(Exception $e){
106
 
107
  UniteFunctionsUC::throwError("Failed to paste section from remote site");
110
  return($contentZIP);
111
  }
112
 
113
+ /**
114
+ * get paste params from params string
115
+ */
116
+ private function getArrPasteParams($params){
117
+
118
+ if(is_string($params) == false)
119
+ UniteFunctionsUC::throwError("wrong paste params format");
120
+
121
+ if(empty($params))
122
+ UniteFunctionsUC::throwError("no paste params found");
123
+
124
+ if(strpos($params, "---uc-section-copy") !== 0)
125
+ UniteFunctionsUC::throwError("paste params - wrong format");
126
+
127
+ $arrParams = explode("~", $params);
128
+
129
+ if(count($arrParams) != 4)
130
+ UniteFunctionsUC::throwError("wrong paste params number");
131
+
132
+ $postID = $arrParams[1];
133
+ $sectionID = $arrParams[2];
134
+ $urlWebsite = $arrParams[3];
135
+
136
+ $arrParams = array();
137
+ $arrParams["post_id"] = $postID;
138
+ $arrParams["section_id"] = $sectionID;
139
+ $arrParams["remote_ajax_url"] = $urlWebsite;
140
+
141
+ return($arrParams);
142
+ }
143
+
144
 
145
  /**
146
  * on paste section ajax action
147
  */
148
  public function pasteSectionAjaxAction($data){
149
 
150
+ if(GlobalsUC::$inDev == false && !defined("UC_ENABLE_COPYPASTE"))
151
  return(false);
152
+
153
+ $paramsData = UniteFunctionsUC::getVal($data, "params_data");
154
+ if(empty($paramsData))
155
+ UniteFunctionsUC::throwError("no paste data found");
156
+
157
+ $targetID = UniteFunctionsUC::getVal($data, "targetid");
158
 
159
+ if(empty($targetID))
160
+ UniteFunctionsUC::throwError("target post not given");
161
+
162
+ //clean:
163
+ $paramsData = str_replace("uesection--", "", $paramsData);
164
+
165
+ //decode
166
+ $paramsString = UniteFunctionsUC::decodeTextContent($paramsData);
167
 
168
+ $arrParams = $this->getArrPasteParams($paramsString);
 
169
 
170
+ $contentZip = $this->pasteSection_getRemoteZip($arrParams);
171
 
172
  if(empty($contentZip) || strlen($contentZip) == 0)
173
  UniteFunctionsUC::throwError("Failed to paste section");
174
 
175
  $objExporter = new UniteCreatorLayoutsExporterElementor();
176
+ $objExporter->importElementorZipContentSection($contentZip, $targetID);
 
177
 
178
  return(true);
179
  }
184
  */
185
  public function getSectionZipFromData($data){
186
 
187
+ if(GlobalsUC::$inDev == false && !defined("UC_ENABLE_COPYPASTE"))
188
  return(null);
189
  try{
190
 
provider/core/plugins/unlimited_elements/elementor/assets/uc_editor_admin.css CHANGED
@@ -104,5 +104,21 @@
104
 
105
  }
106
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
107
 
108
 
104
 
105
  }
106
 
107
+ /* button edit post */
108
+ .uc-button-edit-wrapper{
109
+ padding-top:5px;
110
+ padding-right:5px;
111
+ text-align:right;
112
+ }
113
+
114
+ .uc-button-edit-wrapper a{
115
+ font-size:11px !important;
116
+ font-weight:normal !important;
117
+ color:#6d7882 !important;
118
+ }
119
+
120
+ .uc-button-edit-wrapper a:hover{
121
+ text-decoration:underline;
122
+ }
123
 
124
 
provider/core/plugins/unlimited_elements/elementor/assets/uc_editor_admin.js CHANGED
@@ -510,11 +510,78 @@ function UniteCreatorElementorEditorAdmin(){
510
  return(objControl);
511
  }
512
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
513
  /**
514
  * init the select 2 object eventually
515
  */
516
  function initPostIDsSelect_initObject(objSelect, arrInitData){
517
-
518
  var data = objSelect.data();
519
 
520
  var postType = null;
@@ -549,14 +616,22 @@ function UniteCreatorElementorEditorAdmin(){
549
  }
550
 
551
  objSelect.select2(options);
552
-
553
- if(!arrInitData)
 
 
 
 
 
554
  return(false);
 
555
 
556
  //avoid trigger event on init
557
  objSelect.data("stop_trigger_oninit", true);
558
  objSelect.on("change",function(event){
559
 
 
 
560
  var stopOnInit = objSelect.data("stop_trigger_oninit");
561
  if(!stopOnInit)
562
  return(true);
@@ -823,7 +898,7 @@ function UniteCreatorElementorEditorAdmin(){
823
  * load include file, js or css
824
  */
825
  function loadDOMIncludeFile(type, url, data){
826
-
827
  if(!url)
828
  return(false);
829
 
@@ -832,6 +907,7 @@ function UniteCreatorElementorEditorAdmin(){
832
  var name = getVal(data, "name");
833
  var onload = getVal(data, "onload");
834
  var iframeWindow = getVal(data, "iframe");
 
835
 
836
  //add random number at the end
837
  var noRand = getVal(data, "norand");
@@ -856,6 +932,9 @@ function UniteCreatorElementorEditorAdmin(){
856
  var tag = objWindow.document.createElement('script');
857
  tag.src = url;
858
 
 
 
 
859
  //add onload function if exists
860
  if(typeof onload == "function"){
861
 
@@ -932,7 +1011,7 @@ function UniteCreatorElementorEditorAdmin(){
932
  if( !(objInclude.type == "js" && objInclude.handle == "jquery") )
933
  arrHandles[handle] = objInclude;
934
  });
935
-
936
  var isAllFilesLoaded = false;
937
 
938
  //inner function that check that all files loaded by handle
@@ -977,10 +1056,14 @@ function UniteCreatorElementorEditorAdmin(){
977
  * load include file
978
  */
979
  function loadIncludeFile(objInclude){
980
-
981
  var url = objInclude.url;
982
  var handle = handlePrefix + objInclude.type + "_" + objInclude.handle;
983
  var type = objInclude.type;
 
 
 
 
984
 
985
  //skip jquery for now
986
  if(objInclude.handle == "jquery"){
@@ -996,9 +1079,10 @@ function UniteCreatorElementorEditorAdmin(){
996
  var data = {
997
  replaceID:handle,
998
  name: "uc_include_file",
999
- iframe:windowIframe
 
1000
  };
1001
-
1002
  //onload throw event when all scripts loaded
1003
  data.onload = function(obj, handle){
1004
 
510
  return(objControl);
511
  }
512
 
513
+ /**
514
+ * add edit object if available
515
+ */
516
+ function postIDsSelect_checkEditButton(objSelect, data, arrData){
517
+
518
+ var value = objSelect.val();
519
+
520
+ var type = objSelect.data("datatype");
521
+
522
+ if(type == "terms")
523
+ return(false);
524
+
525
+ var objWrapper = objSelect.parents(".elementor-control-input-wrapper");
526
+
527
+ var objButtonEdit = objWrapper.find(".uc-button-edit-wrapper");
528
+ if(objButtonEdit.length)
529
+ objButtonEdit.remove();
530
+
531
+ if(!value || value == "")
532
+ return(false);
533
+
534
+ if(jQuery.isArray(value))
535
+ return(false);
536
+
537
+ if(jQuery.isNumeric(value) == false)
538
+ return(false);
539
+
540
+ if(typeof g_ucAdminUrl == "undefined")
541
+ return(false);
542
+
543
+ //append the new button
544
+
545
+ switch(type){
546
+ case "post":
547
+ default:
548
+ var buttonText = "Edit Post";
549
+ var urlEdit = g_ucAdminUrl+"post.php?post="+value+"&action=edit";
550
+ break;
551
+ case "elementor_template":
552
+ var buttonText = "Edit Template";
553
+ var urlEdit = g_ucAdminUrl+"post.php?post="+value+"&action=elementor";
554
+ break;
555
+ }
556
+
557
+ var htmlButton = "<div class='uc-button-edit-wrapper'><a href='"+urlEdit+"' target='_blank'>"+buttonText+"</a></div>";
558
+
559
+ objWrapper.append(htmlButton);
560
+
561
+
562
+ /*
563
+ var dataType = getVal(data, "dataType");
564
+ var isSingle = getVal(data,"issingle");
565
+
566
+ trace(dataType);
567
+ trace(isSingle);
568
+
569
+ if(dataType == "terms")
570
+ return(false);
571
+
572
+ if(isSingle == false)
573
+ return(false);
574
+
575
+ trace("check init data");
576
+ */
577
+ }
578
+
579
+
580
  /**
581
  * init the select 2 object eventually
582
  */
583
  function initPostIDsSelect_initObject(objSelect, arrInitData){
584
+
585
  var data = objSelect.data();
586
 
587
  var postType = null;
616
  }
617
 
618
  objSelect.select2(options);
619
+
620
+ if(!arrInitData){
621
+
622
+ objSelect.on("change",function(event){
623
+ postIDsSelect_checkEditButton(objSelect);
624
+ });
625
+
626
  return(false);
627
+ }
628
 
629
  //avoid trigger event on init
630
  objSelect.data("stop_trigger_oninit", true);
631
  objSelect.on("change",function(event){
632
 
633
+ postIDsSelect_checkEditButton(objSelect);
634
+
635
  var stopOnInit = objSelect.data("stop_trigger_oninit");
636
  if(!stopOnInit)
637
  return(true);
898
  * load include file, js or css
899
  */
900
  function loadDOMIncludeFile(type, url, data){
901
+
902
  if(!url)
903
  return(false);
904
 
907
  var name = getVal(data, "name");
908
  var onload = getVal(data, "onload");
909
  var iframeWindow = getVal(data, "iframe");
910
+ var isModule = getVal(data, "ismodule");
911
 
912
  //add random number at the end
913
  var noRand = getVal(data, "norand");
932
  var tag = objWindow.document.createElement('script');
933
  tag.src = url;
934
 
935
+ if(isModule === true)
936
+ tag.type = "module";
937
+
938
  //add onload function if exists
939
  if(typeof onload == "function"){
940
 
1011
  if( !(objInclude.type == "js" && objInclude.handle == "jquery") )
1012
  arrHandles[handle] = objInclude;
1013
  });
1014
+
1015
  var isAllFilesLoaded = false;
1016
 
1017
  //inner function that check that all files loaded by handle
1056
  * load include file
1057
  */
1058
  function loadIncludeFile(objInclude){
1059
+
1060
  var url = objInclude.url;
1061
  var handle = handlePrefix + objInclude.type + "_" + objInclude.handle;
1062
  var type = objInclude.type;
1063
+ var isModule = false;
1064
+ if(objInclude.hasOwnProperty("is_module") && objInclude.is_module == true && type == "js")
1065
+ isModule = true;
1066
+
1067
 
1068
  //skip jquery for now
1069
  if(objInclude.handle == "jquery"){
1079
  var data = {
1080
  replaceID:handle,
1081
  name: "uc_include_file",
1082
+ iframe:windowIframe,
1083
+ ismodule:isModule
1084
  };
1085
+
1086
  //onload throw event when all scripts loaded
1087
  data.onload = function(obj, handle){
1088
 
provider/core/plugins/unlimited_elements/elementor/assets/uc_front_section_paste.css CHANGED
@@ -18,4 +18,13 @@
18
  .uc-section-paste-button:hover{
19
  color:white;
20
  background-color:black;
21
- }
 
 
 
 
 
 
 
 
 
18
  .uc-section-paste-button:hover{
19
  color:white;
20
  background-color:black;
21
+ }
22
+
23
+ .uc-section-paste-debug{
24
+ background-color:white;
25
+ max-width:600px;
26
+ padding:10px;
27
+ border:1px solid gray;
28
+ max-height:300px;
29
+ overflow:auto;
30
+ }
provider/core/plugins/unlimited_elements/elementor/assets/uc_front_section_paste.js CHANGED
@@ -1,7 +1,7 @@
1
  function UnlimitedElementsPasteSection(){
2
 
3
  var g_options = {};
4
- var g_objPupup, g_objButton;
5
 
6
 
7
  /**
@@ -11,19 +11,141 @@ function UnlimitedElementsPasteSection(){
11
 
12
  var html = "";
13
  html += "<div id='uc_paste_section_popup' class='uc-section-paste-popup'>";
 
14
  html += " <input type='text' class='uc-section-paste-input'>";
15
  html += " <a href='javascript:void(0)' class='uc-section-paste-button'>Paste Section</a>";
 
 
16
  html += "</div>";
17
 
18
  jQuery("body").append(html);
19
  }
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  /**
22
  * init events
23
  */
24
  function initEvents(){
25
-
26
- trace("init events");
 
27
  }
28
 
29
  /**
@@ -35,9 +157,9 @@ function UnlimitedElementsPasteSection(){
35
  console.log("paste section error - no config found");
36
  return(false);
37
  }
38
-
39
  g_options = JSON.parse(g_ucPasteSectionConfig);
40
-
41
  putPasteHtml();
42
 
43
  g_objPopup = jQuery("#uc_paste_section_popup");
@@ -48,7 +170,9 @@ function UnlimitedElementsPasteSection(){
48
  }
49
 
50
  g_objButton = g_objPopup.find(".uc-section-paste-button");
51
-
 
 
52
 
53
  initEvents();
54
  }
1
  function UnlimitedElementsPasteSection(){
2
 
3
  var g_options = {};
4
+ var g_objPupup, g_objButton, g_objInput, g_objLoader, g_objDebug;
5
 
6
 
7
  /**
11
 
12
  var html = "";
13
  html += "<div id='uc_paste_section_popup' class='uc-section-paste-popup'>";
14
+ html += " <div class='uc-section-paste-debug' style='display:none'>debug</div>";
15
  html += " <input type='text' class='uc-section-paste-input'>";
16
  html += " <a href='javascript:void(0)' class='uc-section-paste-button'>Paste Section</a>";
17
+ html += " <div class='uc-section-paste-loader' style='display:none'>Pasting, please wait...</div>";
18
+
19
  html += "</div>";
20
 
21
  jQuery("body").append(html);
22
  }
23
 
24
+ /**
25
+ * show ajax error
26
+ */
27
+ function showAjaxError(error){
28
+
29
+ g_objDebug.html(error);
30
+ g_objDebug.show();
31
+
32
+ //alert(error);
33
+ }
34
+
35
+ /**
36
+ * small ajax request
37
+ */
38
+ function ajaxRequest(action, objData, onSuccess){
39
+
40
+ if(!objData)
41
+ var objData = {};
42
+
43
+ if(typeof objData != "object")
44
+ throw new Error("wrong ajax param");
45
+
46
+ var ajaxUrl = g_options.ajax_url;
47
+
48
+ var ajaxData = {};
49
+ ajaxData["action"] = "unlimitedelements_ajax_action";
50
+ ajaxData["client_action"] = action;
51
+ ajaxData["data"] = objData;
52
+
53
+
54
+ var ajaxOptions = {
55
+ type:"post",
56
+ url:ajaxUrl,
57
+ dataType: 'json',
58
+ data:ajaxData,
59
+ success:function(response){
60
+
61
+ if(!response){
62
+ showAjaxError("Empty ajax response!");
63
+ return(false);
64
+ }
65
+
66
+ if(typeof response != "object"){
67
+
68
+ try{
69
+ response = jQuery.parseJSON(response);
70
+ }catch(e){
71
+ showAjaxError("Ajax Error!!! not ajax response");
72
+ return(false);
73
+ }
74
+ }
75
+
76
+ if(response == -1){
77
+ showAjaxError("ajax error!!!");
78
+ return(false);
79
+ }
80
+
81
+ if(response == 0){
82
+ showAjaxError("ajax error, action: <b>"+action+"</b> not found");
83
+ return(false);
84
+ }
85
+
86
+ if(response.success == undefined){
87
+ showAjaxError("The 'success' param is a must!");
88
+ return(false);
89
+ }
90
+
91
+ if(response.success == false){
92
+ showAjaxError(response.message);
93
+ return(false);
94
+ }
95
+
96
+ if(typeof onSuccess == "function")
97
+ onSuccess(response);
98
+
99
+ },
100
+ error:function(jqXHR, textStatus, errorThrown){
101
+
102
+ switch(textStatus){
103
+ case "parsererror":
104
+ case "error":
105
+ showAjaxError(jqXHR.responseText);
106
+ break;
107
+ }
108
+ }
109
+ }
110
+
111
+
112
+ jQuery.ajax(ajaxOptions);
113
+
114
+ }
115
+
116
+ /**
117
+ * on paste button click
118
+ */
119
+ function onPasteButtonClick(){
120
+
121
+ var postID = g_options.post_id;
122
+
123
+ if(!postID)
124
+ throw new Error("missing target post id");
125
+
126
+ g_objLoader.show();
127
+
128
+ var strCopyData = g_objInput.val();
129
+
130
+ var objData = {};
131
+ objData["params_data"] = strCopyData;
132
+ objData["targetid"] = postID;
133
+
134
+ ajaxRequest("paste_section_front", objData, function(){
135
+
136
+ location.reload();
137
+
138
+ });
139
+
140
+ }
141
+
142
  /**
143
  * init events
144
  */
145
  function initEvents(){
146
+
147
+ g_objButton.click(onPasteButtonClick);
148
+
149
  }
150
 
151
  /**
157
  console.log("paste section error - no config found");
158
  return(false);
159
  }
160
+
161
  g_options = JSON.parse(g_ucPasteSectionConfig);
162
+
163
  putPasteHtml();
164
 
165
  g_objPopup = jQuery("#uc_paste_section_popup");
170
  }
171
 
172
  g_objButton = g_objPopup.find(".uc-section-paste-button");
173
+ g_objLoader = g_objPopup.find(".uc-section-paste-loader");
174
+ g_objInput = g_objPopup.find(".uc-section-paste-input");
175
+ g_objDebug = g_objPopup.find(".uc-section-paste-debug");
176
 
177
  initEvents();
178
  }
provider/core/plugins/unlimited_elements/elementor/elementor_background_widget.class.php CHANGED
@@ -35,6 +35,7 @@ class UniteCreatorElementorBackgroundWidget extends UniteCreatorElementorWidget
35
 
36
  foreach($params as $key=>$param){
37
 
 
38
  $name = UniteFunctionsUC::getVal($param, "name");
39
  if(empty($name))
40
  continue;
@@ -42,6 +43,11 @@ class UniteCreatorElementorBackgroundWidget extends UniteCreatorElementorWidget
42
  $param["name"] = $alias."_".$name;
43
  $param["elementor_condition"] = $condition;
44
 
 
 
 
 
 
45
  $params[$key] = $param;
46
  }
47
 
35
 
36
  foreach($params as $key=>$param){
37
 
38
+ //modify nmae
39
  $name = UniteFunctionsUC::getVal($param, "name");
40
  if(empty($name))
41
  continue;
43
  $param["name"] = $alias."_".$name;
44
  $param["elementor_condition"] = $condition;
45
 
46
+ //modify condition
47
+ $conditionAttribute = UniteFunctionsUC::getVal($param, "condition_attribute");
48
+ if(!empty($conditionAttribute))
49
+ $param["condition_attribute"] = $alias."_".$conditionAttribute;
50
+
51
  $params[$key] = $param;
52
  }
53
 
provider/core/plugins/unlimited_elements/elementor/elementor_integrate.class.php CHANGED
@@ -717,7 +717,7 @@ class UniteCreatorElementorIntegrate{
717
  if(empty(self::$objAddons))
718
  self::$objAddons = new UniteCreatorAddons();
719
 
720
- $output = self::$objAddons->getAddonOutput($objAddon);
721
 
722
  if(empty($output))
723
  return(false);
@@ -874,7 +874,7 @@ class UniteCreatorElementorIntegrate{
874
 
875
  $objWidget = new UniteCreatorElementorBackgroundWidget();
876
  $objWidget->initBGWidget($objAddon, $objControls);
877
-
878
  $objWidget->registerBGControls();
879
  }
880
 
@@ -920,15 +920,11 @@ class UniteCreatorElementorIntegrate{
920
  $arrAddons = $this->getArrAddons();
921
 
922
  $objAddons = new UniteCreatorAddons();
923
- $arrPreviewUrls = $objAddons->getArrAddonPreviewUrls($arrAddons, "title");
924
-
925
- $jsonPreviews = UniteFunctionsUC::jsonEncodeForClientSide($arrPreviewUrls);
926
-
927
  $urlAssets = GlobalsUC::$url_assets;
928
 
929
  $script = "";
930
  $script .= "\n\n // ----- unlimited elements scripts ------- \n\n";
931
- //$script .= "var g_ucJsonAddonPreviews={$jsonPreviews};\n";
932
  $script .= "var g_ucUrlAssets='{$urlAssets}';\n";
933
 
934
  if($this->enableBackgroundWidgets == true)
@@ -938,6 +934,11 @@ class UniteCreatorElementorIntegrate{
938
 
939
  $script .= "var g_ucNonce=\"{$nonce}\";\n";
940
 
 
 
 
 
 
941
  return($script);
942
  }
943
 
@@ -1433,7 +1434,7 @@ class UniteCreatorElementorIntegrate{
1433
  */
1434
  private function initCopyPaste(){
1435
 
1436
- if(GlobalsUC::$inDev == false)
1437
  return(false);
1438
 
1439
  //check current user
@@ -1494,7 +1495,7 @@ class UniteCreatorElementorIntegrate{
1494
  //remove me
1495
  $enableDynamicVisibility = false;
1496
 
1497
- if(GlobalsUC::$inDev == true){
1498
  $enableDynamicVisibility = HelperProviderCoreUC_EL::getGeneralSetting("enable_dynamic_visibility");
1499
  $enableDynamicVisibility = UniteFunctionsUC::strToBool($enableDynamicVisibility);
1500
  }
717
  if(empty(self::$objAddons))
718
  self::$objAddons = new UniteCreatorAddons();
719
 
720
+ $output = self::$objAddons->getAddonOutput($objAddon, false); //nowrap
721
 
722
  if(empty($output))
723
  return(false);
874
 
875
  $objWidget = new UniteCreatorElementorBackgroundWidget();
876
  $objWidget->initBGWidget($objAddon, $objControls);
877
+
878
  $objWidget->registerBGControls();
879
  }
880
 
920
  $arrAddons = $this->getArrAddons();
921
 
922
  $objAddons = new UniteCreatorAddons();
923
+
 
 
 
924
  $urlAssets = GlobalsUC::$url_assets;
925
 
926
  $script = "";
927
  $script .= "\n\n // ----- unlimited elements scripts ------- \n\n";
 
928
  $script .= "var g_ucUrlAssets='{$urlAssets}';\n";
929
 
930
  if($this->enableBackgroundWidgets == true)
934
 
935
  $script .= "var g_ucNonce=\"{$nonce}\";\n";
936
 
937
+ $urlAdmin = admin_url();
938
+
939
+ $script .= "var g_ucAdminUrl=\"{$urlAdmin}\";\n";
940
+
941
+
942
  return($script);
943
  }
944
 
1434
  */
1435
  private function initCopyPaste(){
1436
 
1437
+ if(GlobalsUC::$inDev == false && !defined("UC_ENABLE_COPYPASTE"))
1438
  return(false);
1439
 
1440
  //check current user
1495
  //remove me
1496
  $enableDynamicVisibility = false;
1497
 
1498
+ if(GlobalsUC::$inDev == true){ //dynamic visibility
1499
  $enableDynamicVisibility = HelperProviderCoreUC_EL::getGeneralSetting("enable_dynamic_visibility");
1500
  $enableDynamicVisibility = UniteFunctionsUC::strToBool($enableDynamicVisibility);
1501
  }
provider/core/plugins/unlimited_elements/elementor/elementor_layout_exporter.class.php CHANGED
@@ -353,8 +353,9 @@ class UniteCreatorLayoutsExporterElementor extends UniteCreatorLayoutsExporter{
353
  UniteFunctionsUC::throwError("The file is not zip");
354
 
355
  $this->prepareImportFolders();
 
356
  $this->extractImportLayoutFile($filepath);
357
-
358
  //prepare the content and the json file path after extracted before import
359
  $this->importElementorTemplateNew_prepareLayoutImportContent();
360
 
@@ -475,9 +476,15 @@ class UniteCreatorLayoutsExporterElementor extends UniteCreatorLayoutsExporter{
475
  if(empty($targetPost))
476
  UniteFunctionsUC::throwError("Target post not found");
477
 
 
 
 
478
  $pathTemp = sys_get_temp_dir();
479
- $filepath = $pathTemp."/elementor_section".UniteFunctionsUC::getRandomString().".zip";
 
480
 
 
 
481
  UniteFunctionsUC::writeFile($contentZip, $filepath);
482
 
483
  $arrLayout = $this->importElementorTemplateNew($filepath, true,array("no_import" => true));
@@ -494,17 +501,28 @@ class UniteCreatorLayoutsExporterElementor extends UniteCreatorLayoutsExporter{
494
  if(empty($arrPageLayout) || is_array($arrPageLayout) == false)
495
  UniteFunctionsUC::throwError("No page elementor layout found");
496
 
497
- //insert section into new content
498
- $numSections = count($arrPageLayout);
499
 
500
- if($numSections <= 1)
501
- $arrPageLayout[] = $arrSection;
502
- else
503
- array_splice($arrPageLayout, 1, 0, $arrSection);
 
 
 
 
 
 
 
 
 
 
 
 
504
 
505
  //update elementor data
506
- $this->updateElementorDataMeta($targetPostID, $arrPageLayout);
507
 
 
508
  }
509
 
510
 
353
  UniteFunctionsUC::throwError("The file is not zip");
354
 
355
  $this->prepareImportFolders();
356
+
357
  $this->extractImportLayoutFile($filepath);
358
+
359
  //prepare the content and the json file path after extracted before import
360
  $this->importElementorTemplateNew_prepareLayoutImportContent();
361
 
476
  if(empty($targetPost))
477
  UniteFunctionsUC::throwError("Target post not found");
478
 
479
+ $filename = "elementor_section".UniteFunctionsUC::getRandomString().".zip";
480
+
481
+ /*
482
  $pathTemp = sys_get_temp_dir();
483
+ $filepath = $pathTemp."/".$filename;
484
+ */
485
 
486
+ $filepath = GlobalsUC::$path_cache.$filename;
487
+
488
  UniteFunctionsUC::writeFile($contentZip, $filepath);
489
 
490
  $arrLayout = $this->importElementorTemplateNew($filepath, true,array("no_import" => true));
501
  if(empty($arrPageLayout) || is_array($arrPageLayout) == false)
502
  UniteFunctionsUC::throwError("No page elementor layout found");
503
 
 
 
504
 
505
+ //insert the section
506
+
507
+ $arrPageLayoutNEW = array();
508
+ $isInserted = false;
509
+ foreach($arrPageLayout as $index=>$sectionExisting){
510
+
511
+ $arrPageLayoutNEW[] = $sectionExisting;
512
+
513
+ if($index == 0){
514
+ $arrPageLayoutNEW[] = $arrSection;
515
+ $isInserted = true;
516
+ }
517
+ }
518
+
519
+ if($isInserted == false)
520
+ $arrPageLayoutNEW[] = $arrSection;
521
 
522
  //update elementor data
523
+ $this->updateElementorDataMeta($targetPostID, $arrPageLayoutNEW);
524
 
525
+ HelperProviderCoreUC_EL::removeElementorPostCacheFile($targetPostID);
526
  }
527
 
528
 
provider/core/plugins/unlimited_elements/elementor/elementor_widget.class.php CHANGED
@@ -481,17 +481,26 @@ class UniteCreatorElementorWidget extends Widget_Base {
481
  $this->addElementorParamUC($param, $repeater);
482
  continue;
483
  }
484
-
485
  switch($type){
486
  case UniteCreatorDialogParam::PARAM_TEMPLATE: //convert template to text param
487
- $param["type"] = UniteCreatorDialogParam::PARAM_TEXTFIELD;
 
 
 
 
 
488
  $param["name"] .= "_templateid";
489
- $param["placeholder"] = "Put ID only, like 745";
 
490
  $param["label_block"] = true;
 
 
491
  $name .= "_templateid";
492
  break;
493
  }
494
 
 
495
  $arrControl = $this->getControlArrayUC($param, true);
496
  $repeater->add_control($name, $arrControl);
497
 
@@ -545,17 +554,21 @@ class UniteCreatorElementorWidget extends Widget_Base {
545
  /**
546
  * get elementor condition from the param
547
  */
548
- private function getControlArrayUC_getCondition($param){
549
 
550
  $conditionAttribute = UniteFunctionsUC::getVal($param, "condition_attribute");
551
  $conditionOperator = UniteFunctionsUC::getVal($param, "condition_operator");
552
  $conditionValue = UniteFunctionsUC::getVal($param, "condition_value");
553
 
554
  if(empty($conditionAttribute))
555
- return(null);
556
-
557
  $arrCondition = array();
558
 
 
 
 
 
559
  if($conditionAttribute == "not_equal")
560
  $conditionValue = "!".$conditionValue;
561
 
@@ -589,11 +602,13 @@ class UniteCreatorElementorWidget extends Widget_Base {
589
 
590
  $enableCondition = UniteFunctionsUC::getVal($param, "enable_condition");
591
  $enableCondition = UniteFunctionsUC::strToBool($enableCondition);
592
-
593
  //set condition
594
- if(empty($elementorCondition) && $enableCondition == true)
595
- $elementorCondition = $this->getControlArrayUC_getCondition($param);
 
596
 
 
597
  if(isset($param["value"]))
598
  $value = $param["value"];
599
 
@@ -661,7 +676,11 @@ class UniteCreatorElementorWidget extends Widget_Base {
661
  break;
662
  case UniteCreatorDialogParam::PARAM_DROPDOWN:
663
 
664
- if($isMultiple == true){
 
 
 
 
665
  $controlType = Controls_Manager::SELECT2;
666
  $arrControl["label_block"] = true;
667
  }
@@ -1100,16 +1119,35 @@ class UniteCreatorElementorWidget extends Widget_Base {
1100
  if($isResponsive == true){
1101
  $arrControl["uc_responsive"] = true;
1102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1103
  $arrControl["tablet_default"] = array(
1104
- "size" => UniteFunctionsUC::getVal($param, "default_value_tablet"),
1105
  "unit" => $rangeUnit
1106
  );
1107
 
1108
  $arrControl["mobile_default"] = array(
1109
- "size" => UniteFunctionsUC::getVal($param, "default_value_mobile"),
1110
- "unit" => $rangeUnit
1111
  );
1112
-
1113
  }
1114
 
1115
  break;
@@ -1128,7 +1166,7 @@ class UniteCreatorElementorWidget extends Widget_Base {
1128
 
1129
  $arrControl["desktop_default"] = $defaultValue;
1130
  $arrControl["tablet_default"] = $defaultTablet;
1131
- $arrControl["mobile_default"] = $defaultMobile;
1132
  }
1133
 
1134
  //add min max step
@@ -1144,7 +1182,8 @@ class UniteCreatorElementorWidget extends Widget_Base {
1144
 
1145
  if(!empty($step))
1146
  $arrControl["step"] = $step;
1147
-
 
1148
  break;
1149
  case UniteCreatorDialogParam::PARAM_TEXTSHADOW:
1150
 
@@ -1698,7 +1737,7 @@ class UniteCreatorElementorWidget extends Widget_Base {
1698
  protected function addAdvancedSectionControls($hasPostsList = false, $isItemsEnabled = false){
1699
 
1700
  $this->start_controls_section("unlimited_advanced_features", array(
1701
- "label"=>__("Advanced", 'unlimited_elements'),
1702
  "tab"=>"general"));
1703
 
1704
  if(UniteCreatorElementorIntegrate::$enableEditHTMLButton == true)
@@ -1707,7 +1746,7 @@ class UniteCreatorElementorWidget extends Widget_Base {
1707
  $this->add_control(
1708
  'show_widget_debug_data',
1709
  array(
1710
- 'label' => __( 'Show Widget Data For Debug', 'unlimited_elements' ),
1711
  'type' => Controls_Manager::SWITCHER,
1712
  'label_on' => __( 'Yes', 'unlimited-elements-for-elementor' ),
1713
  'label_off' => __( 'No', 'unlimited-elements-for-elementor' ),
@@ -2996,6 +3035,7 @@ class UniteCreatorElementorWidget extends Widget_Base {
2996
 
2997
  if($isEditMode == true){
2998
  $arrIncludes = $output->getProcessedIncludes(true, false, "js");
 
2999
  $jsonIncludes = UniteFunctionsUC::jsonEncodeForClientSide($arrIncludes);
3000
 
3001
  if(empty($arrIncludes))
481
  $this->addElementorParamUC($param, $repeater);
482
  continue;
483
  }
484
+
485
  switch($type){
486
  case UniteCreatorDialogParam::PARAM_TEMPLATE: //convert template to text param
487
+
488
+ $arrTemplates = HelperProviderCoreUC_EL::getArrElementorTemplatesShort();
489
+ $arrTemplates = UniteFunctionsUC::addArrFirstValue($arrTemplates, __("[No Template Selected]","unlimited-elements-for-elementor"),"__none__");
490
+ $arrTemplates = array_flip($arrTemplates);
491
+
492
+ $param["type"] = "select2";
493
  $param["name"] .= "_templateid";
494
+ $param["options"] = $arrTemplates;
495
+ $param["placeholder"] = __("Choose Template","unlimited-elements-for-elementor");
496
  $param["label_block"] = true;
497
+ $param["value"] = "__none__";
498
+
499
  $name .= "_templateid";
500
  break;
501
  }
502
 
503
+
504
  $arrControl = $this->getControlArrayUC($param, true);
505
  $repeater->add_control($name, $arrControl);
506
 
554
  /**
555
  * get elementor condition from the param
556
  */
557
+ private function getControlArrayUC_getCondition($param, $elementorCondition = null){
558
 
559
  $conditionAttribute = UniteFunctionsUC::getVal($param, "condition_attribute");
560
  $conditionOperator = UniteFunctionsUC::getVal($param, "condition_operator");
561
  $conditionValue = UniteFunctionsUC::getVal($param, "condition_value");
562
 
563
  if(empty($conditionAttribute))
564
+ return($elementorCondition);
565
+
566
  $arrCondition = array();
567
 
568
+ if(!empty($elementorCondition) && is_array($elementorCondition)){
569
+ $arrCondition = $elementorCondition;
570
+ }
571
+
572
  if($conditionAttribute == "not_equal")
573
  $conditionValue = "!".$conditionValue;
574
 
602
 
603
  $enableCondition = UniteFunctionsUC::getVal($param, "enable_condition");
604
  $enableCondition = UniteFunctionsUC::strToBool($enableCondition);
605
+
606
  //set condition
607
+ if($enableCondition == true){
608
+ $elementorCondition = $this->getControlArrayUC_getCondition($param, $elementorCondition);
609
+ }
610
 
611
+
612
  if(isset($param["value"]))
613
  $value = $param["value"];
614
 
676
  break;
677
  case UniteCreatorDialogParam::PARAM_DROPDOWN:
678
 
679
+ $isSelect2 = UniteFunctionsUC::getVal($param, "select2");
680
+ $isSelect2 = UniteFunctionsUC::strToBool($isSelect2);
681
+
682
+ if($isMultiple == true || $isSelect2 == true){
683
+
684
  $controlType = Controls_Manager::SELECT2;
685
  $arrControl["label_block"] = true;
686
  }
1119
  if($isResponsive == true){
1120
  $arrControl["uc_responsive"] = true;
1121
 
1122
+ $defaultValueTablet = UniteFunctionsUC::getVal($param, "default_value_tablet");
1123
+ $unitTablet = $rangeUnit;
1124
+
1125
+ if(!empty($defaultValueTablet)){
1126
+ $arrSize = UniteFunctionsUC::getSizeAndUnit($defaultValueTablet, $rangeUnit);
1127
+ $defaultValueTablet = $arrSize["size"];
1128
+ $unitTablet = $arrSize["unit"];
1129
+ }
1130
+
1131
+
1132
+ $defaultValueMobile = UniteFunctionsUC::getVal($param, "default_value_mobile");
1133
+ $unitMobile = $rangeUnit;
1134
+
1135
+ if(!empty($defaultValueMobile)){
1136
+ $arrSize = UniteFunctionsUC::getSizeAndUnit($defaultValueMobile, $rangeUnit);
1137
+ $defaultValueMobile = $arrSize["size"];
1138
+ $unitMobile = $arrSize["unit"];
1139
+ }
1140
+
1141
  $arrControl["tablet_default"] = array(
1142
+ "size" => $defaultValueTablet,
1143
  "unit" => $rangeUnit
1144
  );
1145
 
1146
  $arrControl["mobile_default"] = array(
1147
+ "size" => $defaultValueMobile,
1148
+ "unit" => $unitMobile
1149
  );
1150
+
1151
  }
1152
 
1153
  break;
1166
 
1167
  $arrControl["desktop_default"] = $defaultValue;
1168
  $arrControl["tablet_default"] = $defaultTablet;
1169
+ $arrControl["mobile_default"] = $defaultMobile;
1170
  }
1171
 
1172
  //add min max step
1182
 
1183
  if(!empty($step))
1184
  $arrControl["step"] = $step;
1185
+
1186
+
1187
  break;
1188
  case UniteCreatorDialogParam::PARAM_TEXTSHADOW:
1189
 
1737
  protected function addAdvancedSectionControls($hasPostsList = false, $isItemsEnabled = false){
1738
 
1739
  $this->start_controls_section("unlimited_advanced_features", array(
1740
+ "label"=>__("Advanced", 'unlimited-elements-for-elementor'),
1741
  "tab"=>"general"));
1742
 
1743
  if(UniteCreatorElementorIntegrate::$enableEditHTMLButton == true)
1746
  $this->add_control(
1747
  'show_widget_debug_data',
1748
  array(
1749
+ 'label' => __( 'Show Widget Data For Debug', 'unlimited-elements-for-elementor' ),
1750
  'type' => Controls_Manager::SWITCHER,
1751
  'label_on' => __( 'Yes', 'unlimited-elements-for-elementor' ),
1752
  'label_off' => __( 'No', 'unlimited-elements-for-elementor' ),
3035
 
3036
  if($isEditMode == true){
3037
  $arrIncludes = $output->getProcessedIncludes(true, false, "js");
3038
+
3039
  $jsonIncludes = UniteFunctionsUC::jsonEncodeForClientSide($arrIncludes);
3040
 
3041
  if(empty($arrIncludes))
provider/core/plugins/unlimited_elements/elementor/images/new2.svg DELETED
@@ -1,15 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <svg width="16px" height="16px" viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
- <!-- Generator: Sketch 64 (93537) - https://sketch.com -->
4
- <title>Artboard</title>
5
- <desc>Created with Sketch.</desc>
6
- <defs>
7
- <linearGradient x1="1.4609375%" y1="93.3752694%" x2="98.5390625%" y2="6.62473059%" id="linearGradient-1">
8
- <stop stop-color="#6F00D8" offset="0%"></stop>
9
- <stop stop-color="#1C6AFF" offset="100%"></stop>
10
- </linearGradient>
11
- </defs>
12
- <g id="Artboard" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
13
- <path d="M16,9.8125 C16,9.15670869 15.495423,8.625 14.8732589,8.625 L12.3767411,8.625 C11.754577,8.625 11.25,9.15670869 11.25,9.8125 C11.25,10.4682913 11.754577,11 12.3767411,11 L14.8732589,11 C15.495423,11 16,10.4682913 16,9.8125 M16,5.3125 C16,4.65688127 15.4955868,4.125 14.8730951,4.125 L12.3769049,4.125 C11.754577,4.125 11.25,4.65688127 11.25,5.3125 C11.25,5.96829131 11.754577,6.5 12.3769049,6.5 L14.8730951,6.5 C15.4955868,6.5 16,5.96829131 16,5.3125 M6.08906748,9.49285349 L6.08906748,5.06742919 C6.08906748,3.52164857 7.31894407,2.26412848 8.83054671,2.26412848 L14.8928858,2.26412848 C15.5042844,2.26412848 16,1.75720458 16,1.13214651 C16,0.506923905 15.5042844,0 14.8928858,0 L8.83054671,0 C6.09807756,0 3.875,2.27317776 3.875,5.06742919 L3.875,9.49285349 C3.875,10.1180761 4.37071557,10.625 4.98211419,10.625 C5.59351281,10.625 6.08906748,10.1180761 6.08906748,9.49285349 M5.06258218,15.125 C3.71014952,15.125 2.4389154,14.5848817 1.48277772,13.604136 C0.526640043,12.6230531 0,11.3188772 0,9.9313987 L0,5.28533542 C0,4.64454562 0.506422588,4.125 1.13102688,4.125 C1.75563118,4.125 2.26205377,4.64454562 2.26205377,5.28533542 L2.26205377,9.9313987 C2.26205377,10.6989974 2.55331661,11.4203918 3.08225783,11.9630396 C3.61103468,12.5056874 4.31437199,12.8044978 5.06258218,12.8044978 C6.60666975,12.8044978 7.86294623,11.5156672 7.86294623,9.9313987 L7.86294623,5.28533542 C7.86294623,4.64454562 8.36936882,4.125 8.99397312,4.125 C9.61857741,4.125 10.125,4.64454562 10.125,5.28533542 L10.125,9.9313987 C10.125,12.7952232 7.85390591,15.125 5.06258218,15.125" id="Fill-1" fill="url(#linearGradient-1)"></path>
14
- </g>
15
- </svg>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
provider/core/plugins/unlimited_elements/helper_provider_core.class.php CHANGED
@@ -17,7 +17,7 @@ class HelperProviderCoreUC_EL{
17
  public static $arrWidgetNames;
18
  public static $arrImages;
19
  public static $arrGlobalColors;
20
-
21
 
22
 
23
  /**
@@ -73,6 +73,27 @@ class HelperProviderCoreUC_EL{
73
  }
74
 
75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  /**
77
  * process param value by type
78
  */
@@ -190,6 +211,84 @@ class HelperProviderCoreUC_EL{
190
  }
191
 
192
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  /**
194
  * get imported elementor template by name
195
  */
@@ -205,20 +304,6 @@ class HelperProviderCoreUC_EL{
205
  return($templateID);
206
  }
207
 
208
- /**
209
- * get images array from elementor content
210
- */
211
- public static function getImagesFromElementorContent($arrContent){
212
-
213
- if(is_array($arrContent) == true){
214
- //foreach($arrContent)
215
- }
216
-
217
- dmp("get imges");
218
- dmp($arrContent);
219
- exit();
220
-
221
- }
222
 
223
  /**
224
  * get addons list from elementor content
17
  public static $arrWidgetNames;
18
  public static $arrImages;
19
  public static $arrGlobalColors;
20
+ private static $arrCacheElementorTemplate;
21
 
22
 
23
  /**
73
  }
74
 
75
 
76
+ /**
77
+ * remove elementor cache file by post id
78
+ */
79
+ public static function removeElementorPostCacheFile($postID){
80
+
81
+ //remove post meta
82
+ delete_post_meta($postID, "_elementor_css");
83
+
84
+ $pathFiles = GlobalsUC::$path_images."elementor/css/";
85
+
86
+ $filepath = $pathFiles."post-{$postID}.css";
87
+
88
+ $fileExists = file_exists($filepath);
89
+
90
+ if($fileExists == false)
91
+ return(false);
92
+
93
+ @unlink($filepath);
94
+ }
95
+
96
+
97
  /**
98
  * process param value by type
99
  */
211
  }
212
 
213
 
214
+ /**
215
+ * get elementor templates list
216
+ */
217
+ public static function getArrElementorTemplatesShort(){
218
+
219
+ if(!empty(self::$arrCacheElementorTemplate))
220
+ return(self::$arrCacheElementorTemplate);
221
+
222
+
223
+ $arrOptions = array();
224
+ $arrOptions["post_type"] = "elementor_library";
225
+ $arrOptions["numberposts"] = 500;
226
+ $arrOptions["state"] = "published";
227
+
228
+ $arrPosts = get_posts($arrOptions);
229
+
230
+ if(empty($arrPosts))
231
+ return(array());
232
+
233
+ $arrItems = array();
234
+ $arrDuplicates = array();
235
+
236
+ foreach($arrPosts as $post){
237
+
238
+ $postID = $post->ID;
239
+ $title = $post->post_title;
240
+ $slug = $post->post_name;
241
+
242
+ $templateType = get_post_meta($postID, "_elementor_template_type", true);
243
+
244
+ switch($templateType){
245
+ case "single-post":
246
+ $templateType = "single";
247
+ break;
248
+ case "wp-page":
249
+ $templateType = "page";
250
+ break;
251
+ case "kit":
252
+ continue(2);
253
+ break;
254
+ }
255
+
256
+ $templateType = ucfirst($templateType);
257
+
258
+ if(isset($arrDuplicates[$title]))
259
+ $arrDuplicates[$title] = true;
260
+ else
261
+ $arrDuplicates[$title] = false;
262
+
263
+ $arrItems[$postID] = array($slug, $title, $templateType);
264
+ }
265
+
266
+ //fix the duplicates
267
+ $arrShort = array();
268
+ foreach($arrItems as $id=>$arr){
269
+
270
+ $name = $arr[0];
271
+ $title = $arr[1];
272
+ $type = $arr[2];
273
+
274
+ $isDuplicate = $arrDuplicates[$title];
275
+
276
+ if($isDuplicate == true)
277
+ $showTitle = "$title ($name) | $type";
278
+ else
279
+ $showTitle = "$title | $type";
280
+
281
+ $arrShort[$id] = $showTitle;
282
+ }
283
+
284
+ asort($arrShort);
285
+
286
+ self::$arrCacheElementorTemplate = $arrShort;
287
+
288
+ return($arrShort);
289
+ }
290
+
291
+
292
  /**
293
  * get imported elementor template by name
294
  */
304
  return($templateID);
305
  }
306
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
307
 
308
  /**
309
  * get addons list from elementor content
provider/core/plugins/unlimited_elements/settings/general_settings_el.xml CHANGED
@@ -157,7 +157,7 @@
157
  </field>
158
 
159
  </fieldset>
160
- <fieldset name="copy_paste_mode" label="Copy Paste Mode" visibility="dev">
161
 
162
  <field name="copy_mode_enable_copy"
163
  type="boolean"
157
  </field>
158
 
159
  </fieldset>
160
+ <fieldset name="copy_paste_mode" label="Copy Paste Mode - Test" visibility="dev">
161
 
162
  <field name="copy_mode_enable_copy"
163
  type="boolean"
provider/core/plugins/unlimited_elements/views/settingselementor.php CHANGED
@@ -43,7 +43,7 @@ class UniteCreatorViewElementorSettings extends UniteCreatorSettingsView{
43
  $objSettings = $this->modifyConsolidateAddonsSetting($objSettings);
44
 
45
  //show the setting that was hidden in first place
46
- if(GlobalsUC::$inDev == true)
47
  $objSettings->updateSettingProperty("enable_dynamic_visibility", "hidden", "false");
48
 
49
  return($objSettings);
43
  $objSettings = $this->modifyConsolidateAddonsSetting($objSettings);
44
 
45
  //show the setting that was hidden in first place
46
+ if(GlobalsUC::$inDev == true) //dynamic visibility
47
  $objSettings->updateSettingProperty("enable_dynamic_visibility", "hidden", "false");
48
 
49
  return($objSettings);
provider/freemius/README.md DELETED
@@ -1,282 +0,0 @@
1
- Freemius WordPress SDK
2
- ======================
3
-
4
- Welcome to the official repository for the Freemius SDK! Adding the SDK to your WordPress plugin, theme, or add-ons, enables all the benefits that come with using the [Freemius platform](https://freemius.com) such as:
5
-
6
- * [Software Licensing](https://freemius.com/wordpress/software-licensing/)
7
- * [Secure Checkout](https://freemius.com/wordpress/checkout/)
8
- * [Subscriptions](https://freemius.com/wordpress/recurring-payments-subscriptions/)
9
- * [Automatic Updates](https://freemius.com/wordpress/automatic-software-updates/)
10
- * [Seamless EU VAT](https://freemius.com/wordpress/collecting-eu-vat-europe/)
11
- * [Cart Abandonment Recovery](https://freemius.com/wordpress/cart-abandonment-recovery/)
12
- * [Affiliate Platform](https://freemius.com/wordpress/affiliate-platform/)
13
- * [Analytics & Usage Tracking](https://freemius.com/wordpress/insights/)
14
- * [User Dashboard](https://freemius.com/wordpress/user-dashboard/)
15
-
16
- * [Monetization](https://freemius.com/wordpress/)
17
- * [Analytics](https://freemius.com/wordpress/insights/)
18
- * [More...](https://freemius.com/wordpress/features-comparison/)
19
-
20
- Freemius truly empowers developers to create prosperous subscription-based businesses.
21
-
22
- If you're new to Freemius then we recommend taking a look at our [Getting Started](https://freemius.com/help/documentation/getting-started/) guide first.
23
-
24
- If you're a WordPress plugin or theme developer and are interested in monetizing with Freemius then you can [sign-up for a FREE account](https://dashboard.freemius.com/register/):
25
-
26
- https://dashboard.freemius.com/register/
27
-
28
- Once you have your account setup and are familiar with how it all works you're ready to begin [integrating Freemius](https://freemius.com/help/documentation/wordpress-sdk/integrating-freemius-sdk/) into your WordPress product
29
-
30
- You can see some of the existing WordPress.org plugins & themes that are already utilizing the power of Freemius here:
31
-
32
- * https://profiles.wordpress.org/freemius/#content-plugins
33
- * https://includewp.com/freemius/#focus
34
-
35
- ## Code Documentation
36
-
37
- You can find the SDK's documentation here:
38
- https://freemius.com/help/documentation/wordpress-sdk/
39
-
40
- ## Integrating & Initializing the SDK
41
-
42
- As part of the integration process, you'll need to [add the latest version](https://freemius.com/help/documentation/getting-started/#add_the_latest_wordpress_sdk_into_your_product) of the Freemius SDK into your WordPress project.
43
-
44
- Then, when you've completed the [SDK integration form](https://freemius.com/help/documentation/getting-started/#fill_out_the_sdk_integration_form) a snippet of code is generated which you'll need to copy and paste into the top of your main plugin's PHP file, right after the plugin's header comment.
45
-
46
- Note: For themes, this will be in the root `functions.php` file instead.
47
-
48
- A typical SDK snippet will look similar to the following (your particular snippet may differ slightly depending on your integration):
49
-
50
- ```php
51
- if ( ! function_exists( 'my_prefix_fs' ) ) {
52
- // Create a helper function for easy SDK access.
53
- function my_prefix_fs() {
54
- global $my_prefix_fs;
55
-
56
- if ( ! isset( $my_prefix_fs ) ) {
57
- // Include Freemius SDK.
58
- require_once dirname(__FILE__) . '/freemius/start.php';
59
-
60
- $my_prefix_fs = fs_dynamic_init( array(
61
- 'id' => '1234',
62
- 'slug' => 'my-new-plugin',
63
- 'premium_slug' => 'my-new-plugin-premium',
64
- 'type' => 'plugin',
65
- 'public_key' => 'pk_bAEfta69seKymZzmf2xtqq8QXHz9y',
66
- 'is_premium' => true,
67
- // If your plugin is a serviceware, set this option to false.
68
- 'has_premium_version' => true,
69
- 'has_paid_plans' => true,
70
- 'is_org_compliant' => true,
71
- 'menu' => array(
72
- 'slug' => 'my-new-plugin',
73
- 'parent' => array(
74
- 'slug' => 'options-general.php',
75
- ),
76
- ),
77
- // Set the SDK to work in a sandbox mode (for development & testing).
78
- // IMPORTANT: MAKE SURE TO REMOVE SECRET KEY BEFORE DEPLOYMENT.
79
- 'secret_key' => 'sk_ubb4yN3mzqGR2x8#P7r5&@*xC$utE',
80
- ) );
81
- }
82
-
83
- return $my_prefix_fs;
84
- }
85
-
86
- // Init Freemius.
87
- my_prefix_fs();
88
- // Signal that SDK was initiated.
89
- do_action( 'my_prefix_fs_loaded' );
90
- }
91
-
92
- ```
93
-
94
- ## Usage example
95
-
96
- You can call anySDK methods by prefixing them with the shortcode function for your particular plugin/theme (specified when completing the SDK integration form in the Developer Dashboard):
97
-
98
- ```php
99
- <?php my_prefix_fs()->get_upgrade_url(); ?>
100
- ```
101
-
102
- Or when calling Freemius multiple times in a scope, it's recommended to use it with the global variable:
103
-
104
- ```php
105
- <?php
106
- global $my_prefix_fs;
107
- $my_prefix_fs->get_account_url();
108
- ?>
109
- ```
110
-
111
- There are many other SDK methods available that you can use to enhance the functionality of your WordPress product. Some of the more common use-cases are covered in the [Freemius SDK Gists](https://freemius.com/help/documentation/wordpress-sdk/gists/) documentation.
112
-
113
- ## Adding license based logic examples
114
-
115
- Add marketing content to encourage your users to upgrade for your paid version:
116
-
117
- ```php
118
- <?php
119
- if ( my_prefix_fs()->is_not_paying() ) {
120
- echo '<section><h1>' . esc_html__('Awesome Premium Features', 'my-plugin-slug') . '</h1>';
121
- echo '<a href="' . my_prefix_fs()->get_upgrade_url() . '">' .
122
- esc_html__('Upgrade Now!', 'my-plugin-slug') .
123
- '</a>';
124
- echo '</section>';
125
- }
126
- ?>
127
- ```
128
-
129
- Add logic which will only be available in your premium plugin version:
130
-
131
- ```php
132
- <?php
133
- // This "if" block will be auto removed from the Free version.
134
- if ( my_prefix_fs()->is__premium_only() ) {
135
-
136
- // ... premium only logic ...
137
-
138
- }
139
- ?>
140
- ```
141
-
142
- To add a function which will only be available in your premium plugin version, simply add __premium_only as the suffix of the function name. Just make sure that all lines that call that method directly or by hooks, are also wrapped in premium only logic:
143
-
144
- ```php
145
- <?php
146
- class My_Plugin {
147
- function init() {
148
- ...
149
-
150
- // This "if" block will be auto removed from the free version.
151
- if ( my_prefix_fs()->is__premium_only() ) {
152
- // Init premium version.
153
- $this->admin_init__premium_only();
154
-
155
- add_action( 'admin_init', array( &$this, 'admin_init_hook__premium_only' );
156
- }
157
-
158
- ...
159
- }
160
-
161
- // This method will be only included in the premium version.
162
- function admin_init__premium_only() {
163
- ...
164
- }
165
-
166
- // This method will be only included in the premium version.
167
- function admin_init_hook__premium_only() {
168
- ...
169
- }
170
- }
171
- ?>
172
- ```
173
-
174
- Add logic which will only be executed for customers in your 'professional' plan:
175
-
176
- ```php
177
- <?php
178
- if ( my_prefix_fs()->is_plan('professional', true) ) {
179
- // .. logic related to Professional plan only ...
180
- }
181
- ?>
182
- ```
183
-
184
- Add logic which will only be executed for customers in your 'professional' plan or higher plans:
185
-
186
- ```php
187
- <?php
188
- if ( my_prefix_fs()->is_plan('professional') ) {
189
- // ... logic related to Professional plan and higher plans ...
190
- }
191
- ?>
192
- ```
193
-
194
- Add logic which will only be available in your premium plugin version AND will only be executed for customers in your 'professional' plan (and higher plans):
195
-
196
- ```php
197
- <?php
198
- // This "if" block will be auto removed from the Free version.
199
- if ( my_prefix_fs()->is_plan__premium_only('professional') ) {
200
- // ... logic related to Professional plan and higher plans ...
201
- }
202
- ?>
203
- ```
204
-
205
- Add logic only for users in trial:
206
-
207
- ```php
208
- <?php
209
- if ( my_prefix_fs()->is_trial() ) {
210
- // ... logic for users in trial ...
211
- }
212
- ?>
213
- ```
214
-
215
- Add logic for specified paid plan:
216
-
217
- ```php
218
- <?php
219
- // This "if" block will be auto removed from the Free version.
220
- if ( my_prefix_fs()->is__premium_only() ) {
221
- if ( my_prefix_fs()->is_plan( 'professional', true ) ) {
222
-
223
- // ... logic related to Professional plan only ...
224
-
225
- } else if ( my_prefix_fs()->is_plan( 'business' ) ) {
226
-
227
- // ... logic related to Business plan and higher plans ...
228
-
229
- }
230
- }
231
- ?>
232
- ```
233
-
234
- ## Excluding files and folders from the free plugin version
235
- There are [two ways](https://freemius.com/help/documentation/wordpress-sdk/software-licensing/#excluding_files_and_folders_from_the_free_plugin_version) to exclude files from your free version.
236
-
237
- 1. Add `__premium_only` just before the file extension. For example, functions__premium_only.php will be only included in the premium plugin version. This works for all types of files, not only PHP.
238
- 2. Add `@fs_premium_only` a special meta tag to the plugin's main PHP file header. Example:
239
- ```php
240
- <?php
241
- /**
242
- * Plugin Name: My Very Awesome Plugin
243
- * Plugin URI: http://my-awesome-plugin.com
244
- * Description: Create and manage Awesomeness right in WordPress.
245
- * Version: 1.0.0
246
- * Author: Awesomattic
247
- * Author URI: http://my-awesome-plugin.com/me/
248
- * License: GPLv2
249
- * Text Domain: myplugin
250
- * Domain Path: /langs
251
- *
252
- * @fs_premium_only /lib/functions.php, /premium-files/
253
- */
254
-
255
- if ( ! defined( 'ABSPATH' ) ) {
256
- exit;
257
- }
258
-
259
- // ... my code ...
260
- ?>
261
- ```
262
- In the example plugin header above, the file `/lib/functions.php` and the directory `/premium-files/` will be removed from the free plugin version.
263
-
264
- # WordPress.org Compliance
265
- Based on [WordPress.org Guidelines](https://wordpress.org/plugins/about/guidelines/) you are not allowed to submit a plugin that has premium code in it:
266
- > All code hosted by WordPress.org servers must be free and fully-functional. If you want to sell advanced features for a plugin (such as a "pro" version), then you must sell and serve that code from your own site, we will not host it on our servers.
267
-
268
- Therefore, if you want to deploy your free plugin's version to WordPress.org, make sure you wrap all your premium code with `if ( my_prefix_fs()->{{ method }}__premium_only() )` or use [some of the other methods](https://freemius.com/help/documentation/wordpress-sdk/software-licensing/) provided by the SDK to exclude premium features & files from the free version.
269
-
270
- ## Deployment
271
- Zip your Freemius product’s root folder and [upload it in the Deployment section](https://freemius.com/help/documentation/selling-with-freemius/deployment/) in the *Freemius Developer's Dashboard*.
272
- The plugin/theme will automatically be scanned and processed by a custom-developed *PHP Processor* which will auto-generate two versions of your plugin:
273
-
274
- 1. **Premium version**: Identical to your uploaded version, including all code (except your `secret_key`). Will be enabled for download ONLY for your paying or in trial customers.
275
- 2. **Free version**: The code stripped from all your paid features (based on the logic added wrapped in `{ method }__premium_only()`).
276
-
277
- The free version is the one that you should give your users to download. Therefore, download the free generated version and upload to your site. Or, if your plugin was WordPress.org compliant and you made sure to exclude all your premium code with the different provided techniques, you can deploy the downloaded free version to the .org repo.
278
-
279
- ## License
280
- Copyright (c) Freemius®, Inc.
281
-
282
- Licensed under the GNU general public license (version 3).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
provider/freemius/assets/img/unlimited-elements-for-elementor.png DELETED
Binary file
provider/freemius/package.json DELETED
@@ -1,27 +0,0 @@
1
- {
2
- "name": "freemius-wordpress-sdk",
3
- "description": "Monetization, analytics, and marketing automation platform for plugin & theme developers.",
4
- "author": "Freemius, Inc.",
5
- "license": "GPL-3.0",
6
- "homepage": "https://freemius.com",
7
- "version": "2.4.2",
8
- "main": "gulpfile.js",
9
- "dependencies": {},
10
- "scripts": {
11
- "test": "echo \"Error: no test specified\" && exit 1",
12
- "prune": "rimraf .codeclimate.yml .git .github .gitignore .travis.yml gulpfile.js composer.json"
13
- },
14
- "repository": "Freemius/wordpress-sdk.git",
15
- "devDependencies": {
16
- "gulp": "^3.9.1",
17
- "gulp-clean": "^0.3.2",
18
- "gulp-fs": "0.0.2",
19
- "gulp-gettext": "^0.3.0",
20
- "gulp-path": "^3.0.3",
21
- "gulp-pofill": "^1.0.0",
22
- "gulp-rename": "^1.2.2",
23
- "gulp-sort": "^2.0.0",
24
- "gulp-transifex": "^0.1.17",
25
- "gulp-wp-pot": "^1.3.5"
26
- }
27
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
provider/functions_wordpress.class.php CHANGED
@@ -43,6 +43,7 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
43
  const THUMB_SMALL = "thumbnail";
44
  const THUMB_MEDIUM = "medium";
45
  const THUMB_LARGE = "large";
 
46
  const THUMB_FULL = "full";
47
 
48
  const STATE_PUBLISHED = "publish";
@@ -2167,6 +2168,21 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
2167
  return($item);
2168
  }
2169
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2170
 
2171
  /**
2172
  * get attachment data
@@ -2214,7 +2230,7 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
2214
  if(empty($title))
2215
  $title = $post->post_title;
2216
 
2217
- $urlThumb = self::getUrlAttachmentImage($thumbID,self::THUMB_MEDIUM);
2218
  if(empty($urlThumb))
2219
  $urlThumb = $post->guid;
2220
 
@@ -2666,10 +2682,17 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
2666
  /**
2667
  * get users array short
2668
  */
2669
- public static function getArrAuthorsShort(){
2670
 
2671
- if(!empty(self::$cacheAuthorsShort))
 
 
 
 
 
 
2672
  return(self::$cacheAuthorsShort);
 
2673
 
2674
  $args = array("role__not_in"=>array("subscriber", "customer"));
2675
  $arrUsers = get_users($args);
@@ -2691,6 +2714,11 @@ defined('UNLIMITED_ELEMENTS_INC') or die('Restricted access');
2691
 
2692
  self::$cacheAuthorsShort = $arrUsersShort;
2693
 
 
 
 
 
 
2694
  return($arrUsersShort);
2695
  }
2696
 
43
  const THUMB_SMALL = "thumbnail";
44
  const THUMB_MEDIUM = "medium";
45
  const THUMB_LARGE = "large";
46
+ const THUMB_MEDIUM_LARGE = "medium_large";
47
  const THUMB_FULL = "full";
48
 
49
  const STATE_PUBLISHED = "publish";
2168
  return($item);
2169
  }
2170
 
2171
+ /**
2172
+ * get product category image
2173
+ */
2174
+ public static function getProductCatImage($productCatID){
2175
+
2176
+ $imageID = get_term_meta( $productCatID, "thumbnail_id", true);
2177
+
2178
+ if(empty($imageID))
2179
+ return("");
2180
+
2181
+ $urlImage = self::getUrlAttachmentImage($imageID, UniteFunctionsWPUC::THUMB_LARGE);
2182
+
2183
+ return($urlImage);
2184
+ }
2185
+
2186
 
2187
  /**
2188
  * get attachment data
2230
  if(empty($title))
2231
  $title = $post->post_title;
2232
 
2233
+ $urlThumb = self::getUrlAttachmentImage($thumbID,self::THUMB_MEDIUM_LARGE);
2234
  if(empty($urlThumb))
2235
  $urlThumb = $post->guid;
2236
 
2682
  /**
2683
  * get users array short
2684
  */
2685
+ public static function getArrAuthorsShort($addCurrentUser = false){
2686
 
2687
+ if(!empty(self::$cacheAuthorsShort)){
2688
+
2689
+ if($addCurrentUser){
2690
+ $arrUsers = UniteFunctionsUC::addArrFirstValue(self::$cacheAuthorsShort, "-- Logged In User --", "uc_loggedin_user");
2691
+ return($arrUsers);
2692
+ }
2693
+
2694
  return(self::$cacheAuthorsShort);
2695
+ }
2696
 
2697
  $args = array("role__not_in"=>array("subscriber", "customer"));
2698
  $arrUsers = get_users($args);
2714
 
2715
  self::$cacheAuthorsShort = $arrUsersShort;
2716
 
2717
+ if($addCurrentUser == true){
2718
+ $arrUsers = UniteFunctionsUC::addArrFirstValue(self::$cacheAuthorsShort, "-- Logged In User --", "uc_loggedin_user");
2719
+ return($arrUsers);
2720
+ }
2721
+
2722
  return($arrUsersShort);
2723
  }
2724
 
provider/provider_front.class.php CHANGED
@@ -25,7 +25,25 @@ class UniteProviderFrontUC{
25
 
26
  add_filter($tag, array($this, $func), $priority, $accepted_args);
27
  }
 
 
 
 
 
 
28
 
 
 
 
 
 
 
 
 
 
 
 
 
29
 
30
  /**
31
  *
@@ -44,6 +62,9 @@ class UniteProviderFrontUC{
44
 
45
  $this->addAction( 'wp_head', 'onPrintHeadStyles' );
46
 
 
 
 
47
  }
48
 
49
 
25
 
26
  add_filter($tag, array($this, $func), $priority, $accepted_args);
27
  }
28
+
29
+
30
+ /**
31
+ * on script tag output. modify the output by options
32
+ */
33
+ public function onScriptTagOutput($tag, $handle, $src){
34
 
35
+ if(isset(GlobalsProviderUC::$arrJSHandlesModules[$handle])){
36
+
37
+ //modify tag, change to module if needed
38
+
39
+ $search = "type='text/javascript'";
40
+ $replace = "type='module'";
41
+
42
+ $tag = str_replace($search, $replace, $tag);
43
+ }
44
+
45
+ return($tag);
46
+ }
47
 
48
  /**
49
  *
62
 
63
  $this->addAction( 'wp_head', 'onPrintHeadStyles' );
64
 
65
+ //modify output <script> tag, add module to it
66
+ $this->addFilter("script_loader_tag", 'onScriptTagOutput',10,3);
67
+
68
  }
69
 
70
 
provider/provider_functions.class.php CHANGED
@@ -215,7 +215,7 @@ class UniteProviderFunctionsUC{
215
  UniteFunctionsUC::throwError("empty script url, handle: $handle");
216
 
217
  $version = UNLIMITED_ELEMENTS_VERSION;
218
- if(GlobalsUC::$inDev == true)
219
  $version = time();
220
 
221
  wp_register_script($handle , $url, $deps, $version, $inFooter);
@@ -233,7 +233,7 @@ class UniteProviderFunctionsUC{
233
  UniteFunctionsUC::throwError("empty style url, handle: $handle");
234
 
235
  $version = UNLIMITED_ELEMENTS_VERSION;
236
- if(GlobalsUC::$inDev == true)
237
  $version = time();
238
 
239
  wp_register_style($handle, $url, array(), $version);
215
  UniteFunctionsUC::throwError("empty script url, handle: $handle");
216
 
217
  $version = UNLIMITED_ELEMENTS_VERSION;
218
+ if(GlobalsUC::$inDev == true) //add script
219
  $version = time();
220
 
221
  wp_register_script($handle , $url, $deps, $version, $inFooter);
233
  UniteFunctionsUC::throwError("empty style url, handle: $handle");
234
 
235
  $version = UNLIMITED_ELEMENTS_VERSION;
236
+ if(GlobalsUC::$inDev == true) //add script
237
  $version = time();
238
 
239
  wp_register_style($handle, $url, array(), $version);
provider/provider_globals.class.php CHANGED
@@ -24,8 +24,11 @@ class GlobalsProviderUC{
24
  const ACTION_RUN_ADMIN = "unitecreator_run_admin";
25
  const ACTION_RUN_FRONT = "unitecreator_run_front";
26
 
 
 
27
  public static $lastPostQuery = null;
28
  public static $lastPostQuery_page = null;
 
29
 
30
  public static $arrFilterPostTypes = array( //filter post types that will not show
31
  "elementor_library",
24
  const ACTION_RUN_ADMIN = "unitecreator_run_admin";
25
  const ACTION_RUN_FRONT = "unitecreator_run_front";
26
 
27
+ public static $arrJSHandlesModules = array();
28
+
29
  public static $lastPostQuery = null;
30
  public static $lastPostQuery_page = null;
31
+ public static $arrFetchedPostIDs = array();
32
 
33
  public static $arrFilterPostTypes = array( //filter post types that will not show
34
  "elementor_library",
provider/provider_params_processor.class.php CHANGED
@@ -11,7 +11,6 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
11
 
12
  private static $arrPostTypeTaxCache = array();
13
 
14
-
15
  /**
16
  * add other image thumbs based of the platform
17
  */
@@ -252,7 +251,7 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
252
  private function getPostListData_getIDsFromPostMeta($value, $name, $showDebugQuery){
253
 
254
  $postIDs = UniteFunctionsUC::getVal($value, $name."_includeby_postmeta_postid");
255
-
256
  $metaName = UniteFunctionsUC::getVal($value, $name."_includeby_postmeta_metafield");
257
 
258
  $errorMessagePrefix = "Get post ids from meta error: ";
@@ -470,7 +469,7 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
470
  if(empty($arrTerms))
471
  return(array());
472
 
473
- $arrCatsOutput = $this->modifyArrTermsForOutput($arrTerms);
474
 
475
  //get term data
476
  if(count($arrTerms) == 1){ //single
@@ -484,11 +483,17 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
484
 
485
  $catID = UniteFunctionsUC::getVal($arrTermData, "term_id");
486
 
 
 
487
  $arrCategory = array();
488
  $arrCategory["category_id"] = $catID;
489
  $arrCategory["category_name"] = UniteFunctionsUC::getVal($arrTermData, "name");
490
  $arrCategory["category_slug"] = UniteFunctionsUC::getVal($arrTermData, "slug");
491
  $arrCategory["category_link"] = UniteFunctionsUC::getVal($arrTermData, "link");
 
 
 
 
492
  $arrCategory["categories"] = $arrCatsOutput;
493
 
494
 
@@ -1021,6 +1026,8 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
1021
  $excludeByAuthors = false;
1022
  $arrExcludeTerms = array();
1023
  $offset = null;
 
 
1024
 
1025
  foreach($arrExcludeBy as $excludeBy){
1026
 
@@ -1094,6 +1101,17 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
1094
  $offset = (int)$offset;
1095
 
1096
  break;
 
 
 
 
 
 
 
 
 
 
 
1097
  }
1098
 
1099
  }
@@ -1105,7 +1123,7 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
1105
 
1106
  $filters = $this->getPostListData_addOrderBy($filters, $value, $name);
1107
 
1108
- if(GlobalsUC::$inDev == true){
1109
 
1110
  if($isFilterable == true)
1111
  $filters = $this->getPostListData_getPostGetFilters_filters($filters);
@@ -1120,8 +1138,23 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
1120
  //exclude by authors
1121
 
1122
  if($excludeByAuthors == true){
 
1123
  $arrExcludeByAuthors = UniteFunctionsUC::getVal($value, "{$name}_excludeby_authors");
1124
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1125
  if(!empty($arrExcludeByAuthors))
1126
  $args["author__not_in"] = $arrExcludeByAuthors;
1127
  }
@@ -1145,11 +1178,35 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
1145
  $arrPostsNotIn = $specificPostsToExclude;
1146
  else
1147
  $arrPostsNotIn = array_merge($arrPostsNotIn, $specificPostsToExclude);
1148
- $arrPostsNotIn = array_unique($arrPostsNotIn);
1149
  }
1150
 
1151
  }
1152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1153
  //add the include by
1154
  $arrIncludeBy = UniteFunctionsUC::getVal($value, "{$name}_includeby");
1155
  if(empty($arrIncludeBy))
@@ -1168,9 +1225,11 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
1168
  $arrIDsPopular = array();
1169
  $arrIDsPHPFunction = array();
1170
  $arrIDsPostMeta = array();
 
1171
 
1172
- $makePostINOrder = false;
1173
 
 
 
1174
  foreach($arrIncludeBy as $includeby){
1175
 
1176
  switch($includeby){
@@ -1225,6 +1284,24 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
1225
 
1226
  $arrIncludeByAuthors = UniteFunctionsUC::getVal($value, "{$name}_includeby_authors");
1227
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1228
  if(!empty($arrIncludeByAuthors))
1229
  $args["author__in"] = $arrIncludeByAuthors;
1230
 
@@ -1329,6 +1406,13 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
1329
  $arrIDsPostMeta = $this->getPostListData_getIDsFromPostMeta($value, $name, $showDebugQuery);
1330
 
1331
  break;
 
 
 
 
 
 
 
1332
  }
1333
 
1334
  }
@@ -1359,6 +1443,12 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
1359
  $makePostINOrder = true;
1360
  }
1361
 
 
 
 
 
 
 
1362
  //make order as "post__id"
1363
 
1364
  if($makePostINOrder == true){
@@ -1404,8 +1494,10 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
1404
  $args["meta_query"] = $arrMetaQuery;
1405
 
1406
  //add exclude specific posts if available
1407
- if(!empty($arrPostsNotIn))
 
1408
  $args["post__not_in"] = $arrPostsNotIn;
 
1409
 
1410
  $isWpmlExists = UniteCreatorWpmlIntegrate::isWpmlExists();
1411
  if($isWpmlExists)
@@ -1486,12 +1578,18 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
1486
  //save last query
1487
  GlobalsProviderUC::$lastPostQuery = $query;
1488
 
 
 
 
 
 
 
1489
  HelperUC::addDebug("posts found: ".count($arrPosts));
1490
 
1491
  if($showDebugQuery == true){
1492
  dmp("Found Posts: ".count($arrPosts));
1493
  }
1494
-
1495
 
1496
  return($arrPosts);
1497
  }
@@ -1612,6 +1710,19 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
1612
 
1613
  $postIDs = UniteFunctionsUC::getVal($value, $name."_manual_select_post_ids");
1614
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1615
  $showDebugQuery = UniteFunctionsUC::getVal($value, "{$name}_show_query_debug");
1616
  $showDebugQuery = UniteFunctionsUC::strToBool($showDebugQuery);
1617
 
@@ -2152,7 +2263,7 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
2152
  */
2153
  private function getPostListData_getPostGetFilters_filters($filters){
2154
 
2155
- if(GlobalsUC::$inDev == false)
2156
  return($filters);
2157
 
2158
  $objFiltersProcess = new UniteCreatorFiltersProcess();
@@ -2750,6 +2861,9 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
2750
  return($htmlMenu);
2751
  }
2752
 
 
 
 
2753
  /**
2754
  * get template data
2755
  */
@@ -2760,16 +2874,22 @@ class UniteCreatorParamsProcessor extends UniteCreatorParamsProcessorWork{
2760
  if(empty($templateID))
2761
  return($data);
2762
 
2763
- $shortcode = "[elementor-template id=\"$templateID\"]";
 
2764
 
 
 
 
 
 
2765
  $data[$name] = $shortcode;
2766
  $data[$name."_templateid"] = $templateID;
2767
 
2768
  return($data);
2769
  }
2770
 
2771
- protected function z_______________GET_PARAMS____________(){}
2772
 
 
2773
 
2774
 
2775
  /**
11
 
12
  private static $arrPostTypeTaxCache = array();
13
 
 
14
  /**
15
  * add other image thumbs based of the platform
16
  */
251
  private function getPostListData_getIDsFromPostMeta($value, $name, $showDebugQuery){
252
 
253
  $postIDs = UniteFunctionsUC::getVal($value, $name."_includeby_postmeta_postid");
254
+
255
  $metaName = UniteFunctionsUC::getVal($value, $name."_includeby_postmeta_metafield");
256
 
257
  $errorMessagePrefix = "Get post ids from meta error: ";
469
  if(empty($arrTerms))
470
  return(array());
471
 
472
+ $arrCatsOutput = $this->modifyArrTermsForOutput($arrTerms, $taxonomy);
473
 
474
  //get term data
475
  if(count($arrTerms) == 1){ //single
483
 
484
  $catID = UniteFunctionsUC::getVal($arrTermData, "term_id");
485
 
486
+ $urlImage = null;
487
+
488
  $arrCategory = array();
489
  $arrCategory["category_id"] = $catID;
490
  $arrCategory["category_name"] = UniteFunctionsUC::getVal($arrTermData, "name");
491
  $arrCategory["category_slug"] = UniteFunctionsUC::getVal($arrTermData, "slug");
492
  $arrCategory["category_link"] = UniteFunctionsUC::getVal($arrTermData, "link");
493
+
494
+ if($taxonomy == "product_cat")
495
+ $arrCategory["category_image"] = UniteFunctionsWPUC::getProductCatImage($catID);
496
+
497
  $arrCategory["categories"] = $arrCatsOutput;
498
 
499
 
1026
  $excludeByAuthors = false;
1027
  $arrExcludeTerms = array();
1028
  $offset = null;
1029
+ $isAvoidDuplicates = false;
1030
+ $arrExcludeIDsDynamic = null;
1031
 
1032
  foreach($arrExcludeBy as $excludeBy){
1033
 
1101
  $offset = (int)$offset;
1102
 
1103
  break;
1104
+ case "avoid_duplicates":
1105
+
1106
+ $isAvoidDuplicates = true;
1107
+
1108
+ break;
1109
+ case "ids_from_dynamic":
1110
+
1111
+ $arrExcludeIDsDynamic = UniteFunctionsUC::getVal($value, $name."_exclude_dynamic_field");
1112
+ $arrExcludeIDsDynamic = UniteFunctionsUC::getIDsArray($arrExcludeIDsDynamic);
1113
+
1114
+ break;
1115
  }
1116
 
1117
  }
1123
 
1124
  $filters = $this->getPostListData_addOrderBy($filters, $value, $name);
1125
 
1126
+ if(GlobalsUC::$inDev == true){ //filters
1127
 
1128
  if($isFilterable == true)
1129
  $filters = $this->getPostListData_getPostGetFilters_filters($filters);
1138
  //exclude by authors
1139
 
1140
  if($excludeByAuthors == true){
1141
+
1142
  $arrExcludeByAuthors = UniteFunctionsUC::getVal($value, "{$name}_excludeby_authors");
1143
+
1144
+ foreach($arrExcludeByAuthors as $key => $userID){
1145
+
1146
+ if($userID == "uc_loggedin_user"){
1147
+
1148
+ $userID = get_current_user_id();
1149
+
1150
+ if(empty($userID))
1151
+ unset($arrExcludeByAuthors[$key]);
1152
+ else
1153
+ $arrExcludeByAuthors[$key] = $userID;
1154
+ }
1155
+
1156
+ }
1157
+
1158
  if(!empty($arrExcludeByAuthors))
1159
  $args["author__not_in"] = $arrExcludeByAuthors;
1160
  }
1178
  $arrPostsNotIn = $specificPostsToExclude;
1179
  else
1180
  $arrPostsNotIn = array_merge($arrPostsNotIn, $specificPostsToExclude);
 
1181
  }
1182
 
1183
  }
1184
 
1185
+ //exclude from dynamic field
1186
+
1187
+ if(!empty($arrExcludeIDsDynamic)){
1188
+
1189
+ if(empty($arrExcludeIDsDynamic))
1190
+ $arrPostsNotIn = $arrExcludeIDsDynamic;
1191
+ else
1192
+ $arrPostsNotIn = array_merge($arrPostsNotIn, $arrExcludeIDsDynamic);
1193
+ }
1194
+
1195
+
1196
+ // exclude duplicates
1197
+
1198
+ if(!empty(GlobalsProviderUC::$arrFetchedPostIDs)){
1199
+
1200
+ $arrFetchedIDs = array_keys(GlobalsProviderUC::$arrFetchedPostIDs);
1201
+
1202
+ if(empty($arrPostsNotIn))
1203
+ $arrPostsNotIn = $arrFetchedIDs;
1204
+ else
1205
+ $arrPostsNotIn = array_merge($arrPostsNotIn, $arrFetchedIDs);
1206
+
1207
+ }
1208
+
1209
+
1210
  //add the include by
1211
  $arrIncludeBy = UniteFunctionsUC::getVal($value, "{$name}_includeby");
1212
  if(empty($arrIncludeBy))
1225
  $arrIDsPopular = array();
1226
  $arrIDsPHPFunction = array();
1227
  $arrIDsPostMeta = array();
1228
+ $arrIDsDynamicField = array();
1229
 
 
1230
 
1231
+ $makePostINOrder = false;
1232
+
1233
  foreach($arrIncludeBy as $includeby){
1234
 
1235
  switch($includeby){
1284
 
1285
  $arrIncludeByAuthors = UniteFunctionsUC::getVal($value, "{$name}_includeby_authors");
1286
 
1287
+ //if set to current user, and no user logged in, then get no posts at all
1288
+ $authorMakeZero = false;
1289
+ foreach($arrIncludeByAuthors as $key => $userID){
1290
+
1291
+ if($userID == "uc_loggedin_user"){
1292
+
1293
+ $userID = get_current_user_id();
1294
+ $arrIncludeByAuthors[$key] = $userID;
1295
+
1296
+ if(empty($userID))
1297
+ $authorMakeZero = true;
1298
+ }
1299
+
1300
+ }
1301
+
1302
+ if($authorMakeZero == true)
1303
+ $arrIncludeByAuthors = array("0");
1304
+
1305
  if(!empty($arrIncludeByAuthors))
1306
  $args["author__in"] = $arrIncludeByAuthors;
1307
 
1406
  $arrIDsPostMeta = $this->getPostListData_getIDsFromPostMeta($value, $name, $showDebugQuery);
1407
 
1408
  break;
1409
+ case "ids_from_dynamic":
1410
+
1411
+ $arrIDsDynamicField = UniteFunctionsUC::getVal($value, $name."_includeby_dynamic_field");
1412
+
1413
+ $arrIDsDynamicField = UniteFunctionsUC::getIDsArray($arrIDsDynamicField);
1414
+
1415
+ break;
1416
  }
1417
 
1418
  }
1443
  $makePostINOrder = true;
1444
  }
1445
 
1446
+ if(!empty($arrIDsDynamicField)){
1447
+ $arrPostInIDs = $arrIDsDynamicField;
1448
+ $makePostINOrder = true;
1449
+ }
1450
+
1451
+
1452
  //make order as "post__id"
1453
 
1454
  if($makePostINOrder == true){
1494
  $args["meta_query"] = $arrMetaQuery;
1495
 
1496
  //add exclude specific posts if available
1497
+ if(!empty($arrPostsNotIn)){
1498
+ $arrPostsNotIn = array_unique($arrPostsNotIn);
1499
  $args["post__not_in"] = $arrPostsNotIn;
1500
+ }
1501
 
1502
  $isWpmlExists = UniteCreatorWpmlIntegrate::isWpmlExists();
1503
  if($isWpmlExists)
1578
  //save last query
1579
  GlobalsProviderUC::$lastPostQuery = $query;
1580
 
1581
+ //remember duplicate posts
1582
+ if($isAvoidDuplicates == true){
1583
+ foreach($arrPosts as $post)
1584
+ GlobalsProviderUC::$arrFetchedPostIDs[$post->ID] = true;
1585
+ }
1586
+
1587
  HelperUC::addDebug("posts found: ".count($arrPosts));
1588
 
1589
  if($showDebugQuery == true){
1590
  dmp("Found Posts: ".count($arrPosts));
1591
  }
1592
+
1593
 
1594
  return($arrPosts);
1595
  }
1710
 
1711
  $postIDs = UniteFunctionsUC::getVal($value, $name."_manual_select_post_ids");
1712
 
1713
+ if(empty($postIDs))
1714
+ $postIDs = array();
1715
+
1716
+ //post id's by dynamic text field
1717
+
1718
+ $dynamicIDs = UniteFunctionsUC::getVal($value, $name."_manual_post_ids_dynamic");
1719
+
1720
+ $arrDynamicIDs = UniteFunctionsUC::getIDsArray($dynamicIDs);
1721
+
1722
+ if(!empty($arrDynamicIDs))
1723
+ $postIDs = array_merge($postIDs, $arrDynamicIDs);
1724
+
1725
+
1726
  $showDebugQuery = UniteFunctionsUC::getVal($value, "{$name}_show_query_debug");
1727
  $showDebugQuery = UniteFunctionsUC::strToBool($showDebugQuery);
1728
 
2263
  */
2264
  private function getPostListData_getPostGetFilters_filters($filters){
2265
 
2266
+ if(GlobalsUC::$inDev == false) //filters
2267
  return($filters);
2268
 
2269
  $objFiltersProcess = new UniteCreatorFiltersProcess();
2861
  return($htmlMenu);
2862
  }
2863
 
2864
+
2865
+ protected function z_______________TEMPLATE____________(){}
2866
+
2867
  /**
2868
  * get template data
2869
  */
2874
  if(empty($templateID))
2875
  return($data);
2876
 
2877
+ if($templateID == "__none__")
2878
+ $templateID = "";
2879
 
2880
+ if(empty($templateID))
2881
+ $shortcode = "";
2882
+ else
2883
+ $shortcode = "[elementor-template id=\"$templateID\"]";
2884
+
2885
  $data[$name] = $shortcode;
2886
  $data[$name."_templateid"] = $templateID;
2887
 
2888
  return($data);
2889
  }
2890
 
 
2891
 
2892
+ protected function z_______________GET_PARAMS____________(){}
2893
 
2894
 
2895
  /**
provider/provider_settings.class.php CHANGED
@@ -57,10 +57,18 @@ class UniteCreatorSettings extends UniteCreatorSettingsWork{
57
  */
58
  protected function addTemplatePicker($name,$value,$title,$extra){
59
 
60
- $this->addPostIDSelect($name."_templateid", "Choose Template", null, "elementor_template");
 
 
 
 
 
 
 
61
 
62
  }
63
 
 
64
  /**
65
  * get categories from all post types
66
  */
@@ -964,7 +972,7 @@ class UniteCreatorSettings extends UniteCreatorSettingsWork{
964
  $params["datasource"] = "post_type";
965
  $params["origtype"] = "uc_select_special";
966
  $params["label_block"] = true;
967
-
968
  if(!empty($elementorCondition))
969
  $params["elementor_condition"] = $elementorCondition;
970
 
@@ -1200,7 +1208,7 @@ class UniteCreatorSettings extends UniteCreatorSettingsWork{
1200
  $arrIncludeBy["most_viewed"] = __("Most Viewed", "unlimited-elements-for-elementor");
1201
  $arrIncludeBy["php_function"] = __("IDs from PHP function","unlimited-elements-for-elementor");
1202
  $arrIncludeBy["ids_from_meta"] = __("IDs from Post Meta","unlimited-elements-for-elementor");
1203
-
1204
 
1205
  if($isForWooProducts == true){
1206
  $arrIncludeBy["products_on_sale"] = __("Products On Sale Only (woo)","unlimited-elements-for-elementor");
@@ -1225,19 +1233,20 @@ class UniteCreatorSettings extends UniteCreatorSettingsWork{
1225
 
1226
  $this->addMultiSelect($name."_includeby", $arrIncludeBy, esc_html__("Include By", "unlimited-elements-for-elementor"), $includeBy, $params);
1227
 
1228
- //--- add hr after include by----
1229
-
1230
- $params = array();
1231
- $params["origtype"] = UniteCreatorDialogParam::PARAM_HR;
1232
-
1233
- $params["elementor_condition"] = $arrConditionIncludeBy;
1234
-
1235
- $this->addHr($name."_after_include_by",$params);
1236
 
1237
- //---- Include By Author -----
 
 
 
 
 
1238
 
1239
- $arrAuthors = UniteFunctionsWPUC::getArrAuthorsShort();
1240
 
 
 
 
 
1241
  $params = array();
1242
  $params["origtype"] = UniteCreatorDialogParam::PARAM_DROPDOWN;
1243
  $params["is_multiple"] = true;
@@ -1250,6 +1259,7 @@ class UniteCreatorSettings extends UniteCreatorSettingsWork{
1250
 
1251
  $arrAuthors = array_flip($arrAuthors);
1252
 
 
1253
  $this->addMultiSelect($name."_includeby_authors", $arrAuthors, __("Include By Author", "unlimited-elements-for-elementor"), "", $params);
1254
 
1255
  //---- Include By Date -----
@@ -1398,6 +1408,20 @@ class UniteCreatorSettings extends UniteCreatorSettingsWork{
1398
  $params["elementor_condition"] = $arrConditionIncludePostMeta;
1399
 
1400
  $this->addTextBox($name."_includeby_postmeta_metafield", "", esc_html__("Meta Field Name", "unlimited-elements-for-elementor"), $params);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1401
 
1402
 
1403
  // --------- include by most viewed -------------
@@ -1521,6 +1545,19 @@ class UniteCreatorSettings extends UniteCreatorSettingsWork{
1521
  $textManualSelect = sprintf(__("Seach And Select %s"), $textPosts);
1522
 
1523
  $this->addPostIDSelect($name."_manual_select_post_ids", $textManualSelect, $arrManualElementorCondition, $isForWooProducts);
 
 
 
 
 
 
 
 
 
 
 
 
 
1524
 
1525
  // --------- add hr before exclude -------------
1526
 
@@ -1548,6 +1585,8 @@ class UniteCreatorSettings extends UniteCreatorSettingsWork{
1548
  $arrExclude["current_category"] = sprintf(__("%s with Current Category", "unlimited-elements-for-elementor"),$textPosts);
1549
  $arrExclude["current_tags"] = sprintf(__("%s With Current Tags", "unlimited-elements-for-elementor"),$textPosts);
1550
  $arrExclude["offset"] = sprintf(__("Offset", "unlimited-elements-for-elementor"),$textPosts);
 
 
1551
 
1552
  $params = array();
1553
  $params["origtype"] = UniteCreatorDialogParam::PARAM_DROPDOWN;
@@ -1562,7 +1601,34 @@ class UniteCreatorSettings extends UniteCreatorSettingsWork{
1562
  $arrExcludeValues = "";
1563
 
1564
  $this->addMultiSelect($name."_excludeby", $arrExclude, __("Exclude By", "unlimited-elements-for-elementor"), $arrExcludeValues, $params);
 
 
 
 
 
1565
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1566
  //------- Exclude By --- TERM --------
1567
 
1568
  $params = $paramsTermSelect;
57
  */
58
  protected function addTemplatePicker($name,$value,$title,$extra){
59
 
60
+ $arrTemplates = HelperProviderCoreUC_EL::getArrElementorTemplatesShort();
61
+ $arrTemplates = UniteFunctionsUC::addArrFirstValue($arrTemplates, __("[No Template Selected]","unlimited-elements-for-elementor"),"__none__");
62
+ $arrTemplates = array_flip($arrTemplates);
63
+
64
+ $params = array();
65
+ $params["origtype"] = "select2";
66
+
67
+ $this->addSelect($name."_templateid", $arrTemplates, __("Choose Template","unlimited-elements-for-elementor"),"__none__", $params);
68
 
69
  }
70
 
71
+
72
  /**
73
  * get categories from all post types
74
  */
972
  $params["datasource"] = "post_type";
973
  $params["origtype"] = "uc_select_special";
974
  $params["label_block"] = true;
975
+
976
  if(!empty($elementorCondition))
977
  $params["elementor_condition"] = $elementorCondition;
978
 
1208
  $arrIncludeBy["most_viewed"] = __("Most Viewed", "unlimited-elements-for-elementor");
1209
  $arrIncludeBy["php_function"] = __("IDs from PHP function","unlimited-elements-for-elementor");
1210
  $arrIncludeBy["ids_from_meta"] = __("IDs from Post Meta","unlimited-elements-for-elementor");
1211
+ $arrIncludeBy["ids_from_dynamic"] = __("IDs from Dynamic Field","unlimited-elements-for-elementor");
1212
 
1213
  if($isForWooProducts == true){
1214
  $arrIncludeBy["products_on_sale"] = __("Products On Sale Only (woo)","unlimited-elements-for-elementor");
1233
 
1234
  $this->addMultiSelect($name."_includeby", $arrIncludeBy, esc_html__("Include By", "unlimited-elements-for-elementor"), $includeBy, $params);
1235
 
1236
+ //--- add hr after include by----
 
 
 
 
 
 
 
1237
 
1238
+ $params = array();
1239
+ $params["origtype"] = UniteCreatorDialogParam::PARAM_HR;
1240
+
1241
+ $params["elementor_condition"] = $arrConditionIncludeBy;
1242
+
1243
+ $this->addHr($name."_after_include_by",$params);
1244
 
 
1245
 
1246
+ //---- Include By Author -----
1247
+
1248
+ $arrAuthors = UniteFunctionsWPUC::getArrAuthorsShort(true);
1249
+
1250
  $params = array();
1251
  $params["origtype"] = UniteCreatorDialogParam::PARAM_DROPDOWN;
1252
  $params["is_multiple"] = true;
1259
 
1260
  $arrAuthors = array_flip($arrAuthors);
1261
 
1262
+
1263
  $this->addMultiSelect($name."_includeby_authors", $arrAuthors, __("Include By Author", "unlimited-elements-for-elementor"), "", $params);
1264
 
1265
  //---- Include By Date -----
1408
  $params["elementor_condition"] = $arrConditionIncludePostMeta;
1409
 
1410
  $this->addTextBox($name."_includeby_postmeta_metafield", "", esc_html__("Meta Field Name", "unlimited-elements-for-elementor"), $params);
1411
+
1412
+ //----- include id's from dynamic field -------
1413
+
1414
+ $arrConditionIncludeDynamic = $arrConditionIncludeBy;
1415
+ $arrConditionIncludeDynamic[$name."_includeby"] = "ids_from_dynamic";
1416
+
1417
+ $params = array();
1418
+ $params["origtype"] = UniteCreatorDialogParam::PARAM_TEXTFIELD;
1419
+ $params["description"] = __("Enter post id's like 45,65,76, or select from dynamic tag","unlimited-elements-for-elementor");
1420
+ $params["elementor_condition"] = $arrConditionIncludeDynamic;
1421
+ $params["label_block"] = true;
1422
+ $params["add_dynamic"] = true;
1423
+
1424
+ $this->addTextBox($name."_includeby_dynamic_field","",__("Include Posts by Dynamic Field","unlimited-elements-for-elementor"), $params);
1425
 
1426
 
1427
  // --------- include by most viewed -------------
1545
  $textManualSelect = sprintf(__("Seach And Select %s"), $textPosts);
1546
 
1547
  $this->addPostIDSelect($name."_manual_select_post_ids", $textManualSelect, $arrManualElementorCondition, $isForWooProducts);
1548
+
1549
+ // --------- add dynamic post ids -------------
1550
+
1551
+ $params = array();
1552
+ $params["origtype"] = UniteCreatorDialogParam::PARAM_TEXTFIELD;
1553
+
1554
+ $params["elementor_condition"] = $arrManualElementorCondition;
1555
+ $params["add_dynamic"] = true;
1556
+ $params["label_block"] = true;
1557
+ $params["description"] = "Optional. Select some dynamic field, that has output of post ids (string or array) like 15,40,23";
1558
+
1559
+ $this->addTextBox($name."_manual_post_ids_dynamic", "", __("Or Select Post IDs by Dynamic Field", "unlimited-elements-for-elementor"), $params);
1560
+
1561
 
1562
  // --------- add hr before exclude -------------
1563
 
1585
  $arrExclude["current_category"] = sprintf(__("%s with Current Category", "unlimited-elements-for-elementor"),$textPosts);
1586
  $arrExclude["current_tags"] = sprintf(__("%s With Current Tags", "unlimited-elements-for-elementor"),$textPosts);
1587
  $arrExclude["offset"] = sprintf(__("Offset", "unlimited-elements-for-elementor"),$textPosts);
1588
+ $arrExclude["avoid_duplicates"] = sprintf(__("Avoid Duplicates", "unlimited-elements-for-elementor"),$textPosts);
1589
+ $arrExclude["ids_from_dynamic"] = sprintf(__("IDs from Dynamic Field", "unlimited-elements-for-elementor"),$textPosts);
1590
 
1591
  $params = array();
1592
  $params["origtype"] = UniteCreatorDialogParam::PARAM_DROPDOWN;
1601
  $arrExcludeValues = "";
1602
 
1603
  $this->addMultiSelect($name."_excludeby", $arrExclude, __("Exclude By", "unlimited-elements-for-elementor"), $arrExcludeValues, $params);
1604
+
1605
+ //----- exclude id's from dynamic field -------
1606
+
1607
+ $conditionExcludeByDynamic = $conditionExcludeBy;
1608
+ $conditionExcludeByDynamic[$name."_excludeby"] = "ids_from_dynamic";
1609
 
1610
+ $params = array();
1611
+ $params["origtype"] = UniteCreatorDialogParam::PARAM_TEXTFIELD;
1612
+ $params["description"] = __("Enter post id's like 45,65,76, or select from dynamic tag","unlimited-elements-for-elementor");
1613
+ $params["elementor_condition"] = $conditionExcludeByDynamic;
1614
+ $params["label_block"] = true;
1615
+ $params["add_dynamic"] = true;
1616
+
1617
+ $this->addTextBox($name."_exclude_dynamic_field","",__("Exclude Posts by Dynamic Field","unlimited-elements-for-elementor"), $params);
1618
+
1619
+
1620
+ //------- Already Fetched --------
1621
+
1622
+ $conditionExcludeByFetched = $conditionExcludeBy;
1623
+ $conditionExcludeByFetched[$name."_excludeby"] = "avoid_duplicates";
1624
+
1625
+ $params = array();
1626
+ $params["origtype"] = UniteCreatorDialogParam::PARAM_STATIC_TEXT;
1627
+ $params["elementor_condition"] = $conditionExcludeByFetched;
1628
+
1629
+ $this->addStaticText(__("Avoid duplicate posts, that fetched by another post widgets in the page, and have this option seleted (avoid duplicates)","unlimited-elements-for-elementor"), $name."_alreadyfethcedtext", $params);
1630
+
1631
+
1632
  //------- Exclude By --- TERM --------
1633
 
1634
  $params = $paramsTermSelect;
provider/provider_web_api.class.php CHANGED
@@ -114,12 +114,12 @@ class UniteCreatorWebAPI extends UniteCreatorWebAPIWork{
114
  public function getCatalogArray($objAddonsType){
115
 
116
  $arrCatalogItems = parent::getCatalogArray($objAddonsType);
117
-
118
  if($objAddonsType->isLayout == true)
119
  return($arrCatalogItems);
120
 
121
  $arrCatalogItems = $this->filterCatalogAddons($arrCatalogItems);
122
-
123
  return($arrCatalogItems);
124
  }
125
 
114
  public function getCatalogArray($objAddonsType){
115
 
116
  $arrCatalogItems = parent::getCatalogArray($objAddonsType);
117
+
118
  if($objAddonsType->isLayout == true)
119
  return($arrCatalogItems);
120
 
121
  $arrCatalogItems = $this->filterCatalogAddons($arrCatalogItems);
122
+
123
  return($arrCatalogItems);
124
  }
125
 
readme.txt CHANGED
@@ -499,6 +499,18 @@ Note : This plugin works with Elementor. Make sure you have [Elementor](https://
499
 
500
  == Changelog ==
501
 
 
 
 
 
 
 
 
 
 
 
 
 
502
  version 1.4.74 = 2021-06-02
503
 
504
  * Feature: added function put_date_range to twig functions. good for events widgets
499
 
500
  == Changelog ==
501
 
502
+ version 1.4.75 = 2021-06-21
503
+
504
+ * Feature: added category image to products list
505
+ * Feature: added option to include as module widget js include
506
+ * Feature: added option to write custom handle to widget js and css include
507
+ * Feature: added options - avoid duplicate posts to post query exclude
508
+ * Feature: added option to include or exclude posts by dynamic field to posts selection
509
+ * Feature: added option to include or exclude posts by logged in user, in posts selection
510
+ * Fix: fixed background widget condition functionality
511
+ * Fix: changed template picker to simple select2 list
512
+
513
+
514
  version 1.4.74 = 2021-06-02
515
 
516
  * Feature: added function put_date_range to twig functions. good for events widgets
release_log.txt CHANGED
@@ -1,4 +1,16 @@
1
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  version 1.4.74
3
 
4
  -feature: added function put_date_range to twig functions. good for events widgets
1
 
2
+ version 1.4.75
3
+
4
+ -feature: added category image to products list
5
+ -feature: added option to include as module widget js include
6
+ -feature: added option to write custom handle to widget js and css include
7
+ -feature: added options - avoid duplicate posts to post query exclude
8
+ -feature: added option to include or exclude posts by dynamic field to posts selection
9
+ -feature: added option to include or exclude posts by logged in user, in posts selection
10
+ -bug fix: fixed background widget condition functionality
11
+ -change: changed template picker to simple select2 list
12
+
13
+
14
  version 1.4.74
15
 
16
  -feature: added function put_date_range to twig functions. good for events widgets
temp/index.html DELETED
File without changes
unlimited_elements.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Unlimited Elements for Elementor
4
  Plugin URI: http://unlimited-elements.com
5
  Description: Unlimited Elements - Huge Widgets Pack for Elementor Page Builder, with html/css/js widget creator and editor
6
  Author: Unlimited Elements
7
- Version: 1.4.74
8
  Author URI: http://unlimited-elements.com
9
  Text Domain: unlimited-elements-for-elementor
10
  Domain Path: /languages
4
  Plugin URI: http://unlimited-elements.com
5
  Description: Unlimited Elements - Huge Widgets Pack for Elementor Page Builder, with html/css/js widget creator and editor
6
  Author: Unlimited Elements
7
+ Version: 1.4.75
8
  Author URI: http://unlimited-elements.com
9
  Text Domain: unlimited-elements-for-elementor
10
  Domain Path: /languages
views/objects/addon_view.class.php CHANGED
@@ -610,15 +610,37 @@ class UniteCreatorAddonView{
610
  </span>
611
 
612
  <?php HelperHtmlUC::putDialogControlFieldsNotice() ?>
 
 
 
 
 
 
 
 
 
 
613
 
614
  <div class="vert_sap10"></div>
615
 
616
- <label>
617
- <input id="uc_dialog_include_after_elementor_frontend" type="checkbox" name="include_after_elementor_frontend">
618
- &nbsp;
619
- <?php _e("Include after elementor-frontend.js", "unlimited-elements-for-elementor")?>
 
 
 
 
620
 
621
- </label>
 
 
 
 
 
 
 
 
622
 
623
  </div>
624
  </div>
610
  </span>
611
 
612
  <?php HelperHtmlUC::putDialogControlFieldsNotice() ?>
613
+
614
+ <div class="vert_sap20"></div>
615
+
616
+ <label class="unite-inputs-label">
617
+ <?php _e("Handle")?>
618
+ </label>
619
+
620
+ <input type="text" name="include_handle" class="unite-input-alias">
621
+
622
+ <i>* <?php _e("leave empty for auto", "unlimited-elements-for-elementor")?></i>
623
 
624
  <div class="vert_sap10"></div>
625
 
626
+ <div class="uc-dialog-includes-js">
627
+
628
+ <label>
629
+ <input id="uc_dialog_include_after_elementor_frontend" type="checkbox" name="include_after_elementor_frontend">
630
+ &nbsp;
631
+ <?php _e("Include after elementor-frontend.js", "unlimited-elements-for-elementor")?>
632
+
633
+ </label>
634
 
635
+ <div class="vert_sap10"></div>
636
+ <label>
637
+ <input id="uc_dialog_include_as_module" type="checkbox" name="include_as_module">
638
+ &nbsp;
639
+ <?php _e("Include as ES6 module", "unlimited-elements-for-elementor")?>
640
+
641
+ </label>
642
+
643
+ </div>
644
 
645
  </div>
646
  </div>
views/objects/addon_view_childparams.class.php CHANGED
@@ -365,6 +365,7 @@ jQuery(document).ready(function(){
365
  $arrParams[] = $this->createChildParam("category_name");
366
  $arrParams[] = $this->createChildParam("category_slug");
367
  $arrParams[] = $this->createChildParam("category_link");
 
368
 
369
  //create categories array foreach
370
 
365
  $arrParams[] = $this->createChildParam("category_name");
366
  $arrParams[] = $this->createChildParam("category_slug");
367
  $arrParams[] = $this->createChildParam("category_link");
368
+ $arrParams[] = $this->createChildParam("category_image");
369
 
370
  //create categories array foreach
371
 
views/troubleshooting-api-access.php DELETED
@@ -1,101 +0,0 @@
1
-
2
- <h1>Unlimited Elements - API Access Test</h1>
3
-
4
- <br>
5
-
6
- <?php
7
-
8
- /**
9
- * check zip file request
10
- */
11
- function checkZipFile(){
12
-
13
- //request single file
14
- $urlAPI = GlobalsUC::URL_API;
15
-
16
- $arrPost = array(
17
- "action"=>"get_addon_zip",
18
- "name"=>"blox_particles_logo",
19
- "cat"=>"Extras",
20
- "type"=>"addons",
21
- "catalog_date"=>"1563618449",
22
- "code"=>""
23
- );
24
-
25
-
26
- dmp("requesting widget zip from API");
27
-
28
- $response = UniteFunctionsUC::getUrlContents($urlAPI, $arrPost);
29
-
30
- if(empty($response))
31
- UniteFunctionsUC::throwError("Empty server response");
32
-
33
- $len = strlen($response);
34
-
35
- print_r("api response OK, recieve string size: $len");
36
-
37
- }
38
-
39
-
40
- /**
41
- * check zip file request
42
- */
43
- function checkCatalogRequest(){
44
-
45
- //request single file
46
- $urlAPI = GlobalsUC::URL_API;
47
-
48
- $arrPost = array(
49
- "action"=>"check_catalog",
50
- "catalog_date"=>"1563618449",
51
- "include_pages"=>false,
52
- "domain"=>"localhost",
53
- "platform"=>"wp"
54
- );
55
-
56
- dmp("requesting catalog check");
57
-
58
- $response = UniteFunctionsUC::getUrlContents($urlAPI, $arrPost);
59
-
60
- if(empty($response))
61
- UniteFunctionsUC::throwError("Empty server response");
62
-
63
- $len = strlen($response);
64
-
65
- print_r("api response OK, recieve string size: $len");
66
-
67
- }
68
-
69
- /**
70
- * various
71
- */
72
- function checkVariousOptions(){
73
-
74
- dmp("checking file get contents");
75
-
76
- $urlAPI = GlobalsUC::URL_API;
77
- $response = file_get_contents($urlAPI);
78
-
79
- $len = strlen($response);
80
-
81
- dmp("file get contents OK, recieve string size: $len");
82
-
83
- }
84
-
85
- try{
86
-
87
- checkVariousOptions();
88
-
89
- echo "<br><br>";
90
-
91
- //checkCatalogRequest();
92
-
93
- echo "<br><br>";
94
-
95
- //checkZipFile();
96
-
97
-
98
- }catch(Exception $e){
99
- echo $e->getMessage();
100
- }
101
-