Auto Terms of Service and Privacy Policy - Version 2.2.2

Version Description

Download this release

Release Info

Developer wpautoterms
Plugin Icon Auto Terms of Service and Privacy Policy
Version 2.2.2
Comparing to
See all releases

Code changes from version 2.2.1 to 2.2.2

Files changed (69) hide show
  1. README.txt +20 -4
  2. auto-terms-of-service-privacy-policy.php +6 -8
  3. css/admin.css +180 -2
  4. css/admin.min.css +1 -1
  5. css/jquery-ui-accordion.css +52 -0
  6. css/jquery-ui-themes/base/theme.css +236 -0
  7. css/jquery-ui.structure.css +886 -0
  8. css/page-help.css +63 -0
  9. css/post-new.css +0 -5
  10. includes/action-base.php +7 -0
  11. includes/admin/admin.php +28 -11
  12. includes/admin/menu.php +2 -2
  13. includes/admin/options.php +5 -2
  14. includes/admin/page/compliancekits.php +4 -1
  15. includes/admin/page/{contact.php → help.php} +6 -1
  16. includes/admin/page/settings-page.php +4 -0
  17. includes/admin/review-banner.php +36 -0
  18. includes/box/box.php +53 -2
  19. includes/box/cookies-notice-box.php +8 -0
  20. includes/box/endorsements-box.php +12 -0
  21. includes/box/links-box.php +9 -0
  22. includes/box/update-notice-box.php +9 -1
  23. includes/cpt/admin-columns.php +17 -1
  24. includes/cpt/cpt.php +60 -26
  25. includes/frontend.php +17 -5
  26. includes/frontend/endorsements.php +5 -1
  27. includes/frontend/links.php +6 -3
  28. includes/frontend/notice/cookies-notice.php +3 -1
  29. includes/frontend/notice/update-notice.php +3 -1
  30. includes/frontend/pages-widget-extend.php +33 -0
  31. includes/frontend/widget.php +146 -0
  32. includes/option/option.php +3 -2
  33. includes/shortcode/i-shortcode-handler.php +11 -0
  34. includes/shortcode/post-base.php +22 -0
  35. includes/shortcode/shortcode.php +12 -5
  36. includes/shortcode/sub-shortcode.php +1 -1
  37. includes/shortcodes.php +1 -0
  38. includes/upgrade.php +2 -2
  39. includes/wpautoterms.php +4 -1
  40. js/codemirror-5.42.0/addon/edit/closebrackets.js +187 -0
  41. js/codemirror-5.42.0/addon/edit/matchbrackets.js +145 -0
  42. js/codemirror-5.42.0/addon/hint/css-hint.js +60 -0
  43. js/codemirror-5.42.0/addon/hint/show-hint.css +36 -0
  44. js/codemirror-5.42.0/addon/hint/show-hint.js +436 -0
  45. js/codemirror-5.42.0/addon/scroll/annotatescrollbar.js +122 -0
  46. js/codemirror-5.42.0/addon/search/match-highlighter.js +165 -0
  47. js/codemirror-5.42.0/addon/search/matchesonscrollbar.css +8 -0
  48. js/codemirror-5.42.0/addon/search/matchesonscrollbar.js +97 -0
  49. js/codemirror-5.42.0/addon/search/searchcursor.js +293 -0
  50. js/codemirror-5.42.0/addon/selection/active-line.js +72 -0
  51. js/codemirror-5.42.0/codemirror.css +346 -0
  52. js/codemirror-5.42.0/codemirror.js +9725 -0
  53. js/codemirror-5.42.0/css.js +832 -0
  54. js/common.js +35 -0
  55. js/compliancekits-page.js +2 -2
  56. js/contact-form.js +12 -0
  57. js/css-hints.js +55 -0
  58. js/kits.js +12 -0
  59. js/post-new.js +1 -1
  60. js/wpautoterms.js +1 -2
  61. templates/cookies-notice.php +9 -2
  62. templates/links.php +6 -2
  63. templates/options/css-textarea-option.php +44 -0
  64. templates/pages/contact.php +0 -147
  65. templates/pages/help-q-a.php +21 -0
  66. templates/pages/help.php +165 -0
  67. templates/review-banner.php +15 -0
  68. templates/update-notice.php +9 -2
  69. uninstall.php +7 -11
README.txt CHANGED
@@ -2,9 +2,9 @@
2
  Contributors: wpautoterms
3
  Tags: gdpr, privacy policy, terms and conditions, terms of service, terms of use, disclosure, disclaimer, affiliate, cookies, cookie consent, legal
4
  Requires at least: 4.2
5
- Tested up to: 4.9.7
6
  Requires PHP: 5.3
7
- Stable tag: 2.2.1
8
  License: GPL version 3 or any later version
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
@@ -48,6 +48,10 @@ WP AutoTerms is provided with the purpose of helping you with compliance. While
48
 
49
  We're just getting started. Have a chat with us and let us know what you'd like to see added.
50
 
 
 
 
 
51
  == Frequently Asked Questions ==
52
 
53
  = Is WP AutoTerms free? =
@@ -59,9 +63,9 @@ A premium license is available to purchase as a one-time fee if you'd like to up
59
  - Include a Cookies Notice banner
60
  - Inform users of your affiliate links usage
61
 
62
- = What legal agreements can I create with WPAutoTerms? =
63
 
64
- You can create the following legal agreements with WPAutoTerms:
65
 
66
  - Terms & Conditions
67
  - Privacy Policy
@@ -113,6 +117,18 @@ Installing the plugin is easy. Just follow these steps:
113
 
114
  == Changelog ==
115
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  = Version 2.2.1 =
117
  * Nov 09, 2018
118
  * Allow for the license key to be used on multiple websites
2
  Contributors: wpautoterms
3
  Tags: gdpr, privacy policy, terms and conditions, terms of service, terms of use, disclosure, disclaimer, affiliate, cookies, cookie consent, legal
4
  Requires at least: 4.2
5
+ Tested up to: 5.0.2
6
  Requires PHP: 5.3
7
+ Stable tag: 2.2.2
8
  License: GPL version 3 or any later version
9
  License URI: http://www.gnu.org/licenses/gpl-3.0.html
10
 
48
 
49
  We're just getting started. Have a chat with us and let us know what you'd like to see added.
50
 
51
+ == Honory Mention ==
52
+
53
+ Special thanks to this plugin's original author, Clifford Paulick of https://tourkick.com/
54
+
55
  == Frequently Asked Questions ==
56
 
57
  = Is WP AutoTerms free? =
63
  - Include a Cookies Notice banner
64
  - Inform users of your affiliate links usage
65
 
66
+ = What legal agreements can I create with WP AutoTerms? =
67
 
68
+ You can create the following legal agreements with WP AutoTerms:
69
 
70
  - Terms & Conditions
71
  - Privacy Policy
117
 
118
  == Changelog ==
119
 
120
+ = Version 2.2.2 =
121
+ * Jan 7, 2019
122
+ * Tested up to WordPress 5.0.2
123
+ * Short codes for generated Legal Pages
124
+ * Option for Pages Widget to list published legal pages
125
+ * Add our very own WP AutoTerms Legal Pages Widget
126
+ * CSS Syntax Highlighter for Additional CSS textarea
127
+ * Display CSS selectors related to WP AutoTerms in Additional CSS textarea
128
+ * Add Help page with FAQ section for faster support
129
+ * Bug fix for User Type capabilities
130
+ * Bug fix for maximum links when using Links to Legal Pages Compliance Kit
131
+
132
  = Version 2.2.1 =
133
  * Nov 09, 2018
134
  * Allow for the license key to be used on multiple websites
auto-terms-of-service-privacy-policy.php CHANGED
@@ -5,10 +5,10 @@ Plugin URI: https://wpautoterms.com
5
  Description: Create Privacy Policy (Simple or GDPR), Terms & Conditions, Disclaimers and more. Compliance Kits to help you be compliant with the law.
6
  Author: WP AutoTerms
7
  Author URI: https://wpautoterms.com
8
- Version: 2.2.1
9
  License: GPLv2 or later
10
  Text Domain: wpautoterms
11
- Domain Path: /languages
12
  */
13
 
14
  /*
@@ -45,6 +45,10 @@ if ( ! defined( 'ABSPATH' ) ) {
45
  exit;
46
  }
47
 
 
 
 
 
48
  define( 'WPAUTOTERMS_PLUGIN_URL', plugins_url( '/', __FILE__ ) );
49
  define( 'WPAUTOTERMS_PLUGIN_DIR', __DIR__ . DIRECTORY_SEPARATOR );
50
  define( 'WPAUTOTERMS_TAG', 'wpautoterms' );
@@ -81,13 +85,7 @@ define( 'WPAUTOTERMS_VERSION', get_version( __FILE__ ) );
81
 
82
  require_once WPAUTOTERMS_PLUGIN_DIR . 'api.php';
83
  require_once WPAUTOTERMS_PLUGIN_DIR . 'deactivate.php';
84
- require_once WPAUTOTERMS_PLUGIN_DIR . 'uninstall.php';
85
  register_deactivation_hook( __FILE__, '\wpautoterms\deactivate' );
86
- register_uninstall_hook( __FILE__, '\wpautoterms\uninstall' );
87
-
88
- if ( defined( 'WP_UNINSTALL_PLUGIN' ) ) {
89
- return;
90
- }
91
 
92
  require_once WPAUTOTERMS_PLUGIN_DIR . 'includes' . DIRECTORY_SEPARATOR . 'autoload.php';
93
 
5
  Description: Create Privacy Policy (Simple or GDPR), Terms & Conditions, Disclaimers and more. Compliance Kits to help you be compliant with the law.
6
  Author: WP AutoTerms
7
  Author URI: https://wpautoterms.com
8
+ Version: 2.2.2
9
  License: GPLv2 or later
10
  Text Domain: wpautoterms
11
+ Domain Path: /languages
12
  */
13
 
14
  /*
45
  exit;
46
  }
47
 
48
+ if ( defined( 'WP_UNINSTALL_PLUGIN' ) ) {
49
+ return;
50
+ }
51
+
52
  define( 'WPAUTOTERMS_PLUGIN_URL', plugins_url( '/', __FILE__ ) );
53
  define( 'WPAUTOTERMS_PLUGIN_DIR', __DIR__ . DIRECTORY_SEPARATOR );
54
  define( 'WPAUTOTERMS_TAG', 'wpautoterms' );
85
 
86
  require_once WPAUTOTERMS_PLUGIN_DIR . 'api.php';
87
  require_once WPAUTOTERMS_PLUGIN_DIR . 'deactivate.php';
 
88
  register_deactivation_hook( __FILE__, '\wpautoterms\deactivate' );
 
 
 
 
 
89
 
90
  require_once WPAUTOTERMS_PLUGIN_DIR . 'includes' . DIRECTORY_SEPARATOR . 'autoload.php';
91
 
css/admin.css CHANGED
@@ -140,7 +140,7 @@ ul.legal-pages-form-radio {
140
  }
141
 
142
  .wpautoterms-option-info {
143
- padding: 5px 2px;
144
  }
145
 
146
  .wpautoterms-pull-right {
@@ -157,4 +157,182 @@ ul.legal-pages-form-radio {
157
 
158
  .wpautoterms-resize-both {
159
  resize: both;
160
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  }
141
 
142
  .wpautoterms-option-info {
143
+ padding: 0;
144
  }
145
 
146
  .wpautoterms-pull-right {
157
 
158
  .wpautoterms-resize-both {
159
  resize: both;
160
+ }
161
+
162
+ .wpautoterms-flex {
163
+ display: flex;
164
+ }
165
+
166
+ .wpautoterms-w-3 {
167
+ flex: 3;
168
+ }
169
+
170
+ .wpautoterms-w-9 {
171
+ flex: 9;
172
+ }
173
+
174
+ .wpautoterms-pad-left {
175
+ padding-left: 1em;
176
+ }
177
+
178
+ .wpautoterms-bold {
179
+ font-weight: 600;
180
+ }
181
+
182
+ .cm-matchhighlight {
183
+ background-color: lightgreen
184
+ }
185
+
186
+ .CodeMirror-selection-highlight-scrollbar {
187
+ background-color: green
188
+ }
189
+
190
+ .CodeMirror {
191
+ resize: both;
192
+ }
193
+
194
+ .wpautoterms-list {
195
+ padding: 0 0 0 20px;
196
+ }
197
+
198
+ .wpautoterms-list li {
199
+ list-style-type: square;
200
+ }
201
+
202
+ .wpautoterms-custom-css-available-selectors {
203
+ padding: 20px;
204
+ margin-top: -5px;
205
+ background: #EEE;
206
+ box-shadow: inset 0 -1px 2px rgba(0, 0, 0, .07);
207
+ }
208
+
209
+ .wpautoterms-custom-css-available-selectors .wpautoterms-list {
210
+ margin-bottom: 0;
211
+ }
212
+
213
+ .wpautoterms-custom-css-available-selectors .wpautoterms-list li {
214
+ line-height: 25px;
215
+ margin: 0 0 10px 0;
216
+ }
217
+
218
+ .wpautoterms-custom-css-available-selectors .wpautoterms-selector-type {
219
+ display: block;
220
+ }
221
+
222
+ .wpautoterms-custom-css-available-selectors .wpautoterms-selector {
223
+ padding: 2px 4px;
224
+ background: #FFF;
225
+ border-radius: 5px;
226
+ }
227
+
228
+ #wpautoterms_links_custom_css,
229
+ #wpautoterms_update_notice_custom_css,
230
+ #wpautoterms_cookies_notice_custom_css,
231
+ #wpautoterms_endorsements_custom_css {
232
+ width: 100%;
233
+ min-height: 200px;
234
+ }
235
+
236
+ .wpautoterms-list {
237
+ padding: 0 0 0 20px;
238
+ }
239
+
240
+ .wpautoterms-list li {
241
+ list-style-type: square;
242
+ }
243
+
244
+ .wpautoterms-custom-css-available-selectors {
245
+ padding: 20px;
246
+ margin-top: -5px;
247
+ background: #EEE;
248
+ box-shadow: inset 0 -1px 2px rgba(0, 0, 0, .07);
249
+ }
250
+
251
+ .wpautoterms-custom-css-available-selectors .wpautoterms-list {
252
+ margin-bottom: 0;
253
+ }
254
+
255
+ .wpautoterms-custom-css-available-selectors .wpautoterms-list li {
256
+ line-height: 25px;
257
+ margin: 0 0 10px 0;
258
+ }
259
+
260
+ .wpautoterms-custom-css-available-selectors .wpautoterms-selector-type {
261
+ display: block;
262
+ }
263
+
264
+ .wpautoterms-custom-css-available-selectors .wpautoterms-selector {
265
+ padding: 2px 4px;
266
+ background: #FFF;
267
+ border-radius: 5px;
268
+ }
269
+
270
+ #wpautoterms_links_custom_css,
271
+ #wpautoterms_update_notice_custom_css,
272
+ #wpautoterms_cookies_notice_custom_css,
273
+ #wpautoterms_endorsements_custom_css {
274
+ width: 100%;
275
+ min-height: 200px;
276
+ }
277
+
278
+ .wpautoterms-review-banner {
279
+ padding: 30px;
280
+ }
281
+ .wpautoterms-review-banner h4 {
282
+ font-size: 20px;
283
+ margin: 0 0 10px 0;
284
+ }
285
+ .wpautoterms-review-banner p {
286
+ font-size: 16px;
287
+ }
288
+ .wpautoterms-review-banner p:last-child {
289
+ margin: 0;
290
+ }
291
+ .wpautoterms-review-banner .button-primary {
292
+ font-size: 16px;
293
+ }
294
+
295
+ .wpautoterms-is-dismissible {
296
+ padding-right: 38px;
297
+ position: relative;
298
+ }
299
+
300
+ .wpautoterms-dismiss-icon:before {
301
+ background: none;
302
+ color: #72777c;
303
+ content: "\f153";
304
+ display: inline-block;
305
+ font: normal 16px/20px dashicons;
306
+ text-align: center;
307
+ width: 20px;
308
+ vertical-align: middle;
309
+ }
310
+
311
+ .wpautoterms-dismiss-button {
312
+ position: absolute;
313
+ top: 0;
314
+ right: 1px;
315
+ border: none;
316
+ margin: 0;
317
+ padding: 9px;
318
+ background: none;
319
+ color: #72777c;
320
+ cursor: pointer;
321
+ }
322
+
323
+ .wpautoterms-dismiss-button:hover .wpautoterms-dismiss-icon:before,
324
+ .wpautoterms-dismiss-button:active .wpautoterms-dismiss-icon:before,
325
+ .wpautoterms-dismiss-button:focus .wpautoterms-dismiss-icon:before {
326
+ color: #c00;
327
+ }
328
+
329
+ .wpautoterms-dismiss-button:hover,
330
+ .wpautoterms-dismiss-button:active,
331
+ .wpautoterms-dismiss-button:focus {
332
+ color: #933;
333
+ }
334
+
335
+ .wpautoterms-dismiss-button:focus {
336
+ outline: none;
337
+ box-shadow: 0 0 0 1px #5b9dd9, 0 0 2px 1px rgba(30, 140, 190, .8);
338
+ }
css/admin.min.css CHANGED
@@ -1 +1 @@
1
- .inline-row-action-summary{display:block;width:100%!important}#legal-page-create-selector,.wpautoterms-hidden{display:none}#legal-page-create-selector ul,ul.legal-pages-form-checkbox-group,ul.legal-pages-form-radio{list-style-type:none}.wpautoterms-nopadding{padding:0}.wpautoterms-nomargin{margin:0}.wpautoterms-topalign{vertical-align:top}.wpautoterms-fullwidth{width:100%}.wpautoterms-options-box,.wpautoterms-options-header{width:300px;float:left;margin:1em 1em 0 0!important;background:0 0}.wpautoterms-options-header{border:0;box-shadow:none}.wpautoterms-options-header h3{padding:8px 0;margin:0}.wpautoterms-options-box{height:180px;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px}.wpautoterms-options-box.wpautoterms-paid{background-color:beige}.wpautoterms-options-box h3{padding:8px 12px;margin:0}.wpautoterms-options-box .inside{padding:0 12px}.wpautoterms-options-box .box-status{color:#000}.wpautoterms-options-box .box-status.enabled{color:green}.wpautoterms-options-box .box-status.disabled{color:#888}.wpautoterms-box-enable-button{position:absolute;bottom:8px;left:12px}.wpautoterms-box-configure-button{position:absolute;bottom:8px;right:12px}.wpautoterms-box-page-submit{float:left}.wpautoterms-box-page-back{float:left;padding:5px 0 0 20px}.wpautoterms-options-select-combo .inside{padding:4px}.wpautoterms-option-required{color:red}.wpautoterms-form-errors{color:red;padding:10px 0 0;margin:0}.wpautoterms-recheck-license-button{display:inline;margin-left:1em}.wpautoterms-recheck-license-button a{vertical-align:inherit!important}.wpautoterms-button-disabled{pointer-events:none;color:#d3d3d3!important}.wpautoterms-license-key{width:24em}.wpautoterms-option-info{padding:5px 2px}.wpautoterms-pull-right{float:right}.wpautoterms-clear{clear:both}.wpautoterms-wrapper{display:inline-block}.wpautoterms-resize-both{resize:both}
1
+ .inline-row-action-summary{display:block;width:100%!important;}#legal-page-create-selector{display:none;}#legal-page-create-selector ul{list-style-type:none;}ul.legal-pages-form-checkbox-group,ul.legal-pages-form-radio{list-style-type:none;}.wpautoterms-nopadding{padding:0;}.wpautoterms-nomargin{margin:0;}.wpautoterms-topalign{vertical-align:top;}.wpautoterms-fullwidth{width:100%;}.wpautoterms-options-header,.wpautoterms-options-box{width:300px;float:left;margin:1em 1em 0 0!important;background:none;}.wpautoterms-options-header{border:0;box-shadow:none;}.wpautoterms-options-header h3{padding:8px 0;margin:0;}.wpautoterms-options-box{height:180px;-webkit-border-radius:6px;-moz-border-radius:6px;border-radius:6px;}.wpautoterms-options-box.wpautoterms-paid{background-color:beige;}.wpautoterms-options-box h3{padding:8px 12px;margin:0;}.wpautoterms-options-box .inside{padding:0 12px;}.wpautoterms-options-box .box-status{color:#000;}.wpautoterms-options-box .box-status.enabled{color:green;}.wpautoterms-options-box .box-status.disabled{color:#888;}.wpautoterms-box-enable-button{position:absolute;bottom:8px;left:12px;}.wpautoterms-box-configure-button{position:absolute;bottom:8px;right:12px;}.wpautoterms-box-page-submit{float:left;}.wpautoterms-box-page-back{float:left;padding:5px 0 0 20px;}.wpautoterms-hidden{display:none;}.wpautoterms-options-select-combo .inside{padding:4px;}.wpautoterms-option-required{color:red;}.wpautoterms-form-errors{color:red;padding:10px 0 0 0;margin:0;}.wpautoterms-recheck-license-button{display:inline;margin-left:1em;}.wpautoterms-recheck-license-button a{vertical-align:inherit!important;}.wpautoterms-button-disabled{pointer-events:none;color:lightgray!important;}.wpautoterms-license-key{width:24em;}.wpautoterms-option-info{padding:0;}.wpautoterms-pull-right{float:right;}.wpautoterms-clear{clear:both;}.wpautoterms-wrapper{display:inline-block;}.wpautoterms-resize-both{resize:both;}.wpautoterms-flex{display:flex;}.wpautoterms-w-3{flex:3;}.wpautoterms-w-9{flex:9;}.wpautoterms-pad-left{padding-left:1em;}.wpautoterms-bold{font-weight:600;}.cm-matchhighlight{background-color:lightgreen;}.CodeMirror-selection-highlight-scrollbar{background-color:green;}.CodeMirror{resize:both;}.wpautoterms-list{padding:0 0 0 20px;}.wpautoterms-list li{list-style-type:square;}.wpautoterms-custom-css-available-selectors{padding:20px;margin-top:-5px;background:#EEE;box-shadow:inset 0 -1px 2px rgba(0,0,0,.07);}.wpautoterms-custom-css-available-selectors .wpautoterms-list{margin-bottom:0;}.wpautoterms-custom-css-available-selectors .wpautoterms-list li{line-height:25px;margin:0 0 10px 0;}.wpautoterms-custom-css-available-selectors .wpautoterms-selector-type{display:block;}.wpautoterms-custom-css-available-selectors .wpautoterms-selector{padding:2px 4px;background:#FFF;border-radius:5px;}#wpautoterms_links_custom_css,#wpautoterms_update_notice_custom_css,#wpautoterms_cookies_notice_custom_css,#wpautoterms_endorsements_custom_css{width:100%;min-height:200px;}.wpautoterms-list{padding:0 0 0 20px;}.wpautoterms-list li{list-style-type:square;}.wpautoterms-custom-css-available-selectors{padding:20px;margin-top:-5px;background:#EEE;box-shadow:inset 0 -1px 2px rgba(0,0,0,.07);}.wpautoterms-custom-css-available-selectors .wpautoterms-list{margin-bottom:0;}.wpautoterms-custom-css-available-selectors .wpautoterms-list li{line-height:25px;margin:0 0 10px 0;}.wpautoterms-custom-css-available-selectors .wpautoterms-selector-type{display:block;}.wpautoterms-custom-css-available-selectors .wpautoterms-selector{padding:2px 4px;background:#FFF;border-radius:5px;}#wpautoterms_links_custom_css,#wpautoterms_update_notice_custom_css,#wpautoterms_cookies_notice_custom_css,#wpautoterms_endorsements_custom_css{width:100%;min-height:200px;}.wpautoterms-review-banner{padding:30px;}.wpautoterms-review-banner h4{font-size:20px;margin:0 0 10px 0;}.wpautoterms-review-banner p{font-size:16px;}.wpautoterms-review-banner p:last-child{margin:0;}.wpautoterms-review-banner .button-primary{font-size:16px;}.wpautoterms-is-dismissible{padding-right:38px;position:relative;}.wpautoterms-dismiss-icon:before{background:none;color:#72777c;content:"\f153";display:inline-block;font:normal 16px/20px dashicons;text-align:center;width:20px;vertical-align:middle;}.wpautoterms-dismiss-button{position:absolute;top:0;right:1px;border:none;margin:0;padding:9px;background:none;color:#72777c;cursor:pointer;}.wpautoterms-dismiss-button:hover .wpautoterms-dismiss-icon:before,.wpautoterms-dismiss-button:active .wpautoterms-dismiss-icon:before,.wpautoterms-dismiss-button:focus .wpautoterms-dismiss-icon:before{color:#c00;}.wpautoterms-dismiss-button:hover,.wpautoterms-dismiss-button:active,.wpautoterms-dismiss-button:focus{color:#933;}.wpautoterms-dismiss-button:focus{outline:none;box-shadow:0 0 0 1px #5b9dd9,0 0 2px 1px rgba(30,140,190,.8);}
css/jquery-ui-accordion.css ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* Icons
2
+ ----------------------------------*/
3
+
4
+ .ui-widget-icon-block {
5
+ left: 50%;
6
+ margin-left: -8px;
7
+ display: block;
8
+ }
9
+
10
+ /* Overlays */
11
+ .ui-accordion .ui-accordion-header {
12
+ display: block;
13
+ cursor: pointer;
14
+ position: relative;
15
+ margin: 2px 0 0 0;
16
+ padding: .5em .5em .5em .7em;
17
+ font-size: 100%;
18
+ }
19
+
20
+ .ui-accordion .ui-accordion-content {
21
+ padding: 1em 2.2em;
22
+ border-top: 0;
23
+ overflow: auto;
24
+ }
25
+
26
+ .ui-icon-triangle-1-s {
27
+ -webkit-transform: scale(0.8, 0.8);
28
+ -moz-transform: scale(0.8, 0.8);
29
+ -o-transform: scale(0.8, 0.8);
30
+ transform: scale(0.8, 0.8);
31
+ -ms-transform: scale(0.8, 0.8);
32
+ -webkit-transform-origin: center center;
33
+ -moz-transform-origin: center center;
34
+ -o-transform-origin: center center;
35
+ -ms-transform-origin: center center;
36
+ transform-origin: center center;
37
+ content: url(data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4KPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2ZXJzaW9uPSIxLjEiIGlkPSJ0cmkiIHg9IjBweCIgeT0iMHB4IiB3aWR0aD0iNTEycHgiIGhlaWdodD0iNTEycHgiIHZpZXdCb3g9IjAgMCAyOTIuMzYyIDI5Mi4zNjIiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDI5Mi4zNjIgMjkyLjM2MjsiIHhtbDpzcGFjZT0icHJlc2VydmUiPgo8Zz4KCTxwYXRoIGQ9Ik0yODYuOTM1LDY5LjM3N2MtMy42MTQtMy42MTctNy44OTgtNS40MjQtMTIuODQ4LTUuNDI0SDE4LjI3NGMtNC45NTIsMC05LjIzMywxLjgwNy0xMi44NSw1LjQyNCAgIEMxLjgwNyw3Mi45OTgsMCw3Ny4yNzksMCw4Mi4yMjhjMCw0Ljk0OCwxLjgwNyw5LjIyOSw1LjQyNCwxMi44NDdsMTI3LjkwNywxMjcuOTA3YzMuNjIxLDMuNjE3LDcuOTAyLDUuNDI4LDEyLjg1LDUuNDI4ICAgczkuMjMzLTEuODExLDEyLjg0Ny01LjQyOEwyODYuOTM1LDk1LjA3NGMzLjYxMy0zLjYxNyw1LjQyNy03Ljg5OCw1LjQyNy0xMi44NDdDMjkyLjM2Miw3Ny4yNzksMjkwLjU0OCw3Mi45OTgsMjg2LjkzNSw2OS4zNzd6IiBmaWxsPSIjMDAwMDAwIi8+CjwvZz4KPC9zdmc+Cg==)
38
+ }
39
+
40
+ .ui-icon-triangle-1-e {
41
+ -webkit-transform: scale(0.6, 0.8);
42
+ -moz-transform: scale(0.6, 0.8);
43
+ -o-transform: scale(0.6, 0.8);
44
+ transform: scale(0.6, 0.8);
45
+ -ms-transform: scale(0.6, 0.8);
46
+ -webkit-transform-origin: center center;
47
+ -moz-transform-origin: center center;
48
+ -o-transform-origin: center center;
49
+ -ms-transform-origin: center center;
50
+ transform-origin: center center;
51
+ content: url(data:image/svg+xml;utf8;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4KPCFET0NUWVBFIHN2ZyBQVUJMSUMgIi0vL1czQy8vRFREIFNWRyAxLjEvL0VOIiAiaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkIj4KPHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB2ZXJzaW9uPSIxLjEiIGlkPSJ0cmkiIHg9IjBweCIgeT0iMHB4IiB3aWR0aD0iMTZweCIgaGVpZ2h0PSIxNnB4IiB2aWV3Qm94PSIwIDAgMzczLjAwOCAzNzMuMDA4IiBzdHlsZT0iZW5hYmxlLWJhY2tncm91bmQ6bmV3IDAgMCAzNzMuMDA4IDM3My4wMDg7IiB4bWw6c3BhY2U9InByZXNlcnZlIj4KCTxnIGlkPSJMYXllcl84XzE2XyI+CgkJPHBhdGggZD0iTTYxLjc5MiwyLjU4OEM2NC43NzEsMC44NjQsNjguMTA1LDAsNzEuNDQ0LDBjMy4zMywwLDYuNjYzLDAuODY0LDkuNjU1LDIuNTg4bDIzMC4xMTYsMTY3LjIgICAgYzUuOTYzLDMuNDQ1LDkuNjU2LDkuODIzLDkuNjU2LDE2LjcxOWMwLDYuODk1LTMuNjgzLDEzLjI3Mi05LjY1NiwxNi43MTNMODEuMDk5LDM3MC40MjdjLTUuOTcyLDMuNDQxLTEzLjMzNCwzLjQ0MS0xOS4zMDIsMCAgICBjLTUuOTczLTMuNDUzLTkuNjYtOS44MzMtOS42Ni0xNi43MjRWMTkuMzA1QzUyLjEzNywxMi40MTMsNTUuODE4LDYuMDM2LDYxLjc5MiwyLjU4OHoiIGZpbGw9IiMwMDAwMDAiLz4KCTwvZz4KPC9zdmc+)
52
+ }
css/jquery-ui-themes/base/theme.css ADDED
@@ -0,0 +1,236 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * jQuery UI CSS Framework 1.12.1
3
+ * http://jqueryui.com
4
+ *
5
+ * Copyright jQuery Foundation and other contributors
6
+ * Released under the MIT license.
7
+ * http://jquery.org/license
8
+ *
9
+ * http://api.jqueryui.com/category/theming/
10
+ *
11
+ * To view and modify this theme, visit http://jqueryui.com/themeroller/?ffDefault=Arial%2CHelvetica%2Csans-serif&fsDefault=1em&fwDefault=normal&cornerRadius=3px&bgColorHeader=e9e9e9&bgTextureHeader=flat&borderColorHeader=dddddd&fcHeader=333333&iconColorHeader=444444&bgColorContent=ffffff&bgTextureContent=flat&borderColorContent=dddddd&fcContent=333333&iconColorContent=444444&bgColorDefault=f6f6f6&bgTextureDefault=flat&borderColorDefault=c5c5c5&fcDefault=454545&iconColorDefault=777777&bgColorHover=ededed&bgTextureHover=flat&borderColorHover=cccccc&fcHover=2b2b2b&iconColorHover=555555&bgColorActive=007fff&bgTextureActive=flat&borderColorActive=003eff&fcActive=ffffff&iconColorActive=ffffff&bgColorHighlight=fffa90&bgTextureHighlight=flat&borderColorHighlight=dad55e&fcHighlight=777620&iconColorHighlight=777620&bgColorError=fddfdf&bgTextureError=flat&borderColorError=f1a899&fcError=5f3f3f&iconColorError=cc0000&bgColorOverlay=aaaaaa&bgTextureOverlay=flat&bgImgOpacityOverlay=0&opacityOverlay=30&bgColorShadow=666666&bgTextureShadow=flat&bgImgOpacityShadow=0&opacityShadow=30&thicknessShadow=5px&offsetTopShadow=0px&offsetLeftShadow=0px&cornerRadiusShadow=8px
12
+ */
13
+
14
+
15
+ /* Component containers
16
+ ----------------------------------*/
17
+ .ui-widget {
18
+ font-family: Arial,Helvetica,sans-serif;
19
+ font-size: 1em;
20
+ }
21
+ .ui-widget .ui-widget {
22
+ font-size: 1em;
23
+ }
24
+ .ui-widget input,
25
+ .ui-widget select,
26
+ .ui-widget textarea,
27
+ .ui-widget button {
28
+ font-family: Arial,Helvetica,sans-serif;
29
+ font-size: 1em;
30
+ }
31
+ .ui-widget.ui-widget-content {
32
+ border: 1px solid #c5c5c5;
33
+ }
34
+ .ui-widget-content {
35
+ border: 1px solid #dddddd;
36
+ background: #ffffff;
37
+ color: #333333;
38
+ }
39
+ .ui-widget-content a {
40
+ color: #333333;
41
+ }
42
+ .ui-widget-header {
43
+ border: 1px solid #dddddd;
44
+ background: #e9e9e9;
45
+ color: #333333;
46
+ font-weight: bold;
47
+ }
48
+ .ui-widget-header a {
49
+ color: #333333;
50
+ }
51
+
52
+ /* Interaction states
53
+ ----------------------------------*/
54
+ .ui-state-default,
55
+ .ui-widget-content .ui-state-default,
56
+ .ui-widget-header .ui-state-default,
57
+ .ui-button,
58
+
59
+ /* We use html here because we need a greater specificity to make sure disabled
60
+ works properly when clicked or hovered */
61
+ html .ui-button.ui-state-disabled:hover,
62
+ html .ui-button.ui-state-disabled:active {
63
+ border: 1px solid #c5c5c5;
64
+ background: #f6f6f6;
65
+ font-weight: normal;
66
+ color: #454545;
67
+ }
68
+ .ui-state-default a,
69
+ .ui-state-default a:link,
70
+ .ui-state-default a:visited,
71
+ a.ui-button,
72
+ a:link.ui-button,
73
+ a:visited.ui-button,
74
+ .ui-button {
75
+ color: #454545;
76
+ text-decoration: none;
77
+ }
78
+ .ui-state-hover,
79
+ .ui-widget-content .ui-state-hover,
80
+ .ui-widget-header .ui-state-hover,
81
+ .ui-state-focus,
82
+ .ui-widget-content .ui-state-focus,
83
+ .ui-widget-header .ui-state-focus,
84
+ .ui-button:hover,
85
+ .ui-button:focus {
86
+ border: 1px solid #cccccc;
87
+ background: #ededed;
88
+ font-weight: normal;
89
+ color: #2b2b2b;
90
+ }
91
+ .ui-state-hover a,
92
+ .ui-state-hover a:hover,
93
+ .ui-state-hover a:link,
94
+ .ui-state-hover a:visited,
95
+ .ui-state-focus a,
96
+ .ui-state-focus a:hover,
97
+ .ui-state-focus a:link,
98
+ .ui-state-focus a:visited,
99
+ a.ui-button:hover,
100
+ a.ui-button:focus {
101
+ color: #2b2b2b;
102
+ text-decoration: none;
103
+ }
104
+
105
+ .ui-visual-focus {
106
+ box-shadow: 0 0 3px 1px rgb(94, 158, 214);
107
+ }
108
+ .ui-state-active,
109
+ .ui-widget-content .ui-state-active,
110
+ .ui-widget-header .ui-state-active,
111
+ a.ui-button:active,
112
+ .ui-button:active,
113
+ .ui-button.ui-state-active:hover {
114
+ border: 1px solid #57b0ff;
115
+ background: #3db1ff;
116
+ font-weight: normal;
117
+ color: #ffffff;
118
+ }
119
+ .ui-icon-background,
120
+ .ui-state-active .ui-icon-background {
121
+ border: #003eff;
122
+ background-color: #ffffff;
123
+ }
124
+ .ui-state-active a,
125
+ .ui-state-active a:link,
126
+ .ui-state-active a:visited {
127
+ color: #ffffff;
128
+ text-decoration: none;
129
+ }
130
+
131
+ /* Interaction Cues
132
+ ----------------------------------*/
133
+ .ui-state-highlight,
134
+ .ui-widget-content .ui-state-highlight,
135
+ .ui-widget-header .ui-state-highlight {
136
+ border: 1px solid #dad55e;
137
+ background: #fffa90;
138
+ color: #777620;
139
+ }
140
+ .ui-state-checked {
141
+ border: 1px solid #dad55e;
142
+ background: #fffa90;
143
+ }
144
+ .ui-state-highlight a,
145
+ .ui-widget-content .ui-state-highlight a,
146
+ .ui-widget-header .ui-state-highlight a {
147
+ color: #777620;
148
+ }
149
+ .ui-state-error,
150
+ .ui-widget-content .ui-state-error,
151
+ .ui-widget-header .ui-state-error {
152
+ border: 1px solid #f1a899;
153
+ background: #fddfdf;
154
+ color: #5f3f3f;
155
+ }
156
+ .ui-state-error a,
157
+ .ui-widget-content .ui-state-error a,
158
+ .ui-widget-header .ui-state-error a {
159
+ color: #5f3f3f;
160
+ }
161
+ .ui-state-error-text,
162
+ .ui-widget-content .ui-state-error-text,
163
+ .ui-widget-header .ui-state-error-text {
164
+ color: #5f3f3f;
165
+ }
166
+ .ui-priority-primary,
167
+ .ui-widget-content .ui-priority-primary,
168
+ .ui-widget-header .ui-priority-primary {
169
+ font-weight: bold;
170
+ }
171
+ .ui-priority-secondary,
172
+ .ui-widget-content .ui-priority-secondary,
173
+ .ui-widget-header .ui-priority-secondary {
174
+ opacity: .7;
175
+ filter:Alpha(Opacity=70); /* support: IE8 */
176
+ font-weight: normal;
177
+ }
178
+ .ui-state-disabled,
179
+ .ui-widget-content .ui-state-disabled,
180
+ .ui-widget-header .ui-state-disabled {
181
+ opacity: .35;
182
+ filter:Alpha(Opacity=35); /* support: IE8 */
183
+ background-image: none;
184
+ }
185
+ .ui-state-disabled .ui-icon {
186
+ filter:Alpha(Opacity=35); /* support: IE8 - See #6059 */
187
+ }
188
+
189
+ /* Icons
190
+ ----------------------------------*/
191
+
192
+ /* states and images */
193
+ .ui-icon {
194
+ width: 16px;
195
+ height: 16px;
196
+ }
197
+
198
+ /* Misc visuals
199
+ ----------------------------------*/
200
+
201
+ /* Corner radius */
202
+ .ui-corner-all,
203
+ .ui-corner-top,
204
+ .ui-corner-left,
205
+ .ui-corner-tl {
206
+ border-top-left-radius: 3px;
207
+ }
208
+ .ui-corner-all,
209
+ .ui-corner-top,
210
+ .ui-corner-right,
211
+ .ui-corner-tr {
212
+ border-top-right-radius: 3px;
213
+ }
214
+ .ui-corner-all,
215
+ .ui-corner-bottom,
216
+ .ui-corner-left,
217
+ .ui-corner-bl {
218
+ border-bottom-left-radius: 3px;
219
+ }
220
+ .ui-corner-all,
221
+ .ui-corner-bottom,
222
+ .ui-corner-right,
223
+ .ui-corner-br {
224
+ border-bottom-right-radius: 3px;
225
+ }
226
+
227
+ /* Overlays */
228
+ .ui-widget-overlay {
229
+ background: #aaaaaa;
230
+ opacity: .3;
231
+ filter: Alpha(Opacity=30); /* support: IE8 */
232
+ }
233
+ .ui-widget-shadow {
234
+ -webkit-box-shadow: 0px 0px 5px #666666;
235
+ box-shadow: 0px 0px 5px #666666;
236
+ }
css/jquery-ui.structure.css ADDED
@@ -0,0 +1,886 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*!
2
+ * jQuery UI CSS Framework 1.12.1
3
+ * http://jqueryui.com
4
+ *
5
+ * Copyright jQuery Foundation and other contributors
6
+ * Released under the MIT license.
7
+ * http://jquery.org/license
8
+ *
9
+ * http://api.jqueryui.com/category/theming/
10
+ */
11
+ /* Layout helpers
12
+ ----------------------------------*/
13
+ .ui-helper-hidden {
14
+ display: none;
15
+ }
16
+ .ui-helper-hidden-accessible {
17
+ border: 0;
18
+ clip: rect(0 0 0 0);
19
+ height: 1px;
20
+ margin: -1px;
21
+ overflow: hidden;
22
+ padding: 0;
23
+ position: absolute;
24
+ width: 1px;
25
+ }
26
+ .ui-helper-reset {
27
+ margin: 0;
28
+ padding: 0;
29
+ border: 0;
30
+ outline: 0;
31
+ line-height: 1.3;
32
+ text-decoration: none;
33
+ font-size: 100%;
34
+ list-style: none;
35
+ }
36
+ .ui-helper-clearfix:before,
37
+ .ui-helper-clearfix:after {
38
+ content: "";
39
+ display: table;
40
+ border-collapse: collapse;
41
+ }
42
+ .ui-helper-clearfix:after {
43
+ clear: both;
44
+ }
45
+ .ui-helper-zfix {
46
+ width: 100%;
47
+ height: 100%;
48
+ top: 0;
49
+ left: 0;
50
+ position: absolute;
51
+ opacity: 0;
52
+ filter:Alpha(Opacity=0); /* support: IE8 */
53
+ }
54
+
55
+ .ui-front {
56
+ z-index: 100;
57
+ }
58
+
59
+
60
+ /* Interaction Cues
61
+ ----------------------------------*/
62
+ .ui-state-disabled {
63
+ cursor: default !important;
64
+ pointer-events: none;
65
+ }
66
+
67
+
68
+ /* Icons
69
+ ----------------------------------*/
70
+ .ui-icon {
71
+ display: inline-block;
72
+ vertical-align: middle;
73
+ margin-top: -.25em;
74
+ position: relative;
75
+ text-indent: -99999px;
76
+ overflow: hidden;
77
+ background-repeat: no-repeat;
78
+ }
79
+
80
+ .ui-widget-icon-block {
81
+ left: 50%;
82
+ margin-left: -8px;
83
+ display: block;
84
+ }
85
+
86
+ /* Misc visuals
87
+ ----------------------------------*/
88
+
89
+ /* Overlays */
90
+ .ui-widget-overlay {
91
+ position: fixed;
92
+ top: 0;
93
+ left: 0;
94
+ width: 100%;
95
+ height: 100%;
96
+ }
97
+ .ui-accordion .ui-accordion-header {
98
+ display: block;
99
+ cursor: pointer;
100
+ position: relative;
101
+ margin: 2px 0 0 0;
102
+ padding: .5em .5em .5em .7em;
103
+ font-size: 100%;
104
+ }
105
+ .ui-accordion .ui-accordion-content {
106
+ padding: 1em 2.2em;
107
+ border-top: 0;
108
+ overflow: auto;
109
+ }
110
+ .ui-autocomplete {
111
+ position: absolute;
112
+ top: 0;
113
+ left: 0;
114
+ cursor: default;
115
+ }
116
+ .ui-menu {
117
+ list-style: none;
118
+ padding: 0;
119
+ margin: 0;
120
+ display: block;
121
+ outline: 0;
122
+ }
123
+ .ui-menu .ui-menu {
124
+ position: absolute;
125
+ }
126
+ .ui-menu .ui-menu-item {
127
+ margin: 0;
128
+ cursor: pointer;
129
+ /* support: IE10, see #8844 */
130
+ list-style-image: url("data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7");
131
+ }
132
+ .ui-menu .ui-menu-item-wrapper {
133
+ position: relative;
134
+ padding: 3px 1em 3px .4em;
135
+ }
136
+ .ui-menu .ui-menu-divider {
137
+ margin: 5px 0;
138
+ height: 0;
139
+ font-size: 0;
140
+ line-height: 0;
141
+ border-width: 1px 0 0 0;
142
+ }
143
+ .ui-menu .ui-state-focus,
144
+ .ui-menu .ui-state-active {
145
+ margin: -1px;
146
+ }
147
+
148
+ /* icon support */
149
+ .ui-menu-icons {
150
+ position: relative;
151
+ }
152
+ .ui-menu-icons .ui-menu-item-wrapper {
153
+ padding-left: 2em;
154
+ }
155
+
156
+ /* left-aligned */
157
+ .ui-menu .ui-icon {
158
+ position: absolute;
159
+ top: 0;
160
+ bottom: 0;
161
+ left: .2em;
162
+ margin: auto 0;
163
+ }
164
+
165
+ /* right-aligned */
166
+ .ui-menu .ui-menu-icon {
167
+ left: auto;
168
+ right: 0;
169
+ }
170
+ .ui-button {
171
+ padding: .4em 1em;
172
+ display: inline-block;
173
+ position: relative;
174
+ line-height: normal;
175
+ margin-right: .1em;
176
+ cursor: pointer;
177
+ vertical-align: middle;
178
+ text-align: center;
179
+ -webkit-user-select: none;
180
+ -moz-user-select: none;
181
+ -ms-user-select: none;
182
+ user-select: none;
183
+
184
+ /* Support: IE <= 11 */
185
+ overflow: visible;
186
+ }
187
+
188
+ .ui-button,
189
+ .ui-button:link,
190
+ .ui-button:visited,
191
+ .ui-button:hover,
192
+ .ui-button:active {
193
+ text-decoration: none;
194
+ }
195
+
196
+ /* to make room for the icon, a width needs to be set here */
197
+ .ui-button-icon-only {
198
+ width: 2em;
199
+ box-sizing: border-box;
200
+ text-indent: -9999px;
201
+ white-space: nowrap;
202
+ }
203
+
204
+ /* no icon support for input elements */
205
+ input.ui-button.ui-button-icon-only {
206
+ text-indent: 0;
207
+ }
208
+
209
+ /* button icon element(s) */
210
+ .ui-button-icon-only .ui-icon {
211
+ position: absolute;
212
+ top: 50%;
213
+ left: 50%;
214
+ margin-top: -8px;
215
+ margin-left: -8px;
216
+ }
217
+
218
+ .ui-button.ui-icon-notext .ui-icon {
219
+ padding: 0;
220
+ width: 2.1em;
221
+ height: 2.1em;
222
+ text-indent: -9999px;
223
+ white-space: nowrap;
224
+
225
+ }
226
+
227
+ input.ui-button.ui-icon-notext .ui-icon {
228
+ width: auto;
229
+ height: auto;
230
+ text-indent: 0;
231
+ white-space: normal;
232
+ padding: .4em 1em;
233
+ }
234
+
235
+ /* workarounds */
236
+ /* Support: Firefox 5 - 40 */
237
+ input.ui-button::-moz-focus-inner,
238
+ button.ui-button::-moz-focus-inner {
239
+ border: 0;
240
+ padding: 0;
241
+ }
242
+ .ui-controlgroup {
243
+ vertical-align: middle;
244
+ display: inline-block;
245
+ }
246
+ .ui-controlgroup > .ui-controlgroup-item {
247
+ float: left;
248
+ margin-left: 0;
249
+ margin-right: 0;
250
+ }
251
+ .ui-controlgroup > .ui-controlgroup-item:focus,
252
+ .ui-controlgroup > .ui-controlgroup-item.ui-visual-focus {
253
+ z-index: 9999;
254
+ }
255
+ .ui-controlgroup-vertical > .ui-controlgroup-item {
256
+ display: block;
257
+ float: none;
258
+ width: 100%;
259
+ margin-top: 0;
260
+ margin-bottom: 0;
261
+ text-align: left;
262
+ }
263
+ .ui-controlgroup-vertical .ui-controlgroup-item {
264
+ box-sizing: border-box;
265
+ }
266
+ .ui-controlgroup .ui-controlgroup-label {
267
+ padding: .4em 1em;
268
+ }
269
+ .ui-controlgroup .ui-controlgroup-label span {
270
+ font-size: 80%;
271
+ }
272
+ .ui-controlgroup-horizontal .ui-controlgroup-label + .ui-controlgroup-item {
273
+ border-left: none;
274
+ }
275
+ .ui-controlgroup-vertical .ui-controlgroup-label + .ui-controlgroup-item {
276
+ border-top: none;
277
+ }
278
+ .ui-controlgroup-horizontal .ui-controlgroup-label.ui-widget-content {
279
+ border-right: none;
280
+ }
281
+ .ui-controlgroup-vertical .ui-controlgroup-label.ui-widget-content {
282
+ border-bottom: none;
283
+ }
284
+
285
+ /* Spinner specific style fixes */
286
+ .ui-controlgroup-vertical .ui-spinner-input {
287
+
288
+ /* Support: IE8 only, Android < 4.4 only */
289
+ width: 75%;
290
+ width: calc( 100% - 2.4em );
291
+ }
292
+ .ui-controlgroup-vertical .ui-spinner .ui-spinner-up {
293
+ border-top-style: solid;
294
+ }
295
+
296
+ .ui-checkboxradio-label .ui-icon-background {
297
+ box-shadow: inset 1px 1px 1px #ccc;
298
+ border-radius: .12em;
299
+ border: none;
300
+ }
301
+ .ui-checkboxradio-radio-label .ui-icon-background {
302
+ width: 16px;
303
+ height: 16px;
304
+ border-radius: 1em;
305
+ overflow: visible;
306
+ border: none;
307
+ }
308
+ .ui-checkboxradio-radio-label.ui-checkboxradio-checked .ui-icon,
309
+ .ui-checkboxradio-radio-label.ui-checkboxradio-checked:hover .ui-icon {
310
+ background-image: none;
311
+ width: 8px;
312
+ height: 8px;
313
+ border-width: 4px;
314
+ border-style: solid;
315
+ }
316
+ .ui-checkboxradio-disabled {
317
+ pointer-events: none;
318
+ }
319
+ .ui-datepicker {
320
+ width: 17em;
321
+ padding: .2em .2em 0;
322
+ display: none;
323
+ }
324
+ .ui-datepicker .ui-datepicker-header {
325
+ position: relative;
326
+ padding: .2em 0;
327
+ }
328
+ .ui-datepicker .ui-datepicker-prev,
329
+ .ui-datepicker .ui-datepicker-next {
330
+ position: absolute;
331
+ top: 2px;
332
+ width: 1.8em;
333
+ height: 1.8em;
334
+ }
335
+ .ui-datepicker .ui-datepicker-prev-hover,
336
+ .ui-datepicker .ui-datepicker-next-hover {
337
+ top: 1px;
338
+ }
339
+ .ui-datepicker .ui-datepicker-prev {
340
+ left: 2px;
341
+ }
342
+ .ui-datepicker .ui-datepicker-next {
343
+ right: 2px;
344
+ }
345
+ .ui-datepicker .ui-datepicker-prev-hover {
346
+ left: 1px;
347
+ }
348
+ .ui-datepicker .ui-datepicker-next-hover {
349
+ right: 1px;
350
+ }
351
+ .ui-datepicker .ui-datepicker-prev span,
352
+ .ui-datepicker .ui-datepicker-next span {
353
+ display: block;
354
+ position: absolute;
355
+ left: 50%;
356
+ margin-left: -8px;
357
+ top: 50%;
358
+ margin-top: -8px;
359
+ }
360
+ .ui-datepicker .ui-datepicker-title {
361
+ margin: 0 2.3em;
362
+ line-height: 1.8em;
363
+ text-align: center;
364
+ }
365
+ .ui-datepicker .ui-datepicker-title select {
366
+ font-size: 1em;
367
+ margin: 1px 0;
368
+ }
369
+ .ui-datepicker select.ui-datepicker-month,
370
+ .ui-datepicker select.ui-datepicker-year {
371
+ width: 45%;
372
+ }
373
+ .ui-datepicker table {
374
+ width: 100%;
375
+ font-size: .9em;
376
+ border-collapse: collapse;
377
+ margin: 0 0 .4em;
378
+ }
379
+ .ui-datepicker th {
380
+ padding: .7em .3em;
381
+ text-align: center;
382
+ font-weight: bold;
383
+ border: 0;
384
+ }
385
+ .ui-datepicker td {
386
+ border: 0;
387
+ padding: 1px;
388
+ }
389
+ .ui-datepicker td span,
390
+ .ui-datepicker td a {
391
+ display: block;
392
+ padding: .2em;
393
+ text-align: right;
394
+ text-decoration: none;
395
+ }
396
+ .ui-datepicker .ui-datepicker-buttonpane {
397
+ background-image: none;
398
+ margin: .7em 0 0 0;
399
+ padding: 0 .2em;
400
+ border-left: 0;
401
+ border-right: 0;
402
+ border-bottom: 0;
403
+ }
404
+ .ui-datepicker .ui-datepicker-buttonpane button {
405
+ float: right;
406
+ margin: .5em .2em .4em;
407
+ cursor: pointer;
408
+ padding: .2em .6em .3em .6em;
409
+ width: auto;
410
+ overflow: visible;
411
+ }
412
+ .ui-datepicker .ui-datepicker-buttonpane button.ui-datepicker-current {
413
+ float: left;
414
+ }
415
+
416
+ /* with multiple calendars */
417
+ .ui-datepicker.ui-datepicker-multi {
418
+ width: auto;
419
+ }
420
+ .ui-datepicker-multi .ui-datepicker-group {
421
+ float: left;
422
+ }
423
+ .ui-datepicker-multi .ui-datepicker-group table {
424
+ width: 95%;
425
+ margin: 0 auto .4em;
426
+ }
427
+ .ui-datepicker-multi-2 .ui-datepicker-group {
428
+ width: 50%;
429
+ }
430
+ .ui-datepicker-multi-3 .ui-datepicker-group {
431
+ width: 33.3%;
432
+ }
433
+ .ui-datepicker-multi-4 .ui-datepicker-group {
434
+ width: 25%;
435
+ }
436
+ .ui-datepicker-multi .ui-datepicker-group-last .ui-datepicker-header,
437
+ .ui-datepicker-multi .ui-datepicker-group-middle .ui-datepicker-header {
438
+ border-left-width: 0;
439
+ }
440
+ .ui-datepicker-multi .ui-datepicker-buttonpane {
441
+ clear: left;
442
+ }
443
+ .ui-datepicker-row-break {
444
+ clear: both;
445
+ width: 100%;
446
+ font-size: 0;
447
+ }
448
+
449
+ /* RTL support */
450
+ .ui-datepicker-rtl {
451
+ direction: rtl;
452
+ }
453
+ .ui-datepicker-rtl .ui-datepicker-prev {
454
+ right: 2px;
455
+ left: auto;
456
+ }
457
+ .ui-datepicker-rtl .ui-datepicker-next {
458
+ left: 2px;
459
+ right: auto;
460
+ }
461
+ .ui-datepicker-rtl .ui-datepicker-prev:hover {
462
+ right: 1px;
463
+ left: auto;
464
+ }
465
+ .ui-datepicker-rtl .ui-datepicker-next:hover {
466
+ left: 1px;
467
+ right: auto;
468
+ }
469
+ .ui-datepicker-rtl .ui-datepicker-buttonpane {
470
+ clear: right;
471
+ }
472
+ .ui-datepicker-rtl .ui-datepicker-buttonpane button {
473
+ float: left;
474
+ }
475
+ .ui-datepicker-rtl .ui-datepicker-buttonpane button.ui-datepicker-current,
476
+ .ui-datepicker-rtl .ui-datepicker-group {
477
+ float: right;
478
+ }
479
+ .ui-datepicker-rtl .ui-datepicker-group-last .ui-datepicker-header,
480
+ .ui-datepicker-rtl .ui-datepicker-group-middle .ui-datepicker-header {
481
+ border-right-width: 0;
482
+ border-left-width: 1px;
483
+ }
484
+
485
+ /* Icons */
486
+ .ui-datepicker .ui-icon {
487
+ display: block;
488
+ text-indent: -99999px;
489
+ overflow: hidden;
490
+ background-repeat: no-repeat;
491
+ left: .5em;
492
+ top: .3em;
493
+ }
494
+ .ui-dialog {
495
+ position: absolute;
496
+ top: 0;
497
+ left: 0;
498
+ padding: .2em;
499
+ outline: 0;
500
+ }
501
+ .ui-dialog .ui-dialog-titlebar {
502
+ padding: .4em 1em;
503
+ position: relative;
504
+ }
505
+ .ui-dialog .ui-dialog-title {
506
+ float: left;
507
+ margin: .1em 0;
508
+ white-space: nowrap;
509
+ width: 90%;
510
+ overflow: hidden;
511
+ text-overflow: ellipsis;
512
+ }
513
+ .ui-dialog .ui-dialog-titlebar-close {
514
+ position: absolute;
515
+ right: .3em;
516
+ top: 50%;
517
+ width: 20px;
518
+ margin: -10px 0 0 0;
519
+ padding: 1px;
520
+ height: 20px;
521
+ }
522
+ .ui-dialog .ui-dialog-content {
523
+ position: relative;
524
+ border: 0;
525
+ padding: .5em 1em;
526
+ background: none;
527
+ overflow: auto;
528
+ }
529
+ .ui-dialog .ui-dialog-buttonpane {
530
+ text-align: left;
531
+ border-width: 1px 0 0 0;
532
+ background-image: none;
533
+ margin-top: .5em;
534
+ padding: .3em 1em .5em .4em;
535
+ }
536
+ .ui-dialog .ui-dialog-buttonpane .ui-dialog-buttonset {
537
+ float: right;
538
+ }
539
+ .ui-dialog .ui-dialog-buttonpane button {
540
+ margin: .5em .4em .5em 0;
541
+ cursor: pointer;
542
+ }
543
+ .ui-dialog .ui-resizable-n {
544
+ height: 2px;
545
+ top: 0;
546
+ }
547
+ .ui-dialog .ui-resizable-e {
548
+ width: 2px;
549
+ right: 0;
550
+ }
551
+ .ui-dialog .ui-resizable-s {
552
+ height: 2px;
553
+ bottom: 0;
554
+ }
555
+ .ui-dialog .ui-resizable-w {
556
+ width: 2px;
557
+ left: 0;
558
+ }
559
+ .ui-dialog .ui-resizable-se,
560
+ .ui-dialog .ui-resizable-sw,
561
+ .ui-dialog .ui-resizable-ne,
562
+ .ui-dialog .ui-resizable-nw {
563
+ width: 7px;
564
+ height: 7px;
565
+ }
566
+ .ui-dialog .ui-resizable-se {
567
+ right: 0;
568
+ bottom: 0;
569
+ }
570
+ .ui-dialog .ui-resizable-sw {
571
+ left: 0;
572
+ bottom: 0;
573
+ }
574
+ .ui-dialog .ui-resizable-ne {
575
+ right: 0;
576
+ top: 0;
577
+ }
578
+ .ui-dialog .ui-resizable-nw {
579
+ left: 0;
580
+ top: 0;
581
+ }
582
+ .ui-draggable .ui-dialog-titlebar {
583
+ cursor: move;
584
+ }
585
+ .ui-draggable-handle {
586
+ -ms-touch-action: none;
587
+ touch-action: none;
588
+ }
589
+ .ui-resizable {
590
+ position: relative;
591
+ }
592
+ .ui-resizable-handle {
593
+ position: absolute;
594
+ font-size: 0.1px;
595
+ display: block;
596
+ -ms-touch-action: none;
597
+ touch-action: none;
598
+ }
599
+ .ui-resizable-disabled .ui-resizable-handle,
600
+ .ui-resizable-autohide .ui-resizable-handle {
601
+ display: none;
602
+ }
603
+ .ui-resizable-n {
604
+ cursor: n-resize;
605
+ height: 7px;
606
+ width: 100%;
607
+ top: -5px;
608
+ left: 0;
609
+ }
610
+ .ui-resizable-s {
611
+ cursor: s-resize;
612
+ height: 7px;
613
+ width: 100%;
614
+ bottom: -5px;
615
+ left: 0;
616
+ }
617
+ .ui-resizable-e {
618
+ cursor: e-resize;
619
+ width: 7px;
620
+ right: -5px;
621
+ top: 0;
622
+ height: 100%;
623
+ }
624
+ .ui-resizable-w {
625
+ cursor: w-resize;
626
+ width: 7px;
627
+ left: -5px;
628
+ top: 0;
629
+ height: 100%;
630
+ }
631
+ .ui-resizable-se {
632
+ cursor: se-resize;
633
+ width: 12px;
634
+ height: 12px;
635
+ right: 1px;
636
+ bottom: 1px;
637
+ }
638
+ .ui-resizable-sw {
639
+ cursor: sw-resize;
640
+ width: 9px;
641
+ height: 9px;
642
+ left: -5px;
643
+ bottom: -5px;
644
+ }
645
+ .ui-resizable-nw {
646
+ cursor: nw-resize;
647
+ width: 9px;
648
+ height: 9px;
649
+ left: -5px;
650
+ top: -5px;
651
+ }
652
+ .ui-resizable-ne {
653
+ cursor: ne-resize;
654
+ width: 9px;
655
+ height: 9px;
656
+ right: -5px;
657
+ top: -5px;
658
+ }
659
+ .ui-progressbar {
660
+ height: 2em;
661
+ text-align: left;
662
+ overflow: hidden;
663
+ }
664
+ .ui-progressbar .ui-progressbar-value {
665
+ margin: -1px;
666
+ height: 100%;
667
+ }
668
+ .ui-progressbar .ui-progressbar-overlay {
669
+ background: url("data:image/gif;base64,R0lGODlhKAAoAIABAAAAAP///yH/C05FVFNDQVBFMi4wAwEAAAAh+QQJAQABACwAAAAAKAAoAAACkYwNqXrdC52DS06a7MFZI+4FHBCKoDeWKXqymPqGqxvJrXZbMx7Ttc+w9XgU2FB3lOyQRWET2IFGiU9m1frDVpxZZc6bfHwv4c1YXP6k1Vdy292Fb6UkuvFtXpvWSzA+HycXJHUXiGYIiMg2R6W459gnWGfHNdjIqDWVqemH2ekpObkpOlppWUqZiqr6edqqWQAAIfkECQEAAQAsAAAAACgAKAAAApSMgZnGfaqcg1E2uuzDmmHUBR8Qil95hiPKqWn3aqtLsS18y7G1SzNeowWBENtQd+T1JktP05nzPTdJZlR6vUxNWWjV+vUWhWNkWFwxl9VpZRedYcflIOLafaa28XdsH/ynlcc1uPVDZxQIR0K25+cICCmoqCe5mGhZOfeYSUh5yJcJyrkZWWpaR8doJ2o4NYq62lAAACH5BAkBAAEALAAAAAAoACgAAAKVDI4Yy22ZnINRNqosw0Bv7i1gyHUkFj7oSaWlu3ovC8GxNso5fluz3qLVhBVeT/Lz7ZTHyxL5dDalQWPVOsQWtRnuwXaFTj9jVVh8pma9JjZ4zYSj5ZOyma7uuolffh+IR5aW97cHuBUXKGKXlKjn+DiHWMcYJah4N0lYCMlJOXipGRr5qdgoSTrqWSq6WFl2ypoaUAAAIfkECQEAAQAsAAAAACgAKAAAApaEb6HLgd/iO7FNWtcFWe+ufODGjRfoiJ2akShbueb0wtI50zm02pbvwfWEMWBQ1zKGlLIhskiEPm9R6vRXxV4ZzWT2yHOGpWMyorblKlNp8HmHEb/lCXjcW7bmtXP8Xt229OVWR1fod2eWqNfHuMjXCPkIGNileOiImVmCOEmoSfn3yXlJWmoHGhqp6ilYuWYpmTqKUgAAIfkECQEAAQAsAAAAACgAKAAAApiEH6kb58biQ3FNWtMFWW3eNVcojuFGfqnZqSebuS06w5V80/X02pKe8zFwP6EFWOT1lDFk8rGERh1TTNOocQ61Hm4Xm2VexUHpzjymViHrFbiELsefVrn6XKfnt2Q9G/+Xdie499XHd2g4h7ioOGhXGJboGAnXSBnoBwKYyfioubZJ2Hn0RuRZaflZOil56Zp6iioKSXpUAAAh+QQJAQABACwAAAAAKAAoAAACkoQRqRvnxuI7kU1a1UU5bd5tnSeOZXhmn5lWK3qNTWvRdQxP8qvaC+/yaYQzXO7BMvaUEmJRd3TsiMAgswmNYrSgZdYrTX6tSHGZO73ezuAw2uxuQ+BbeZfMxsexY35+/Qe4J1inV0g4x3WHuMhIl2jXOKT2Q+VU5fgoSUI52VfZyfkJGkha6jmY+aaYdirq+lQAACH5BAkBAAEALAAAAAAoACgAAAKWBIKpYe0L3YNKToqswUlvznigd4wiR4KhZrKt9Upqip61i9E3vMvxRdHlbEFiEXfk9YARYxOZZD6VQ2pUunBmtRXo1Lf8hMVVcNl8JafV38aM2/Fu5V16Bn63r6xt97j09+MXSFi4BniGFae3hzbH9+hYBzkpuUh5aZmHuanZOZgIuvbGiNeomCnaxxap2upaCZsq+1kAACH5BAkBAAEALAAAAAAoACgAAAKXjI8By5zf4kOxTVrXNVlv1X0d8IGZGKLnNpYtm8Lr9cqVeuOSvfOW79D9aDHizNhDJidFZhNydEahOaDH6nomtJjp1tutKoNWkvA6JqfRVLHU/QUfau9l2x7G54d1fl995xcIGAdXqMfBNadoYrhH+Mg2KBlpVpbluCiXmMnZ2Sh4GBqJ+ckIOqqJ6LmKSllZmsoq6wpQAAAh+QQJAQABACwAAAAAKAAoAAAClYx/oLvoxuJDkU1a1YUZbJ59nSd2ZXhWqbRa2/gF8Gu2DY3iqs7yrq+xBYEkYvFSM8aSSObE+ZgRl1BHFZNr7pRCavZ5BW2142hY3AN/zWtsmf12p9XxxFl2lpLn1rseztfXZjdIWIf2s5dItwjYKBgo9yg5pHgzJXTEeGlZuenpyPmpGQoKOWkYmSpaSnqKileI2FAAACH5BAkBAAEALAAAAAAoACgAAAKVjB+gu+jG4kORTVrVhRlsnn2dJ3ZleFaptFrb+CXmO9OozeL5VfP99HvAWhpiUdcwkpBH3825AwYdU8xTqlLGhtCosArKMpvfa1mMRae9VvWZfeB2XfPkeLmm18lUcBj+p5dnN8jXZ3YIGEhYuOUn45aoCDkp16hl5IjYJvjWKcnoGQpqyPlpOhr3aElaqrq56Bq7VAAAOw==");
670
+ height: 100%;
671
+ filter: alpha(opacity=25); /* support: IE8 */
672
+ opacity: 0.25;
673
+ }
674
+ .ui-progressbar-indeterminate .ui-progressbar-value {
675
+ background-image: none;
676
+ }
677
+ .ui-selectable {
678
+ -ms-touch-action: none;
679
+ touch-action: none;
680
+ }
681
+ .ui-selectable-helper {
682
+ position: absolute;
683
+ z-index: 100;
684
+ border: 1px dotted black;
685
+ }
686
+ .ui-selectmenu-menu {
687
+ padding: 0;
688
+ margin: 0;
689
+ position: absolute;
690
+ top: 0;
691
+ left: 0;
692
+ display: none;
693
+ }
694
+ .ui-selectmenu-menu .ui-menu {
695
+ overflow: auto;
696
+ overflow-x: hidden;
697
+ padding-bottom: 1px;
698
+ }
699
+ .ui-selectmenu-menu .ui-menu .ui-selectmenu-optgroup {
700
+ font-size: 1em;
701
+ font-weight: bold;
702
+ line-height: 1.5;
703
+ padding: 2px 0.4em;
704
+ margin: 0.5em 0 0 0;
705
+ height: auto;
706
+ border: 0;
707
+ }
708
+ .ui-selectmenu-open {
709
+ display: block;
710
+ }
711
+ .ui-selectmenu-text {
712
+ display: block;
713
+ margin-right: 20px;
714
+ overflow: hidden;
715
+ text-overflow: ellipsis;
716
+ }
717
+ .ui-selectmenu-button.ui-button {
718
+ text-align: left;
719
+ white-space: nowrap;
720
+ width: 14em;
721
+ }
722
+ .ui-selectmenu-icon.ui-icon {
723
+ float: right;
724
+ margin-top: 0;
725
+ }
726
+ .ui-slider {
727
+ position: relative;
728
+ text-align: left;
729
+ }
730
+ .ui-slider .ui-slider-handle {
731
+ position: absolute;
732
+ z-index: 2;
733
+ width: 1.2em;
734
+ height: 1.2em;
735
+ cursor: default;
736
+ -ms-touch-action: none;
737
+ touch-action: none;
738
+ }
739
+ .ui-slider .ui-slider-range {
740
+ position: absolute;
741
+ z-index: 1;
742
+ font-size: .7em;
743
+ display: block;
744
+ border: 0;
745
+ background-position: 0 0;
746
+ }
747
+
748
+ /* support: IE8 - See #6727 */
749
+ .ui-slider.ui-state-disabled .ui-slider-handle,
750
+ .ui-slider.ui-state-disabled .ui-slider-range {
751
+ filter: inherit;
752
+ }
753
+
754
+ .ui-slider-horizontal {
755
+ height: .8em;
756
+ }
757
+ .ui-slider-horizontal .ui-slider-handle {
758
+ top: -.3em;
759
+ margin-left: -.6em;
760
+ }
761
+ .ui-slider-horizontal .ui-slider-range {
762
+ top: 0;
763
+ height: 100%;
764
+ }
765
+ .ui-slider-horizontal .ui-slider-range-min {
766
+ left: 0;
767
+ }
768
+ .ui-slider-horizontal .ui-slider-range-max {
769
+ right: 0;
770
+ }
771
+
772
+ .ui-slider-vertical {
773
+ width: .8em;
774
+ height: 100px;
775
+ }
776
+ .ui-slider-vertical .ui-slider-handle {
777
+ left: -.3em;
778
+ margin-left: 0;
779
+ margin-bottom: -.6em;
780
+ }
781
+ .ui-slider-vertical .ui-slider-range {
782
+ left: 0;
783
+ width: 100%;
784
+ }
785
+ .ui-slider-vertical .ui-slider-range-min {
786
+ bottom: 0;
787
+ }
788
+ .ui-slider-vertical .ui-slider-range-max {
789
+ top: 0;
790
+ }
791
+ .ui-sortable-handle {
792
+ -ms-touch-action: none;
793
+ touch-action: none;
794
+ }
795
+ .ui-spinner {
796
+ position: relative;
797
+ display: inline-block;
798
+ overflow: hidden;
799
+ padding: 0;
800
+ vertical-align: middle;
801
+ }
802
+ .ui-spinner-input {
803
+ border: none;
804
+ background: none;
805
+ color: inherit;
806
+ padding: .222em 0;
807
+ margin: .2em 0;
808
+ vertical-align: middle;
809
+ margin-left: .4em;
810
+ margin-right: 2em;
811
+ }
812
+ .ui-spinner-button {
813
+ width: 1.6em;
814
+ height: 50%;
815
+ font-size: .5em;
816
+ padding: 0;
817
+ margin: 0;
818
+ text-align: center;
819
+ position: absolute;
820
+ cursor: default;
821
+ display: block;
822
+ overflow: hidden;
823
+ right: 0;
824
+ }
825
+ /* more specificity required here to override default borders */
826
+ .ui-spinner a.ui-spinner-button {
827
+ border-top-style: none;
828
+ border-bottom-style: none;
829
+ border-right-style: none;
830
+ }
831
+ .ui-spinner-up {
832
+ top: 0;
833
+ }
834
+ .ui-spinner-down {
835
+ bottom: 0;
836
+ }
837
+ .ui-tabs {
838
+ position: relative;/* position: relative prevents IE scroll bug (element with position: relative inside container with overflow: auto appear as "fixed") */
839
+ padding: .2em;
840
+ }
841
+ .ui-tabs .ui-tabs-nav {
842
+ margin: 0;
843
+ padding: .2em .2em 0;
844
+ }
845
+ .ui-tabs .ui-tabs-nav li {
846
+ list-style: none;
847
+ float: left;
848
+ position: relative;
849
+ top: 0;
850
+ margin: 1px .2em 0 0;
851
+ border-bottom-width: 0;
852
+ padding: 0;
853
+ white-space: nowrap;
854
+ }
855
+ .ui-tabs .ui-tabs-nav .ui-tabs-anchor {
856
+ float: left;
857
+ padding: .5em 1em;
858
+ text-decoration: none;
859
+ }
860
+ .ui-tabs .ui-tabs-nav li.ui-tabs-active {
861
+ margin-bottom: -1px;
862
+ padding-bottom: 1px;
863
+ }
864
+ .ui-tabs .ui-tabs-nav li.ui-tabs-active .ui-tabs-anchor,
865
+ .ui-tabs .ui-tabs-nav li.ui-state-disabled .ui-tabs-anchor,
866
+ .ui-tabs .ui-tabs-nav li.ui-tabs-loading .ui-tabs-anchor {
867
+ cursor: text;
868
+ }
869
+ .ui-tabs-collapsible .ui-tabs-nav li.ui-tabs-active .ui-tabs-anchor {
870
+ cursor: pointer;
871
+ }
872
+ .ui-tabs .ui-tabs-panel {
873
+ display: block;
874
+ border-width: 0;
875
+ padding: 1em 1.4em;
876
+ background: none;
877
+ }
878
+ .ui-tooltip {
879
+ padding: 8px;
880
+ position: absolute;
881
+ z-index: 9999;
882
+ max-width: 300px;
883
+ }
884
+ body .ui-tooltip {
885
+ border-width: 2px;
886
+ }
css/page-help.css ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .wpautoterms-help-page-container {
2
+ display: block;
3
+ }
4
+
5
+ .wpautoterms-help-page-help {
6
+
7
+ }
8
+
9
+ .wpautoterms-help-page-no-answer-text {
10
+ margin: 5px 0 0 0;
11
+ font-size: 14px;
12
+ display: inline-block;
13
+ }
14
+ .wpautoterms-help-page-form-button {
15
+ margin: 15px 0 0 0;
16
+ }
17
+ .wpautoterms-help-page-form {
18
+ display: none;
19
+
20
+ background: #FFF;
21
+ border: 1px solid #e5e5e5;
22
+ border-radius: 0;
23
+ box-shadow: 0 1px 1px rgba(0,0,0,0.04);
24
+ color: #555;
25
+ font-size: 16px;
26
+ padding: 5px 15px;
27
+ margin: 10px 0 0 0;
28
+ }
29
+ .wpautoterms-help-page-site-info-notice {
30
+
31
+ }
32
+ .wpautoterms-help-page-form textarea {
33
+ resize: vertical;
34
+ display: block;
35
+ width: 100%;
36
+ min-height: 150px;
37
+ }
38
+
39
+ h3 small.wpautoterms-small {
40
+ font-weight: normal;
41
+ }
42
+
43
+ .wpautoterms-help-page-container .ui-accordion,
44
+ .wpautoterms-help-page-container .ui-accordion p,
45
+ .wpautoterms-help-page-container .ui-accordion li {
46
+ font-size: 16px;
47
+ line-height: 24px;
48
+ }
49
+ .wpautoterms-help-page-container .ui-accordion .ui-accordion-header {
50
+ background: #FFF;
51
+ border: 1px solid #e5e5e5;
52
+ border-radius: 0;
53
+ box-shadow: 0 1px 1px rgba(0,0,0,0.04);
54
+ color: #555;
55
+ font-size: 16px;
56
+ }
57
+ .wpautoterms-help-page-container .ui-accordion .ui-accordion-header-active {
58
+ background: #f9f9f9;
59
+ }
60
+
61
+ .wpautoterms-help-page-container .ui-accordion .ui-accordion-header-icon {
62
+ margin-right: 10px;
63
+ }
css/post-new.css CHANGED
@@ -72,11 +72,6 @@
72
  width: 75%;
73
  }
74
 
75
- .wpautoterms-is-dismissible {
76
- padding-right: 38px;
77
- position: relative;
78
- }
79
-
80
  .wpautoterms-notice-permanent-hide {
81
  float: right;
82
  margin: 0.5em 0;
72
  width: 75%;
73
  }
74
 
 
 
 
 
 
75
  .wpautoterms-notice-permanent-hide {
76
  float: right;
77
  margin: 0.5em 0;
includes/action-base.php CHANGED
@@ -18,6 +18,8 @@ class Action_Base {
18
  */
19
  protected $_handler;
20
 
 
 
21
  public function __construct( $capability, $args = null, $name = '', $handler = null, $fail_handler = null, $admin_post = false ) {
22
  $this->_name = empty( $name ) ? static::NAME : $name;
23
  $this->_args = $args;
@@ -28,6 +30,11 @@ class Action_Base {
28
  add_action( 'admin_post_' . $this->name(), array( $this, 'handle_post' ) );
29
  }
30
  add_action( 'wp_ajax_' . $this->name(), array( $this, 'handle' ) );
 
 
 
 
 
31
  }
32
 
33
  public function name() {
18
  */
19
  protected $_handler;
20
 
21
+ protected static $_actions = array();
22
+
23
  public function __construct( $capability, $args = null, $name = '', $handler = null, $fail_handler = null, $admin_post = false ) {
24
  $this->_name = empty( $name ) ? static::NAME : $name;
25
  $this->_args = $args;
30
  add_action( 'admin_post_' . $this->name(), array( $this, 'handle_post' ) );
31
  }
32
  add_action( 'wp_ajax_' . $this->name(), array( $this, 'handle' ) );
33
+ static::$_actions[] = $this;
34
+ }
35
+
36
+ public static function actions() {
37
+ return self::$_actions;
38
  }
39
 
40
  public function name() {
includes/admin/admin.php CHANGED
@@ -6,6 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
 
9
  use wpautoterms\admin\action\Recheck_License;
10
  use wpautoterms\admin\action\Set_Option;
11
  use wpautoterms\admin\form\Legal_Page;
@@ -32,6 +33,10 @@ abstract class Admin {
32
  * @var Set_Option
33
  */
34
  protected static $_warning_action;
 
 
 
 
35
 
36
  public static function init( License $license, Query $query ) {
37
  static::$_license = $license;
@@ -39,6 +44,7 @@ abstract class Admin {
39
  add_action( 'init', array( __CLASS__, 'action_init' ) );
40
  new Slug_Helper();
41
  new Upgrade();
 
42
  }
43
 
44
  public static function action_init() {
@@ -65,7 +71,7 @@ abstract class Admin {
65
  }
66
 
67
  public static function update_wp_builtin_pp( $pages, $r ) {
68
- if ( ! isset( $r['name'] ) || !in_array( $r['name'], array(
69
  'wp_page_for_privacy_policy',
70
  'page_for_privacy_policy',
71
  'woocommerce_terms_page_id'
@@ -153,8 +159,11 @@ abstract class Admin {
153
  }
154
 
155
  public static function enqueue_scripts( $page ) {
 
 
 
156
  global $post;
157
- if ( ! empty( $post ) && ( $post->post_type == CPT::type() ) ) {
158
  // NOTE: load media scripts in case 3-rd party plugin fails to enqueue them properly.
159
  $scripts = wp_scripts();
160
  if ( ! empty( $scripts->queue ) ) {
@@ -187,23 +196,31 @@ abstract class Admin {
187
  wp_localize_script( WPAUTOTERMS_SLUG . '_post_new', 'wpautotermsPostNew', array(
188
  'hidden' => $hidden,
189
  'dependencies' => $dependencies,
190
- 'settings_warning_disable_nonce' => static::$_warning_action->nonce(),
191
  'page_id' => $page_id
192
  ) );
193
  wp_register_style( WPAUTOTERMS_SLUG . '_post_new_css', WPAUTOTERMS_PLUGIN_URL . 'css/post-new.css', false );
194
  wp_enqueue_style( WPAUTOTERMS_SLUG . '_post_new_css' );
195
- wp_register_style( WPAUTOTERMS_SLUG . '_admin_css', WPAUTOTERMS_PLUGIN_URL . 'css/admin.css', false );
196
- wp_enqueue_style( WPAUTOTERMS_SLUG . '_admin_css' );
197
  }
198
- }
199
 
200
- $prefix = WPAUTOTERMS_SLUG . '_';
201
- if ( strncmp( $page, $prefix, strlen( $prefix ) ) != 0 ) {
202
- return;
203
  }
204
- Countries::enqueue_scripts();
205
- wp_enqueue_script( WPAUTOTERMS_SLUG . '_admin', WPAUTOTERMS_PLUGIN_URL . 'js/admin.js', false, false, true );
206
  wp_register_style( WPAUTOTERMS_SLUG . '_admin_css', WPAUTOTERMS_PLUGIN_URL . 'css/admin.css', false );
207
  wp_enqueue_style( WPAUTOTERMS_SLUG . '_admin_css' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  }
209
  }
6
  exit;
7
  }
8
 
9
+ use wpautoterms\Action_Base;
10
  use wpautoterms\admin\action\Recheck_License;
11
  use wpautoterms\admin\action\Set_Option;
12
  use wpautoterms\admin\form\Legal_Page;
33
  * @var Set_Option
34
  */
35
  protected static $_warning_action;
36
+ /**
37
+ * @var Review_Banner
38
+ */
39
+ protected static $_review_banner;
40
 
41
  public static function init( License $license, Query $query ) {
42
  static::$_license = $license;
44
  add_action( 'init', array( __CLASS__, 'action_init' ) );
45
  new Slug_Helper();
46
  new Upgrade();
47
+ static::$_review_banner = new Review_Banner();
48
  }
49
 
50
  public static function action_init() {
71
  }
72
 
73
  public static function update_wp_builtin_pp( $pages, $r ) {
74
+ if ( ! isset( $r['name'] ) || ! in_array( $r['name'], array(
75
  'wp_page_for_privacy_policy',
76
  'page_for_privacy_policy',
77
  'woocommerce_terms_page_id'
159
  }
160
 
161
  public static function enqueue_scripts( $page ) {
162
+ if ( ! isset ( $_REQUEST['post_type'] ) || $_REQUEST['post_type'] !== CPT::type() ) {
163
+ return;
164
+ }
165
  global $post;
166
+ if ( ! empty( $post ) ) {
167
  // NOTE: load media scripts in case 3-rd party plugin fails to enqueue them properly.
168
  $scripts = wp_scripts();
169
  if ( ! empty( $scripts->queue ) ) {
196
  wp_localize_script( WPAUTOTERMS_SLUG . '_post_new', 'wpautotermsPostNew', array(
197
  'hidden' => $hidden,
198
  'dependencies' => $dependencies,
 
199
  'page_id' => $page_id
200
  ) );
201
  wp_register_style( WPAUTOTERMS_SLUG . '_post_new_css', WPAUTOTERMS_PLUGIN_URL . 'css/post-new.css', false );
202
  wp_enqueue_style( WPAUTOTERMS_SLUG . '_post_new_css' );
 
 
203
  }
 
204
 
 
 
 
205
  }
 
 
206
  wp_register_style( WPAUTOTERMS_SLUG . '_admin_css', WPAUTOTERMS_PLUGIN_URL . 'css/admin.css', false );
207
  wp_enqueue_style( WPAUTOTERMS_SLUG . '_admin_css' );
208
+ wp_enqueue_script( WPAUTOTERMS_SLUG . '_common', WPAUTOTERMS_PLUGIN_URL . 'js/common.js',
209
+ false, false, true );
210
+ $nonce = array();
211
+ /**
212
+ * @var Action_Base $action
213
+ */
214
+ foreach ( Action_Base::actions() as $action ) {
215
+ $nonce[ $action->name() ] = $action->nonce();
216
+ }
217
+ wp_localize_script( WPAUTOTERMS_SLUG . '_common', 'wpautotermsCommon', array(
218
+ 'nonce' => $nonce,
219
+ ) );
220
+ $prefix = WPAUTOTERMS_SLUG . '_';
221
+ if ( strncmp( $page, $prefix, strlen( $prefix ) ) === 0 ) {
222
+ Countries::enqueue_scripts();
223
+ wp_enqueue_script( WPAUTOTERMS_SLUG . '_admin', WPAUTOTERMS_PLUGIN_URL . 'js/kits.js', false, false, true );
224
+ }
225
  }
226
  }
includes/admin/menu.php CHANGED
@@ -21,7 +21,7 @@ abstract class Menu {
21
  const VERSION = 'version';
22
  const LEGACY_OPTIONS = 'legacy_options';
23
 
24
- const PAGE_CONTACT = 'contact';
25
  const PAGE_SETTINGS = 'settings';
26
  const PAGE_COMPLIANCE_KITS = 'compliancekits';
27
  const PAGE_LICENSE_SETTINGS = 'license_settings';
@@ -57,7 +57,7 @@ abstract class Menu {
57
  $ls = new License_Settings( static::PAGE_LICENSE_SETTINGS, __( 'License Settings', WPAUTOTERMS_SLUG ),
58
  __( 'License', WPAUTOTERMS_SLUG ) );
59
  $ls->set_license( $license );
60
- $contact = new page\Contact( static::PAGE_CONTACT, __( 'Contact', WPAUTOTERMS_SLUG ) );
61
  $sm = new Send_Message( CPT::edit_cap(), null, $contact->id(), null,
62
  __( 'Access denied', WPAUTOTERMS_SLUG ), true );
63
  $contact->action = $sm;
21
  const VERSION = 'version';
22
  const LEGACY_OPTIONS = 'legacy_options';
23
 
24
+ const PAGE_HELP = 'help';
25
  const PAGE_SETTINGS = 'settings';
26
  const PAGE_COMPLIANCE_KITS = 'compliancekits';
27
  const PAGE_LICENSE_SETTINGS = 'license_settings';
57
  $ls = new License_Settings( static::PAGE_LICENSE_SETTINGS, __( 'License Settings', WPAUTOTERMS_SLUG ),
58
  __( 'License', WPAUTOTERMS_SLUG ) );
59
  $ls->set_license( $license );
60
+ $contact = new page\Help( static::PAGE_HELP, __( 'Help', WPAUTOTERMS_SLUG ) );
61
  $sm = new Send_Message( CPT::edit_cap(), null, $contact->id(), null,
62
  __( 'Access denied', WPAUTOTERMS_SLUG ), true );
63
  $contact->action = $sm;
includes/admin/options.php CHANGED
@@ -9,6 +9,7 @@ class Options {
9
  const COUNTRY = 'country';
10
  const STATE = 'state';
11
  const LEGAL_PAGES_SLUG = 'legal_pages_slug';
 
12
  protected static $_defaults;
13
 
14
  public static function all_options() {
@@ -18,7 +19,8 @@ class Options {
18
  static::COMPANY_NAME,
19
  static::COUNTRY,
20
  static::STATE,
21
- static::LEGAL_PAGES_SLUG
 
22
  );
23
  }
24
 
@@ -31,7 +33,8 @@ class Options {
31
  Options::COMPANY_NAME => $blogname,
32
  Options::COUNTRY => '',
33
  Options::STATE => '',
34
- Options::LEGAL_PAGES_SLUG => 'wpautoterms'
 
35
  );
36
  }
37
 
9
  const COUNTRY = 'country';
10
  const STATE = 'state';
11
  const LEGAL_PAGES_SLUG = 'legal_pages_slug';
12
+ const SHOW_IN_PAGES_WIDGET = 'show_in_pages_widget';
13
  protected static $_defaults;
14
 
15
  public static function all_options() {
19
  static::COMPANY_NAME,
20
  static::COUNTRY,
21
  static::STATE,
22
+ static::LEGAL_PAGES_SLUG,
23
+ static::SHOW_IN_PAGES_WIDGET
24
  );
25
  }
26
 
33
  Options::COMPANY_NAME => $blogname,
34
  Options::COUNTRY => '',
35
  Options::STATE => '',
36
+ Options::LEGAL_PAGES_SLUG => 'wpautoterms',
37
+ Options::SHOW_IN_PAGES_WIDGET => false
38
  );
39
  }
40
 
includes/admin/page/compliancekits.php CHANGED
@@ -20,6 +20,9 @@ class Compliancekits extends Settings_Base {
20
  const KIT_UPDATE_NOTICE = 'update_notice';
21
 
22
  protected $_boxes;
 
 
 
23
  protected $_box = false;
24
 
25
  function __construct( $id, $title, License $license, $menu_title = null ) {
@@ -67,7 +70,6 @@ class Compliancekits extends Settings_Base {
67
  wp_localize_script( WPAUTOTERMS_SLUG . '_compliancekits_page', 'wpautotermsComplianceKits', array(
68
  'boxData' => array_reduce( $this->_boxes, function ( $acc, Box $x ) {
69
  $acc[ $x->enable_action_id() ] = array(
70
- 'nonce' => $x->action()->nonce(),
71
  'noticeText' => array(
72
  $x->title() . ' ' . __( 'disabled.', WPAUTOTERMS_SLUG ),
73
  $x->title() . ' ' . __( 'enabled.', WPAUTOTERMS_SLUG ),
@@ -86,6 +88,7 @@ class Compliancekits extends Settings_Base {
86
  array( 'wp-color-picker' ),
87
  false,
88
  true );
 
89
  }
90
  }
91
 
20
  const KIT_UPDATE_NOTICE = 'update_notice';
21
 
22
  protected $_boxes;
23
+ /**
24
+ * @var bool|Box
25
+ */
26
  protected $_box = false;
27
 
28
  function __construct( $id, $title, License $license, $menu_title = null ) {
70
  wp_localize_script( WPAUTOTERMS_SLUG . '_compliancekits_page', 'wpautotermsComplianceKits', array(
71
  'boxData' => array_reduce( $this->_boxes, function ( $acc, Box $x ) {
72
  $acc[ $x->enable_action_id() ] = array(
 
73
  'noticeText' => array(
74
  $x->title() . ' ' . __( 'disabled.', WPAUTOTERMS_SLUG ),
75
  $x->title() . ' ' . __( 'enabled.', WPAUTOTERMS_SLUG ),
88
  array( 'wp-color-picker' ),
89
  false,
90
  true );
91
+ $this->_box->enqueue_scripts();
92
  }
93
  }
94
 
includes/admin/page/{contact.php → help.php} RENAMED
@@ -5,7 +5,7 @@ namespace wpautoterms\admin\page;
5
 
6
  use wpautoterms\admin\action\Send_Message;
7
 
8
- class Contact extends Base {
9
  const EP_MESSAGE = 'contact/v2/message_prepare';
10
  /**
11
  * @var Send_Message
@@ -18,6 +18,11 @@ class Contact extends Base {
18
 
19
  public function enqueue_scripts() {
20
  parent::enqueue_scripts();
 
 
 
 
 
21
  wp_enqueue_script( WPAUTOTERMS_SLUG . '_contact_form', WPAUTOTERMS_PLUGIN_URL . 'js/contact-form.js',
22
  array( 'underscore', 'wp-util' ), false, true );
23
  wp_localize_script( WPAUTOTERMS_SLUG . '_contact_form', 'wpautotermsContact', array(
5
 
6
  use wpautoterms\admin\action\Send_Message;
7
 
8
+ class Help extends Base {
9
  const EP_MESSAGE = 'contact/v2/message_prepare';
10
  /**
11
  * @var Send_Message
18
 
19
  public function enqueue_scripts() {
20
  parent::enqueue_scripts();
21
+ wp_enqueue_script( 'jquery-ui-accordion' );
22
+ wp_enqueue_style( 'wpautoterms-page-help', WPAUTOTERMS_PLUGIN_URL . 'css/page-help.css' );
23
+ wp_enqueue_style( 'jquery-ui-structure', WPAUTOTERMS_PLUGIN_URL . 'css/jquery-ui.structure.css' );
24
+ wp_enqueue_style( 'jquery-ui-theme', WPAUTOTERMS_PLUGIN_URL . 'css/jquery-ui-themes/base/theme.css' );
25
+ wp_enqueue_style( 'jquery-ui-accordion', WPAUTOTERMS_PLUGIN_URL . 'css/jquery-ui-accordion.css', array( 'wp-jquery-ui-dialog' ) );
26
  wp_enqueue_script( WPAUTOTERMS_SLUG . '_contact_form', WPAUTOTERMS_PLUGIN_URL . 'js/contact-form.js',
27
  array( 'underscore', 'wp-util' ), false, true );
28
  wp_localize_script( WPAUTOTERMS_SLUG . '_contact_form', 'wpautotermsContact', array(
includes/admin/page/settings-page.php CHANGED
@@ -6,6 +6,7 @@ use wpautoterms\admin\Notices;
6
  use wpautoterms\admin\Options;
7
  use wpautoterms\api\License;
8
  use wpautoterms\Countries;
 
9
  use wpautoterms\option\Choices_Option;
10
  use wpautoterms\option\CPT_Slug_Option;
11
  use wpautoterms\option\Text_Option;
@@ -85,6 +86,8 @@ class Settings_Page extends Settings_Base {
85
  $tooltip,
86
  $this->id(), static::SECTION_ID, false, $attrs );
87
  $slug->set_fallback( array( $this, 'slug_fail' ) );
 
 
88
  }
89
 
90
  protected function _default_slug() {
@@ -115,6 +118,7 @@ class Settings_Page extends Settings_Base {
115
  public function defaults() {
116
  return array_reduce( Options::all_options(), function ( $acc, $x ) {
117
  $acc[ $x ] = Options::default_value( $x );
 
118
  return $acc;
119
  }, array() );
120
  }
6
  use wpautoterms\admin\Options;
7
  use wpautoterms\api\License;
8
  use wpautoterms\Countries;
9
+ use wpautoterms\option\Checkbox_Option;
10
  use wpautoterms\option\Choices_Option;
11
  use wpautoterms\option\CPT_Slug_Option;
12
  use wpautoterms\option\Text_Option;
86
  $tooltip,
87
  $this->id(), static::SECTION_ID, false, $attrs );
88
  $slug->set_fallback( array( $this, 'slug_fail' ) );
89
+ new Checkbox_Option( Options::SHOW_IN_PAGES_WIDGET, __( 'Show legal pages in Pages Widget', WPAUTOTERMS_SLUG ),
90
+ '', $this->id(), static::SECTION_ID );
91
  }
92
 
93
  protected function _default_slug() {
118
  public function defaults() {
119
  return array_reduce( Options::all_options(), function ( $acc, $x ) {
120
  $acc[ $x ] = Options::default_value( $x );
121
+
122
  return $acc;
123
  }, array() );
124
  }
includes/admin/review-banner.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace wpautoterms\admin;
4
+
5
+ use wpautoterms\admin\action\Set_Option;
6
+ use wpautoterms\cpt\CPT;
7
+
8
+ class Review_Banner {
9
+ const ACTION_ID = 'review_banner_disable';
10
+
11
+ /**
12
+ * @var Set_Option
13
+ */
14
+ public $action;
15
+
16
+ public function __construct() {
17
+ if ( Options::get_option( static::ACTION_ID, true ) ) {
18
+ return;
19
+ }
20
+ add_action( 'admin_notices', array( $this, 'print_notice' ) );
21
+ $this->action = new Set_Option( CPT::edit_cap(), null, static::ACTION_ID );
22
+ $this->action->set_option_name( static::ACTION_ID );
23
+ }
24
+
25
+ public function print_notice() {
26
+ if ( ! isset ( $_REQUEST['post_type'] ) || $_REQUEST['post_type'] !== CPT::type() ) {
27
+ return;
28
+ }
29
+ $c = (array) wp_count_posts( CPT::type() );
30
+ $c = array_sum( array_values( $c ) );
31
+ if ( $c < 1 ) {
32
+ return;
33
+ }
34
+ \wpautoterms\print_template( "review-banner", array( 'action_id' => static::ACTION_ID ) );
35
+ }
36
+ }
includes/box/box.php CHANGED
@@ -5,6 +5,7 @@ namespace wpautoterms\box;
5
  use wpautoterms\admin\action\Toggle_Action;
6
  use wpautoterms\admin\page;
7
  use wpautoterms\cpt\CPT;
 
8
  use wpautoterms\option\Text_Option;
9
 
10
  if ( ! defined( 'ABSPATH' ) ) {
@@ -23,6 +24,8 @@ abstract class Box {
23
  $this->_action->set_option_name( $this->_enabled_option() );
24
  $this->_title = $title;
25
  $this->_infotip = $infotip;
 
 
26
  }
27
 
28
  public function action() {
@@ -72,6 +75,19 @@ abstract class Box {
72
  );
73
  }
74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75
  public function render_page( page\Base $page ) {
76
  \wpautoterms\print_template( 'options/box-page', $this->_page_args( $page ) );
77
  }
@@ -85,7 +101,42 @@ abstract class Box {
85
  abstract public function define_options( $page_id, $section_id );
86
 
87
  protected function _custom_css_options( $page_id, $section_id ) {
88
- new Text_Option( $this->id() . '_custom_css', __( 'Additional CSS', WPAUTOTERMS_SLUG ), '',
89
- $page_id, $section_id, Text_Option::TYPE_TEXTAREA, array(), array( 'wpautoterms-resize-both' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
90
  }
91
  }
5
  use wpautoterms\admin\action\Toggle_Action;
6
  use wpautoterms\admin\page;
7
  use wpautoterms\cpt\CPT;
8
+ use wpautoterms\Frontend;
9
  use wpautoterms\option\Text_Option;
10
 
11
  if ( ! defined( 'ABSPATH' ) ) {
24
  $this->_action->set_option_name( $this->_enabled_option() );
25
  $this->_title = $title;
26
  $this->_infotip = $infotip;
27
+ // Do not uncomment, called by Compliancekits class.
28
+ // add_action( 'admin_enqueue_scripts', array( $this, 'enqueue_scripts' ) );
29
  }
30
 
31
  public function action() {
75
  );
76
  }
77
 
78
+ protected function _class_hints() {
79
+ return array();
80
+ }
81
+
82
+ protected static function _container_classes() {
83
+ return array(
84
+ '#' . Frontend::container_id( Frontend::CONTAINER_LOCATION_TOP, Frontend::CONTAINER_TYPE_STATIC ),
85
+ '#' . Frontend::container_id( Frontend::CONTAINER_LOCATION_TOP, Frontend::CONTAINER_TYPE_FIXED ),
86
+ '#' . Frontend::container_id( Frontend::CONTAINER_LOCATION_BOTTOM, Frontend::CONTAINER_TYPE_STATIC ),
87
+ '#' . Frontend::container_id( Frontend::CONTAINER_LOCATION_BOTTOM, Frontend::CONTAINER_TYPE_FIXED )
88
+ );
89
+ }
90
+
91
  public function render_page( page\Base $page ) {
92
  \wpautoterms\print_template( 'options/box-page', $this->_page_args( $page ) );
93
  }
101
  abstract public function define_options( $page_id, $section_id );
102
 
103
  protected function _custom_css_options( $page_id, $section_id ) {
104
+ $to = new Text_Option( $this->id() . '_custom_css', __( 'Additional CSS', WPAUTOTERMS_SLUG ), '',
105
+ $page_id, $section_id, 'css-textarea-option', array( 'data-codemirror' => null ),
106
+ array( 'wpautoterms-resize-both' ) );
107
+ $to->additional_template_args['class_hints'] = $this->_class_hints();
108
+ $to->additional_template_args['container_classes'] = static::_container_classes();
109
+ }
110
+
111
+ public function enqueue_scripts() {
112
+ wp_enqueue_script( WPAUTOTERMS_SLUG . '_codemirror',
113
+ WPAUTOTERMS_PLUGIN_URL . 'js/codemirror-5.42.0/codemirror.js', false, false, true );
114
+ wp_enqueue_script( WPAUTOTERMS_SLUG . '_codemirror_css',
115
+ WPAUTOTERMS_PLUGIN_URL . 'js/codemirror-5.42.0/css.js', false, false, true );
116
+ wp_enqueue_script( WPAUTOTERMS_SLUG . '_codemirror_hint',
117
+ WPAUTOTERMS_PLUGIN_URL . 'js/codemirror-5.42.0/addon/hint/show-hint.js', false, false, true );
118
+ wp_enqueue_script( WPAUTOTERMS_SLUG . '_codemirror_css_hint',
119
+ WPAUTOTERMS_PLUGIN_URL . 'js/codemirror-5.42.0/addon/hint/css-hint.js', false, false, true );
120
+ wp_enqueue_script( WPAUTOTERMS_SLUG . '_codemirror_matchbrackets',
121
+ WPAUTOTERMS_PLUGIN_URL . 'js/codemirror-5.42.0/addon/edit/matchbrackets.js', false, false, true );
122
+ wp_enqueue_script( WPAUTOTERMS_SLUG . '_codemirror_closebrackets',
123
+ WPAUTOTERMS_PLUGIN_URL . 'js/codemirror-5.42.0/addon/edit/closebrackets.js', false, false, true );
124
+ wp_enqueue_script( WPAUTOTERMS_SLUG . '_codemirror_active_line',
125
+ WPAUTOTERMS_PLUGIN_URL . 'js/codemirror-5.42.0/addon/selection/active-line.js', false, false, true );
126
+ wp_enqueue_script( WPAUTOTERMS_SLUG . '_codemirror_annotatescrollbar',
127
+ WPAUTOTERMS_PLUGIN_URL . 'js/codemirror-5.42.0/addon/scroll/annotatescrollbar.js', false, false, true );
128
+ wp_enqueue_script( WPAUTOTERMS_SLUG . '_codemirror_matchesonscrollbar',
129
+ WPAUTOTERMS_PLUGIN_URL . 'js/codemirror-5.42.0/addon/search/matchesonscrollbar.js', false, false, true );
130
+ wp_enqueue_script( WPAUTOTERMS_SLUG . '_codemirror_search_cursor',
131
+ WPAUTOTERMS_PLUGIN_URL . 'js/codemirror-5.42.0/addon/search/searchcursor.js', false, false, true );
132
+ wp_enqueue_script( WPAUTOTERMS_SLUG . '_codemirror_match_highlight',
133
+ WPAUTOTERMS_PLUGIN_URL . 'js/codemirror-5.42.0/addon/search/match-highlighter.js', false, false, true );
134
+ wp_enqueue_style( WPAUTOTERMS_SLUG . '_codemirror', WPAUTOTERMS_PLUGIN_URL . 'js/codemirror-5.42.0/codemirror.css' );
135
+ wp_enqueue_style( WPAUTOTERMS_SLUG . '_codemirror_hint',
136
+ WPAUTOTERMS_PLUGIN_URL . 'js/codemirror-5.42.0/addon/hint/show-hint.css' );
137
+ wp_enqueue_style( WPAUTOTERMS_SLUG . '_codemirror_matchesonscrollbar',
138
+ WPAUTOTERMS_PLUGIN_URL . 'js/codemirror-5.42.0/addon/search/matchesonscrollbar.css' );
139
+
140
+ wp_enqueue_script( WPAUTOTERMS_SLUG . '_css_hint', WPAUTOTERMS_PLUGIN_URL . 'js/css-hints.js', false, false, true );
141
  }
142
  }
includes/box/cookies-notice-box.php CHANGED
@@ -4,6 +4,7 @@ namespace wpautoterms\box;
4
 
5
  use wpautoterms\admin\Menu;
6
  use wpautoterms\cpt\CPT;
 
7
  use wpautoterms\option;
8
 
9
  if ( ! defined( 'ABSPATH' ) ) {
@@ -126,4 +127,11 @@ class Cookies_Notice_Box extends Licensed_Box {
126
  $this->id() . '_links_color' => '',
127
  ) );
128
  }
 
 
 
 
 
 
 
129
  }
4
 
5
  use wpautoterms\admin\Menu;
6
  use wpautoterms\cpt\CPT;
7
+ use wpautoterms\frontend\notice\Cookies_Notice;
8
  use wpautoterms\option;
9
 
10
  if ( ! defined( 'ABSPATH' ) ) {
127
  $this->id() . '_links_color' => '',
128
  ) );
129
  }
130
+
131
+ protected function _class_hints() {
132
+ return array(
133
+ __( 'Cookies notice bar class:', WPAUTOTERMS_SLUG ) => '.' . Cookies_Notice::CLASS_COOKIES_NOTICE,
134
+ __( 'Close button class:', WPAUTOTERMS_SLUG ) => '.' . Cookies_Notice::CLASS_CLOSE_BUTTON,
135
+ );
136
+ }
137
  }
includes/box/endorsements-box.php CHANGED
@@ -3,6 +3,7 @@
3
  namespace wpautoterms\box;
4
 
5
  use wpautoterms\admin\Menu;
 
6
  use wpautoterms\option;
7
 
8
  if ( ! defined( 'ABSPATH' ) ) {
@@ -95,4 +96,15 @@ class Endorsements_Box extends Licensed_Box {
95
  //$this->id().'_where'=>'',
96
  ) );
97
  }
 
 
 
 
 
 
 
 
 
 
 
98
  }
3
  namespace wpautoterms\box;
4
 
5
  use wpautoterms\admin\Menu;
6
+ use wpautoterms\frontend\Endorsements;
7
  use wpautoterms\option;
8
 
9
  if ( ! defined( 'ABSPATH' ) ) {
96
  //$this->id().'_where'=>'',
97
  ) );
98
  }
99
+
100
+ protected static function _container_classes() {
101
+ return array();
102
+
103
+ }
104
+
105
+ protected function _class_hints() {
106
+ return array(
107
+ __( 'Endorsement block class:', WPAUTOTERMS_SLUG ) => '.' . Endorsements::css_class_id(),
108
+ );
109
+ }
110
  }
includes/box/links-box.php CHANGED
@@ -3,6 +3,7 @@
3
  namespace wpautoterms\box;
4
 
5
  use wpautoterms\admin\Menu;
 
6
  use wpautoterms\option;
7
 
8
  if ( ! defined( 'ABSPATH' ) ) {
@@ -48,4 +49,12 @@ class Links_Box extends Box {
48
  $this->id() . '_target_blank' => false,
49
  );
50
  }
 
 
 
 
 
 
 
 
51
  }
3
  namespace wpautoterms\box;
4
 
5
  use wpautoterms\admin\Menu;
6
+ use wpautoterms\frontend\Links;
7
  use wpautoterms\option;
8
 
9
  if ( ! defined( 'ABSPATH' ) ) {
49
  $this->id() . '_target_blank' => false,
50
  );
51
  }
52
+
53
+ protected function _class_hints() {
54
+ return array(
55
+ __( 'Links bar class:', WPAUTOTERMS_SLUG ) => '.'.Links::FOOTER_CLASS,
56
+ __( 'Separator class:', WPAUTOTERMS_SLUG ) => '.'.Links::FOOTER_CLASS . ' .' . Links::SEPARATOR_CLASS,
57
+ __( 'Link class:', WPAUTOTERMS_SLUG ) => '.'.Links::FOOTER_CLASS . ' a',
58
+ );
59
+ }
60
  }
includes/box/update-notice-box.php CHANGED
@@ -4,6 +4,7 @@ namespace wpautoterms\box;
4
 
5
  use wpautoterms\admin\Menu;
6
  use wpautoterms\cpt\CPT;
 
7
  use wpautoterms\option;
8
 
9
  if ( ! defined( 'ABSPATH' ) ) {
@@ -138,7 +139,7 @@ class Update_Notice_Box extends Box {
138
  $a->set_values( Menu::font_sizes() );
139
  new option\Color_Option( $this->id() . '_text_color', __( 'Text color', WPAUTOTERMS_SLUG ), '', $page_id, $section_id );
140
  new option\Color_Option( $this->id() . '_links_color', __( 'Links color', WPAUTOTERMS_SLUG ), '', $page_id, $section_id );
141
- $this->_custom_css_options($page_id, $section_id);
142
  }
143
 
144
  public function defaults() {
@@ -158,4 +159,11 @@ class Update_Notice_Box extends Box {
158
  $this->id() . '_links_color' => '',
159
  );
160
  }
 
 
 
 
 
 
 
161
  }
4
 
5
  use wpautoterms\admin\Menu;
6
  use wpautoterms\cpt\CPT;
7
+ use wpautoterms\frontend\notice\Update_Notice;
8
  use wpautoterms\option;
9
 
10
  if ( ! defined( 'ABSPATH' ) ) {
139
  $a->set_values( Menu::font_sizes() );
140
  new option\Color_Option( $this->id() . '_text_color', __( 'Text color', WPAUTOTERMS_SLUG ), '', $page_id, $section_id );
141
  new option\Color_Option( $this->id() . '_links_color', __( 'Links color', WPAUTOTERMS_SLUG ), '', $page_id, $section_id );
142
+ $this->_custom_css_options( $page_id, $section_id );
143
  }
144
 
145
  public function defaults() {
159
  $this->id() . '_links_color' => '',
160
  );
161
  }
162
+
163
+ protected function _class_hints() {
164
+ return array(
165
+ __( 'Update notice class:', WPAUTOTERMS_SLUG ) => '.' . Update_Notice::BLOCK_CLASS,
166
+ __( 'Close button class:', WPAUTOTERMS_SLUG ) => '.' . Update_Notice::CLOSE_CLASS,
167
+ );
168
+ }
169
  }
includes/cpt/admin-columns.php CHANGED
@@ -10,6 +10,7 @@ abstract class Admin_Columns {
10
  const COL_CB = 'cb';
11
  const COL_TITLE = 'title';
12
  const COL_STATUS = 'status';
 
13
  const COL_LAST_DATE = 'last_date';
14
  const COL_DATE = 'date';
15
 
@@ -31,6 +32,7 @@ abstract class Admin_Columns {
31
  static::COL_CB => '<input type="checkbox" />',
32
  static::COL_TITLE => __( 'Title', WPAUTOTERMS_SLUG ),
33
  static::COL_STATUS => __( 'Status', WPAUTOTERMS_SLUG ),
 
34
  static::COL_LAST_DATE => __( 'Last Effective Date', WPAUTOTERMS_SLUG ),
35
  static::COL_DATE => __( 'Date', WPAUTOTERMS_SLUG )
36
  );
@@ -39,6 +41,7 @@ abstract class Admin_Columns {
39
  static function sortable_columns( $columns ) {
40
  $columns[ static::COL_STATUS ] = static::COL_STATUS;
41
  $columns[ static::COL_LAST_DATE ] = static::COL_LAST_DATE;
 
42
 
43
  return $columns;
44
  }
@@ -51,9 +54,22 @@ abstract class Admin_Columns {
51
  switch ( $column ) {
52
  case static::COL_LAST_DATE:
53
  if ( $post->post_status == 'publish' ) {
54
- echo esc_html(get_post_modified_time( get_option( 'date_format' ), false, $post, true ));
55
  }
56
  break;
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  }
58
  }
59
 
10
  const COL_CB = 'cb';
11
  const COL_TITLE = 'title';
12
  const COL_STATUS = 'status';
13
+ const COL_SHORTCODE = 'shortcode';
14
  const COL_LAST_DATE = 'last_date';
15
  const COL_DATE = 'date';
16
 
32
  static::COL_CB => '<input type="checkbox" />',
33
  static::COL_TITLE => __( 'Title', WPAUTOTERMS_SLUG ),
34
  static::COL_STATUS => __( 'Status', WPAUTOTERMS_SLUG ),
35
+ static::COL_SHORTCODE => __( 'Shortcode', WPAUTOTERMS_SLUG ),
36
  static::COL_LAST_DATE => __( 'Last Effective Date', WPAUTOTERMS_SLUG ),
37
  static::COL_DATE => __( 'Date', WPAUTOTERMS_SLUG )
38
  );
41
  static function sortable_columns( $columns ) {
42
  $columns[ static::COL_STATUS ] = static::COL_STATUS;
43
  $columns[ static::COL_LAST_DATE ] = static::COL_LAST_DATE;
44
+ $columns[ static::COL_SHORTCODE ] = static::COL_SHORTCODE;
45
 
46
  return $columns;
47
  }
54
  switch ( $column ) {
55
  case static::COL_LAST_DATE:
56
  if ( $post->post_status == 'publish' ) {
57
+ echo esc_html( get_post_modified_time( get_option( 'date_format' ), false, $post, true ) );
58
  }
59
  break;
60
+ case static::COL_SHORTCODE:
61
+ if ( $post->post_status == 'publish' ) {
62
+ echo esc_html( '[' . WPAUTOTERMS_SLUG . ' page="' . $post->post_name . '"]' );
63
+ } else {
64
+ echo '<abbr title="' .
65
+ __( 'Publish page to get shortcode.', WPAUTOTERMS_SLUG ) . '">' .
66
+ _x( 'N/A', 'Legal pages list', WPAUTOTERMS_SLUG )
67
+ . '</abbr>';
68
+ }
69
+ break;
70
+ case static::COL_STATUS:
71
+ echo esc_html( $post->post_status );
72
+ break;
73
  }
74
  }
75
 
includes/cpt/cpt.php CHANGED
@@ -2,8 +2,6 @@
2
 
3
  namespace wpautoterms\cpt;
4
 
5
- use wpautoterms\admin\Options;
6
-
7
  if ( ! defined( 'ABSPATH' ) ) {
8
  exit;
9
  }
@@ -11,11 +9,14 @@ if ( ! defined( 'ABSPATH' ) ) {
11
 
12
  abstract class CPT {
13
  const ROLE = 'manage_wpautoterms_pages';
14
- const ADD_TO_ROLE = 'administrator';
 
 
15
 
16
  public static function init() {
17
  add_filter( 'theme_' . static::type() . '_templates', array( __CLASS__, 'filter_templates' ), 10, 2 );
18
- add_action( 'user_register', array( __CLASS__, 'add_role' ), 10, 1 );
 
19
  }
20
 
21
  public static function edit_cap() {
@@ -51,7 +52,7 @@ abstract class CPT {
51
  );
52
  }
53
 
54
- public static function register() {
55
  $labels = array(
56
  'name' => __( 'Legal Pages', WPAUTOTERMS_SLUG ),
57
  'all_items' => __( 'All Legal Pages', WPAUTOTERMS_SLUG ),
@@ -71,9 +72,6 @@ abstract class CPT {
71
  'menu_name' => __( 'WP AutoTerms', WPAUTOTERMS_SLUG ),
72
  );
73
 
74
- $cs = static::cap_singular();
75
- $cp = static::cap_plural();
76
-
77
  $args = array(
78
  'labels' => $labels,
79
  'hierarchical' => true,
@@ -87,41 +85,40 @@ abstract class CPT {
87
  'has_archive' => true,
88
  'query_var' => true,
89
  'can_export' => true,
90
- 'rewrite' => array( 'slug' => Options::get_option( Options::LEGAL_PAGES_SLUG ) ),
91
  'map_meta_cap' => true,
92
  'capability_type' => array( static::cap_singular(), static::cap_plural() ),
93
  'menu_icon' => WPAUTOTERMS_PLUGIN_URL . 'images/icon.png',
94
  'show_admin_column' => true,
 
95
  );
96
 
97
  register_post_type( static::type(), $args );
98
  }
99
 
100
- public static function register_role() {
101
- $role = add_role( static::ROLE, __( 'WPAutoTerms Legal pages editor' ), static::caps() );
102
- if ( $role === null ) {
103
- return;
 
 
 
104
  }
105
- $users = get_users( array( 'role' => static::ADD_TO_ROLE ) );
 
 
 
 
106
  if ( ! empty( $users ) ) {
107
  /**
108
  * @var $user \WP_User
109
  */
110
  foreach ( $users as $user ) {
111
- $user->add_role( static::ROLE );
 
112
  }
113
  }
114
- }
115
-
116
- public static function unregister_role() {
117
- remove_role( static::ROLE );
118
- }
119
-
120
- public static function add_role( $user_id ) {
121
- $user = get_user_by( 'id', $user_id );
122
- if ( in_array( static::ADD_TO_ROLE, $user->roles ) ) {
123
- $user->add_role( static::ROLE );
124
- }
125
  }
126
 
127
  /**
@@ -133,4 +130,41 @@ abstract class CPT {
133
  public static function filter_templates( $post_templates, $theme ) {
134
  return array_merge( $post_templates, $theme->get_page_templates() );
135
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  }
2
 
3
  namespace wpautoterms\cpt;
4
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
9
 
10
  abstract class CPT {
11
  const ROLE = 'manage_wpautoterms_pages';
12
+ const ROLE_EDITOR = 'manage_wpautoterms_pages_editor';
13
+ const BASE_ROLE = 'editor';
14
+ protected static $_taxonomies = array( 'category' );
15
 
16
  public static function init() {
17
  add_filter( 'theme_' . static::type() . '_templates', array( __CLASS__, 'filter_templates' ), 10, 2 );
18
+ add_filter( 'map_meta_cap', array( __CLASS__, 'map_meta_cap' ), 10, 4 );
19
+ add_action( 'admin_menu', array( __CLASS__, 'remove_taxonomies' ) );
20
  }
21
 
22
  public static function edit_cap() {
52
  );
53
  }
54
 
55
+ public static function register( $slug ) {
56
  $labels = array(
57
  'name' => __( 'Legal Pages', WPAUTOTERMS_SLUG ),
58
  'all_items' => __( 'All Legal Pages', WPAUTOTERMS_SLUG ),
72
  'menu_name' => __( 'WP AutoTerms', WPAUTOTERMS_SLUG ),
73
  );
74
 
 
 
 
75
  $args = array(
76
  'labels' => $labels,
77
  'hierarchical' => true,
85
  'has_archive' => true,
86
  'query_var' => true,
87
  'can_export' => true,
88
+ 'rewrite' => array( 'slug' => $slug ),
89
  'map_meta_cap' => true,
90
  'capability_type' => array( static::cap_singular(), static::cap_plural() ),
91
  'menu_icon' => WPAUTOTERMS_PLUGIN_URL . 'images/icon.png',
92
  'show_admin_column' => true,
93
+ 'taxonomies' => static::$_taxonomies
94
  );
95
 
96
  register_post_type( static::type(), $args );
97
  }
98
 
99
+ public static function register_roles() {
100
+ add_role( static::ROLE, __( 'WPAutoTerms Pages Editor (additional)' ), static::caps() );
101
+ $role = get_role( static::BASE_ROLE );
102
+ if ( ! empty( $role ) ) {
103
+ add_role( static::ROLE_EDITOR,
104
+ __( 'Editor + WPAutoTerms Pages Editor' ),
105
+ array_merge( $role->capabilities, static::caps() ) );
106
  }
107
+ }
108
+
109
+ public static function unregister_roles() {
110
+ remove_role( static::ROLE );
111
+ $users = get_users( array( 'role' => static::ROLE_EDITOR ) );
112
  if ( ! empty( $users ) ) {
113
  /**
114
  * @var $user \WP_User
115
  */
116
  foreach ( $users as $user ) {
117
+ $user->add_role( static::BASE_ROLE );
118
+ $user->remove_role( static::ROLE_EDITOR );
119
  }
120
  }
121
+ remove_role( static::ROLE_EDITOR );
 
 
 
 
 
 
 
 
 
 
122
  }
123
 
124
  /**
130
  public static function filter_templates( $post_templates, $theme ) {
131
  return array_merge( $post_templates, $theme->get_page_templates() );
132
  }
133
+
134
+ public static function endswith( $haystack, $needle ) {
135
+ return $needle === substr( $haystack, - strlen( $needle ) );
136
+ }
137
+
138
+ protected static function is_current_cap( $cap ) {
139
+ return static::endswith( $cap, static::cap_singular() ) || static::endswith( $cap, static::cap_plural() );
140
+ }
141
+
142
+ public static function map_meta_cap( $caps, $cap, $user_id, $args ) {
143
+ if ( isset( $args[0] ) ) {
144
+ $ok = false;
145
+ foreach ( $caps as $c ) {
146
+ if ( static::is_current_cap( $caps[0] ) ) {
147
+ $ok = true;
148
+ break;
149
+ }
150
+ }
151
+ if ( ! $ok ) {
152
+ return $caps;
153
+ }
154
+ } elseif ( ! static::is_current_cap( $cap ) ) {
155
+ return $caps;
156
+ }
157
+ if ( is_super_admin( $user_id ) ) {
158
+ return array();
159
+ }
160
+
161
+ return $caps;
162
+ }
163
+
164
+ public static function remove_taxonomies() {
165
+ foreach ( static::$_taxonomies as $t ) {
166
+ remove_submenu_page( 'edit.php?post_type=' . static::type(),
167
+ 'edit-tags.php?taxonomy=' . $t . '&amp;post_type=' . static::type() );
168
+ }
169
+ }
170
  }
includes/frontend.php CHANGED
@@ -7,6 +7,7 @@ use wpautoterms\frontend\Endorsements;
7
  use wpautoterms\frontend\Links;
8
  use wpautoterms\frontend\notice\Cookies_Notice;
9
  use wpautoterms\frontend\notice\Update_Notice;
 
10
 
11
  abstract class Frontend {
12
  protected static $_body_top = '';
@@ -15,6 +16,12 @@ abstract class Frontend {
15
  */
16
  protected static $_links;
17
 
 
 
 
 
 
 
18
  public static function init( $license ) {
19
  global $pagenow;
20
  if ( in_array( $pagenow, array( 'wp-login.php', 'wp-register.php' ) ) ) {
@@ -31,6 +38,7 @@ abstract class Frontend {
31
  $a->init();
32
  new Endorsements( $license );
33
  static::$_links = new Links();
 
34
  }
35
 
36
 
@@ -81,13 +89,17 @@ abstract class Frontend {
81
  static::bottom_container();
82
  }
83
 
 
 
 
 
84
  protected static function container( $where, $type, $return = false ) {
85
  ob_start();
86
  do_action( WPAUTOTERMS_SLUG . '_container', $where, $type );
87
  $c = ob_get_contents();
88
  ob_end_clean();
89
  if ( ! empty( $c ) ) {
90
- $c = '<div id="wpautoterms-' . $where . '-' . $type . '-container">' . $c . '</div>';
91
  }
92
  if ( $return ) {
93
  return $c;
@@ -98,8 +110,8 @@ abstract class Frontend {
98
  }
99
 
100
  protected static function top_container( $return = false ) {
101
- $c = static::container( 'top', 'static', $return );
102
- $c .= static::container( 'top', 'fixed', $return );
103
  if ( $return ) {
104
  return $c;
105
  }
@@ -109,7 +121,7 @@ abstract class Frontend {
109
  }
110
 
111
  protected static function bottom_container() {
112
- static::container( 'bottom', 'fixed' );
113
- static::container( 'bottom', 'static' );
114
  }
115
  }
7
  use wpautoterms\frontend\Links;
8
  use wpautoterms\frontend\notice\Cookies_Notice;
9
  use wpautoterms\frontend\notice\Update_Notice;
10
+ use wpautoterms\frontend\Pages_Widget_Extend;
11
 
12
  abstract class Frontend {
13
  protected static $_body_top = '';
16
  */
17
  protected static $_links;
18
 
19
+ const CONTAINER_LOCATION_TOP = 'top';
20
+ const CONTAINER_LOCATION_BOTTOM = 'bottom';
21
+ const CONTAINER_TYPE_STATIC = 'static';
22
+ const CONTAINER_TYPE_FIXED = 'fixed';
23
+
24
+
25
  public static function init( $license ) {
26
  global $pagenow;
27
  if ( in_array( $pagenow, array( 'wp-login.php', 'wp-register.php' ) ) ) {
38
  $a->init();
39
  new Endorsements( $license );
40
  static::$_links = new Links();
41
+ new Pages_Widget_Extend();
42
  }
43
 
44
 
89
  static::bottom_container();
90
  }
91
 
92
+ public static function container_id( $where = self::CONTAINER_LOCATION_TOP, $type = self::CONTAINER_TYPE_STATIC ) {
93
+ return 'wpautoterms-' . $where . '-' . $type . '-container';
94
+ }
95
+
96
  protected static function container( $where, $type, $return = false ) {
97
  ob_start();
98
  do_action( WPAUTOTERMS_SLUG . '_container', $where, $type );
99
  $c = ob_get_contents();
100
  ob_end_clean();
101
  if ( ! empty( $c ) ) {
102
+ $c = '<div id="' . static::container_id( $where, $type ) . '">' . $c . '</div>';
103
  }
104
  if ( $return ) {
105
  return $c;
110
  }
111
 
112
  protected static function top_container( $return = false ) {
113
+ $c = static::container( self::CONTAINER_LOCATION_TOP, self::CONTAINER_TYPE_STATIC, $return );
114
+ $c .= static::container( self::CONTAINER_LOCATION_TOP, self::CONTAINER_TYPE_FIXED, $return );
115
  if ( $return ) {
116
  return $c;
117
  }
121
  }
122
 
123
  protected static function bottom_container() {
124
+ static::container( self::CONTAINER_LOCATION_BOTTOM, self::CONTAINER_TYPE_FIXED );
125
+ static::container( self::CONTAINER_LOCATION_BOTTOM, self::CONTAINER_TYPE_STATIC );
126
  }
127
  }
includes/frontend/endorsements.php CHANGED
@@ -46,11 +46,15 @@ class Endorsements {
46
  $message = \wpautoterms\print_template( static::ID, array(
47
  'message' => do_shortcode( $message )
48
  ), true );
49
- $message = Styles::print_styles( static::ID, 'wpautoterms-' . static::ID, true ) . $message;
50
  if ( $where == 'bottom' ) {
51
  return $content . $message;
52
  }
53
 
54
  return $message . $content;
55
  }
 
 
 
 
56
  }
46
  $message = \wpautoterms\print_template( static::ID, array(
47
  'message' => do_shortcode( $message )
48
  ), true );
49
+ $message = Styles::print_styles( static::ID, static::css_class_id(), true ) . $message;
50
  if ( $where == 'bottom' ) {
51
  return $content . $message;
52
  }
53
 
54
  return $message . $content;
55
  }
56
+
57
+ public static function css_class_id() {
58
+ return 'wpautoterms-' . static::ID;
59
+ }
60
  }
includes/frontend/links.php CHANGED
@@ -9,6 +9,8 @@ use wpautoterms\gen_css\Record;
9
 
10
  class Links {
11
  const MODULE_ID = 'links';
 
 
12
 
13
  public function __construct() {
14
  add_action( 'wp_print_styles', array( $this, 'print_styles' ) );
@@ -26,6 +28,7 @@ class Links {
26
  'post_type' => CPT::type(),
27
  'post_status' => 'publish',
28
  'orderby' => 'post_modified',
 
29
  );
30
 
31
  $posts = get_posts( $args );
@@ -40,16 +43,16 @@ class Links {
40
  }
41
 
42
  $d = new Document( array(
43
- new Record( '.wpautoterms-footer', array(
44
  new Attr( $option_prefix, Attr::TYPE_BG_COLOR ),
45
  new Attr( $option_prefix, Attr::TYPE_TEXT_ALIGN ),
46
  ) ),
47
- new Record( '.wpautoterms-footer a', array(
48
  new Attr( $option_prefix, Attr::TYPE_LINKS_COLOR ),
49
  new Attr( $option_prefix, Attr::TYPE_FONT ),
50
  new Attr( $option_prefix, Attr::TYPE_FONT_SIZE ),
51
  ) ),
52
- new Record( '.wpautoterms-footer .separator', array(
53
  new Attr( $option_prefix, Attr::TYPE_TEXT_COLOR ),
54
  new Attr( $option_prefix, Attr::TYPE_FONT ),
55
  new Attr( $option_prefix, Attr::TYPE_FONT_SIZE ),
9
 
10
  class Links {
11
  const MODULE_ID = 'links';
12
+ const FOOTER_CLASS = 'wpautoterms-footer';
13
+ const SEPARATOR_CLASS = 'separator';
14
 
15
  public function __construct() {
16
  add_action( 'wp_print_styles', array( $this, 'print_styles' ) );
28
  'post_type' => CPT::type(),
29
  'post_status' => 'publish',
30
  'orderby' => 'post_modified',
31
+ 'numberposts' => - 1
32
  );
33
 
34
  $posts = get_posts( $args );
43
  }
44
 
45
  $d = new Document( array(
46
+ new Record( '.' . static::FOOTER_CLASS, array(
47
  new Attr( $option_prefix, Attr::TYPE_BG_COLOR ),
48
  new Attr( $option_prefix, Attr::TYPE_TEXT_ALIGN ),
49
  ) ),
50
+ new Record( '.' . static::FOOTER_CLASS . ' a', array(
51
  new Attr( $option_prefix, Attr::TYPE_LINKS_COLOR ),
52
  new Attr( $option_prefix, Attr::TYPE_FONT ),
53
  new Attr( $option_prefix, Attr::TYPE_FONT_SIZE ),
54
  ) ),
55
+ new Record( '.' . static::FOOTER_CLASS . ' .' . static::SEPARATOR_CLASS, array(
56
  new Attr( $option_prefix, Attr::TYPE_TEXT_COLOR ),
57
  new Attr( $option_prefix, Attr::TYPE_FONT ),
58
  new Attr( $option_prefix, Attr::TYPE_FONT_SIZE ),
includes/frontend/notice/cookies-notice.php CHANGED
@@ -9,13 +9,15 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  }
10
 
11
  class Cookies_Notice extends Base_Notice {
 
 
12
  /**
13
  * @var License
14
  */
15
  protected $_license;
16
 
17
  public static function create( $license ) {
18
- $a = new Cookies_Notice( 'cookies_notice', 'wpautoterms-cookies-notice-container', 'wpautoterms-cookies-notice' );
19
  $a->set_license( $license );
20
 
21
  return $a;
9
  }
10
 
11
  class Cookies_Notice extends Base_Notice {
12
+ const CLASS_COOKIES_NOTICE = 'wpautoterms-cookies-notice';
13
+ const CLASS_CLOSE_BUTTON = 'wpautoterms-notice-close';
14
  /**
15
  * @var License
16
  */
17
  protected $_license;
18
 
19
  public static function create( $license ) {
20
+ $a = new Cookies_Notice( 'cookies_notice', 'wpautoterms-cookies-notice-container', self::CLASS_COOKIES_NOTICE );
21
  $a->set_license( $license );
22
 
23
  return $a;
includes/frontend/notice/update-notice.php CHANGED
@@ -9,13 +9,15 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  }
10
 
11
  class Update_Notice extends Base_Notice {
 
 
12
 
13
  protected $_duration;
14
  protected $_posts;
15
  public $message_multiple;
16
 
17
  public static function create() {
18
- $a = new Update_Notice( 'update_notice', 'wpautoterms-update-notice-container', 'wpautoterms-update-notice' );
19
  $a->message_multiple = get_option( WPAUTOTERMS_OPTION_PREFIX . $a->id() . '_message_multiple' );
20
 
21
  return $a;
9
  }
10
 
11
  class Update_Notice extends Base_Notice {
12
+ const BLOCK_CLASS = 'wpautoterms-update-notice';
13
+ const CLOSE_CLASS = 'wpautoterms-notice-close';
14
 
15
  protected $_duration;
16
  protected $_posts;
17
  public $message_multiple;
18
 
19
  public static function create() {
20
+ $a = new Update_Notice( 'update_notice', 'wpautoterms-update-notice-container', static::BLOCK_CLASS );
21
  $a->message_multiple = get_option( WPAUTOTERMS_OPTION_PREFIX . $a->id() . '_message_multiple' );
22
 
23
  return $a;
includes/frontend/pages-widget-extend.php ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace wpautoterms\frontend;
4
+
5
+ use wpautoterms\admin\Options;
6
+ use wpautoterms\cpt\CPT;
7
+
8
+ class Pages_Widget_Extend {
9
+ const MARKER = 'wpautoterms_pages_widget_extend_marker';
10
+
11
+ public function __construct() {
12
+ add_filter( 'widget_pages_args', array( $this, 'widget_pages_args' ), 10 );
13
+ add_filter( 'wp_list_pages', array( $this, 'wp_list_pages' ), 10, 3 );
14
+ }
15
+
16
+ public function widget_pages_args( $args ) {
17
+ $args[ static::MARKER ] = true;
18
+
19
+ return $args;
20
+ }
21
+
22
+ public function wp_list_pages( $output, $r, $pages ) {
23
+ if ( ! isset( $r[ static::MARKER ] ) || ! Options::get_option( Options::SHOW_IN_PAGES_WIDGET ) ) {
24
+ return $output;
25
+ }
26
+ $args = $r;
27
+ unset( $args[ static::MARKER ] );
28
+ $args['post_type'] = CPT::type();
29
+ $output .= wp_list_pages( $args );
30
+
31
+ return $output;
32
+ }
33
+ }
includes/frontend/widget.php ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace wpautoterms\frontend;
4
+
5
+ use wpautoterms\cpt\CPT;
6
+
7
+ class Widget extends \WP_Widget {
8
+ const ORDER_POST_TITLE = 'post_title';
9
+ const ORDER_MENU_ORDER = 'menu_order';
10
+ const ORDER_ID = 'ID';
11
+
12
+ protected $_default_order;
13
+
14
+ function __construct() {
15
+ $this->_default_order = static::ORDER_MENU_ORDER;
16
+ parent::__construct(
17
+ WPAUTOTERMS_SLUG . '_widget',
18
+ esc_html__( 'Legal Pages', WPAUTOTERMS_SLUG ),
19
+ array( 'description' => esc_html__( 'Show WP AutoTerms Legal Pages list', WPAUTOTERMS_SLUG ), )
20
+ );
21
+ }
22
+
23
+ public static function init() {
24
+ add_action( 'widgets_init', array( __CLASS__, '_register_widget' ) );
25
+ }
26
+
27
+ public static function _register_widget() {
28
+ register_widget( 'wpautoterms\frontend\Widget' );
29
+ }
30
+
31
+ /**
32
+ * Front-end display of widget.
33
+ *
34
+ * @see WP_Widget::widget()
35
+ *
36
+ * @param array $args Widget arguments.
37
+ * @param array $instance Saved values from database.
38
+ */
39
+ public function widget( $args, $instance ) {
40
+ $title = ! empty( $instance['title'] ) ? $instance['title'] : __( 'WP AutoTerms Legal Pages' );
41
+ $sortby = empty( $instance['sortby'] ) ? $this->_default_order : $instance['sortby'];
42
+ $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
43
+
44
+ if ( $sortby == static::ORDER_MENU_ORDER ) {
45
+ $sortby = 'menu_order, post_title';
46
+ }
47
+
48
+ $out = wp_list_pages( array(
49
+ 'title_li' => '',
50
+ 'echo' => 0,
51
+ 'sort_column' => $sortby,
52
+ 'exclude' => $exclude,
53
+ 'post_type' => CPT::type()
54
+ ) );
55
+
56
+ if ( ! empty( $out ) ) {
57
+ echo $args['before_widget'];
58
+ if ( $title ) {
59
+ echo $args['before_title'] . $title . $args['after_title'];
60
+ }
61
+ ?>
62
+ <ul>
63
+ <?php echo $out; ?>
64
+ </ul>
65
+ <?php
66
+ echo $args['after_widget'];
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Back-end widget form.
72
+ *
73
+ * @see WP_Widget::form()
74
+ *
75
+ * @param array $instance Previously saved values from database.
76
+ */
77
+ public function form( $instance ) {
78
+ $instance = wp_parse_args( (array) $instance, array(
79
+ 'sortby' => $this->_default_order,
80
+ 'title' => '',
81
+ 'exclude' => ''
82
+ ) );
83
+ ?>
84
+ <p>
85
+ <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php
86
+ echo _x( 'Title:', 'widget', WPAUTOTERMS_SLUG ); ?></label>
87
+ <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"
88
+ name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text"
89
+ value="<?php echo esc_attr( $instance['title'] ); ?>"/>
90
+ </p>
91
+ <p>
92
+ <label for="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>"><?php
93
+ echo _x( 'Sort by:', 'widget', WPAUTOTERMS_SLUG ); ?></label>
94
+ <select name="<?php echo esc_attr( $this->get_field_name( 'sortby' ) ); ?>"
95
+ id="<?php echo esc_attr( $this->get_field_id( 'sortby' ) ); ?>" class="widefat">
96
+ <option value="<?php static::ORDER_POST_TITLE; ?>"<?php
97
+ selected( $instance['sortby'], static::ORDER_POST_TITLE ); ?>><?php
98
+ echo _x( 'Page title', 'widget', WPAUTOTERMS_SLUG ); ?></option>
99
+ <option value="<?php static::ORDER_MENU_ORDER; ?>"<?php
100
+ selected( $instance['sortby'], static::ORDER_MENU_ORDER ); ?>><?php
101
+ echo _x( 'Page order', 'widget', WPAUTOTERMS_SLUG ); ?></option>
102
+ <option value="<?php static::ORDER_ID; ?>"<?php
103
+ selected( $instance['sortby'], static::ORDER_ID ); ?>><?php
104
+ echo _x( 'Page ID', 'widget', WPAUTOTERMS_SLUG ); ?></option>
105
+ </select>
106
+ </p>
107
+ <p>
108
+ <label for="<?php echo esc_attr( $this->get_field_id( 'exclude' ) ); ?>"><?php
109
+ echo _x( 'Exclude:', 'widget', WPAUTOTERMS_SLUG ); ?></label>
110
+ <input type="text" value="<?php echo esc_attr( $instance['exclude'] ); ?>"
111
+ name="<?php echo esc_attr( $this->get_field_name( 'exclude' ) ); ?>"
112
+ id="<?php echo esc_attr( $this->get_field_id( 'exclude' ) ); ?>" class="widefat"/>
113
+ <br/>
114
+ <small><?php echo _x( 'Page IDs, separated by commas.', 'widget', WPAUTOTERMS_SLUG ); ?></small>
115
+ </p>
116
+ <?php
117
+ }
118
+
119
+ /**
120
+ * Sanitize widget form values as they are saved.
121
+ *
122
+ * @see WP_Widget::update()
123
+ *
124
+ * @param array $new_instance Values just sent to be saved.
125
+ * @param array $old_instance Previously saved values from database.
126
+ *
127
+ * @return array Updated safe values to be saved.
128
+ */
129
+ public function update( $new_instance, $old_instance ) {
130
+ $instance = $old_instance;
131
+ $instance['title'] = sanitize_text_field( $new_instance['title'] );
132
+ if ( in_array( $new_instance['sortby'], array(
133
+ static::ORDER_POST_TITLE,
134
+ static::ORDER_MENU_ORDER,
135
+ static::ORDER_ID
136
+ ) ) ) {
137
+ $instance['sortby'] = $new_instance['sortby'];
138
+ } else {
139
+ $instance['sortby'] = $this->_default_order;
140
+ }
141
+
142
+ $instance['exclude'] = sanitize_text_field( $new_instance['exclude'] );
143
+
144
+ return $instance;
145
+ }
146
+ }
includes/option/option.php CHANGED
@@ -18,6 +18,7 @@ abstract class Option {
18
  protected $_tooltip;
19
  protected $_attrs;
20
  protected $_classes;
 
21
 
22
  protected function _prepare_attrs() {
23
  $ret = array();
@@ -94,13 +95,13 @@ abstract class Option {
94
  }
95
 
96
  protected function _template_args() {
97
- return array(
98
  'name' => esc_attr( $this->_name ),
99
  'value' => $this->get_value(),
100
  'tooltip' => $this->_tooltip,
101
  'attrs' => $this->_prepare_attrs(),
102
  'classes' => join( ' ', array_map( 'esc_attr', $this->_classes ) )
103
- );
104
  }
105
 
106
  protected function _handle_render( $template, $args ) {
18
  protected $_tooltip;
19
  protected $_attrs;
20
  protected $_classes;
21
+ public $additional_template_args = array();
22
 
23
  protected function _prepare_attrs() {
24
  $ret = array();
95
  }
96
 
97
  protected function _template_args() {
98
+ return array_merge( array(
99
  'name' => esc_attr( $this->_name ),
100
  'value' => $this->get_value(),
101
  'tooltip' => $this->_tooltip,
102
  'attrs' => $this->_prepare_attrs(),
103
  'classes' => join( ' ', array_map( 'esc_attr', $this->_classes ) )
104
+ ), $this->additional_template_args );
105
  }
106
 
107
  protected function _handle_render( $template, $args ) {
includes/shortcode/i-shortcode-handler.php ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ namespace wpautoterms\shortcode;
4
+
5
+ if ( ! defined( 'ABSPATH' ) ) {
6
+ exit;
7
+ }
8
+
9
+ interface I_Shortcode_Handler {
10
+ function handle( $values, $content );
11
+ }
includes/shortcode/post-base.php CHANGED
@@ -2,6 +2,8 @@
2
 
3
  namespace wpautoterms\shortcode;
4
 
 
 
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
@@ -9,6 +11,19 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  abstract class Post_Base extends Sub_Shortcode {
10
 
11
  function handle( $values, $content ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  global $wpautoterms_post;
13
  if ( ! empty( $wpautoterms_post ) ) {
14
  return $this->handle_post( $wpautoterms_post, $values, $content );
@@ -21,5 +36,12 @@ abstract class Post_Base extends Sub_Shortcode {
21
  return $this->handle_post( $post, $values, $content );
22
  }
23
 
 
 
 
 
 
 
 
24
  abstract protected function handle_post( $post, $values, $content );
25
  }
2
 
3
  namespace wpautoterms\shortcode;
4
 
5
+ use wpautoterms\cpt\CPT;
6
+
7
  if ( ! defined( 'ABSPATH' ) ) {
8
  exit;
9
  }
11
  abstract class Post_Base extends Sub_Shortcode {
12
 
13
  function handle( $values, $content ) {
14
+ $k = array_keys( $values );
15
+ if ( ! empty( $k ) && isset( $values[ $k[0] ] ) ) {
16
+ $args = array(
17
+ 'name' => $values[ $k[0] ],
18
+ 'post_status' => 'publish',
19
+ 'numberposts' => 1,
20
+ 'post_type' => CPT::type()
21
+ );
22
+ $posts = get_posts( $args );
23
+ if ( ! empty( $posts ) ) {
24
+ return $this->handle_post( $posts[0], $values, $content );
25
+ }
26
+ }
27
  global $wpautoterms_post;
28
  if ( ! empty( $wpautoterms_post ) ) {
29
  return $this->handle_post( $wpautoterms_post, $values, $content );
36
  return $this->handle_post( $post, $values, $content );
37
  }
38
 
39
+ /**
40
+ * @param \WP_Post $post
41
+ * @param array $values
42
+ * @param $content
43
+ *
44
+ * @return string
45
+ */
46
  abstract protected function handle_post( $post, $values, $content );
47
  }
includes/shortcode/shortcode.php CHANGED
@@ -6,9 +6,15 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
- class Shortcode {
10
  protected $_name;
 
 
 
11
  protected $_subs = array();
 
 
 
12
  protected $_default_handler;
13
 
14
  function __construct( $name, $default_handler = false ) {
@@ -18,8 +24,9 @@ class Shortcode {
18
  }
19
 
20
  function handle( $values, $content ) {
21
- if ( isset( $values[0] ) && isset( $this->_subs[ $values[0] ] ) ) {
22
- return $this->_subs[ $values[0] ]->handle( $values, $content );
 
23
  }
24
  if ( $this->_default_handler ) {
25
  return $this->_default_handler->handle( $values, $content );
@@ -28,11 +35,11 @@ class Shortcode {
28
  return '';
29
  }
30
 
31
- function add_subshortcode( $sub ) {
32
  $this->_subs[ $sub->name() ] = $sub;
33
  }
34
 
35
- function remove_subshortcode( $sub ) {
36
  unset( $this->_subs[ $sub->name() ] );
37
  }
38
 
6
  exit;
7
  }
8
 
9
+ class Shortcode implements I_Shortcode_Handler {
10
  protected $_name;
11
+ /**
12
+ * @var I_Shortcode_Handler[]
13
+ */
14
  protected $_subs = array();
15
+ /**
16
+ * @var false|I_Shortcode_Handler
17
+ */
18
  protected $_default_handler;
19
 
20
  function __construct( $name, $default_handler = false ) {
24
  }
25
 
26
  function handle( $values, $content ) {
27
+ $k = array_keys( $values );
28
+ if ( isset( $k[0] ) && isset( $this->_subs[ $k[0] ] ) ) {
29
+ return $this->_subs[ $k[0] ]->handle( $values, $content );
30
  }
31
  if ( $this->_default_handler ) {
32
  return $this->_default_handler->handle( $values, $content );
35
  return '';
36
  }
37
 
38
+ function add_subshortcode( Sub_Shortcode $sub ) {
39
  $this->_subs[ $sub->name() ] = $sub;
40
  }
41
 
42
+ function remove_subshortcode( Sub_Shortcode $sub ) {
43
  unset( $this->_subs[ $sub->name() ] );
44
  }
45
 
includes/shortcode/sub-shortcode.php CHANGED
@@ -6,7 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
8
 
9
- abstract class Sub_Shortcode {
10
  protected $_name;
11
 
12
  function __construct( $name ) {
6
  exit;
7
  }
8
 
9
+ abstract class Sub_Shortcode implements I_Shortcode_Handler {
10
  protected $_name;
11
 
12
  function __construct( $name ) {
includes/shortcodes.php CHANGED
@@ -21,6 +21,7 @@ abstract class Shortcodes {
21
  static::$_root = new shortcode\Shortcode( WPAUTOTERMS_SLUG );
22
  static::$_root->add_subshortcode( new shortcode\Last_Updated( 'last_updated_date' ) );
23
  static::$_root->add_subshortcode( new shortcode\Post_Data( 'page_title', 'post_title' ) );
 
24
  static::$_root->add_subshortcode( new shortcode\Post_Link( 'page_link' ) );
25
  static::$_root->add_subshortcode( new shortcode\Post_Titles( 'page_titles' ) );
26
  static::$_root->add_subshortcode( new shortcode\Post_Links( 'page_links' ) );
21
  static::$_root = new shortcode\Shortcode( WPAUTOTERMS_SLUG );
22
  static::$_root->add_subshortcode( new shortcode\Last_Updated( 'last_updated_date' ) );
23
  static::$_root->add_subshortcode( new shortcode\Post_Data( 'page_title', 'post_title' ) );
24
+ static::$_root->add_subshortcode( new shortcode\Post_Data( 'page', 'post_content' ) );
25
  static::$_root->add_subshortcode( new shortcode\Post_Link( 'page_link' ) );
26
  static::$_root->add_subshortcode( new shortcode\Post_Titles( 'page_titles' ) );
27
  static::$_root->add_subshortcode( new shortcode\Post_Links( 'page_links' ) );
includes/upgrade.php CHANGED
@@ -20,7 +20,7 @@ class Upgrade {
20
  if ( ! get_option( WPAUTOTERMS_OPTION_PREFIX . WPAUTOTERMS_OPTION_ACTIVATED ) ) {
21
  flush_rewrite_rules();
22
  update_option( WPAUTOTERMS_OPTION_PREFIX . WPAUTOTERMS_OPTION_ACTIVATED, true );
23
- CPT::register_role();
24
  $activated = true;
25
  $this->_activate = true;
26
  } else {
@@ -33,7 +33,7 @@ class Upgrade {
33
  }
34
  $this->_add_slug_option();
35
  if ( ! $activated ) {
36
- CPT::register_role();
37
  }
38
  update_option( WPAUTOTERMS_OPTION_PREFIX . Menu::VERSION, WPAUTOTERMS_VERSION );
39
  }
20
  if ( ! get_option( WPAUTOTERMS_OPTION_PREFIX . WPAUTOTERMS_OPTION_ACTIVATED ) ) {
21
  flush_rewrite_rules();
22
  update_option( WPAUTOTERMS_OPTION_PREFIX . WPAUTOTERMS_OPTION_ACTIVATED, true );
23
+ CPT::register_roles();
24
  $activated = true;
25
  $this->_activate = true;
26
  } else {
33
  }
34
  $this->_add_slug_option();
35
  if ( ! $activated ) {
36
+ CPT::register_roles();
37
  }
38
  update_option( WPAUTOTERMS_OPTION_PREFIX . Menu::VERSION, WPAUTOTERMS_VERSION );
39
  }
includes/wpautoterms.php CHANGED
@@ -3,7 +3,9 @@
3
  namespace wpautoterms;
4
 
5
  use wpautoterms\admin\form\Legal_Page;
 
6
  use wpautoterms\cpt\CPT;
 
7
  use wpautoterms\legal_pages;
8
 
9
  abstract class Wpautoterms {
@@ -28,6 +30,7 @@ abstract class Wpautoterms {
28
  CPT::init();
29
  Shortcodes::init();
30
  Legacy_Shortcodes::init();
 
31
  }
32
 
33
  /**
@@ -57,7 +60,7 @@ abstract class Wpautoterms {
57
  }
58
 
59
  public static function action_init() {
60
- CPT::register();
61
  do_action( WPAUTOTERMS_SLUG . '_registered_cpt' );
62
  }
63
  }
3
  namespace wpautoterms;
4
 
5
  use wpautoterms\admin\form\Legal_Page;
6
+ use wpautoterms\admin\Options;
7
  use wpautoterms\cpt\CPT;
8
+ use wpautoterms\frontend\Widget;
9
  use wpautoterms\legal_pages;
10
 
11
  abstract class Wpautoterms {
30
  CPT::init();
31
  Shortcodes::init();
32
  Legacy_Shortcodes::init();
33
+ Widget::init();
34
  }
35
 
36
  /**
60
  }
61
 
62
  public static function action_init() {
63
+ CPT::register( Options::get_option( Options::LEGAL_PAGES_SLUG ) );
64
  do_action( WPAUTOTERMS_SLUG . '_registered_cpt' );
65
  }
66
  }
js/codemirror-5.42.0/addon/edit/closebrackets.js ADDED
@@ -0,0 +1,187 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
+
4
+ (function(mod) {
5
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
6
+ mod(require("../../lib/codemirror"));
7
+ else if (typeof define == "function" && define.amd) // AMD
8
+ define(["../../lib/codemirror"], mod);
9
+ else // Plain browser env
10
+ mod(CodeMirror);
11
+ })(function(CodeMirror) {
12
+ var defaults = {
13
+ pairs: "()[]{}''\"\"",
14
+ triples: "",
15
+ explode: "[]{}"
16
+ };
17
+
18
+ var Pos = CodeMirror.Pos;
19
+
20
+ CodeMirror.defineOption("autoCloseBrackets", false, function(cm, val, old) {
21
+ if (old && old != CodeMirror.Init) {
22
+ cm.removeKeyMap(keyMap);
23
+ cm.state.closeBrackets = null;
24
+ }
25
+ if (val) {
26
+ ensureBound(getOption(val, "pairs"))
27
+ cm.state.closeBrackets = val;
28
+ cm.addKeyMap(keyMap);
29
+ }
30
+ });
31
+
32
+ function getOption(conf, name) {
33
+ if (name == "pairs" && typeof conf == "string") return conf;
34
+ if (typeof conf == "object" && conf[name] != null) return conf[name];
35
+ return defaults[name];
36
+ }
37
+
38
+ var keyMap = {Backspace: handleBackspace, Enter: handleEnter};
39
+ function ensureBound(chars) {
40
+ for (var i = 0; i < chars.length; i++) {
41
+ var ch = chars.charAt(i), key = "'" + ch + "'"
42
+ if (!keyMap[key]) keyMap[key] = handler(ch)
43
+ }
44
+ }
45
+ ensureBound(defaults.pairs + "`")
46
+
47
+ function handler(ch) {
48
+ return function(cm) { return handleChar(cm, ch); };
49
+ }
50
+
51
+ function getConfig(cm) {
52
+ var deflt = cm.state.closeBrackets;
53
+ if (!deflt || deflt.override) return deflt;
54
+ var mode = cm.getModeAt(cm.getCursor());
55
+ return mode.closeBrackets || deflt;
56
+ }
57
+
58
+ function handleBackspace(cm) {
59
+ var conf = getConfig(cm);
60
+ if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass;
61
+
62
+ var pairs = getOption(conf, "pairs");
63
+ var ranges = cm.listSelections();
64
+ for (var i = 0; i < ranges.length; i++) {
65
+ if (!ranges[i].empty()) return CodeMirror.Pass;
66
+ var around = charsAround(cm, ranges[i].head);
67
+ if (!around || pairs.indexOf(around) % 2 != 0) return CodeMirror.Pass;
68
+ }
69
+ for (var i = ranges.length - 1; i >= 0; i--) {
70
+ var cur = ranges[i].head;
71
+ cm.replaceRange("", Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1), "+delete");
72
+ }
73
+ }
74
+
75
+ function handleEnter(cm) {
76
+ var conf = getConfig(cm);
77
+ var explode = conf && getOption(conf, "explode");
78
+ if (!explode || cm.getOption("disableInput")) return CodeMirror.Pass;
79
+
80
+ var ranges = cm.listSelections();
81
+ for (var i = 0; i < ranges.length; i++) {
82
+ if (!ranges[i].empty()) return CodeMirror.Pass;
83
+ var around = charsAround(cm, ranges[i].head);
84
+ if (!around || explode.indexOf(around) % 2 != 0) return CodeMirror.Pass;
85
+ }
86
+ cm.operation(function() {
87
+ var linesep = cm.lineSeparator() || "\n";
88
+ cm.replaceSelection(linesep + linesep, null);
89
+ cm.execCommand("goCharLeft");
90
+ ranges = cm.listSelections();
91
+ for (var i = 0; i < ranges.length; i++) {
92
+ var line = ranges[i].head.line;
93
+ cm.indentLine(line, null, true);
94
+ cm.indentLine(line + 1, null, true);
95
+ }
96
+ });
97
+ }
98
+
99
+ function contractSelection(sel) {
100
+ var inverted = CodeMirror.cmpPos(sel.anchor, sel.head) > 0;
101
+ return {anchor: new Pos(sel.anchor.line, sel.anchor.ch + (inverted ? -1 : 1)),
102
+ head: new Pos(sel.head.line, sel.head.ch + (inverted ? 1 : -1))};
103
+ }
104
+
105
+ function handleChar(cm, ch) {
106
+ var conf = getConfig(cm);
107
+ if (!conf || cm.getOption("disableInput")) return CodeMirror.Pass;
108
+
109
+ var pairs = getOption(conf, "pairs");
110
+ var pos = pairs.indexOf(ch);
111
+ if (pos == -1) return CodeMirror.Pass;
112
+ var triples = getOption(conf, "triples");
113
+
114
+ var identical = pairs.charAt(pos + 1) == ch;
115
+ var ranges = cm.listSelections();
116
+ var opening = pos % 2 == 0;
117
+
118
+ var type;
119
+ for (var i = 0; i < ranges.length; i++) {
120
+ var range = ranges[i], cur = range.head, curType;
121
+ var next = cm.getRange(cur, Pos(cur.line, cur.ch + 1));
122
+ if (opening && !range.empty()) {
123
+ curType = "surround";
124
+ } else if ((identical || !opening) && next == ch) {
125
+ if (identical && stringStartsAfter(cm, cur))
126
+ curType = "both";
127
+ else if (triples.indexOf(ch) >= 0 && cm.getRange(cur, Pos(cur.line, cur.ch + 3)) == ch + ch + ch)
128
+ curType = "skipThree";
129
+ else
130
+ curType = "skip";
131
+ } else if (identical && cur.ch > 1 && triples.indexOf(ch) >= 0 &&
132
+ cm.getRange(Pos(cur.line, cur.ch - 2), cur) == ch + ch) {
133
+ if (cur.ch > 2 && /\bstring/.test(cm.getTokenTypeAt(Pos(cur.line, cur.ch - 2)))) return CodeMirror.Pass;
134
+ curType = "addFour";
135
+ } else if (identical) {
136
+ var prev = cur.ch == 0 ? " " : cm.getRange(Pos(cur.line, cur.ch - 1), cur)
137
+ if (!CodeMirror.isWordChar(next) && prev != ch && !CodeMirror.isWordChar(prev)) curType = "both";
138
+ else return CodeMirror.Pass;
139
+ } else if (opening) {
140
+ curType = "both";
141
+ } else {
142
+ return CodeMirror.Pass;
143
+ }
144
+ if (!type) type = curType;
145
+ else if (type != curType) return CodeMirror.Pass;
146
+ }
147
+
148
+ var left = pos % 2 ? pairs.charAt(pos - 1) : ch;
149
+ var right = pos % 2 ? ch : pairs.charAt(pos + 1);
150
+ cm.operation(function() {
151
+ if (type == "skip") {
152
+ cm.execCommand("goCharRight");
153
+ } else if (type == "skipThree") {
154
+ for (var i = 0; i < 3; i++)
155
+ cm.execCommand("goCharRight");
156
+ } else if (type == "surround") {
157
+ var sels = cm.getSelections();
158
+ for (var i = 0; i < sels.length; i++)
159
+ sels[i] = left + sels[i] + right;
160
+ cm.replaceSelections(sels, "around");
161
+ sels = cm.listSelections().slice();
162
+ for (var i = 0; i < sels.length; i++)
163
+ sels[i] = contractSelection(sels[i]);
164
+ cm.setSelections(sels);
165
+ } else if (type == "both") {
166
+ cm.replaceSelection(left + right, null);
167
+ cm.triggerElectric(left + right);
168
+ cm.execCommand("goCharLeft");
169
+ } else if (type == "addFour") {
170
+ cm.replaceSelection(left + left + left + left, "before");
171
+ cm.execCommand("goCharRight");
172
+ }
173
+ });
174
+ }
175
+
176
+ function charsAround(cm, pos) {
177
+ var str = cm.getRange(Pos(pos.line, pos.ch - 1),
178
+ Pos(pos.line, pos.ch + 1));
179
+ return str.length == 2 ? str : null;
180
+ }
181
+
182
+ function stringStartsAfter(cm, pos) {
183
+ var token = cm.getTokenAt(Pos(pos.line, pos.ch + 1))
184
+ return /\bstring/.test(token.type) && token.start == pos.ch &&
185
+ (pos.ch == 0 || !/\bstring/.test(cm.getTokenTypeAt(pos)))
186
+ }
187
+ });
js/codemirror-5.42.0/addon/edit/matchbrackets.js ADDED
@@ -0,0 +1,145 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
+
4
+ (function(mod) {
5
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
6
+ mod(require("../../lib/codemirror"));
7
+ else if (typeof define == "function" && define.amd) // AMD
8
+ define(["../../lib/codemirror"], mod);
9
+ else // Plain browser env
10
+ mod(CodeMirror);
11
+ })(function(CodeMirror) {
12
+ var ie_lt8 = /MSIE \d/.test(navigator.userAgent) &&
13
+ (document.documentMode == null || document.documentMode < 8);
14
+
15
+ var Pos = CodeMirror.Pos;
16
+
17
+ var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"};
18
+
19
+ function findMatchingBracket(cm, where, config) {
20
+ var line = cm.getLineHandle(where.line), pos = where.ch - 1;
21
+ var afterCursor = config && config.afterCursor
22
+ if (afterCursor == null)
23
+ afterCursor = /(^| )cm-fat-cursor($| )/.test(cm.getWrapperElement().className)
24
+
25
+ // A cursor is defined as between two characters, but in in vim command mode
26
+ // (i.e. not insert mode), the cursor is visually represented as a
27
+ // highlighted box on top of the 2nd character. Otherwise, we allow matches
28
+ // from before or after the cursor.
29
+ var match = (!afterCursor && pos >= 0 && matching[line.text.charAt(pos)]) ||
30
+ matching[line.text.charAt(++pos)];
31
+ if (!match) return null;
32
+ var dir = match.charAt(1) == ">" ? 1 : -1;
33
+ if (config && config.strict && (dir > 0) != (pos == where.ch)) return null;
34
+ var style = cm.getTokenTypeAt(Pos(where.line, pos + 1));
35
+
36
+ var found = scanForBracket(cm, Pos(where.line, pos + (dir > 0 ? 1 : 0)), dir, style || null, config);
37
+ if (found == null) return null;
38
+ return {from: Pos(where.line, pos), to: found && found.pos,
39
+ match: found && found.ch == match.charAt(0), forward: dir > 0};
40
+ }
41
+
42
+ // bracketRegex is used to specify which type of bracket to scan
43
+ // should be a regexp, e.g. /[[\]]/
44
+ //
45
+ // Note: If "where" is on an open bracket, then this bracket is ignored.
46
+ //
47
+ // Returns false when no bracket was found, null when it reached
48
+ // maxScanLines and gave up
49
+ function scanForBracket(cm, where, dir, style, config) {
50
+ var maxScanLen = (config && config.maxScanLineLength) || 10000;
51
+ var maxScanLines = (config && config.maxScanLines) || 1000;
52
+
53
+ var stack = [];
54
+ var re = config && config.bracketRegex ? config.bracketRegex : /[(){}[\]]/;
55
+ var lineEnd = dir > 0 ? Math.min(where.line + maxScanLines, cm.lastLine() + 1)
56
+ : Math.max(cm.firstLine() - 1, where.line - maxScanLines);
57
+ for (var lineNo = where.line; lineNo != lineEnd; lineNo += dir) {
58
+ var line = cm.getLine(lineNo);
59
+ if (!line) continue;
60
+ var pos = dir > 0 ? 0 : line.length - 1, end = dir > 0 ? line.length : -1;
61
+ if (line.length > maxScanLen) continue;
62
+ if (lineNo == where.line) pos = where.ch - (dir < 0 ? 1 : 0);
63
+ for (; pos != end; pos += dir) {
64
+ var ch = line.charAt(pos);
65
+ if (re.test(ch) && (style === undefined || cm.getTokenTypeAt(Pos(lineNo, pos + 1)) == style)) {
66
+ var match = matching[ch];
67
+ if ((match.charAt(1) == ">") == (dir > 0)) stack.push(ch);
68
+ else if (!stack.length) return {pos: Pos(lineNo, pos), ch: ch};
69
+ else stack.pop();
70
+ }
71
+ }
72
+ }
73
+ return lineNo - dir == (dir > 0 ? cm.lastLine() : cm.firstLine()) ? false : null;
74
+ }
75
+
76
+ function matchBrackets(cm, autoclear, config) {
77
+ // Disable brace matching in long lines, since it'll cause hugely slow updates
78
+ var maxHighlightLen = cm.state.matchBrackets.maxHighlightLineLength || 1000;
79
+ var marks = [], ranges = cm.listSelections();
80
+ for (var i = 0; i < ranges.length; i++) {
81
+ var match = ranges[i].empty() && findMatchingBracket(cm, ranges[i].head, config);
82
+ if (match && cm.getLine(match.from.line).length <= maxHighlightLen) {
83
+ var style = match.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
84
+ marks.push(cm.markText(match.from, Pos(match.from.line, match.from.ch + 1), {className: style}));
85
+ if (match.to && cm.getLine(match.to.line).length <= maxHighlightLen)
86
+ marks.push(cm.markText(match.to, Pos(match.to.line, match.to.ch + 1), {className: style}));
87
+ }
88
+ }
89
+
90
+ if (marks.length) {
91
+ // Kludge to work around the IE bug from issue #1193, where text
92
+ // input stops going to the textare whever this fires.
93
+ if (ie_lt8 && cm.state.focused) cm.focus();
94
+
95
+ var clear = function() {
96
+ cm.operation(function() {
97
+ for (var i = 0; i < marks.length; i++) marks[i].clear();
98
+ });
99
+ };
100
+ if (autoclear) setTimeout(clear, 800);
101
+ else return clear;
102
+ }
103
+ }
104
+
105
+ function doMatchBrackets(cm) {
106
+ cm.operation(function() {
107
+ if (cm.state.matchBrackets.currentlyHighlighted) {
108
+ cm.state.matchBrackets.currentlyHighlighted();
109
+ cm.state.matchBrackets.currentlyHighlighted = null;
110
+ }
111
+ cm.state.matchBrackets.currentlyHighlighted = matchBrackets(cm, false, cm.state.matchBrackets);
112
+ });
113
+ }
114
+
115
+ CodeMirror.defineOption("matchBrackets", false, function(cm, val, old) {
116
+ if (old && old != CodeMirror.Init) {
117
+ cm.off("cursorActivity", doMatchBrackets);
118
+ if (cm.state.matchBrackets && cm.state.matchBrackets.currentlyHighlighted) {
119
+ cm.state.matchBrackets.currentlyHighlighted();
120
+ cm.state.matchBrackets.currentlyHighlighted = null;
121
+ }
122
+ }
123
+ if (val) {
124
+ cm.state.matchBrackets = typeof val == "object" ? val : {};
125
+ cm.on("cursorActivity", doMatchBrackets);
126
+ }
127
+ });
128
+
129
+ CodeMirror.defineExtension("matchBrackets", function() {matchBrackets(this, true);});
130
+ CodeMirror.defineExtension("findMatchingBracket", function(pos, config, oldConfig){
131
+ // Backwards-compatibility kludge
132
+ if (oldConfig || typeof config == "boolean") {
133
+ if (!oldConfig) {
134
+ config = config ? {strict: true} : null
135
+ } else {
136
+ oldConfig.strict = config
137
+ config = oldConfig
138
+ }
139
+ }
140
+ return findMatchingBracket(this, pos, config)
141
+ });
142
+ CodeMirror.defineExtension("scanForBracket", function(pos, dir, style, config){
143
+ return scanForBracket(this, pos, dir, style, config);
144
+ });
145
+ });
js/codemirror-5.42.0/addon/hint/css-hint.js ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
+
4
+ (function(mod) {
5
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
6
+ mod(require("../../lib/codemirror"), require("../../mode/css/css"));
7
+ else if (typeof define == "function" && define.amd) // AMD
8
+ define(["../../lib/codemirror", "../../mode/css/css"], mod);
9
+ else // Plain browser env
10
+ mod(CodeMirror);
11
+ })(function(CodeMirror) {
12
+ "use strict";
13
+
14
+ var pseudoClasses = {link: 1, visited: 1, active: 1, hover: 1, focus: 1,
15
+ "first-letter": 1, "first-line": 1, "first-child": 1,
16
+ before: 1, after: 1, lang: 1};
17
+
18
+ CodeMirror.registerHelper("hint", "css", function(cm) {
19
+ var cur = cm.getCursor(), token = cm.getTokenAt(cur);
20
+ var inner = CodeMirror.innerMode(cm.getMode(), token.state);
21
+ if (inner.mode.name != "css") return;
22
+
23
+ if (token.type == "keyword" && "!important".indexOf(token.string) == 0)
24
+ return {list: ["!important"], from: CodeMirror.Pos(cur.line, token.start),
25
+ to: CodeMirror.Pos(cur.line, token.end)};
26
+
27
+ var start = token.start, end = cur.ch, word = token.string.slice(0, end - start);
28
+ if (/[^\w$_-]/.test(word)) {
29
+ word = ""; start = end = cur.ch;
30
+ }
31
+
32
+ var spec = CodeMirror.resolveMode("text/css");
33
+
34
+ var result = [];
35
+ function add(keywords) {
36
+ for (var name in keywords)
37
+ if (!word || name.lastIndexOf(word, 0) == 0)
38
+ result.push(name);
39
+ }
40
+
41
+ var st = inner.state.state;
42
+ if (st == "pseudo" || token.type == "variable-3") {
43
+ add(pseudoClasses);
44
+ } else if (st == "block" || st == "maybeprop") {
45
+ add(spec.propertyKeywords);
46
+ } else if (st == "prop" || st == "parens" || st == "at" || st == "params") {
47
+ add(spec.valueKeywords);
48
+ add(spec.colorKeywords);
49
+ } else if (st == "media" || st == "media_parens") {
50
+ add(spec.mediaTypes);
51
+ add(spec.mediaFeatures);
52
+ }
53
+
54
+ if (result.length) return {
55
+ list: result,
56
+ from: CodeMirror.Pos(cur.line, start),
57
+ to: CodeMirror.Pos(cur.line, end)
58
+ };
59
+ });
60
+ });
js/codemirror-5.42.0/addon/hint/show-hint.css ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ .CodeMirror-hints {
2
+ position: absolute;
3
+ z-index: 10;
4
+ overflow: hidden;
5
+ list-style: none;
6
+
7
+ margin: 0;
8
+ padding: 2px;
9
+
10
+ -webkit-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
11
+ -moz-box-shadow: 2px 3px 5px rgba(0,0,0,.2);
12
+ box-shadow: 2px 3px 5px rgba(0,0,0,.2);
13
+ border-radius: 3px;
14
+ border: 1px solid silver;
15
+
16
+ background: white;
17
+ font-size: 90%;
18
+ font-family: monospace;
19
+
20
+ max-height: 20em;
21
+ overflow-y: auto;
22
+ }
23
+
24
+ .CodeMirror-hint {
25
+ margin: 0;
26
+ padding: 0 4px;
27
+ border-radius: 2px;
28
+ white-space: pre;
29
+ color: black;
30
+ cursor: pointer;
31
+ }
32
+
33
+ li.CodeMirror-hint-active {
34
+ background: #08f;
35
+ color: white;
36
+ }
js/codemirror-5.42.0/addon/hint/show-hint.js ADDED
@@ -0,0 +1,436 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
+
4
+ (function(mod) {
5
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
6
+ mod(require("../../lib/codemirror"));
7
+ else if (typeof define == "function" && define.amd) // AMD
8
+ define(["../../lib/codemirror"], mod);
9
+ else // Plain browser env
10
+ mod(CodeMirror);
11
+ })(function(CodeMirror) {
12
+ "use strict";
13
+
14
+ var HINT_ELEMENT_CLASS = "CodeMirror-hint";
15
+ var ACTIVE_HINT_ELEMENT_CLASS = "CodeMirror-hint-active";
16
+
17
+ // This is the old interface, kept around for now to stay
18
+ // backwards-compatible.
19
+ CodeMirror.showHint = function(cm, getHints, options) {
20
+ if (!getHints) return cm.showHint(options);
21
+ if (options && options.async) getHints.async = true;
22
+ var newOpts = {hint: getHints};
23
+ if (options) for (var prop in options) newOpts[prop] = options[prop];
24
+ return cm.showHint(newOpts);
25
+ };
26
+
27
+ CodeMirror.defineExtension("showHint", function(options) {
28
+ options = parseOptions(this, this.getCursor("start"), options);
29
+ var selections = this.listSelections()
30
+ if (selections.length > 1) return;
31
+ // By default, don't allow completion when something is selected.
32
+ // A hint function can have a `supportsSelection` property to
33
+ // indicate that it can handle selections.
34
+ if (this.somethingSelected()) {
35
+ if (!options.hint.supportsSelection) return;
36
+ // Don't try with cross-line selections
37
+ for (var i = 0; i < selections.length; i++)
38
+ if (selections[i].head.line != selections[i].anchor.line) return;
39
+ }
40
+
41
+ if (this.state.completionActive) this.state.completionActive.close();
42
+ var completion = this.state.completionActive = new Completion(this, options);
43
+ if (!completion.options.hint) return;
44
+
45
+ CodeMirror.signal(this, "startCompletion", this);
46
+ completion.update(true);
47
+ });
48
+
49
+ function Completion(cm, options) {
50
+ this.cm = cm;
51
+ this.options = options;
52
+ this.widget = null;
53
+ this.debounce = 0;
54
+ this.tick = 0;
55
+ this.startPos = this.cm.getCursor("start");
56
+ this.startLen = this.cm.getLine(this.startPos.line).length - this.cm.getSelection().length;
57
+
58
+ var self = this;
59
+ cm.on("cursorActivity", this.activityFunc = function() { self.cursorActivity(); });
60
+ }
61
+
62
+ var requestAnimationFrame = window.requestAnimationFrame || function(fn) {
63
+ return setTimeout(fn, 1000/60);
64
+ };
65
+ var cancelAnimationFrame = window.cancelAnimationFrame || clearTimeout;
66
+
67
+ Completion.prototype = {
68
+ close: function() {
69
+ if (!this.active()) return;
70
+ this.cm.state.completionActive = null;
71
+ this.tick = null;
72
+ this.cm.off("cursorActivity", this.activityFunc);
73
+
74
+ if (this.widget && this.data) CodeMirror.signal(this.data, "close");
75
+ if (this.widget) this.widget.close();
76
+ CodeMirror.signal(this.cm, "endCompletion", this.cm);
77
+ },
78
+
79
+ active: function() {
80
+ return this.cm.state.completionActive == this;
81
+ },
82
+
83
+ pick: function(data, i) {
84
+ var completion = data.list[i];
85
+ if (completion.hint) completion.hint(this.cm, data, completion);
86
+ else this.cm.replaceRange(getText(completion), completion.from || data.from,
87
+ completion.to || data.to, "complete");
88
+ CodeMirror.signal(data, "pick", completion);
89
+ this.close();
90
+ },
91
+
92
+ cursorActivity: function() {
93
+ if (this.debounce) {
94
+ cancelAnimationFrame(this.debounce);
95
+ this.debounce = 0;
96
+ }
97
+
98
+ var pos = this.cm.getCursor(), line = this.cm.getLine(pos.line);
99
+ if (pos.line != this.startPos.line || line.length - pos.ch != this.startLen - this.startPos.ch ||
100
+ pos.ch < this.startPos.ch || this.cm.somethingSelected() ||
101
+ (!pos.ch || this.options.closeCharacters.test(line.charAt(pos.ch - 1)))) {
102
+ this.close();
103
+ } else {
104
+ var self = this;
105
+ this.debounce = requestAnimationFrame(function() {self.update();});
106
+ if (this.widget) this.widget.disable();
107
+ }
108
+ },
109
+
110
+ update: function(first) {
111
+ if (this.tick == null) return
112
+ var self = this, myTick = ++this.tick
113
+ fetchHints(this.options.hint, this.cm, this.options, function(data) {
114
+ if (self.tick == myTick) self.finishUpdate(data, first)
115
+ })
116
+ },
117
+
118
+ finishUpdate: function(data, first) {
119
+ if (this.data) CodeMirror.signal(this.data, "update");
120
+
121
+ var picked = (this.widget && this.widget.picked) || (first && this.options.completeSingle);
122
+ if (this.widget) this.widget.close();
123
+
124
+ this.data = data;
125
+
126
+ if (data && data.list.length) {
127
+ if (picked && data.list.length == 1) {
128
+ this.pick(data, 0);
129
+ } else {
130
+ this.widget = new Widget(this, data);
131
+ CodeMirror.signal(data, "shown");
132
+ }
133
+ }
134
+ }
135
+ };
136
+
137
+ function parseOptions(cm, pos, options) {
138
+ var editor = cm.options.hintOptions;
139
+ var out = {};
140
+ for (var prop in defaultOptions) out[prop] = defaultOptions[prop];
141
+ if (editor) for (var prop in editor)
142
+ if (editor[prop] !== undefined) out[prop] = editor[prop];
143
+ if (options) for (var prop in options)
144
+ if (options[prop] !== undefined) out[prop] = options[prop];
145
+ if (out.hint.resolve) out.hint = out.hint.resolve(cm, pos)
146
+ return out;
147
+ }
148
+
149
+ function getText(completion) {
150
+ if (typeof completion == "string") return completion;
151
+ else return completion.text;
152
+ }
153
+
154
+ function buildKeyMap(completion, handle) {
155
+ var baseMap = {
156
+ Up: function() {handle.moveFocus(-1);},
157
+ Down: function() {handle.moveFocus(1);},
158
+ PageUp: function() {handle.moveFocus(-handle.menuSize() + 1, true);},
159
+ PageDown: function() {handle.moveFocus(handle.menuSize() - 1, true);},
160
+ Home: function() {handle.setFocus(0);},
161
+ End: function() {handle.setFocus(handle.length - 1);},
162
+ Enter: handle.pick,
163
+ Tab: handle.pick,
164
+ Esc: handle.close
165
+ };
166
+ var custom = completion.options.customKeys;
167
+ var ourMap = custom ? {} : baseMap;
168
+ function addBinding(key, val) {
169
+ var bound;
170
+ if (typeof val != "string")
171
+ bound = function(cm) { return val(cm, handle); };
172
+ // This mechanism is deprecated
173
+ else if (baseMap.hasOwnProperty(val))
174
+ bound = baseMap[val];
175
+ else
176
+ bound = val;
177
+ ourMap[key] = bound;
178
+ }
179
+ if (custom)
180
+ for (var key in custom) if (custom.hasOwnProperty(key))
181
+ addBinding(key, custom[key]);
182
+ var extra = completion.options.extraKeys;
183
+ if (extra)
184
+ for (var key in extra) if (extra.hasOwnProperty(key))
185
+ addBinding(key, extra[key]);
186
+ return ourMap;
187
+ }
188
+
189
+ function getHintElement(hintsElement, el) {
190
+ while (el && el != hintsElement) {
191
+ if (el.nodeName.toUpperCase() === "LI" && el.parentNode == hintsElement) return el;
192
+ el = el.parentNode;
193
+ }
194
+ }
195
+
196
+ function Widget(completion, data) {
197
+ this.completion = completion;
198
+ this.data = data;
199
+ this.picked = false;
200
+ var widget = this, cm = completion.cm;
201
+ var ownerDocument = cm.getInputField().ownerDocument;
202
+ var parentWindow = ownerDocument.defaultView || ownerDocument.parentWindow;
203
+
204
+ var hints = this.hints = ownerDocument.createElement("ul");
205
+ var theme = completion.cm.options.theme;
206
+ hints.className = "CodeMirror-hints " + theme;
207
+ this.selectedHint = data.selectedHint || 0;
208
+
209
+ var completions = data.list;
210
+ for (var i = 0; i < completions.length; ++i) {
211
+ var elt = hints.appendChild(ownerDocument.createElement("li")), cur = completions[i];
212
+ var className = HINT_ELEMENT_CLASS + (i != this.selectedHint ? "" : " " + ACTIVE_HINT_ELEMENT_CLASS);
213
+ if (cur.className != null) className = cur.className + " " + className;
214
+ elt.className = className;
215
+ if (cur.render) cur.render(elt, data, cur);
216
+ else elt.appendChild(ownerDocument.createTextNode(cur.displayText || getText(cur)));
217
+ elt.hintId = i;
218
+ }
219
+
220
+ var pos = cm.cursorCoords(completion.options.alignWithWord ? data.from : null);
221
+ var left = pos.left, top = pos.bottom, below = true;
222
+ hints.style.left = left + "px";
223
+ hints.style.top = top + "px";
224
+ // If we're at the edge of the screen, then we want the menu to appear on the left of the cursor.
225
+ var winW = parentWindow.innerWidth || Math.max(ownerDocument.body.offsetWidth, ownerDocument.documentElement.offsetWidth);
226
+ var winH = parentWindow.innerHeight || Math.max(ownerDocument.body.offsetHeight, ownerDocument.documentElement.offsetHeight);
227
+ (completion.options.container || ownerDocument.body).appendChild(hints);
228
+ var box = hints.getBoundingClientRect(), overlapY = box.bottom - winH;
229
+ var scrolls = hints.scrollHeight > hints.clientHeight + 1
230
+ var startScroll = cm.getScrollInfo();
231
+
232
+ if (overlapY > 0) {
233
+ var height = box.bottom - box.top, curTop = pos.top - (pos.bottom - box.top);
234
+ if (curTop - height > 0) { // Fits above cursor
235
+ hints.style.top = (top = pos.top - height) + "px";
236
+ below = false;
237
+ } else if (height > winH) {
238
+ hints.style.height = (winH - 5) + "px";
239
+ hints.style.top = (top = pos.bottom - box.top) + "px";
240
+ var cursor = cm.getCursor();
241
+ if (data.from.ch != cursor.ch) {
242
+ pos = cm.cursorCoords(cursor);
243
+ hints.style.left = (left = pos.left) + "px";
244
+ box = hints.getBoundingClientRect();
245
+ }
246
+ }
247
+ }
248
+ var overlapX = box.right - winW;
249
+ if (overlapX > 0) {
250
+ if (box.right - box.left > winW) {
251
+ hints.style.width = (winW - 5) + "px";
252
+ overlapX -= (box.right - box.left) - winW;
253
+ }
254
+ hints.style.left = (left = pos.left - overlapX) + "px";
255
+ }
256
+ if (scrolls) for (var node = hints.firstChild; node; node = node.nextSibling)
257
+ node.style.paddingRight = cm.display.nativeBarWidth + "px"
258
+
259
+ cm.addKeyMap(this.keyMap = buildKeyMap(completion, {
260
+ moveFocus: function(n, avoidWrap) { widget.changeActive(widget.selectedHint + n, avoidWrap); },
261
+ setFocus: function(n) { widget.changeActive(n); },
262
+ menuSize: function() { return widget.screenAmount(); },
263
+ length: completions.length,
264
+ close: function() { completion.close(); },
265
+ pick: function() { widget.pick(); },
266
+ data: data
267
+ }));
268
+
269
+ if (completion.options.closeOnUnfocus) {
270
+ var closingOnBlur;
271
+ cm.on("blur", this.onBlur = function() { closingOnBlur = setTimeout(function() { completion.close(); }, 100); });
272
+ cm.on("focus", this.onFocus = function() { clearTimeout(closingOnBlur); });
273
+ }
274
+
275
+ cm.on("scroll", this.onScroll = function() {
276
+ var curScroll = cm.getScrollInfo(), editor = cm.getWrapperElement().getBoundingClientRect();
277
+ var newTop = top + startScroll.top - curScroll.top;
278
+ var point = newTop - (parentWindow.pageYOffset || (ownerDocument.documentElement || ownerDocument.body).scrollTop);
279
+ if (!below) point += hints.offsetHeight;
280
+ if (point <= editor.top || point >= editor.bottom) return completion.close();
281
+ hints.style.top = newTop + "px";
282
+ hints.style.left = (left + startScroll.left - curScroll.left) + "px";
283
+ });
284
+
285
+ CodeMirror.on(hints, "dblclick", function(e) {
286
+ var t = getHintElement(hints, e.target || e.srcElement);
287
+ if (t && t.hintId != null) {widget.changeActive(t.hintId); widget.pick();}
288
+ });
289
+
290
+ CodeMirror.on(hints, "click", function(e) {
291
+ var t = getHintElement(hints, e.target || e.srcElement);
292
+ if (t && t.hintId != null) {
293
+ widget.changeActive(t.hintId);
294
+ if (completion.options.completeOnSingleClick) widget.pick();
295
+ }
296
+ });
297
+
298
+ CodeMirror.on(hints, "mousedown", function() {
299
+ setTimeout(function(){cm.focus();}, 20);
300
+ });
301
+
302
+ CodeMirror.signal(data, "select", completions[this.selectedHint], hints.childNodes[this.selectedHint]);
303
+ return true;
304
+ }
305
+
306
+ Widget.prototype = {
307
+ close: function() {
308
+ if (this.completion.widget != this) return;
309
+ this.completion.widget = null;
310
+ this.hints.parentNode.removeChild(this.hints);
311
+ this.completion.cm.removeKeyMap(this.keyMap);
312
+
313
+ var cm = this.completion.cm;
314
+ if (this.completion.options.closeOnUnfocus) {
315
+ cm.off("blur", this.onBlur);
316
+ cm.off("focus", this.onFocus);
317
+ }
318
+ cm.off("scroll", this.onScroll);
319
+ },
320
+
321
+ disable: function() {
322
+ this.completion.cm.removeKeyMap(this.keyMap);
323
+ var widget = this;
324
+ this.keyMap = {Enter: function() { widget.picked = true; }};
325
+ this.completion.cm.addKeyMap(this.keyMap);
326
+ },
327
+
328
+ pick: function() {
329
+ this.completion.pick(this.data, this.selectedHint);
330
+ },
331
+
332
+ changeActive: function(i, avoidWrap) {
333
+ if (i >= this.data.list.length)
334
+ i = avoidWrap ? this.data.list.length - 1 : 0;
335
+ else if (i < 0)
336
+ i = avoidWrap ? 0 : this.data.list.length - 1;
337
+ if (this.selectedHint == i) return;
338
+ var node = this.hints.childNodes[this.selectedHint];
339
+ if (node) node.className = node.className.replace(" " + ACTIVE_HINT_ELEMENT_CLASS, "");
340
+ node = this.hints.childNodes[this.selectedHint = i];
341
+ node.className += " " + ACTIVE_HINT_ELEMENT_CLASS;
342
+ if (node.offsetTop < this.hints.scrollTop)
343
+ this.hints.scrollTop = node.offsetTop - 3;
344
+ else if (node.offsetTop + node.offsetHeight > this.hints.scrollTop + this.hints.clientHeight)
345
+ this.hints.scrollTop = node.offsetTop + node.offsetHeight - this.hints.clientHeight + 3;
346
+ CodeMirror.signal(this.data, "select", this.data.list[this.selectedHint], node);
347
+ },
348
+
349
+ screenAmount: function() {
350
+ return Math.floor(this.hints.clientHeight / this.hints.firstChild.offsetHeight) || 1;
351
+ }
352
+ };
353
+
354
+ function applicableHelpers(cm, helpers) {
355
+ if (!cm.somethingSelected()) return helpers
356
+ var result = []
357
+ for (var i = 0; i < helpers.length; i++)
358
+ if (helpers[i].supportsSelection) result.push(helpers[i])
359
+ return result
360
+ }
361
+
362
+ function fetchHints(hint, cm, options, callback) {
363
+ if (hint.async) {
364
+ hint(cm, callback, options)
365
+ } else {
366
+ var result = hint(cm, options)
367
+ if (result && result.then) result.then(callback)
368
+ else callback(result)
369
+ }
370
+ }
371
+
372
+ function resolveAutoHints(cm, pos) {
373
+ var helpers = cm.getHelpers(pos, "hint"), words
374
+ if (helpers.length) {
375
+ var resolved = function(cm, callback, options) {
376
+ var app = applicableHelpers(cm, helpers);
377
+ function run(i) {
378
+ if (i == app.length) return callback(null)
379
+ fetchHints(app[i], cm, options, function(result) {
380
+ if (result && result.list.length > 0) callback(result)
381
+ else run(i + 1)
382
+ })
383
+ }
384
+ run(0)
385
+ }
386
+ resolved.async = true
387
+ resolved.supportsSelection = true
388
+ return resolved
389
+ } else if (words = cm.getHelper(cm.getCursor(), "hintWords")) {
390
+ return function(cm) { return CodeMirror.hint.fromList(cm, {words: words}) }
391
+ } else if (CodeMirror.hint.anyword) {
392
+ return function(cm, options) { return CodeMirror.hint.anyword(cm, options) }
393
+ } else {
394
+ return function() {}
395
+ }
396
+ }
397
+
398
+ CodeMirror.registerHelper("hint", "auto", {
399
+ resolve: resolveAutoHints
400
+ });
401
+
402
+ CodeMirror.registerHelper("hint", "fromList", function(cm, options) {
403
+ var cur = cm.getCursor(), token = cm.getTokenAt(cur)
404
+ var term, from = CodeMirror.Pos(cur.line, token.start), to = cur
405
+ if (token.start < cur.ch && /\w/.test(token.string.charAt(cur.ch - token.start - 1))) {
406
+ term = token.string.substr(0, cur.ch - token.start)
407
+ } else {
408
+ term = ""
409
+ from = cur
410
+ }
411
+ var found = [];
412
+ for (var i = 0; i < options.words.length; i++) {
413
+ var word = options.words[i];
414
+ if (word.slice(0, term.length) == term)
415
+ found.push(word);
416
+ }
417
+
418
+ if (found.length) return {list: found, from: from, to: to};
419
+ });
420
+
421
+ CodeMirror.commands.autocomplete = CodeMirror.showHint;
422
+
423
+ var defaultOptions = {
424
+ hint: CodeMirror.hint.auto,
425
+ completeSingle: true,
426
+ alignWithWord: true,
427
+ closeCharacters: /[\s()\[\]{};:>,]/,
428
+ closeOnUnfocus: true,
429
+ completeOnSingleClick: true,
430
+ container: null,
431
+ customKeys: null,
432
+ extraKeys: null
433
+ };
434
+
435
+ CodeMirror.defineOption("hintOptions", null);
436
+ });
js/codemirror-5.42.0/addon/scroll/annotatescrollbar.js ADDED
@@ -0,0 +1,122 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
+
4
+ (function(mod) {
5
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
6
+ mod(require("../../lib/codemirror"));
7
+ else if (typeof define == "function" && define.amd) // AMD
8
+ define(["../../lib/codemirror"], mod);
9
+ else // Plain browser env
10
+ mod(CodeMirror);
11
+ })(function(CodeMirror) {
12
+ "use strict";
13
+
14
+ CodeMirror.defineExtension("annotateScrollbar", function(options) {
15
+ if (typeof options == "string") options = {className: options};
16
+ return new Annotation(this, options);
17
+ });
18
+
19
+ CodeMirror.defineOption("scrollButtonHeight", 0);
20
+
21
+ function Annotation(cm, options) {
22
+ this.cm = cm;
23
+ this.options = options;
24
+ this.buttonHeight = options.scrollButtonHeight || cm.getOption("scrollButtonHeight");
25
+ this.annotations = [];
26
+ this.doRedraw = this.doUpdate = null;
27
+ this.div = cm.getWrapperElement().appendChild(document.createElement("div"));
28
+ this.div.style.cssText = "position: absolute; right: 0; top: 0; z-index: 7; pointer-events: none";
29
+ this.computeScale();
30
+
31
+ function scheduleRedraw(delay) {
32
+ clearTimeout(self.doRedraw);
33
+ self.doRedraw = setTimeout(function() { self.redraw(); }, delay);
34
+ }
35
+
36
+ var self = this;
37
+ cm.on("refresh", this.resizeHandler = function() {
38
+ clearTimeout(self.doUpdate);
39
+ self.doUpdate = setTimeout(function() {
40
+ if (self.computeScale()) scheduleRedraw(20);
41
+ }, 100);
42
+ });
43
+ cm.on("markerAdded", this.resizeHandler);
44
+ cm.on("markerCleared", this.resizeHandler);
45
+ if (options.listenForChanges !== false)
46
+ cm.on("change", this.changeHandler = function() {
47
+ scheduleRedraw(250);
48
+ });
49
+ }
50
+
51
+ Annotation.prototype.computeScale = function() {
52
+ var cm = this.cm;
53
+ var hScale = (cm.getWrapperElement().clientHeight - cm.display.barHeight - this.buttonHeight * 2) /
54
+ cm.getScrollerElement().scrollHeight
55
+ if (hScale != this.hScale) {
56
+ this.hScale = hScale;
57
+ return true;
58
+ }
59
+ };
60
+
61
+ Annotation.prototype.update = function(annotations) {
62
+ this.annotations = annotations;
63
+ this.redraw();
64
+ };
65
+
66
+ Annotation.prototype.redraw = function(compute) {
67
+ if (compute !== false) this.computeScale();
68
+ var cm = this.cm, hScale = this.hScale;
69
+
70
+ var frag = document.createDocumentFragment(), anns = this.annotations;
71
+
72
+ var wrapping = cm.getOption("lineWrapping");
73
+ var singleLineH = wrapping && cm.defaultTextHeight() * 1.5;
74
+ var curLine = null, curLineObj = null;
75
+ function getY(pos, top) {
76
+ if (curLine != pos.line) {
77
+ curLine = pos.line;
78
+ curLineObj = cm.getLineHandle(curLine);
79
+ }
80
+ if ((curLineObj.widgets && curLineObj.widgets.length) ||
81
+ (wrapping && curLineObj.height > singleLineH))
82
+ return cm.charCoords(pos, "local")[top ? "top" : "bottom"];
83
+ var topY = cm.heightAtLine(curLineObj, "local");
84
+ return topY + (top ? 0 : curLineObj.height);
85
+ }
86
+
87
+ var lastLine = cm.lastLine()
88
+ if (cm.display.barWidth) for (var i = 0, nextTop; i < anns.length; i++) {
89
+ var ann = anns[i];
90
+ if (ann.to.line > lastLine) continue;
91
+ var top = nextTop || getY(ann.from, true) * hScale;
92
+ var bottom = getY(ann.to, false) * hScale;
93
+ while (i < anns.length - 1) {
94
+ if (anns[i + 1].to.line > lastLine) break;
95
+ nextTop = getY(anns[i + 1].from, true) * hScale;
96
+ if (nextTop > bottom + .9) break;
97
+ ann = anns[++i];
98
+ bottom = getY(ann.to, false) * hScale;
99
+ }
100
+ if (bottom == top) continue;
101
+ var height = Math.max(bottom - top, 3);
102
+
103
+ var elt = frag.appendChild(document.createElement("div"));
104
+ elt.style.cssText = "position: absolute; right: 0px; width: " + Math.max(cm.display.barWidth - 1, 2) + "px; top: "
105
+ + (top + this.buttonHeight) + "px; height: " + height + "px";
106
+ elt.className = this.options.className;
107
+ if (ann.id) {
108
+ elt.setAttribute("annotation-id", ann.id);
109
+ }
110
+ }
111
+ this.div.textContent = "";
112
+ this.div.appendChild(frag);
113
+ };
114
+
115
+ Annotation.prototype.clear = function() {
116
+ this.cm.off("refresh", this.resizeHandler);
117
+ this.cm.off("markerAdded", this.resizeHandler);
118
+ this.cm.off("markerCleared", this.resizeHandler);
119
+ if (this.changeHandler) this.cm.off("change", this.changeHandler);
120
+ this.div.parentNode.removeChild(this.div);
121
+ };
122
+ });
js/codemirror-5.42.0/addon/search/match-highlighter.js ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
+
4
+ // Highlighting text that matches the selection
5
+ //
6
+ // Defines an option highlightSelectionMatches, which, when enabled,
7
+ // will style strings that match the selection throughout the
8
+ // document.
9
+ //
10
+ // The option can be set to true to simply enable it, or to a
11
+ // {minChars, style, wordsOnly, showToken, delay} object to explicitly
12
+ // configure it. minChars is the minimum amount of characters that should be
13
+ // selected for the behavior to occur, and style is the token style to
14
+ // apply to the matches. This will be prefixed by "cm-" to create an
15
+ // actual CSS class name. If wordsOnly is enabled, the matches will be
16
+ // highlighted only if the selected text is a word. showToken, when enabled,
17
+ // will cause the current token to be highlighted when nothing is selected.
18
+ // delay is used to specify how much time to wait, in milliseconds, before
19
+ // highlighting the matches. If annotateScrollbar is enabled, the occurences
20
+ // will be highlighted on the scrollbar via the matchesonscrollbar addon.
21
+
22
+ (function(mod) {
23
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
24
+ mod(require("../../lib/codemirror"), require("./matchesonscrollbar"));
25
+ else if (typeof define == "function" && define.amd) // AMD
26
+ define(["../../lib/codemirror", "./matchesonscrollbar"], mod);
27
+ else // Plain browser env
28
+ mod(CodeMirror);
29
+ })(function(CodeMirror) {
30
+ "use strict";
31
+
32
+ var defaults = {
33
+ style: "matchhighlight",
34
+ minChars: 2,
35
+ delay: 100,
36
+ wordsOnly: false,
37
+ annotateScrollbar: false,
38
+ showToken: false,
39
+ trim: true
40
+ }
41
+
42
+ function State(options) {
43
+ this.options = {}
44
+ for (var name in defaults)
45
+ this.options[name] = (options && options.hasOwnProperty(name) ? options : defaults)[name]
46
+ this.overlay = this.timeout = null;
47
+ this.matchesonscroll = null;
48
+ this.active = false;
49
+ }
50
+
51
+ CodeMirror.defineOption("highlightSelectionMatches", false, function(cm, val, old) {
52
+ if (old && old != CodeMirror.Init) {
53
+ removeOverlay(cm);
54
+ clearTimeout(cm.state.matchHighlighter.timeout);
55
+ cm.state.matchHighlighter = null;
56
+ cm.off("cursorActivity", cursorActivity);
57
+ cm.off("focus", onFocus)
58
+ }
59
+ if (val) {
60
+ var state = cm.state.matchHighlighter = new State(val);
61
+ if (cm.hasFocus()) {
62
+ state.active = true
63
+ highlightMatches(cm)
64
+ } else {
65
+ cm.on("focus", onFocus)
66
+ }
67
+ cm.on("cursorActivity", cursorActivity);
68
+ }
69
+ });
70
+
71
+ function cursorActivity(cm) {
72
+ var state = cm.state.matchHighlighter;
73
+ if (state.active || cm.hasFocus()) scheduleHighlight(cm, state)
74
+ }
75
+
76
+ function onFocus(cm) {
77
+ var state = cm.state.matchHighlighter
78
+ if (!state.active) {
79
+ state.active = true
80
+ scheduleHighlight(cm, state)
81
+ }
82
+ }
83
+
84
+ function scheduleHighlight(cm, state) {
85
+ clearTimeout(state.timeout);
86
+ state.timeout = setTimeout(function() {highlightMatches(cm);}, state.options.delay);
87
+ }
88
+
89
+ function addOverlay(cm, query, hasBoundary, style) {
90
+ var state = cm.state.matchHighlighter;
91
+ cm.addOverlay(state.overlay = makeOverlay(query, hasBoundary, style));
92
+ if (state.options.annotateScrollbar && cm.showMatchesOnScrollbar) {
93
+ var searchFor = hasBoundary ? new RegExp("\\b" + query.replace(/[\\\[.+*?(){|^$]/g, "\\$&") + "\\b") : query;
94
+ state.matchesonscroll = cm.showMatchesOnScrollbar(searchFor, false,
95
+ {className: "CodeMirror-selection-highlight-scrollbar"});
96
+ }
97
+ }
98
+
99
+ function removeOverlay(cm) {
100
+ var state = cm.state.matchHighlighter;
101
+ if (state.overlay) {
102
+ cm.removeOverlay(state.overlay);
103
+ state.overlay = null;
104
+ if (state.matchesonscroll) {
105
+ state.matchesonscroll.clear();
106
+ state.matchesonscroll = null;
107
+ }
108
+ }
109
+ }
110
+
111
+ function highlightMatches(cm) {
112
+ cm.operation(function() {
113
+ var state = cm.state.matchHighlighter;
114
+ removeOverlay(cm);
115
+ if (!cm.somethingSelected() && state.options.showToken) {
116
+ var re = state.options.showToken === true ? /[\w$]/ : state.options.showToken;
117
+ var cur = cm.getCursor(), line = cm.getLine(cur.line), start = cur.ch, end = start;
118
+ while (start && re.test(line.charAt(start - 1))) --start;
119
+ while (end < line.length && re.test(line.charAt(end))) ++end;
120
+ if (start < end)
121
+ addOverlay(cm, line.slice(start, end), re, state.options.style);
122
+ return;
123
+ }
124
+ var from = cm.getCursor("from"), to = cm.getCursor("to");
125
+ if (from.line != to.line) return;
126
+ if (state.options.wordsOnly && !isWord(cm, from, to)) return;
127
+ var selection = cm.getRange(from, to)
128
+ if (state.options.trim) selection = selection.replace(/^\s+|\s+$/g, "")
129
+ if (selection.length >= state.options.minChars)
130
+ addOverlay(cm, selection, false, state.options.style);
131
+ });
132
+ }
133
+
134
+ function isWord(cm, from, to) {
135
+ var str = cm.getRange(from, to);
136
+ if (str.match(/^\w+$/) !== null) {
137
+ if (from.ch > 0) {
138
+ var pos = {line: from.line, ch: from.ch - 1};
139
+ var chr = cm.getRange(pos, from);
140
+ if (chr.match(/\W/) === null) return false;
141
+ }
142
+ if (to.ch < cm.getLine(from.line).length) {
143
+ var pos = {line: to.line, ch: to.ch + 1};
144
+ var chr = cm.getRange(to, pos);
145
+ if (chr.match(/\W/) === null) return false;
146
+ }
147
+ return true;
148
+ } else return false;
149
+ }
150
+
151
+ function boundariesAround(stream, re) {
152
+ return (!stream.start || !re.test(stream.string.charAt(stream.start - 1))) &&
153
+ (stream.pos == stream.string.length || !re.test(stream.string.charAt(stream.pos)));
154
+ }
155
+
156
+ function makeOverlay(query, hasBoundary, style) {
157
+ return {token: function(stream) {
158
+ if (stream.match(query) &&
159
+ (!hasBoundary || boundariesAround(stream, hasBoundary)))
160
+ return style;
161
+ stream.next();
162
+ stream.skipTo(query.charAt(0)) || stream.skipToEnd();
163
+ }};
164
+ }
165
+ });
js/codemirror-5.42.0/addon/search/matchesonscrollbar.css ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ .CodeMirror-search-match {
2
+ background: gold;
3
+ border-top: 1px solid orange;
4
+ border-bottom: 1px solid orange;
5
+ -moz-box-sizing: border-box;
6
+ box-sizing: border-box;
7
+ opacity: .5;
8
+ }
js/codemirror-5.42.0/addon/search/matchesonscrollbar.js ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
+
4
+ (function(mod) {
5
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
6
+ mod(require("../../lib/codemirror"), require("./searchcursor"), require("../scroll/annotatescrollbar"));
7
+ else if (typeof define == "function" && define.amd) // AMD
8
+ define(["../../lib/codemirror", "./searchcursor", "../scroll/annotatescrollbar"], mod);
9
+ else // Plain browser env
10
+ mod(CodeMirror);
11
+ })(function(CodeMirror) {
12
+ "use strict";
13
+
14
+ CodeMirror.defineExtension("showMatchesOnScrollbar", function(query, caseFold, options) {
15
+ if (typeof options == "string") options = {className: options};
16
+ if (!options) options = {};
17
+ return new SearchAnnotation(this, query, caseFold, options);
18
+ });
19
+
20
+ function SearchAnnotation(cm, query, caseFold, options) {
21
+ this.cm = cm;
22
+ this.options = options;
23
+ var annotateOptions = {listenForChanges: false};
24
+ for (var prop in options) annotateOptions[prop] = options[prop];
25
+ if (!annotateOptions.className) annotateOptions.className = "CodeMirror-search-match";
26
+ this.annotation = cm.annotateScrollbar(annotateOptions);
27
+ this.query = query;
28
+ this.caseFold = caseFold;
29
+ this.gap = {from: cm.firstLine(), to: cm.lastLine() + 1};
30
+ this.matches = [];
31
+ this.update = null;
32
+
33
+ this.findMatches();
34
+ this.annotation.update(this.matches);
35
+
36
+ var self = this;
37
+ cm.on("change", this.changeHandler = function(_cm, change) { self.onChange(change); });
38
+ }
39
+
40
+ var MAX_MATCHES = 1000;
41
+
42
+ SearchAnnotation.prototype.findMatches = function() {
43
+ if (!this.gap) return;
44
+ for (var i = 0; i < this.matches.length; i++) {
45
+ var match = this.matches[i];
46
+ if (match.from.line >= this.gap.to) break;
47
+ if (match.to.line >= this.gap.from) this.matches.splice(i--, 1);
48
+ }
49
+ var cursor = this.cm.getSearchCursor(this.query, CodeMirror.Pos(this.gap.from, 0), this.caseFold);
50
+ var maxMatches = this.options && this.options.maxMatches || MAX_MATCHES;
51
+ while (cursor.findNext()) {
52
+ var match = {from: cursor.from(), to: cursor.to()};
53
+ if (match.from.line >= this.gap.to) break;
54
+ this.matches.splice(i++, 0, match);
55
+ if (this.matches.length > maxMatches) break;
56
+ }
57
+ this.gap = null;
58
+ };
59
+
60
+ function offsetLine(line, changeStart, sizeChange) {
61
+ if (line <= changeStart) return line;
62
+ return Math.max(changeStart, line + sizeChange);
63
+ }
64
+
65
+ SearchAnnotation.prototype.onChange = function(change) {
66
+ var startLine = change.from.line;
67
+ var endLine = CodeMirror.changeEnd(change).line;
68
+ var sizeChange = endLine - change.to.line;
69
+ if (this.gap) {
70
+ this.gap.from = Math.min(offsetLine(this.gap.from, startLine, sizeChange), change.from.line);
71
+ this.gap.to = Math.max(offsetLine(this.gap.to, startLine, sizeChange), change.from.line);
72
+ } else {
73
+ this.gap = {from: change.from.line, to: endLine + 1};
74
+ }
75
+
76
+ if (sizeChange) for (var i = 0; i < this.matches.length; i++) {
77
+ var match = this.matches[i];
78
+ var newFrom = offsetLine(match.from.line, startLine, sizeChange);
79
+ if (newFrom != match.from.line) match.from = CodeMirror.Pos(newFrom, match.from.ch);
80
+ var newTo = offsetLine(match.to.line, startLine, sizeChange);
81
+ if (newTo != match.to.line) match.to = CodeMirror.Pos(newTo, match.to.ch);
82
+ }
83
+ clearTimeout(this.update);
84
+ var self = this;
85
+ this.update = setTimeout(function() { self.updateAfterChange(); }, 250);
86
+ };
87
+
88
+ SearchAnnotation.prototype.updateAfterChange = function() {
89
+ this.findMatches();
90
+ this.annotation.update(this.matches);
91
+ };
92
+
93
+ SearchAnnotation.prototype.clear = function() {
94
+ this.cm.off("change", this.changeHandler);
95
+ this.annotation.clear();
96
+ };
97
+ });
js/codemirror-5.42.0/addon/search/searchcursor.js ADDED
@@ -0,0 +1,293 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
+
4
+ (function(mod) {
5
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
6
+ mod(require("../../lib/codemirror"))
7
+ else if (typeof define == "function" && define.amd) // AMD
8
+ define(["../../lib/codemirror"], mod)
9
+ else // Plain browser env
10
+ mod(CodeMirror)
11
+ })(function(CodeMirror) {
12
+ "use strict"
13
+ var Pos = CodeMirror.Pos
14
+
15
+ function regexpFlags(regexp) {
16
+ var flags = regexp.flags
17
+ return flags != null ? flags : (regexp.ignoreCase ? "i" : "")
18
+ + (regexp.global ? "g" : "")
19
+ + (regexp.multiline ? "m" : "")
20
+ }
21
+
22
+ function ensureFlags(regexp, flags) {
23
+ var current = regexpFlags(regexp), target = current
24
+ for (var i = 0; i < flags.length; i++) if (target.indexOf(flags.charAt(i)) == -1)
25
+ target += flags.charAt(i)
26
+ return current == target ? regexp : new RegExp(regexp.source, target)
27
+ }
28
+
29
+ function maybeMultiline(regexp) {
30
+ return /\\s|\\n|\n|\\W|\\D|\[\^/.test(regexp.source)
31
+ }
32
+
33
+ function searchRegexpForward(doc, regexp, start) {
34
+ regexp = ensureFlags(regexp, "g")
35
+ for (var line = start.line, ch = start.ch, last = doc.lastLine(); line <= last; line++, ch = 0) {
36
+ regexp.lastIndex = ch
37
+ var string = doc.getLine(line), match = regexp.exec(string)
38
+ if (match)
39
+ return {from: Pos(line, match.index),
40
+ to: Pos(line, match.index + match[0].length),
41
+ match: match}
42
+ }
43
+ }
44
+
45
+ function searchRegexpForwardMultiline(doc, regexp, start) {
46
+ if (!maybeMultiline(regexp)) return searchRegexpForward(doc, regexp, start)
47
+
48
+ regexp = ensureFlags(regexp, "gm")
49
+ var string, chunk = 1
50
+ for (var line = start.line, last = doc.lastLine(); line <= last;) {
51
+ // This grows the search buffer in exponentially-sized chunks
52
+ // between matches, so that nearby matches are fast and don't
53
+ // require concatenating the whole document (in case we're
54
+ // searching for something that has tons of matches), but at the
55
+ // same time, the amount of retries is limited.
56
+ for (var i = 0; i < chunk; i++) {
57
+ if (line > last) break
58
+ var curLine = doc.getLine(line++)
59
+ string = string == null ? curLine : string + "\n" + curLine
60
+ }
61
+ chunk = chunk * 2
62
+ regexp.lastIndex = start.ch
63
+ var match = regexp.exec(string)
64
+ if (match) {
65
+ var before = string.slice(0, match.index).split("\n"), inside = match[0].split("\n")
66
+ var startLine = start.line + before.length - 1, startCh = before[before.length - 1].length
67
+ return {from: Pos(startLine, startCh),
68
+ to: Pos(startLine + inside.length - 1,
69
+ inside.length == 1 ? startCh + inside[0].length : inside[inside.length - 1].length),
70
+ match: match}
71
+ }
72
+ }
73
+ }
74
+
75
+ function lastMatchIn(string, regexp) {
76
+ var cutOff = 0, match
77
+ for (;;) {
78
+ regexp.lastIndex = cutOff
79
+ var newMatch = regexp.exec(string)
80
+ if (!newMatch) return match
81
+ match = newMatch
82
+ cutOff = match.index + (match[0].length || 1)
83
+ if (cutOff == string.length) return match
84
+ }
85
+ }
86
+
87
+ function searchRegexpBackward(doc, regexp, start) {
88
+ regexp = ensureFlags(regexp, "g")
89
+ for (var line = start.line, ch = start.ch, first = doc.firstLine(); line >= first; line--, ch = -1) {
90
+ var string = doc.getLine(line)
91
+ if (ch > -1) string = string.slice(0, ch)
92
+ var match = lastMatchIn(string, regexp)
93
+ if (match)
94
+ return {from: Pos(line, match.index),
95
+ to: Pos(line, match.index + match[0].length),
96
+ match: match}
97
+ }
98
+ }
99
+
100
+ function searchRegexpBackwardMultiline(doc, regexp, start) {
101
+ regexp = ensureFlags(regexp, "gm")
102
+ var string, chunk = 1
103
+ for (var line = start.line, first = doc.firstLine(); line >= first;) {
104
+ for (var i = 0; i < chunk; i++) {
105
+ var curLine = doc.getLine(line--)
106
+ string = string == null ? curLine.slice(0, start.ch) : curLine + "\n" + string
107
+ }
108
+ chunk *= 2
109
+
110
+ var match = lastMatchIn(string, regexp)
111
+ if (match) {
112
+ var before = string.slice(0, match.index).split("\n"), inside = match[0].split("\n")
113
+ var startLine = line + before.length, startCh = before[before.length - 1].length
114
+ return {from: Pos(startLine, startCh),
115
+ to: Pos(startLine + inside.length - 1,
116
+ inside.length == 1 ? startCh + inside[0].length : inside[inside.length - 1].length),
117
+ match: match}
118
+ }
119
+ }
120
+ }
121
+
122
+ var doFold, noFold
123
+ if (String.prototype.normalize) {
124
+ doFold = function(str) { return str.normalize("NFD").toLowerCase() }
125
+ noFold = function(str) { return str.normalize("NFD") }
126
+ } else {
127
+ doFold = function(str) { return str.toLowerCase() }
128
+ noFold = function(str) { return str }
129
+ }
130
+
131
+ // Maps a position in a case-folded line back to a position in the original line
132
+ // (compensating for codepoints increasing in number during folding)
133
+ function adjustPos(orig, folded, pos, foldFunc) {
134
+ if (orig.length == folded.length) return pos
135
+ for (var min = 0, max = pos + Math.max(0, orig.length - folded.length);;) {
136
+ if (min == max) return min
137
+ var mid = (min + max) >> 1
138
+ var len = foldFunc(orig.slice(0, mid)).length
139
+ if (len == pos) return mid
140
+ else if (len > pos) max = mid
141
+ else min = mid + 1
142
+ }
143
+ }
144
+
145
+ function searchStringForward(doc, query, start, caseFold) {
146
+ // Empty string would match anything and never progress, so we
147
+ // define it to match nothing instead.
148
+ if (!query.length) return null
149
+ var fold = caseFold ? doFold : noFold
150
+ var lines = fold(query).split(/\r|\n\r?/)
151
+
152
+ search: for (var line = start.line, ch = start.ch, last = doc.lastLine() + 1 - lines.length; line <= last; line++, ch = 0) {
153
+ var orig = doc.getLine(line).slice(ch), string = fold(orig)
154
+ if (lines.length == 1) {
155
+ var found = string.indexOf(lines[0])
156
+ if (found == -1) continue search
157
+ var start = adjustPos(orig, string, found, fold) + ch
158
+ return {from: Pos(line, adjustPos(orig, string, found, fold) + ch),
159
+ to: Pos(line, adjustPos(orig, string, found + lines[0].length, fold) + ch)}
160
+ } else {
161
+ var cutFrom = string.length - lines[0].length
162
+ if (string.slice(cutFrom) != lines[0]) continue search
163
+ for (var i = 1; i < lines.length - 1; i++)
164
+ if (fold(doc.getLine(line + i)) != lines[i]) continue search
165
+ var end = doc.getLine(line + lines.length - 1), endString = fold(end), lastLine = lines[lines.length - 1]
166
+ if (endString.slice(0, lastLine.length) != lastLine) continue search
167
+ return {from: Pos(line, adjustPos(orig, string, cutFrom, fold) + ch),
168
+ to: Pos(line + lines.length - 1, adjustPos(end, endString, lastLine.length, fold))}
169
+ }
170
+ }
171
+ }
172
+
173
+ function searchStringBackward(doc, query, start, caseFold) {
174
+ if (!query.length) return null
175
+ var fold = caseFold ? doFold : noFold
176
+ var lines = fold(query).split(/\r|\n\r?/)
177
+
178
+ search: for (var line = start.line, ch = start.ch, first = doc.firstLine() - 1 + lines.length; line >= first; line--, ch = -1) {
179
+ var orig = doc.getLine(line)
180
+ if (ch > -1) orig = orig.slice(0, ch)
181
+ var string = fold(orig)
182
+ if (lines.length == 1) {
183
+ var found = string.lastIndexOf(lines[0])
184
+ if (found == -1) continue search
185
+ return {from: Pos(line, adjustPos(orig, string, found, fold)),
186
+ to: Pos(line, adjustPos(orig, string, found + lines[0].length, fold))}
187
+ } else {
188
+ var lastLine = lines[lines.length - 1]
189
+ if (string.slice(0, lastLine.length) != lastLine) continue search
190
+ for (var i = 1, start = line - lines.length + 1; i < lines.length - 1; i++)
191
+ if (fold(doc.getLine(start + i)) != lines[i]) continue search
192
+ var top = doc.getLine(line + 1 - lines.length), topString = fold(top)
193
+ if (topString.slice(topString.length - lines[0].length) != lines[0]) continue search
194
+ return {from: Pos(line + 1 - lines.length, adjustPos(top, topString, top.length - lines[0].length, fold)),
195
+ to: Pos(line, adjustPos(orig, string, lastLine.length, fold))}
196
+ }
197
+ }
198
+ }
199
+
200
+ function SearchCursor(doc, query, pos, options) {
201
+ this.atOccurrence = false
202
+ this.doc = doc
203
+ pos = pos ? doc.clipPos(pos) : Pos(0, 0)
204
+ this.pos = {from: pos, to: pos}
205
+
206
+ var caseFold
207
+ if (typeof options == "object") {
208
+ caseFold = options.caseFold
209
+ } else { // Backwards compat for when caseFold was the 4th argument
210
+ caseFold = options
211
+ options = null
212
+ }
213
+
214
+ if (typeof query == "string") {
215
+ if (caseFold == null) caseFold = false
216
+ this.matches = function(reverse, pos) {
217
+ return (reverse ? searchStringBackward : searchStringForward)(doc, query, pos, caseFold)
218
+ }
219
+ } else {
220
+ query = ensureFlags(query, "gm")
221
+ if (!options || options.multiline !== false)
222
+ this.matches = function(reverse, pos) {
223
+ return (reverse ? searchRegexpBackwardMultiline : searchRegexpForwardMultiline)(doc, query, pos)
224
+ }
225
+ else
226
+ this.matches = function(reverse, pos) {
227
+ return (reverse ? searchRegexpBackward : searchRegexpForward)(doc, query, pos)
228
+ }
229
+ }
230
+ }
231
+
232
+ SearchCursor.prototype = {
233
+ findNext: function() {return this.find(false)},
234
+ findPrevious: function() {return this.find(true)},
235
+
236
+ find: function(reverse) {
237
+ var result = this.matches(reverse, this.doc.clipPos(reverse ? this.pos.from : this.pos.to))
238
+
239
+ // Implements weird auto-growing behavior on null-matches for
240
+ // backwards-compatiblity with the vim code (unfortunately)
241
+ while (result && CodeMirror.cmpPos(result.from, result.to) == 0) {
242
+ if (reverse) {
243
+ if (result.from.ch) result.from = Pos(result.from.line, result.from.ch - 1)
244
+ else if (result.from.line == this.doc.firstLine()) result = null
245
+ else result = this.matches(reverse, this.doc.clipPos(Pos(result.from.line - 1)))
246
+ } else {
247
+ if (result.to.ch < this.doc.getLine(result.to.line).length) result.to = Pos(result.to.line, result.to.ch + 1)
248
+ else if (result.to.line == this.doc.lastLine()) result = null
249
+ else result = this.matches(reverse, Pos(result.to.line + 1, 0))
250
+ }
251
+ }
252
+
253
+ if (result) {
254
+ this.pos = result
255
+ this.atOccurrence = true
256
+ return this.pos.match || true
257
+ } else {
258
+ var end = Pos(reverse ? this.doc.firstLine() : this.doc.lastLine() + 1, 0)
259
+ this.pos = {from: end, to: end}
260
+ return this.atOccurrence = false
261
+ }
262
+ },
263
+
264
+ from: function() {if (this.atOccurrence) return this.pos.from},
265
+ to: function() {if (this.atOccurrence) return this.pos.to},
266
+
267
+ replace: function(newText, origin) {
268
+ if (!this.atOccurrence) return
269
+ var lines = CodeMirror.splitLines(newText)
270
+ this.doc.replaceRange(lines, this.pos.from, this.pos.to, origin)
271
+ this.pos.to = Pos(this.pos.from.line + lines.length - 1,
272
+ lines[lines.length - 1].length + (lines.length == 1 ? this.pos.from.ch : 0))
273
+ }
274
+ }
275
+
276
+ CodeMirror.defineExtension("getSearchCursor", function(query, pos, caseFold) {
277
+ return new SearchCursor(this.doc, query, pos, caseFold)
278
+ })
279
+ CodeMirror.defineDocExtension("getSearchCursor", function(query, pos, caseFold) {
280
+ return new SearchCursor(this, query, pos, caseFold)
281
+ })
282
+
283
+ CodeMirror.defineExtension("selectMatches", function(query, caseFold) {
284
+ var ranges = []
285
+ var cur = this.getSearchCursor(query, this.getCursor("from"), caseFold)
286
+ while (cur.findNext()) {
287
+ if (CodeMirror.cmpPos(cur.to(), this.getCursor("to")) > 0) break
288
+ ranges.push({anchor: cur.from(), head: cur.to()})
289
+ }
290
+ if (ranges.length)
291
+ this.setSelections(ranges, 0)
292
+ })
293
+ });
js/codemirror-5.42.0/addon/selection/active-line.js ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
+
4
+ (function(mod) {
5
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
6
+ mod(require("../../lib/codemirror"));
7
+ else if (typeof define == "function" && define.amd) // AMD
8
+ define(["../../lib/codemirror"], mod);
9
+ else // Plain browser env
10
+ mod(CodeMirror);
11
+ })(function(CodeMirror) {
12
+ "use strict";
13
+ var WRAP_CLASS = "CodeMirror-activeline";
14
+ var BACK_CLASS = "CodeMirror-activeline-background";
15
+ var GUTT_CLASS = "CodeMirror-activeline-gutter";
16
+
17
+ CodeMirror.defineOption("styleActiveLine", false, function(cm, val, old) {
18
+ var prev = old == CodeMirror.Init ? false : old;
19
+ if (val == prev) return
20
+ if (prev) {
21
+ cm.off("beforeSelectionChange", selectionChange);
22
+ clearActiveLines(cm);
23
+ delete cm.state.activeLines;
24
+ }
25
+ if (val) {
26
+ cm.state.activeLines = [];
27
+ updateActiveLines(cm, cm.listSelections());
28
+ cm.on("beforeSelectionChange", selectionChange);
29
+ }
30
+ });
31
+
32
+ function clearActiveLines(cm) {
33
+ for (var i = 0; i < cm.state.activeLines.length; i++) {
34
+ cm.removeLineClass(cm.state.activeLines[i], "wrap", WRAP_CLASS);
35
+ cm.removeLineClass(cm.state.activeLines[i], "background", BACK_CLASS);
36
+ cm.removeLineClass(cm.state.activeLines[i], "gutter", GUTT_CLASS);
37
+ }
38
+ }
39
+
40
+ function sameArray(a, b) {
41
+ if (a.length != b.length) return false;
42
+ for (var i = 0; i < a.length; i++)
43
+ if (a[i] != b[i]) return false;
44
+ return true;
45
+ }
46
+
47
+ function updateActiveLines(cm, ranges) {
48
+ var active = [];
49
+ for (var i = 0; i < ranges.length; i++) {
50
+ var range = ranges[i];
51
+ var option = cm.getOption("styleActiveLine");
52
+ if (typeof option == "object" && option.nonEmpty ? range.anchor.line != range.head.line : !range.empty())
53
+ continue
54
+ var line = cm.getLineHandleVisualStart(range.head.line);
55
+ if (active[active.length - 1] != line) active.push(line);
56
+ }
57
+ if (sameArray(cm.state.activeLines, active)) return;
58
+ cm.operation(function() {
59
+ clearActiveLines(cm);
60
+ for (var i = 0; i < active.length; i++) {
61
+ cm.addLineClass(active[i], "wrap", WRAP_CLASS);
62
+ cm.addLineClass(active[i], "background", BACK_CLASS);
63
+ cm.addLineClass(active[i], "gutter", GUTT_CLASS);
64
+ }
65
+ cm.state.activeLines = active;
66
+ });
67
+ }
68
+
69
+ function selectionChange(cm, sel) {
70
+ updateActiveLines(cm, sel.ranges);
71
+ }
72
+ });
js/codemirror-5.42.0/codemirror.css ADDED
@@ -0,0 +1,346 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ direction: ltr;
9
+ }
10
+
11
+ /* PADDING */
12
+
13
+ .CodeMirror-lines {
14
+ padding: 4px 0; /* Vertical padding around content */
15
+ }
16
+ .CodeMirror pre {
17
+ padding: 0 4px; /* Horizontal padding of content */
18
+ }
19
+
20
+ .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
21
+ background-color: white; /* The little square between H and V scrollbars */
22
+ }
23
+
24
+ /* GUTTER */
25
+
26
+ .CodeMirror-gutters {
27
+ border-right: 1px solid #ddd;
28
+ background-color: #f7f7f7;
29
+ white-space: nowrap;
30
+ }
31
+ .CodeMirror-linenumbers {}
32
+ .CodeMirror-linenumber {
33
+ padding: 0 3px 0 5px;
34
+ min-width: 20px;
35
+ text-align: right;
36
+ color: #999;
37
+ white-space: nowrap;
38
+ }
39
+
40
+ .CodeMirror-guttermarker { color: black; }
41
+ .CodeMirror-guttermarker-subtle { color: #999; }
42
+
43
+ /* CURSOR */
44
+
45
+ .CodeMirror-cursor {
46
+ border-left: 1px solid black;
47
+ border-right: none;
48
+ width: 0;
49
+ }
50
+ /* Shown when moving in bi-directional text */
51
+ .CodeMirror div.CodeMirror-secondarycursor {
52
+ border-left: 1px solid silver;
53
+ }
54
+ .cm-fat-cursor .CodeMirror-cursor {
55
+ width: auto;
56
+ border: 0 !important;
57
+ background: #7e7;
58
+ }
59
+ .cm-fat-cursor div.CodeMirror-cursors {
60
+ z-index: 1;
61
+ }
62
+ .cm-fat-cursor-mark {
63
+ background-color: rgba(20, 255, 20, 0.5);
64
+ -webkit-animation: blink 1.06s steps(1) infinite;
65
+ -moz-animation: blink 1.06s steps(1) infinite;
66
+ animation: blink 1.06s steps(1) infinite;
67
+ }
68
+ .cm-animate-fat-cursor {
69
+ width: auto;
70
+ border: 0;
71
+ -webkit-animation: blink 1.06s steps(1) infinite;
72
+ -moz-animation: blink 1.06s steps(1) infinite;
73
+ animation: blink 1.06s steps(1) infinite;
74
+ background-color: #7e7;
75
+ }
76
+ @-moz-keyframes blink {
77
+ 0% {}
78
+ 50% { background-color: transparent; }
79
+ 100% {}
80
+ }
81
+ @-webkit-keyframes blink {
82
+ 0% {}
83
+ 50% { background-color: transparent; }
84
+ 100% {}
85
+ }
86
+ @keyframes blink {
87
+ 0% {}
88
+ 50% { background-color: transparent; }
89
+ 100% {}
90
+ }
91
+
92
+ /* Can style cursor different in overwrite (non-insert) mode */
93
+ .CodeMirror-overwrite .CodeMirror-cursor {}
94
+
95
+ .cm-tab { display: inline-block; text-decoration: inherit; }
96
+
97
+ .CodeMirror-rulers {
98
+ position: absolute;
99
+ left: 0; right: 0; top: -50px; bottom: -20px;
100
+ overflow: hidden;
101
+ }
102
+ .CodeMirror-ruler {
103
+ border-left: 1px solid #ccc;
104
+ top: 0; bottom: 0;
105
+ position: absolute;
106
+ }
107
+
108
+ /* DEFAULT THEME */
109
+
110
+ .cm-s-default .cm-header {color: blue;}
111
+ .cm-s-default .cm-quote {color: #090;}
112
+ .cm-negative {color: #d44;}
113
+ .cm-positive {color: #292;}
114
+ .cm-header, .cm-strong {font-weight: bold;}
115
+ .cm-em {font-style: italic;}
116
+ .cm-link {text-decoration: underline;}
117
+ .cm-strikethrough {text-decoration: line-through;}
118
+
119
+ .cm-s-default .cm-keyword {color: #708;}
120
+ .cm-s-default .cm-atom {color: #219;}
121
+ .cm-s-default .cm-number {color: #164;}
122
+ .cm-s-default .cm-def {color: #00f;}
123
+ .cm-s-default .cm-variable,
124
+ .cm-s-default .cm-punctuation,
125
+ .cm-s-default .cm-property,
126
+ .cm-s-default .cm-operator {}
127
+ .cm-s-default .cm-variable-2 {color: #05a;}
128
+ .cm-s-default .cm-variable-3, .cm-s-default .cm-type {color: #085;}
129
+ .cm-s-default .cm-comment {color: #a50;}
130
+ .cm-s-default .cm-string {color: #a11;}
131
+ .cm-s-default .cm-string-2 {color: #f50;}
132
+ .cm-s-default .cm-meta {color: #555;}
133
+ .cm-s-default .cm-qualifier {color: #555;}
134
+ .cm-s-default .cm-builtin {color: #30a;}
135
+ .cm-s-default .cm-bracket {color: #997;}
136
+ .cm-s-default .cm-tag {color: #170;}
137
+ .cm-s-default .cm-attribute {color: #00c;}
138
+ .cm-s-default .cm-hr {color: #999;}
139
+ .cm-s-default .cm-link {color: #00c;}
140
+
141
+ .cm-s-default .cm-error {color: #f00;}
142
+ .cm-invalidchar {color: #f00;}
143
+
144
+ .CodeMirror-composing { border-bottom: 2px solid; }
145
+
146
+ /* Default styles for common addons */
147
+
148
+ div.CodeMirror span.CodeMirror-matchingbracket {color: #0b0;}
149
+ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #a22;}
150
+ .CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
151
+ .CodeMirror-activeline-background {background: #e8f2ff;}
152
+
153
+ /* STOP */
154
+
155
+ /* The rest of this file contains styles related to the mechanics of
156
+ the editor. You probably shouldn't touch them. */
157
+
158
+ .CodeMirror {
159
+ position: relative;
160
+ overflow: hidden;
161
+ background: white;
162
+ }
163
+
164
+ .CodeMirror-scroll {
165
+ overflow: scroll !important; /* Things will break if this is overridden */
166
+ /* 30px is the magic margin used to hide the element's real scrollbars */
167
+ /* See overflow: hidden in .CodeMirror */
168
+ margin-bottom: -30px; margin-right: -30px;
169
+ padding-bottom: 30px;
170
+ height: 100%;
171
+ outline: none; /* Prevent dragging from highlighting the element */
172
+ position: relative;
173
+ }
174
+ .CodeMirror-sizer {
175
+ position: relative;
176
+ border-right: 30px solid transparent;
177
+ }
178
+
179
+ /* The fake, visible scrollbars. Used to force redraw during scrolling
180
+ before actual scrolling happens, thus preventing shaking and
181
+ flickering artifacts. */
182
+ .CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
183
+ position: absolute;
184
+ z-index: 6;
185
+ display: none;
186
+ }
187
+ .CodeMirror-vscrollbar {
188
+ right: 0; top: 0;
189
+ overflow-x: hidden;
190
+ overflow-y: scroll;
191
+ }
192
+ .CodeMirror-hscrollbar {
193
+ bottom: 0; left: 0;
194
+ overflow-y: hidden;
195
+ overflow-x: scroll;
196
+ }
197
+ .CodeMirror-scrollbar-filler {
198
+ right: 0; bottom: 0;
199
+ }
200
+ .CodeMirror-gutter-filler {
201
+ left: 0; bottom: 0;
202
+ }
203
+
204
+ .CodeMirror-gutters {
205
+ position: absolute; left: 0; top: 0;
206
+ min-height: 100%;
207
+ z-index: 3;
208
+ }
209
+ .CodeMirror-gutter {
210
+ white-space: normal;
211
+ height: 100%;
212
+ display: inline-block;
213
+ vertical-align: top;
214
+ margin-bottom: -30px;
215
+ }
216
+ .CodeMirror-gutter-wrapper {
217
+ position: absolute;
218
+ z-index: 4;
219
+ background: none !important;
220
+ border: none !important;
221
+ }
222
+ .CodeMirror-gutter-background {
223
+ position: absolute;
224
+ top: 0; bottom: 0;
225
+ z-index: 4;
226
+ }
227
+ .CodeMirror-gutter-elt {
228
+ position: absolute;
229
+ cursor: default;
230
+ z-index: 4;
231
+ }
232
+ .CodeMirror-gutter-wrapper ::selection { background-color: transparent }
233
+ .CodeMirror-gutter-wrapper ::-moz-selection { background-color: transparent }
234
+
235
+ .CodeMirror-lines {
236
+ cursor: text;
237
+ min-height: 1px; /* prevents collapsing before first draw */
238
+ }
239
+ .CodeMirror pre {
240
+ /* Reset some styles that the rest of the page might have set */
241
+ -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
242
+ border-width: 0;
243
+ background: transparent;
244
+ font-family: inherit;
245
+ font-size: inherit;
246
+ margin: 0;
247
+ white-space: pre;
248
+ word-wrap: normal;
249
+ line-height: inherit;
250
+ color: inherit;
251
+ z-index: 2;
252
+ position: relative;
253
+ overflow: visible;
254
+ -webkit-tap-highlight-color: transparent;
255
+ -webkit-font-variant-ligatures: contextual;
256
+ font-variant-ligatures: contextual;
257
+ }
258
+ .CodeMirror-wrap pre {
259
+ word-wrap: break-word;
260
+ white-space: pre-wrap;
261
+ word-break: normal;
262
+ }
263
+
264
+ .CodeMirror-linebackground {
265
+ position: absolute;
266
+ left: 0; right: 0; top: 0; bottom: 0;
267
+ z-index: 0;
268
+ }
269
+
270
+ .CodeMirror-linewidget {
271
+ position: relative;
272
+ z-index: 2;
273
+ padding: 0.1px; /* Force widget margins to stay inside of the container */
274
+ }
275
+
276
+ .CodeMirror-widget {}
277
+
278
+ .CodeMirror-rtl pre { direction: rtl; }
279
+
280
+ .CodeMirror-code {
281
+ outline: none;
282
+ }
283
+
284
+ /* Force content-box sizing for the elements where we expect it */
285
+ .CodeMirror-scroll,
286
+ .CodeMirror-sizer,
287
+ .CodeMirror-gutter,
288
+ .CodeMirror-gutters,
289
+ .CodeMirror-linenumber {
290
+ -moz-box-sizing: content-box;
291
+ box-sizing: content-box;
292
+ }
293
+
294
+ .CodeMirror-measure {
295
+ position: absolute;
296
+ width: 100%;
297
+ height: 0;
298
+ overflow: hidden;
299
+ visibility: hidden;
300
+ }
301
+
302
+ .CodeMirror-cursor {
303
+ position: absolute;
304
+ pointer-events: none;
305
+ }
306
+ .CodeMirror-measure pre { position: static; }
307
+
308
+ div.CodeMirror-cursors {
309
+ visibility: hidden;
310
+ position: relative;
311
+ z-index: 3;
312
+ }
313
+ div.CodeMirror-dragcursors {
314
+ visibility: visible;
315
+ }
316
+
317
+ .CodeMirror-focused div.CodeMirror-cursors {
318
+ visibility: visible;
319
+ }
320
+
321
+ .CodeMirror-selected { background: #d9d9d9; }
322
+ .CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
323
+ .CodeMirror-crosshair { cursor: crosshair; }
324
+ .CodeMirror-line::selection, .CodeMirror-line > span::selection, .CodeMirror-line > span > span::selection { background: #d7d4f0; }
325
+ .CodeMirror-line::-moz-selection, .CodeMirror-line > span::-moz-selection, .CodeMirror-line > span > span::-moz-selection { background: #d7d4f0; }
326
+
327
+ .cm-searching {
328
+ background-color: #ffa;
329
+ background-color: rgba(255, 255, 0, .4);
330
+ }
331
+
332
+ /* Used to force a border model for a node */
333
+ .cm-force-border { padding-right: .1px; }
334
+
335
+ @media print {
336
+ /* Hide the cursor when printing */
337
+ .CodeMirror div.CodeMirror-cursors {
338
+ visibility: hidden;
339
+ }
340
+ }
341
+
342
+ /* See issue #2901 */
343
+ .cm-tab-wrap-hack:after { content: ''; }
344
+
345
+ /* Help users use markselection to safely style text background */
346
+ span.CodeMirror-selectedtext { background: none; }
js/codemirror-5.42.0/codemirror.js ADDED
@@ -0,0 +1,9725 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
+
4
+ // This is CodeMirror (https://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 (global, factory) {
11
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
12
+ typeof define === 'function' && define.amd ? define(factory) :
13
+ (global.CodeMirror = factory());
14
+ }(this, (function () { 'use strict';
15
+
16
+ // Kludges for bugs and behavior differences that can't be feature
17
+ // detected are enabled based on userAgent etc sniffing.
18
+ var userAgent = navigator.userAgent;
19
+ var platform = navigator.platform;
20
+
21
+ var gecko = /gecko\/\d/i.test(userAgent);
22
+ var ie_upto10 = /MSIE \d/.test(userAgent);
23
+ var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(userAgent);
24
+ var edge = /Edge\/(\d+)/.exec(userAgent);
25
+ var ie = ie_upto10 || ie_11up || edge;
26
+ var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : +(edge || ie_11up)[1]);
27
+ var webkit = !edge && /WebKit\//.test(userAgent);
28
+ var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(userAgent);
29
+ var chrome = !edge && /Chrome\//.test(userAgent);
30
+ var presto = /Opera\//.test(userAgent);
31
+ var safari = /Apple Computer/.test(navigator.vendor);
32
+ var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(userAgent);
33
+ var phantom = /PhantomJS/.test(userAgent);
34
+
35
+ var ios = !edge && /AppleWebKit/.test(userAgent) && /Mobile\/\w+/.test(userAgent);
36
+ var android = /Android/.test(userAgent);
37
+ // This is woefully incomplete. Suggestions for alternative methods welcome.
38
+ var mobile = ios || android || /webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(userAgent);
39
+ var mac = ios || /Mac/.test(platform);
40
+ var chromeOS = /\bCrOS\b/.test(userAgent);
41
+ var windows = /win/i.test(platform);
42
+
43
+ var presto_version = presto && userAgent.match(/Version\/(\d*\.\d*)/);
44
+ if (presto_version) { presto_version = Number(presto_version[1]); }
45
+ if (presto_version && presto_version >= 15) { presto = false; webkit = true; }
46
+ // Some browsers use the wrong event properties to signal cmd/ctrl on OS X
47
+ var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11));
48
+ var captureRightClick = gecko || (ie && ie_version >= 9);
49
+
50
+ function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*") }
51
+
52
+ var rmClass = function(node, cls) {
53
+ var current = node.className;
54
+ var match = classTest(cls).exec(current);
55
+ if (match) {
56
+ var after = current.slice(match.index + match[0].length);
57
+ node.className = current.slice(0, match.index) + (after ? match[1] + after : "");
58
+ }
59
+ };
60
+
61
+ function removeChildren(e) {
62
+ for (var count = e.childNodes.length; count > 0; --count)
63
+ { e.removeChild(e.firstChild); }
64
+ return e
65
+ }
66
+
67
+ function removeChildrenAndAdd(parent, e) {
68
+ return removeChildren(parent).appendChild(e)
69
+ }
70
+
71
+ function elt(tag, content, className, style) {
72
+ var e = document.createElement(tag);
73
+ if (className) { e.className = className; }
74
+ if (style) { e.style.cssText = style; }
75
+ if (typeof content == "string") { e.appendChild(document.createTextNode(content)); }
76
+ else if (content) { for (var i = 0; i < content.length; ++i) { e.appendChild(content[i]); } }
77
+ return e
78
+ }
79
+ // wrapper for elt, which removes the elt from the accessibility tree
80
+ function eltP(tag, content, className, style) {
81
+ var e = elt(tag, content, className, style);
82
+ e.setAttribute("role", "presentation");
83
+ return e
84
+ }
85
+
86
+ var range;
87
+ if (document.createRange) { range = function(node, start, end, endNode) {
88
+ var r = document.createRange();
89
+ r.setEnd(endNode || node, end);
90
+ r.setStart(node, start);
91
+ return r
92
+ }; }
93
+ else { range = function(node, start, end) {
94
+ var r = document.body.createTextRange();
95
+ try { r.moveToElementText(node.parentNode); }
96
+ catch(e) { return r }
97
+ r.collapse(true);
98
+ r.moveEnd("character", end);
99
+ r.moveStart("character", start);
100
+ return r
101
+ }; }
102
+
103
+ function contains(parent, child) {
104
+ if (child.nodeType == 3) // Android browser always returns false when child is a textnode
105
+ { child = child.parentNode; }
106
+ if (parent.contains)
107
+ { return parent.contains(child) }
108
+ do {
109
+ if (child.nodeType == 11) { child = child.host; }
110
+ if (child == parent) { return true }
111
+ } while (child = child.parentNode)
112
+ }
113
+
114
+ function activeElt() {
115
+ // IE and Edge may throw an "Unspecified Error" when accessing document.activeElement.
116
+ // IE < 10 will throw when accessed while the page is loading or in an iframe.
117
+ // IE > 9 and Edge will throw when accessed in an iframe if document.body is unavailable.
118
+ var activeElement;
119
+ try {
120
+ activeElement = document.activeElement;
121
+ } catch(e) {
122
+ activeElement = document.body || null;
123
+ }
124
+ while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot.activeElement)
125
+ { activeElement = activeElement.shadowRoot.activeElement; }
126
+ return activeElement
127
+ }
128
+
129
+ function addClass(node, cls) {
130
+ var current = node.className;
131
+ if (!classTest(cls).test(current)) { node.className += (current ? " " : "") + cls; }
132
+ }
133
+ function joinClasses(a, b) {
134
+ var as = a.split(" ");
135
+ for (var i = 0; i < as.length; i++)
136
+ { if (as[i] && !classTest(as[i]).test(b)) { b += " " + as[i]; } }
137
+ return b
138
+ }
139
+
140
+ var selectInput = function(node) { node.select(); };
141
+ if (ios) // Mobile Safari apparently has a bug where select() is broken.
142
+ { selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length; }; }
143
+ else if (ie) // Suppress mysterious IE10 errors
144
+ { selectInput = function(node) { try { node.select(); } catch(_e) {} }; }
145
+
146
+ function bind(f) {
147
+ var args = Array.prototype.slice.call(arguments, 1);
148
+ return function(){return f.apply(null, args)}
149
+ }
150
+
151
+ function copyObj(obj, target, overwrite) {
152
+ if (!target) { target = {}; }
153
+ for (var prop in obj)
154
+ { if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))
155
+ { target[prop] = obj[prop]; } }
156
+ return target
157
+ }
158
+
159
+ // Counts the column offset in a string, taking tabs into account.
160
+ // Used mostly to find indentation.
161
+ function countColumn(string, end, tabSize, startIndex, startValue) {
162
+ if (end == null) {
163
+ end = string.search(/[^\s\u00a0]/);
164
+ if (end == -1) { end = string.length; }
165
+ }
166
+ for (var i = startIndex || 0, n = startValue || 0;;) {
167
+ var nextTab = string.indexOf("\t", i);
168
+ if (nextTab < 0 || nextTab >= end)
169
+ { return n + (end - i) }
170
+ n += nextTab - i;
171
+ n += tabSize - (n % tabSize);
172
+ i = nextTab + 1;
173
+ }
174
+ }
175
+
176
+ var Delayed = function() {this.id = null;};
177
+ Delayed.prototype.set = function (ms, f) {
178
+ clearTimeout(this.id);
179
+ this.id = setTimeout(f, ms);
180
+ };
181
+
182
+ function indexOf(array, elt) {
183
+ for (var i = 0; i < array.length; ++i)
184
+ { if (array[i] == elt) { return i } }
185
+ return -1
186
+ }
187
+
188
+ // Number of pixels added to scroller and sizer to hide scrollbar
189
+ var scrollerGap = 30;
190
+
191
+ // Returned or thrown by various protocols to signal 'I'm not
192
+ // handling this'.
193
+ var Pass = {toString: function(){return "CodeMirror.Pass"}};
194
+
195
+ // Reused option objects for setSelection & friends
196
+ var sel_dontScroll = {scroll: false}, sel_mouse = {origin: "*mouse"}, sel_move = {origin: "+move"};
197
+
198
+ // The inverse of countColumn -- find the offset that corresponds to
199
+ // a particular column.
200
+ function findColumn(string, goal, tabSize) {
201
+ for (var pos = 0, col = 0;;) {
202
+ var nextTab = string.indexOf("\t", pos);
203
+ if (nextTab == -1) { nextTab = string.length; }
204
+ var skipped = nextTab - pos;
205
+ if (nextTab == string.length || col + skipped >= goal)
206
+ { return pos + Math.min(skipped, goal - col) }
207
+ col += nextTab - pos;
208
+ col += tabSize - (col % tabSize);
209
+ pos = nextTab + 1;
210
+ if (col >= goal) { return pos }
211
+ }
212
+ }
213
+
214
+ var spaceStrs = [""];
215
+ function spaceStr(n) {
216
+ while (spaceStrs.length <= n)
217
+ { spaceStrs.push(lst(spaceStrs) + " "); }
218
+ return spaceStrs[n]
219
+ }
220
+
221
+ function lst(arr) { return arr[arr.length-1] }
222
+
223
+ function map(array, f) {
224
+ var out = [];
225
+ for (var i = 0; i < array.length; i++) { out[i] = f(array[i], i); }
226
+ return out
227
+ }
228
+
229
+ function insertSorted(array, value, score) {
230
+ var pos = 0, priority = score(value);
231
+ while (pos < array.length && score(array[pos]) <= priority) { pos++; }
232
+ array.splice(pos, 0, value);
233
+ }
234
+
235
+ function nothing() {}
236
+
237
+ function createObj(base, props) {
238
+ var inst;
239
+ if (Object.create) {
240
+ inst = Object.create(base);
241
+ } else {
242
+ nothing.prototype = base;
243
+ inst = new nothing();
244
+ }
245
+ if (props) { copyObj(props, inst); }
246
+ return inst
247
+ }
248
+
249
+ var nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
250
+ function isWordCharBasic(ch) {
251
+ return /\w/.test(ch) || ch > "\x80" &&
252
+ (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch))
253
+ }
254
+ function isWordChar(ch, helper) {
255
+ if (!helper) { return isWordCharBasic(ch) }
256
+ if (helper.source.indexOf("\\w") > -1 && isWordCharBasic(ch)) { return true }
257
+ return helper.test(ch)
258
+ }
259
+
260
+ function isEmpty(obj) {
261
+ for (var n in obj) { if (obj.hasOwnProperty(n) && obj[n]) { return false } }
262
+ return true
263
+ }
264
+
265
+ // Extending unicode characters. A series of a non-extending char +
266
+ // any number of extending chars is treated as a single unit as far
267
+ // as editing and measuring is concerned. This is not fully correct,
268
+ // since some scripts/fonts/browsers also treat other configurations
269
+ // of code points as a group.
270
+ 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]/;
271
+ function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch) }
272
+
273
+ // Returns a number from the range [`0`; `str.length`] unless `pos` is outside that range.
274
+ function skipExtendingChars(str, pos, dir) {
275
+ while ((dir < 0 ? pos > 0 : pos < str.length) && isExtendingChar(str.charAt(pos))) { pos += dir; }
276
+ return pos
277
+ }
278
+
279
+ // Returns the value from the range [`from`; `to`] that satisfies
280
+ // `pred` and is closest to `from`. Assumes that at least `to`
281
+ // satisfies `pred`. Supports `from` being greater than `to`.
282
+ function findFirst(pred, from, to) {
283
+ // At any point we are certain `to` satisfies `pred`, don't know
284
+ // whether `from` does.
285
+ var dir = from > to ? -1 : 1;
286
+ for (;;) {
287
+ if (from == to) { return from }
288
+ var midF = (from + to) / 2, mid = dir < 0 ? Math.ceil(midF) : Math.floor(midF);
289
+ if (mid == from) { return pred(mid) ? from : to }
290
+ if (pred(mid)) { to = mid; }
291
+ else { from = mid + dir; }
292
+ }
293
+ }
294
+
295
+ // The display handles the DOM integration, both for input reading
296
+ // and content drawing. It holds references to DOM nodes and
297
+ // display-related state.
298
+
299
+ function Display(place, doc, input) {
300
+ var d = this;
301
+ this.input = input;
302
+
303
+ // Covers bottom-right square when both scrollbars are present.
304
+ d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
305
+ d.scrollbarFiller.setAttribute("cm-not-content", "true");
306
+ // Covers bottom of gutter when coverGutterNextToScrollbar is on
307
+ // and h scrollbar is present.
308
+ d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler");
309
+ d.gutterFiller.setAttribute("cm-not-content", "true");
310
+ // Will contain the actual code, positioned to cover the viewport.
311
+ d.lineDiv = eltP("div", null, "CodeMirror-code");
312
+ // Elements are added to these to represent selection and cursors.
313
+ d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
314
+ d.cursorDiv = elt("div", null, "CodeMirror-cursors");
315
+ // A visibility: hidden element used to find the size of things.
316
+ d.measure = elt("div", null, "CodeMirror-measure");
317
+ // When lines outside of the viewport are measured, they are drawn in this.
318
+ d.lineMeasure = elt("div", null, "CodeMirror-measure");
319
+ // Wraps everything that needs to exist inside the vertically-padded coordinate system
320
+ d.lineSpace = eltP("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
321
+ null, "position: relative; outline: none");
322
+ var lines = eltP("div", [d.lineSpace], "CodeMirror-lines");
323
+ // Moved around its parent to cover visible view.
324
+ d.mover = elt("div", [lines], null, "position: relative");
325
+ // Set to the height of the document, allowing scrolling.
326
+ d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
327
+ d.sizerWidth = null;
328
+ // Behavior of elts with overflow: auto and padding is
329
+ // inconsistent across browsers. This is used to ensure the
330
+ // scrollable area is big enough.
331
+ d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;");
332
+ // Will contain the gutters, if any.
333
+ d.gutters = elt("div", null, "CodeMirror-gutters");
334
+ d.lineGutter = null;
335
+ // Actual scrollable element.
336
+ d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll");
337
+ d.scroller.setAttribute("tabIndex", "-1");
338
+ // The element in which the editor lives.
339
+ d.wrapper = elt("div", [d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
340
+
341
+ // Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
342
+ if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; }
343
+ if (!webkit && !(gecko && mobile)) { d.scroller.draggable = true; }
344
+
345
+ if (place) {
346
+ if (place.appendChild) { place.appendChild(d.wrapper); }
347
+ else { place(d.wrapper); }
348
+ }
349
+
350
+ // Current rendered range (may be bigger than the view window).
351
+ d.viewFrom = d.viewTo = doc.first;
352
+ d.reportedViewFrom = d.reportedViewTo = doc.first;
353
+ // Information about the rendered lines.
354
+ d.view = [];
355
+ d.renderedView = null;
356
+ // Holds info about a single rendered line when it was rendered
357
+ // for measurement, while not in view.
358
+ d.externalMeasured = null;
359
+ // Empty space (in pixels) above the view
360
+ d.viewOffset = 0;
361
+ d.lastWrapHeight = d.lastWrapWidth = 0;
362
+ d.updateLineNumbers = null;
363
+
364
+ d.nativeBarWidth = d.barHeight = d.barWidth = 0;
365
+ d.scrollbarsClipped = false;
366
+
367
+ // Used to only resize the line number gutter when necessary (when
368
+ // the amount of lines crosses a boundary that makes its width change)
369
+ d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
370
+ // Set to true when a non-horizontal-scrolling line widget is
371
+ // added. As an optimization, line widget aligning is skipped when
372
+ // this is false.
373
+ d.alignWidgets = false;
374
+
375
+ d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
376
+
377
+ // Tracks the maximum line length so that the horizontal scrollbar
378
+ // can be kept static when scrolling.
379
+ d.maxLine = null;
380
+ d.maxLineLength = 0;
381
+ d.maxLineChanged = false;
382
+
383
+ // Used for measuring wheel scrolling granularity
384
+ d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null;
385
+
386
+ // True when shift is held down.
387
+ d.shift = false;
388
+
389
+ // Used to track whether anything happened since the context menu
390
+ // was opened.
391
+ d.selForContextMenu = null;
392
+
393
+ d.activeTouch = null;
394
+
395
+ input.init(d);
396
+ }
397
+
398
+ // Find the line object corresponding to the given line number.
399
+ function getLine(doc, n) {
400
+ n -= doc.first;
401
+ if (n < 0 || n >= doc.size) { throw new Error("There is no line " + (n + doc.first) + " in the document.") }
402
+ var chunk = doc;
403
+ while (!chunk.lines) {
404
+ for (var i = 0;; ++i) {
405
+ var child = chunk.children[i], sz = child.chunkSize();
406
+ if (n < sz) { chunk = child; break }
407
+ n -= sz;
408
+ }
409
+ }
410
+ return chunk.lines[n]
411
+ }
412
+
413
+ // Get the part of a document between two positions, as an array of
414
+ // strings.
415
+ function getBetween(doc, start, end) {
416
+ var out = [], n = start.line;
417
+ doc.iter(start.line, end.line + 1, function (line) {
418
+ var text = line.text;
419
+ if (n == end.line) { text = text.slice(0, end.ch); }
420
+ if (n == start.line) { text = text.slice(start.ch); }
421
+ out.push(text);
422
+ ++n;
423
+ });
424
+ return out
425
+ }
426
+ // Get the lines between from and to, as array of strings.
427
+ function getLines(doc, from, to) {
428
+ var out = [];
429
+ doc.iter(from, to, function (line) { out.push(line.text); }); // iter aborts when callback returns truthy value
430
+ return out
431
+ }
432
+
433
+ // Update the height of a line, propagating the height change
434
+ // upwards to parent nodes.
435
+ function updateLineHeight(line, height) {
436
+ var diff = height - line.height;
437
+ if (diff) { for (var n = line; n; n = n.parent) { n.height += diff; } }
438
+ }
439
+
440
+ // Given a line object, find its line number by walking up through
441
+ // its parent links.
442
+ function lineNo(line) {
443
+ if (line.parent == null) { return null }
444
+ var cur = line.parent, no = indexOf(cur.lines, line);
445
+ for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
446
+ for (var i = 0;; ++i) {
447
+ if (chunk.children[i] == cur) { break }
448
+ no += chunk.children[i].chunkSize();
449
+ }
450
+ }
451
+ return no + cur.first
452
+ }
453
+
454
+ // Find the line at the given vertical position, using the height
455
+ // information in the document tree.
456
+ function lineAtHeight(chunk, h) {
457
+ var n = chunk.first;
458
+ outer: do {
459
+ for (var i$1 = 0; i$1 < chunk.children.length; ++i$1) {
460
+ var child = chunk.children[i$1], ch = child.height;
461
+ if (h < ch) { chunk = child; continue outer }
462
+ h -= ch;
463
+ n += child.chunkSize();
464
+ }
465
+ return n
466
+ } while (!chunk.lines)
467
+ var i = 0;
468
+ for (; i < chunk.lines.length; ++i) {
469
+ var line = chunk.lines[i], lh = line.height;
470
+ if (h < lh) { break }
471
+ h -= lh;
472
+ }
473
+ return n + i
474
+ }
475
+
476
+ function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size}
477
+
478
+ function lineNumberFor(options, i) {
479
+ return String(options.lineNumberFormatter(i + options.firstLineNumber))
480
+ }
481
+
482
+ // A Pos instance represents a position within the text.
483
+ function Pos(line, ch, sticky) {
484
+ if ( sticky === void 0 ) sticky = null;
485
+
486
+ if (!(this instanceof Pos)) { return new Pos(line, ch, sticky) }
487
+ this.line = line;
488
+ this.ch = ch;
489
+ this.sticky = sticky;
490
+ }
491
+
492
+ // Compare two positions, return 0 if they are the same, a negative
493
+ // number when a is less, and a positive number otherwise.
494
+ function cmp(a, b) { return a.line - b.line || a.ch - b.ch }
495
+
496
+ function equalCursorPos(a, b) { return a.sticky == b.sticky && cmp(a, b) == 0 }
497
+
498
+ function copyPos(x) {return Pos(x.line, x.ch)}
499
+ function maxPos(a, b) { return cmp(a, b) < 0 ? b : a }
500
+ function minPos(a, b) { return cmp(a, b) < 0 ? a : b }
501
+
502
+ // Most of the external API clips given positions to make sure they
503
+ // actually exist within the document.
504
+ function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1))}
505
+ function clipPos(doc, pos) {
506
+ if (pos.line < doc.first) { return Pos(doc.first, 0) }
507
+ var last = doc.first + doc.size - 1;
508
+ if (pos.line > last) { return Pos(last, getLine(doc, last).text.length) }
509
+ return clipToLen(pos, getLine(doc, pos.line).text.length)
510
+ }
511
+ function clipToLen(pos, linelen) {
512
+ var ch = pos.ch;
513
+ if (ch == null || ch > linelen) { return Pos(pos.line, linelen) }
514
+ else if (ch < 0) { return Pos(pos.line, 0) }
515
+ else { return pos }
516
+ }
517
+ function clipPosArray(doc, array) {
518
+ var out = [];
519
+ for (var i = 0; i < array.length; i++) { out[i] = clipPos(doc, array[i]); }
520
+ return out
521
+ }
522
+
523
+ // Optimize some code when these features are not used.
524
+ var sawReadOnlySpans = false, sawCollapsedSpans = false;
525
+
526
+ function seeReadOnlySpans() {
527
+ sawReadOnlySpans = true;
528
+ }
529
+
530
+ function seeCollapsedSpans() {
531
+ sawCollapsedSpans = true;
532
+ }
533
+
534
+ // TEXTMARKER SPANS
535
+
536
+ function MarkedSpan(marker, from, to) {
537
+ this.marker = marker;
538
+ this.from = from; this.to = to;
539
+ }
540
+
541
+ // Search an array of spans for a span matching the given marker.
542
+ function getMarkedSpanFor(spans, marker) {
543
+ if (spans) { for (var i = 0; i < spans.length; ++i) {
544
+ var span = spans[i];
545
+ if (span.marker == marker) { return span }
546
+ } }
547
+ }
548
+ // Remove a span from an array, returning undefined if no spans are
549
+ // left (we don't store arrays for lines without spans).
550
+ function removeMarkedSpan(spans, span) {
551
+ var r;
552
+ for (var i = 0; i < spans.length; ++i)
553
+ { if (spans[i] != span) { (r || (r = [])).push(spans[i]); } }
554
+ return r
555
+ }
556
+ // Add a span to a line.
557
+ function addMarkedSpan(line, span) {
558
+ line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];
559
+ span.marker.attachLine(line);
560
+ }
561
+
562
+ // Used for the algorithm that adjusts markers for a change in the
563
+ // document. These functions cut an array of spans at a given
564
+ // character position, returning an array of remaining chunks (or
565
+ // undefined if nothing remains).
566
+ function markedSpansBefore(old, startCh, isInsert) {
567
+ var nw;
568
+ if (old) { for (var i = 0; i < old.length; ++i) {
569
+ var span = old[i], marker = span.marker;
570
+ var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
571
+ if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
572
+ var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh)
573
+ ;(nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to));
574
+ }
575
+ } }
576
+ return nw
577
+ }
578
+ function markedSpansAfter(old, endCh, isInsert) {
579
+ var nw;
580
+ if (old) { for (var i = 0; i < old.length; ++i) {
581
+ var span = old[i], marker = span.marker;
582
+ var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
583
+ if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
584
+ var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh)
585
+ ;(nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh,
586
+ span.to == null ? null : span.to - endCh));
587
+ }
588
+ } }
589
+ return nw
590
+ }
591
+
592
+ // Given a change object, compute the new set of marker spans that
593
+ // cover the line in which the change took place. Removes spans
594
+ // entirely within the change, reconnects spans belonging to the
595
+ // same marker that appear on both sides of the change, and cuts off
596
+ // spans partially within the change. Returns an array of span
597
+ // arrays with one element for each line in (after) the change.
598
+ function stretchSpansOverChange(doc, change) {
599
+ if (change.full) { return null }
600
+ var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;
601
+ var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;
602
+ if (!oldFirst && !oldLast) { return null }
603
+
604
+ var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0;
605
+ // Get the spans that 'stick out' on both sides
606
+ var first = markedSpansBefore(oldFirst, startCh, isInsert);
607
+ var last = markedSpansAfter(oldLast, endCh, isInsert);
608
+
609
+ // Next, merge those two ends
610
+ var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0);
611
+ if (first) {
612
+ // Fix up .to properties of first
613
+ for (var i = 0; i < first.length; ++i) {
614
+ var span = first[i];
615
+ if (span.to == null) {
616
+ var found = getMarkedSpanFor(last, span.marker);
617
+ if (!found) { span.to = startCh; }
618
+ else if (sameLine) { span.to = found.to == null ? null : found.to + offset; }
619
+ }
620
+ }
621
+ }
622
+ if (last) {
623
+ // Fix up .from in last (or move them into first in case of sameLine)
624
+ for (var i$1 = 0; i$1 < last.length; ++i$1) {
625
+ var span$1 = last[i$1];
626
+ if (span$1.to != null) { span$1.to += offset; }
627
+ if (span$1.from == null) {
628
+ var found$1 = getMarkedSpanFor(first, span$1.marker);
629
+ if (!found$1) {
630
+ span$1.from = offset;
631
+ if (sameLine) { (first || (first = [])).push(span$1); }
632
+ }
633
+ } else {
634
+ span$1.from += offset;
635
+ if (sameLine) { (first || (first = [])).push(span$1); }
636
+ }
637
+ }
638
+ }
639
+ // Make sure we didn't create any zero-length spans
640
+ if (first) { first = clearEmptySpans(first); }
641
+ if (last && last != first) { last = clearEmptySpans(last); }
642
+
643
+ var newMarkers = [first];
644
+ if (!sameLine) {
645
+ // Fill gap with whole-line-spans
646
+ var gap = change.text.length - 2, gapMarkers;
647
+ if (gap > 0 && first)
648
+ { for (var i$2 = 0; i$2 < first.length; ++i$2)
649
+ { if (first[i$2].to == null)
650
+ { (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i$2].marker, null, null)); } } }
651
+ for (var i$3 = 0; i$3 < gap; ++i$3)
652
+ { newMarkers.push(gapMarkers); }
653
+ newMarkers.push(last);
654
+ }
655
+ return newMarkers
656
+ }
657
+
658
+ // Remove spans that are empty and don't have a clearWhenEmpty
659
+ // option of false.
660
+ function clearEmptySpans(spans) {
661
+ for (var i = 0; i < spans.length; ++i) {
662
+ var span = spans[i];
663
+ if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false)
664
+ { spans.splice(i--, 1); }
665
+ }
666
+ if (!spans.length) { return null }
667
+ return spans
668
+ }
669
+
670
+ // Used to 'clip' out readOnly ranges when making a change.
671
+ function removeReadOnlyRanges(doc, from, to) {
672
+ var markers = null;
673
+ doc.iter(from.line, to.line + 1, function (line) {
674
+ if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
675
+ var mark = line.markedSpans[i].marker;
676
+ if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
677
+ { (markers || (markers = [])).push(mark); }
678
+ } }
679
+ });
680
+ if (!markers) { return null }
681
+ var parts = [{from: from, to: to}];
682
+ for (var i = 0; i < markers.length; ++i) {
683
+ var mk = markers[i], m = mk.find(0);
684
+ for (var j = 0; j < parts.length; ++j) {
685
+ var p = parts[j];
686
+ if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) { continue }
687
+ var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to);
688
+ if (dfrom < 0 || !mk.inclusiveLeft && !dfrom)
689
+ { newParts.push({from: p.from, to: m.from}); }
690
+ if (dto > 0 || !mk.inclusiveRight && !dto)
691
+ { newParts.push({from: m.to, to: p.to}); }
692
+ parts.splice.apply(parts, newParts);
693
+ j += newParts.length - 3;
694
+ }
695
+ }
696
+ return parts
697
+ }
698
+
699
+ // Connect or disconnect spans from a line.
700
+ function detachMarkedSpans(line) {
701
+ var spans = line.markedSpans;
702
+ if (!spans) { return }
703
+ for (var i = 0; i < spans.length; ++i)
704
+ { spans[i].marker.detachLine(line); }
705
+ line.markedSpans = null;
706
+ }
707
+ function attachMarkedSpans(line, spans) {
708
+ if (!spans) { return }
709
+ for (var i = 0; i < spans.length; ++i)
710
+ { spans[i].marker.attachLine(line); }
711
+ line.markedSpans = spans;
712
+ }
713
+
714
+ // Helpers used when computing which overlapping collapsed span
715
+ // counts as the larger one.
716
+ function extraLeft(marker) { return marker.inclusiveLeft ? -1 : 0 }
717
+ function extraRight(marker) { return marker.inclusiveRight ? 1 : 0 }
718
+
719
+ // Returns a number indicating which of two overlapping collapsed
720
+ // spans is larger (and thus includes the other). Falls back to
721
+ // comparing ids when the spans cover exactly the same range.
722
+ function compareCollapsedMarkers(a, b) {
723
+ var lenDiff = a.lines.length - b.lines.length;
724
+ if (lenDiff != 0) { return lenDiff }
725
+ var aPos = a.find(), bPos = b.find();
726
+ var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b);
727
+ if (fromCmp) { return -fromCmp }
728
+ var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b);
729
+ if (toCmp) { return toCmp }
730
+ return b.id - a.id
731
+ }
732
+
733
+ // Find out whether a line ends or starts in a collapsed span. If
734
+ // so, return the marker for that span.
735
+ function collapsedSpanAtSide(line, start) {
736
+ var sps = sawCollapsedSpans && line.markedSpans, found;
737
+ if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) {
738
+ sp = sps[i];
739
+ if (sp.marker.collapsed && (start ? sp.from : sp.to) == null &&
740
+ (!found || compareCollapsedMarkers(found, sp.marker) < 0))
741
+ { found = sp.marker; }
742
+ } }
743
+ return found
744
+ }
745
+ function collapsedSpanAtStart(line) { return collapsedSpanAtSide(line, true) }
746
+ function collapsedSpanAtEnd(line) { return collapsedSpanAtSide(line, false) }
747
+
748
+ function collapsedSpanAround(line, ch) {
749
+ var sps = sawCollapsedSpans && line.markedSpans, found;
750
+ if (sps) { for (var i = 0; i < sps.length; ++i) {
751
+ var sp = sps[i];
752
+ if (sp.marker.collapsed && (sp.from == null || sp.from < ch) && (sp.to == null || sp.to > ch) &&
753
+ (!found || compareCollapsedMarkers(found, sp.marker) < 0)) { found = sp.marker; }
754
+ } }
755
+ return found
756
+ }
757
+
758
+ // Test whether there exists a collapsed span that partially
759
+ // overlaps (covers the start or end, but not both) of a new span.
760
+ // Such overlap is not allowed.
761
+ function conflictingCollapsedRange(doc, lineNo$$1, from, to, marker) {
762
+ var line = getLine(doc, lineNo$$1);
763
+ var sps = sawCollapsedSpans && line.markedSpans;
764
+ if (sps) { for (var i = 0; i < sps.length; ++i) {
765
+ var sp = sps[i];
766
+ if (!sp.marker.collapsed) { continue }
767
+ var found = sp.marker.find(0);
768
+ var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker);
769
+ var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker);
770
+ if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) { continue }
771
+ if (fromCmp <= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.to, from) >= 0 : cmp(found.to, from) > 0) ||
772
+ fromCmp >= 0 && (sp.marker.inclusiveRight && marker.inclusiveLeft ? cmp(found.from, to) <= 0 : cmp(found.from, to) < 0))
773
+ { return true }
774
+ } }
775
+ }
776
+
777
+ // A visual line is a line as drawn on the screen. Folding, for
778
+ // example, can cause multiple logical lines to appear on the same
779
+ // visual line. This finds the start of the visual line that the
780
+ // given line is part of (usually that is the line itself).
781
+ function visualLine(line) {
782
+ var merged;
783
+ while (merged = collapsedSpanAtStart(line))
784
+ { line = merged.find(-1, true).line; }
785
+ return line
786
+ }
787
+
788
+ function visualLineEnd(line) {
789
+ var merged;
790
+ while (merged = collapsedSpanAtEnd(line))
791
+ { line = merged.find(1, true).line; }
792
+ return line
793
+ }
794
+
795
+ // Returns an array of logical lines that continue the visual line
796
+ // started by the argument, or undefined if there are no such lines.
797
+ function visualLineContinued(line) {
798
+ var merged, lines;
799
+ while (merged = collapsedSpanAtEnd(line)) {
800
+ line = merged.find(1, true).line
801
+ ;(lines || (lines = [])).push(line);
802
+ }
803
+ return lines
804
+ }
805
+
806
+ // Get the line number of the start of the visual line that the
807
+ // given line number is part of.
808
+ function visualLineNo(doc, lineN) {
809
+ var line = getLine(doc, lineN), vis = visualLine(line);
810
+ if (line == vis) { return lineN }
811
+ return lineNo(vis)
812
+ }
813
+
814
+ // Get the line number of the start of the next visual line after
815
+ // the given line.
816
+ function visualLineEndNo(doc, lineN) {
817
+ if (lineN > doc.lastLine()) { return lineN }
818
+ var line = getLine(doc, lineN), merged;
819
+ if (!lineIsHidden(doc, line)) { return lineN }
820
+ while (merged = collapsedSpanAtEnd(line))
821
+ { line = merged.find(1, true).line; }
822
+ return lineNo(line) + 1
823
+ }
824
+
825
+ // Compute whether a line is hidden. Lines count as hidden when they
826
+ // are part of a visual line that starts with another line, or when
827
+ // they are entirely covered by collapsed, non-widget span.
828
+ function lineIsHidden(doc, line) {
829
+ var sps = sawCollapsedSpans && line.markedSpans;
830
+ if (sps) { for (var sp = (void 0), i = 0; i < sps.length; ++i) {
831
+ sp = sps[i];
832
+ if (!sp.marker.collapsed) { continue }
833
+ if (sp.from == null) { return true }
834
+ if (sp.marker.widgetNode) { continue }
835
+ if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp))
836
+ { return true }
837
+ } }
838
+ }
839
+ function lineIsHiddenInner(doc, line, span) {
840
+ if (span.to == null) {
841
+ var end = span.marker.find(1, true);
842
+ return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker))
843
+ }
844
+ if (span.marker.inclusiveRight && span.to == line.text.length)
845
+ { return true }
846
+ for (var sp = (void 0), i = 0; i < line.markedSpans.length; ++i) {
847
+ sp = line.markedSpans[i];
848
+ if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to &&
849
+ (sp.to == null || sp.to != span.from) &&
850
+ (sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
851
+ lineIsHiddenInner(doc, line, sp)) { return true }
852
+ }
853
+ }
854
+
855
+ // Find the height above the given line.
856
+ function heightAtLine(lineObj) {
857
+ lineObj = visualLine(lineObj);
858
+
859
+ var h = 0, chunk = lineObj.parent;
860
+ for (var i = 0; i < chunk.lines.length; ++i) {
861
+ var line = chunk.lines[i];
862
+ if (line == lineObj) { break }
863
+ else { h += line.height; }
864
+ }
865
+ for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
866
+ for (var i$1 = 0; i$1 < p.children.length; ++i$1) {
867
+ var cur = p.children[i$1];
868
+ if (cur == chunk) { break }
869
+ else { h += cur.height; }
870
+ }
871
+ }
872
+ return h
873
+ }
874
+
875
+ // Compute the character length of a line, taking into account
876
+ // collapsed ranges (see markText) that might hide parts, and join
877
+ // other lines onto it.
878
+ function lineLength(line) {
879
+ if (line.height == 0) { return 0 }
880
+ var len = line.text.length, merged, cur = line;
881
+ while (merged = collapsedSpanAtStart(cur)) {
882
+ var found = merged.find(0, true);
883
+ cur = found.from.line;
884
+ len += found.from.ch - found.to.ch;
885
+ }
886
+ cur = line;
887
+ while (merged = collapsedSpanAtEnd(cur)) {
888
+ var found$1 = merged.find(0, true);
889
+ len -= cur.text.length - found$1.from.ch;
890
+ cur = found$1.to.line;
891
+ len += cur.text.length - found$1.to.ch;
892
+ }
893
+ return len
894
+ }
895
+
896
+ // Find the longest line in the document.
897
+ function findMaxLine(cm) {
898
+ var d = cm.display, doc = cm.doc;
899
+ d.maxLine = getLine(doc, doc.first);
900
+ d.maxLineLength = lineLength(d.maxLine);
901
+ d.maxLineChanged = true;
902
+ doc.iter(function (line) {
903
+ var len = lineLength(line);
904
+ if (len > d.maxLineLength) {
905
+ d.maxLineLength = len;
906
+ d.maxLine = line;
907
+ }
908
+ });
909
+ }
910
+
911
+ // BIDI HELPERS
912
+
913
+ function iterateBidiSections(order, from, to, f) {
914
+ if (!order) { return f(from, to, "ltr", 0) }
915
+ var found = false;
916
+ for (var i = 0; i < order.length; ++i) {
917
+ var part = order[i];
918
+ if (part.from < to && part.to > from || from == to && part.to == from) {
919
+ f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr", i);
920
+ found = true;
921
+ }
922
+ }
923
+ if (!found) { f(from, to, "ltr"); }
924
+ }
925
+
926
+ var bidiOther = null;
927
+ function getBidiPartAt(order, ch, sticky) {
928
+ var found;
929
+ bidiOther = null;
930
+ for (var i = 0; i < order.length; ++i) {
931
+ var cur = order[i];
932
+ if (cur.from < ch && cur.to > ch) { return i }
933
+ if (cur.to == ch) {
934
+ if (cur.from != cur.to && sticky == "before") { found = i; }
935
+ else { bidiOther = i; }
936
+ }
937
+ if (cur.from == ch) {
938
+ if (cur.from != cur.to && sticky != "before") { found = i; }
939
+ else { bidiOther = i; }
940
+ }
941
+ }
942
+ return found != null ? found : bidiOther
943
+ }
944
+
945
+ // Bidirectional ordering algorithm
946
+ // See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
947
+ // that this (partially) implements.
948
+
949
+ // One-char codes used for character types:
950
+ // L (L): Left-to-Right
951
+ // R (R): Right-to-Left
952
+ // r (AL): Right-to-Left Arabic
953
+ // 1 (EN): European Number
954
+ // + (ES): European Number Separator
955
+ // % (ET): European Number Terminator
956
+ // n (AN): Arabic Number
957
+ // , (CS): Common Number Separator
958
+ // m (NSM): Non-Spacing Mark
959
+ // b (BN): Boundary Neutral
960
+ // s (B): Paragraph Separator
961
+ // t (S): Segment Separator
962
+ // w (WS): Whitespace
963
+ // N (ON): Other Neutrals
964
+
965
+ // Returns null if characters are ordered as they appear
966
+ // (left-to-right), or an array of sections ({from, to, level}
967
+ // objects) in the order in which they occur visually.
968
+ var bidiOrdering = (function() {
969
+ // Character types for codepoints 0 to 0xff
970
+ var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN";
971
+ // Character types for codepoints 0x600 to 0x6f9
972
+ var arabicTypes = "nnnnnnNNr%%r,rNNmmmmmmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmmmnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmnNmmmmmmrrmmNmmmmrr1111111111";
973
+ function charType(code) {
974
+ if (code <= 0xf7) { return lowTypes.charAt(code) }
975
+ else if (0x590 <= code && code <= 0x5f4) { return "R" }
976
+ else if (0x600 <= code && code <= 0x6f9) { return arabicTypes.charAt(code - 0x600) }
977
+ else if (0x6ee <= code && code <= 0x8ac) { return "r" }
978
+ else if (0x2000 <= code && code <= 0x200b) { return "w" }
979
+ else if (code == 0x200c) { return "b" }
980
+ else { return "L" }
981
+ }
982
+
983
+ var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
984
+ var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/;
985
+
986
+ function BidiSpan(level, from, to) {
987
+ this.level = level;
988
+ this.from = from; this.to = to;
989
+ }
990
+
991
+ return function(str, direction) {
992
+ var outerType = direction == "ltr" ? "L" : "R";
993
+
994
+ if (str.length == 0 || direction == "ltr" && !bidiRE.test(str)) { return false }
995
+ var len = str.length, types = [];
996
+ for (var i = 0; i < len; ++i)
997
+ { types.push(charType(str.charCodeAt(i))); }
998
+
999
+ // W1. Examine each non-spacing mark (NSM) in the level run, and
1000
+ // change the type of the NSM to the type of the previous
1001
+ // character. If the NSM is at the start of the level run, it will
1002
+ // get the type of sor.
1003
+ for (var i$1 = 0, prev = outerType; i$1 < len; ++i$1) {
1004
+ var type = types[i$1];
1005
+ if (type == "m") { types[i$1] = prev; }
1006
+ else { prev = type; }
1007
+ }
1008
+
1009
+ // W2. Search backwards from each instance of a European number
1010
+ // until the first strong type (R, L, AL, or sor) is found. If an
1011
+ // AL is found, change the type of the European number to Arabic
1012
+ // number.
1013
+ // W3. Change all ALs to R.
1014
+ for (var i$2 = 0, cur = outerType; i$2 < len; ++i$2) {
1015
+ var type$1 = types[i$2];
1016
+ if (type$1 == "1" && cur == "r") { types[i$2] = "n"; }
1017
+ else if (isStrong.test(type$1)) { cur = type$1; if (type$1 == "r") { types[i$2] = "R"; } }
1018
+ }
1019
+
1020
+ // W4. A single European separator between two European numbers
1021
+ // changes to a European number. A single common separator between
1022
+ // two numbers of the same type changes to that type.
1023
+ for (var i$3 = 1, prev$1 = types[0]; i$3 < len - 1; ++i$3) {
1024
+ var type$2 = types[i$3];
1025
+ if (type$2 == "+" && prev$1 == "1" && types[i$3+1] == "1") { types[i$3] = "1"; }
1026
+ else if (type$2 == "," && prev$1 == types[i$3+1] &&
1027
+ (prev$1 == "1" || prev$1 == "n")) { types[i$3] = prev$1; }
1028
+ prev$1 = type$2;
1029
+ }
1030
+
1031
+ // W5. A sequence of European terminators adjacent to European
1032
+ // numbers changes to all European numbers.
1033
+ // W6. Otherwise, separators and terminators change to Other
1034
+ // Neutral.
1035
+ for (var i$4 = 0; i$4 < len; ++i$4) {
1036
+ var type$3 = types[i$4];
1037
+ if (type$3 == ",") { types[i$4] = "N"; }
1038
+ else if (type$3 == "%") {
1039
+ var end = (void 0);
1040
+ for (end = i$4 + 1; end < len && types[end] == "%"; ++end) {}
1041
+ var replace = (i$4 && types[i$4-1] == "!") || (end < len && types[end] == "1") ? "1" : "N";
1042
+ for (var j = i$4; j < end; ++j) { types[j] = replace; }
1043
+ i$4 = end - 1;
1044
+ }
1045
+ }
1046
+
1047
+ // W7. Search backwards from each instance of a European number
1048
+ // until the first strong type (R, L, or sor) is found. If an L is
1049
+ // found, then change the type of the European number to L.
1050
+ for (var i$5 = 0, cur$1 = outerType; i$5 < len; ++i$5) {
1051
+ var type$4 = types[i$5];
1052
+ if (cur$1 == "L" && type$4 == "1") { types[i$5] = "L"; }
1053
+ else if (isStrong.test(type$4)) { cur$1 = type$4; }
1054
+ }
1055
+
1056
+ // N1. A sequence of neutrals takes the direction of the
1057
+ // surrounding strong text if the text on both sides has the same
1058
+ // direction. European and Arabic numbers act as if they were R in
1059
+ // terms of their influence on neutrals. Start-of-level-run (sor)
1060
+ // and end-of-level-run (eor) are used at level run boundaries.
1061
+ // N2. Any remaining neutrals take the embedding direction.
1062
+ for (var i$6 = 0; i$6 < len; ++i$6) {
1063
+ if (isNeutral.test(types[i$6])) {
1064
+ var end$1 = (void 0);
1065
+ for (end$1 = i$6 + 1; end$1 < len && isNeutral.test(types[end$1]); ++end$1) {}
1066
+ var before = (i$6 ? types[i$6-1] : outerType) == "L";
1067
+ var after = (end$1 < len ? types[end$1] : outerType) == "L";
1068
+ var replace$1 = before == after ? (before ? "L" : "R") : outerType;
1069
+ for (var j$1 = i$6; j$1 < end$1; ++j$1) { types[j$1] = replace$1; }
1070
+ i$6 = end$1 - 1;
1071
+ }
1072
+ }
1073
+
1074
+ // Here we depart from the documented algorithm, in order to avoid
1075
+ // building up an actual levels array. Since there are only three
1076
+ // levels (0, 1, 2) in an implementation that doesn't take
1077
+ // explicit embedding into account, we can build up the order on
1078
+ // the fly, without following the level-based algorithm.
1079
+ var order = [], m;
1080
+ for (var i$7 = 0; i$7 < len;) {
1081
+ if (countsAsLeft.test(types[i$7])) {
1082
+ var start = i$7;
1083
+ for (++i$7; i$7 < len && countsAsLeft.test(types[i$7]); ++i$7) {}
1084
+ order.push(new BidiSpan(0, start, i$7));
1085
+ } else {
1086
+ var pos = i$7, at = order.length;
1087
+ for (++i$7; i$7 < len && types[i$7] != "L"; ++i$7) {}
1088
+ for (var j$2 = pos; j$2 < i$7;) {
1089
+ if (countsAsNum.test(types[j$2])) {
1090
+ if (pos < j$2) { order.splice(at, 0, new BidiSpan(1, pos, j$2)); }
1091
+ var nstart = j$2;
1092
+ for (++j$2; j$2 < i$7 && countsAsNum.test(types[j$2]); ++j$2) {}
1093
+ order.splice(at, 0, new BidiSpan(2, nstart, j$2));
1094
+ pos = j$2;
1095
+ } else { ++j$2; }
1096
+ }
1097
+ if (pos < i$7) { order.splice(at, 0, new BidiSpan(1, pos, i$7)); }
1098
+ }
1099
+ }
1100
+ if (direction == "ltr") {
1101
+ if (order[0].level == 1 && (m = str.match(/^\s+/))) {
1102
+ order[0].from = m[0].length;
1103
+ order.unshift(new BidiSpan(0, 0, m[0].length));
1104
+ }
1105
+ if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
1106
+ lst(order).to -= m[0].length;
1107
+ order.push(new BidiSpan(0, len - m[0].length, len));
1108
+ }
1109
+ }
1110
+
1111
+ return direction == "rtl" ? order.reverse() : order
1112
+ }
1113
+ })();
1114
+
1115
+ // Get the bidi ordering for the given line (and cache it). Returns
1116
+ // false for lines that are fully left-to-right, and an array of
1117
+ // BidiSpan objects otherwise.
1118
+ function getOrder(line, direction) {
1119
+ var order = line.order;
1120
+ if (order == null) { order = line.order = bidiOrdering(line.text, direction); }
1121
+ return order
1122
+ }
1123
+
1124
+ // EVENT HANDLING
1125
+
1126
+ // Lightweight event framework. on/off also work on DOM nodes,
1127
+ // registering native DOM handlers.
1128
+
1129
+ var noHandlers = [];
1130
+
1131
+ var on = function(emitter, type, f) {
1132
+ if (emitter.addEventListener) {
1133
+ emitter.addEventListener(type, f, false);
1134
+ } else if (emitter.attachEvent) {
1135
+ emitter.attachEvent("on" + type, f);
1136
+ } else {
1137
+ var map$$1 = emitter._handlers || (emitter._handlers = {});
1138
+ map$$1[type] = (map$$1[type] || noHandlers).concat(f);
1139
+ }
1140
+ };
1141
+
1142
+ function getHandlers(emitter, type) {
1143
+ return emitter._handlers && emitter._handlers[type] || noHandlers
1144
+ }
1145
+
1146
+ function off(emitter, type, f) {
1147
+ if (emitter.removeEventListener) {
1148
+ emitter.removeEventListener(type, f, false);
1149
+ } else if (emitter.detachEvent) {
1150
+ emitter.detachEvent("on" + type, f);
1151
+ } else {
1152
+ var map$$1 = emitter._handlers, arr = map$$1 && map$$1[type];
1153
+ if (arr) {
1154
+ var index = indexOf(arr, f);
1155
+ if (index > -1)
1156
+ { map$$1[type] = arr.slice(0, index).concat(arr.slice(index + 1)); }
1157
+ }
1158
+ }
1159
+ }
1160
+
1161
+ function signal(emitter, type /*, values...*/) {
1162
+ var handlers = getHandlers(emitter, type);
1163
+ if (!handlers.length) { return }
1164
+ var args = Array.prototype.slice.call(arguments, 2);
1165
+ for (var i = 0; i < handlers.length; ++i) { handlers[i].apply(null, args); }
1166
+ }
1167
+
1168
+ // The DOM events that CodeMirror handles can be overridden by
1169
+ // registering a (non-DOM) handler on the editor for the event name,
1170
+ // and preventDefault-ing the event in that handler.
1171
+ function signalDOMEvent(cm, e, override) {
1172
+ if (typeof e == "string")
1173
+ { e = {type: e, preventDefault: function() { this.defaultPrevented = true; }}; }
1174
+ signal(cm, override || e.type, cm, e);
1175
+ return e_defaultPrevented(e) || e.codemirrorIgnore
1176
+ }
1177
+
1178
+ function signalCursorActivity(cm) {
1179
+ var arr = cm._handlers && cm._handlers.cursorActivity;
1180
+ if (!arr) { return }
1181
+ var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = []);
1182
+ for (var i = 0; i < arr.length; ++i) { if (indexOf(set, arr[i]) == -1)
1183
+ { set.push(arr[i]); } }
1184
+ }
1185
+
1186
+ function hasHandler(emitter, type) {
1187
+ return getHandlers(emitter, type).length > 0
1188
+ }
1189
+
1190
+ // Add on and off methods to a constructor's prototype, to make
1191
+ // registering events on such objects more convenient.
1192
+ function eventMixin(ctor) {
1193
+ ctor.prototype.on = function(type, f) {on(this, type, f);};
1194
+ ctor.prototype.off = function(type, f) {off(this, type, f);};
1195
+ }
1196
+
1197
+ // Due to the fact that we still support jurassic IE versions, some
1198
+ // compatibility wrappers are needed.
1199
+
1200
+ function e_preventDefault(e) {
1201
+ if (e.preventDefault) { e.preventDefault(); }
1202
+ else { e.returnValue = false; }
1203
+ }
1204
+ function e_stopPropagation(e) {
1205
+ if (e.stopPropagation) { e.stopPropagation(); }
1206
+ else { e.cancelBubble = true; }
1207
+ }
1208
+ function e_defaultPrevented(e) {
1209
+ return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false
1210
+ }
1211
+ function e_stop(e) {e_preventDefault(e); e_stopPropagation(e);}
1212
+
1213
+ function e_target(e) {return e.target || e.srcElement}
1214
+ function e_button(e) {
1215
+ var b = e.which;
1216
+ if (b == null) {
1217
+ if (e.button & 1) { b = 1; }
1218
+ else if (e.button & 2) { b = 3; }
1219
+ else if (e.button & 4) { b = 2; }
1220
+ }
1221
+ if (mac && e.ctrlKey && b == 1) { b = 3; }
1222
+ return b
1223
+ }
1224
+
1225
+ // Detect drag-and-drop
1226
+ var dragAndDrop = function() {
1227
+ // There is *some* kind of drag-and-drop support in IE6-8, but I
1228
+ // couldn't get it to work yet.
1229
+ if (ie && ie_version < 9) { return false }
1230
+ var div = elt('div');
1231
+ return "draggable" in div || "dragDrop" in div
1232
+ }();
1233
+
1234
+ var zwspSupported;
1235
+ function zeroWidthElement(measure) {
1236
+ if (zwspSupported == null) {
1237
+ var test = elt("span", "\u200b");
1238
+ removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]));
1239
+ if (measure.firstChild.offsetHeight != 0)
1240
+ { zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8); }
1241
+ }
1242
+ var node = zwspSupported ? elt("span", "\u200b") :
1243
+ elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px");
1244
+ node.setAttribute("cm-text", "");
1245
+ return node
1246
+ }
1247
+
1248
+ // Feature-detect IE's crummy client rect reporting for bidi text
1249
+ var badBidiRects;
1250
+ function hasBadBidiRects(measure) {
1251
+ if (badBidiRects != null) { return badBidiRects }
1252
+ var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA"));
1253
+ var r0 = range(txt, 0, 1).getBoundingClientRect();
1254
+ var r1 = range(txt, 1, 2).getBoundingClientRect();
1255
+ removeChildren(measure);
1256
+ if (!r0 || r0.left == r0.right) { return false } // Safari returns null in some cases (#2780)
1257
+ return badBidiRects = (r1.right - r0.right < 3)
1258
+ }
1259
+
1260
+ // See if "".split is the broken IE version, if so, provide an
1261
+ // alternative way to split lines.
1262
+ var splitLinesAuto = "\n\nb".split(/\n/).length != 3 ? function (string) {
1263
+ var pos = 0, result = [], l = string.length;
1264
+ while (pos <= l) {
1265
+ var nl = string.indexOf("\n", pos);
1266
+ if (nl == -1) { nl = string.length; }
1267
+ var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
1268
+ var rt = line.indexOf("\r");
1269
+ if (rt != -1) {
1270
+ result.push(line.slice(0, rt));
1271
+ pos += rt + 1;
1272
+ } else {
1273
+ result.push(line);
1274
+ pos = nl + 1;
1275
+ }
1276
+ }
1277
+ return result
1278
+ } : function (string) { return string.split(/\r\n?|\n/); };
1279
+
1280
+ var hasSelection = window.getSelection ? function (te) {
1281
+ try { return te.selectionStart != te.selectionEnd }
1282
+ catch(e) { return false }
1283
+ } : function (te) {
1284
+ var range$$1;
1285
+ try {range$$1 = te.ownerDocument.selection.createRange();}
1286
+ catch(e) {}
1287
+ if (!range$$1 || range$$1.parentElement() != te) { return false }
1288
+ return range$$1.compareEndPoints("StartToEnd", range$$1) != 0
1289
+ };
1290
+
1291
+ var hasCopyEvent = (function () {
1292
+ var e = elt("div");
1293
+ if ("oncopy" in e) { return true }
1294
+ e.setAttribute("oncopy", "return;");
1295
+ return typeof e.oncopy == "function"
1296
+ })();
1297
+
1298
+ var badZoomedRects = null;
1299
+ function hasBadZoomedRects(measure) {
1300
+ if (badZoomedRects != null) { return badZoomedRects }
1301
+ var node = removeChildrenAndAdd(measure, elt("span", "x"));
1302
+ var normal = node.getBoundingClientRect();
1303
+ var fromRange = range(node, 0, 1).getBoundingClientRect();
1304
+ return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1
1305
+ }
1306
+
1307
+ // Known modes, by name and by MIME
1308
+ var modes = {}, mimeModes = {};
1309
+
1310
+ // Extra arguments are stored as the mode's dependencies, which is
1311
+ // used by (legacy) mechanisms like loadmode.js to automatically
1312
+ // load a mode. (Preferred mechanism is the require/define calls.)
1313
+ function defineMode(name, mode) {
1314
+ if (arguments.length > 2)
1315
+ { mode.dependencies = Array.prototype.slice.call(arguments, 2); }
1316
+ modes[name] = mode;
1317
+ }
1318
+
1319
+ function defineMIME(mime, spec) {
1320
+ mimeModes[mime] = spec;
1321
+ }
1322
+
1323
+ // Given a MIME type, a {name, ...options} config object, or a name
1324
+ // string, return a mode config object.
1325
+ function resolveMode(spec) {
1326
+ if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
1327
+ spec = mimeModes[spec];
1328
+ } else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
1329
+ var found = mimeModes[spec.name];
1330
+ if (typeof found == "string") { found = {name: found}; }
1331
+ spec = createObj(found, spec);
1332
+ spec.name = found.name;
1333
+ } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
1334
+ return resolveMode("application/xml")
1335
+ } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+json$/.test(spec)) {
1336
+ return resolveMode("application/json")
1337
+ }
1338
+ if (typeof spec == "string") { return {name: spec} }
1339
+ else { return spec || {name: "null"} }
1340
+ }
1341
+
1342
+ // Given a mode spec (anything that resolveMode accepts), find and
1343
+ // initialize an actual mode object.
1344
+ function getMode(options, spec) {
1345
+ spec = resolveMode(spec);
1346
+ var mfactory = modes[spec.name];
1347
+ if (!mfactory) { return getMode(options, "text/plain") }
1348
+ var modeObj = mfactory(options, spec);
1349
+ if (modeExtensions.hasOwnProperty(spec.name)) {
1350
+ var exts = modeExtensions[spec.name];
1351
+ for (var prop in exts) {
1352
+ if (!exts.hasOwnProperty(prop)) { continue }
1353
+ if (modeObj.hasOwnProperty(prop)) { modeObj["_" + prop] = modeObj[prop]; }
1354
+ modeObj[prop] = exts[prop];
1355
+ }
1356
+ }
1357
+ modeObj.name = spec.name;
1358
+ if (spec.helperType) { modeObj.helperType = spec.helperType; }
1359
+ if (spec.modeProps) { for (var prop$1 in spec.modeProps)
1360
+ { modeObj[prop$1] = spec.modeProps[prop$1]; } }
1361
+
1362
+ return modeObj
1363
+ }
1364
+
1365
+ // This can be used to attach properties to mode objects from
1366
+ // outside the actual mode definition.
1367
+ var modeExtensions = {};
1368
+ function extendMode(mode, properties) {
1369
+ var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
1370
+ copyObj(properties, exts);
1371
+ }
1372
+
1373
+ function copyState(mode, state) {
1374
+ if (state === true) { return state }
1375
+ if (mode.copyState) { return mode.copyState(state) }
1376
+ var nstate = {};
1377
+ for (var n in state) {
1378
+ var val = state[n];
1379
+ if (val instanceof Array) { val = val.concat([]); }
1380
+ nstate[n] = val;
1381
+ }
1382
+ return nstate
1383
+ }
1384
+
1385
+ // Given a mode and a state (for that mode), find the inner mode and
1386
+ // state at the position that the state refers to.
1387
+ function innerMode(mode, state) {
1388
+ var info;
1389
+ while (mode.innerMode) {
1390
+ info = mode.innerMode(state);
1391
+ if (!info || info.mode == mode) { break }
1392
+ state = info.state;
1393
+ mode = info.mode;
1394
+ }
1395
+ return info || {mode: mode, state: state}
1396
+ }
1397
+
1398
+ function startState(mode, a1, a2) {
1399
+ return mode.startState ? mode.startState(a1, a2) : true
1400
+ }
1401
+
1402
+ // STRING STREAM
1403
+
1404
+ // Fed to the mode parsers, provides helper functions to make
1405
+ // parsers more succinct.
1406
+
1407
+ var StringStream = function(string, tabSize, lineOracle) {
1408
+ this.pos = this.start = 0;
1409
+ this.string = string;
1410
+ this.tabSize = tabSize || 8;
1411
+ this.lastColumnPos = this.lastColumnValue = 0;
1412
+ this.lineStart = 0;
1413
+ this.lineOracle = lineOracle;
1414
+ };
1415
+
1416
+ StringStream.prototype.eol = function () {return this.pos >= this.string.length};
1417
+ StringStream.prototype.sol = function () {return this.pos == this.lineStart};
1418
+ StringStream.prototype.peek = function () {return this.string.charAt(this.pos) || undefined};
1419
+ StringStream.prototype.next = function () {
1420
+ if (this.pos < this.string.length)
1421
+ { return this.string.charAt(this.pos++) }
1422
+ };
1423
+ StringStream.prototype.eat = function (match) {
1424
+ var ch = this.string.charAt(this.pos);
1425
+ var ok;
1426
+ if (typeof match == "string") { ok = ch == match; }
1427
+ else { ok = ch && (match.test ? match.test(ch) : match(ch)); }
1428
+ if (ok) {++this.pos; return ch}
1429
+ };
1430
+ StringStream.prototype.eatWhile = function (match) {
1431
+ var start = this.pos;
1432
+ while (this.eat(match)){}
1433
+ return this.pos > start
1434
+ };
1435
+ StringStream.prototype.eatSpace = function () {
1436
+ var this$1 = this;
1437
+
1438
+ var start = this.pos;
1439
+ while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) { ++this$1.pos; }
1440
+ return this.pos > start
1441
+ };
1442
+ StringStream.prototype.skipToEnd = function () {this.pos = this.string.length;};
1443
+ StringStream.prototype.skipTo = function (ch) {
1444
+ var found = this.string.indexOf(ch, this.pos);
1445
+ if (found > -1) {this.pos = found; return true}
1446
+ };
1447
+ StringStream.prototype.backUp = function (n) {this.pos -= n;};
1448
+ StringStream.prototype.column = function () {
1449
+ if (this.lastColumnPos < this.start) {
1450
+ this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);
1451
+ this.lastColumnPos = this.start;
1452
+ }
1453
+ return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
1454
+ };
1455
+ StringStream.prototype.indentation = function () {
1456
+ return countColumn(this.string, null, this.tabSize) -
1457
+ (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0)
1458
+ };
1459
+ StringStream.prototype.match = function (pattern, consume, caseInsensitive) {
1460
+ if (typeof pattern == "string") {
1461
+ var cased = function (str) { return caseInsensitive ? str.toLowerCase() : str; };
1462
+ var substr = this.string.substr(this.pos, pattern.length);
1463
+ if (cased(substr) == cased(pattern)) {
1464
+ if (consume !== false) { this.pos += pattern.length; }
1465
+ return true
1466
+ }
1467
+ } else {
1468
+ var match = this.string.slice(this.pos).match(pattern);
1469
+ if (match && match.index > 0) { return null }
1470
+ if (match && consume !== false) { this.pos += match[0].length; }
1471
+ return match
1472
+ }
1473
+ };
1474
+ StringStream.prototype.current = function (){return this.string.slice(this.start, this.pos)};
1475
+ StringStream.prototype.hideFirstChars = function (n, inner) {
1476
+ this.lineStart += n;
1477
+ try { return inner() }
1478
+ finally { this.lineStart -= n; }
1479
+ };
1480
+ StringStream.prototype.lookAhead = function (n) {
1481
+ var oracle = this.lineOracle;
1482
+ return oracle && oracle.lookAhead(n)
1483
+ };
1484
+ StringStream.prototype.baseToken = function () {
1485
+ var oracle = this.lineOracle;
1486
+ return oracle && oracle.baseToken(this.pos)
1487
+ };
1488
+
1489
+ var SavedContext = function(state, lookAhead) {
1490
+ this.state = state;
1491
+ this.lookAhead = lookAhead;
1492
+ };
1493
+
1494
+ var Context = function(doc, state, line, lookAhead) {
1495
+ this.state = state;
1496
+ this.doc = doc;
1497
+ this.line = line;
1498
+ this.maxLookAhead = lookAhead || 0;
1499
+ this.baseTokens = null;
1500
+ this.baseTokenPos = 1;
1501
+ };
1502
+
1503
+ Context.prototype.lookAhead = function (n) {
1504
+ var line = this.doc.getLine(this.line + n);
1505
+ if (line != null && n > this.maxLookAhead) { this.maxLookAhead = n; }
1506
+ return line
1507
+ };
1508
+
1509
+ Context.prototype.baseToken = function (n) {
1510
+ var this$1 = this;
1511
+
1512
+ if (!this.baseTokens) { return null }
1513
+ while (this.baseTokens[this.baseTokenPos] <= n)
1514
+ { this$1.baseTokenPos += 2; }
1515
+ var type = this.baseTokens[this.baseTokenPos + 1];
1516
+ return {type: type && type.replace(/( |^)overlay .*/, ""),
1517
+ size: this.baseTokens[this.baseTokenPos] - n}
1518
+ };
1519
+
1520
+ Context.prototype.nextLine = function () {
1521
+ this.line++;
1522
+ if (this.maxLookAhead > 0) { this.maxLookAhead--; }
1523
+ };
1524
+
1525
+ Context.fromSaved = function (doc, saved, line) {
1526
+ if (saved instanceof SavedContext)
1527
+ { return new Context(doc, copyState(doc.mode, saved.state), line, saved.lookAhead) }
1528
+ else
1529
+ { return new Context(doc, copyState(doc.mode, saved), line) }
1530
+ };
1531
+
1532
+ Context.prototype.save = function (copy) {
1533
+ var state = copy !== false ? copyState(this.doc.mode, this.state) : this.state;
1534
+ return this.maxLookAhead > 0 ? new SavedContext(state, this.maxLookAhead) : state
1535
+ };
1536
+
1537
+
1538
+ // Compute a style array (an array starting with a mode generation
1539
+ // -- for invalidation -- followed by pairs of end positions and
1540
+ // style strings), which is used to highlight the tokens on the
1541
+ // line.
1542
+ function highlightLine(cm, line, context, forceToEnd) {
1543
+ // A styles array always starts with a number identifying the
1544
+ // mode/overlays that it is based on (for easy invalidation).
1545
+ var st = [cm.state.modeGen], lineClasses = {};
1546
+ // Compute the base array of styles
1547
+ runMode(cm, line.text, cm.doc.mode, context, function (end, style) { return st.push(end, style); },
1548
+ lineClasses, forceToEnd);
1549
+ var state = context.state;
1550
+
1551
+ // Run overlays, adjust style array.
1552
+ var loop = function ( o ) {
1553
+ context.baseTokens = st;
1554
+ var overlay = cm.state.overlays[o], i = 1, at = 0;
1555
+ context.state = true;
1556
+ runMode(cm, line.text, overlay.mode, context, function (end, style) {
1557
+ var start = i;
1558
+ // Ensure there's a token end at the current position, and that i points at it
1559
+ while (at < end) {
1560
+ var i_end = st[i];
1561
+ if (i_end > end)
1562
+ { st.splice(i, 1, end, st[i+1], i_end); }
1563
+ i += 2;
1564
+ at = Math.min(end, i_end);
1565
+ }
1566
+ if (!style) { return }
1567
+ if (overlay.opaque) {
1568
+ st.splice(start, i - start, end, "overlay " + style);
1569
+ i = start + 2;
1570
+ } else {
1571
+ for (; start < i; start += 2) {
1572
+ var cur = st[start+1];
1573
+ st[start+1] = (cur ? cur + " " : "") + "overlay " + style;
1574
+ }
1575
+ }
1576
+ }, lineClasses);
1577
+ context.state = state;
1578
+ context.baseTokens = null;
1579
+ context.baseTokenPos = 1;
1580
+ };
1581
+
1582
+ for (var o = 0; o < cm.state.overlays.length; ++o) loop( o );
1583
+
1584
+ return {styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null}
1585
+ }
1586
+
1587
+ function getLineStyles(cm, line, updateFrontier) {
1588
+ if (!line.styles || line.styles[0] != cm.state.modeGen) {
1589
+ var context = getContextBefore(cm, lineNo(line));
1590
+ var resetState = line.text.length > cm.options.maxHighlightLength && copyState(cm.doc.mode, context.state);
1591
+ var result = highlightLine(cm, line, context);
1592
+ if (resetState) { context.state = resetState; }
1593
+ line.stateAfter = context.save(!resetState);
1594
+ line.styles = result.styles;
1595
+ if (result.classes) { line.styleClasses = result.classes; }
1596
+ else if (line.styleClasses) { line.styleClasses = null; }
1597
+ if (updateFrontier === cm.doc.highlightFrontier)
1598
+ { cm.doc.modeFrontier = Math.max(cm.doc.modeFrontier, ++cm.doc.highlightFrontier); }
1599
+ }
1600
+ return line.styles
1601
+ }
1602
+
1603
+ function getContextBefore(cm, n, precise) {
1604
+ var doc = cm.doc, display = cm.display;
1605
+ if (!doc.mode.startState) { return new Context(doc, true, n) }
1606
+ var start = findStartLine(cm, n, precise);
1607
+ var saved = start > doc.first && getLine(doc, start - 1).stateAfter;
1608
+ var context = saved ? Context.fromSaved(doc, saved, start) : new Context(doc, startState(doc.mode), start);
1609
+
1610
+ doc.iter(start, n, function (line) {
1611
+ processLine(cm, line.text, context);
1612
+ var pos = context.line;
1613
+ line.stateAfter = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo ? context.save() : null;
1614
+ context.nextLine();
1615
+ });
1616
+ if (precise) { doc.modeFrontier = context.line; }
1617
+ return context
1618
+ }
1619
+
1620
+ // Lightweight form of highlight -- proceed over this line and
1621
+ // update state, but don't save a style array. Used for lines that
1622
+ // aren't currently visible.
1623
+ function processLine(cm, text, context, startAt) {
1624
+ var mode = cm.doc.mode;
1625
+ var stream = new StringStream(text, cm.options.tabSize, context);
1626
+ stream.start = stream.pos = startAt || 0;
1627
+ if (text == "") { callBlankLine(mode, context.state); }
1628
+ while (!stream.eol()) {
1629
+ readToken(mode, stream, context.state);
1630
+ stream.start = stream.pos;
1631
+ }
1632
+ }
1633
+
1634
+ function callBlankLine(mode, state) {
1635
+ if (mode.blankLine) { return mode.blankLine(state) }
1636
+ if (!mode.innerMode) { return }
1637
+ var inner = innerMode(mode, state);
1638
+ if (inner.mode.blankLine) { return inner.mode.blankLine(inner.state) }
1639
+ }
1640
+
1641
+ function readToken(mode, stream, state, inner) {
1642
+ for (var i = 0; i < 10; i++) {
1643
+ if (inner) { inner[0] = innerMode(mode, state).mode; }
1644
+ var style = mode.token(stream, state);
1645
+ if (stream.pos > stream.start) { return style }
1646
+ }
1647
+ throw new Error("Mode " + mode.name + " failed to advance stream.")
1648
+ }
1649
+
1650
+ var Token = function(stream, type, state) {
1651
+ this.start = stream.start; this.end = stream.pos;
1652
+ this.string = stream.current();
1653
+ this.type = type || null;
1654
+ this.state = state;
1655
+ };
1656
+
1657
+ // Utility for getTokenAt and getLineTokens
1658
+ function takeToken(cm, pos, precise, asArray) {
1659
+ var doc = cm.doc, mode = doc.mode, style;
1660
+ pos = clipPos(doc, pos);
1661
+ var line = getLine(doc, pos.line), context = getContextBefore(cm, pos.line, precise);
1662
+ var stream = new StringStream(line.text, cm.options.tabSize, context), tokens;
1663
+ if (asArray) { tokens = []; }
1664
+ while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
1665
+ stream.start = stream.pos;
1666
+ style = readToken(mode, stream, context.state);
1667
+ if (asArray) { tokens.push(new Token(stream, style, copyState(doc.mode, context.state))); }
1668
+ }
1669
+ return asArray ? tokens : new Token(stream, style, context.state)
1670
+ }
1671
+
1672
+ function extractLineClasses(type, output) {
1673
+ if (type) { for (;;) {
1674
+ var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/);
1675
+ if (!lineClass) { break }
1676
+ type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length);
1677
+ var prop = lineClass[1] ? "bgClass" : "textClass";
1678
+ if (output[prop] == null)
1679
+ { output[prop] = lineClass[2]; }
1680
+ else if (!(new RegExp("(?:^|\s)" + lineClass[2] + "(?:$|\s)")).test(output[prop]))
1681
+ { output[prop] += " " + lineClass[2]; }
1682
+ } }
1683
+ return type
1684
+ }
1685
+
1686
+ // Run the given mode's parser over a line, calling f for each token.
1687
+ function runMode(cm, text, mode, context, f, lineClasses, forceToEnd) {
1688
+ var flattenSpans = mode.flattenSpans;
1689
+ if (flattenSpans == null) { flattenSpans = cm.options.flattenSpans; }
1690
+ var curStart = 0, curStyle = null;
1691
+ var stream = new StringStream(text, cm.options.tabSize, context), style;
1692
+ var inner = cm.options.addModeClass && [null];
1693
+ if (text == "") { extractLineClasses(callBlankLine(mode, context.state), lineClasses); }
1694
+ while (!stream.eol()) {
1695
+ if (stream.pos > cm.options.maxHighlightLength) {
1696
+ flattenSpans = false;
1697
+ if (forceToEnd) { processLine(cm, text, context, stream.pos); }
1698
+ stream.pos = text.length;
1699
+ style = null;
1700
+ } else {
1701
+ style = extractLineClasses(readToken(mode, stream, context.state, inner), lineClasses);
1702
+ }
1703
+ if (inner) {
1704
+ var mName = inner[0].name;
1705
+ if (mName) { style = "m-" + (style ? mName + " " + style : mName); }
1706
+ }
1707
+ if (!flattenSpans || curStyle != style) {
1708
+ while (curStart < stream.start) {
1709
+ curStart = Math.min(stream.start, curStart + 5000);
1710
+ f(curStart, curStyle);
1711
+ }
1712
+ curStyle = style;
1713
+ }
1714
+ stream.start = stream.pos;
1715
+ }
1716
+ while (curStart < stream.pos) {
1717
+ // Webkit seems to refuse to render text nodes longer than 57444
1718
+ // characters, and returns inaccurate measurements in nodes
1719
+ // starting around 5000 chars.
1720
+ var pos = Math.min(stream.pos, curStart + 5000);
1721
+ f(pos, curStyle);
1722
+ curStart = pos;
1723
+ }
1724
+ }
1725
+
1726
+ // Finds the line to start with when starting a parse. Tries to
1727
+ // find a line with a stateAfter, so that it can start with a
1728
+ // valid state. If that fails, it returns the line with the
1729
+ // smallest indentation, which tends to need the least context to
1730
+ // parse correctly.
1731
+ function findStartLine(cm, n, precise) {
1732
+ var minindent, minline, doc = cm.doc;
1733
+ var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100);
1734
+ for (var search = n; search > lim; --search) {
1735
+ if (search <= doc.first) { return doc.first }
1736
+ var line = getLine(doc, search - 1), after = line.stateAfter;
1737
+ if (after && (!precise || search + (after instanceof SavedContext ? after.lookAhead : 0) <= doc.modeFrontier))
1738
+ { return search }
1739
+ var indented = countColumn(line.text, null, cm.options.tabSize);
1740
+ if (minline == null || minindent > indented) {
1741
+ minline = search - 1;
1742
+ minindent = indented;
1743
+ }
1744
+ }
1745
+ return minline
1746
+ }
1747
+
1748
+ function retreatFrontier(doc, n) {
1749
+ doc.modeFrontier = Math.min(doc.modeFrontier, n);
1750
+ if (doc.highlightFrontier < n - 10) { return }
1751
+ var start = doc.first;
1752
+ for (var line = n - 1; line > start; line--) {
1753
+ var saved = getLine(doc, line).stateAfter;
1754
+ // change is on 3
1755
+ // state on line 1 looked ahead 2 -- so saw 3
1756
+ // test 1 + 2 < 3 should cover this
1757
+ if (saved && (!(saved instanceof SavedContext) || line + saved.lookAhead < n)) {
1758
+ start = line + 1;
1759
+ break
1760
+ }
1761
+ }
1762
+ doc.highlightFrontier = Math.min(doc.highlightFrontier, start);
1763
+ }
1764
+
1765
+ // LINE DATA STRUCTURE
1766
+
1767
+ // Line objects. These hold state related to a line, including
1768
+ // highlighting info (the styles array).
1769
+ var Line = function(text, markedSpans, estimateHeight) {
1770
+ this.text = text;
1771
+ attachMarkedSpans(this, markedSpans);
1772
+ this.height = estimateHeight ? estimateHeight(this) : 1;
1773
+ };
1774
+
1775
+ Line.prototype.lineNo = function () { return lineNo(this) };
1776
+ eventMixin(Line);
1777
+
1778
+ // Change the content (text, markers) of a line. Automatically
1779
+ // invalidates cached information and tries to re-estimate the
1780
+ // line's height.
1781
+ function updateLine(line, text, markedSpans, estimateHeight) {
1782
+ line.text = text;
1783
+ if (line.stateAfter) { line.stateAfter = null; }
1784
+ if (line.styles) { line.styles = null; }
1785
+ if (line.order != null) { line.order = null; }
1786
+ detachMarkedSpans(line);
1787
+ attachMarkedSpans(line, markedSpans);
1788
+ var estHeight = estimateHeight ? estimateHeight(line) : 1;
1789
+ if (estHeight != line.height) { updateLineHeight(line, estHeight); }
1790
+ }
1791
+
1792
+ // Detach a line from the document tree and its markers.
1793
+ function cleanUpLine(line) {
1794
+ line.parent = null;
1795
+ detachMarkedSpans(line);
1796
+ }
1797
+
1798
+ // Convert a style as returned by a mode (either null, or a string
1799
+ // containing one or more styles) to a CSS style. This is cached,
1800
+ // and also looks for line-wide styles.
1801
+ var styleToClassCache = {}, styleToClassCacheWithMode = {};
1802
+ function interpretTokenStyle(style, options) {
1803
+ if (!style || /^\s*$/.test(style)) { return null }
1804
+ var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache;
1805
+ return cache[style] ||
1806
+ (cache[style] = style.replace(/\S+/g, "cm-$&"))
1807
+ }
1808
+
1809
+ // Render the DOM representation of the text of a line. Also builds
1810
+ // up a 'line map', which points at the DOM nodes that represent
1811
+ // specific stretches of text, and is used by the measuring code.
1812
+ // The returned object contains the DOM node, this map, and
1813
+ // information about line-wide styles that were set by the mode.
1814
+ function buildLineContent(cm, lineView) {
1815
+ // The padding-right forces the element to have a 'border', which
1816
+ // is needed on Webkit to be able to get line-level bounding
1817
+ // rectangles for it (in measureChar).
1818
+ var content = eltP("span", null, null, webkit ? "padding-right: .1px" : null);
1819
+ var builder = {pre: eltP("pre", [content], "CodeMirror-line"), content: content,
1820
+ col: 0, pos: 0, cm: cm,
1821
+ trailingSpace: false,
1822
+ splitSpaces: cm.getOption("lineWrapping")};
1823
+ lineView.measure = {};
1824
+
1825
+ // Iterate over the logical lines that make up this visual line.
1826
+ for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {
1827
+ var line = i ? lineView.rest[i - 1] : lineView.line, order = (void 0);
1828
+ builder.pos = 0;
1829
+ builder.addToken = buildToken;
1830
+ // Optionally wire in some hacks into the token-rendering
1831
+ // algorithm, to deal with browser quirks.
1832
+ if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line, cm.doc.direction)))
1833
+ { builder.addToken = buildTokenBadBidi(builder.addToken, order); }
1834
+ builder.map = [];
1835
+ var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line);
1836
+ insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate));
1837
+ if (line.styleClasses) {
1838
+ if (line.styleClasses.bgClass)
1839
+ { builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || ""); }
1840
+ if (line.styleClasses.textClass)
1841
+ { builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || ""); }
1842
+ }
1843
+
1844
+ // Ensure at least a single node is present, for measuring.
1845
+ if (builder.map.length == 0)
1846
+ { builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure))); }
1847
+
1848
+ // Store the map and a cache object for the current logical line
1849
+ if (i == 0) {
1850
+ lineView.measure.map = builder.map;
1851
+ lineView.measure.cache = {};
1852
+ } else {
1853
+ (lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map)
1854
+ ;(lineView.measure.caches || (lineView.measure.caches = [])).push({});
1855
+ }
1856
+ }
1857
+
1858
+ // See issue #2901
1859
+ if (webkit) {
1860
+ var last = builder.content.lastChild;
1861
+ if (/\bcm-tab\b/.test(last.className) || (last.querySelector && last.querySelector(".cm-tab")))
1862
+ { builder.content.className = "cm-tab-wrap-hack"; }
1863
+ }
1864
+
1865
+ signal(cm, "renderLine", cm, lineView.line, builder.pre);
1866
+ if (builder.pre.className)
1867
+ { builder.textClass = joinClasses(builder.pre.className, builder.textClass || ""); }
1868
+
1869
+ return builder
1870
+ }
1871
+
1872
+ function defaultSpecialCharPlaceholder(ch) {
1873
+ var token = elt("span", "\u2022", "cm-invalidchar");
1874
+ token.title = "\\u" + ch.charCodeAt(0).toString(16);
1875
+ token.setAttribute("aria-label", token.title);
1876
+ return token
1877
+ }
1878
+
1879
+ // Build up the DOM representation for a single token, and add it to
1880
+ // the line map. Takes care to render special characters separately.
1881
+ function buildToken(builder, text, style, startStyle, endStyle, css, attributes) {
1882
+ if (!text) { return }
1883
+ var displayText = builder.splitSpaces ? splitSpaces(text, builder.trailingSpace) : text;
1884
+ var special = builder.cm.state.specialChars, mustWrap = false;
1885
+ var content;
1886
+ if (!special.test(text)) {
1887
+ builder.col += text.length;
1888
+ content = document.createTextNode(displayText);
1889
+ builder.map.push(builder.pos, builder.pos + text.length, content);
1890
+ if (ie && ie_version < 9) { mustWrap = true; }
1891
+ builder.pos += text.length;
1892
+ } else {
1893
+ content = document.createDocumentFragment();
1894
+ var pos = 0;
1895
+ while (true) {
1896
+ special.lastIndex = pos;
1897
+ var m = special.exec(text);
1898
+ var skipped = m ? m.index - pos : text.length - pos;
1899
+ if (skipped) {
1900
+ var txt = document.createTextNode(displayText.slice(pos, pos + skipped));
1901
+ if (ie && ie_version < 9) { content.appendChild(elt("span", [txt])); }
1902
+ else { content.appendChild(txt); }
1903
+ builder.map.push(builder.pos, builder.pos + skipped, txt);
1904
+ builder.col += skipped;
1905
+ builder.pos += skipped;
1906
+ }
1907
+ if (!m) { break }
1908
+ pos += skipped + 1;
1909
+ var txt$1 = (void 0);
1910
+ if (m[0] == "\t") {
1911
+ var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
1912
+ txt$1 = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
1913
+ txt$1.setAttribute("role", "presentation");
1914
+ txt$1.setAttribute("cm-text", "\t");
1915
+ builder.col += tabWidth;
1916
+ } else if (m[0] == "\r" || m[0] == "\n") {
1917
+ txt$1 = content.appendChild(elt("span", m[0] == "\r" ? "\u240d" : "\u2424", "cm-invalidchar"));
1918
+ txt$1.setAttribute("cm-text", m[0]);
1919
+ builder.col += 1;
1920
+ } else {
1921
+ txt$1 = builder.cm.options.specialCharPlaceholder(m[0]);
1922
+ txt$1.setAttribute("cm-text", m[0]);
1923
+ if (ie && ie_version < 9) { content.appendChild(elt("span", [txt$1])); }
1924
+ else { content.appendChild(txt$1); }
1925
+ builder.col += 1;
1926
+ }
1927
+ builder.map.push(builder.pos, builder.pos + 1, txt$1);
1928
+ builder.pos++;
1929
+ }
1930
+ }
1931
+ builder.trailingSpace = displayText.charCodeAt(text.length - 1) == 32;
1932
+ if (style || startStyle || endStyle || mustWrap || css) {
1933
+ var fullStyle = style || "";
1934
+ if (startStyle) { fullStyle += startStyle; }
1935
+ if (endStyle) { fullStyle += endStyle; }
1936
+ var token = elt("span", [content], fullStyle, css);
1937
+ if (attributes) {
1938
+ for (var attr in attributes) { if (attributes.hasOwnProperty(attr) && attr != "style" && attr != "class")
1939
+ { token.setAttribute(attr, attributes[attr]); } }
1940
+ }
1941
+ return builder.content.appendChild(token)
1942
+ }
1943
+ builder.content.appendChild(content);
1944
+ }
1945
+
1946
+ // Change some spaces to NBSP to prevent the browser from collapsing
1947
+ // trailing spaces at the end of a line when rendering text (issue #1362).
1948
+ function splitSpaces(text, trailingBefore) {
1949
+ if (text.length > 1 && !/ /.test(text)) { return text }
1950
+ var spaceBefore = trailingBefore, result = "";
1951
+ for (var i = 0; i < text.length; i++) {
1952
+ var ch = text.charAt(i);
1953
+ if (ch == " " && spaceBefore && (i == text.length - 1 || text.charCodeAt(i + 1) == 32))
1954
+ { ch = "\u00a0"; }
1955
+ result += ch;
1956
+ spaceBefore = ch == " ";
1957
+ }
1958
+ return result
1959
+ }
1960
+
1961
+ // Work around nonsense dimensions being reported for stretches of
1962
+ // right-to-left text.
1963
+ function buildTokenBadBidi(inner, order) {
1964
+ return function (builder, text, style, startStyle, endStyle, css, attributes) {
1965
+ style = style ? style + " cm-force-border" : "cm-force-border";
1966
+ var start = builder.pos, end = start + text.length;
1967
+ for (;;) {
1968
+ // Find the part that overlaps with the start of this text
1969
+ var part = (void 0);
1970
+ for (var i = 0; i < order.length; i++) {
1971
+ part = order[i];
1972
+ if (part.to > start && part.from <= start) { break }
1973
+ }
1974
+ if (part.to >= end) { return inner(builder, text, style, startStyle, endStyle, css, attributes) }
1975
+ inner(builder, text.slice(0, part.to - start), style, startStyle, null, css, attributes);
1976
+ startStyle = null;
1977
+ text = text.slice(part.to - start);
1978
+ start = part.to;
1979
+ }
1980
+ }
1981
+ }
1982
+
1983
+ function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
1984
+ var widget = !ignoreWidget && marker.widgetNode;
1985
+ if (widget) { builder.map.push(builder.pos, builder.pos + size, widget); }
1986
+ if (!ignoreWidget && builder.cm.display.input.needsContentAttribute) {
1987
+ if (!widget)
1988
+ { widget = builder.content.appendChild(document.createElement("span")); }
1989
+ widget.setAttribute("cm-marker", marker.id);
1990
+ }
1991
+ if (widget) {
1992
+ builder.cm.display.input.setUneditable(widget);
1993
+ builder.content.appendChild(widget);
1994
+ }
1995
+ builder.pos += size;
1996
+ builder.trailingSpace = false;
1997
+ }
1998
+
1999
+ // Outputs a number of spans to make up a line, taking highlighting
2000
+ // and marked text into account.
2001
+ function insertLineContent(line, builder, styles) {
2002
+ var spans = line.markedSpans, allText = line.text, at = 0;
2003
+ if (!spans) {
2004
+ for (var i$1 = 1; i$1 < styles.length; i$1+=2)
2005
+ { builder.addToken(builder, allText.slice(at, at = styles[i$1]), interpretTokenStyle(styles[i$1+1], builder.cm.options)); }
2006
+ return
2007
+ }
2008
+
2009
+ var len = allText.length, pos = 0, i = 1, text = "", style, css;
2010
+ var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, collapsed, attributes;
2011
+ for (;;) {
2012
+ if (nextChange == pos) { // Update current marker set
2013
+ spanStyle = spanEndStyle = spanStartStyle = css = "";
2014
+ attributes = null;
2015
+ collapsed = null; nextChange = Infinity;
2016
+ var foundBookmarks = [], endStyles = (void 0);
2017
+ for (var j = 0; j < spans.length; ++j) {
2018
+ var sp = spans[j], m = sp.marker;
2019
+ if (m.type == "bookmark" && sp.from == pos && m.widgetNode) {
2020
+ foundBookmarks.push(m);
2021
+ } else if (sp.from <= pos && (sp.to == null || sp.to > pos || m.collapsed && sp.to == pos && sp.from == pos)) {
2022
+ if (sp.to != null && sp.to != pos && nextChange > sp.to) {
2023
+ nextChange = sp.to;
2024
+ spanEndStyle = "";
2025
+ }
2026
+ if (m.className) { spanStyle += " " + m.className; }
2027
+ if (m.css) { css = (css ? css + ";" : "") + m.css; }
2028
+ if (m.startStyle && sp.from == pos) { spanStartStyle += " " + m.startStyle; }
2029
+ if (m.endStyle && sp.to == nextChange) { (endStyles || (endStyles = [])).push(m.endStyle, sp.to); }
2030
+ // support for the old title property
2031
+ // https://github.com/codemirror/CodeMirror/pull/5673
2032
+ if (m.title) { (attributes || (attributes = {})).title = m.title; }
2033
+ if (m.attributes) {
2034
+ for (var attr in m.attributes)
2035
+ { (attributes || (attributes = {}))[attr] = m.attributes[attr]; }
2036
+ }
2037
+ if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0))
2038
+ { collapsed = sp; }
2039
+ } else if (sp.from > pos && nextChange > sp.from) {
2040
+ nextChange = sp.from;
2041
+ }
2042
+ }
2043
+ if (endStyles) { for (var j$1 = 0; j$1 < endStyles.length; j$1 += 2)
2044
+ { if (endStyles[j$1 + 1] == nextChange) { spanEndStyle += " " + endStyles[j$1]; } } }
2045
+
2046
+ if (!collapsed || collapsed.from == pos) { for (var j$2 = 0; j$2 < foundBookmarks.length; ++j$2)
2047
+ { buildCollapsedSpan(builder, 0, foundBookmarks[j$2]); } }
2048
+ if (collapsed && (collapsed.from || 0) == pos) {
2049
+ buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos,
2050
+ collapsed.marker, collapsed.from == null);
2051
+ if (collapsed.to == null) { return }
2052
+ if (collapsed.to == pos) { collapsed = false; }
2053
+ }
2054
+ }
2055
+ if (pos >= len) { break }
2056
+
2057
+ var upto = Math.min(len, nextChange);
2058
+ while (true) {
2059
+ if (text) {
2060
+ var end = pos + text.length;
2061
+ if (!collapsed) {
2062
+ var tokenText = end > upto ? text.slice(0, upto - pos) : text;
2063
+ builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
2064
+ spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", css, attributes);
2065
+ }
2066
+ if (end >= upto) {text = text.slice(upto - pos); pos = upto; break}
2067
+ pos = end;
2068
+ spanStartStyle = "";
2069
+ }
2070
+ text = allText.slice(at, at = styles[i++]);
2071
+ style = interpretTokenStyle(styles[i++], builder.cm.options);
2072
+ }
2073
+ }
2074
+ }
2075
+
2076
+
2077
+ // These objects are used to represent the visible (currently drawn)
2078
+ // part of the document. A LineView may correspond to multiple
2079
+ // logical lines, if those are connected by collapsed ranges.
2080
+ function LineView(doc, line, lineN) {
2081
+ // The starting line
2082
+ this.line = line;
2083
+ // Continuing lines, if any
2084
+ this.rest = visualLineContinued(line);
2085
+ // Number of logical lines in this visual line
2086
+ this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1;
2087
+ this.node = this.text = null;
2088
+ this.hidden = lineIsHidden(doc, line);
2089
+ }
2090
+
2091
+ // Create a range of LineView objects for the given lines.
2092
+ function buildViewArray(cm, from, to) {
2093
+ var array = [], nextPos;
2094
+ for (var pos = from; pos < to; pos = nextPos) {
2095
+ var view = new LineView(cm.doc, getLine(cm.doc, pos), pos);
2096
+ nextPos = pos + view.size;
2097
+ array.push(view);
2098
+ }
2099
+ return array
2100
+ }
2101
+
2102
+ var operationGroup = null;
2103
+
2104
+ function pushOperation(op) {
2105
+ if (operationGroup) {
2106
+ operationGroup.ops.push(op);
2107
+ } else {
2108
+ op.ownsGroup = operationGroup = {
2109
+ ops: [op],
2110
+ delayedCallbacks: []
2111
+ };
2112
+ }
2113
+ }
2114
+
2115
+ function fireCallbacksForOps(group) {
2116
+ // Calls delayed callbacks and cursorActivity handlers until no
2117
+ // new ones appear
2118
+ var callbacks = group.delayedCallbacks, i = 0;
2119
+ do {
2120
+ for (; i < callbacks.length; i++)
2121
+ { callbacks[i].call(null); }
2122
+ for (var j = 0; j < group.ops.length; j++) {
2123
+ var op = group.ops[j];
2124
+ if (op.cursorActivityHandlers)
2125
+ { while (op.cursorActivityCalled < op.cursorActivityHandlers.length)
2126
+ { op.cursorActivityHandlers[op.cursorActivityCalled++].call(null, op.cm); } }
2127
+ }
2128
+ } while (i < callbacks.length)
2129
+ }
2130
+
2131
+ function finishOperation(op, endCb) {
2132
+ var group = op.ownsGroup;
2133
+ if (!group) { return }
2134
+
2135
+ try { fireCallbacksForOps(group); }
2136
+ finally {
2137
+ operationGroup = null;
2138
+ endCb(group);
2139
+ }
2140
+ }
2141
+
2142
+ var orphanDelayedCallbacks = null;
2143
+
2144
+ // Often, we want to signal events at a point where we are in the
2145
+ // middle of some work, but don't want the handler to start calling
2146
+ // other methods on the editor, which might be in an inconsistent
2147
+ // state or simply not expect any other events to happen.
2148
+ // signalLater looks whether there are any handlers, and schedules
2149
+ // them to be executed when the last operation ends, or, if no
2150
+ // operation is active, when a timeout fires.
2151
+ function signalLater(emitter, type /*, values...*/) {
2152
+ var arr = getHandlers(emitter, type);
2153
+ if (!arr.length) { return }
2154
+ var args = Array.prototype.slice.call(arguments, 2), list;
2155
+ if (operationGroup) {
2156
+ list = operationGroup.delayedCallbacks;
2157
+ } else if (orphanDelayedCallbacks) {
2158
+ list = orphanDelayedCallbacks;
2159
+ } else {
2160
+ list = orphanDelayedCallbacks = [];
2161
+ setTimeout(fireOrphanDelayed, 0);
2162
+ }
2163
+ var loop = function ( i ) {
2164
+ list.push(function () { return arr[i].apply(null, args); });
2165
+ };
2166
+
2167
+ for (var i = 0; i < arr.length; ++i)
2168
+ loop( i );
2169
+ }
2170
+
2171
+ function fireOrphanDelayed() {
2172
+ var delayed = orphanDelayedCallbacks;
2173
+ orphanDelayedCallbacks = null;
2174
+ for (var i = 0; i < delayed.length; ++i) { delayed[i](); }
2175
+ }
2176
+
2177
+ // When an aspect of a line changes, a string is added to
2178
+ // lineView.changes. This updates the relevant part of the line's
2179
+ // DOM structure.
2180
+ function updateLineForChanges(cm, lineView, lineN, dims) {
2181
+ for (var j = 0; j < lineView.changes.length; j++) {
2182
+ var type = lineView.changes[j];
2183
+ if (type == "text") { updateLineText(cm, lineView); }
2184
+ else if (type == "gutter") { updateLineGutter(cm, lineView, lineN, dims); }
2185
+ else if (type == "class") { updateLineClasses(cm, lineView); }
2186
+ else if (type == "widget") { updateLineWidgets(cm, lineView, dims); }
2187
+ }
2188
+ lineView.changes = null;
2189
+ }
2190
+
2191
+ // Lines with gutter elements, widgets or a background class need to
2192
+ // be wrapped, and have the extra elements added to the wrapper div
2193
+ function ensureLineWrapped(lineView) {
2194
+ if (lineView.node == lineView.text) {
2195
+ lineView.node = elt("div", null, null, "position: relative");
2196
+ if (lineView.text.parentNode)
2197
+ { lineView.text.parentNode.replaceChild(lineView.node, lineView.text); }
2198
+ lineView.node.appendChild(lineView.text);
2199
+ if (ie && ie_version < 8) { lineView.node.style.zIndex = 2; }
2200
+ }
2201
+ return lineView.node
2202
+ }
2203
+
2204
+ function updateLineBackground(cm, lineView) {
2205
+ var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass;
2206
+ if (cls) { cls += " CodeMirror-linebackground"; }
2207
+ if (lineView.background) {
2208
+ if (cls) { lineView.background.className = cls; }
2209
+ else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null; }
2210
+ } else if (cls) {
2211
+ var wrap = ensureLineWrapped(lineView);
2212
+ lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild);
2213
+ cm.display.input.setUneditable(lineView.background);
2214
+ }
2215
+ }
2216
+
2217
+ // Wrapper around buildLineContent which will reuse the structure
2218
+ // in display.externalMeasured when possible.
2219
+ function getLineContent(cm, lineView) {
2220
+ var ext = cm.display.externalMeasured;
2221
+ if (ext && ext.line == lineView.line) {
2222
+ cm.display.externalMeasured = null;
2223
+ lineView.measure = ext.measure;
2224
+ return ext.built
2225
+ }
2226
+ return buildLineContent(cm, lineView)
2227
+ }
2228
+
2229
+ // Redraw the line's text. Interacts with the background and text
2230
+ // classes because the mode may output tokens that influence these
2231
+ // classes.
2232
+ function updateLineText(cm, lineView) {
2233
+ var cls = lineView.text.className;
2234
+ var built = getLineContent(cm, lineView);
2235
+ if (lineView.text == lineView.node) { lineView.node = built.pre; }
2236
+ lineView.text.parentNode.replaceChild(built.pre, lineView.text);
2237
+ lineView.text = built.pre;
2238
+ if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
2239
+ lineView.bgClass = built.bgClass;
2240
+ lineView.textClass = built.textClass;
2241
+ updateLineClasses(cm, lineView);
2242
+ } else if (cls) {
2243
+ lineView.text.className = cls;
2244
+ }
2245
+ }
2246
+
2247
+ function updateLineClasses(cm, lineView) {
2248
+ updateLineBackground(cm, lineView);
2249
+ if (lineView.line.wrapClass)
2250
+ { ensureLineWrapped(lineView).className = lineView.line.wrapClass; }
2251
+ else if (lineView.node != lineView.text)
2252
+ { lineView.node.className = ""; }
2253
+ var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass;
2254
+ lineView.text.className = textClass || "";
2255
+ }
2256
+
2257
+ function updateLineGutter(cm, lineView, lineN, dims) {
2258
+ if (lineView.gutter) {
2259
+ lineView.node.removeChild(lineView.gutter);
2260
+ lineView.gutter = null;
2261
+ }
2262
+ if (lineView.gutterBackground) {
2263
+ lineView.node.removeChild(lineView.gutterBackground);
2264
+ lineView.gutterBackground = null;
2265
+ }
2266
+ if (lineView.line.gutterClass) {
2267
+ var wrap = ensureLineWrapped(lineView);
2268
+ lineView.gutterBackground = elt("div", null, "CodeMirror-gutter-background " + lineView.line.gutterClass,
2269
+ ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px; width: " + (dims.gutterTotalWidth) + "px"));
2270
+ cm.display.input.setUneditable(lineView.gutterBackground);
2271
+ wrap.insertBefore(lineView.gutterBackground, lineView.text);
2272
+ }
2273
+ var markers = lineView.line.gutterMarkers;
2274
+ if (cm.options.lineNumbers || markers) {
2275
+ var wrap$1 = ensureLineWrapped(lineView);
2276
+ var gutterWrap = lineView.gutter = elt("div", null, "CodeMirror-gutter-wrapper", ("left: " + (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px"));
2277
+ cm.display.input.setUneditable(gutterWrap);
2278
+ wrap$1.insertBefore(gutterWrap, lineView.text);
2279
+ if (lineView.line.gutterClass)
2280
+ { gutterWrap.className += " " + lineView.line.gutterClass; }
2281
+ if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
2282
+ { lineView.lineNumber = gutterWrap.appendChild(
2283
+ elt("div", lineNumberFor(cm.options, lineN),
2284
+ "CodeMirror-linenumber CodeMirror-gutter-elt",
2285
+ ("left: " + (dims.gutterLeft["CodeMirror-linenumbers"]) + "px; width: " + (cm.display.lineNumInnerWidth) + "px"))); }
2286
+ if (markers) { for (var k = 0; k < cm.options.gutters.length; ++k) {
2287
+ var id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id];
2288
+ if (found)
2289
+ { gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt",
2290
+ ("left: " + (dims.gutterLeft[id]) + "px; width: " + (dims.gutterWidth[id]) + "px"))); }
2291
+ } }
2292
+ }
2293
+ }
2294
+
2295
+ function updateLineWidgets(cm, lineView, dims) {
2296
+ if (lineView.alignable) { lineView.alignable = null; }
2297
+ for (var node = lineView.node.firstChild, next = (void 0); node; node = next) {
2298
+ next = node.nextSibling;
2299
+ if (node.className == "CodeMirror-linewidget")
2300
+ { lineView.node.removeChild(node); }
2301
+ }
2302
+ insertLineWidgets(cm, lineView, dims);
2303
+ }
2304
+
2305
+ // Build a line's DOM representation from scratch
2306
+ function buildLineElement(cm, lineView, lineN, dims) {
2307
+ var built = getLineContent(cm, lineView);
2308
+ lineView.text = lineView.node = built.pre;
2309
+ if (built.bgClass) { lineView.bgClass = built.bgClass; }
2310
+ if (built.textClass) { lineView.textClass = built.textClass; }
2311
+
2312
+ updateLineClasses(cm, lineView);
2313
+ updateLineGutter(cm, lineView, lineN, dims);
2314
+ insertLineWidgets(cm, lineView, dims);
2315
+ return lineView.node
2316
+ }
2317
+
2318
+ // A lineView may contain multiple logical lines (when merged by
2319
+ // collapsed spans). The widgets for all of them need to be drawn.
2320
+ function insertLineWidgets(cm, lineView, dims) {
2321
+ insertLineWidgetsFor(cm, lineView.line, lineView, dims, true);
2322
+ if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
2323
+ { insertLineWidgetsFor(cm, lineView.rest[i], lineView, dims, false); } }
2324
+ }
2325
+
2326
+ function insertLineWidgetsFor(cm, line, lineView, dims, allowAbove) {
2327
+ if (!line.widgets) { return }
2328
+ var wrap = ensureLineWrapped(lineView);
2329
+ for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
2330
+ var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget");
2331
+ if (!widget.handleMouseEvents) { node.setAttribute("cm-ignore-events", "true"); }
2332
+ positionLineWidget(widget, node, lineView, dims);
2333
+ cm.display.input.setUneditable(node);
2334
+ if (allowAbove && widget.above)
2335
+ { wrap.insertBefore(node, lineView.gutter || lineView.text); }
2336
+ else
2337
+ { wrap.appendChild(node); }
2338
+ signalLater(widget, "redraw");
2339
+ }
2340
+ }
2341
+
2342
+ function positionLineWidget(widget, node, lineView, dims) {
2343
+ if (widget.noHScroll) {
2344
+ (lineView.alignable || (lineView.alignable = [])).push(node);
2345
+ var width = dims.wrapperWidth;
2346
+ node.style.left = dims.fixedPos + "px";
2347
+ if (!widget.coverGutter) {
2348
+ width -= dims.gutterTotalWidth;
2349
+ node.style.paddingLeft = dims.gutterTotalWidth + "px";
2350
+ }
2351
+ node.style.width = width + "px";
2352
+ }
2353
+ if (widget.coverGutter) {
2354
+ node.style.zIndex = 5;
2355
+ node.style.position = "relative";
2356
+ if (!widget.noHScroll) { node.style.marginLeft = -dims.gutterTotalWidth + "px"; }
2357
+ }
2358
+ }
2359
+
2360
+ function widgetHeight(widget) {
2361
+ if (widget.height != null) { return widget.height }
2362
+ var cm = widget.doc.cm;
2363
+ if (!cm) { return 0 }
2364
+ if (!contains(document.body, widget.node)) {
2365
+ var parentStyle = "position: relative;";
2366
+ if (widget.coverGutter)
2367
+ { parentStyle += "margin-left: -" + cm.display.gutters.offsetWidth + "px;"; }
2368
+ if (widget.noHScroll)
2369
+ { parentStyle += "width: " + cm.display.wrapper.clientWidth + "px;"; }
2370
+ removeChildrenAndAdd(cm.display.measure, elt("div", [widget.node], null, parentStyle));
2371
+ }
2372
+ return widget.height = widget.node.parentNode.offsetHeight
2373
+ }
2374
+
2375
+ // Return true when the given mouse event happened in a widget
2376
+ function eventInWidget(display, e) {
2377
+ for (var n = e_target(e); n != display.wrapper; n = n.parentNode) {
2378
+ if (!n || (n.nodeType == 1 && n.getAttribute("cm-ignore-events") == "true") ||
2379
+ (n.parentNode == display.sizer && n != display.mover))
2380
+ { return true }
2381
+ }
2382
+ }
2383
+
2384
+ // POSITION MEASUREMENT
2385
+
2386
+ function paddingTop(display) {return display.lineSpace.offsetTop}
2387
+ function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight}
2388
+ function paddingH(display) {
2389
+ if (display.cachedPaddingH) { return display.cachedPaddingH }
2390
+ var e = removeChildrenAndAdd(display.measure, elt("pre", "x"));
2391
+ var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle;
2392
+ var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)};
2393
+ if (!isNaN(data.left) && !isNaN(data.right)) { display.cachedPaddingH = data; }
2394
+ return data
2395
+ }
2396
+
2397
+ function scrollGap(cm) { return scrollerGap - cm.display.nativeBarWidth }
2398
+ function displayWidth(cm) {
2399
+ return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth
2400
+ }
2401
+ function displayHeight(cm) {
2402
+ return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight
2403
+ }
2404
+
2405
+ // Ensure the lineView.wrapping.heights array is populated. This is
2406
+ // an array of bottom offsets for the lines that make up a drawn
2407
+ // line. When lineWrapping is on, there might be more than one
2408
+ // height.
2409
+ function ensureLineHeights(cm, lineView, rect) {
2410
+ var wrapping = cm.options.lineWrapping;
2411
+ var curWidth = wrapping && displayWidth(cm);
2412
+ if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
2413
+ var heights = lineView.measure.heights = [];
2414
+ if (wrapping) {
2415
+ lineView.measure.width = curWidth;
2416
+ var rects = lineView.text.firstChild.getClientRects();
2417
+ for (var i = 0; i < rects.length - 1; i++) {
2418
+ var cur = rects[i], next = rects[i + 1];
2419
+ if (Math.abs(cur.bottom - next.bottom) > 2)
2420
+ { heights.push((cur.bottom + next.top) / 2 - rect.top); }
2421
+ }
2422
+ }
2423
+ heights.push(rect.bottom - rect.top);
2424
+ }
2425
+ }
2426
+
2427
+ // Find a line map (mapping character offsets to text nodes) and a
2428
+ // measurement cache for the given line number. (A line view might
2429
+ // contain multiple lines when collapsed ranges are present.)
2430
+ function mapFromLineView(lineView, line, lineN) {
2431
+ if (lineView.line == line)
2432
+ { return {map: lineView.measure.map, cache: lineView.measure.cache} }
2433
+ for (var i = 0; i < lineView.rest.length; i++)
2434
+ { if (lineView.rest[i] == line)
2435
+ { return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i]} } }
2436
+ for (var i$1 = 0; i$1 < lineView.rest.length; i$1++)
2437
+ { if (lineNo(lineView.rest[i$1]) > lineN)
2438
+ { return {map: lineView.measure.maps[i$1], cache: lineView.measure.caches[i$1], before: true} } }
2439
+ }
2440
+
2441
+ // Render a line into the hidden node display.externalMeasured. Used
2442
+ // when measurement is needed for a line that's not in the viewport.
2443
+ function updateExternalMeasurement(cm, line) {
2444
+ line = visualLine(line);
2445
+ var lineN = lineNo(line);
2446
+ var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN);
2447
+ view.lineN = lineN;
2448
+ var built = view.built = buildLineContent(cm, view);
2449
+ view.text = built.pre;
2450
+ removeChildrenAndAdd(cm.display.lineMeasure, built.pre);
2451
+ return view
2452
+ }
2453
+
2454
+ // Get a {top, bottom, left, right} box (in line-local coordinates)
2455
+ // for a given character.
2456
+ function measureChar(cm, line, ch, bias) {
2457
+ return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias)
2458
+ }
2459
+
2460
+ // Find a line view that corresponds to the given line number.
2461
+ function findViewForLine(cm, lineN) {
2462
+ if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo)
2463
+ { return cm.display.view[findViewIndex(cm, lineN)] }
2464
+ var ext = cm.display.externalMeasured;
2465
+ if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size)
2466
+ { return ext }
2467
+ }
2468
+
2469
+ // Measurement can be split in two steps, the set-up work that
2470
+ // applies to the whole line, and the measurement of the actual
2471
+ // character. Functions like coordsChar, that need to do a lot of
2472
+ // measurements in a row, can thus ensure that the set-up work is
2473
+ // only done once.
2474
+ function prepareMeasureForLine(cm, line) {
2475
+ var lineN = lineNo(line);
2476
+ var view = findViewForLine(cm, lineN);
2477
+ if (view && !view.text) {
2478
+ view = null;
2479
+ } else if (view && view.changes) {
2480
+ updateLineForChanges(cm, view, lineN, getDimensions(cm));
2481
+ cm.curOp.forceUpdate = true;
2482
+ }
2483
+ if (!view)
2484
+ { view = updateExternalMeasurement(cm, line); }
2485
+
2486
+ var info = mapFromLineView(view, line, lineN);
2487
+ return {
2488
+ line: line, view: view, rect: null,
2489
+ map: info.map, cache: info.cache, before: info.before,
2490
+ hasHeights: false
2491
+ }
2492
+ }
2493
+
2494
+ // Given a prepared measurement object, measures the position of an
2495
+ // actual character (or fetches it from the cache).
2496
+ function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
2497
+ if (prepared.before) { ch = -1; }
2498
+ var key = ch + (bias || ""), found;
2499
+ if (prepared.cache.hasOwnProperty(key)) {
2500
+ found = prepared.cache[key];
2501
+ } else {
2502
+ if (!prepared.rect)
2503
+ { prepared.rect = prepared.view.text.getBoundingClientRect(); }
2504
+ if (!prepared.hasHeights) {
2505
+ ensureLineHeights(cm, prepared.view, prepared.rect);
2506
+ prepared.hasHeights = true;
2507
+ }
2508
+ found = measureCharInner(cm, prepared, ch, bias);
2509
+ if (!found.bogus) { prepared.cache[key] = found; }
2510
+ }
2511
+ return {left: found.left, right: found.right,
2512
+ top: varHeight ? found.rtop : found.top,
2513
+ bottom: varHeight ? found.rbottom : found.bottom}
2514
+ }
2515
+
2516
+ var nullRect = {left: 0, right: 0, top: 0, bottom: 0};
2517
+
2518
+ function nodeAndOffsetInLineMap(map$$1, ch, bias) {
2519
+ var node, start, end, collapse, mStart, mEnd;
2520
+ // First, search the line map for the text node corresponding to,
2521
+ // or closest to, the target character.
2522
+ for (var i = 0; i < map$$1.length; i += 3) {
2523
+ mStart = map$$1[i];
2524
+ mEnd = map$$1[i + 1];
2525
+ if (ch < mStart) {
2526
+ start = 0; end = 1;
2527
+ collapse = "left";
2528
+ } else if (ch < mEnd) {
2529
+ start = ch - mStart;
2530
+ end = start + 1;
2531
+ } else if (i == map$$1.length - 3 || ch == mEnd && map$$1[i + 3] > ch) {
2532
+ end = mEnd - mStart;
2533
+ start = end - 1;
2534
+ if (ch >= mEnd) { collapse = "right"; }
2535
+ }
2536
+ if (start != null) {
2537
+ node = map$$1[i + 2];
2538
+ if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
2539
+ { collapse = bias; }
2540
+ if (bias == "left" && start == 0)
2541
+ { while (i && map$$1[i - 2] == map$$1[i - 3] && map$$1[i - 1].insertLeft) {
2542
+ node = map$$1[(i -= 3) + 2];
2543
+ collapse = "left";
2544
+ } }
2545
+ if (bias == "right" && start == mEnd - mStart)
2546
+ { while (i < map$$1.length - 3 && map$$1[i + 3] == map$$1[i + 4] && !map$$1[i + 5].insertLeft) {
2547
+ node = map$$1[(i += 3) + 2];
2548
+ collapse = "right";
2549
+ } }
2550
+ break
2551
+ }
2552
+ }
2553
+ return {node: node, start: start, end: end, collapse: collapse, coverStart: mStart, coverEnd: mEnd}
2554
+ }
2555
+
2556
+ function getUsefulRect(rects, bias) {
2557
+ var rect = nullRect;
2558
+ if (bias == "left") { for (var i = 0; i < rects.length; i++) {
2559
+ if ((rect = rects[i]).left != rect.right) { break }
2560
+ } } else { for (var i$1 = rects.length - 1; i$1 >= 0; i$1--) {
2561
+ if ((rect = rects[i$1]).left != rect.right) { break }
2562
+ } }
2563
+ return rect
2564
+ }
2565
+
2566
+ function measureCharInner(cm, prepared, ch, bias) {
2567
+ var place = nodeAndOffsetInLineMap(prepared.map, ch, bias);
2568
+ var node = place.node, start = place.start, end = place.end, collapse = place.collapse;
2569
+
2570
+ var rect;
2571
+ if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates.
2572
+ for (var i$1 = 0; i$1 < 4; i$1++) { // Retry a maximum of 4 times when nonsense rectangles are returned
2573
+ while (start && isExtendingChar(prepared.line.text.charAt(place.coverStart + start))) { --start; }
2574
+ while (place.coverStart + end < place.coverEnd && isExtendingChar(prepared.line.text.charAt(place.coverStart + end))) { ++end; }
2575
+ if (ie && ie_version < 9 && start == 0 && end == place.coverEnd - place.coverStart)
2576
+ { rect = node.parentNode.getBoundingClientRect(); }
2577
+ else
2578
+ { rect = getUsefulRect(range(node, start, end).getClientRects(), bias); }
2579
+ if (rect.left || rect.right || start == 0) { break }
2580
+ end = start;
2581
+ start = start - 1;
2582
+ collapse = "right";
2583
+ }
2584
+ if (ie && ie_version < 11) { rect = maybeUpdateRectForZooming(cm.display.measure, rect); }
2585
+ } else { // If it is a widget, simply get the box for the whole widget.
2586
+ if (start > 0) { collapse = bias = "right"; }
2587
+ var rects;
2588
+ if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1)
2589
+ { rect = rects[bias == "right" ? rects.length - 1 : 0]; }
2590
+ else
2591
+ { rect = node.getBoundingClientRect(); }
2592
+ }
2593
+ if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
2594
+ var rSpan = node.parentNode.getClientRects()[0];
2595
+ if (rSpan)
2596
+ { rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom}; }
2597
+ else
2598
+ { rect = nullRect; }
2599
+ }
2600
+
2601
+ var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top;
2602
+ var mid = (rtop + rbot) / 2;
2603
+ var heights = prepared.view.measure.heights;
2604
+ var i = 0;
2605
+ for (; i < heights.length - 1; i++)
2606
+ { if (mid < heights[i]) { break } }
2607
+ var top = i ? heights[i - 1] : 0, bot = heights[i];
2608
+ var result = {left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left,
2609
+ right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left,
2610
+ top: top, bottom: bot};
2611
+ if (!rect.left && !rect.right) { result.bogus = true; }
2612
+ if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot; }
2613
+
2614
+ return result
2615
+ }
2616
+
2617
+ // Work around problem with bounding client rects on ranges being
2618
+ // returned incorrectly when zoomed on IE10 and below.
2619
+ function maybeUpdateRectForZooming(measure, rect) {
2620
+ if (!window.screen || screen.logicalXDPI == null ||
2621
+ screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure))
2622
+ { return rect }
2623
+ var scaleX = screen.logicalXDPI / screen.deviceXDPI;
2624
+ var scaleY = screen.logicalYDPI / screen.deviceYDPI;
2625
+ return {left: rect.left * scaleX, right: rect.right * scaleX,
2626
+ top: rect.top * scaleY, bottom: rect.bottom * scaleY}
2627
+ }
2628
+
2629
+ function clearLineMeasurementCacheFor(lineView) {
2630
+ if (lineView.measure) {
2631
+ lineView.measure.cache = {};
2632
+ lineView.measure.heights = null;
2633
+ if (lineView.rest) { for (var i = 0; i < lineView.rest.length; i++)
2634
+ { lineView.measure.caches[i] = {}; } }
2635
+ }
2636
+ }
2637
+
2638
+ function clearLineMeasurementCache(cm) {
2639
+ cm.display.externalMeasure = null;
2640
+ removeChildren(cm.display.lineMeasure);
2641
+ for (var i = 0; i < cm.display.view.length; i++)
2642
+ { clearLineMeasurementCacheFor(cm.display.view[i]); }
2643
+ }
2644
+
2645
+ function clearCaches(cm) {
2646
+ clearLineMeasurementCache(cm);
2647
+ cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null;
2648
+ if (!cm.options.lineWrapping) { cm.display.maxLineChanged = true; }
2649
+ cm.display.lineNumChars = null;
2650
+ }
2651
+
2652
+ function pageScrollX() {
2653
+ // Work around https://bugs.chromium.org/p/chromium/issues/detail?id=489206
2654
+ // which causes page_Offset and bounding client rects to use
2655
+ // different reference viewports and invalidate our calculations.
2656
+ if (chrome && android) { return -(document.body.getBoundingClientRect().left - parseInt(getComputedStyle(document.body).marginLeft)) }
2657
+ return window.pageXOffset || (document.documentElement || document.body).scrollLeft
2658
+ }
2659
+ function pageScrollY() {
2660
+ if (chrome && android) { return -(document.body.getBoundingClientRect().top - parseInt(getComputedStyle(document.body).marginTop)) }
2661
+ return window.pageYOffset || (document.documentElement || document.body).scrollTop
2662
+ }
2663
+
2664
+ function widgetTopHeight(lineObj) {
2665
+ var height = 0;
2666
+ if (lineObj.widgets) { for (var i = 0; i < lineObj.widgets.length; ++i) { if (lineObj.widgets[i].above)
2667
+ { height += widgetHeight(lineObj.widgets[i]); } } }
2668
+ return height
2669
+ }
2670
+
2671
+ // Converts a {top, bottom, left, right} box from line-local
2672
+ // coordinates into another coordinate system. Context may be one of
2673
+ // "line", "div" (display.lineDiv), "local"./null (editor), "window",
2674
+ // or "page".
2675
+ function intoCoordSystem(cm, lineObj, rect, context, includeWidgets) {
2676
+ if (!includeWidgets) {
2677
+ var height = widgetTopHeight(lineObj);
2678
+ rect.top += height; rect.bottom += height;
2679
+ }
2680
+ if (context == "line") { return rect }
2681
+ if (!context) { context = "local"; }
2682
+ var yOff = heightAtLine(lineObj);
2683
+ if (context == "local") { yOff += paddingTop(cm.display); }
2684
+ else { yOff -= cm.display.viewOffset; }
2685
+ if (context == "page" || context == "window") {
2686
+ var lOff = cm.display.lineSpace.getBoundingClientRect();
2687
+ yOff += lOff.top + (context == "window" ? 0 : pageScrollY());
2688
+ var xOff = lOff.left + (context == "window" ? 0 : pageScrollX());
2689
+ rect.left += xOff; rect.right += xOff;
2690
+ }
2691
+ rect.top += yOff; rect.bottom += yOff;
2692
+ return rect
2693
+ }
2694
+
2695
+ // Coverts a box from "div" coords to another coordinate system.
2696
+ // Context may be "window", "page", "div", or "local"./null.
2697
+ function fromCoordSystem(cm, coords, context) {
2698
+ if (context == "div") { return coords }
2699
+ var left = coords.left, top = coords.top;
2700
+ // First move into "page" coordinate system
2701
+ if (context == "page") {
2702
+ left -= pageScrollX();
2703
+ top -= pageScrollY();
2704
+ } else if (context == "local" || !context) {
2705
+ var localBox = cm.display.sizer.getBoundingClientRect();
2706
+ left += localBox.left;
2707
+ top += localBox.top;
2708
+ }
2709
+
2710
+ var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect();
2711
+ return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top}
2712
+ }
2713
+
2714
+ function charCoords(cm, pos, context, lineObj, bias) {
2715
+ if (!lineObj) { lineObj = getLine(cm.doc, pos.line); }
2716
+ return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context)
2717
+ }
2718
+
2719
+ // Returns a box for a given cursor position, which may have an
2720
+ // 'other' property containing the position of the secondary cursor
2721
+ // on a bidi boundary.
2722
+ // A cursor Pos(line, char, "before") is on the same visual line as `char - 1`
2723
+ // and after `char - 1` in writing order of `char - 1`
2724
+ // A cursor Pos(line, char, "after") is on the same visual line as `char`
2725
+ // and before `char` in writing order of `char`
2726
+ // Examples (upper-case letters are RTL, lower-case are LTR):
2727
+ // Pos(0, 1, ...)
2728
+ // before after
2729
+ // ab a|b a|b
2730
+ // aB a|B aB|
2731
+ // Ab |Ab A|b
2732
+ // AB B|A B|A
2733
+ // Every position after the last character on a line is considered to stick
2734
+ // to the last character on the line.
2735
+ function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
2736
+ lineObj = lineObj || getLine(cm.doc, pos.line);
2737
+ if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj); }
2738
+ function get(ch, right) {
2739
+ var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight);
2740
+ if (right) { m.left = m.right; } else { m.right = m.left; }
2741
+ return intoCoordSystem(cm, lineObj, m, context)
2742
+ }
2743
+ var order = getOrder(lineObj, cm.doc.direction), ch = pos.ch, sticky = pos.sticky;
2744
+ if (ch >= lineObj.text.length) {
2745
+ ch = lineObj.text.length;
2746
+ sticky = "before";
2747
+ } else if (ch <= 0) {
2748
+ ch = 0;
2749
+ sticky = "after";
2750
+ }
2751
+ if (!order) { return get(sticky == "before" ? ch - 1 : ch, sticky == "before") }
2752
+
2753
+ function getBidi(ch, partPos, invert) {
2754
+ var part = order[partPos], right = part.level == 1;
2755
+ return get(invert ? ch - 1 : ch, right != invert)
2756
+ }
2757
+ var partPos = getBidiPartAt(order, ch, sticky);
2758
+ var other = bidiOther;
2759
+ var val = getBidi(ch, partPos, sticky == "before");
2760
+ if (other != null) { val.other = getBidi(ch, other, sticky != "before"); }
2761
+ return val
2762
+ }
2763
+
2764
+ // Used to cheaply estimate the coordinates for a position. Used for
2765
+ // intermediate scroll updates.
2766
+ function estimateCoords(cm, pos) {
2767
+ var left = 0;
2768
+ pos = clipPos(cm.doc, pos);
2769
+ if (!cm.options.lineWrapping) { left = charWidth(cm.display) * pos.ch; }
2770
+ var lineObj = getLine(cm.doc, pos.line);
2771
+ var top = heightAtLine(lineObj) + paddingTop(cm.display);
2772
+ return {left: left, right: left, top: top, bottom: top + lineObj.height}
2773
+ }
2774
+
2775
+ // Positions returned by coordsChar contain some extra information.
2776
+ // xRel is the relative x position of the input coordinates compared
2777
+ // to the found position (so xRel > 0 means the coordinates are to
2778
+ // the right of the character position, for example). When outside
2779
+ // is true, that means the coordinates lie outside the line's
2780
+ // vertical range.
2781
+ function PosWithInfo(line, ch, sticky, outside, xRel) {
2782
+ var pos = Pos(line, ch, sticky);
2783
+ pos.xRel = xRel;
2784
+ if (outside) { pos.outside = true; }
2785
+ return pos
2786
+ }
2787
+
2788
+ // Compute the character position closest to the given coordinates.
2789
+ // Input must be lineSpace-local ("div" coordinate system).
2790
+ function coordsChar(cm, x, y) {
2791
+ var doc = cm.doc;
2792
+ y += cm.display.viewOffset;
2793
+ if (y < 0) { return PosWithInfo(doc.first, 0, null, true, -1) }
2794
+ var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1;
2795
+ if (lineN > last)
2796
+ { return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, null, true, 1) }
2797
+ if (x < 0) { x = 0; }
2798
+
2799
+ var lineObj = getLine(doc, lineN);
2800
+ for (;;) {
2801
+ var found = coordsCharInner(cm, lineObj, lineN, x, y);
2802
+ var collapsed = collapsedSpanAround(lineObj, found.ch + (found.xRel > 0 ? 1 : 0));
2803
+ if (!collapsed) { return found }
2804
+ var rangeEnd = collapsed.find(1);
2805
+ if (rangeEnd.line == lineN) { return rangeEnd }
2806
+ lineObj = getLine(doc, lineN = rangeEnd.line);
2807
+ }
2808
+ }
2809
+
2810
+ function wrappedLineExtent(cm, lineObj, preparedMeasure, y) {
2811
+ y -= widgetTopHeight(lineObj);
2812
+ var end = lineObj.text.length;
2813
+ var begin = findFirst(function (ch) { return measureCharPrepared(cm, preparedMeasure, ch - 1).bottom <= y; }, end, 0);
2814
+ end = findFirst(function (ch) { return measureCharPrepared(cm, preparedMeasure, ch).top > y; }, begin, end);
2815
+ return {begin: begin, end: end}
2816
+ }
2817
+
2818
+ function wrappedLineExtentChar(cm, lineObj, preparedMeasure, target) {
2819
+ if (!preparedMeasure) { preparedMeasure = prepareMeasureForLine(cm, lineObj); }
2820
+ var targetTop = intoCoordSystem(cm, lineObj, measureCharPrepared(cm, preparedMeasure, target), "line").top;
2821
+ return wrappedLineExtent(cm, lineObj, preparedMeasure, targetTop)
2822
+ }
2823
+
2824
+ // Returns true if the given side of a box is after the given
2825
+ // coordinates, in top-to-bottom, left-to-right order.
2826
+ function boxIsAfter(box, x, y, left) {
2827
+ return box.bottom <= y ? false : box.top > y ? true : (left ? box.left : box.right) > x
2828
+ }
2829
+
2830
+ function coordsCharInner(cm, lineObj, lineNo$$1, x, y) {
2831
+ // Move y into line-local coordinate space
2832
+ y -= heightAtLine(lineObj);
2833
+ var preparedMeasure = prepareMeasureForLine(cm, lineObj);
2834
+ // When directly calling `measureCharPrepared`, we have to adjust
2835
+ // for the widgets at this line.
2836
+ var widgetHeight$$1 = widgetTopHeight(lineObj);
2837
+ var begin = 0, end = lineObj.text.length, ltr = true;
2838
+
2839
+ var order = getOrder(lineObj, cm.doc.direction);
2840
+ // If the line isn't plain left-to-right text, first figure out
2841
+ // which bidi section the coordinates fall into.
2842
+ if (order) {
2843
+ var part = (cm.options.lineWrapping ? coordsBidiPartWrapped : coordsBidiPart)
2844
+ (cm, lineObj, lineNo$$1, preparedMeasure, order, x, y);
2845
+ ltr = part.level != 1;
2846
+ // The awkward -1 offsets are needed because findFirst (called
2847
+ // on these below) will treat its first bound as inclusive,
2848
+ // second as exclusive, but we want to actually address the
2849
+ // characters in the part's range
2850
+ begin = ltr ? part.from : part.to - 1;
2851
+ end = ltr ? part.to : part.from - 1;
2852
+ }
2853
+
2854
+ // A binary search to find the first character whose bounding box
2855
+ // starts after the coordinates. If we run across any whose box wrap
2856
+ // the coordinates, store that.
2857
+ var chAround = null, boxAround = null;
2858
+ var ch = findFirst(function (ch) {
2859
+ var box = measureCharPrepared(cm, preparedMeasure, ch);
2860
+ box.top += widgetHeight$$1; box.bottom += widgetHeight$$1;
2861
+ if (!boxIsAfter(box, x, y, false)) { return false }
2862
+ if (box.top <= y && box.left <= x) {
2863
+ chAround = ch;
2864
+ boxAround = box;
2865
+ }
2866
+ return true
2867
+ }, begin, end);
2868
+
2869
+ var baseX, sticky, outside = false;
2870
+ // If a box around the coordinates was found, use that
2871
+ if (boxAround) {
2872
+ // Distinguish coordinates nearer to the left or right side of the box
2873
+ var atLeft = x - boxAround.left < boxAround.right - x, atStart = atLeft == ltr;
2874
+ ch = chAround + (atStart ? 0 : 1);
2875
+ sticky = atStart ? "after" : "before";
2876
+ baseX = atLeft ? boxAround.left : boxAround.right;
2877
+ } else {
2878
+ // (Adjust for extended bound, if necessary.)
2879
+ if (!ltr && (ch == end || ch == begin)) { ch++; }
2880
+ // To determine which side to associate with, get the box to the
2881
+ // left of the character and compare it's vertical position to the
2882
+ // coordinates
2883
+ sticky = ch == 0 ? "after" : ch == lineObj.text.length ? "before" :
2884
+ (measureCharPrepared(cm, preparedMeasure, ch - (ltr ? 1 : 0)).bottom + widgetHeight$$1 <= y) == ltr ?
2885
+ "after" : "before";
2886
+ // Now get accurate coordinates for this place, in order to get a
2887
+ // base X position
2888
+ var coords = cursorCoords(cm, Pos(lineNo$$1, ch, sticky), "line", lineObj, preparedMeasure);
2889
+ baseX = coords.left;
2890
+ outside = y < coords.top || y >= coords.bottom;
2891
+ }
2892
+
2893
+ ch = skipExtendingChars(lineObj.text, ch, 1);
2894
+ return PosWithInfo(lineNo$$1, ch, sticky, outside, x - baseX)
2895
+ }
2896
+
2897
+ function coordsBidiPart(cm, lineObj, lineNo$$1, preparedMeasure, order, x, y) {
2898
+ // Bidi parts are sorted left-to-right, and in a non-line-wrapping
2899
+ // situation, we can take this ordering to correspond to the visual
2900
+ // ordering. This finds the first part whose end is after the given
2901
+ // coordinates.
2902
+ var index = findFirst(function (i) {
2903
+ var part = order[i], ltr = part.level != 1;
2904
+ return boxIsAfter(cursorCoords(cm, Pos(lineNo$$1, ltr ? part.to : part.from, ltr ? "before" : "after"),
2905
+ "line", lineObj, preparedMeasure), x, y, true)
2906
+ }, 0, order.length - 1);
2907
+ var part = order[index];
2908
+ // If this isn't the first part, the part's start is also after
2909
+ // the coordinates, and the coordinates aren't on the same line as
2910
+ // that start, move one part back.
2911
+ if (index > 0) {
2912
+ var ltr = part.level != 1;
2913
+ var start = cursorCoords(cm, Pos(lineNo$$1, ltr ? part.from : part.to, ltr ? "after" : "before"),
2914
+ "line", lineObj, preparedMeasure);
2915
+ if (boxIsAfter(start, x, y, true) && start.top > y)
2916
+ { part = order[index - 1]; }
2917
+ }
2918
+ return part
2919
+ }
2920
+
2921
+ function coordsBidiPartWrapped(cm, lineObj, _lineNo, preparedMeasure, order, x, y) {
2922
+ // In a wrapped line, rtl text on wrapping boundaries can do things
2923
+ // that don't correspond to the ordering in our `order` array at
2924
+ // all, so a binary search doesn't work, and we want to return a
2925
+ // part that only spans one line so that the binary search in
2926
+ // coordsCharInner is safe. As such, we first find the extent of the
2927
+ // wrapped line, and then do a flat search in which we discard any
2928
+ // spans that aren't on the line.
2929
+ var ref = wrappedLineExtent(cm, lineObj, preparedMeasure, y);
2930
+ var begin = ref.begin;
2931
+ var end = ref.end;
2932
+ if (/\s/.test(lineObj.text.charAt(end - 1))) { end--; }
2933
+ var part = null, closestDist = null;
2934
+ for (var i = 0; i < order.length; i++) {
2935
+ var p = order[i];
2936
+ if (p.from >= end || p.to <= begin) { continue }
2937
+ var ltr = p.level != 1;
2938
+ var endX = measureCharPrepared(cm, preparedMeasure, ltr ? Math.min(end, p.to) - 1 : Math.max(begin, p.from)).right;
2939
+ // Weigh against spans ending before this, so that they are only
2940
+ // picked if nothing ends after
2941
+ var dist = endX < x ? x - endX + 1e9 : endX - x;
2942
+ if (!part || closestDist > dist) {
2943
+ part = p;
2944
+ closestDist = dist;
2945
+ }
2946
+ }
2947
+ if (!part) { part = order[order.length - 1]; }
2948
+ // Clip the part to the wrapped line.
2949
+ if (part.from < begin) { part = {from: begin, to: part.to, level: part.level}; }
2950
+ if (part.to > end) { part = {from: part.from, to: end, level: part.level}; }
2951
+ return part
2952
+ }
2953
+
2954
+ var measureText;
2955
+ // Compute the default text height.
2956
+ function textHeight(display) {
2957
+ if (display.cachedTextHeight != null) { return display.cachedTextHeight }
2958
+ if (measureText == null) {
2959
+ measureText = elt("pre");
2960
+ // Measure a bunch of lines, for browsers that compute
2961
+ // fractional heights.
2962
+ for (var i = 0; i < 49; ++i) {
2963
+ measureText.appendChild(document.createTextNode("x"));
2964
+ measureText.appendChild(elt("br"));
2965
+ }
2966
+ measureText.appendChild(document.createTextNode("x"));
2967
+ }
2968
+ removeChildrenAndAdd(display.measure, measureText);
2969
+ var height = measureText.offsetHeight / 50;
2970
+ if (height > 3) { display.cachedTextHeight = height; }
2971
+ removeChildren(display.measure);
2972
+ return height || 1
2973
+ }
2974
+
2975
+ // Compute the default character width.
2976
+ function charWidth(display) {
2977
+ if (display.cachedCharWidth != null) { return display.cachedCharWidth }
2978
+ var anchor = elt("span", "xxxxxxxxxx");
2979
+ var pre = elt("pre", [anchor]);
2980
+ removeChildrenAndAdd(display.measure, pre);
2981
+ var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10;
2982
+ if (width > 2) { display.cachedCharWidth = width; }
2983
+ return width || 10
2984
+ }
2985
+
2986
+ // Do a bulk-read of the DOM positions and sizes needed to draw the
2987
+ // view, so that we don't interleave reading and writing to the DOM.
2988
+ function getDimensions(cm) {
2989
+ var d = cm.display, left = {}, width = {};
2990
+ var gutterLeft = d.gutters.clientLeft;
2991
+ for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
2992
+ left[cm.options.gutters[i]] = n.offsetLeft + n.clientLeft + gutterLeft;
2993
+ width[cm.options.gutters[i]] = n.clientWidth;
2994
+ }
2995
+ return {fixedPos: compensateForHScroll(d),
2996
+ gutterTotalWidth: d.gutters.offsetWidth,
2997
+ gutterLeft: left,
2998
+ gutterWidth: width,
2999
+ wrapperWidth: d.wrapper.clientWidth}
3000
+ }
3001
+
3002
+ // Computes display.scroller.scrollLeft + display.gutters.offsetWidth,
3003
+ // but using getBoundingClientRect to get a sub-pixel-accurate
3004
+ // result.
3005
+ function compensateForHScroll(display) {
3006
+ return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left
3007
+ }
3008
+
3009
+ // Returns a function that estimates the height of a line, to use as
3010
+ // first approximation until the line becomes visible (and is thus
3011
+ // properly measurable).
3012
+ function estimateHeight(cm) {
3013
+ var th = textHeight(cm.display), wrapping = cm.options.lineWrapping;
3014
+ var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);
3015
+ return function (line) {
3016
+ if (lineIsHidden(cm.doc, line)) { return 0 }
3017
+
3018
+ var widgetsHeight = 0;
3019
+ if (line.widgets) { for (var i = 0; i < line.widgets.length; i++) {
3020
+ if (line.widgets[i].height) { widgetsHeight += line.widgets[i].height; }
3021
+ } }
3022
+
3023
+ if (wrapping)
3024
+ { return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th }
3025
+ else
3026
+ { return widgetsHeight + th }
3027
+ }
3028
+ }
3029
+
3030
+ function estimateLineHeights(cm) {
3031
+ var doc = cm.doc, est = estimateHeight(cm);
3032
+ doc.iter(function (line) {
3033
+ var estHeight = est(line);
3034
+ if (estHeight != line.height) { updateLineHeight(line, estHeight); }
3035
+ });
3036
+ }
3037
+
3038
+ // Given a mouse event, find the corresponding position. If liberal
3039
+ // is false, it checks whether a gutter or scrollbar was clicked,
3040
+ // and returns null if it was. forRect is used by rectangular
3041
+ // selections, and tries to estimate a character position even for
3042
+ // coordinates beyond the right of the text.
3043
+ function posFromMouse(cm, e, liberal, forRect) {
3044
+ var display = cm.display;
3045
+ if (!liberal && e_target(e).getAttribute("cm-not-content") == "true") { return null }
3046
+
3047
+ var x, y, space = display.lineSpace.getBoundingClientRect();
3048
+ // Fails unpredictably on IE[67] when mouse is dragged around quickly.
3049
+ try { x = e.clientX - space.left; y = e.clientY - space.top; }
3050
+ catch (e) { return null }
3051
+ var coords = coordsChar(cm, x, y), line;
3052
+ if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
3053
+ var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;
3054
+ coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff));
3055
+ }
3056
+ return coords
3057
+ }
3058
+
3059
+ // Find the view element corresponding to a given line. Return null
3060
+ // when the line isn't visible.
3061
+ function findViewIndex(cm, n) {
3062
+ if (n >= cm.display.viewTo) { return null }
3063
+ n -= cm.display.viewFrom;
3064
+ if (n < 0) { return null }
3065
+ var view = cm.display.view;
3066
+ for (var i = 0; i < view.length; i++) {
3067
+ n -= view[i].size;
3068
+ if (n < 0) { return i }
3069
+ }
3070
+ }
3071
+
3072
+ function updateSelection(cm) {
3073
+ cm.display.input.showSelection(cm.display.input.prepareSelection());
3074
+ }
3075
+
3076
+ function prepareSelection(cm, primary) {
3077
+ if ( primary === void 0 ) primary = true;
3078
+
3079
+ var doc = cm.doc, result = {};
3080
+ var curFragment = result.cursors = document.createDocumentFragment();
3081
+ var selFragment = result.selection = document.createDocumentFragment();
3082
+
3083
+ for (var i = 0; i < doc.sel.ranges.length; i++) {
3084
+ if (!primary && i == doc.sel.primIndex) { continue }
3085
+ var range$$1 = doc.sel.ranges[i];
3086
+ if (range$$1.from().line >= cm.display.viewTo || range$$1.to().line < cm.display.viewFrom) { continue }
3087
+ var collapsed = range$$1.empty();
3088
+ if (collapsed || cm.options.showCursorWhenSelecting)
3089
+ { drawSelectionCursor(cm, range$$1.head, curFragment); }
3090
+ if (!collapsed)
3091
+ { drawSelectionRange(cm, range$$1, selFragment); }
3092
+ }
3093
+ return result
3094
+ }
3095
+
3096
+ // Draws a cursor for the given range
3097
+ function drawSelectionCursor(cm, head, output) {
3098
+ var pos = cursorCoords(cm, head, "div", null, null, !cm.options.singleCursorHeightPerLine);
3099
+
3100
+ var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"));
3101
+ cursor.style.left = pos.left + "px";
3102
+ cursor.style.top = pos.top + "px";
3103
+ cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
3104
+
3105
+ if (pos.other) {
3106
+ // Secondary cursor, shown when on a 'jump' in bi-directional text
3107
+ var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"));
3108
+ otherCursor.style.display = "";
3109
+ otherCursor.style.left = pos.other.left + "px";
3110
+ otherCursor.style.top = pos.other.top + "px";
3111
+ otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px";
3112
+ }
3113
+ }
3114
+
3115
+ function cmpCoords(a, b) { return a.top - b.top || a.left - b.left }
3116
+
3117
+ // Draws the given range as a highlighted selection
3118
+ function drawSelectionRange(cm, range$$1, output) {
3119
+ var display = cm.display, doc = cm.doc;
3120
+ var fragment = document.createDocumentFragment();
3121
+ var padding = paddingH(cm.display), leftSide = padding.left;
3122
+ var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right;
3123
+ var docLTR = doc.direction == "ltr";
3124
+
3125
+ function add(left, top, width, bottom) {
3126
+ if (top < 0) { top = 0; }
3127
+ top = Math.round(top);
3128
+ bottom = Math.round(bottom);
3129
+ fragment.appendChild(elt("div", null, "CodeMirror-selected", ("position: absolute; left: " + left + "px;\n top: " + top + "px; width: " + (width == null ? rightSide - left : width) + "px;\n height: " + (bottom - top) + "px")));
3130
+ }
3131
+
3132
+ function drawForLine(line, fromArg, toArg) {
3133
+ var lineObj = getLine(doc, line);
3134
+ var lineLen = lineObj.text.length;
3135
+ var start, end;
3136
+ function coords(ch, bias) {
3137
+ return charCoords(cm, Pos(line, ch), "div", lineObj, bias)
3138
+ }
3139
+
3140
+ function wrapX(pos, dir, side) {
3141
+ var extent = wrappedLineExtentChar(cm, lineObj, null, pos);
3142
+ var prop = (dir == "ltr") == (side == "after") ? "left" : "right";
3143
+ var ch = side == "after" ? extent.begin : extent.end - (/\s/.test(lineObj.text.charAt(extent.end - 1)) ? 2 : 1);
3144
+ return coords(ch, prop)[prop]
3145
+ }
3146
+
3147
+ var order = getOrder(lineObj, doc.direction);
3148
+ iterateBidiSections(order, fromArg || 0, toArg == null ? lineLen : toArg, function (from, to, dir, i) {
3149
+ var ltr = dir == "ltr";
3150
+ var fromPos = coords(from, ltr ? "left" : "right");
3151
+ var toPos = coords(to - 1, ltr ? "right" : "left");
3152
+
3153
+ var openStart = fromArg == null && from == 0, openEnd = toArg == null && to == lineLen;
3154
+ var first = i == 0, last = !order || i == order.length - 1;
3155
+ if (toPos.top - fromPos.top <= 3) { // Single line
3156
+ var openLeft = (docLTR ? openStart : openEnd) && first;
3157
+ var openRight = (docLTR ? openEnd : openStart) && last;
3158
+ var left = openLeft ? leftSide : (ltr ? fromPos : toPos).left;
3159
+ var right = openRight ? rightSide : (ltr ? toPos : fromPos).right;
3160
+ add(left, fromPos.top, right - left, fromPos.bottom);
3161
+ } else { // Multiple lines
3162
+ var topLeft, topRight, botLeft, botRight;
3163
+ if (ltr) {
3164
+ topLeft = docLTR && openStart && first ? leftSide : fromPos.left;
3165
+ topRight = docLTR ? rightSide : wrapX(from, dir, "before");
3166
+ botLeft = docLTR ? leftSide : wrapX(to, dir, "after");
3167
+ botRight = docLTR && openEnd && last ? rightSide : toPos.right;
3168
+ } else {
3169
+ topLeft = !docLTR ? leftSide : wrapX(from, dir, "before");
3170
+ topRight = !docLTR && openStart && first ? rightSide : fromPos.right;
3171
+ botLeft = !docLTR && openEnd && last ? leftSide : toPos.left;
3172
+ botRight = !docLTR ? rightSide : wrapX(to, dir, "after");
3173
+ }
3174
+ add(topLeft, fromPos.top, topRight - topLeft, fromPos.bottom);
3175
+ if (fromPos.bottom < toPos.top) { add(leftSide, fromPos.bottom, null, toPos.top); }
3176
+ add(botLeft, toPos.top, botRight - botLeft, toPos.bottom);
3177
+ }
3178
+
3179
+ if (!start || cmpCoords(fromPos, start) < 0) { start = fromPos; }
3180
+ if (cmpCoords(toPos, start) < 0) { start = toPos; }
3181
+ if (!end || cmpCoords(fromPos, end) < 0) { end = fromPos; }
3182
+ if (cmpCoords(toPos, end) < 0) { end = toPos; }
3183
+ });
3184
+ return {start: start, end: end}
3185
+ }
3186
+
3187
+ var sFrom = range$$1.from(), sTo = range$$1.to();
3188
+ if (sFrom.line == sTo.line) {
3189
+ drawForLine(sFrom.line, sFrom.ch, sTo.ch);
3190
+ } else {
3191
+ var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line);
3192
+ var singleVLine = visualLine(fromLine) == visualLine(toLine);
3193
+ var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end;
3194
+ var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start;
3195
+ if (singleVLine) {
3196
+ if (leftEnd.top < rightStart.top - 2) {
3197
+ add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
3198
+ add(leftSide, rightStart.top, rightStart.left, rightStart.bottom);
3199
+ } else {
3200
+ add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
3201
+ }
3202
+ }
3203
+ if (leftEnd.bottom < rightStart.top)
3204
+ { add(leftSide, leftEnd.bottom, null, rightStart.top); }
3205
+ }
3206
+
3207
+ output.appendChild(fragment);
3208
+ }
3209
+
3210
+ // Cursor-blinking
3211
+ function restartBlink(cm) {
3212
+ if (!cm.state.focused) { return }
3213
+ var display = cm.display;
3214
+ clearInterval(display.blinker);
3215
+ var on = true;
3216
+ display.cursorDiv.style.visibility = "";
3217
+ if (cm.options.cursorBlinkRate > 0)
3218
+ { display.blinker = setInterval(function () { return display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden"; },
3219
+ cm.options.cursorBlinkRate); }
3220
+ else if (cm.options.cursorBlinkRate < 0)
3221
+ { display.cursorDiv.style.visibility = "hidden"; }
3222
+ }
3223
+
3224
+ function ensureFocus(cm) {
3225
+ if (!cm.state.focused) { cm.display.input.focus(); onFocus(cm); }
3226
+ }
3227
+
3228
+ function delayBlurEvent(cm) {
3229
+ cm.state.delayingBlurEvent = true;
3230
+ setTimeout(function () { if (cm.state.delayingBlurEvent) {
3231
+ cm.state.delayingBlurEvent = false;
3232
+ onBlur(cm);
3233
+ } }, 100);
3234
+ }
3235
+
3236
+ function onFocus(cm, e) {
3237
+ if (cm.state.delayingBlurEvent) { cm.state.delayingBlurEvent = false; }
3238
+
3239
+ if (cm.options.readOnly == "nocursor") { return }
3240
+ if (!cm.state.focused) {
3241
+ signal(cm, "focus", cm, e);
3242
+ cm.state.focused = true;
3243
+ addClass(cm.display.wrapper, "CodeMirror-focused");
3244
+ // This test prevents this from firing when a context
3245
+ // menu is closed (since the input reset would kill the
3246
+ // select-all detection hack)
3247
+ if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
3248
+ cm.display.input.reset();
3249
+ if (webkit) { setTimeout(function () { return cm.display.input.reset(true); }, 20); } // Issue #1730
3250
+ }
3251
+ cm.display.input.receivedFocus();
3252
+ }
3253
+ restartBlink(cm);
3254
+ }
3255
+ function onBlur(cm, e) {
3256
+ if (cm.state.delayingBlurEvent) { return }
3257
+
3258
+ if (cm.state.focused) {
3259
+ signal(cm, "blur", cm, e);
3260
+ cm.state.focused = false;
3261
+ rmClass(cm.display.wrapper, "CodeMirror-focused");
3262
+ }
3263
+ clearInterval(cm.display.blinker);
3264
+ setTimeout(function () { if (!cm.state.focused) { cm.display.shift = false; } }, 150);
3265
+ }
3266
+
3267
+ // Read the actual heights of the rendered lines, and update their
3268
+ // stored heights to match.
3269
+ function updateHeightsInViewport(cm) {
3270
+ var display = cm.display;
3271
+ var prevBottom = display.lineDiv.offsetTop;
3272
+ for (var i = 0; i < display.view.length; i++) {
3273
+ var cur = display.view[i], wrapping = cm.options.lineWrapping;
3274
+ var height = (void 0), width = 0;
3275
+ if (cur.hidden) { continue }
3276
+ if (ie && ie_version < 8) {
3277
+ var bot = cur.node.offsetTop + cur.node.offsetHeight;
3278
+ height = bot - prevBottom;
3279
+ prevBottom = bot;
3280
+ } else {
3281
+ var box = cur.node.getBoundingClientRect();
3282
+ height = box.bottom - box.top;
3283
+ // Check that lines don't extend past the right of the current
3284
+ // editor width
3285
+ if (!wrapping && cur.text.firstChild)
3286
+ { width = cur.text.firstChild.getBoundingClientRect().right - box.left - 1; }
3287
+ }
3288
+ var diff = cur.line.height - height;
3289
+ if (height < 2) { height = textHeight(display); }
3290
+ if (diff > .005 || diff < -.005) {
3291
+ updateLineHeight(cur.line, height);
3292
+ updateWidgetHeight(cur.line);
3293
+ if (cur.rest) { for (var j = 0; j < cur.rest.length; j++)
3294
+ { updateWidgetHeight(cur.rest[j]); } }
3295
+ }
3296
+ if (width > cm.display.sizerWidth) {
3297
+ var chWidth = Math.ceil(width / charWidth(cm.display));
3298
+ if (chWidth > cm.display.maxLineLength) {
3299
+ cm.display.maxLineLength = chWidth;
3300
+ cm.display.maxLine = cur.line;
3301
+ cm.display.maxLineChanged = true;
3302
+ }
3303
+ }
3304
+ }
3305
+ }
3306
+
3307
+ // Read and store the height of line widgets associated with the
3308
+ // given line.
3309
+ function updateWidgetHeight(line) {
3310
+ if (line.widgets) { for (var i = 0; i < line.widgets.length; ++i) {
3311
+ var w = line.widgets[i], parent = w.node.parentNode;
3312
+ if (parent) { w.height = parent.offsetHeight; }
3313
+ } }
3314
+ }
3315
+
3316
+ // Compute the lines that are visible in a given viewport (defaults
3317
+ // the the current scroll position). viewport may contain top,
3318
+ // height, and ensure (see op.scrollToPos) properties.
3319
+ function visibleLines(display, doc, viewport) {
3320
+ var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop;
3321
+ top = Math.floor(top - paddingTop(display));
3322
+ var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight;
3323
+
3324
+ var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom);
3325
+ // Ensure is a {from: {line, ch}, to: {line, ch}} object, and
3326
+ // forces those lines into the viewport (if possible).
3327
+ if (viewport && viewport.ensure) {
3328
+ var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line;
3329
+ if (ensureFrom < from) {
3330
+ from = ensureFrom;
3331
+ to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight);
3332
+ } else if (Math.min(ensureTo, doc.lastLine()) >= to) {
3333
+ from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight);
3334
+ to = ensureTo;
3335
+ }
3336
+ }
3337
+ return {from: from, to: Math.max(to, from + 1)}
3338
+ }
3339
+
3340
+ // Re-align line numbers and gutter marks to compensate for
3341
+ // horizontal scrolling.
3342
+ function alignHorizontally(cm) {
3343
+ var display = cm.display, view = display.view;
3344
+ if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) { return }
3345
+ var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft;
3346
+ var gutterW = display.gutters.offsetWidth, left = comp + "px";
3347
+ for (var i = 0; i < view.length; i++) { if (!view[i].hidden) {
3348
+ if (cm.options.fixedGutter) {
3349
+ if (view[i].gutter)
3350
+ { view[i].gutter.style.left = left; }
3351
+ if (view[i].gutterBackground)
3352
+ { view[i].gutterBackground.style.left = left; }
3353
+ }
3354
+ var align = view[i].alignable;
3355
+ if (align) { for (var j = 0; j < align.length; j++)
3356
+ { align[j].style.left = left; } }
3357
+ } }
3358
+ if (cm.options.fixedGutter)
3359
+ { display.gutters.style.left = (comp + gutterW) + "px"; }
3360
+ }
3361
+
3362
+ // Used to ensure that the line number gutter is still the right
3363
+ // size for the current document size. Returns true when an update
3364
+ // is needed.
3365
+ function maybeUpdateLineNumberWidth(cm) {
3366
+ if (!cm.options.lineNumbers) { return false }
3367
+ var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display;
3368
+ if (last.length != display.lineNumChars) {
3369
+ var test = display.measure.appendChild(elt("div", [elt("div", last)],
3370
+ "CodeMirror-linenumber CodeMirror-gutter-elt"));
3371
+ var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
3372
+ display.lineGutter.style.width = "";
3373
+ display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding) + 1;
3374
+ display.lineNumWidth = display.lineNumInnerWidth + padding;
3375
+ display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
3376
+ display.lineGutter.style.width = display.lineNumWidth + "px";
3377
+ updateGutterSpace(cm);
3378
+ return true
3379
+ }
3380
+ return false
3381
+ }
3382
+
3383
+ // SCROLLING THINGS INTO VIEW
3384
+
3385
+ // If an editor sits on the top or bottom of the window, partially
3386
+ // scrolled out of view, this ensures that the cursor is visible.
3387
+ function maybeScrollWindow(cm, rect) {
3388
+ if (signalDOMEvent(cm, "scrollCursorIntoView")) { return }
3389
+
3390
+ var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null;
3391
+ if (rect.top + box.top < 0) { doScroll = true; }
3392
+ else if (rect.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) { doScroll = false; }
3393
+ if (doScroll != null && !phantom) {
3394
+ var scrollNode = elt("div", "\u200b", null, ("position: absolute;\n top: " + (rect.top - display.viewOffset - paddingTop(cm.display)) + "px;\n height: " + (rect.bottom - rect.top + scrollGap(cm) + display.barHeight) + "px;\n left: " + (rect.left) + "px; width: " + (Math.max(2, rect.right - rect.left)) + "px;"));
3395
+ cm.display.lineSpace.appendChild(scrollNode);
3396
+ scrollNode.scrollIntoView(doScroll);
3397
+ cm.display.lineSpace.removeChild(scrollNode);
3398
+ }
3399
+ }
3400
+
3401
+ // Scroll a given position into view (immediately), verifying that
3402
+ // it actually became visible (as line heights are accurately
3403
+ // measured, the position of something may 'drift' during drawing).
3404
+ function scrollPosIntoView(cm, pos, end, margin) {
3405
+ if (margin == null) { margin = 0; }
3406
+ var rect;
3407
+ if (!cm.options.lineWrapping && pos == end) {
3408
+ // Set pos and end to the cursor positions around the character pos sticks to
3409
+ // If pos.sticky == "before", that is around pos.ch - 1, otherwise around pos.ch
3410
+ // If pos == Pos(_, 0, "before"), pos and end are unchanged
3411
+ pos = pos.ch ? Pos(pos.line, pos.sticky == "before" ? pos.ch - 1 : pos.ch, "after") : pos;
3412
+ end = pos.sticky == "before" ? Pos(pos.line, pos.ch + 1, "before") : pos;
3413
+ }
3414
+ for (var limit = 0; limit < 5; limit++) {
3415
+ var changed = false;
3416
+ var coords = cursorCoords(cm, pos);
3417
+ var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
3418
+ rect = {left: Math.min(coords.left, endCoords.left),
3419
+ top: Math.min(coords.top, endCoords.top) - margin,
3420
+ right: Math.max(coords.left, endCoords.left),
3421
+ bottom: Math.max(coords.bottom, endCoords.bottom) + margin};
3422
+ var scrollPos = calculateScrollPos(cm, rect);
3423
+ var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft;
3424
+ if (scrollPos.scrollTop != null) {
3425
+ updateScrollTop(cm, scrollPos.scrollTop);
3426
+ if (Math.abs(cm.doc.scrollTop - startTop) > 1) { changed = true; }
3427
+ }
3428
+ if (scrollPos.scrollLeft != null) {
3429
+ setScrollLeft(cm, scrollPos.scrollLeft);
3430
+ if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) { changed = true; }
3431
+ }
3432
+ if (!changed) { break }
3433
+ }
3434
+ return rect
3435
+ }
3436
+
3437
+ // Scroll a given set of coordinates into view (immediately).
3438
+ function scrollIntoView(cm, rect) {
3439
+ var scrollPos = calculateScrollPos(cm, rect);
3440
+ if (scrollPos.scrollTop != null) { updateScrollTop(cm, scrollPos.scrollTop); }
3441
+ if (scrollPos.scrollLeft != null) { setScrollLeft(cm, scrollPos.scrollLeft); }
3442
+ }
3443
+
3444
+ // Calculate a new scroll position needed to scroll the given
3445
+ // rectangle into view. Returns an object with scrollTop and
3446
+ // scrollLeft properties. When these are undefined, the
3447
+ // vertical/horizontal position does not need to be adjusted.
3448
+ function calculateScrollPos(cm, rect) {
3449
+ var display = cm.display, snapMargin = textHeight(cm.display);
3450
+ if (rect.top < 0) { rect.top = 0; }
3451
+ var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop;
3452
+ var screen = displayHeight(cm), result = {};
3453
+ if (rect.bottom - rect.top > screen) { rect.bottom = rect.top + screen; }
3454
+ var docBottom = cm.doc.height + paddingVert(display);
3455
+ var atTop = rect.top < snapMargin, atBottom = rect.bottom > docBottom - snapMargin;
3456
+ if (rect.top < screentop) {
3457
+ result.scrollTop = atTop ? 0 : rect.top;
3458
+ } else if (rect.bottom > screentop + screen) {
3459
+ var newTop = Math.min(rect.top, (atBottom ? docBottom : rect.bottom) - screen);
3460
+ if (newTop != screentop) { result.scrollTop = newTop; }
3461
+ }
3462
+
3463
+ var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft;
3464
+ var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0);
3465
+ var tooWide = rect.right - rect.left > screenw;
3466
+ if (tooWide) { rect.right = rect.left + screenw; }
3467
+ if (rect.left < 10)
3468
+ { result.scrollLeft = 0; }
3469
+ else if (rect.left < screenleft)
3470
+ { result.scrollLeft = Math.max(0, rect.left - (tooWide ? 0 : 10)); }
3471
+ else if (rect.right > screenw + screenleft - 3)
3472
+ { result.scrollLeft = rect.right + (tooWide ? 0 : 10) - screenw; }
3473
+ return result
3474
+ }
3475
+
3476
+ // Store a relative adjustment to the scroll position in the current
3477
+ // operation (to be applied when the operation finishes).
3478
+ function addToScrollTop(cm, top) {
3479
+ if (top == null) { return }
3480
+ resolveScrollToPos(cm);
3481
+ cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top;
3482
+ }
3483
+
3484
+ // Make sure that at the end of the operation the current cursor is
3485
+ // shown.
3486
+ function ensureCursorVisible(cm) {
3487
+ resolveScrollToPos(cm);
3488
+ var cur = cm.getCursor();
3489
+ cm.curOp.scrollToPos = {from: cur, to: cur, margin: cm.options.cursorScrollMargin};
3490
+ }
3491
+
3492
+ function scrollToCoords(cm, x, y) {
3493
+ if (x != null || y != null) { resolveScrollToPos(cm); }
3494
+ if (x != null) { cm.curOp.scrollLeft = x; }
3495
+ if (y != null) { cm.curOp.scrollTop = y; }
3496
+ }
3497
+
3498
+ function scrollToRange(cm, range$$1) {
3499
+ resolveScrollToPos(cm);
3500
+ cm.curOp.scrollToPos = range$$1;
3501
+ }
3502
+
3503
+ // When an operation has its scrollToPos property set, and another
3504
+ // scroll action is applied before the end of the operation, this
3505
+ // 'simulates' scrolling that position into view in a cheap way, so
3506
+ // that the effect of intermediate scroll commands is not ignored.
3507
+ function resolveScrollToPos(cm) {
3508
+ var range$$1 = cm.curOp.scrollToPos;
3509
+ if (range$$1) {
3510
+ cm.curOp.scrollToPos = null;
3511
+ var from = estimateCoords(cm, range$$1.from), to = estimateCoords(cm, range$$1.to);
3512
+ scrollToCoordsRange(cm, from, to, range$$1.margin);
3513
+ }
3514
+ }
3515
+
3516
+ function scrollToCoordsRange(cm, from, to, margin) {
3517
+ var sPos = calculateScrollPos(cm, {
3518
+ left: Math.min(from.left, to.left),
3519
+ top: Math.min(from.top, to.top) - margin,
3520
+ right: Math.max(from.right, to.right),
3521
+ bottom: Math.max(from.bottom, to.bottom) + margin
3522
+ });
3523
+ scrollToCoords(cm, sPos.scrollLeft, sPos.scrollTop);
3524
+ }
3525
+
3526
+ // Sync the scrollable area and scrollbars, ensure the viewport
3527
+ // covers the visible area.
3528
+ function updateScrollTop(cm, val) {
3529
+ if (Math.abs(cm.doc.scrollTop - val) < 2) { return }
3530
+ if (!gecko) { updateDisplaySimple(cm, {top: val}); }
3531
+ setScrollTop(cm, val, true);
3532
+ if (gecko) { updateDisplaySimple(cm); }
3533
+ startWorker(cm, 100);
3534
+ }
3535
+
3536
+ function setScrollTop(cm, val, forceScroll) {
3537
+ val = Math.min(cm.display.scroller.scrollHeight - cm.display.scroller.clientHeight, val);
3538
+ if (cm.display.scroller.scrollTop == val && !forceScroll) { return }
3539
+ cm.doc.scrollTop = val;
3540
+ cm.display.scrollbars.setScrollTop(val);
3541
+ if (cm.display.scroller.scrollTop != val) { cm.display.scroller.scrollTop = val; }
3542
+ }
3543
+
3544
+ // Sync scroller and scrollbar, ensure the gutter elements are
3545
+ // aligned.
3546
+ function setScrollLeft(cm, val, isScroller, forceScroll) {
3547
+ val = Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth);
3548
+ if ((isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) && !forceScroll) { return }
3549
+ cm.doc.scrollLeft = val;
3550
+ alignHorizontally(cm);
3551
+ if (cm.display.scroller.scrollLeft != val) { cm.display.scroller.scrollLeft = val; }
3552
+ cm.display.scrollbars.setScrollLeft(val);
3553
+ }
3554
+
3555
+ // SCROLLBARS
3556
+
3557
+ // Prepare DOM reads needed to update the scrollbars. Done in one
3558
+ // shot to minimize update/measure roundtrips.
3559
+ function measureForScrollbars(cm) {
3560
+ var d = cm.display, gutterW = d.gutters.offsetWidth;
3561
+ var docH = Math.round(cm.doc.height + paddingVert(cm.display));
3562
+ return {
3563
+ clientHeight: d.scroller.clientHeight,
3564
+ viewHeight: d.wrapper.clientHeight,
3565
+ scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth,
3566
+ viewWidth: d.wrapper.clientWidth,
3567
+ barLeft: cm.options.fixedGutter ? gutterW : 0,
3568
+ docHeight: docH,
3569
+ scrollHeight: docH + scrollGap(cm) + d.barHeight,
3570
+ nativeBarWidth: d.nativeBarWidth,
3571
+ gutterWidth: gutterW
3572
+ }
3573
+ }
3574
+
3575
+ var NativeScrollbars = function(place, scroll, cm) {
3576
+ this.cm = cm;
3577
+ var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar");
3578
+ var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar");
3579
+ vert.tabIndex = horiz.tabIndex = -1;
3580
+ place(vert); place(horiz);
3581
+
3582
+ on(vert, "scroll", function () {
3583
+ if (vert.clientHeight) { scroll(vert.scrollTop, "vertical"); }
3584
+ });
3585
+ on(horiz, "scroll", function () {
3586
+ if (horiz.clientWidth) { scroll(horiz.scrollLeft, "horizontal"); }
3587
+ });
3588
+
3589
+ this.checkedZeroWidth = false;
3590
+ // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
3591
+ if (ie && ie_version < 8) { this.horiz.style.minHeight = this.vert.style.minWidth = "18px"; }
3592
+ };
3593
+
3594
+ NativeScrollbars.prototype.update = function (measure) {
3595
+ var needsH = measure.scrollWidth > measure.clientWidth + 1;
3596
+ var needsV = measure.scrollHeight > measure.clientHeight + 1;
3597
+ var sWidth = measure.nativeBarWidth;
3598
+
3599
+ if (needsV) {
3600
+ this.vert.style.display = "block";
3601
+ this.vert.style.bottom = needsH ? sWidth + "px" : "0";
3602
+ var totalHeight = measure.viewHeight - (needsH ? sWidth : 0);
3603
+ // A bug in IE8 can cause this value to be negative, so guard it.
3604
+ this.vert.firstChild.style.height =
3605
+ Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px";
3606
+ } else {
3607
+ this.vert.style.display = "";
3608
+ this.vert.firstChild.style.height = "0";
3609
+ }
3610
+
3611
+ if (needsH) {
3612
+ this.horiz.style.display = "block";
3613
+ this.horiz.style.right = needsV ? sWidth + "px" : "0";
3614
+ this.horiz.style.left = measure.barLeft + "px";
3615
+ var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0);
3616
+ this.horiz.firstChild.style.width =
3617
+ Math.max(0, measure.scrollWidth - measure.clientWidth + totalWidth) + "px";
3618
+ } else {
3619
+ this.horiz.style.display = "";
3620
+ this.horiz.firstChild.style.width = "0";
3621
+ }
3622
+
3623
+ if (!this.checkedZeroWidth && measure.clientHeight > 0) {
3624
+ if (sWidth == 0) { this.zeroWidthHack(); }
3625
+ this.checkedZeroWidth = true;
3626
+ }
3627
+
3628
+ return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0}
3629
+ };
3630
+
3631
+ NativeScrollbars.prototype.setScrollLeft = function (pos) {
3632
+ if (this.horiz.scrollLeft != pos) { this.horiz.scrollLeft = pos; }
3633
+ if (this.disableHoriz) { this.enableZeroWidthBar(this.horiz, this.disableHoriz, "horiz"); }
3634
+ };
3635
+
3636
+ NativeScrollbars.prototype.setScrollTop = function (pos) {
3637
+ if (this.vert.scrollTop != pos) { this.vert.scrollTop = pos; }
3638
+ if (this.disableVert) { this.enableZeroWidthBar(this.vert, this.disableVert, "vert"); }
3639
+ };
3640
+
3641
+ NativeScrollbars.prototype.zeroWidthHack = function () {
3642
+ var w = mac && !mac_geMountainLion ? "12px" : "18px";
3643
+ this.horiz.style.height = this.vert.style.width = w;
3644
+ this.horiz.style.pointerEvents = this.vert.style.pointerEvents = "none";
3645
+ this.disableHoriz = new Delayed;
3646
+ this.disableVert = new Delayed;
3647
+ };
3648
+
3649
+ NativeScrollbars.prototype.enableZeroWidthBar = function (bar, delay, type) {
3650
+ bar.style.pointerEvents = "auto";
3651
+ function maybeDisable() {
3652
+ // To find out whether the scrollbar is still visible, we
3653
+ // check whether the element under the pixel in the bottom
3654
+ // right corner of the scrollbar box is the scrollbar box
3655
+ // itself (when the bar is still visible) or its filler child
3656
+ // (when the bar is hidden). If it is still visible, we keep
3657
+ // it enabled, if it's hidden, we disable pointer events.
3658
+ var box = bar.getBoundingClientRect();
3659
+ var elt$$1 = type == "vert" ? document.elementFromPoint(box.right - 1, (box.top + box.bottom) / 2)
3660
+ : document.elementFromPoint((box.right + box.left) / 2, box.bottom - 1);
3661
+ if (elt$$1 != bar) { bar.style.pointerEvents = "none"; }
3662
+ else { delay.set(1000, maybeDisable); }
3663
+ }
3664
+ delay.set(1000, maybeDisable);
3665
+ };
3666
+
3667
+ NativeScrollbars.prototype.clear = function () {
3668
+ var parent = this.horiz.parentNode;
3669
+ parent.removeChild(this.horiz);
3670
+ parent.removeChild(this.vert);
3671
+ };
3672
+
3673
+ var NullScrollbars = function () {};
3674
+
3675
+ NullScrollbars.prototype.update = function () { return {bottom: 0, right: 0} };
3676
+ NullScrollbars.prototype.setScrollLeft = function () {};
3677
+ NullScrollbars.prototype.setScrollTop = function () {};
3678
+ NullScrollbars.prototype.clear = function () {};
3679
+
3680
+ function updateScrollbars(cm, measure) {
3681
+ if (!measure) { measure = measureForScrollbars(cm); }
3682
+ var startWidth = cm.display.barWidth, startHeight = cm.display.barHeight;
3683
+ updateScrollbarsInner(cm, measure);
3684
+ for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) {
3685
+ if (startWidth != cm.display.barWidth && cm.options.lineWrapping)
3686
+ { updateHeightsInViewport(cm); }
3687
+ updateScrollbarsInner(cm, measureForScrollbars(cm));
3688
+ startWidth = cm.display.barWidth; startHeight = cm.display.barHeight;
3689
+ }
3690
+ }
3691
+
3692
+ // Re-synchronize the fake scrollbars with the actual size of the
3693
+ // content.
3694
+ function updateScrollbarsInner(cm, measure) {
3695
+ var d = cm.display;
3696
+ var sizes = d.scrollbars.update(measure);
3697
+
3698
+ d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px";
3699
+ d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px";
3700
+ d.heightForcer.style.borderBottom = sizes.bottom + "px solid transparent";
3701
+
3702
+ if (sizes.right && sizes.bottom) {
3703
+ d.scrollbarFiller.style.display = "block";
3704
+ d.scrollbarFiller.style.height = sizes.bottom + "px";
3705
+ d.scrollbarFiller.style.width = sizes.right + "px";
3706
+ } else { d.scrollbarFiller.style.display = ""; }
3707
+ if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
3708
+ d.gutterFiller.style.display = "block";
3709
+ d.gutterFiller.style.height = sizes.bottom + "px";
3710
+ d.gutterFiller.style.width = measure.gutterWidth + "px";
3711
+ } else { d.gutterFiller.style.display = ""; }
3712
+ }
3713
+
3714
+ var scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars};
3715
+
3716
+ function initScrollbars(cm) {
3717
+ if (cm.display.scrollbars) {
3718
+ cm.display.scrollbars.clear();
3719
+ if (cm.display.scrollbars.addClass)
3720
+ { rmClass(cm.display.wrapper, cm.display.scrollbars.addClass); }
3721
+ }
3722
+
3723
+ cm.display.scrollbars = new scrollbarModel[cm.options.scrollbarStyle](function (node) {
3724
+ cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller);
3725
+ // Prevent clicks in the scrollbars from killing focus
3726
+ on(node, "mousedown", function () {
3727
+ if (cm.state.focused) { setTimeout(function () { return cm.display.input.focus(); }, 0); }
3728
+ });
3729
+ node.setAttribute("cm-not-content", "true");
3730
+ }, function (pos, axis) {
3731
+ if (axis == "horizontal") { setScrollLeft(cm, pos); }
3732
+ else { updateScrollTop(cm, pos); }
3733
+ }, cm);
3734
+ if (cm.display.scrollbars.addClass)
3735
+ { addClass(cm.display.wrapper, cm.display.scrollbars.addClass); }
3736
+ }
3737
+
3738
+ // Operations are used to wrap a series of changes to the editor
3739
+ // state in such a way that each change won't have to update the
3740
+ // cursor and display (which would be awkward, slow, and
3741
+ // error-prone). Instead, display updates are batched and then all
3742
+ // combined and executed at once.
3743
+
3744
+ var nextOpId = 0;
3745
+ // Start a new operation.
3746
+ function startOperation(cm) {
3747
+ cm.curOp = {
3748
+ cm: cm,
3749
+ viewChanged: false, // Flag that indicates that lines might need to be redrawn
3750
+ startHeight: cm.doc.height, // Used to detect need to update scrollbar
3751
+ forceUpdate: false, // Used to force a redraw
3752
+ updateInput: null, // Whether to reset the input textarea
3753
+ typing: false, // Whether this reset should be careful to leave existing text (for compositing)
3754
+ changeObjs: null, // Accumulated changes, for firing change events
3755
+ cursorActivityHandlers: null, // Set of handlers to fire cursorActivity on
3756
+ cursorActivityCalled: 0, // Tracks which cursorActivity handlers have been called already
3757
+ selectionChanged: false, // Whether the selection needs to be redrawn
3758
+ updateMaxLine: false, // Set when the widest line needs to be determined anew
3759
+ scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet
3760
+ scrollToPos: null, // Used to scroll to a specific position
3761
+ focus: false,
3762
+ id: ++nextOpId // Unique ID
3763
+ };
3764
+ pushOperation(cm.curOp);
3765
+ }
3766
+
3767
+ // Finish an operation, updating the display and signalling delayed events
3768
+ function endOperation(cm) {
3769
+ var op = cm.curOp;
3770
+ if (op) { finishOperation(op, function (group) {
3771
+ for (var i = 0; i < group.ops.length; i++)
3772
+ { group.ops[i].cm.curOp = null; }
3773
+ endOperations(group);
3774
+ }); }
3775
+ }
3776
+
3777
+ // The DOM updates done when an operation finishes are batched so
3778
+ // that the minimum number of relayouts are required.
3779
+ function endOperations(group) {
3780
+ var ops = group.ops;
3781
+ for (var i = 0; i < ops.length; i++) // Read DOM
3782
+ { endOperation_R1(ops[i]); }
3783
+ for (var i$1 = 0; i$1 < ops.length; i$1++) // Write DOM (maybe)
3784
+ { endOperation_W1(ops[i$1]); }
3785
+ for (var i$2 = 0; i$2 < ops.length; i$2++) // Read DOM
3786
+ { endOperation_R2(ops[i$2]); }
3787
+ for (var i$3 = 0; i$3 < ops.length; i$3++) // Write DOM (maybe)
3788
+ { endOperation_W2(ops[i$3]); }
3789
+ for (var i$4 = 0; i$4 < ops.length; i$4++) // Read DOM
3790
+ { endOperation_finish(ops[i$4]); }
3791
+ }
3792
+
3793
+ function endOperation_R1(op) {
3794
+ var cm = op.cm, display = cm.display;
3795
+ maybeClipScrollbars(cm);
3796
+ if (op.updateMaxLine) { findMaxLine(cm); }
3797
+
3798
+ op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null ||
3799
+ op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom ||
3800
+ op.scrollToPos.to.line >= display.viewTo) ||
3801
+ display.maxLineChanged && cm.options.lineWrapping;
3802
+ op.update = op.mustUpdate &&
3803
+ new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate);
3804
+ }
3805
+
3806
+ function endOperation_W1(op) {
3807
+ op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update);
3808
+ }
3809
+
3810
+ function endOperation_R2(op) {
3811
+ var cm = op.cm, display = cm.display;
3812
+ if (op.updatedDisplay) { updateHeightsInViewport(cm); }
3813
+
3814
+ op.barMeasure = measureForScrollbars(cm);
3815
+
3816
+ // If the max line changed since it was last measured, measure it,
3817
+ // and ensure the document's width matches it.
3818
+ // updateDisplay_W2 will use these properties to do the actual resizing
3819
+ if (display.maxLineChanged && !cm.options.lineWrapping) {
3820
+ op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3;
3821
+ cm.display.sizerWidth = op.adjustWidthTo;
3822
+ op.barMeasure.scrollWidth =
3823
+ Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth);
3824
+ op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm));
3825
+ }
3826
+
3827
+ if (op.updatedDisplay || op.selectionChanged)
3828
+ { op.preparedSelection = display.input.prepareSelection(); }
3829
+ }
3830
+
3831
+ function endOperation_W2(op) {
3832
+ var cm = op.cm;
3833
+
3834
+ if (op.adjustWidthTo != null) {
3835
+ cm.display.sizer.style.minWidth = op.adjustWidthTo + "px";
3836
+ if (op.maxScrollLeft < cm.doc.scrollLeft)
3837
+ { setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true); }
3838
+ cm.display.maxLineChanged = false;
3839
+ }
3840
+
3841
+ var takeFocus = op.focus && op.focus == activeElt();
3842
+ if (op.preparedSelection)
3843
+ { cm.display.input.showSelection(op.preparedSelection, takeFocus); }
3844
+ if (op.updatedDisplay || op.startHeight != cm.doc.height)
3845
+ { updateScrollbars(cm, op.barMeasure); }
3846
+ if (op.updatedDisplay)
3847
+ { setDocumentHeight(cm, op.barMeasure); }
3848
+
3849
+ if (op.selectionChanged) { restartBlink(cm); }
3850
+
3851
+ if (cm.state.focused && op.updateInput)
3852
+ { cm.display.input.reset(op.typing); }
3853
+ if (takeFocus) { ensureFocus(op.cm); }
3854
+ }
3855
+
3856
+ function endOperation_finish(op) {
3857
+ var cm = op.cm, display = cm.display, doc = cm.doc;
3858
+
3859
+ if (op.updatedDisplay) { postUpdateDisplay(cm, op.update); }
3860
+
3861
+ // Abort mouse wheel delta measurement, when scrolling explicitly
3862
+ if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos))
3863
+ { display.wheelStartX = display.wheelStartY = null; }
3864
+
3865
+ // Propagate the scroll position to the actual DOM scroller
3866
+ if (op.scrollTop != null) { setScrollTop(cm, op.scrollTop, op.forceScroll); }
3867
+
3868
+ if (op.scrollLeft != null) { setScrollLeft(cm, op.scrollLeft, true, true); }
3869
+ // If we need to scroll a specific position into view, do so.
3870
+ if (op.scrollToPos) {
3871
+ var rect = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
3872
+ clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin);
3873
+ maybeScrollWindow(cm, rect);
3874
+ }
3875
+
3876
+ // Fire events for markers that are hidden/unidden by editing or
3877
+ // undoing
3878
+ var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers;
3879
+ if (hidden) { for (var i = 0; i < hidden.length; ++i)
3880
+ { if (!hidden[i].lines.length) { signal(hidden[i], "hide"); } } }
3881
+ if (unhidden) { for (var i$1 = 0; i$1 < unhidden.length; ++i$1)
3882
+ { if (unhidden[i$1].lines.length) { signal(unhidden[i$1], "unhide"); } } }
3883
+
3884
+ if (display.wrapper.offsetHeight)
3885
+ { doc.scrollTop = cm.display.scroller.scrollTop; }
3886
+
3887
+ // Fire change events, and delayed event handlers
3888
+ if (op.changeObjs)
3889
+ { signal(cm, "changes", cm, op.changeObjs); }
3890
+ if (op.update)
3891
+ { op.update.finish(); }
3892
+ }
3893
+
3894
+ // Run the given function in an operation
3895
+ function runInOp(cm, f) {
3896
+ if (cm.curOp) { return f() }
3897
+ startOperation(cm);
3898
+ try { return f() }
3899
+ finally { endOperation(cm); }
3900
+ }
3901
+ // Wraps a function in an operation. Returns the wrapped function.
3902
+ function operation(cm, f) {
3903
+ return function() {
3904
+ if (cm.curOp) { return f.apply(cm, arguments) }
3905
+ startOperation(cm);
3906
+ try { return f.apply(cm, arguments) }
3907
+ finally { endOperation(cm); }
3908
+ }
3909
+ }
3910
+ // Used to add methods to editor and doc instances, wrapping them in
3911
+ // operations.
3912
+ function methodOp(f) {
3913
+ return function() {
3914
+ if (this.curOp) { return f.apply(this, arguments) }
3915
+ startOperation(this);
3916
+ try { return f.apply(this, arguments) }
3917
+ finally { endOperation(this); }
3918
+ }
3919
+ }
3920
+ function docMethodOp(f) {
3921
+ return function() {
3922
+ var cm = this.cm;
3923
+ if (!cm || cm.curOp) { return f.apply(this, arguments) }
3924
+ startOperation(cm);
3925
+ try { return f.apply(this, arguments) }
3926
+ finally { endOperation(cm); }
3927
+ }
3928
+ }
3929
+
3930
+ // Updates the display.view data structure for a given change to the
3931
+ // document. From and to are in pre-change coordinates. Lendiff is
3932
+ // the amount of lines added or subtracted by the change. This is
3933
+ // used for changes that span multiple lines, or change the way
3934
+ // lines are divided into visual lines. regLineChange (below)
3935
+ // registers single-line changes.
3936
+ function regChange(cm, from, to, lendiff) {
3937
+ if (from == null) { from = cm.doc.first; }
3938
+ if (to == null) { to = cm.doc.first + cm.doc.size; }
3939
+ if (!lendiff) { lendiff = 0; }
3940
+
3941
+ var display = cm.display;
3942
+ if (lendiff && to < display.viewTo &&
3943
+ (display.updateLineNumbers == null || display.updateLineNumbers > from))
3944
+ { display.updateLineNumbers = from; }
3945
+
3946
+ cm.curOp.viewChanged = true;
3947
+
3948
+ if (from >= display.viewTo) { // Change after
3949
+ if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo)
3950
+ { resetView(cm); }
3951
+ } else if (to <= display.viewFrom) { // Change before
3952
+ if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
3953
+ resetView(cm);
3954
+ } else {
3955
+ display.viewFrom += lendiff;
3956
+ display.viewTo += lendiff;
3957
+ }
3958
+ } else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap
3959
+ resetView(cm);
3960
+ } else if (from <= display.viewFrom) { // Top overlap
3961
+ var cut = viewCuttingPoint(cm, to, to + lendiff, 1);
3962
+ if (cut) {
3963
+ display.view = display.view.slice(cut.index);
3964
+ display.viewFrom = cut.lineN;
3965
+ display.viewTo += lendiff;
3966
+ } else {
3967
+ resetView(cm);
3968
+ }
3969
+ } else if (to >= display.viewTo) { // Bottom overlap
3970
+ var cut$1 = viewCuttingPoint(cm, from, from, -1);
3971
+ if (cut$1) {
3972
+ display.view = display.view.slice(0, cut$1.index);
3973
+ display.viewTo = cut$1.lineN;
3974
+ } else {
3975
+ resetView(cm);
3976
+ }
3977
+ } else { // Gap in the middle
3978
+ var cutTop = viewCuttingPoint(cm, from, from, -1);
3979
+ var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1);
3980
+ if (cutTop && cutBot) {
3981
+ display.view = display.view.slice(0, cutTop.index)
3982
+ .concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
3983
+ .concat(display.view.slice(cutBot.index));
3984
+ display.viewTo += lendiff;
3985
+ } else {
3986
+ resetView(cm);
3987
+ }
3988
+ }
3989
+
3990
+ var ext = display.externalMeasured;
3991
+ if (ext) {
3992
+ if (to < ext.lineN)
3993
+ { ext.lineN += lendiff; }
3994
+ else if (from < ext.lineN + ext.size)
3995
+ { display.externalMeasured = null; }
3996
+ }
3997
+ }
3998
+
3999
+ // Register a change to a single line. Type must be one of "text",
4000
+ // "gutter", "class", "widget"
4001
+ function regLineChange(cm, line, type) {
4002
+ cm.curOp.viewChanged = true;
4003
+ var display = cm.display, ext = cm.display.externalMeasured;
4004
+ if (ext && line >= ext.lineN && line < ext.lineN + ext.size)
4005
+ { display.externalMeasured = null; }
4006
+
4007
+ if (line < display.viewFrom || line >= display.viewTo) { return }
4008
+ var lineView = display.view[findViewIndex(cm, line)];
4009
+ if (lineView.node == null) { return }
4010
+ var arr = lineView.changes || (lineView.changes = []);
4011
+ if (indexOf(arr, type) == -1) { arr.push(type); }
4012
+ }
4013
+
4014
+ // Clear the view.
4015
+ function resetView(cm) {
4016
+ cm.display.viewFrom = cm.display.viewTo = cm.doc.first;
4017
+ cm.display.view = [];
4018
+ cm.display.viewOffset = 0;
4019
+ }
4020
+
4021
+ function viewCuttingPoint(cm, oldN, newN, dir) {
4022
+ var index = findViewIndex(cm, oldN), diff, view = cm.display.view;
4023
+ if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
4024
+ { return {index: index, lineN: newN} }
4025
+ var n = cm.display.viewFrom;
4026
+ for (var i = 0; i < index; i++)
4027
+ { n += view[i].size; }
4028
+ if (n != oldN) {
4029
+ if (dir > 0) {
4030
+ if (index == view.length - 1) { return null }
4031
+ diff = (n + view[index].size) - oldN;
4032
+ index++;
4033
+ } else {
4034
+ diff = n - oldN;
4035
+ }
4036
+ oldN += diff; newN += diff;
4037
+ }
4038
+ while (visualLineNo(cm.doc, newN) != newN) {
4039
+ if (index == (dir < 0 ? 0 : view.length - 1)) { return null }
4040
+ newN += dir * view[index - (dir < 0 ? 1 : 0)].size;
4041
+ index += dir;
4042
+ }
4043
+ return {index: index, lineN: newN}
4044
+ }
4045
+
4046
+ // Force the view to cover a given range, adding empty view element
4047
+ // or clipping off existing ones as needed.
4048
+ function adjustView(cm, from, to) {
4049
+ var display = cm.display, view = display.view;
4050
+ if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
4051
+ display.view = buildViewArray(cm, from, to);
4052
+ display.viewFrom = from;
4053
+ } else {
4054
+ if (display.viewFrom > from)
4055
+ { display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view); }
4056
+ else if (display.viewFrom < from)
4057
+ { display.view = display.view.slice(findViewIndex(cm, from)); }
4058
+ display.viewFrom = from;
4059
+ if (display.viewTo < to)
4060
+ { display.view = display.view.concat(buildViewArray(cm, display.viewTo, to)); }
4061
+ else if (display.viewTo > to)
4062
+ { display.view = display.view.slice(0, findViewIndex(cm, to)); }
4063
+ }
4064
+ display.viewTo = to;
4065
+ }
4066
+
4067
+ // Count the number of lines in the view whose DOM representation is
4068
+ // out of date (or nonexistent).
4069
+ function countDirtyView(cm) {
4070
+ var view = cm.display.view, dirty = 0;
4071
+ for (var i = 0; i < view.length; i++) {
4072
+ var lineView = view[i];
4073
+ if (!lineView.hidden && (!lineView.node || lineView.changes)) { ++dirty; }
4074
+ }
4075
+ return dirty
4076
+ }
4077
+
4078
+ // HIGHLIGHT WORKER
4079
+
4080
+ function startWorker(cm, time) {
4081
+ if (cm.doc.highlightFrontier < cm.display.viewTo)
4082
+ { cm.state.highlight.set(time, bind(highlightWorker, cm)); }
4083
+ }
4084
+
4085
+ function highlightWorker(cm) {
4086
+ var doc = cm.doc;
4087
+ if (doc.highlightFrontier >= cm.display.viewTo) { return }
4088
+ var end = +new Date + cm.options.workTime;
4089
+ var context = getContextBefore(cm, doc.highlightFrontier);
4090
+ var changedLines = [];
4091
+
4092
+ doc.iter(context.line, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function (line) {
4093
+ if (context.line >= cm.display.viewFrom) { // Visible
4094
+ var oldStyles = line.styles;
4095
+ var resetState = line.text.length > cm.options.maxHighlightLength ? copyState(doc.mode, context.state) : null;
4096
+ var highlighted = highlightLine(cm, line, context, true);
4097
+ if (resetState) { context.state = resetState; }
4098
+ line.styles = highlighted.styles;
4099
+ var oldCls = line.styleClasses, newCls = highlighted.classes;
4100
+ if (newCls) { line.styleClasses = newCls; }
4101
+ else if (oldCls) { line.styleClasses = null; }
4102
+ var ischange = !oldStyles || oldStyles.length != line.styles.length ||
4103
+ oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass);
4104
+ for (var i = 0; !ischange && i < oldStyles.length; ++i) { ischange = oldStyles[i] != line.styles[i]; }
4105
+ if (ischange) { changedLines.push(context.line); }
4106
+ line.stateAfter = context.save();
4107
+ context.nextLine();
4108
+ } else {
4109
+ if (line.text.length <= cm.options.maxHighlightLength)
4110
+ { processLine(cm, line.text, context); }
4111
+ line.stateAfter = context.line % 5 == 0 ? context.save() : null;
4112
+ context.nextLine();
4113
+ }
4114
+ if (+new Date > end) {
4115
+ startWorker(cm, cm.options.workDelay);
4116
+ return true
4117
+ }
4118
+ });
4119
+ doc.highlightFrontier = context.line;
4120
+ doc.modeFrontier = Math.max(doc.modeFrontier, context.line);
4121
+ if (changedLines.length) { runInOp(cm, function () {
4122
+ for (var i = 0; i < changedLines.length; i++)
4123
+ { regLineChange(cm, changedLines[i], "text"); }
4124
+ }); }
4125
+ }
4126
+
4127
+ // DISPLAY DRAWING
4128
+
4129
+ var DisplayUpdate = function(cm, viewport, force) {
4130
+ var display = cm.display;
4131
+
4132
+ this.viewport = viewport;
4133
+ // Store some values that we'll need later (but don't want to force a relayout for)
4134
+ this.visible = visibleLines(display, cm.doc, viewport);
4135
+ this.editorIsHidden = !display.wrapper.offsetWidth;
4136
+ this.wrapperHeight = display.wrapper.clientHeight;
4137
+ this.wrapperWidth = display.wrapper.clientWidth;
4138
+ this.oldDisplayWidth = displayWidth(cm);
4139
+ this.force = force;
4140
+ this.dims = getDimensions(cm);
4141
+ this.events = [];
4142
+ };
4143
+
4144
+ DisplayUpdate.prototype.signal = function (emitter, type) {
4145
+ if (hasHandler(emitter, type))
4146
+ { this.events.push(arguments); }
4147
+ };
4148
+ DisplayUpdate.prototype.finish = function () {
4149
+ var this$1 = this;
4150
+
4151
+ for (var i = 0; i < this.events.length; i++)
4152
+ { signal.apply(null, this$1.events[i]); }
4153
+ };
4154
+
4155
+ function maybeClipScrollbars(cm) {
4156
+ var display = cm.display;
4157
+ if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
4158
+ display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth;
4159
+ display.heightForcer.style.height = scrollGap(cm) + "px";
4160
+ display.sizer.style.marginBottom = -display.nativeBarWidth + "px";
4161
+ display.sizer.style.borderRightWidth = scrollGap(cm) + "px";
4162
+ display.scrollbarsClipped = true;
4163
+ }
4164
+ }
4165
+
4166
+ function selectionSnapshot(cm) {
4167
+ if (cm.hasFocus()) { return null }
4168
+ var active = activeElt();
4169
+ if (!active || !contains(cm.display.lineDiv, active)) { return null }
4170
+ var result = {activeElt: active};
4171
+ if (window.getSelection) {
4172
+ var sel = window.getSelection();
4173
+ if (sel.anchorNode && sel.extend && contains(cm.display.lineDiv, sel.anchorNode)) {
4174
+ result.anchorNode = sel.anchorNode;
4175
+ result.anchorOffset = sel.anchorOffset;
4176
+ result.focusNode = sel.focusNode;
4177
+ result.focusOffset = sel.focusOffset;
4178
+ }
4179
+ }
4180
+ return result
4181
+ }
4182
+
4183
+ function restoreSelection(snapshot) {
4184
+ if (!snapshot || !snapshot.activeElt || snapshot.activeElt == activeElt()) { return }
4185
+ snapshot.activeElt.focus();
4186
+ if (snapshot.anchorNode && contains(document.body, snapshot.anchorNode) && contains(document.body, snapshot.focusNode)) {
4187
+ var sel = window.getSelection(), range$$1 = document.createRange();
4188
+ range$$1.setEnd(snapshot.anchorNode, snapshot.anchorOffset);
4189
+ range$$1.collapse(false);
4190
+ sel.removeAllRanges();
4191
+ sel.addRange(range$$1);
4192
+ sel.extend(snapshot.focusNode, snapshot.focusOffset);
4193
+ }
4194
+ }
4195
+
4196
+ // Does the actual updating of the line display. Bails out
4197
+ // (returning false) when there is nothing to be done and forced is
4198
+ // false.
4199
+ function updateDisplayIfNeeded(cm, update) {
4200
+ var display = cm.display, doc = cm.doc;
4201
+
4202
+ if (update.editorIsHidden) {
4203
+ resetView(cm);
4204
+ return false
4205
+ }
4206
+
4207
+ // Bail out if the visible area is already rendered and nothing changed.
4208
+ if (!update.force &&
4209
+ update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
4210
+ (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
4211
+ display.renderedView == display.view && countDirtyView(cm) == 0)
4212
+ { return false }
4213
+
4214
+ if (maybeUpdateLineNumberWidth(cm)) {
4215
+ resetView(cm);
4216
+ update.dims = getDimensions(cm);
4217
+ }
4218
+
4219
+ // Compute a suitable new viewport (from & to)
4220
+ var end = doc.first + doc.size;
4221
+ var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first);
4222
+ var to = Math.min(end, update.visible.to + cm.options.viewportMargin);
4223
+ if (display.viewFrom < from && from - display.viewFrom < 20) { from = Math.max(doc.first, display.viewFrom); }
4224
+ if (display.viewTo > to && display.viewTo - to < 20) { to = Math.min(end, display.viewTo); }
4225
+ if (sawCollapsedSpans) {
4226
+ from = visualLineNo(cm.doc, from);
4227
+ to = visualLineEndNo(cm.doc, to);
4228
+ }
4229
+
4230
+ var different = from != display.viewFrom || to != display.viewTo ||
4231
+ display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth;
4232
+ adjustView(cm, from, to);
4233
+
4234
+ display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom));
4235
+ // Position the mover div to align with the current scroll position
4236
+ cm.display.mover.style.top = display.viewOffset + "px";
4237
+
4238
+ var toUpdate = countDirtyView(cm);
4239
+ if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
4240
+ (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
4241
+ { return false }
4242
+
4243
+ // For big changes, we hide the enclosing element during the
4244
+ // update, since that speeds up the operations on most browsers.
4245
+ var selSnapshot = selectionSnapshot(cm);
4246
+ if (toUpdate > 4) { display.lineDiv.style.display = "none"; }
4247
+ patchDisplay(cm, display.updateLineNumbers, update.dims);
4248
+ if (toUpdate > 4) { display.lineDiv.style.display = ""; }
4249
+ display.renderedView = display.view;
4250
+ // There might have been a widget with a focused element that got
4251
+ // hidden or updated, if so re-focus it.
4252
+ restoreSelection(selSnapshot);
4253
+
4254
+ // Prevent selection and cursors from interfering with the scroll
4255
+ // width and height.
4256
+ removeChildren(display.cursorDiv);
4257
+ removeChildren(display.selectionDiv);
4258
+ display.gutters.style.height = display.sizer.style.minHeight = 0;
4259
+
4260
+ if (different) {
4261
+ display.lastWrapHeight = update.wrapperHeight;
4262
+ display.lastWrapWidth = update.wrapperWidth;
4263
+ startWorker(cm, 400);
4264
+ }
4265
+
4266
+ display.updateLineNumbers = null;
4267
+
4268
+ return true
4269
+ }
4270
+
4271
+ function postUpdateDisplay(cm, update) {
4272
+ var viewport = update.viewport;
4273
+
4274
+ for (var first = true;; first = false) {
4275
+ if (!first || !cm.options.lineWrapping || update.oldDisplayWidth == displayWidth(cm)) {
4276
+ // Clip forced viewport to actual scrollable area.
4277
+ if (viewport && viewport.top != null)
4278
+ { viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)}; }
4279
+ // Updated line heights might result in the drawn area not
4280
+ // actually covering the viewport. Keep looping until it does.
4281
+ update.visible = visibleLines(cm.display, cm.doc, viewport);
4282
+ if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo)
4283
+ { break }
4284
+ }
4285
+ if (!updateDisplayIfNeeded(cm, update)) { break }
4286
+ updateHeightsInViewport(cm);
4287
+ var barMeasure = measureForScrollbars(cm);
4288
+ updateSelection(cm);
4289
+ updateScrollbars(cm, barMeasure);
4290
+ setDocumentHeight(cm, barMeasure);
4291
+ update.force = false;
4292
+ }
4293
+
4294
+ update.signal(cm, "update", cm);
4295
+ if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
4296
+ update.signal(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo);
4297
+ cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo;
4298
+ }
4299
+ }
4300
+
4301
+ function updateDisplaySimple(cm, viewport) {
4302
+ var update = new DisplayUpdate(cm, viewport);
4303
+ if (updateDisplayIfNeeded(cm, update)) {
4304
+ updateHeightsInViewport(cm);
4305
+ postUpdateDisplay(cm, update);
4306
+ var barMeasure = measureForScrollbars(cm);
4307
+ updateSelection(cm);
4308
+ updateScrollbars(cm, barMeasure);
4309
+ setDocumentHeight(cm, barMeasure);
4310
+ update.finish();
4311
+ }
4312
+ }
4313
+
4314
+ // Sync the actual display DOM structure with display.view, removing
4315
+ // nodes for lines that are no longer in view, and creating the ones
4316
+ // that are not there yet, and updating the ones that are out of
4317
+ // date.
4318
+ function patchDisplay(cm, updateNumbersFrom, dims) {
4319
+ var display = cm.display, lineNumbers = cm.options.lineNumbers;
4320
+ var container = display.lineDiv, cur = container.firstChild;
4321
+
4322
+ function rm(node) {
4323
+ var next = node.nextSibling;
4324
+ // Works around a throw-scroll bug in OS X Webkit
4325
+ if (webkit && mac && cm.display.currentWheelTarget == node)
4326
+ { node.style.display = "none"; }
4327
+ else
4328
+ { node.parentNode.removeChild(node); }
4329
+ return next
4330
+ }
4331
+
4332
+ var view = display.view, lineN = display.viewFrom;
4333
+ // Loop over the elements in the view, syncing cur (the DOM nodes
4334
+ // in display.lineDiv) with the view as we go.
4335
+ for (var i = 0; i < view.length; i++) {
4336
+ var lineView = view[i];
4337
+ if (lineView.hidden) ; else if (!lineView.node || lineView.node.parentNode != container) { // Not drawn yet
4338
+ var node = buildLineElement(cm, lineView, lineN, dims);
4339
+ container.insertBefore(node, cur);
4340
+ } else { // Already drawn
4341
+ while (cur != lineView.node) { cur = rm(cur); }
4342
+ var updateNumber = lineNumbers && updateNumbersFrom != null &&
4343
+ updateNumbersFrom <= lineN && lineView.lineNumber;
4344
+ if (lineView.changes) {
4345
+ if (indexOf(lineView.changes, "gutter") > -1) { updateNumber = false; }
4346
+ updateLineForChanges(cm, lineView, lineN, dims);
4347
+ }
4348
+ if (updateNumber) {
4349
+ removeChildren(lineView.lineNumber);
4350
+ lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)));
4351
+ }
4352
+ cur = lineView.node.nextSibling;
4353
+ }
4354
+ lineN += lineView.size;
4355
+ }
4356
+ while (cur) { cur = rm(cur); }
4357
+ }
4358
+
4359
+ function updateGutterSpace(cm) {
4360
+ var width = cm.display.gutters.offsetWidth;
4361
+ cm.display.sizer.style.marginLeft = width + "px";
4362
+ }
4363
+
4364
+ function setDocumentHeight(cm, measure) {
4365
+ cm.display.sizer.style.minHeight = measure.docHeight + "px";
4366
+ cm.display.heightForcer.style.top = measure.docHeight + "px";
4367
+ cm.display.gutters.style.height = (measure.docHeight + cm.display.barHeight + scrollGap(cm)) + "px";
4368
+ }
4369
+
4370
+ // Rebuild the gutter elements, ensure the margin to the left of the
4371
+ // code matches their width.
4372
+ function updateGutters(cm) {
4373
+ var gutters = cm.display.gutters, specs = cm.options.gutters;
4374
+ removeChildren(gutters);
4375
+ var i = 0;
4376
+ for (; i < specs.length; ++i) {
4377
+ var gutterClass = specs[i];
4378
+ var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass));
4379
+ if (gutterClass == "CodeMirror-linenumbers") {
4380
+ cm.display.lineGutter = gElt;
4381
+ gElt.style.width = (cm.display.lineNumWidth || 1) + "px";
4382
+ }
4383
+ }
4384
+ gutters.style.display = i ? "" : "none";
4385
+ updateGutterSpace(cm);
4386
+ }
4387
+
4388
+ // Make sure the gutters options contains the element
4389
+ // "CodeMirror-linenumbers" when the lineNumbers option is true.
4390
+ function setGuttersForLineNumbers(options) {
4391
+ var found = indexOf(options.gutters, "CodeMirror-linenumbers");
4392
+ if (found == -1 && options.lineNumbers) {
4393
+ options.gutters = options.gutters.concat(["CodeMirror-linenumbers"]);
4394
+ } else if (found > -1 && !options.lineNumbers) {
4395
+ options.gutters = options.gutters.slice(0);
4396
+ options.gutters.splice(found, 1);
4397
+ }
4398
+ }
4399
+
4400
+ // Since the delta values reported on mouse wheel events are
4401
+ // unstandardized between browsers and even browser versions, and
4402
+ // generally horribly unpredictable, this code starts by measuring
4403
+ // the scroll effect that the first few mouse wheel events have,
4404
+ // and, from that, detects the way it can convert deltas to pixel
4405
+ // offsets afterwards.
4406
+ //
4407
+ // The reason we want to know the amount a wheel event will scroll
4408
+ // is that it gives us a chance to update the display before the
4409
+ // actual scrolling happens, reducing flickering.
4410
+
4411
+ var wheelSamples = 0, wheelPixelsPerUnit = null;
4412
+ // Fill in a browser-detected starting value on browsers where we
4413
+ // know one. These don't have to be accurate -- the result of them
4414
+ // being wrong would just be a slight flicker on the first wheel
4415
+ // scroll (if it is large enough).
4416
+ if (ie) { wheelPixelsPerUnit = -.53; }
4417
+ else if (gecko) { wheelPixelsPerUnit = 15; }
4418
+ else if (chrome) { wheelPixelsPerUnit = -.7; }
4419
+ else if (safari) { wheelPixelsPerUnit = -1/3; }
4420
+
4421
+ function wheelEventDelta(e) {
4422
+ var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
4423
+ if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) { dx = e.detail; }
4424
+ if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) { dy = e.detail; }
4425
+ else if (dy == null) { dy = e.wheelDelta; }
4426
+ return {x: dx, y: dy}
4427
+ }
4428
+ function wheelEventPixels(e) {
4429
+ var delta = wheelEventDelta(e);
4430
+ delta.x *= wheelPixelsPerUnit;
4431
+ delta.y *= wheelPixelsPerUnit;
4432
+ return delta
4433
+ }
4434
+
4435
+ function onScrollWheel(cm, e) {
4436
+ var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y;
4437
+
4438
+ var display = cm.display, scroll = display.scroller;
4439
+ // Quit if there's nothing to scroll here
4440
+ var canScrollX = scroll.scrollWidth > scroll.clientWidth;
4441
+ var canScrollY = scroll.scrollHeight > scroll.clientHeight;
4442
+ if (!(dx && canScrollX || dy && canScrollY)) { return }
4443
+
4444
+ // Webkit browsers on OS X abort momentum scrolls when the target
4445
+ // of the scroll event is removed from the scrollable element.
4446
+ // This hack (see related code in patchDisplay) makes sure the
4447
+ // element is kept around.
4448
+ if (dy && mac && webkit) {
4449
+ outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
4450
+ for (var i = 0; i < view.length; i++) {
4451
+ if (view[i].node == cur) {
4452
+ cm.display.currentWheelTarget = cur;
4453
+ break outer
4454
+ }
4455
+ }
4456
+ }
4457
+ }
4458
+
4459
+ // On some browsers, horizontal scrolling will cause redraws to
4460
+ // happen before the gutter has been realigned, causing it to
4461
+ // wriggle around in a most unseemly way. When we have an
4462
+ // estimated pixels/delta value, we just handle horizontal
4463
+ // scrolling entirely here. It'll be slightly off from native, but
4464
+ // better than glitching out.
4465
+ if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
4466
+ if (dy && canScrollY)
4467
+ { updateScrollTop(cm, Math.max(0, scroll.scrollTop + dy * wheelPixelsPerUnit)); }
4468
+ setScrollLeft(cm, Math.max(0, scroll.scrollLeft + dx * wheelPixelsPerUnit));
4469
+ // Only prevent default scrolling if vertical scrolling is
4470
+ // actually possible. Otherwise, it causes vertical scroll
4471
+ // jitter on OSX trackpads when deltaX is small and deltaY
4472
+ // is large (issue #3579)
4473
+ if (!dy || (dy && canScrollY))
4474
+ { e_preventDefault(e); }
4475
+ display.wheelStartX = null; // Abort measurement, if in progress
4476
+ return
4477
+ }
4478
+
4479
+ // 'Project' the visible viewport to cover the area that is being
4480
+ // scrolled into view (if we know enough to estimate it).
4481
+ if (dy && wheelPixelsPerUnit != null) {
4482
+ var pixels = dy * wheelPixelsPerUnit;
4483
+ var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight;
4484
+ if (pixels < 0) { top = Math.max(0, top + pixels - 50); }
4485
+ else { bot = Math.min(cm.doc.height, bot + pixels + 50); }
4486
+ updateDisplaySimple(cm, {top: top, bottom: bot});
4487
+ }
4488
+
4489
+ if (wheelSamples < 20) {
4490
+ if (display.wheelStartX == null) {
4491
+ display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop;
4492
+ display.wheelDX = dx; display.wheelDY = dy;
4493
+ setTimeout(function () {
4494
+ if (display.wheelStartX == null) { return }
4495
+ var movedX = scroll.scrollLeft - display.wheelStartX;
4496
+ var movedY = scroll.scrollTop - display.wheelStartY;
4497
+ var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
4498
+ (movedX && display.wheelDX && movedX / display.wheelDX);
4499
+ display.wheelStartX = display.wheelStartY = null;
4500
+ if (!sample) { return }
4501
+ wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
4502
+ ++wheelSamples;
4503
+ }, 200);
4504
+ } else {
4505
+ display.wheelDX += dx; display.wheelDY += dy;
4506
+ }
4507
+ }
4508
+ }
4509
+
4510
+ // Selection objects are immutable. A new one is created every time
4511
+ // the selection changes. A selection is one or more non-overlapping
4512
+ // (and non-touching) ranges, sorted, and an integer that indicates
4513
+ // which one is the primary selection (the one that's scrolled into
4514
+ // view, that getCursor returns, etc).
4515
+ var Selection = function(ranges, primIndex) {
4516
+ this.ranges = ranges;
4517
+ this.primIndex = primIndex;
4518
+ };
4519
+
4520
+ Selection.prototype.primary = function () { return this.ranges[this.primIndex] };
4521
+
4522
+ Selection.prototype.equals = function (other) {
4523
+ var this$1 = this;
4524
+
4525
+ if (other == this) { return true }
4526
+ if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) { return false }
4527
+ for (var i = 0; i < this.ranges.length; i++) {
4528
+ var here = this$1.ranges[i], there = other.ranges[i];
4529
+ if (!equalCursorPos(here.anchor, there.anchor) || !equalCursorPos(here.head, there.head)) { return false }
4530
+ }
4531
+ return true
4532
+ };
4533
+
4534
+ Selection.prototype.deepCopy = function () {
4535
+ var this$1 = this;
4536
+
4537
+ var out = [];
4538
+ for (var i = 0; i < this.ranges.length; i++)
4539
+ { out[i] = new Range(copyPos(this$1.ranges[i].anchor), copyPos(this$1.ranges[i].head)); }
4540
+ return new Selection(out, this.primIndex)
4541
+ };
4542
+
4543
+ Selection.prototype.somethingSelected = function () {
4544
+ var this$1 = this;
4545
+
4546
+ for (var i = 0; i < this.ranges.length; i++)
4547
+ { if (!this$1.ranges[i].empty()) { return true } }
4548
+ return false
4549
+ };
4550
+
4551
+ Selection.prototype.contains = function (pos, end) {
4552
+ var this$1 = this;
4553
+
4554
+ if (!end) { end = pos; }
4555
+ for (var i = 0; i < this.ranges.length; i++) {
4556
+ var range = this$1.ranges[i];
4557
+ if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0)
4558
+ { return i }
4559
+ }
4560
+ return -1
4561
+ };
4562
+
4563
+ var Range = function(anchor, head) {
4564
+ this.anchor = anchor; this.head = head;
4565
+ };
4566
+
4567
+ Range.prototype.from = function () { return minPos(this.anchor, this.head) };
4568
+ Range.prototype.to = function () { return maxPos(this.anchor, this.head) };
4569
+ Range.prototype.empty = function () { return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch };
4570
+
4571
+ // Take an unsorted, potentially overlapping set of ranges, and
4572
+ // build a selection out of it. 'Consumes' ranges array (modifying
4573
+ // it).
4574
+ function normalizeSelection(cm, ranges, primIndex) {
4575
+ var mayTouch = cm && cm.options.selectionsMayTouch;
4576
+ var prim = ranges[primIndex];
4577
+ ranges.sort(function (a, b) { return cmp(a.from(), b.from()); });
4578
+ primIndex = indexOf(ranges, prim);
4579
+ for (var i = 1; i < ranges.length; i++) {
4580
+ var cur = ranges[i], prev = ranges[i - 1];
4581
+ var diff = cmp(prev.to(), cur.from());
4582
+ if (mayTouch && !cur.empty() ? diff > 0 : diff >= 0) {
4583
+ var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to());
4584
+ var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head;
4585
+ if (i <= primIndex) { --primIndex; }
4586
+ ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to));
4587
+ }
4588
+ }
4589
+ return new Selection(ranges, primIndex)
4590
+ }
4591
+
4592
+ function simpleSelection(anchor, head) {
4593
+ return new Selection([new Range(anchor, head || anchor)], 0)
4594
+ }
4595
+
4596
+ // Compute the position of the end of a change (its 'to' property
4597
+ // refers to the pre-change end).
4598
+ function changeEnd(change) {
4599
+ if (!change.text) { return change.to }
4600
+ return Pos(change.from.line + change.text.length - 1,
4601
+ lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0))
4602
+ }
4603
+
4604
+ // Adjust a position to refer to the post-change position of the
4605
+ // same text, or the end of the change if the change covers it.
4606
+ function adjustForChange(pos, change) {
4607
+ if (cmp(pos, change.from) < 0) { return pos }
4608
+ if (cmp(pos, change.to) <= 0) { return changeEnd(change) }
4609
+
4610
+ var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch;
4611
+ if (pos.line == change.to.line) { ch += changeEnd(change).ch - change.to.ch; }
4612
+ return Pos(line, ch)
4613
+ }
4614
+
4615
+ function computeSelAfterChange(doc, change) {
4616
+ var out = [];
4617
+ for (var i = 0; i < doc.sel.ranges.length; i++) {
4618
+ var range = doc.sel.ranges[i];
4619
+ out.push(new Range(adjustForChange(range.anchor, change),
4620
+ adjustForChange(range.head, change)));
4621
+ }
4622
+ return normalizeSelection(doc.cm, out, doc.sel.primIndex)
4623
+ }
4624
+
4625
+ function offsetPos(pos, old, nw) {
4626
+ if (pos.line == old.line)
4627
+ { return Pos(nw.line, pos.ch - old.ch + nw.ch) }
4628
+ else
4629
+ { return Pos(nw.line + (pos.line - old.line), pos.ch) }
4630
+ }
4631
+
4632
+ // Used by replaceSelections to allow moving the selection to the
4633
+ // start or around the replaced test. Hint may be "start" or "around".
4634
+ function computeReplacedSel(doc, changes, hint) {
4635
+ var out = [];
4636
+ var oldPrev = Pos(doc.first, 0), newPrev = oldPrev;
4637
+ for (var i = 0; i < changes.length; i++) {
4638
+ var change = changes[i];
4639
+ var from = offsetPos(change.from, oldPrev, newPrev);
4640
+ var to = offsetPos(changeEnd(change), oldPrev, newPrev);
4641
+ oldPrev = change.to;
4642
+ newPrev = to;
4643
+ if (hint == "around") {
4644
+ var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0;
4645
+ out[i] = new Range(inv ? to : from, inv ? from : to);
4646
+ } else {
4647
+ out[i] = new Range(from, from);
4648
+ }
4649
+ }
4650
+ return new Selection(out, doc.sel.primIndex)
4651
+ }
4652
+
4653
+ // Used to get the editor into a consistent state again when options change.
4654
+
4655
+ function loadMode(cm) {
4656
+ cm.doc.mode = getMode(cm.options, cm.doc.modeOption);
4657
+ resetModeState(cm);
4658
+ }
4659
+
4660
+ function resetModeState(cm) {
4661
+ cm.doc.iter(function (line) {
4662
+ if (line.stateAfter) { line.stateAfter = null; }
4663
+ if (line.styles) { line.styles = null; }
4664
+ });
4665
+ cm.doc.modeFrontier = cm.doc.highlightFrontier = cm.doc.first;
4666
+ startWorker(cm, 100);
4667
+ cm.state.modeGen++;
4668
+ if (cm.curOp) { regChange(cm); }
4669
+ }
4670
+
4671
+ // DOCUMENT DATA STRUCTURE
4672
+
4673
+ // By default, updates that start and end at the beginning of a line
4674
+ // are treated specially, in order to make the association of line
4675
+ // widgets and marker elements with the text behave more intuitive.
4676
+ function isWholeLineUpdate(doc, change) {
4677
+ return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" &&
4678
+ (!doc.cm || doc.cm.options.wholeLineUpdateBefore)
4679
+ }
4680
+
4681
+ // Perform a change on the document data structure.
4682
+ function updateDoc(doc, change, markedSpans, estimateHeight$$1) {
4683
+ function spansFor(n) {return markedSpans ? markedSpans[n] : null}
4684
+ function update(line, text, spans) {
4685
+ updateLine(line, text, spans, estimateHeight$$1);
4686
+ signalLater(line, "change", line, change);
4687
+ }
4688
+ function linesFor(start, end) {
4689
+ var result = [];
4690
+ for (var i = start; i < end; ++i)
4691
+ { result.push(new Line(text[i], spansFor(i), estimateHeight$$1)); }
4692
+ return result
4693
+ }
4694
+
4695
+ var from = change.from, to = change.to, text = change.text;
4696
+ var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line);
4697
+ var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line;
4698
+
4699
+ // Adjust the line structure
4700
+ if (change.full) {
4701
+ doc.insert(0, linesFor(0, text.length));
4702
+ doc.remove(text.length, doc.size - text.length);
4703
+ } else if (isWholeLineUpdate(doc, change)) {
4704
+ // This is a whole-line replace. Treated specially to make
4705
+ // sure line objects move the way they are supposed to.
4706
+ var added = linesFor(0, text.length - 1);
4707
+ update(lastLine, lastLine.text, lastSpans);
4708
+ if (nlines) { doc.remove(from.line, nlines); }
4709
+ if (added.length) { doc.insert(from.line, added); }
4710
+ } else if (firstLine == lastLine) {
4711
+ if (text.length == 1) {
4712
+ update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans);
4713
+ } else {
4714
+ var added$1 = linesFor(1, text.length - 1);
4715
+ added$1.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight$$1));
4716
+ update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
4717
+ doc.insert(from.line + 1, added$1);
4718
+ }
4719
+ } else if (text.length == 1) {
4720
+ update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0));
4721
+ doc.remove(from.line + 1, nlines);
4722
+ } else {
4723
+ update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
4724
+ update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans);
4725
+ var added$2 = linesFor(1, text.length - 1);
4726
+ if (nlines > 1) { doc.remove(from.line + 1, nlines - 1); }
4727
+ doc.insert(from.line + 1, added$2);
4728
+ }
4729
+
4730
+ signalLater(doc, "change", doc, change);
4731
+ }
4732
+
4733
+ // Call f for all linked documents.
4734
+ function linkedDocs(doc, f, sharedHistOnly) {
4735
+ function propagate(doc, skip, sharedHist) {
4736
+ if (doc.linked) { for (var i = 0; i < doc.linked.length; ++i) {
4737
+ var rel = doc.linked[i];
4738
+ if (rel.doc == skip) { continue }
4739
+ var shared = sharedHist && rel.sharedHist;
4740
+ if (sharedHistOnly && !shared) { continue }
4741
+ f(rel.doc, shared);
4742
+ propagate(rel.doc, doc, shared);
4743
+ } }
4744
+ }
4745
+ propagate(doc, null, true);
4746
+ }
4747
+
4748
+ // Attach a document to an editor.
4749
+ function attachDoc(cm, doc) {
4750
+ if (doc.cm) { throw new Error("This document is already in use.") }
4751
+ cm.doc = doc;
4752
+ doc.cm = cm;
4753
+ estimateLineHeights(cm);
4754
+ loadMode(cm);
4755
+ setDirectionClass(cm);
4756
+ if (!cm.options.lineWrapping) { findMaxLine(cm); }
4757
+ cm.options.mode = doc.modeOption;
4758
+ regChange(cm);
4759
+ }
4760
+
4761
+ function setDirectionClass(cm) {
4762
+ (cm.doc.direction == "rtl" ? addClass : rmClass)(cm.display.lineDiv, "CodeMirror-rtl");
4763
+ }
4764
+
4765
+ function directionChanged(cm) {
4766
+ runInOp(cm, function () {
4767
+ setDirectionClass(cm);
4768
+ regChange(cm);
4769
+ });
4770
+ }
4771
+
4772
+ function History(startGen) {
4773
+ // Arrays of change events and selections. Doing something adds an
4774
+ // event to done and clears undo. Undoing moves events from done
4775
+ // to undone, redoing moves them in the other direction.
4776
+ this.done = []; this.undone = [];
4777
+ this.undoDepth = Infinity;
4778
+ // Used to track when changes can be merged into a single undo
4779
+ // event
4780
+ this.lastModTime = this.lastSelTime = 0;
4781
+ this.lastOp = this.lastSelOp = null;
4782
+ this.lastOrigin = this.lastSelOrigin = null;
4783
+ // Used by the isClean() method
4784
+ this.generation = this.maxGeneration = startGen || 1;
4785
+ }
4786
+
4787
+ // Create a history change event from an updateDoc-style change
4788
+ // object.
4789
+ function historyChangeFromChange(doc, change) {
4790
+ var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)};
4791
+ attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);
4792
+ linkedDocs(doc, function (doc) { return attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1); }, true);
4793
+ return histChange
4794
+ }
4795
+
4796
+ // Pop all selection events off the end of a history array. Stop at
4797
+ // a change event.
4798
+ function clearSelectionEvents(array) {
4799
+ while (array.length) {
4800
+ var last = lst(array);
4801
+ if (last.ranges) { array.pop(); }
4802
+ else { break }
4803
+ }
4804
+ }
4805
+
4806
+ // Find the top change event in the history. Pop off selection
4807
+ // events that are in the way.
4808
+ function lastChangeEvent(hist, force) {
4809
+ if (force) {
4810
+ clearSelectionEvents(hist.done);
4811
+ return lst(hist.done)
4812
+ } else if (hist.done.length && !lst(hist.done).ranges) {
4813
+ return lst(hist.done)
4814
+ } else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
4815
+ hist.done.pop();
4816
+ return lst(hist.done)
4817
+ }
4818
+ }
4819
+
4820
+ // Register a change in the history. Merges changes that are within
4821
+ // a single operation, or are close together with an origin that
4822
+ // allows merging (starting with "+") into a single event.
4823
+ function addChangeToHistory(doc, change, selAfter, opId) {
4824
+ var hist = doc.history;
4825
+ hist.undone.length = 0;
4826
+ var time = +new Date, cur;
4827
+ var last;
4828
+
4829
+ if ((hist.lastOp == opId ||
4830
+ hist.lastOrigin == change.origin && change.origin &&
4831
+ ((change.origin.charAt(0) == "+" && hist.lastModTime > time - (doc.cm ? doc.cm.options.historyEventDelay : 500)) ||
4832
+ change.origin.charAt(0) == "*")) &&
4833
+ (cur = lastChangeEvent(hist, hist.lastOp == opId))) {
4834
+ // Merge this change into the last event
4835
+ last = lst(cur.changes);
4836
+ if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
4837
+ // Optimized case for simple insertion -- don't want to add
4838
+ // new changesets for every character typed
4839
+ last.to = changeEnd(change);
4840
+ } else {
4841
+ // Add new sub-event
4842
+ cur.changes.push(historyChangeFromChange(doc, change));
4843
+ }
4844
+ } else {
4845
+ // Can not be merged, start a new event.
4846
+ var before = lst(hist.done);
4847
+ if (!before || !before.ranges)
4848
+ { pushSelectionToHistory(doc.sel, hist.done); }
4849
+ cur = {changes: [historyChangeFromChange(doc, change)],
4850
+ generation: hist.generation};
4851
+ hist.done.push(cur);
4852
+ while (hist.done.length > hist.undoDepth) {
4853
+ hist.done.shift();
4854
+ if (!hist.done[0].ranges) { hist.done.shift(); }
4855
+ }
4856
+ }
4857
+ hist.done.push(selAfter);
4858
+ hist.generation = ++hist.maxGeneration;
4859
+ hist.lastModTime = hist.lastSelTime = time;
4860
+ hist.lastOp = hist.lastSelOp = opId;
4861
+ hist.lastOrigin = hist.lastSelOrigin = change.origin;
4862
+
4863
+ if (!last) { signal(doc, "historyAdded"); }
4864
+ }
4865
+
4866
+ function selectionEventCanBeMerged(doc, origin, prev, sel) {
4867
+ var ch = origin.charAt(0);
4868
+ return ch == "*" ||
4869
+ ch == "+" &&
4870
+ prev.ranges.length == sel.ranges.length &&
4871
+ prev.somethingSelected() == sel.somethingSelected() &&
4872
+ new Date - doc.history.lastSelTime <= (doc.cm ? doc.cm.options.historyEventDelay : 500)
4873
+ }
4874
+
4875
+ // Called whenever the selection changes, sets the new selection as
4876
+ // the pending selection in the history, and pushes the old pending
4877
+ // selection into the 'done' array when it was significantly
4878
+ // different (in number of selected ranges, emptiness, or time).
4879
+ function addSelectionToHistory(doc, sel, opId, options) {
4880
+ var hist = doc.history, origin = options && options.origin;
4881
+
4882
+ // A new event is started when the previous origin does not match
4883
+ // the current, or the origins don't allow matching. Origins
4884
+ // starting with * are always merged, those starting with + are
4885
+ // merged when similar and close together in time.
4886
+ if (opId == hist.lastSelOp ||
4887
+ (origin && hist.lastSelOrigin == origin &&
4888
+ (hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin ||
4889
+ selectionEventCanBeMerged(doc, origin, lst(hist.done), sel))))
4890
+ { hist.done[hist.done.length - 1] = sel; }
4891
+ else
4892
+ { pushSelectionToHistory(sel, hist.done); }
4893
+
4894
+ hist.lastSelTime = +new Date;
4895
+ hist.lastSelOrigin = origin;
4896
+ hist.lastSelOp = opId;
4897
+ if (options && options.clearRedo !== false)
4898
+ { clearSelectionEvents(hist.undone); }
4899
+ }
4900
+
4901
+ function pushSelectionToHistory(sel, dest) {
4902
+ var top = lst(dest);
4903
+ if (!(top && top.ranges && top.equals(sel)))
4904
+ { dest.push(sel); }
4905
+ }
4906
+
4907
+ // Used to store marked span information in the history.
4908
+ function attachLocalSpans(doc, change, from, to) {
4909
+ var existing = change["spans_" + doc.id], n = 0;
4910
+ doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function (line) {
4911
+ if (line.markedSpans)
4912
+ { (existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans; }
4913
+ ++n;
4914
+ });
4915
+ }
4916
+
4917
+ // When un/re-doing restores text containing marked spans, those
4918
+ // that have been explicitly cleared should not be restored.
4919
+ function removeClearedSpans(spans) {
4920
+ if (!spans) { return null }
4921
+ var out;
4922
+ for (var i = 0; i < spans.length; ++i) {
4923
+ if (spans[i].marker.explicitlyCleared) { if (!out) { out = spans.slice(0, i); } }
4924
+ else if (out) { out.push(spans[i]); }
4925
+ }
4926
+ return !out ? spans : out.length ? out : null
4927
+ }
4928
+
4929
+ // Retrieve and filter the old marked spans stored in a change event.
4930
+ function getOldSpans(doc, change) {
4931
+ var found = change["spans_" + doc.id];
4932
+ if (!found) { return null }
4933
+ var nw = [];
4934
+ for (var i = 0; i < change.text.length; ++i)
4935
+ { nw.push(removeClearedSpans(found[i])); }
4936
+ return nw
4937
+ }
4938
+
4939
+ // Used for un/re-doing changes from the history. Combines the
4940
+ // result of computing the existing spans with the set of spans that
4941
+ // existed in the history (so that deleting around a span and then
4942
+ // undoing brings back the span).
4943
+ function mergeOldSpans(doc, change) {
4944
+ var old = getOldSpans(doc, change);
4945
+ var stretched = stretchSpansOverChange(doc, change);
4946
+ if (!old) { return stretched }
4947
+ if (!stretched) { return old }
4948
+
4949
+ for (var i = 0; i < old.length; ++i) {
4950
+ var oldCur = old[i], stretchCur = stretched[i];
4951
+ if (oldCur && stretchCur) {
4952
+ spans: for (var j = 0; j < stretchCur.length; ++j) {
4953
+ var span = stretchCur[j];
4954
+ for (var k = 0; k < oldCur.length; ++k)
4955
+ { if (oldCur[k].marker == span.marker) { continue spans } }
4956
+ oldCur.push(span);
4957
+ }
4958
+ } else if (stretchCur) {
4959
+ old[i] = stretchCur;
4960
+ }
4961
+ }
4962
+ return old
4963
+ }
4964
+
4965
+ // Used both to provide a JSON-safe object in .getHistory, and, when
4966
+ // detaching a document, to split the history in two
4967
+ function copyHistoryArray(events, newGroup, instantiateSel) {
4968
+ var copy = [];
4969
+ for (var i = 0; i < events.length; ++i) {
4970
+ var event = events[i];
4971
+ if (event.ranges) {
4972
+ copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event);
4973
+ continue
4974
+ }
4975
+ var changes = event.changes, newChanges = [];
4976
+ copy.push({changes: newChanges});
4977
+ for (var j = 0; j < changes.length; ++j) {
4978
+ var change = changes[j], m = (void 0);
4979
+ newChanges.push({from: change.from, to: change.to, text: change.text});
4980
+ if (newGroup) { for (var prop in change) { if (m = prop.match(/^spans_(\d+)$/)) {
4981
+ if (indexOf(newGroup, Number(m[1])) > -1) {
4982
+ lst(newChanges)[prop] = change[prop];
4983
+ delete change[prop];
4984
+ }
4985
+ } } }
4986
+ }
4987
+ }
4988
+ return copy
4989
+ }
4990
+
4991
+ // The 'scroll' parameter given to many of these indicated whether
4992
+ // the new cursor position should be scrolled into view after
4993
+ // modifying the selection.
4994
+
4995
+ // If shift is held or the extend flag is set, extends a range to
4996
+ // include a given position (and optionally a second position).
4997
+ // Otherwise, simply returns the range between the given positions.
4998
+ // Used for cursor motion and such.
4999
+ function extendRange(range, head, other, extend) {
5000
+ if (extend) {
5001
+ var anchor = range.anchor;
5002
+ if (other) {
5003
+ var posBefore = cmp(head, anchor) < 0;
5004
+ if (posBefore != (cmp(other, anchor) < 0)) {
5005
+ anchor = head;
5006
+ head = other;
5007
+ } else if (posBefore != (cmp(head, other) < 0)) {
5008
+ head = other;
5009
+ }
5010
+ }
5011
+ return new Range(anchor, head)
5012
+ } else {
5013
+ return new Range(other || head, head)
5014
+ }
5015
+ }
5016
+
5017
+ // Extend the primary selection range, discard the rest.
5018
+ function extendSelection(doc, head, other, options, extend) {
5019
+ if (extend == null) { extend = doc.cm && (doc.cm.display.shift || doc.extend); }
5020
+ setSelection(doc, new Selection([extendRange(doc.sel.primary(), head, other, extend)], 0), options);
5021
+ }
5022
+
5023
+ // Extend all selections (pos is an array of selections with length
5024
+ // equal the number of selections)
5025
+ function extendSelections(doc, heads, options) {
5026
+ var out = [];
5027
+ var extend = doc.cm && (doc.cm.display.shift || doc.extend);
5028
+ for (var i = 0; i < doc.sel.ranges.length; i++)
5029
+ { out[i] = extendRange(doc.sel.ranges[i], heads[i], null, extend); }
5030
+ var newSel = normalizeSelection(doc.cm, out, doc.sel.primIndex);
5031
+ setSelection(doc, newSel, options);
5032
+ }
5033
+
5034
+ // Updates a single range in the selection.
5035
+ function replaceOneSelection(doc, i, range, options) {
5036
+ var ranges = doc.sel.ranges.slice(0);
5037
+ ranges[i] = range;
5038
+ setSelection(doc, normalizeSelection(doc.cm, ranges, doc.sel.primIndex), options);
5039
+ }
5040
+
5041
+ // Reset the selection to a single range.
5042
+ function setSimpleSelection(doc, anchor, head, options) {
5043
+ setSelection(doc, simpleSelection(anchor, head), options);
5044
+ }
5045
+
5046
+ // Give beforeSelectionChange handlers a change to influence a
5047
+ // selection update.
5048
+ function filterSelectionChange(doc, sel, options) {
5049
+ var obj = {
5050
+ ranges: sel.ranges,
5051
+ update: function(ranges) {
5052
+ var this$1 = this;
5053
+
5054
+ this.ranges = [];
5055
+ for (var i = 0; i < ranges.length; i++)
5056
+ { this$1.ranges[i] = new Range(clipPos(doc, ranges[i].anchor),
5057
+ clipPos(doc, ranges[i].head)); }
5058
+ },
5059
+ origin: options && options.origin
5060
+ };
5061
+ signal(doc, "beforeSelectionChange", doc, obj);
5062
+ if (doc.cm) { signal(doc.cm, "beforeSelectionChange", doc.cm, obj); }
5063
+ if (obj.ranges != sel.ranges) { return normalizeSelection(doc.cm, obj.ranges, obj.ranges.length - 1) }
5064
+ else { return sel }
5065
+ }
5066
+
5067
+ function setSelectionReplaceHistory(doc, sel, options) {
5068
+ var done = doc.history.done, last = lst(done);
5069
+ if (last && last.ranges) {
5070
+ done[done.length - 1] = sel;
5071
+ setSelectionNoUndo(doc, sel, options);
5072
+ } else {
5073
+ setSelection(doc, sel, options);
5074
+ }
5075
+ }
5076
+
5077
+ // Set a new selection.
5078
+ function setSelection(doc, sel, options) {
5079
+ setSelectionNoUndo(doc, sel, options);
5080
+ addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options);
5081
+ }
5082
+
5083
+ function setSelectionNoUndo(doc, sel, options) {
5084
+ if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange"))
5085
+ { sel = filterSelectionChange(doc, sel, options); }
5086
+
5087
+ var bias = options && options.bias ||
5088
+ (cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1);
5089
+ setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true));
5090
+
5091
+ if (!(options && options.scroll === false) && doc.cm)
5092
+ { ensureCursorVisible(doc.cm); }
5093
+ }
5094
+
5095
+ function setSelectionInner(doc, sel) {
5096
+ if (sel.equals(doc.sel)) { return }
5097
+
5098
+ doc.sel = sel;
5099
+
5100
+ if (doc.cm) {
5101
+ doc.cm.curOp.updateInput = doc.cm.curOp.selectionChanged = true;
5102
+ signalCursorActivity(doc.cm);
5103
+ }
5104
+ signalLater(doc, "cursorActivity", doc);
5105
+ }
5106
+
5107
+ // Verify that the selection does not partially select any atomic
5108
+ // marked ranges.
5109
+ function reCheckSelection(doc) {
5110
+ setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false));
5111
+ }
5112
+
5113
+ // Return a selection that does not partially select any atomic
5114
+ // ranges.
5115
+ function skipAtomicInSelection(doc, sel, bias, mayClear) {
5116
+ var out;
5117
+ for (var i = 0; i < sel.ranges.length; i++) {
5118
+ var range = sel.ranges[i];
5119
+ var old = sel.ranges.length == doc.sel.ranges.length && doc.sel.ranges[i];
5120
+ var newAnchor = skipAtomic(doc, range.anchor, old && old.anchor, bias, mayClear);
5121
+ var newHead = skipAtomic(doc, range.head, old && old.head, bias, mayClear);
5122
+ if (out || newAnchor != range.anchor || newHead != range.head) {
5123
+ if (!out) { out = sel.ranges.slice(0, i); }
5124
+ out[i] = new Range(newAnchor, newHead);
5125
+ }
5126
+ }
5127
+ return out ? normalizeSelection(doc.cm, out, sel.primIndex) : sel
5128
+ }
5129
+
5130
+ function skipAtomicInner(doc, pos, oldPos, dir, mayClear) {
5131
+ var line = getLine(doc, pos.line);
5132
+ if (line.markedSpans) { for (var i = 0; i < line.markedSpans.length; ++i) {
5133
+ var sp = line.markedSpans[i], m = sp.marker;
5134
+ if ((sp.from == null || (m.inclusiveLeft ? sp.from <= pos.ch : sp.from < pos.ch)) &&
5135
+ (sp.to == null || (m.inclusiveRight ? sp.to >= pos.ch : sp.to > pos.ch))) {
5136
+ if (mayClear) {
5137
+ signal(m, "beforeCursorEnter");
5138
+ if (m.explicitlyCleared) {
5139
+ if (!line.markedSpans) { break }
5140
+ else {--i; continue}
5141
+ }
5142
+ }
5143
+ if (!m.atomic) { continue }
5144
+
5145
+ if (oldPos) {
5146
+ var near = m.find(dir < 0 ? 1 : -1), diff = (void 0);
5147
+ if (dir < 0 ? m.inclusiveRight : m.inclusiveLeft)
5148
+ { near = movePos(doc, near, -dir, near && near.line == pos.line ? line : null); }
5149
+ if (near && near.line == pos.line && (diff = cmp(near, oldPos)) && (dir < 0 ? diff < 0 : diff > 0))
5150
+ { return skipAtomicInner(doc, near, pos, dir, mayClear) }
5151
+ }
5152
+
5153
+ var far = m.find(dir < 0 ? -1 : 1);
5154
+ if (dir < 0 ? m.inclusiveLeft : m.inclusiveRight)
5155
+ { far = movePos(doc, far, dir, far.line == pos.line ? line : null); }
5156
+ return far ? skipAtomicInner(doc, far, pos, dir, mayClear) : null
5157
+ }
5158
+ } }
5159
+ return pos
5160
+ }
5161
+
5162
+ // Ensure a given position is not inside an atomic range.
5163
+ function skipAtomic(doc, pos, oldPos, bias, mayClear) {
5164
+ var dir = bias || 1;
5165
+ var found = skipAtomicInner(doc, pos, oldPos, dir, mayClear) ||
5166
+ (!mayClear && skipAtomicInner(doc, pos, oldPos, dir, true)) ||
5167
+ skipAtomicInner(doc, pos, oldPos, -dir, mayClear) ||
5168
+ (!mayClear && skipAtomicInner(doc, pos, oldPos, -dir, true));
5169
+ if (!found) {
5170
+ doc.cantEdit = true;
5171
+ return Pos(doc.first, 0)
5172
+ }
5173
+ return found
5174
+ }
5175
+
5176
+ function movePos(doc, pos, dir, line) {
5177
+ if (dir < 0 && pos.ch == 0) {
5178
+ if (pos.line > doc.first) { return clipPos(doc, Pos(pos.line - 1)) }
5179
+ else { return null }
5180
+ } else if (dir > 0 && pos.ch == (line || getLine(doc, pos.line)).text.length) {
5181
+ if (pos.line < doc.first + doc.size - 1) { return Pos(pos.line + 1, 0) }
5182
+ else { return null }
5183
+ } else {
5184
+ return new Pos(pos.line, pos.ch + dir)
5185
+ }
5186
+ }
5187
+
5188
+ function selectAll(cm) {
5189
+ cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll);
5190
+ }
5191
+
5192
+ // UPDATING
5193
+
5194
+ // Allow "beforeChange" event handlers to influence a change
5195
+ function filterChange(doc, change, update) {
5196
+ var obj = {
5197
+ canceled: false,
5198
+ from: change.from,
5199
+ to: change.to,
5200
+ text: change.text,
5201
+ origin: change.origin,
5202
+ cancel: function () { return obj.canceled = true; }
5203
+ };
5204
+ if (update) { obj.update = function (from, to, text, origin) {
5205
+ if (from) { obj.from = clipPos(doc, from); }
5206
+ if (to) { obj.to = clipPos(doc, to); }
5207
+ if (text) { obj.text = text; }
5208
+ if (origin !== undefined) { obj.origin = origin; }
5209
+ }; }
5210
+ signal(doc, "beforeChange", doc, obj);
5211
+ if (doc.cm) { signal(doc.cm, "beforeChange", doc.cm, obj); }
5212
+
5213
+ if (obj.canceled) { return null }
5214
+ return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin}
5215
+ }
5216
+
5217
+ // Apply a change to a document, and add it to the document's
5218
+ // history, and propagating it to all linked documents.
5219
+ function makeChange(doc, change, ignoreReadOnly) {
5220
+ if (doc.cm) {
5221
+ if (!doc.cm.curOp) { return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly) }
5222
+ if (doc.cm.state.suppressEdits) { return }
5223
+ }
5224
+
5225
+ if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
5226
+ change = filterChange(doc, change, true);
5227
+ if (!change) { return }
5228
+ }
5229
+
5230
+ // Possibly split or suppress the update based on the presence
5231
+ // of read-only spans in its range.
5232
+ var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to);
5233
+ if (split) {
5234
+ for (var i = split.length - 1; i >= 0; --i)
5235
+ { makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text, origin: change.origin}); }
5236
+ } else {
5237
+ makeChangeInner(doc, change);
5238
+ }
5239
+ }
5240
+
5241
+ function makeChangeInner(doc, change) {
5242
+ if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) { return }
5243
+ var selAfter = computeSelAfterChange(doc, change);
5244
+ addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN);
5245
+
5246
+ makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change));
5247
+ var rebased = [];
5248
+
5249
+ linkedDocs(doc, function (doc, sharedHist) {
5250
+ if (!sharedHist && indexOf(rebased, doc.history) == -1) {
5251
+ rebaseHist(doc.history, change);
5252
+ rebased.push(doc.history);
5253
+ }
5254
+ makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change));
5255
+ });
5256
+ }
5257
+
5258
+ // Revert a change stored in a document's history.
5259
+ function makeChangeFromHistory(doc, type, allowSelectionOnly) {
5260
+ var suppress = doc.cm && doc.cm.state.suppressEdits;
5261
+ if (suppress && !allowSelectionOnly) { return }
5262
+
5263
+ var hist = doc.history, event, selAfter = doc.sel;
5264
+ var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done;
5265
+
5266
+ // Verify that there is a useable event (so that ctrl-z won't
5267
+ // needlessly clear selection events)
5268
+ var i = 0;
5269
+ for (; i < source.length; i++) {
5270
+ event = source[i];
5271
+ if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges)
5272
+ { break }
5273
+ }
5274
+ if (i == source.length) { return }
5275
+ hist.lastOrigin = hist.lastSelOrigin = null;
5276
+
5277
+ for (;;) {
5278
+ event = source.pop();
5279
+ if (event.ranges) {
5280
+ pushSelectionToHistory(event, dest);
5281
+ if (allowSelectionOnly && !event.equals(doc.sel)) {
5282
+ setSelection(doc, event, {clearRedo: false});
5283
+ return
5284
+ }
5285
+ selAfter = event;
5286
+ } else if (suppress) {
5287
+ source.push(event);
5288
+ return
5289
+ } else { break }
5290
+ }
5291
+
5292
+ // Build up a reverse change object to add to the opposite history
5293
+ // stack (redo when undoing, and vice versa).
5294
+ var antiChanges = [];
5295
+ pushSelectionToHistory(selAfter, dest);
5296
+ dest.push({changes: antiChanges, generation: hist.generation});
5297
+ hist.generation = event.generation || ++hist.maxGeneration;
5298
+
5299
+ var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange");
5300
+
5301
+ var loop = function ( i ) {
5302
+ var change = event.changes[i];
5303
+ change.origin = type;
5304
+ if (filter && !filterChange(doc, change, false)) {
5305
+ source.length = 0;
5306
+ return {}
5307
+ }
5308
+
5309
+ antiChanges.push(historyChangeFromChange(doc, change));
5310
+
5311
+ var after = i ? computeSelAfterChange(doc, change) : lst(source);
5312
+ makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change));
5313
+ if (!i && doc.cm) { doc.cm.scrollIntoView({from: change.from, to: changeEnd(change)}); }
5314
+ var rebased = [];
5315
+
5316
+ // Propagate to the linked documents
5317
+ linkedDocs(doc, function (doc, sharedHist) {
5318
+ if (!sharedHist && indexOf(rebased, doc.history) == -1) {
5319
+ rebaseHist(doc.history, change);
5320
+ rebased.push(doc.history);
5321
+ }
5322
+ makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change));
5323
+ });
5324
+ };
5325
+
5326
+ for (var i$1 = event.changes.length - 1; i$1 >= 0; --i$1) {
5327
+ var returned = loop( i$1 );
5328
+
5329
+ if ( returned ) return returned.v;
5330
+ }
5331
+ }
5332
+
5333
+ // Sub-views need their line numbers shifted when text is added
5334
+ // above or below them in the parent document.
5335
+ function shiftDoc(doc, distance) {
5336
+ if (distance == 0) { return }
5337
+ doc.first += distance;
5338
+ doc.sel = new Selection(map(doc.sel.ranges, function (range) { return new Range(
5339
+ Pos(range.anchor.line + distance, range.anchor.ch),
5340
+ Pos(range.head.line + distance, range.head.ch)
5341
+ ); }), doc.sel.primIndex);
5342
+ if (doc.cm) {
5343
+ regChange(doc.cm, doc.first, doc.first - distance, distance);
5344
+ for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++)
5345
+ { regLineChange(doc.cm, l, "gutter"); }
5346
+ }
5347
+ }
5348
+
5349
+ // More lower-level change function, handling only a single document
5350
+ // (not linked ones).
5351
+ function makeChangeSingleDoc(doc, change, selAfter, spans) {
5352
+ if (doc.cm && !doc.cm.curOp)
5353
+ { return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans) }
5354
+
5355
+ if (change.to.line < doc.first) {
5356
+ shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line));
5357
+ return
5358
+ }
5359
+ if (change.from.line > doc.lastLine()) { return }
5360
+
5361
+ // Clip the change to the size of this doc
5362
+ if (change.from.line < doc.first) {
5363
+ var shift = change.text.length - 1 - (doc.first - change.from.line);
5364
+ shiftDoc(doc, shift);
5365
+ change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
5366
+ text: [lst(change.text)], origin: change.origin};
5367
+ }
5368
+ var last = doc.lastLine();
5369
+ if (change.to.line > last) {
5370
+ change = {from: change.from, to: Pos(last, getLine(doc, last).text.length),
5371
+ text: [change.text[0]], origin: change.origin};
5372
+ }
5373
+
5374
+ change.removed = getBetween(doc, change.from, change.to);
5375
+
5376
+ if (!selAfter) { selAfter = computeSelAfterChange(doc, change); }
5377
+ if (doc.cm) { makeChangeSingleDocInEditor(doc.cm, change, spans); }
5378
+ else { updateDoc(doc, change, spans); }
5379
+ setSelectionNoUndo(doc, selAfter, sel_dontScroll);
5380
+ }
5381
+
5382
+ // Handle the interaction of a change to a document with the editor
5383
+ // that this document is part of.
5384
+ function makeChangeSingleDocInEditor(cm, change, spans) {
5385
+ var doc = cm.doc, display = cm.display, from = change.from, to = change.to;
5386
+
5387
+ var recomputeMaxLength = false, checkWidthStart = from.line;
5388
+ if (!cm.options.lineWrapping) {
5389
+ checkWidthStart = lineNo(visualLine(getLine(doc, from.line)));
5390
+ doc.iter(checkWidthStart, to.line + 1, function (line) {
5391
+ if (line == display.maxLine) {
5392
+ recomputeMaxLength = true;
5393
+ return true
5394
+ }
5395
+ });
5396
+ }
5397
+
5398
+ if (doc.sel.contains(change.from, change.to) > -1)
5399
+ { signalCursorActivity(cm); }
5400
+
5401
+ updateDoc(doc, change, spans, estimateHeight(cm));
5402
+
5403
+ if (!cm.options.lineWrapping) {
5404
+ doc.iter(checkWidthStart, from.line + change.text.length, function (line) {
5405
+ var len = lineLength(line);
5406
+ if (len > display.maxLineLength) {
5407
+ display.maxLine = line;
5408
+ display.maxLineLength = len;
5409
+ display.maxLineChanged = true;
5410
+ recomputeMaxLength = false;
5411
+ }
5412
+ });
5413
+ if (recomputeMaxLength) { cm.curOp.updateMaxLine = true; }
5414
+ }
5415
+
5416
+ retreatFrontier(doc, from.line);
5417
+ startWorker(cm, 400);
5418
+
5419
+ var lendiff = change.text.length - (to.line - from.line) - 1;
5420
+ // Remember that these lines changed, for updating the display
5421
+ if (change.full)
5422
+ { regChange(cm); }
5423
+ else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change))
5424
+ { regLineChange(cm, from.line, "text"); }
5425
+ else
5426
+ { regChange(cm, from.line, to.line + 1, lendiff); }
5427
+
5428
+ var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change");
5429
+ if (changeHandler || changesHandler) {
5430
+ var obj = {
5431
+ from: from, to: to,
5432
+ text: change.text,
5433
+ removed: change.removed,
5434
+ origin: change.origin
5435
+ };
5436
+ if (changeHandler) { signalLater(cm, "change", cm, obj); }
5437
+ if (changesHandler) { (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj); }
5438
+ }
5439
+ cm.display.selForContextMenu = null;
5440
+ }
5441
+
5442
+ function replaceRange(doc, code, from, to, origin) {
5443
+ var assign;
5444
+
5445
+ if (!to) { to = from; }
5446
+ if (cmp(to, from) < 0) { (assign = [to, from], from = assign[0], to = assign[1]); }
5447
+ if (typeof code == "string") { code = doc.splitLines(code); }
5448
+ makeChange(doc, {from: from, to: to, text: code, origin: origin});
5449
+ }
5450
+
5451
+ // Rebasing/resetting history to deal with externally-sourced changes
5452
+
5453
+ function rebaseHistSelSingle(pos, from, to, diff) {
5454
+ if (to < pos.line) {
5455
+ pos.line += diff;
5456
+ } else if (from < pos.line) {
5457
+ pos.line = from;
5458
+ pos.ch = 0;
5459
+ }
5460
+ }
5461
+
5462
+ // Tries to rebase an array of history events given a change in the
5463
+ // document. If the change touches the same lines as the event, the
5464
+ // event, and everything 'behind' it, is discarded. If the change is
5465
+ // before the event, the event's positions are updated. Uses a
5466
+ // copy-on-write scheme for the positions, to avoid having to
5467
+ // reallocate them all on every rebase, but also avoid problems with
5468
+ // shared position objects being unsafely updated.
5469
+ function rebaseHistArray(array, from, to, diff) {
5470
+ for (var i = 0; i < array.length; ++i) {
5471
+ var sub = array[i], ok = true;
5472
+ if (sub.ranges) {
5473
+ if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true; }
5474
+ for (var j = 0; j < sub.ranges.length; j++) {
5475
+ rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff);
5476
+ rebaseHistSelSingle(sub.ranges[j].head, from, to, diff);
5477
+ }
5478
+ continue
5479
+ }
5480
+ for (var j$1 = 0; j$1 < sub.changes.length; ++j$1) {
5481
+ var cur = sub.changes[j$1];
5482
+ if (to < cur.from.line) {
5483
+ cur.from = Pos(cur.from.line + diff, cur.from.ch);
5484
+ cur.to = Pos(cur.to.line + diff, cur.to.ch);
5485
+ } else if (from <= cur.to.line) {
5486
+ ok = false;
5487
+ break
5488
+ }
5489
+ }
5490
+ if (!ok) {
5491
+ array.splice(0, i + 1);
5492
+ i = 0;
5493
+ }
5494
+ }
5495
+ }
5496
+
5497
+ function rebaseHist(hist, change) {
5498
+ var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1;
5499
+ rebaseHistArray(hist.done, from, to, diff);
5500
+ rebaseHistArray(hist.undone, from, to, diff);
5501
+ }
5502
+
5503
+ // Utility for applying a change to a line by handle or number,
5504
+ // returning the number and optionally registering the line as
5505
+ // changed.
5506
+ function changeLine(doc, handle, changeType, op) {
5507
+ var no = handle, line = handle;
5508
+ if (typeof handle == "number") { line = getLine(doc, clipLine(doc, handle)); }
5509
+ else { no = lineNo(handle); }
5510
+ if (no == null) { return null }
5511
+ if (op(line, no) && doc.cm) { regLineChange(doc.cm, no, changeType); }
5512
+ return line
5513
+ }
5514
+
5515
+ // The document is represented as a BTree consisting of leaves, with
5516
+ // chunk of lines in them, and branches, with up to ten leaves or
5517
+ // other branch nodes below them. The top node is always a branch
5518
+ // node, and is the document object itself (meaning it has
5519
+ // additional methods and properties).
5520
+ //
5521
+ // All nodes have parent links. The tree is used both to go from
5522
+ // line numbers to line objects, and to go from objects to numbers.
5523
+ // It also indexes by height, and is used to convert between height
5524
+ // and line object, and to find the total height of the document.
5525
+ //
5526
+ // See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html
5527
+
5528
+ function LeafChunk(lines) {
5529
+ var this$1 = this;
5530
+
5531
+ this.lines = lines;
5532
+ this.parent = null;
5533
+ var height = 0;
5534
+ for (var i = 0; i < lines.length; ++i) {
5535
+ lines[i].parent = this$1;
5536
+ height += lines[i].height;
5537
+ }
5538
+ this.height = height;
5539
+ }
5540
+
5541
+ LeafChunk.prototype = {
5542
+ chunkSize: function() { return this.lines.length },
5543
+
5544
+ // Remove the n lines at offset 'at'.
5545
+ removeInner: function(at, n) {
5546
+ var this$1 = this;
5547
+
5548
+ for (var i = at, e = at + n; i < e; ++i) {
5549
+ var line = this$1.lines[i];
5550
+ this$1.height -= line.height;
5551
+ cleanUpLine(line);
5552
+ signalLater(line, "delete");
5553
+ }
5554
+ this.lines.splice(at, n);
5555
+ },
5556
+
5557
+ // Helper used to collapse a small branch into a single leaf.
5558
+ collapse: function(lines) {
5559
+ lines.push.apply(lines, this.lines);
5560
+ },
5561
+
5562
+ // Insert the given array of lines at offset 'at', count them as
5563
+ // having the given height.
5564
+ insertInner: function(at, lines, height) {
5565
+ var this$1 = this;
5566
+
5567
+ this.height += height;
5568
+ this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
5569
+ for (var i = 0; i < lines.length; ++i) { lines[i].parent = this$1; }
5570
+ },
5571
+
5572
+ // Used to iterate over a part of the tree.
5573
+ iterN: function(at, n, op) {
5574
+ var this$1 = this;
5575
+
5576
+ for (var e = at + n; at < e; ++at)
5577
+ { if (op(this$1.lines[at])) { return true } }
5578
+ }
5579
+ };
5580
+
5581
+ function BranchChunk(children) {
5582
+ var this$1 = this;
5583
+
5584
+ this.children = children;
5585
+ var size = 0, height = 0;
5586
+ for (var i = 0; i < children.length; ++i) {
5587
+ var ch = children[i];
5588
+ size += ch.chunkSize(); height += ch.height;
5589
+ ch.parent = this$1;
5590
+ }
5591
+ this.size = size;
5592
+ this.height = height;
5593
+ this.parent = null;
5594
+ }
5595
+
5596
+ BranchChunk.prototype = {
5597
+ chunkSize: function() { return this.size },
5598
+
5599
+ removeInner: function(at, n) {
5600
+ var this$1 = this;
5601
+
5602
+ this.size -= n;
5603
+ for (var i = 0; i < this.children.length; ++i) {
5604
+ var child = this$1.children[i], sz = child.chunkSize();
5605
+ if (at < sz) {
5606
+ var rm = Math.min(n, sz - at), oldHeight = child.height;
5607
+ child.removeInner(at, rm);
5608
+ this$1.height -= oldHeight - child.height;
5609
+ if (sz == rm) { this$1.children.splice(i--, 1); child.parent = null; }
5610
+ if ((n -= rm) == 0) { break }
5611
+ at = 0;
5612
+ } else { at -= sz; }
5613
+ }
5614
+ // If the result is smaller than 25 lines, ensure that it is a
5615
+ // single leaf node.
5616
+ if (this.size - n < 25 &&
5617
+ (this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {
5618
+ var lines = [];
5619
+ this.collapse(lines);
5620
+ this.children = [new LeafChunk(lines)];
5621
+ this.children[0].parent = this;
5622
+ }
5623
+ },
5624
+
5625
+ collapse: function(lines) {
5626
+ var this$1 = this;
5627
+
5628
+ for (var i = 0; i < this.children.length; ++i) { this$1.children[i].collapse(lines); }
5629
+ },
5630
+
5631
+ insertInner: function(at, lines, height) {
5632
+ var this$1 = this;
5633
+
5634
+ this.size += lines.length;
5635
+ this.height += height;
5636
+ for (var i = 0; i < this.children.length; ++i) {
5637
+ var child = this$1.children[i], sz = child.chunkSize();
5638
+ if (at <= sz) {
5639
+ child.insertInner(at, lines, height);
5640
+ if (child.lines && child.lines.length > 50) {
5641
+ // To avoid memory thrashing when child.lines is huge (e.g. first view of a large file), it's never spliced.
5642
+ // Instead, small slices are taken. They're taken in order because sequential memory accesses are fastest.
5643
+ var remaining = child.lines.length % 25 + 25;
5644
+ for (var pos = remaining; pos < child.lines.length;) {
5645
+ var leaf = new LeafChunk(child.lines.slice(pos, pos += 25));
5646
+ child.height -= leaf.height;
5647
+ this$1.children.splice(++i, 0, leaf);
5648
+ leaf.parent = this$1;
5649
+ }
5650
+ child.lines = child.lines.slice(0, remaining);
5651
+ this$1.maybeSpill();
5652
+ }
5653
+ break
5654
+ }
5655
+ at -= sz;
5656
+ }
5657
+ },
5658
+
5659
+ // When a node has grown, check whether it should be split.
5660
+ maybeSpill: function() {
5661
+ if (this.children.length <= 10) { return }
5662
+ var me = this;
5663
+ do {
5664
+ var spilled = me.children.splice(me.children.length - 5, 5);
5665
+ var sibling = new BranchChunk(spilled);
5666
+ if (!me.parent) { // Become the parent node
5667
+ var copy = new BranchChunk(me.children);
5668
+ copy.parent = me;
5669
+ me.children = [copy, sibling];
5670
+ me = copy;
5671
+ } else {
5672
+ me.size -= sibling.size;
5673
+ me.height -= sibling.height;
5674
+ var myIndex = indexOf(me.parent.children, me);
5675
+ me.parent.children.splice(myIndex + 1, 0, sibling);
5676
+ }
5677
+ sibling.parent = me.parent;
5678
+ } while (me.children.length > 10)
5679
+ me.parent.maybeSpill();
5680
+ },
5681
+
5682
+ iterN: function(at, n, op) {
5683
+ var this$1 = this;
5684
+
5685
+ for (var i = 0; i < this.children.length; ++i) {
5686
+ var child = this$1.children[i], sz = child.chunkSize();
5687
+ if (at < sz) {
5688
+ var used = Math.min(n, sz - at);
5689
+ if (child.iterN(at, used, op)) { return true }
5690
+ if ((n -= used) == 0) { break }
5691
+ at = 0;
5692
+ } else { at -= sz; }
5693
+ }
5694
+ }
5695
+ };
5696
+
5697
+ // Line widgets are block elements displayed above or below a line.
5698
+
5699
+ var LineWidget = function(doc, node, options) {
5700
+ var this$1 = this;
5701
+
5702
+ if (options) { for (var opt in options) { if (options.hasOwnProperty(opt))
5703
+ { this$1[opt] = options[opt]; } } }
5704
+ this.doc = doc;
5705
+ this.node = node;
5706
+ };
5707
+
5708
+ LineWidget.prototype.clear = function () {
5709
+ var this$1 = this;
5710
+
5711
+ var cm = this.doc.cm, ws = this.line.widgets, line = this.line, no = lineNo(line);
5712
+ if (no == null || !ws) { return }
5713
+ for (var i = 0; i < ws.length; ++i) { if (ws[i] == this$1) { ws.splice(i--, 1); } }
5714
+ if (!ws.length) { line.widgets = null; }
5715
+ var height = widgetHeight(this);
5716
+ updateLineHeight(line, Math.max(0, line.height - height));
5717
+ if (cm) {
5718
+ runInOp(cm, function () {
5719
+ adjustScrollWhenAboveVisible(cm, line, -height);
5720
+ regLineChange(cm, no, "widget");
5721
+ });
5722
+ signalLater(cm, "lineWidgetCleared", cm, this, no);
5723
+ }
5724
+ };
5725
+
5726
+ LineWidget.prototype.changed = function () {
5727
+ var this$1 = this;
5728
+
5729
+ var oldH = this.height, cm = this.doc.cm, line = this.line;
5730
+ this.height = null;
5731
+ var diff = widgetHeight(this) - oldH;
5732
+ if (!diff) { return }
5733
+ if (!lineIsHidden(this.doc, line)) { updateLineHeight(line, line.height + diff); }
5734
+ if (cm) {
5735
+ runInOp(cm, function () {
5736
+ cm.curOp.forceUpdate = true;
5737
+ adjustScrollWhenAboveVisible(cm, line, diff);
5738
+ signalLater(cm, "lineWidgetChanged", cm, this$1, lineNo(line));
5739
+ });
5740
+ }
5741
+ };
5742
+ eventMixin(LineWidget);
5743
+
5744
+ function adjustScrollWhenAboveVisible(cm, line, diff) {
5745
+ if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop))
5746
+ { addToScrollTop(cm, diff); }
5747
+ }
5748
+
5749
+ function addLineWidget(doc, handle, node, options) {
5750
+ var widget = new LineWidget(doc, node, options);
5751
+ var cm = doc.cm;
5752
+ if (cm && widget.noHScroll) { cm.display.alignWidgets = true; }
5753
+ changeLine(doc, handle, "widget", function (line) {
5754
+ var widgets = line.widgets || (line.widgets = []);
5755
+ if (widget.insertAt == null) { widgets.push(widget); }
5756
+ else { widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget); }
5757
+ widget.line = line;
5758
+ if (cm && !lineIsHidden(doc, line)) {
5759
+ var aboveVisible = heightAtLine(line) < doc.scrollTop;
5760
+ updateLineHeight(line, line.height + widgetHeight(widget));
5761
+ if (aboveVisible) { addToScrollTop(cm, widget.height); }
5762
+ cm.curOp.forceUpdate = true;
5763
+ }
5764
+ return true
5765
+ });
5766
+ if (cm) { signalLater(cm, "lineWidgetAdded", cm, widget, typeof handle == "number" ? handle : lineNo(handle)); }
5767
+ return widget
5768
+ }
5769
+
5770
+ // TEXTMARKERS
5771
+
5772
+ // Created with markText and setBookmark methods. A TextMarker is a
5773
+ // handle that can be used to clear or find a marked position in the
5774
+ // document. Line objects hold arrays (markedSpans) containing
5775
+ // {from, to, marker} object pointing to such marker objects, and
5776
+ // indicating that such a marker is present on that line. Multiple
5777
+ // lines may point to the same marker when it spans across lines.
5778
+ // The spans will have null for their from/to properties when the
5779
+ // marker continues beyond the start/end of the line. Markers have
5780
+ // links back to the lines they currently touch.
5781
+
5782
+ // Collapsed markers have unique ids, in order to be able to order
5783
+ // them, which is needed for uniquely determining an outer marker
5784
+ // when they overlap (they may nest, but not partially overlap).
5785
+ var nextMarkerId = 0;
5786
+
5787
+ var TextMarker = function(doc, type) {
5788
+ this.lines = [];
5789
+ this.type = type;
5790
+ this.doc = doc;
5791
+ this.id = ++nextMarkerId;
5792
+ };
5793
+
5794
+ // Clear the marker.
5795
+ TextMarker.prototype.clear = function () {
5796
+ var this$1 = this;
5797
+
5798
+ if (this.explicitlyCleared) { return }
5799
+ var cm = this.doc.cm, withOp = cm && !cm.curOp;
5800
+ if (withOp) { startOperation(cm); }
5801
+ if (hasHandler(this, "clear")) {
5802
+ var found = this.find();
5803
+ if (found) { signalLater(this, "clear", found.from, found.to); }
5804
+ }
5805
+ var min = null, max = null;
5806
+ for (var i = 0; i < this.lines.length; ++i) {
5807
+ var line = this$1.lines[i];
5808
+ var span = getMarkedSpanFor(line.markedSpans, this$1);
5809
+ if (cm && !this$1.collapsed) { regLineChange(cm, lineNo(line), "text"); }
5810
+ else if (cm) {
5811
+ if (span.to != null) { max = lineNo(line); }
5812
+ if (span.from != null) { min = lineNo(line); }
5813
+ }
5814
+ line.markedSpans = removeMarkedSpan(line.markedSpans, span);
5815
+ if (span.from == null && this$1.collapsed && !lineIsHidden(this$1.doc, line) && cm)
5816
+ { updateLineHeight(line, textHeight(cm.display)); }
5817
+ }
5818
+ if (cm && this.collapsed && !cm.options.lineWrapping) { for (var i$1 = 0; i$1 < this.lines.length; ++i$1) {
5819
+ var visual = visualLine(this$1.lines[i$1]), len = lineLength(visual);
5820
+ if (len > cm.display.maxLineLength) {
5821
+ cm.display.maxLine = visual;
5822
+ cm.display.maxLineLength = len;
5823
+ cm.display.maxLineChanged = true;
5824
+ }
5825
+ } }
5826
+
5827
+ if (min != null && cm && this.collapsed) { regChange(cm, min, max + 1); }
5828
+ this.lines.length = 0;
5829
+ this.explicitlyCleared = true;
5830
+ if (this.atomic && this.doc.cantEdit) {
5831
+ this.doc.cantEdit = false;
5832
+ if (cm) { reCheckSelection(cm.doc); }
5833
+ }
5834
+ if (cm) { signalLater(cm, "markerCleared", cm, this, min, max); }
5835
+ if (withOp) { endOperation(cm); }
5836
+ if (this.parent) { this.parent.clear(); }
5837
+ };
5838
+
5839
+ // Find the position of the marker in the document. Returns a {from,
5840
+ // to} object by default. Side can be passed to get a specific side
5841
+ // -- 0 (both), -1 (left), or 1 (right). When lineObj is true, the
5842
+ // Pos objects returned contain a line object, rather than a line
5843
+ // number (used to prevent looking up the same line twice).
5844
+ TextMarker.prototype.find = function (side, lineObj) {
5845
+ var this$1 = this;
5846
+
5847
+ if (side == null && this.type == "bookmark") { side = 1; }
5848
+ var from, to;
5849
+ for (var i = 0; i < this.lines.length; ++i) {
5850
+ var line = this$1.lines[i];
5851
+ var span = getMarkedSpanFor(line.markedSpans, this$1);
5852
+ if (span.from != null) {
5853
+ from = Pos(lineObj ? line : lineNo(line), span.from);
5854
+ if (side == -1) { return from }
5855
+ }
5856
+ if (span.to != null) {
5857
+ to = Pos(lineObj ? line : lineNo(line), span.to);
5858
+ if (side == 1) { return to }
5859
+ }
5860
+ }
5861
+ return from && {from: from, to: to}
5862
+ };
5863
+
5864
+ // Signals that the marker's widget changed, and surrounding layout
5865
+ // should be recomputed.
5866
+ TextMarker.prototype.changed = function () {
5867
+ var this$1 = this;
5868
+
5869
+ var pos = this.find(-1, true), widget = this, cm = this.doc.cm;
5870
+ if (!pos || !cm) { return }
5871
+ runInOp(cm, function () {
5872
+ var line = pos.line, lineN = lineNo(pos.line);
5873
+ var view = findViewForLine(cm, lineN);
5874
+ if (view) {
5875
+ clearLineMeasurementCacheFor(view);
5876
+ cm.curOp.selectionChanged = cm.curOp.forceUpdate = true;
5877
+ }
5878
+ cm.curOp.updateMaxLine = true;
5879
+ if (!lineIsHidden(widget.doc, line) && widget.height != null) {
5880
+ var oldHeight = widget.height;
5881
+ widget.height = null;
5882
+ var dHeight = widgetHeight(widget) - oldHeight;
5883
+ if (dHeight)
5884
+ { updateLineHeight(line, line.height + dHeight); }
5885
+ }
5886
+ signalLater(cm, "markerChanged", cm, this$1);
5887
+ });
5888
+ };
5889
+
5890
+ TextMarker.prototype.attachLine = function (line) {
5891
+ if (!this.lines.length && this.doc.cm) {
5892
+ var op = this.doc.cm.curOp;
5893
+ if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1)
5894
+ { (op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this); }
5895
+ }
5896
+ this.lines.push(line);
5897
+ };
5898
+
5899
+ TextMarker.prototype.detachLine = function (line) {
5900
+ this.lines.splice(indexOf(this.lines, line), 1);
5901
+ if (!this.lines.length && this.doc.cm) {
5902
+ var op = this.doc.cm.curOp
5903
+ ;(op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this);
5904
+ }
5905
+ };
5906
+ eventMixin(TextMarker);
5907
+
5908
+ // Create a marker, wire it up to the right lines, and
5909
+ function markText(doc, from, to, options, type) {
5910
+ // Shared markers (across linked documents) are handled separately
5911
+ // (markTextShared will call out to this again, once per
5912
+ // document).
5913
+ if (options && options.shared) { return markTextShared(doc, from, to, options, type) }
5914
+ // Ensure we are in an operation.
5915
+ if (doc.cm && !doc.cm.curOp) { return operation(doc.cm, markText)(doc, from, to, options, type) }
5916
+
5917
+ var marker = new TextMarker(doc, type), diff = cmp(from, to);
5918
+ if (options) { copyObj(options, marker, false); }
5919
+ // Don't connect empty markers unless clearWhenEmpty is false
5920
+ if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
5921
+ { return marker }
5922
+ if (marker.replacedWith) {
5923
+ // Showing up as a widget implies collapsed (widget replaces text)
5924
+ marker.collapsed = true;
5925
+ marker.widgetNode = eltP("span", [marker.replacedWith], "CodeMirror-widget");
5926
+ if (!options.handleMouseEvents) { marker.widgetNode.setAttribute("cm-ignore-events", "true"); }
5927
+ if (options.insertLeft) { marker.widgetNode.insertLeft = true; }
5928
+ }
5929
+ if (marker.collapsed) {
5930
+ if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
5931
+ from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
5932
+ { throw new Error("Inserting collapsed marker partially overlapping an existing one") }
5933
+ seeCollapsedSpans();
5934
+ }
5935
+
5936
+ if (marker.addToHistory)
5937
+ { addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN); }
5938
+
5939
+ var curLine = from.line, cm = doc.cm, updateMaxLine;
5940
+ doc.iter(curLine, to.line + 1, function (line) {
5941
+ if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
5942
+ { updateMaxLine = true; }
5943
+ if (marker.collapsed && curLine != from.line) { updateLineHeight(line, 0); }
5944
+ addMarkedSpan(line, new MarkedSpan(marker,
5945
+ curLine == from.line ? from.ch : null,
5946
+ curLine == to.line ? to.ch : null));
5947
+ ++curLine;
5948
+ });
5949
+ // lineIsHidden depends on the presence of the spans, so needs a second pass
5950
+ if (marker.collapsed) { doc.iter(from.line, to.line + 1, function (line) {
5951
+ if (lineIsHidden(doc, line)) { updateLineHeight(line, 0); }
5952
+ }); }
5953
+
5954
+ if (marker.clearOnEnter) { on(marker, "beforeCursorEnter", function () { return marker.clear(); }); }
5955
+
5956
+ if (marker.readOnly) {
5957
+ seeReadOnlySpans();
5958
+ if (doc.history.done.length || doc.history.undone.length)
5959
+ { doc.clearHistory(); }
5960
+ }
5961
+ if (marker.collapsed) {
5962
+ marker.id = ++nextMarkerId;
5963
+ marker.atomic = true;
5964
+ }
5965
+ if (cm) {
5966
+ // Sync editor state
5967
+ if (updateMaxLine) { cm.curOp.updateMaxLine = true; }
5968
+ if (marker.collapsed)
5969
+ { regChange(cm, from.line, to.line + 1); }
5970
+ else if (marker.className || marker.startStyle || marker.endStyle || marker.css ||
5971
+ marker.attributes || marker.title)
5972
+ { for (var i = from.line; i <= to.line; i++) { regLineChange(cm, i, "text"); } }
5973
+ if (marker.atomic) { reCheckSelection(cm.doc); }
5974
+ signalLater(cm, "markerAdded", cm, marker);
5975
+ }
5976
+ return marker
5977
+ }
5978
+
5979
+ // SHARED TEXTMARKERS
5980
+
5981
+ // A shared marker spans multiple linked documents. It is
5982
+ // implemented as a meta-marker-object controlling multiple normal
5983
+ // markers.
5984
+ var SharedTextMarker = function(markers, primary) {
5985
+ var this$1 = this;
5986
+
5987
+ this.markers = markers;
5988
+ this.primary = primary;
5989
+ for (var i = 0; i < markers.length; ++i)
5990
+ { markers[i].parent = this$1; }
5991
+ };
5992
+
5993
+ SharedTextMarker.prototype.clear = function () {
5994
+ var this$1 = this;
5995
+
5996
+ if (this.explicitlyCleared) { return }
5997
+ this.explicitlyCleared = true;
5998
+ for (var i = 0; i < this.markers.length; ++i)
5999
+ { this$1.markers[i].clear(); }
6000
+ signalLater(this, "clear");
6001
+ };
6002
+
6003
+ SharedTextMarker.prototype.find = function (side, lineObj) {
6004
+ return this.primary.find(side, lineObj)
6005
+ };
6006
+ eventMixin(SharedTextMarker);
6007
+
6008
+ function markTextShared(doc, from, to, options, type) {
6009
+ options = copyObj(options);
6010
+ options.shared = false;
6011
+ var markers = [markText(doc, from, to, options, type)], primary = markers[0];
6012
+ var widget = options.widgetNode;
6013
+ linkedDocs(doc, function (doc) {
6014
+ if (widget) { options.widgetNode = widget.cloneNode(true); }
6015
+ markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type));
6016
+ for (var i = 0; i < doc.linked.length; ++i)
6017
+ { if (doc.linked[i].isParent) { return } }
6018
+ primary = lst(markers);
6019
+ });
6020
+ return new SharedTextMarker(markers, primary)
6021
+ }
6022
+
6023
+ function findSharedMarkers(doc) {
6024
+ return doc.findMarks(Pos(doc.first, 0), doc.clipPos(Pos(doc.lastLine())), function (m) { return m.parent; })
6025
+ }
6026
+
6027
+ function copySharedMarkers(doc, markers) {
6028
+ for (var i = 0; i < markers.length; i++) {
6029
+ var marker = markers[i], pos = marker.find();
6030
+ var mFrom = doc.clipPos(pos.from), mTo = doc.clipPos(pos.to);
6031
+ if (cmp(mFrom, mTo)) {
6032
+ var subMark = markText(doc, mFrom, mTo, marker.primary, marker.primary.type);
6033
+ marker.markers.push(subMark);
6034
+ subMark.parent = marker;
6035
+ }
6036
+ }
6037
+ }
6038
+
6039
+ function detachSharedMarkers(markers) {
6040
+ var loop = function ( i ) {
6041
+ var marker = markers[i], linked = [marker.primary.doc];
6042
+ linkedDocs(marker.primary.doc, function (d) { return linked.push(d); });
6043
+ for (var j = 0; j < marker.markers.length; j++) {
6044
+ var subMarker = marker.markers[j];
6045
+ if (indexOf(linked, subMarker.doc) == -1) {
6046
+ subMarker.parent = null;
6047
+ marker.markers.splice(j--, 1);
6048
+ }
6049
+ }
6050
+ };
6051
+
6052
+ for (var i = 0; i < markers.length; i++) loop( i );
6053
+ }
6054
+
6055
+ var nextDocId = 0;
6056
+ var Doc = function(text, mode, firstLine, lineSep, direction) {
6057
+ if (!(this instanceof Doc)) { return new Doc(text, mode, firstLine, lineSep, direction) }
6058
+ if (firstLine == null) { firstLine = 0; }
6059
+
6060
+ BranchChunk.call(this, [new LeafChunk([new Line("", null)])]);
6061
+ this.first = firstLine;
6062
+ this.scrollTop = this.scrollLeft = 0;
6063
+ this.cantEdit = false;
6064
+ this.cleanGeneration = 1;
6065
+ this.modeFrontier = this.highlightFrontier = firstLine;
6066
+ var start = Pos(firstLine, 0);
6067
+ this.sel = simpleSelection(start);
6068
+ this.history = new History(null);
6069
+ this.id = ++nextDocId;
6070
+ this.modeOption = mode;
6071
+ this.lineSep = lineSep;
6072
+ this.direction = (direction == "rtl") ? "rtl" : "ltr";
6073
+ this.extend = false;
6074
+
6075
+ if (typeof text == "string") { text = this.splitLines(text); }
6076
+ updateDoc(this, {from: start, to: start, text: text});
6077
+ setSelection(this, simpleSelection(start), sel_dontScroll);
6078
+ };
6079
+
6080
+ Doc.prototype = createObj(BranchChunk.prototype, {
6081
+ constructor: Doc,
6082
+ // Iterate over the document. Supports two forms -- with only one
6083
+ // argument, it calls that for each line in the document. With
6084
+ // three, it iterates over the range given by the first two (with
6085
+ // the second being non-inclusive).
6086
+ iter: function(from, to, op) {
6087
+ if (op) { this.iterN(from - this.first, to - from, op); }
6088
+ else { this.iterN(this.first, this.first + this.size, from); }
6089
+ },
6090
+
6091
+ // Non-public interface for adding and removing lines.
6092
+ insert: function(at, lines) {
6093
+ var height = 0;
6094
+ for (var i = 0; i < lines.length; ++i) { height += lines[i].height; }
6095
+ this.insertInner(at - this.first, lines, height);
6096
+ },
6097
+ remove: function(at, n) { this.removeInner(at - this.first, n); },
6098
+
6099
+ // From here, the methods are part of the public interface. Most
6100
+ // are also available from CodeMirror (editor) instances.
6101
+
6102
+ getValue: function(lineSep) {
6103
+ var lines = getLines(this, this.first, this.first + this.size);
6104
+ if (lineSep === false) { return lines }
6105
+ return lines.join(lineSep || this.lineSeparator())
6106
+ },
6107
+ setValue: docMethodOp(function(code) {
6108
+ var top = Pos(this.first, 0), last = this.first + this.size - 1;
6109
+ makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length),
6110
+ text: this.splitLines(code), origin: "setValue", full: true}, true);
6111
+ if (this.cm) { scrollToCoords(this.cm, 0, 0); }
6112
+ setSelection(this, simpleSelection(top), sel_dontScroll);
6113
+ }),
6114
+ replaceRange: function(code, from, to, origin) {
6115
+ from = clipPos(this, from);
6116
+ to = to ? clipPos(this, to) : from;
6117
+ replaceRange(this, code, from, to, origin);
6118
+ },
6119
+ getRange: function(from, to, lineSep) {
6120
+ var lines = getBetween(this, clipPos(this, from), clipPos(this, to));
6121
+ if (lineSep === false) { return lines }
6122
+ return lines.join(lineSep || this.lineSeparator())
6123
+ },
6124
+
6125
+ getLine: function(line) {var l = this.getLineHandle(line); return l && l.text},
6126
+
6127
+ getLineHandle: function(line) {if (isLine(this, line)) { return getLine(this, line) }},
6128
+ getLineNumber: function(line) {return lineNo(line)},
6129
+
6130
+ getLineHandleVisualStart: function(line) {
6131
+ if (typeof line == "number") { line = getLine(this, line); }
6132
+ return visualLine(line)
6133
+ },
6134
+
6135
+ lineCount: function() {return this.size},
6136
+ firstLine: function() {return this.first},
6137
+ lastLine: function() {return this.first + this.size - 1},
6138
+
6139
+ clipPos: function(pos) {return clipPos(this, pos)},
6140
+
6141
+ getCursor: function(start) {
6142
+ var range$$1 = this.sel.primary(), pos;
6143
+ if (start == null || start == "head") { pos = range$$1.head; }
6144
+ else if (start == "anchor") { pos = range$$1.anchor; }
6145
+ else if (start == "end" || start == "to" || start === false) { pos = range$$1.to(); }
6146
+ else { pos = range$$1.from(); }
6147
+ return pos
6148
+ },
6149
+ listSelections: function() { return this.sel.ranges },
6150
+ somethingSelected: function() {return this.sel.somethingSelected()},
6151
+
6152
+ setCursor: docMethodOp(function(line, ch, options) {
6153
+ setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options);
6154
+ }),
6155
+ setSelection: docMethodOp(function(anchor, head, options) {
6156
+ setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options);
6157
+ }),
6158
+ extendSelection: docMethodOp(function(head, other, options) {
6159
+ extendSelection(this, clipPos(this, head), other && clipPos(this, other), options);
6160
+ }),
6161
+ extendSelections: docMethodOp(function(heads, options) {
6162
+ extendSelections(this, clipPosArray(this, heads), options);
6163
+ }),
6164
+ extendSelectionsBy: docMethodOp(function(f, options) {
6165
+ var heads = map(this.sel.ranges, f);
6166
+ extendSelections(this, clipPosArray(this, heads), options);
6167
+ }),
6168
+ setSelections: docMethodOp(function(ranges, primary, options) {
6169
+ var this$1 = this;
6170
+
6171
+ if (!ranges.length) { return }
6172
+ var out = [];
6173
+ for (var i = 0; i < ranges.length; i++)
6174
+ { out[i] = new Range(clipPos(this$1, ranges[i].anchor),
6175
+ clipPos(this$1, ranges[i].head)); }
6176
+ if (primary == null) { primary = Math.min(ranges.length - 1, this.sel.primIndex); }
6177
+ setSelection(this, normalizeSelection(this.cm, out, primary), options);
6178
+ }),
6179
+ addSelection: docMethodOp(function(anchor, head, options) {
6180
+ var ranges = this.sel.ranges.slice(0);
6181
+ ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor)));
6182
+ setSelection(this, normalizeSelection(this.cm, ranges, ranges.length - 1), options);
6183
+ }),
6184
+
6185
+ getSelection: function(lineSep) {
6186
+ var this$1 = this;
6187
+
6188
+ var ranges = this.sel.ranges, lines;
6189
+ for (var i = 0; i < ranges.length; i++) {
6190
+ var sel = getBetween(this$1, ranges[i].from(), ranges[i].to());
6191
+ lines = lines ? lines.concat(sel) : sel;
6192
+ }
6193
+ if (lineSep === false) { return lines }
6194
+ else { return lines.join(lineSep || this.lineSeparator()) }
6195
+ },
6196
+ getSelections: function(lineSep) {
6197
+ var this$1 = this;
6198
+
6199
+ var parts = [], ranges = this.sel.ranges;
6200
+ for (var i = 0; i < ranges.length; i++) {
6201
+ var sel = getBetween(this$1, ranges[i].from(), ranges[i].to());
6202
+ if (lineSep !== false) { sel = sel.join(lineSep || this$1.lineSeparator()); }
6203
+ parts[i] = sel;
6204
+ }
6205
+ return parts
6206
+ },
6207
+ replaceSelection: function(code, collapse, origin) {
6208
+ var dup = [];
6209
+ for (var i = 0; i < this.sel.ranges.length; i++)
6210
+ { dup[i] = code; }
6211
+ this.replaceSelections(dup, collapse, origin || "+input");
6212
+ },
6213
+ replaceSelections: docMethodOp(function(code, collapse, origin) {
6214
+ var this$1 = this;
6215
+
6216
+ var changes = [], sel = this.sel;
6217
+ for (var i = 0; i < sel.ranges.length; i++) {
6218
+ var range$$1 = sel.ranges[i];
6219
+ changes[i] = {from: range$$1.from(), to: range$$1.to(), text: this$1.splitLines(code[i]), origin: origin};
6220
+ }
6221
+ var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse);
6222
+ for (var i$1 = changes.length - 1; i$1 >= 0; i$1--)
6223
+ { makeChange(this$1, changes[i$1]); }
6224
+ if (newSel) { setSelectionReplaceHistory(this, newSel); }
6225
+ else if (this.cm) { ensureCursorVisible(this.cm); }
6226
+ }),
6227
+ undo: docMethodOp(function() {makeChangeFromHistory(this, "undo");}),
6228
+ redo: docMethodOp(function() {makeChangeFromHistory(this, "redo");}),
6229
+ undoSelection: docMethodOp(function() {makeChangeFromHistory(this, "undo", true);}),
6230
+ redoSelection: docMethodOp(function() {makeChangeFromHistory(this, "redo", true);}),
6231
+
6232
+ setExtending: function(val) {this.extend = val;},
6233
+ getExtending: function() {return this.extend},
6234
+
6235
+ historySize: function() {
6236
+ var hist = this.history, done = 0, undone = 0;
6237
+ for (var i = 0; i < hist.done.length; i++) { if (!hist.done[i].ranges) { ++done; } }
6238
+ for (var i$1 = 0; i$1 < hist.undone.length; i$1++) { if (!hist.undone[i$1].ranges) { ++undone; } }
6239
+ return {undo: done, redo: undone}
6240
+ },
6241
+ clearHistory: function() {this.history = new History(this.history.maxGeneration);},
6242
+
6243
+ markClean: function() {
6244
+ this.cleanGeneration = this.changeGeneration(true);
6245
+ },
6246
+ changeGeneration: function(forceSplit) {
6247
+ if (forceSplit)
6248
+ { this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null; }
6249
+ return this.history.generation
6250
+ },
6251
+ isClean: function (gen) {
6252
+ return this.history.generation == (gen || this.cleanGeneration)
6253
+ },
6254
+
6255
+ getHistory: function() {
6256
+ return {done: copyHistoryArray(this.history.done),
6257
+ undone: copyHistoryArray(this.history.undone)}
6258
+ },
6259
+ setHistory: function(histData) {
6260
+ var hist = this.history = new History(this.history.maxGeneration);
6261
+ hist.done = copyHistoryArray(histData.done.slice(0), null, true);
6262
+ hist.undone = copyHistoryArray(histData.undone.slice(0), null, true);
6263
+ },
6264
+
6265
+ setGutterMarker: docMethodOp(function(line, gutterID, value) {
6266
+ return changeLine(this, line, "gutter", function (line) {
6267
+ var markers = line.gutterMarkers || (line.gutterMarkers = {});
6268
+ markers[gutterID] = value;
6269
+ if (!value && isEmpty(markers)) { line.gutterMarkers = null; }
6270
+ return true
6271
+ })
6272
+ }),
6273
+
6274
+ clearGutter: docMethodOp(function(gutterID) {
6275
+ var this$1 = this;
6276
+
6277
+ this.iter(function (line) {
6278
+ if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
6279
+ changeLine(this$1, line, "gutter", function () {
6280
+ line.gutterMarkers[gutterID] = null;
6281
+ if (isEmpty(line.gutterMarkers)) { line.gutterMarkers = null; }
6282
+ return true
6283
+ });
6284
+ }
6285
+ });
6286
+ }),
6287
+
6288
+ lineInfo: function(line) {
6289
+ var n;
6290
+ if (typeof line == "number") {
6291
+ if (!isLine(this, line)) { return null }
6292
+ n = line;
6293
+ line = getLine(this, line);
6294
+ if (!line) { return null }
6295
+ } else {
6296
+ n = lineNo(line);
6297
+ if (n == null) { return null }
6298
+ }
6299
+ return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
6300
+ textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
6301
+ widgets: line.widgets}
6302
+ },
6303
+
6304
+ addLineClass: docMethodOp(function(handle, where, cls) {
6305
+ return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
6306
+ var prop = where == "text" ? "textClass"
6307
+ : where == "background" ? "bgClass"
6308
+ : where == "gutter" ? "gutterClass" : "wrapClass";
6309
+ if (!line[prop]) { line[prop] = cls; }
6310
+ else if (classTest(cls).test(line[prop])) { return false }
6311
+ else { line[prop] += " " + cls; }
6312
+ return true
6313
+ })
6314
+ }),
6315
+ removeLineClass: docMethodOp(function(handle, where, cls) {
6316
+ return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function (line) {
6317
+ var prop = where == "text" ? "textClass"
6318
+ : where == "background" ? "bgClass"
6319
+ : where == "gutter" ? "gutterClass" : "wrapClass";
6320
+ var cur = line[prop];
6321
+ if (!cur) { return false }
6322
+ else if (cls == null) { line[prop] = null; }
6323
+ else {
6324
+ var found = cur.match(classTest(cls));
6325
+ if (!found) { return false }
6326
+ var end = found.index + found[0].length;
6327
+ line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null;
6328
+ }
6329
+ return true
6330
+ })
6331
+ }),
6332
+
6333
+ addLineWidget: docMethodOp(function(handle, node, options) {
6334
+ return addLineWidget(this, handle, node, options)
6335
+ }),
6336
+ removeLineWidget: function(widget) { widget.clear(); },
6337
+
6338
+ markText: function(from, to, options) {
6339
+ return markText(this, clipPos(this, from), clipPos(this, to), options, options && options.type || "range")
6340
+ },
6341
+ setBookmark: function(pos, options) {
6342
+ var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options),
6343
+ insertLeft: options && options.insertLeft,
6344
+ clearWhenEmpty: false, shared: options && options.shared,
6345
+ handleMouseEvents: options && options.handleMouseEvents};
6346
+ pos = clipPos(this, pos);
6347
+ return markText(this, pos, pos, realOpts, "bookmark")
6348
+ },
6349
+ findMarksAt: function(pos) {
6350
+ pos = clipPos(this, pos);
6351
+ var markers = [], spans = getLine(this, pos.line).markedSpans;
6352
+ if (spans) { for (var i = 0; i < spans.length; ++i) {
6353
+ var span = spans[i];
6354
+ if ((span.from == null || span.from <= pos.ch) &&
6355
+ (span.to == null || span.to >= pos.ch))
6356
+ { markers.push(span.marker.parent || span.marker); }
6357
+ } }
6358
+ return markers
6359
+ },
6360
+ findMarks: function(from, to, filter) {
6361
+ from = clipPos(this, from); to = clipPos(this, to);
6362
+ var found = [], lineNo$$1 = from.line;
6363
+ this.iter(from.line, to.line + 1, function (line) {
6364
+ var spans = line.markedSpans;
6365
+ if (spans) { for (var i = 0; i < spans.length; i++) {
6366
+ var span = spans[i];
6367
+ if (!(span.to != null && lineNo$$1 == from.line && from.ch >= span.to ||
6368
+ span.from == null && lineNo$$1 != from.line ||
6369
+ span.from != null && lineNo$$1 == to.line && span.from >= to.ch) &&
6370
+ (!filter || filter(span.marker)))
6371
+ { found.push(span.marker.parent || span.marker); }
6372
+ } }
6373
+ ++lineNo$$1;
6374
+ });
6375
+ return found
6376
+ },
6377
+ getAllMarks: function() {
6378
+ var markers = [];
6379
+ this.iter(function (line) {
6380
+ var sps = line.markedSpans;
6381
+ if (sps) { for (var i = 0; i < sps.length; ++i)
6382
+ { if (sps[i].from != null) { markers.push(sps[i].marker); } } }
6383
+ });
6384
+ return markers
6385
+ },
6386
+
6387
+ posFromIndex: function(off) {
6388
+ var ch, lineNo$$1 = this.first, sepSize = this.lineSeparator().length;
6389
+ this.iter(function (line) {
6390
+ var sz = line.text.length + sepSize;
6391
+ if (sz > off) { ch = off; return true }
6392
+ off -= sz;
6393
+ ++lineNo$$1;
6394
+ });
6395
+ return clipPos(this, Pos(lineNo$$1, ch))
6396
+ },
6397
+ indexFromPos: function (coords) {
6398
+ coords = clipPos(this, coords);
6399
+ var index = coords.ch;
6400
+ if (coords.line < this.first || coords.ch < 0) { return 0 }
6401
+ var sepSize = this.lineSeparator().length;
6402
+ this.iter(this.first, coords.line, function (line) { // iter aborts when callback returns a truthy value
6403
+ index += line.text.length + sepSize;
6404
+ });
6405
+ return index
6406
+ },
6407
+
6408
+ copy: function(copyHistory) {
6409
+ var doc = new Doc(getLines(this, this.first, this.first + this.size),
6410
+ this.modeOption, this.first, this.lineSep, this.direction);
6411
+ doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft;
6412
+ doc.sel = this.sel;
6413
+ doc.extend = false;
6414
+ if (copyHistory) {
6415
+ doc.history.undoDepth = this.history.undoDepth;
6416
+ doc.setHistory(this.getHistory());
6417
+ }
6418
+ return doc
6419
+ },
6420
+
6421
+ linkedDoc: function(options) {
6422
+ if (!options) { options = {}; }
6423
+ var from = this.first, to = this.first + this.size;
6424
+ if (options.from != null && options.from > from) { from = options.from; }
6425
+ if (options.to != null && options.to < to) { to = options.to; }
6426
+ var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from, this.lineSep, this.direction);
6427
+ if (options.sharedHist) { copy.history = this.history
6428
+ ; }(this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist});
6429
+ copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}];
6430
+ copySharedMarkers(copy, findSharedMarkers(this));
6431
+ return copy
6432
+ },
6433
+ unlinkDoc: function(other) {
6434
+ var this$1 = this;
6435
+
6436
+ if (other instanceof CodeMirror) { other = other.doc; }
6437
+ if (this.linked) { for (var i = 0; i < this.linked.length; ++i) {
6438
+ var link = this$1.linked[i];
6439
+ if (link.doc != other) { continue }
6440
+ this$1.linked.splice(i, 1);
6441
+ other.unlinkDoc(this$1);
6442
+ detachSharedMarkers(findSharedMarkers(this$1));
6443
+ break
6444
+ } }
6445
+ // If the histories were shared, split them again
6446
+ if (other.history == this.history) {
6447
+ var splitIds = [other.id];
6448
+ linkedDocs(other, function (doc) { return splitIds.push(doc.id); }, true);
6449
+ other.history = new History(null);
6450
+ other.history.done = copyHistoryArray(this.history.done, splitIds);
6451
+ other.history.undone = copyHistoryArray(this.history.undone, splitIds);
6452
+ }
6453
+ },
6454
+ iterLinkedDocs: function(f) {linkedDocs(this, f);},
6455
+
6456
+ getMode: function() {return this.mode},
6457
+ getEditor: function() {return this.cm},
6458
+
6459
+ splitLines: function(str) {
6460
+ if (this.lineSep) { return str.split(this.lineSep) }
6461
+ return splitLinesAuto(str)
6462
+ },
6463
+ lineSeparator: function() { return this.lineSep || "\n" },
6464
+
6465
+ setDirection: docMethodOp(function (dir) {
6466
+ if (dir != "rtl") { dir = "ltr"; }
6467
+ if (dir == this.direction) { return }
6468
+ this.direction = dir;
6469
+ this.iter(function (line) { return line.order = null; });
6470
+ if (this.cm) { directionChanged(this.cm); }
6471
+ })
6472
+ });
6473
+
6474
+ // Public alias.
6475
+ Doc.prototype.eachLine = Doc.prototype.iter;
6476
+
6477
+ // Kludge to work around strange IE behavior where it'll sometimes
6478
+ // re-fire a series of drag-related events right after the drop (#1551)
6479
+ var lastDrop = 0;
6480
+
6481
+ function onDrop(e) {
6482
+ var cm = this;
6483
+ clearDragCursor(cm);
6484
+ if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
6485
+ { return }
6486
+ e_preventDefault(e);
6487
+ if (ie) { lastDrop = +new Date; }
6488
+ var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
6489
+ if (!pos || cm.isReadOnly()) { return }
6490
+ // Might be a file drop, in which case we simply extract the text
6491
+ // and insert it.
6492
+ if (files && files.length && window.FileReader && window.File) {
6493
+ var n = files.length, text = Array(n), read = 0;
6494
+ var loadFile = function (file, i) {
6495
+ if (cm.options.allowDropFileTypes &&
6496
+ indexOf(cm.options.allowDropFileTypes, file.type) == -1)
6497
+ { return }
6498
+
6499
+ var reader = new FileReader;
6500
+ reader.onload = operation(cm, function () {
6501
+ var content = reader.result;
6502
+ if (/[\x00-\x08\x0e-\x1f]{2}/.test(content)) { content = ""; }
6503
+ text[i] = content;
6504
+ if (++read == n) {
6505
+ pos = clipPos(cm.doc, pos);
6506
+ var change = {from: pos, to: pos,
6507
+ text: cm.doc.splitLines(text.join(cm.doc.lineSeparator())),
6508
+ origin: "paste"};
6509
+ makeChange(cm.doc, change);
6510
+ setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change)));
6511
+ }
6512
+ });
6513
+ reader.readAsText(file);
6514
+ };
6515
+ for (var i = 0; i < n; ++i) { loadFile(files[i], i); }
6516
+ } else { // Normal drop
6517
+ // Don't do a replace if the drop happened inside of the selected text.
6518
+ if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
6519
+ cm.state.draggingText(e);
6520
+ // Ensure the editor is re-focused
6521
+ setTimeout(function () { return cm.display.input.focus(); }, 20);
6522
+ return
6523
+ }
6524
+ try {
6525
+ var text$1 = e.dataTransfer.getData("Text");
6526
+ if (text$1) {
6527
+ var selected;
6528
+ if (cm.state.draggingText && !cm.state.draggingText.copy)
6529
+ { selected = cm.listSelections(); }
6530
+ setSelectionNoUndo(cm.doc, simpleSelection(pos, pos));
6531
+ if (selected) { for (var i$1 = 0; i$1 < selected.length; ++i$1)
6532
+ { replaceRange(cm.doc, "", selected[i$1].anchor, selected[i$1].head, "drag"); } }
6533
+ cm.replaceSelection(text$1, "around", "paste");
6534
+ cm.display.input.focus();
6535
+ }
6536
+ }
6537
+ catch(e){}
6538
+ }
6539
+ }
6540
+
6541
+ function onDragStart(cm, e) {
6542
+ if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return }
6543
+ if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) { return }
6544
+
6545
+ e.dataTransfer.setData("Text", cm.getSelection());
6546
+ e.dataTransfer.effectAllowed = "copyMove";
6547
+
6548
+ // Use dummy image instead of default browsers image.
6549
+ // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
6550
+ if (e.dataTransfer.setDragImage && !safari) {
6551
+ var img = elt("img", null, null, "position: fixed; left: 0; top: 0;");
6552
+ img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
6553
+ if (presto) {
6554
+ img.width = img.height = 1;
6555
+ cm.display.wrapper.appendChild(img);
6556
+ // Force a relayout, or Opera won't use our image for some obscure reason
6557
+ img._top = img.offsetTop;
6558
+ }
6559
+ e.dataTransfer.setDragImage(img, 0, 0);
6560
+ if (presto) { img.parentNode.removeChild(img); }
6561
+ }
6562
+ }
6563
+
6564
+ function onDragOver(cm, e) {
6565
+ var pos = posFromMouse(cm, e);
6566
+ if (!pos) { return }
6567
+ var frag = document.createDocumentFragment();
6568
+ drawSelectionCursor(cm, pos, frag);
6569
+ if (!cm.display.dragCursor) {
6570
+ cm.display.dragCursor = elt("div", null, "CodeMirror-cursors CodeMirror-dragcursors");
6571
+ cm.display.lineSpace.insertBefore(cm.display.dragCursor, cm.display.cursorDiv);
6572
+ }
6573
+ removeChildrenAndAdd(cm.display.dragCursor, frag);
6574
+ }
6575
+
6576
+ function clearDragCursor(cm) {
6577
+ if (cm.display.dragCursor) {
6578
+ cm.display.lineSpace.removeChild(cm.display.dragCursor);
6579
+ cm.display.dragCursor = null;
6580
+ }
6581
+ }
6582
+
6583
+ // These must be handled carefully, because naively registering a
6584
+ // handler for each editor will cause the editors to never be
6585
+ // garbage collected.
6586
+
6587
+ function forEachCodeMirror(f) {
6588
+ if (!document.getElementsByClassName) { return }
6589
+ var byClass = document.getElementsByClassName("CodeMirror"), editors = [];
6590
+ for (var i = 0; i < byClass.length; i++) {
6591
+ var cm = byClass[i].CodeMirror;
6592
+ if (cm) { editors.push(cm); }
6593
+ }
6594
+ if (editors.length) { editors[0].operation(function () {
6595
+ for (var i = 0; i < editors.length; i++) { f(editors[i]); }
6596
+ }); }
6597
+ }
6598
+
6599
+ var globalsRegistered = false;
6600
+ function ensureGlobalHandlers() {
6601
+ if (globalsRegistered) { return }
6602
+ registerGlobalHandlers();
6603
+ globalsRegistered = true;
6604
+ }
6605
+ function registerGlobalHandlers() {
6606
+ // When the window resizes, we need to refresh active editors.
6607
+ var resizeTimer;
6608
+ on(window, "resize", function () {
6609
+ if (resizeTimer == null) { resizeTimer = setTimeout(function () {
6610
+ resizeTimer = null;
6611
+ forEachCodeMirror(onResize);
6612
+ }, 100); }
6613
+ });
6614
+ // When the window loses focus, we want to show the editor as blurred
6615
+ on(window, "blur", function () { return forEachCodeMirror(onBlur); });
6616
+ }
6617
+ // Called when the window resizes
6618
+ function onResize(cm) {
6619
+ var d = cm.display;
6620
+ // Might be a text scaling operation, clear size caches.
6621
+ d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
6622
+ d.scrollbarsClipped = false;
6623
+ cm.setSize();
6624
+ }
6625
+
6626
+ var keyNames = {
6627
+ 3: "Pause", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
6628
+ 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
6629
+ 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
6630
+ 46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod",
6631
+ 106: "*", 107: "=", 109: "-", 110: ".", 111: "/", 127: "Delete", 145: "ScrollLock",
6632
+ 173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
6633
+ 221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete",
6634
+ 63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"
6635
+ };
6636
+
6637
+ // Number keys
6638
+ for (var i = 0; i < 10; i++) { keyNames[i + 48] = keyNames[i + 96] = String(i); }
6639
+ // Alphabetic keys
6640
+ for (var i$1 = 65; i$1 <= 90; i$1++) { keyNames[i$1] = String.fromCharCode(i$1); }
6641
+ // Function keys
6642
+ for (var i$2 = 1; i$2 <= 12; i$2++) { keyNames[i$2 + 111] = keyNames[i$2 + 63235] = "F" + i$2; }
6643
+
6644
+ var keyMap = {};
6645
+
6646
+ keyMap.basic = {
6647
+ "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
6648
+ "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
6649
+ "Delete": "delCharAfter", "Backspace": "delCharBefore", "Shift-Backspace": "delCharBefore",
6650
+ "Tab": "defaultTab", "Shift-Tab": "indentAuto",
6651
+ "Enter": "newlineAndIndent", "Insert": "toggleOverwrite",
6652
+ "Esc": "singleSelection"
6653
+ };
6654
+ // Note that the save and find-related commands aren't defined by
6655
+ // default. User code or addons can define them. Unknown commands
6656
+ // are simply ignored.
6657
+ keyMap.pcDefault = {
6658
+ "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
6659
+ "Ctrl-Home": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Up": "goLineUp", "Ctrl-Down": "goLineDown",
6660
+ "Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
6661
+ "Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find",
6662
+ "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
6663
+ "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
6664
+ "Ctrl-U": "undoSelection", "Shift-Ctrl-U": "redoSelection", "Alt-U": "redoSelection",
6665
+ "fallthrough": "basic"
6666
+ };
6667
+ // Very basic readline/emacs-style bindings, which are standard on Mac.
6668
+ keyMap.emacsy = {
6669
+ "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
6670
+ "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
6671
+ "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
6672
+ "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars",
6673
+ "Ctrl-O": "openLine"
6674
+ };
6675
+ keyMap.macDefault = {
6676
+ "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
6677
+ "Cmd-Home": "goDocStart", "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
6678
+ "Alt-Right": "goGroupRight", "Cmd-Left": "goLineLeft", "Cmd-Right": "goLineRight", "Alt-Backspace": "delGroupBefore",
6679
+ "Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find",
6680
+ "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
6681
+ "Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight",
6682
+ "Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Ctrl-Up": "goDocStart", "Ctrl-Down": "goDocEnd",
6683
+ "fallthrough": ["basic", "emacsy"]
6684
+ };
6685
+ keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
6686
+
6687
+ // KEYMAP DISPATCH
6688
+
6689
+ function normalizeKeyName(name) {
6690
+ var parts = name.split(/-(?!$)/);
6691
+ name = parts[parts.length - 1];
6692
+ var alt, ctrl, shift, cmd;
6693
+ for (var i = 0; i < parts.length - 1; i++) {
6694
+ var mod = parts[i];
6695
+ if (/^(cmd|meta|m)$/i.test(mod)) { cmd = true; }
6696
+ else if (/^a(lt)?$/i.test(mod)) { alt = true; }
6697
+ else if (/^(c|ctrl|control)$/i.test(mod)) { ctrl = true; }
6698
+ else if (/^s(hift)?$/i.test(mod)) { shift = true; }
6699
+ else { throw new Error("Unrecognized modifier name: " + mod) }
6700
+ }
6701
+ if (alt) { name = "Alt-" + name; }
6702
+ if (ctrl) { name = "Ctrl-" + name; }
6703
+ if (cmd) { name = "Cmd-" + name; }
6704
+ if (shift) { name = "Shift-" + name; }
6705
+ return name
6706
+ }
6707
+
6708
+ // This is a kludge to keep keymaps mostly working as raw objects
6709
+ // (backwards compatibility) while at the same time support features
6710
+ // like normalization and multi-stroke key bindings. It compiles a
6711
+ // new normalized keymap, and then updates the old object to reflect
6712
+ // this.
6713
+ function normalizeKeyMap(keymap) {
6714
+ var copy = {};
6715
+ for (var keyname in keymap) { if (keymap.hasOwnProperty(keyname)) {
6716
+ var value = keymap[keyname];
6717
+ if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) { continue }
6718
+ if (value == "...") { delete keymap[keyname]; continue }
6719
+
6720
+ var keys = map(keyname.split(" "), normalizeKeyName);
6721
+ for (var i = 0; i < keys.length; i++) {
6722
+ var val = (void 0), name = (void 0);
6723
+ if (i == keys.length - 1) {
6724
+ name = keys.join(" ");
6725
+ val = value;
6726
+ } else {
6727
+ name = keys.slice(0, i + 1).join(" ");
6728
+ val = "...";
6729
+ }
6730
+ var prev = copy[name];
6731
+ if (!prev) { copy[name] = val; }
6732
+ else if (prev != val) { throw new Error("Inconsistent bindings for " + name) }
6733
+ }
6734
+ delete keymap[keyname];
6735
+ } }
6736
+ for (var prop in copy) { keymap[prop] = copy[prop]; }
6737
+ return keymap
6738
+ }
6739
+
6740
+ function lookupKey(key, map$$1, handle, context) {
6741
+ map$$1 = getKeyMap(map$$1);
6742
+ var found = map$$1.call ? map$$1.call(key, context) : map$$1[key];
6743
+ if (found === false) { return "nothing" }
6744
+ if (found === "...") { return "multi" }
6745
+ if (found != null && handle(found)) { return "handled" }
6746
+
6747
+ if (map$$1.fallthrough) {
6748
+ if (Object.prototype.toString.call(map$$1.fallthrough) != "[object Array]")
6749
+ { return lookupKey(key, map$$1.fallthrough, handle, context) }
6750
+ for (var i = 0; i < map$$1.fallthrough.length; i++) {
6751
+ var result = lookupKey(key, map$$1.fallthrough[i], handle, context);
6752
+ if (result) { return result }
6753
+ }
6754
+ }
6755
+ }
6756
+
6757
+ // Modifier key presses don't count as 'real' key presses for the
6758
+ // purpose of keymap fallthrough.
6759
+ function isModifierKey(value) {
6760
+ var name = typeof value == "string" ? value : keyNames[value.keyCode];
6761
+ return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod"
6762
+ }
6763
+
6764
+ function addModifierNames(name, event, noShift) {
6765
+ var base = name;
6766
+ if (event.altKey && base != "Alt") { name = "Alt-" + name; }
6767
+ if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") { name = "Ctrl-" + name; }
6768
+ if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Cmd") { name = "Cmd-" + name; }
6769
+ if (!noShift && event.shiftKey && base != "Shift") { name = "Shift-" + name; }
6770
+ return name
6771
+ }
6772
+
6773
+ // Look up the name of a key as indicated by an event object.
6774
+ function keyName(event, noShift) {
6775
+ if (presto && event.keyCode == 34 && event["char"]) { return false }
6776
+ var name = keyNames[event.keyCode];
6777
+ if (name == null || event.altGraphKey) { return false }
6778
+ // Ctrl-ScrollLock has keyCode 3, same as Ctrl-Pause,
6779
+ // so we'll use event.code when available (Chrome 48+, FF 38+, Safari 10.1+)
6780
+ if (event.keyCode == 3 && event.code) { name = event.code; }
6781
+ return addModifierNames(name, event, noShift)
6782
+ }
6783
+
6784
+ function getKeyMap(val) {
6785
+ return typeof val == "string" ? keyMap[val] : val
6786
+ }
6787
+
6788
+ // Helper for deleting text near the selection(s), used to implement
6789
+ // backspace, delete, and similar functionality.
6790
+ function deleteNearSelection(cm, compute) {
6791
+ var ranges = cm.doc.sel.ranges, kill = [];
6792
+ // Build up a set of ranges to kill first, merging overlapping
6793
+ // ranges.
6794
+ for (var i = 0; i < ranges.length; i++) {
6795
+ var toKill = compute(ranges[i]);
6796
+ while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
6797
+ var replaced = kill.pop();
6798
+ if (cmp(replaced.from, toKill.from) < 0) {
6799
+ toKill.from = replaced.from;
6800
+ break
6801
+ }
6802
+ }
6803
+ kill.push(toKill);
6804
+ }
6805
+ // Next, remove those actual ranges.
6806
+ runInOp(cm, function () {
6807
+ for (var i = kill.length - 1; i >= 0; i--)
6808
+ { replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete"); }
6809
+ ensureCursorVisible(cm);
6810
+ });
6811
+ }
6812
+
6813
+ function moveCharLogically(line, ch, dir) {
6814
+ var target = skipExtendingChars(line.text, ch + dir, dir);
6815
+ return target < 0 || target > line.text.length ? null : target
6816
+ }
6817
+
6818
+ function moveLogically(line, start, dir) {
6819
+ var ch = moveCharLogically(line, start.ch, dir);
6820
+ return ch == null ? null : new Pos(start.line, ch, dir < 0 ? "after" : "before")
6821
+ }
6822
+
6823
+ function endOfLine(visually, cm, lineObj, lineNo, dir) {
6824
+ if (visually) {
6825
+ var order = getOrder(lineObj, cm.doc.direction);
6826
+ if (order) {
6827
+ var part = dir < 0 ? lst(order) : order[0];
6828
+ var moveInStorageOrder = (dir < 0) == (part.level == 1);
6829
+ var sticky = moveInStorageOrder ? "after" : "before";
6830
+ var ch;
6831
+ // With a wrapped rtl chunk (possibly spanning multiple bidi parts),
6832
+ // it could be that the last bidi part is not on the last visual line,
6833
+ // since visual lines contain content order-consecutive chunks.
6834
+ // Thus, in rtl, we are looking for the first (content-order) character
6835
+ // in the rtl chunk that is on the last line (that is, the same line
6836
+ // as the last (content-order) character).
6837
+ if (part.level > 0 || cm.doc.direction == "rtl") {
6838
+ var prep = prepareMeasureForLine(cm, lineObj);
6839
+ ch = dir < 0 ? lineObj.text.length - 1 : 0;
6840
+ var targetTop = measureCharPrepared(cm, prep, ch).top;
6841
+ ch = findFirst(function (ch) { return measureCharPrepared(cm, prep, ch).top == targetTop; }, (dir < 0) == (part.level == 1) ? part.from : part.to - 1, ch);
6842
+ if (sticky == "before") { ch = moveCharLogically(lineObj, ch, 1); }
6843
+ } else { ch = dir < 0 ? part.to : part.from; }
6844
+ return new Pos(lineNo, ch, sticky)
6845
+ }
6846
+ }
6847
+ return new Pos(lineNo, dir < 0 ? lineObj.text.length : 0, dir < 0 ? "before" : "after")
6848
+ }
6849
+
6850
+ function moveVisually(cm, line, start, dir) {
6851
+ var bidi = getOrder(line, cm.doc.direction);
6852
+ if (!bidi) { return moveLogically(line, start, dir) }
6853
+ if (start.ch >= line.text.length) {
6854
+ start.ch = line.text.length;
6855
+ start.sticky = "before";
6856
+ } else if (start.ch <= 0) {
6857
+ start.ch = 0;
6858
+ start.sticky = "after";
6859
+ }
6860
+ var partPos = getBidiPartAt(bidi, start.ch, start.sticky), part = bidi[partPos];
6861
+ if (cm.doc.direction == "ltr" && part.level % 2 == 0 && (dir > 0 ? part.to > start.ch : part.from < start.ch)) {
6862
+ // Case 1: We move within an ltr part in an ltr editor. Even with wrapped lines,
6863
+ // nothing interesting happens.
6864
+ return moveLogically(line, start, dir)
6865
+ }
6866
+
6867
+ var mv = function (pos, dir) { return moveCharLogically(line, pos instanceof Pos ? pos.ch : pos, dir); };
6868
+ var prep;
6869
+ var getWrappedLineExtent = function (ch) {
6870
+ if (!cm.options.lineWrapping) { return {begin: 0, end: line.text.length} }
6871
+ prep = prep || prepareMeasureForLine(cm, line);
6872
+ return wrappedLineExtentChar(cm, line, prep, ch)
6873
+ };
6874
+ var wrappedLineExtent = getWrappedLineExtent(start.sticky == "before" ? mv(start, -1) : start.ch);
6875
+
6876
+ if (cm.doc.direction == "rtl" || part.level == 1) {
6877
+ var moveInStorageOrder = (part.level == 1) == (dir < 0);
6878
+ var ch = mv(start, moveInStorageOrder ? 1 : -1);
6879
+ if (ch != null && (!moveInStorageOrder ? ch >= part.from && ch >= wrappedLineExtent.begin : ch <= part.to && ch <= wrappedLineExtent.end)) {
6880
+ // Case 2: We move within an rtl part or in an rtl editor on the same visual line
6881
+ var sticky = moveInStorageOrder ? "before" : "after";
6882
+ return new Pos(start.line, ch, sticky)
6883
+ }
6884
+ }
6885
+
6886
+ // Case 3: Could not move within this bidi part in this visual line, so leave
6887
+ // the current bidi part
6888
+
6889
+ var searchInVisualLine = function (partPos, dir, wrappedLineExtent) {
6890
+ var getRes = function (ch, moveInStorageOrder) { return moveInStorageOrder
6891
+ ? new Pos(start.line, mv(ch, 1), "before")
6892
+ : new Pos(start.line, ch, "after"); };
6893
+
6894
+ for (; partPos >= 0 && partPos < bidi.length; partPos += dir) {
6895
+ var part = bidi[partPos];
6896
+ var moveInStorageOrder = (dir > 0) == (part.level != 1);
6897
+ var ch = moveInStorageOrder ? wrappedLineExtent.begin : mv(wrappedLineExtent.end, -1);
6898
+ if (part.from <= ch && ch < part.to) { return getRes(ch, moveInStorageOrder) }
6899
+ ch = moveInStorageOrder ? part.from : mv(part.to, -1);
6900
+ if (wrappedLineExtent.begin <= ch && ch < wrappedLineExtent.end) { return getRes(ch, moveInStorageOrder) }
6901
+ }
6902
+ };
6903
+
6904
+ // Case 3a: Look for other bidi parts on the same visual line
6905
+ var res = searchInVisualLine(partPos + dir, dir, wrappedLineExtent);
6906
+ if (res) { return res }
6907
+
6908
+ // Case 3b: Look for other bidi parts on the next visual line
6909
+ var nextCh = dir > 0 ? wrappedLineExtent.end : mv(wrappedLineExtent.begin, -1);
6910
+ if (nextCh != null && !(dir > 0 && nextCh == line.text.length)) {
6911
+ res = searchInVisualLine(dir > 0 ? 0 : bidi.length - 1, dir, getWrappedLineExtent(nextCh));
6912
+ if (res) { return res }
6913
+ }
6914
+
6915
+ // Case 4: Nowhere to move
6916
+ return null
6917
+ }
6918
+
6919
+ // Commands are parameter-less actions that can be performed on an
6920
+ // editor, mostly used for keybindings.
6921
+ var commands = {
6922
+ selectAll: selectAll,
6923
+ singleSelection: function (cm) { return cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll); },
6924
+ killLine: function (cm) { return deleteNearSelection(cm, function (range) {
6925
+ if (range.empty()) {
6926
+ var len = getLine(cm.doc, range.head.line).text.length;
6927
+ if (range.head.ch == len && range.head.line < cm.lastLine())
6928
+ { return {from: range.head, to: Pos(range.head.line + 1, 0)} }
6929
+ else
6930
+ { return {from: range.head, to: Pos(range.head.line, len)} }
6931
+ } else {
6932
+ return {from: range.from(), to: range.to()}
6933
+ }
6934
+ }); },
6935
+ deleteLine: function (cm) { return deleteNearSelection(cm, function (range) { return ({
6936
+ from: Pos(range.from().line, 0),
6937
+ to: clipPos(cm.doc, Pos(range.to().line + 1, 0))
6938
+ }); }); },
6939
+ delLineLeft: function (cm) { return deleteNearSelection(cm, function (range) { return ({
6940
+ from: Pos(range.from().line, 0), to: range.from()
6941
+ }); }); },
6942
+ delWrappedLineLeft: function (cm) { return deleteNearSelection(cm, function (range) {
6943
+ var top = cm.charCoords(range.head, "div").top + 5;
6944
+ var leftPos = cm.coordsChar({left: 0, top: top}, "div");
6945
+ return {from: leftPos, to: range.from()}
6946
+ }); },
6947
+ delWrappedLineRight: function (cm) { return deleteNearSelection(cm, function (range) {
6948
+ var top = cm.charCoords(range.head, "div").top + 5;
6949
+ var rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div");
6950
+ return {from: range.from(), to: rightPos }
6951
+ }); },
6952
+ undo: function (cm) { return cm.undo(); },
6953
+ redo: function (cm) { return cm.redo(); },
6954
+ undoSelection: function (cm) { return cm.undoSelection(); },
6955
+ redoSelection: function (cm) { return cm.redoSelection(); },
6956
+ goDocStart: function (cm) { return cm.extendSelection(Pos(cm.firstLine(), 0)); },
6957
+ goDocEnd: function (cm) { return cm.extendSelection(Pos(cm.lastLine())); },
6958
+ goLineStart: function (cm) { return cm.extendSelectionsBy(function (range) { return lineStart(cm, range.head.line); },
6959
+ {origin: "+move", bias: 1}
6960
+ ); },
6961
+ goLineStartSmart: function (cm) { return cm.extendSelectionsBy(function (range) { return lineStartSmart(cm, range.head); },
6962
+ {origin: "+move", bias: 1}
6963
+ ); },
6964
+ goLineEnd: function (cm) { return cm.extendSelectionsBy(function (range) { return lineEnd(cm, range.head.line); },
6965
+ {origin: "+move", bias: -1}
6966
+ ); },
6967
+ goLineRight: function (cm) { return cm.extendSelectionsBy(function (range) {
6968
+ var top = cm.cursorCoords(range.head, "div").top + 5;
6969
+ return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div")
6970
+ }, sel_move); },
6971
+ goLineLeft: function (cm) { return cm.extendSelectionsBy(function (range) {
6972
+ var top = cm.cursorCoords(range.head, "div").top + 5;
6973
+ return cm.coordsChar({left: 0, top: top}, "div")
6974
+ }, sel_move); },
6975
+ goLineLeftSmart: function (cm) { return cm.extendSelectionsBy(function (range) {
6976
+ var top = cm.cursorCoords(range.head, "div").top + 5;
6977
+ var pos = cm.coordsChar({left: 0, top: top}, "div");
6978
+ if (pos.ch < cm.getLine(pos.line).search(/\S/)) { return lineStartSmart(cm, range.head) }
6979
+ return pos
6980
+ }, sel_move); },
6981
+ goLineUp: function (cm) { return cm.moveV(-1, "line"); },
6982
+ goLineDown: function (cm) { return cm.moveV(1, "line"); },
6983
+ goPageUp: function (cm) { return cm.moveV(-1, "page"); },
6984
+ goPageDown: function (cm) { return cm.moveV(1, "page"); },
6985
+ goCharLeft: function (cm) { return cm.moveH(-1, "char"); },
6986
+ goCharRight: function (cm) { return cm.moveH(1, "char"); },
6987
+ goColumnLeft: function (cm) { return cm.moveH(-1, "column"); },
6988
+ goColumnRight: function (cm) { return cm.moveH(1, "column"); },
6989
+ goWordLeft: function (cm) { return cm.moveH(-1, "word"); },
6990
+ goGroupRight: function (cm) { return cm.moveH(1, "group"); },
6991
+ goGroupLeft: function (cm) { return cm.moveH(-1, "group"); },
6992
+ goWordRight: function (cm) { return cm.moveH(1, "word"); },
6993
+ delCharBefore: function (cm) { return cm.deleteH(-1, "char"); },
6994
+ delCharAfter: function (cm) { return cm.deleteH(1, "char"); },
6995
+ delWordBefore: function (cm) { return cm.deleteH(-1, "word"); },
6996
+ delWordAfter: function (cm) { return cm.deleteH(1, "word"); },
6997
+ delGroupBefore: function (cm) { return cm.deleteH(-1, "group"); },
6998
+ delGroupAfter: function (cm) { return cm.deleteH(1, "group"); },
6999
+ indentAuto: function (cm) { return cm.indentSelection("smart"); },
7000
+ indentMore: function (cm) { return cm.indentSelection("add"); },
7001
+ indentLess: function (cm) { return cm.indentSelection("subtract"); },
7002
+ insertTab: function (cm) { return cm.replaceSelection("\t"); },
7003
+ insertSoftTab: function (cm) {
7004
+ var spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize;
7005
+ for (var i = 0; i < ranges.length; i++) {
7006
+ var pos = ranges[i].from();
7007
+ var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize);
7008
+ spaces.push(spaceStr(tabSize - col % tabSize));
7009
+ }
7010
+ cm.replaceSelections(spaces);
7011
+ },
7012
+ defaultTab: function (cm) {
7013
+ if (cm.somethingSelected()) { cm.indentSelection("add"); }
7014
+ else { cm.execCommand("insertTab"); }
7015
+ },
7016
+ // Swap the two chars left and right of each selection's head.
7017
+ // Move cursor behind the two swapped characters afterwards.
7018
+ //
7019
+ // Doesn't consider line feeds a character.
7020
+ // Doesn't scan more than one line above to find a character.
7021
+ // Doesn't do anything on an empty line.
7022
+ // Doesn't do anything with non-empty selections.
7023
+ transposeChars: function (cm) { return runInOp(cm, function () {
7024
+ var ranges = cm.listSelections(), newSel = [];
7025
+ for (var i = 0; i < ranges.length; i++) {
7026
+ if (!ranges[i].empty()) { continue }
7027
+ var cur = ranges[i].head, line = getLine(cm.doc, cur.line).text;
7028
+ if (line) {
7029
+ if (cur.ch == line.length) { cur = new Pos(cur.line, cur.ch - 1); }
7030
+ if (cur.ch > 0) {
7031
+ cur = new Pos(cur.line, cur.ch + 1);
7032
+ cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
7033
+ Pos(cur.line, cur.ch - 2), cur, "+transpose");
7034
+ } else if (cur.line > cm.doc.first) {
7035
+ var prev = getLine(cm.doc, cur.line - 1).text;
7036
+ if (prev) {
7037
+ cur = new Pos(cur.line, 1);
7038
+ cm.replaceRange(line.charAt(0) + cm.doc.lineSeparator() +
7039
+ prev.charAt(prev.length - 1),
7040
+ Pos(cur.line - 1, prev.length - 1), cur, "+transpose");
7041
+ }
7042
+ }
7043
+ }
7044
+ newSel.push(new Range(cur, cur));
7045
+ }
7046
+ cm.setSelections(newSel);
7047
+ }); },
7048
+ newlineAndIndent: function (cm) { return runInOp(cm, function () {
7049
+ var sels = cm.listSelections();
7050
+ for (var i = sels.length - 1; i >= 0; i--)
7051
+ { cm.replaceRange(cm.doc.lineSeparator(), sels[i].anchor, sels[i].head, "+input"); }
7052
+ sels = cm.listSelections();
7053
+ for (var i$1 = 0; i$1 < sels.length; i$1++)
7054
+ { cm.indentLine(sels[i$1].from().line, null, true); }
7055
+ ensureCursorVisible(cm);
7056
+ }); },
7057
+ openLine: function (cm) { return cm.replaceSelection("\n", "start"); },
7058
+ toggleOverwrite: function (cm) { return cm.toggleOverwrite(); }
7059
+ };
7060
+
7061
+
7062
+ function lineStart(cm, lineN) {
7063
+ var line = getLine(cm.doc, lineN);
7064
+ var visual = visualLine(line);
7065
+ if (visual != line) { lineN = lineNo(visual); }
7066
+ return endOfLine(true, cm, visual, lineN, 1)
7067
+ }
7068
+ function lineEnd(cm, lineN) {
7069
+ var line = getLine(cm.doc, lineN);
7070
+ var visual = visualLineEnd(line);
7071
+ if (visual != line) { lineN = lineNo(visual); }
7072
+ return endOfLine(true, cm, line, lineN, -1)
7073
+ }
7074
+ function lineStartSmart(cm, pos) {
7075
+ var start = lineStart(cm, pos.line);
7076
+ var line = getLine(cm.doc, start.line);
7077
+ var order = getOrder(line, cm.doc.direction);
7078
+ if (!order || order[0].level == 0) {
7079
+ var firstNonWS = Math.max(0, line.text.search(/\S/));
7080
+ var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch;
7081
+ return Pos(start.line, inWS ? 0 : firstNonWS, start.sticky)
7082
+ }
7083
+ return start
7084
+ }
7085
+
7086
+ // Run a handler that was bound to a key.
7087
+ function doHandleBinding(cm, bound, dropShift) {
7088
+ if (typeof bound == "string") {
7089
+ bound = commands[bound];
7090
+ if (!bound) { return false }
7091
+ }
7092
+ // Ensure previous input has been read, so that the handler sees a
7093
+ // consistent view of the document
7094
+ cm.display.input.ensurePolled();
7095
+ var prevShift = cm.display.shift, done = false;
7096
+ try {
7097
+ if (cm.isReadOnly()) { cm.state.suppressEdits = true; }
7098
+ if (dropShift) { cm.display.shift = false; }
7099
+ done = bound(cm) != Pass;
7100
+ } finally {
7101
+ cm.display.shift = prevShift;
7102
+ cm.state.suppressEdits = false;
7103
+ }
7104
+ return done
7105
+ }
7106
+
7107
+ function lookupKeyForEditor(cm, name, handle) {
7108
+ for (var i = 0; i < cm.state.keyMaps.length; i++) {
7109
+ var result = lookupKey(name, cm.state.keyMaps[i], handle, cm);
7110
+ if (result) { return result }
7111
+ }
7112
+ return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm))
7113
+ || lookupKey(name, cm.options.keyMap, handle, cm)
7114
+ }
7115
+
7116
+ // Note that, despite the name, this function is also used to check
7117
+ // for bound mouse clicks.
7118
+
7119
+ var stopSeq = new Delayed;
7120
+
7121
+ function dispatchKey(cm, name, e, handle) {
7122
+ var seq = cm.state.keySeq;
7123
+ if (seq) {
7124
+ if (isModifierKey(name)) { return "handled" }
7125
+ if (/\'$/.test(name))
7126
+ { cm.state.keySeq = null; }
7127
+ else
7128
+ { stopSeq.set(50, function () {
7129
+ if (cm.state.keySeq == seq) {
7130
+ cm.state.keySeq = null;
7131
+ cm.display.input.reset();
7132
+ }
7133
+ }); }
7134
+ if (dispatchKeyInner(cm, seq + " " + name, e, handle)) { return true }
7135
+ }
7136
+ return dispatchKeyInner(cm, name, e, handle)
7137
+ }
7138
+
7139
+ function dispatchKeyInner(cm, name, e, handle) {
7140
+ var result = lookupKeyForEditor(cm, name, handle);
7141
+
7142
+ if (result == "multi")
7143
+ { cm.state.keySeq = name; }
7144
+ if (result == "handled")
7145
+ { signalLater(cm, "keyHandled", cm, name, e); }
7146
+
7147
+ if (result == "handled" || result == "multi") {
7148
+ e_preventDefault(e);
7149
+ restartBlink(cm);
7150
+ }
7151
+
7152
+ return !!result
7153
+ }
7154
+
7155
+ // Handle a key from the keydown event.
7156
+ function handleKeyBinding(cm, e) {
7157
+ var name = keyName(e, true);
7158
+ if (!name) { return false }
7159
+
7160
+ if (e.shiftKey && !cm.state.keySeq) {
7161
+ // First try to resolve full name (including 'Shift-'). Failing
7162
+ // that, see if there is a cursor-motion command (starting with
7163
+ // 'go') bound to the keyname without 'Shift-'.
7164
+ return dispatchKey(cm, "Shift-" + name, e, function (b) { return doHandleBinding(cm, b, true); })
7165
+ || dispatchKey(cm, name, e, function (b) {
7166
+ if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
7167
+ { return doHandleBinding(cm, b) }
7168
+ })
7169
+ } else {
7170
+ return dispatchKey(cm, name, e, function (b) { return doHandleBinding(cm, b); })
7171
+ }
7172
+ }
7173
+
7174
+ // Handle a key from the keypress event
7175
+ function handleCharBinding(cm, e, ch) {
7176
+ return dispatchKey(cm, "'" + ch + "'", e, function (b) { return doHandleBinding(cm, b, true); })
7177
+ }
7178
+
7179
+ var lastStoppedKey = null;
7180
+ function onKeyDown(e) {
7181
+ var cm = this;
7182
+ cm.curOp.focus = activeElt();
7183
+ if (signalDOMEvent(cm, e)) { return }
7184
+ // IE does strange things with escape.
7185
+ if (ie && ie_version < 11 && e.keyCode == 27) { e.returnValue = false; }
7186
+ var code = e.keyCode;
7187
+ cm.display.shift = code == 16 || e.shiftKey;
7188
+ var handled = handleKeyBinding(cm, e);
7189
+ if (presto) {
7190
+ lastStoppedKey = handled ? code : null;
7191
+ // Opera has no cut event... we try to at least catch the key combo
7192
+ if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
7193
+ { cm.replaceSelection("", null, "cut"); }
7194
+ }
7195
+
7196
+ // Turn mouse into crosshair when Alt is held on Mac.
7197
+ if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className))
7198
+ { showCrossHair(cm); }
7199
+ }
7200
+
7201
+ function showCrossHair(cm) {
7202
+ var lineDiv = cm.display.lineDiv;
7203
+ addClass(lineDiv, "CodeMirror-crosshair");
7204
+
7205
+ function up(e) {
7206
+ if (e.keyCode == 18 || !e.altKey) {
7207
+ rmClass(lineDiv, "CodeMirror-crosshair");
7208
+ off(document, "keyup", up);
7209
+ off(document, "mouseover", up);
7210
+ }
7211
+ }
7212
+ on(document, "keyup", up);
7213
+ on(document, "mouseover", up);
7214
+ }
7215
+
7216
+ function onKeyUp(e) {
7217
+ if (e.keyCode == 16) { this.doc.sel.shift = false; }
7218
+ signalDOMEvent(this, e);
7219
+ }
7220
+
7221
+ function onKeyPress(e) {
7222
+ var cm = this;
7223
+ if (eventInWidget(cm.display, e) || signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) { return }
7224
+ var keyCode = e.keyCode, charCode = e.charCode;
7225
+ if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return}
7226
+ if ((presto && (!e.which || e.which < 10)) && handleKeyBinding(cm, e)) { return }
7227
+ var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
7228
+ // Some browsers fire keypress events for backspace
7229
+ if (ch == "\x08") { return }
7230
+ if (handleCharBinding(cm, e, ch)) { return }
7231
+ cm.display.input.onKeyPress(e);
7232
+ }
7233
+
7234
+ var DOUBLECLICK_DELAY = 400;
7235
+
7236
+ var PastClick = function(time, pos, button) {
7237
+ this.time = time;
7238
+ this.pos = pos;
7239
+ this.button = button;
7240
+ };
7241
+
7242
+ PastClick.prototype.compare = function (time, pos, button) {
7243
+ return this.time + DOUBLECLICK_DELAY > time &&
7244
+ cmp(pos, this.pos) == 0 && button == this.button
7245
+ };
7246
+
7247
+ var lastClick, lastDoubleClick;
7248
+ function clickRepeat(pos, button) {
7249
+ var now = +new Date;
7250
+ if (lastDoubleClick && lastDoubleClick.compare(now, pos, button)) {
7251
+ lastClick = lastDoubleClick = null;
7252
+ return "triple"
7253
+ } else if (lastClick && lastClick.compare(now, pos, button)) {
7254
+ lastDoubleClick = new PastClick(now, pos, button);
7255
+ lastClick = null;
7256
+ return "double"
7257
+ } else {
7258
+ lastClick = new PastClick(now, pos, button);
7259
+ lastDoubleClick = null;
7260
+ return "single"
7261
+ }
7262
+ }
7263
+
7264
+ // A mouse down can be a single click, double click, triple click,
7265
+ // start of selection drag, start of text drag, new cursor
7266
+ // (ctrl-click), rectangle drag (alt-drag), or xwin
7267
+ // middle-click-paste. Or it might be a click on something we should
7268
+ // not interfere with, such as a scrollbar or widget.
7269
+ function onMouseDown(e) {
7270
+ var cm = this, display = cm.display;
7271
+ if (signalDOMEvent(cm, e) || display.activeTouch && display.input.supportsTouch()) { return }
7272
+ display.input.ensurePolled();
7273
+ display.shift = e.shiftKey;
7274
+
7275
+ if (eventInWidget(display, e)) {
7276
+ if (!webkit) {
7277
+ // Briefly turn off draggability, to allow widgets to do
7278
+ // normal dragging things.
7279
+ display.scroller.draggable = false;
7280
+ setTimeout(function () { return display.scroller.draggable = true; }, 100);
7281
+ }
7282
+ return
7283
+ }
7284
+ if (clickInGutter(cm, e)) { return }
7285
+ var pos = posFromMouse(cm, e), button = e_button(e), repeat = pos ? clickRepeat(pos, button) : "single";
7286
+ window.focus();
7287
+
7288
+ // #3261: make sure, that we're not starting a second selection
7289
+ if (button == 1 && cm.state.selectingText)
7290
+ { cm.state.selectingText(e); }
7291
+
7292
+ if (pos && handleMappedButton(cm, button, pos, repeat, e)) { return }
7293
+
7294
+ if (button == 1) {
7295
+ if (pos) { leftButtonDown(cm, pos, repeat, e); }
7296
+ else if (e_target(e) == display.scroller) { e_preventDefault(e); }
7297
+ } else if (button == 2) {
7298
+ if (pos) { extendSelection(cm.doc, pos); }
7299
+ setTimeout(function () { return display.input.focus(); }, 20);
7300
+ } else if (button == 3) {
7301
+ if (captureRightClick) { cm.display.input.onContextMenu(e); }
7302
+ else { delayBlurEvent(cm); }
7303
+ }
7304
+ }
7305
+
7306
+ function handleMappedButton(cm, button, pos, repeat, event) {
7307
+ var name = "Click";
7308
+ if (repeat == "double") { name = "Double" + name; }
7309
+ else if (repeat == "triple") { name = "Triple" + name; }
7310
+ name = (button == 1 ? "Left" : button == 2 ? "Middle" : "Right") + name;
7311
+
7312
+ return dispatchKey(cm, addModifierNames(name, event), event, function (bound) {
7313
+ if (typeof bound == "string") { bound = commands[bound]; }
7314
+ if (!bound) { return false }
7315
+ var done = false;
7316
+ try {
7317
+ if (cm.isReadOnly()) { cm.state.suppressEdits = true; }
7318
+ done = bound(cm, pos) != Pass;
7319
+ } finally {
7320
+ cm.state.suppressEdits = false;
7321
+ }
7322
+ return done
7323
+ })
7324
+ }
7325
+
7326
+ function configureMouse(cm, repeat, event) {
7327
+ var option = cm.getOption("configureMouse");
7328
+ var value = option ? option(cm, repeat, event) : {};
7329
+ if (value.unit == null) {
7330
+ var rect = chromeOS ? event.shiftKey && event.metaKey : event.altKey;
7331
+ value.unit = rect ? "rectangle" : repeat == "single" ? "char" : repeat == "double" ? "word" : "line";
7332
+ }
7333
+ if (value.extend == null || cm.doc.extend) { value.extend = cm.doc.extend || event.shiftKey; }
7334
+ if (value.addNew == null) { value.addNew = mac ? event.metaKey : event.ctrlKey; }
7335
+ if (value.moveOnDrag == null) { value.moveOnDrag = !(mac ? event.altKey : event.ctrlKey); }
7336
+ return value
7337
+ }
7338
+
7339
+ function leftButtonDown(cm, pos, repeat, event) {
7340
+ if (ie) { setTimeout(bind(ensureFocus, cm), 0); }
7341
+ else { cm.curOp.focus = activeElt(); }
7342
+
7343
+ var behavior = configureMouse(cm, repeat, event);
7344
+
7345
+ var sel = cm.doc.sel, contained;
7346
+ if (cm.options.dragDrop && dragAndDrop && !cm.isReadOnly() &&
7347
+ repeat == "single" && (contained = sel.contains(pos)) > -1 &&
7348
+ (cmp((contained = sel.ranges[contained]).from(), pos) < 0 || pos.xRel > 0) &&
7349
+ (cmp(contained.to(), pos) > 0 || pos.xRel < 0))
7350
+ { leftButtonStartDrag(cm, event, pos, behavior); }
7351
+ else
7352
+ { leftButtonSelect(cm, event, pos, behavior); }
7353
+ }
7354
+
7355
+ // Start a text drag. When it ends, see if any dragging actually
7356
+ // happen, and treat as a click if it didn't.
7357
+ function leftButtonStartDrag(cm, event, pos, behavior) {
7358
+ var display = cm.display, moved = false;
7359
+ var dragEnd = operation(cm, function (e) {
7360
+ if (webkit) { display.scroller.draggable = false; }
7361
+ cm.state.draggingText = false;
7362
+ off(display.wrapper.ownerDocument, "mouseup", dragEnd);
7363
+ off(display.wrapper.ownerDocument, "mousemove", mouseMove);
7364
+ off(display.scroller, "dragstart", dragStart);
7365
+ off(display.scroller, "drop", dragEnd);
7366
+ if (!moved) {
7367
+ e_preventDefault(e);
7368
+ if (!behavior.addNew)
7369
+ { extendSelection(cm.doc, pos, null, null, behavior.extend); }
7370
+ // Work around unexplainable focus problem in IE9 (#2127) and Chrome (#3081)
7371
+ if (webkit || ie && ie_version == 9)
7372
+ { setTimeout(function () {display.wrapper.ownerDocument.body.focus(); display.input.focus();}, 20); }
7373
+ else
7374
+ { display.input.focus(); }
7375
+ }
7376
+ });
7377
+ var mouseMove = function(e2) {
7378
+ moved = moved || Math.abs(event.clientX - e2.clientX) + Math.abs(event.clientY - e2.clientY) >= 10;
7379
+ };
7380
+ var dragStart = function () { return moved = true; };
7381
+ // Let the drag handler handle this.
7382
+ if (webkit) { display.scroller.draggable = true; }
7383
+ cm.state.draggingText = dragEnd;
7384
+ dragEnd.copy = !behavior.moveOnDrag;
7385
+ // IE's approach to draggable
7386
+ if (display.scroller.dragDrop) { display.scroller.dragDrop(); }
7387
+ on(display.wrapper.ownerDocument, "mouseup", dragEnd);
7388
+ on(display.wrapper.ownerDocument, "mousemove", mouseMove);
7389
+ on(display.scroller, "dragstart", dragStart);
7390
+ on(display.scroller, "drop", dragEnd);
7391
+
7392
+ delayBlurEvent(cm);
7393
+ setTimeout(function () { return display.input.focus(); }, 20);
7394
+ }
7395
+
7396
+ function rangeForUnit(cm, pos, unit) {
7397
+ if (unit == "char") { return new Range(pos, pos) }
7398
+ if (unit == "word") { return cm.findWordAt(pos) }
7399
+ if (unit == "line") { return new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))) }
7400
+ var result = unit(cm, pos);
7401
+ return new Range(result.from, result.to)
7402
+ }
7403
+
7404
+ // Normal selection, as opposed to text dragging.
7405
+ function leftButtonSelect(cm, event, start, behavior) {
7406
+ var display = cm.display, doc = cm.doc;
7407
+ e_preventDefault(event);
7408
+
7409
+ var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges;
7410
+ if (behavior.addNew && !behavior.extend) {
7411
+ ourIndex = doc.sel.contains(start);
7412
+ if (ourIndex > -1)
7413
+ { ourRange = ranges[ourIndex]; }
7414
+ else
7415
+ { ourRange = new Range(start, start); }
7416
+ } else {
7417
+ ourRange = doc.sel.primary();
7418
+ ourIndex = doc.sel.primIndex;
7419
+ }
7420
+
7421
+ if (behavior.unit == "rectangle") {
7422
+ if (!behavior.addNew) { ourRange = new Range(start, start); }
7423
+ start = posFromMouse(cm, event, true, true);
7424
+ ourIndex = -1;
7425
+ } else {
7426
+ var range$$1 = rangeForUnit(cm, start, behavior.unit);
7427
+ if (behavior.extend)
7428
+ { ourRange = extendRange(ourRange, range$$1.anchor, range$$1.head, behavior.extend); }
7429
+ else
7430
+ { ourRange = range$$1; }
7431
+ }
7432
+
7433
+ if (!behavior.addNew) {
7434
+ ourIndex = 0;
7435
+ setSelection(doc, new Selection([ourRange], 0), sel_mouse);
7436
+ startSel = doc.sel;
7437
+ } else if (ourIndex == -1) {
7438
+ ourIndex = ranges.length;
7439
+ setSelection(doc, normalizeSelection(cm, ranges.concat([ourRange]), ourIndex),
7440
+ {scroll: false, origin: "*mouse"});
7441
+ } else if (ranges.length > 1 && ranges[ourIndex].empty() && behavior.unit == "char" && !behavior.extend) {
7442
+ setSelection(doc, normalizeSelection(cm, ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0),
7443
+ {scroll: false, origin: "*mouse"});
7444
+ startSel = doc.sel;
7445
+ } else {
7446
+ replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);
7447
+ }
7448
+
7449
+ var lastPos = start;
7450
+ function extendTo(pos) {
7451
+ if (cmp(lastPos, pos) == 0) { return }
7452
+ lastPos = pos;
7453
+
7454
+ if (behavior.unit == "rectangle") {
7455
+ var ranges = [], tabSize = cm.options.tabSize;
7456
+ var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
7457
+ var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
7458
+ var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);
7459
+ for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
7460
+ line <= end; line++) {
7461
+ var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize);
7462
+ if (left == right)
7463
+ { ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos))); }
7464
+ else if (text.length > leftPos)
7465
+ { ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize)))); }
7466
+ }
7467
+ if (!ranges.length) { ranges.push(new Range(start, start)); }
7468
+ setSelection(doc, normalizeSelection(cm, startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
7469
+ {origin: "*mouse", scroll: false});
7470
+ cm.scrollIntoView(pos);
7471
+ } else {
7472
+ var oldRange = ourRange;
7473
+ var range$$1 = rangeForUnit(cm, pos, behavior.unit);
7474
+ var anchor = oldRange.anchor, head;
7475
+ if (cmp(range$$1.anchor, anchor) > 0) {
7476
+ head = range$$1.head;
7477
+ anchor = minPos(oldRange.from(), range$$1.anchor);
7478
+ } else {
7479
+ head = range$$1.anchor;
7480
+ anchor = maxPos(oldRange.to(), range$$1.head);
7481
+ }
7482
+ var ranges$1 = startSel.ranges.slice(0);
7483
+ ranges$1[ourIndex] = bidiSimplify(cm, new Range(clipPos(doc, anchor), head));
7484
+ setSelection(doc, normalizeSelection(cm, ranges$1, ourIndex), sel_mouse);
7485
+ }
7486
+ }
7487
+
7488
+ var editorSize = display.wrapper.getBoundingClientRect();
7489
+ // Used to ensure timeout re-tries don't fire when another extend
7490
+ // happened in the meantime (clearTimeout isn't reliable -- at
7491
+ // least on Chrome, the timeouts still happen even when cleared,
7492
+ // if the clear happens after their scheduled firing time).
7493
+ var counter = 0;
7494
+
7495
+ function extend(e) {
7496
+ var curCount = ++counter;
7497
+ var cur = posFromMouse(cm, e, true, behavior.unit == "rectangle");
7498
+ if (!cur) { return }
7499
+ if (cmp(cur, lastPos) != 0) {
7500
+ cm.curOp.focus = activeElt();
7501
+ extendTo(cur);
7502
+ var visible = visibleLines(display, doc);
7503
+ if (cur.line >= visible.to || cur.line < visible.from)
7504
+ { setTimeout(operation(cm, function () {if (counter == curCount) { extend(e); }}), 150); }
7505
+ } else {
7506
+ var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;
7507
+ if (outside) { setTimeout(operation(cm, function () {
7508
+ if (counter != curCount) { return }
7509
+ display.scroller.scrollTop += outside;
7510
+ extend(e);
7511
+ }), 50); }
7512
+ }
7513
+ }
7514
+
7515
+ function done(e) {
7516
+ cm.state.selectingText = false;
7517
+ counter = Infinity;
7518
+ e_preventDefault(e);
7519
+ display.input.focus();
7520
+ off(display.wrapper.ownerDocument, "mousemove", move);
7521
+ off(display.wrapper.ownerDocument, "mouseup", up);
7522
+ doc.history.lastSelOrigin = null;
7523
+ }
7524
+
7525
+ var move = operation(cm, function (e) {
7526
+ if (e.buttons === 0 || !e_button(e)) { done(e); }
7527
+ else { extend(e); }
7528
+ });
7529
+ var up = operation(cm, done);
7530
+ cm.state.selectingText = up;
7531
+ on(display.wrapper.ownerDocument, "mousemove", move);
7532
+ on(display.wrapper.ownerDocument, "mouseup", up);
7533
+ }
7534
+
7535
+ // Used when mouse-selecting to adjust the anchor to the proper side
7536
+ // of a bidi jump depending on the visual position of the head.
7537
+ function bidiSimplify(cm, range$$1) {
7538
+ var anchor = range$$1.anchor;
7539
+ var head = range$$1.head;
7540
+ var anchorLine = getLine(cm.doc, anchor.line);
7541
+ if (cmp(anchor, head) == 0 && anchor.sticky == head.sticky) { return range$$1 }
7542
+ var order = getOrder(anchorLine);
7543
+ if (!order) { return range$$1 }
7544
+ var index = getBidiPartAt(order, anchor.ch, anchor.sticky), part = order[index];
7545
+ if (part.from != anchor.ch && part.to != anchor.ch) { return range$$1 }
7546
+ var boundary = index + ((part.from == anchor.ch) == (part.level != 1) ? 0 : 1);
7547
+ if (boundary == 0 || boundary == order.length) { return range$$1 }
7548
+
7549
+ // Compute the relative visual position of the head compared to the
7550
+ // anchor (<0 is to the left, >0 to the right)
7551
+ var leftSide;
7552
+ if (head.line != anchor.line) {
7553
+ leftSide = (head.line - anchor.line) * (cm.doc.direction == "ltr" ? 1 : -1) > 0;
7554
+ } else {
7555
+ var headIndex = getBidiPartAt(order, head.ch, head.sticky);
7556
+ var dir = headIndex - index || (head.ch - anchor.ch) * (part.level == 1 ? -1 : 1);
7557
+ if (headIndex == boundary - 1 || headIndex == boundary)
7558
+ { leftSide = dir < 0; }
7559
+ else
7560
+ { leftSide = dir > 0; }
7561
+ }
7562
+
7563
+ var usePart = order[boundary + (leftSide ? -1 : 0)];
7564
+ var from = leftSide == (usePart.level == 1);
7565
+ var ch = from ? usePart.from : usePart.to, sticky = from ? "after" : "before";
7566
+ return anchor.ch == ch && anchor.sticky == sticky ? range$$1 : new Range(new Pos(anchor.line, ch, sticky), head)
7567
+ }
7568
+
7569
+
7570
+ // Determines whether an event happened in the gutter, and fires the
7571
+ // handlers for the corresponding event.
7572
+ function gutterEvent(cm, e, type, prevent) {
7573
+ var mX, mY;
7574
+ if (e.touches) {
7575
+ mX = e.touches[0].clientX;
7576
+ mY = e.touches[0].clientY;
7577
+ } else {
7578
+ try { mX = e.clientX; mY = e.clientY; }
7579
+ catch(e) { return false }
7580
+ }
7581
+ if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) { return false }
7582
+ if (prevent) { e_preventDefault(e); }
7583
+
7584
+ var display = cm.display;
7585
+ var lineBox = display.lineDiv.getBoundingClientRect();
7586
+
7587
+ if (mY > lineBox.bottom || !hasHandler(cm, type)) { return e_defaultPrevented(e) }
7588
+ mY -= lineBox.top - display.viewOffset;
7589
+
7590
+ for (var i = 0; i < cm.options.gutters.length; ++i) {
7591
+ var g = display.gutters.childNodes[i];
7592
+ if (g && g.getBoundingClientRect().right >= mX) {
7593
+ var line = lineAtHeight(cm.doc, mY);
7594
+ var gutter = cm.options.gutters[i];
7595
+ signal(cm, type, cm, line, gutter, e);
7596
+ return e_defaultPrevented(e)
7597
+ }
7598
+ }
7599
+ }
7600
+
7601
+ function clickInGutter(cm, e) {
7602
+ return gutterEvent(cm, e, "gutterClick", true)
7603
+ }
7604
+
7605
+ // CONTEXT MENU HANDLING
7606
+
7607
+ // To make the context menu work, we need to briefly unhide the
7608
+ // textarea (making it as unobtrusive as possible) to let the
7609
+ // right-click take effect on it.
7610
+ function onContextMenu(cm, e) {
7611
+ if (eventInWidget(cm.display, e) || contextMenuInGutter(cm, e)) { return }
7612
+ if (signalDOMEvent(cm, e, "contextmenu")) { return }
7613
+ if (!captureRightClick) { cm.display.input.onContextMenu(e); }
7614
+ }
7615
+
7616
+ function contextMenuInGutter(cm, e) {
7617
+ if (!hasHandler(cm, "gutterContextMenu")) { return false }
7618
+ return gutterEvent(cm, e, "gutterContextMenu", false)
7619
+ }
7620
+
7621
+ function themeChanged(cm) {
7622
+ cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
7623
+ cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
7624
+ clearCaches(cm);
7625
+ }
7626
+
7627
+ var Init = {toString: function(){return "CodeMirror.Init"}};
7628
+
7629
+ var defaults = {};
7630
+ var optionHandlers = {};
7631
+
7632
+ function defineOptions(CodeMirror) {
7633
+ var optionHandlers = CodeMirror.optionHandlers;
7634
+
7635
+ function option(name, deflt, handle, notOnInit) {
7636
+ CodeMirror.defaults[name] = deflt;
7637
+ if (handle) { optionHandlers[name] =
7638
+ notOnInit ? function (cm, val, old) {if (old != Init) { handle(cm, val, old); }} : handle; }
7639
+ }
7640
+
7641
+ CodeMirror.defineOption = option;
7642
+
7643
+ // Passed to option handlers when there is no old value.
7644
+ CodeMirror.Init = Init;
7645
+
7646
+ // These two are, on init, called from the constructor because they
7647
+ // have to be initialized before the editor can start at all.
7648
+ option("value", "", function (cm, val) { return cm.setValue(val); }, true);
7649
+ option("mode", null, function (cm, val) {
7650
+ cm.doc.modeOption = val;
7651
+ loadMode(cm);
7652
+ }, true);
7653
+
7654
+ option("indentUnit", 2, loadMode, true);
7655
+ option("indentWithTabs", false);
7656
+ option("smartIndent", true);
7657
+ option("tabSize", 4, function (cm) {
7658
+ resetModeState(cm);
7659
+ clearCaches(cm);
7660
+ regChange(cm);
7661
+ }, true);
7662
+
7663
+ option("lineSeparator", null, function (cm, val) {
7664
+ cm.doc.lineSep = val;
7665
+ if (!val) { return }
7666
+ var newBreaks = [], lineNo = cm.doc.first;
7667
+ cm.doc.iter(function (line) {
7668
+ for (var pos = 0;;) {
7669
+ var found = line.text.indexOf(val, pos);
7670
+ if (found == -1) { break }
7671
+ pos = found + val.length;
7672
+ newBreaks.push(Pos(lineNo, found));
7673
+ }
7674
+ lineNo++;
7675
+ });
7676
+ for (var i = newBreaks.length - 1; i >= 0; i--)
7677
+ { replaceRange(cm.doc, val, newBreaks[i], Pos(newBreaks[i].line, newBreaks[i].ch + val.length)); }
7678
+ });
7679
+ option("specialChars", /[\u0000-\u001f\u007f-\u009f\u00ad\u061c\u200b-\u200f\u2028\u2029\ufeff]/g, function (cm, val, old) {
7680
+ cm.state.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g");
7681
+ if (old != Init) { cm.refresh(); }
7682
+ });
7683
+ option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function (cm) { return cm.refresh(); }, true);
7684
+ option("electricChars", true);
7685
+ option("inputStyle", mobile ? "contenteditable" : "textarea", function () {
7686
+ throw new Error("inputStyle can not (yet) be changed in a running editor") // FIXME
7687
+ }, true);
7688
+ option("spellcheck", false, function (cm, val) { return cm.getInputField().spellcheck = val; }, true);
7689
+ option("rtlMoveVisually", !windows);
7690
+ option("wholeLineUpdateBefore", true);
7691
+
7692
+ option("theme", "default", function (cm) {
7693
+ themeChanged(cm);
7694
+ guttersChanged(cm);
7695
+ }, true);
7696
+ option("keyMap", "default", function (cm, val, old) {
7697
+ var next = getKeyMap(val);
7698
+ var prev = old != Init && getKeyMap(old);
7699
+ if (prev && prev.detach) { prev.detach(cm, next); }
7700
+ if (next.attach) { next.attach(cm, prev || null); }
7701
+ });
7702
+ option("extraKeys", null);
7703
+ option("configureMouse", null);
7704
+
7705
+ option("lineWrapping", false, wrappingChanged, true);
7706
+ option("gutters", [], function (cm) {
7707
+ setGuttersForLineNumbers(cm.options);
7708
+ guttersChanged(cm);
7709
+ }, true);
7710
+ option("fixedGutter", true, function (cm, val) {
7711
+ cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0";
7712
+ cm.refresh();
7713
+ }, true);
7714
+ option("coverGutterNextToScrollbar", false, function (cm) { return updateScrollbars(cm); }, true);
7715
+ option("scrollbarStyle", "native", function (cm) {
7716
+ initScrollbars(cm);
7717
+ updateScrollbars(cm);
7718
+ cm.display.scrollbars.setScrollTop(cm.doc.scrollTop);
7719
+ cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft);
7720
+ }, true);
7721
+ option("lineNumbers", false, function (cm) {
7722
+ setGuttersForLineNumbers(cm.options);
7723
+ guttersChanged(cm);
7724
+ }, true);
7725
+ option("firstLineNumber", 1, guttersChanged, true);
7726
+ option("lineNumberFormatter", function (integer) { return integer; }, guttersChanged, true);
7727
+ option("showCursorWhenSelecting", false, updateSelection, true);
7728
+
7729
+ option("resetSelectionOnContextMenu", true);
7730
+ option("lineWiseCopyCut", true);
7731
+ option("pasteLinesPerSelection", true);
7732
+ option("selectionsMayTouch", false);
7733
+
7734
+ option("readOnly", false, function (cm, val) {
7735
+ if (val == "nocursor") {
7736
+ onBlur(cm);
7737
+ cm.display.input.blur();
7738
+ }
7739
+ cm.display.input.readOnlyChanged(val);
7740
+ });
7741
+ option("disableInput", false, function (cm, val) {if (!val) { cm.display.input.reset(); }}, true);
7742
+ option("dragDrop", true, dragDropChanged);
7743
+ option("allowDropFileTypes", null);
7744
+
7745
+ option("cursorBlinkRate", 530);
7746
+ option("cursorScrollMargin", 0);
7747
+ option("cursorHeight", 1, updateSelection, true);
7748
+ option("singleCursorHeightPerLine", true, updateSelection, true);
7749
+ option("workTime", 100);
7750
+ option("workDelay", 100);
7751
+ option("flattenSpans", true, resetModeState, true);
7752
+ option("addModeClass", false, resetModeState, true);
7753
+ option("pollInterval", 100);
7754
+ option("undoDepth", 200, function (cm, val) { return cm.doc.history.undoDepth = val; });
7755
+ option("historyEventDelay", 1250);
7756
+ option("viewportMargin", 10, function (cm) { return cm.refresh(); }, true);
7757
+ option("maxHighlightLength", 10000, resetModeState, true);
7758
+ option("moveInputWithCursor", true, function (cm, val) {
7759
+ if (!val) { cm.display.input.resetPosition(); }
7760
+ });
7761
+
7762
+ option("tabindex", null, function (cm, val) { return cm.display.input.getField().tabIndex = val || ""; });
7763
+ option("autofocus", null);
7764
+ option("direction", "ltr", function (cm, val) { return cm.doc.setDirection(val); }, true);
7765
+ option("phrases", null);
7766
+ }
7767
+
7768
+ function guttersChanged(cm) {
7769
+ updateGutters(cm);
7770
+ regChange(cm);
7771
+ alignHorizontally(cm);
7772
+ }
7773
+
7774
+ function dragDropChanged(cm, value, old) {
7775
+ var wasOn = old && old != Init;
7776
+ if (!value != !wasOn) {
7777
+ var funcs = cm.display.dragFunctions;
7778
+ var toggle = value ? on : off;
7779
+ toggle(cm.display.scroller, "dragstart", funcs.start);
7780
+ toggle(cm.display.scroller, "dragenter", funcs.enter);
7781
+ toggle(cm.display.scroller, "dragover", funcs.over);
7782
+ toggle(cm.display.scroller, "dragleave", funcs.leave);
7783
+ toggle(cm.display.scroller, "drop", funcs.drop);
7784
+ }
7785
+ }
7786
+
7787
+ function wrappingChanged(cm) {
7788
+ if (cm.options.lineWrapping) {
7789
+ addClass(cm.display.wrapper, "CodeMirror-wrap");
7790
+ cm.display.sizer.style.minWidth = "";
7791
+ cm.display.sizerWidth = null;
7792
+ } else {
7793
+ rmClass(cm.display.wrapper, "CodeMirror-wrap");
7794
+ findMaxLine(cm);
7795
+ }
7796
+ estimateLineHeights(cm);
7797
+ regChange(cm);
7798
+ clearCaches(cm);
7799
+ setTimeout(function () { return updateScrollbars(cm); }, 100);
7800
+ }
7801
+
7802
+ // A CodeMirror instance represents an editor. This is the object
7803
+ // that user code is usually dealing with.
7804
+
7805
+ function CodeMirror(place, options) {
7806
+ var this$1 = this;
7807
+
7808
+ if (!(this instanceof CodeMirror)) { return new CodeMirror(place, options) }
7809
+
7810
+ this.options = options = options ? copyObj(options) : {};
7811
+ // Determine effective options based on given values and defaults.
7812
+ copyObj(defaults, options, false);
7813
+ setGuttersForLineNumbers(options);
7814
+
7815
+ var doc = options.value;
7816
+ if (typeof doc == "string") { doc = new Doc(doc, options.mode, null, options.lineSeparator, options.direction); }
7817
+ else if (options.mode) { doc.modeOption = options.mode; }
7818
+ this.doc = doc;
7819
+
7820
+ var input = new CodeMirror.inputStyles[options.inputStyle](this);
7821
+ var display = this.display = new Display(place, doc, input);
7822
+ display.wrapper.CodeMirror = this;
7823
+ updateGutters(this);
7824
+ themeChanged(this);
7825
+ if (options.lineWrapping)
7826
+ { this.display.wrapper.className += " CodeMirror-wrap"; }
7827
+ initScrollbars(this);
7828
+
7829
+ this.state = {
7830
+ keyMaps: [], // stores maps added by addKeyMap
7831
+ overlays: [], // highlighting overlays, as added by addOverlay
7832
+ modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
7833
+ overwrite: false,
7834
+ delayingBlurEvent: false,
7835
+ focused: false,
7836
+ suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
7837
+ pasteIncoming: false, cutIncoming: false, // help recognize paste/cut edits in input.poll
7838
+ selectingText: false,
7839
+ draggingText: false,
7840
+ highlight: new Delayed(), // stores highlight worker timeout
7841
+ keySeq: null, // Unfinished key sequence
7842
+ specialChars: null
7843
+ };
7844
+
7845
+ if (options.autofocus && !mobile) { display.input.focus(); }
7846
+
7847
+ // Override magic textarea content restore that IE sometimes does
7848
+ // on our hidden textarea on reload
7849
+ if (ie && ie_version < 11) { setTimeout(function () { return this$1.display.input.reset(true); }, 20); }
7850
+
7851
+ registerEventHandlers(this);
7852
+ ensureGlobalHandlers();
7853
+
7854
+ startOperation(this);
7855
+ this.curOp.forceUpdate = true;
7856
+ attachDoc(this, doc);
7857
+
7858
+ if ((options.autofocus && !mobile) || this.hasFocus())
7859
+ { setTimeout(bind(onFocus, this), 20); }
7860
+ else
7861
+ { onBlur(this); }
7862
+
7863
+ for (var opt in optionHandlers) { if (optionHandlers.hasOwnProperty(opt))
7864
+ { optionHandlers[opt](this$1, options[opt], Init); } }
7865
+ maybeUpdateLineNumberWidth(this);
7866
+ if (options.finishInit) { options.finishInit(this); }
7867
+ for (var i = 0; i < initHooks.length; ++i) { initHooks[i](this$1); }
7868
+ endOperation(this);
7869
+ // Suppress optimizelegibility in Webkit, since it breaks text
7870
+ // measuring on line wrapping boundaries.
7871
+ if (webkit && options.lineWrapping &&
7872
+ getComputedStyle(display.lineDiv).textRendering == "optimizelegibility")
7873
+ { display.lineDiv.style.textRendering = "auto"; }
7874
+ }
7875
+
7876
+ // The default configuration options.
7877
+ CodeMirror.defaults = defaults;
7878
+ // Functions to run when options are changed.
7879
+ CodeMirror.optionHandlers = optionHandlers;
7880
+
7881
+ // Attach the necessary event handlers when initializing the editor
7882
+ function registerEventHandlers(cm) {
7883
+ var d = cm.display;
7884
+ on(d.scroller, "mousedown", operation(cm, onMouseDown));
7885
+ // Older IE's will not fire a second mousedown for a double click
7886
+ if (ie && ie_version < 11)
7887
+ { on(d.scroller, "dblclick", operation(cm, function (e) {
7888
+ if (signalDOMEvent(cm, e)) { return }
7889
+ var pos = posFromMouse(cm, e);
7890
+ if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) { return }
7891
+ e_preventDefault(e);
7892
+ var word = cm.findWordAt(pos);
7893
+ extendSelection(cm.doc, word.anchor, word.head);
7894
+ })); }
7895
+ else
7896
+ { on(d.scroller, "dblclick", function (e) { return signalDOMEvent(cm, e) || e_preventDefault(e); }); }
7897
+ // Some browsers fire contextmenu *after* opening the menu, at
7898
+ // which point we can't mess with it anymore. Context menu is
7899
+ // handled in onMouseDown for these browsers.
7900
+ on(d.scroller, "contextmenu", function (e) { return onContextMenu(cm, e); });
7901
+
7902
+ // Used to suppress mouse event handling when a touch happens
7903
+ var touchFinished, prevTouch = {end: 0};
7904
+ function finishTouch() {
7905
+ if (d.activeTouch) {
7906
+ touchFinished = setTimeout(function () { return d.activeTouch = null; }, 1000);
7907
+ prevTouch = d.activeTouch;
7908
+ prevTouch.end = +new Date;
7909
+ }
7910
+ }
7911
+ function isMouseLikeTouchEvent(e) {
7912
+ if (e.touches.length != 1) { return false }
7913
+ var touch = e.touches[0];
7914
+ return touch.radiusX <= 1 && touch.radiusY <= 1
7915
+ }
7916
+ function farAway(touch, other) {
7917
+ if (other.left == null) { return true }
7918
+ var dx = other.left - touch.left, dy = other.top - touch.top;
7919
+ return dx * dx + dy * dy > 20 * 20
7920
+ }
7921
+ on(d.scroller, "touchstart", function (e) {
7922
+ if (!signalDOMEvent(cm, e) && !isMouseLikeTouchEvent(e) && !clickInGutter(cm, e)) {
7923
+ d.input.ensurePolled();
7924
+ clearTimeout(touchFinished);
7925
+ var now = +new Date;
7926
+ d.activeTouch = {start: now, moved: false,
7927
+ prev: now - prevTouch.end <= 300 ? prevTouch : null};
7928
+ if (e.touches.length == 1) {
7929
+ d.activeTouch.left = e.touches[0].pageX;
7930
+ d.activeTouch.top = e.touches[0].pageY;
7931
+ }
7932
+ }
7933
+ });
7934
+ on(d.scroller, "touchmove", function () {
7935
+ if (d.activeTouch) { d.activeTouch.moved = true; }
7936
+ });
7937
+ on(d.scroller, "touchend", function (e) {
7938
+ var touch = d.activeTouch;
7939
+ if (touch && !eventInWidget(d, e) && touch.left != null &&
7940
+ !touch.moved && new Date - touch.start < 300) {
7941
+ var pos = cm.coordsChar(d.activeTouch, "page"), range;
7942
+ if (!touch.prev || farAway(touch, touch.prev)) // Single tap
7943
+ { range = new Range(pos, pos); }
7944
+ else if (!touch.prev.prev || farAway(touch, touch.prev.prev)) // Double tap
7945
+ { range = cm.findWordAt(pos); }
7946
+ else // Triple tap
7947
+ { range = new Range(Pos(pos.line, 0), clipPos(cm.doc, Pos(pos.line + 1, 0))); }
7948
+ cm.setSelection(range.anchor, range.head);
7949
+ cm.focus();
7950
+ e_preventDefault(e);
7951
+ }
7952
+ finishTouch();
7953
+ });
7954
+ on(d.scroller, "touchcancel", finishTouch);
7955
+
7956
+ // Sync scrolling between fake scrollbars and real scrollable
7957
+ // area, ensure viewport is updated when scrolling.
7958
+ on(d.scroller, "scroll", function () {
7959
+ if (d.scroller.clientHeight) {
7960
+ updateScrollTop(cm, d.scroller.scrollTop);
7961
+ setScrollLeft(cm, d.scroller.scrollLeft, true);
7962
+ signal(cm, "scroll", cm);
7963
+ }
7964
+ });
7965
+
7966
+ // Listen to wheel events in order to try and update the viewport on time.
7967
+ on(d.scroller, "mousewheel", function (e) { return onScrollWheel(cm, e); });
7968
+ on(d.scroller, "DOMMouseScroll", function (e) { return onScrollWheel(cm, e); });
7969
+
7970
+ // Prevent wrapper from ever scrolling
7971
+ on(d.wrapper, "scroll", function () { return d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; });
7972
+
7973
+ d.dragFunctions = {
7974
+ enter: function (e) {if (!signalDOMEvent(cm, e)) { e_stop(e); }},
7975
+ over: function (e) {if (!signalDOMEvent(cm, e)) { onDragOver(cm, e); e_stop(e); }},
7976
+ start: function (e) { return onDragStart(cm, e); },
7977
+ drop: operation(cm, onDrop),
7978
+ leave: function (e) {if (!signalDOMEvent(cm, e)) { clearDragCursor(cm); }}
7979
+ };
7980
+
7981
+ var inp = d.input.getField();
7982
+ on(inp, "keyup", function (e) { return onKeyUp.call(cm, e); });
7983
+ on(inp, "keydown", operation(cm, onKeyDown));
7984
+ on(inp, "keypress", operation(cm, onKeyPress));
7985
+ on(inp, "focus", function (e) { return onFocus(cm, e); });
7986
+ on(inp, "blur", function (e) { return onBlur(cm, e); });
7987
+ }
7988
+
7989
+ var initHooks = [];
7990
+ CodeMirror.defineInitHook = function (f) { return initHooks.push(f); };
7991
+
7992
+ // Indent the given line. The how parameter can be "smart",
7993
+ // "add"/null, "subtract", or "prev". When aggressive is false
7994
+ // (typically set to true for forced single-line indents), empty
7995
+ // lines are not indented, and places where the mode returns Pass
7996
+ // are left alone.
7997
+ function indentLine(cm, n, how, aggressive) {
7998
+ var doc = cm.doc, state;
7999
+ if (how == null) { how = "add"; }
8000
+ if (how == "smart") {
8001
+ // Fall back to "prev" when the mode doesn't have an indentation
8002
+ // method.
8003
+ if (!doc.mode.indent) { how = "prev"; }
8004
+ else { state = getContextBefore(cm, n).state; }
8005
+ }
8006
+
8007
+ var tabSize = cm.options.tabSize;
8008
+ var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
8009
+ if (line.stateAfter) { line.stateAfter = null; }
8010
+ var curSpaceString = line.text.match(/^\s*/)[0], indentation;
8011
+ if (!aggressive && !/\S/.test(line.text)) {
8012
+ indentation = 0;
8013
+ how = "not";
8014
+ } else if (how == "smart") {
8015
+ indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
8016
+ if (indentation == Pass || indentation > 150) {
8017
+ if (!aggressive) { return }
8018
+ how = "prev";
8019
+ }
8020
+ }
8021
+ if (how == "prev") {
8022
+ if (n > doc.first) { indentation = countColumn(getLine(doc, n-1).text, null, tabSize); }
8023
+ else { indentation = 0; }
8024
+ } else if (how == "add") {
8025
+ indentation = curSpace + cm.options.indentUnit;
8026
+ } else if (how == "subtract") {
8027
+ indentation = curSpace - cm.options.indentUnit;
8028
+ } else if (typeof how == "number") {
8029
+ indentation = curSpace + how;
8030
+ }
8031
+ indentation = Math.max(0, indentation);
8032
+
8033
+ var indentString = "", pos = 0;
8034
+ if (cm.options.indentWithTabs)
8035
+ { for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";} }
8036
+ if (pos < indentation) { indentString += spaceStr(indentation - pos); }
8037
+
8038
+ if (indentString != curSpaceString) {
8039
+ replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input");
8040
+ line.stateAfter = null;
8041
+ return true
8042
+ } else {
8043
+ // Ensure that, if the cursor was in the whitespace at the start
8044
+ // of the line, it is moved to the end of that space.
8045
+ for (var i$1 = 0; i$1 < doc.sel.ranges.length; i$1++) {
8046
+ var range = doc.sel.ranges[i$1];
8047
+ if (range.head.line == n && range.head.ch < curSpaceString.length) {
8048
+ var pos$1 = Pos(n, curSpaceString.length);
8049
+ replaceOneSelection(doc, i$1, new Range(pos$1, pos$1));
8050
+ break
8051
+ }
8052
+ }
8053
+ }
8054
+ }
8055
+
8056
+ // This will be set to a {lineWise: bool, text: [string]} object, so
8057
+ // that, when pasting, we know what kind of selections the copied
8058
+ // text was made out of.
8059
+ var lastCopied = null;
8060
+
8061
+ function setLastCopied(newLastCopied) {
8062
+ lastCopied = newLastCopied;
8063
+ }
8064
+
8065
+ function applyTextInput(cm, inserted, deleted, sel, origin) {
8066
+ var doc = cm.doc;
8067
+ cm.display.shift = false;
8068
+ if (!sel) { sel = doc.sel; }
8069
+
8070
+ var paste = cm.state.pasteIncoming || origin == "paste";
8071
+ var textLines = splitLinesAuto(inserted), multiPaste = null;
8072
+ // When pasting N lines into N selections, insert one line per selection
8073
+ if (paste && sel.ranges.length > 1) {
8074
+ if (lastCopied && lastCopied.text.join("\n") == inserted) {
8075
+ if (sel.ranges.length % lastCopied.text.length == 0) {
8076
+ multiPaste = [];
8077
+ for (var i = 0; i < lastCopied.text.length; i++)
8078
+ { multiPaste.push(doc.splitLines(lastCopied.text[i])); }
8079
+ }
8080
+ } else if (textLines.length == sel.ranges.length && cm.options.pasteLinesPerSelection) {
8081
+ multiPaste = map(textLines, function (l) { return [l]; });
8082
+ }
8083
+ }
8084
+
8085
+ var updateInput;
8086
+ // Normal behavior is to insert the new text into every selection
8087
+ for (var i$1 = sel.ranges.length - 1; i$1 >= 0; i$1--) {
8088
+ var range$$1 = sel.ranges[i$1];
8089
+ var from = range$$1.from(), to = range$$1.to();
8090
+ if (range$$1.empty()) {
8091
+ if (deleted && deleted > 0) // Handle deletion
8092
+ { from = Pos(from.line, from.ch - deleted); }
8093
+ else if (cm.state.overwrite && !paste) // Handle overwrite
8094
+ { to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length)); }
8095
+ else if (paste && lastCopied && lastCopied.lineWise && lastCopied.text.join("\n") == inserted)
8096
+ { from = to = Pos(from.line, 0); }
8097
+ }
8098
+ updateInput = cm.curOp.updateInput;
8099
+ var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i$1 % multiPaste.length] : textLines,
8100
+ origin: origin || (paste ? "paste" : cm.state.cutIncoming ? "cut" : "+input")};
8101
+ makeChange(cm.doc, changeEvent);
8102
+ signalLater(cm, "inputRead", cm, changeEvent);
8103
+ }
8104
+ if (inserted && !paste)
8105
+ { triggerElectric(cm, inserted); }
8106
+
8107
+ ensureCursorVisible(cm);
8108
+ cm.curOp.updateInput = updateInput;
8109
+ cm.curOp.typing = true;
8110
+ cm.state.pasteIncoming = cm.state.cutIncoming = false;
8111
+ }
8112
+
8113
+ function handlePaste(e, cm) {
8114
+ var pasted = e.clipboardData && e.clipboardData.getData("Text");
8115
+ if (pasted) {
8116
+ e.preventDefault();
8117
+ if (!cm.isReadOnly() && !cm.options.disableInput)
8118
+ { runInOp(cm, function () { return applyTextInput(cm, pasted, 0, null, "paste"); }); }
8119
+ return true
8120
+ }
8121
+ }
8122
+
8123
+ function triggerElectric(cm, inserted) {
8124
+ // When an 'electric' character is inserted, immediately trigger a reindent
8125
+ if (!cm.options.electricChars || !cm.options.smartIndent) { return }
8126
+ var sel = cm.doc.sel;
8127
+
8128
+ for (var i = sel.ranges.length - 1; i >= 0; i--) {
8129
+ var range$$1 = sel.ranges[i];
8130
+ if (range$$1.head.ch > 100 || (i && sel.ranges[i - 1].head.line == range$$1.head.line)) { continue }
8131
+ var mode = cm.getModeAt(range$$1.head);
8132
+ var indented = false;
8133
+ if (mode.electricChars) {
8134
+ for (var j = 0; j < mode.electricChars.length; j++)
8135
+ { if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
8136
+ indented = indentLine(cm, range$$1.head.line, "smart");
8137
+ break
8138
+ } }
8139
+ } else if (mode.electricInput) {
8140
+ if (mode.electricInput.test(getLine(cm.doc, range$$1.head.line).text.slice(0, range$$1.head.ch)))
8141
+ { indented = indentLine(cm, range$$1.head.line, "smart"); }
8142
+ }
8143
+ if (indented) { signalLater(cm, "electricInput", cm, range$$1.head.line); }
8144
+ }
8145
+ }
8146
+
8147
+ function copyableRanges(cm) {
8148
+ var text = [], ranges = [];
8149
+ for (var i = 0; i < cm.doc.sel.ranges.length; i++) {
8150
+ var line = cm.doc.sel.ranges[i].head.line;
8151
+ var lineRange = {anchor: Pos(line, 0), head: Pos(line + 1, 0)};
8152
+ ranges.push(lineRange);
8153
+ text.push(cm.getRange(lineRange.anchor, lineRange.head));
8154
+ }
8155
+ return {text: text, ranges: ranges}
8156
+ }
8157
+
8158
+ function disableBrowserMagic(field, spellcheck) {
8159
+ field.setAttribute("autocorrect", "off");
8160
+ field.setAttribute("autocapitalize", "off");
8161
+ field.setAttribute("spellcheck", !!spellcheck);
8162
+ }
8163
+
8164
+ function hiddenTextarea() {
8165
+ var te = elt("textarea", null, null, "position: absolute; bottom: -1em; padding: 0; width: 1px; height: 1em; outline: none");
8166
+ var div = elt("div", [te], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
8167
+ // The textarea is kept positioned near the cursor to prevent the
8168
+ // fact that it'll be scrolled into view on input from scrolling
8169
+ // our fake cursor out of view. On webkit, when wrap=off, paste is
8170
+ // very slow. So make the area wide instead.
8171
+ if (webkit) { te.style.width = "1000px"; }
8172
+ else { te.setAttribute("wrap", "off"); }
8173
+ // If border: 0; -- iOS fails to open keyboard (issue #1287)
8174
+ if (ios) { te.style.border = "1px solid black"; }
8175
+ disableBrowserMagic(te);
8176
+ return div
8177
+ }
8178
+
8179
+ // The publicly visible API. Note that methodOp(f) means
8180
+ // 'wrap f in an operation, performed on its `this` parameter'.
8181
+
8182
+ // This is not the complete set of editor methods. Most of the
8183
+ // methods defined on the Doc type are also injected into
8184
+ // CodeMirror.prototype, for backwards compatibility and
8185
+ // convenience.
8186
+
8187
+ function addEditorMethods(CodeMirror) {
8188
+ var optionHandlers = CodeMirror.optionHandlers;
8189
+
8190
+ var helpers = CodeMirror.helpers = {};
8191
+
8192
+ CodeMirror.prototype = {
8193
+ constructor: CodeMirror,
8194
+ focus: function(){window.focus(); this.display.input.focus();},
8195
+
8196
+ setOption: function(option, value) {
8197
+ var options = this.options, old = options[option];
8198
+ if (options[option] == value && option != "mode") { return }
8199
+ options[option] = value;
8200
+ if (optionHandlers.hasOwnProperty(option))
8201
+ { operation(this, optionHandlers[option])(this, value, old); }
8202
+ signal(this, "optionChange", this, option);
8203
+ },
8204
+
8205
+ getOption: function(option) {return this.options[option]},
8206
+ getDoc: function() {return this.doc},
8207
+
8208
+ addKeyMap: function(map$$1, bottom) {
8209
+ this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map$$1));
8210
+ },
8211
+ removeKeyMap: function(map$$1) {
8212
+ var maps = this.state.keyMaps;
8213
+ for (var i = 0; i < maps.length; ++i)
8214
+ { if (maps[i] == map$$1 || maps[i].name == map$$1) {
8215
+ maps.splice(i, 1);
8216
+ return true
8217
+ } }
8218
+ },
8219
+
8220
+ addOverlay: methodOp(function(spec, options) {
8221
+ var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec);
8222
+ if (mode.startState) { throw new Error("Overlays may not be stateful.") }
8223
+ insertSorted(this.state.overlays,
8224
+ {mode: mode, modeSpec: spec, opaque: options && options.opaque,
8225
+ priority: (options && options.priority) || 0},
8226
+ function (overlay) { return overlay.priority; });
8227
+ this.state.modeGen++;
8228
+ regChange(this);
8229
+ }),
8230
+ removeOverlay: methodOp(function(spec) {
8231
+ var this$1 = this;
8232
+
8233
+ var overlays = this.state.overlays;
8234
+ for (var i = 0; i < overlays.length; ++i) {
8235
+ var cur = overlays[i].modeSpec;
8236
+ if (cur == spec || typeof spec == "string" && cur.name == spec) {
8237
+ overlays.splice(i, 1);
8238
+ this$1.state.modeGen++;
8239
+ regChange(this$1);
8240
+ return
8241
+ }
8242
+ }
8243
+ }),
8244
+
8245
+ indentLine: methodOp(function(n, dir, aggressive) {
8246
+ if (typeof dir != "string" && typeof dir != "number") {
8247
+ if (dir == null) { dir = this.options.smartIndent ? "smart" : "prev"; }
8248
+ else { dir = dir ? "add" : "subtract"; }
8249
+ }
8250
+ if (isLine(this.doc, n)) { indentLine(this, n, dir, aggressive); }
8251
+ }),
8252
+ indentSelection: methodOp(function(how) {
8253
+ var this$1 = this;
8254
+
8255
+ var ranges = this.doc.sel.ranges, end = -1;
8256
+ for (var i = 0; i < ranges.length; i++) {
8257
+ var range$$1 = ranges[i];
8258
+ if (!range$$1.empty()) {
8259
+ var from = range$$1.from(), to = range$$1.to();
8260
+ var start = Math.max(end, from.line);
8261
+ end = Math.min(this$1.lastLine(), to.line - (to.ch ? 0 : 1)) + 1;
8262
+ for (var j = start; j < end; ++j)
8263
+ { indentLine(this$1, j, how); }
8264
+ var newRanges = this$1.doc.sel.ranges;
8265
+ if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i].from().ch > 0)
8266
+ { replaceOneSelection(this$1.doc, i, new Range(from, newRanges[i].to()), sel_dontScroll); }
8267
+ } else if (range$$1.head.line > end) {
8268
+ indentLine(this$1, range$$1.head.line, how, true);
8269
+ end = range$$1.head.line;
8270
+ if (i == this$1.doc.sel.primIndex) { ensureCursorVisible(this$1); }
8271
+ }
8272
+ }
8273
+ }),
8274
+
8275
+ // Fetch the parser token for a given character. Useful for hacks
8276
+ // that want to inspect the mode state (say, for completion).
8277
+ getTokenAt: function(pos, precise) {
8278
+ return takeToken(this, pos, precise)
8279
+ },
8280
+
8281
+ getLineTokens: function(line, precise) {
8282
+ return takeToken(this, Pos(line), precise, true)
8283
+ },
8284
+
8285
+ getTokenTypeAt: function(pos) {
8286
+ pos = clipPos(this.doc, pos);
8287
+ var styles = getLineStyles(this, getLine(this.doc, pos.line));
8288
+ var before = 0, after = (styles.length - 1) / 2, ch = pos.ch;
8289
+ var type;
8290
+ if (ch == 0) { type = styles[2]; }
8291
+ else { for (;;) {
8292
+ var mid = (before + after) >> 1;
8293
+ if ((mid ? styles[mid * 2 - 1] : 0) >= ch) { after = mid; }
8294
+ else if (styles[mid * 2 + 1] < ch) { before = mid + 1; }
8295
+ else { type = styles[mid * 2 + 2]; break }
8296
+ } }
8297
+ var cut = type ? type.indexOf("overlay ") : -1;
8298
+ return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1)
8299
+ },
8300
+
8301
+ getModeAt: function(pos) {
8302
+ var mode = this.doc.mode;
8303
+ if (!mode.innerMode) { return mode }
8304
+ return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode
8305
+ },
8306
+
8307
+ getHelper: function(pos, type) {
8308
+ return this.getHelpers(pos, type)[0]
8309
+ },
8310
+
8311
+ getHelpers: function(pos, type) {
8312
+ var this$1 = this;
8313
+
8314
+ var found = [];
8315
+ if (!helpers.hasOwnProperty(type)) { return found }
8316
+ var help = helpers[type], mode = this.getModeAt(pos);
8317
+ if (typeof mode[type] == "string") {
8318
+ if (help[mode[type]]) { found.push(help[mode[type]]); }
8319
+ } else if (mode[type]) {
8320
+ for (var i = 0; i < mode[type].length; i++) {
8321
+ var val = help[mode[type][i]];
8322
+ if (val) { found.push(val); }
8323
+ }
8324
+ } else if (mode.helperType && help[mode.helperType]) {
8325
+ found.push(help[mode.helperType]);
8326
+ } else if (help[mode.name]) {
8327
+ found.push(help[mode.name]);
8328
+ }
8329
+ for (var i$1 = 0; i$1 < help._global.length; i$1++) {
8330
+ var cur = help._global[i$1];
8331
+ if (cur.pred(mode, this$1) && indexOf(found, cur.val) == -1)
8332
+ { found.push(cur.val); }
8333
+ }
8334
+ return found
8335
+ },
8336
+
8337
+ getStateAfter: function(line, precise) {
8338
+ var doc = this.doc;
8339
+ line = clipLine(doc, line == null ? doc.first + doc.size - 1: line);
8340
+ return getContextBefore(this, line + 1, precise).state
8341
+ },
8342
+
8343
+ cursorCoords: function(start, mode) {
8344
+ var pos, range$$1 = this.doc.sel.primary();
8345
+ if (start == null) { pos = range$$1.head; }
8346
+ else if (typeof start == "object") { pos = clipPos(this.doc, start); }
8347
+ else { pos = start ? range$$1.from() : range$$1.to(); }
8348
+ return cursorCoords(this, pos, mode || "page")
8349
+ },
8350
+
8351
+ charCoords: function(pos, mode) {
8352
+ return charCoords(this, clipPos(this.doc, pos), mode || "page")
8353
+ },
8354
+
8355
+ coordsChar: function(coords, mode) {
8356
+ coords = fromCoordSystem(this, coords, mode || "page");
8357
+ return coordsChar(this, coords.left, coords.top)
8358
+ },
8359
+
8360
+ lineAtHeight: function(height, mode) {
8361
+ height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top;
8362
+ return lineAtHeight(this.doc, height + this.display.viewOffset)
8363
+ },
8364
+ heightAtLine: function(line, mode, includeWidgets) {
8365
+ var end = false, lineObj;
8366
+ if (typeof line == "number") {
8367
+ var last = this.doc.first + this.doc.size - 1;
8368
+ if (line < this.doc.first) { line = this.doc.first; }
8369
+ else if (line > last) { line = last; end = true; }
8370
+ lineObj = getLine(this.doc, line);
8371
+ } else {
8372
+ lineObj = line;
8373
+ }
8374
+ return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page", includeWidgets || end).top +
8375
+ (end ? this.doc.height - heightAtLine(lineObj) : 0)
8376
+ },
8377
+
8378
+ defaultTextHeight: function() { return textHeight(this.display) },
8379
+ defaultCharWidth: function() { return charWidth(this.display) },
8380
+
8381
+ getViewport: function() { return {from: this.display.viewFrom, to: this.display.viewTo}},
8382
+
8383
+ addWidget: function(pos, node, scroll, vert, horiz) {
8384
+ var display = this.display;
8385
+ pos = cursorCoords(this, clipPos(this.doc, pos));
8386
+ var top = pos.bottom, left = pos.left;
8387
+ node.style.position = "absolute";
8388
+ node.setAttribute("cm-ignore-events", "true");
8389
+ this.display.input.setUneditable(node);
8390
+ display.sizer.appendChild(node);
8391
+ if (vert == "over") {
8392
+ top = pos.top;
8393
+ } else if (vert == "above" || vert == "near") {
8394
+ var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),
8395
+ hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth);
8396
+ // Default to positioning above (if specified and possible); otherwise default to positioning below
8397
+ if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight)
8398
+ { top = pos.top - node.offsetHeight; }
8399
+ else if (pos.bottom + node.offsetHeight <= vspace)
8400
+ { top = pos.bottom; }
8401
+ if (left + node.offsetWidth > hspace)
8402
+ { left = hspace - node.offsetWidth; }
8403
+ }
8404
+ node.style.top = top + "px";
8405
+ node.style.left = node.style.right = "";
8406
+ if (horiz == "right") {
8407
+ left = display.sizer.clientWidth - node.offsetWidth;
8408
+ node.style.right = "0px";
8409
+ } else {
8410
+ if (horiz == "left") { left = 0; }
8411
+ else if (horiz == "middle") { left = (display.sizer.clientWidth - node.offsetWidth) / 2; }
8412
+ node.style.left = left + "px";
8413
+ }
8414
+ if (scroll)
8415
+ { scrollIntoView(this, {left: left, top: top, right: left + node.offsetWidth, bottom: top + node.offsetHeight}); }
8416
+ },
8417
+
8418
+ triggerOnKeyDown: methodOp(onKeyDown),
8419
+ triggerOnKeyPress: methodOp(onKeyPress),
8420
+ triggerOnKeyUp: onKeyUp,
8421
+ triggerOnMouseDown: methodOp(onMouseDown),
8422
+
8423
+ execCommand: function(cmd) {
8424
+ if (commands.hasOwnProperty(cmd))
8425
+ { return commands[cmd].call(null, this) }
8426
+ },
8427
+
8428
+ triggerElectric: methodOp(function(text) { triggerElectric(this, text); }),
8429
+
8430
+ findPosH: function(from, amount, unit, visually) {
8431
+ var this$1 = this;
8432
+
8433
+ var dir = 1;
8434
+ if (amount < 0) { dir = -1; amount = -amount; }
8435
+ var cur = clipPos(this.doc, from);
8436
+ for (var i = 0; i < amount; ++i) {
8437
+ cur = findPosH(this$1.doc, cur, dir, unit, visually);
8438
+ if (cur.hitSide) { break }
8439
+ }
8440
+ return cur
8441
+ },
8442
+
8443
+ moveH: methodOp(function(dir, unit) {
8444
+ var this$1 = this;
8445
+
8446
+ this.extendSelectionsBy(function (range$$1) {
8447
+ if (this$1.display.shift || this$1.doc.extend || range$$1.empty())
8448
+ { return findPosH(this$1.doc, range$$1.head, dir, unit, this$1.options.rtlMoveVisually) }
8449
+ else
8450
+ { return dir < 0 ? range$$1.from() : range$$1.to() }
8451
+ }, sel_move);
8452
+ }),
8453
+
8454
+ deleteH: methodOp(function(dir, unit) {
8455
+ var sel = this.doc.sel, doc = this.doc;
8456
+ if (sel.somethingSelected())
8457
+ { doc.replaceSelection("", null, "+delete"); }
8458
+ else
8459
+ { deleteNearSelection(this, function (range$$1) {
8460
+ var other = findPosH(doc, range$$1.head, dir, unit, false);
8461
+ return dir < 0 ? {from: other, to: range$$1.head} : {from: range$$1.head, to: other}
8462
+ }); }
8463
+ }),
8464
+
8465
+ findPosV: function(from, amount, unit, goalColumn) {
8466
+ var this$1 = this;
8467
+
8468
+ var dir = 1, x = goalColumn;
8469
+ if (amount < 0) { dir = -1; amount = -amount; }
8470
+ var cur = clipPos(this.doc, from);
8471
+ for (var i = 0; i < amount; ++i) {
8472
+ var coords = cursorCoords(this$1, cur, "div");
8473
+ if (x == null) { x = coords.left; }
8474
+ else { coords.left = x; }
8475
+ cur = findPosV(this$1, coords, dir, unit);
8476
+ if (cur.hitSide) { break }
8477
+ }
8478
+ return cur
8479
+ },
8480
+
8481
+ moveV: methodOp(function(dir, unit) {
8482
+ var this$1 = this;
8483
+
8484
+ var doc = this.doc, goals = [];
8485
+ var collapse = !this.display.shift && !doc.extend && doc.sel.somethingSelected();
8486
+ doc.extendSelectionsBy(function (range$$1) {
8487
+ if (collapse)
8488
+ { return dir < 0 ? range$$1.from() : range$$1.to() }
8489
+ var headPos = cursorCoords(this$1, range$$1.head, "div");
8490
+ if (range$$1.goalColumn != null) { headPos.left = range$$1.goalColumn; }
8491
+ goals.push(headPos.left);
8492
+ var pos = findPosV(this$1, headPos, dir, unit);
8493
+ if (unit == "page" && range$$1 == doc.sel.primary())
8494
+ { addToScrollTop(this$1, charCoords(this$1, pos, "div").top - headPos.top); }
8495
+ return pos
8496
+ }, sel_move);
8497
+ if (goals.length) { for (var i = 0; i < doc.sel.ranges.length; i++)
8498
+ { doc.sel.ranges[i].goalColumn = goals[i]; } }
8499
+ }),
8500
+
8501
+ // Find the word at the given position (as returned by coordsChar).
8502
+ findWordAt: function(pos) {
8503
+ var doc = this.doc, line = getLine(doc, pos.line).text;
8504
+ var start = pos.ch, end = pos.ch;
8505
+ if (line) {
8506
+ var helper = this.getHelper(pos, "wordChars");
8507
+ if ((pos.sticky == "before" || end == line.length) && start) { --start; } else { ++end; }
8508
+ var startChar = line.charAt(start);
8509
+ var check = isWordChar(startChar, helper)
8510
+ ? function (ch) { return isWordChar(ch, helper); }
8511
+ : /\s/.test(startChar) ? function (ch) { return /\s/.test(ch); }
8512
+ : function (ch) { return (!/\s/.test(ch) && !isWordChar(ch)); };
8513
+ while (start > 0 && check(line.charAt(start - 1))) { --start; }
8514
+ while (end < line.length && check(line.charAt(end))) { ++end; }
8515
+ }
8516
+ return new Range(Pos(pos.line, start), Pos(pos.line, end))
8517
+ },
8518
+
8519
+ toggleOverwrite: function(value) {
8520
+ if (value != null && value == this.state.overwrite) { return }
8521
+ if (this.state.overwrite = !this.state.overwrite)
8522
+ { addClass(this.display.cursorDiv, "CodeMirror-overwrite"); }
8523
+ else
8524
+ { rmClass(this.display.cursorDiv, "CodeMirror-overwrite"); }
8525
+
8526
+ signal(this, "overwriteToggle", this, this.state.overwrite);
8527
+ },
8528
+ hasFocus: function() { return this.display.input.getField() == activeElt() },
8529
+ isReadOnly: function() { return !!(this.options.readOnly || this.doc.cantEdit) },
8530
+
8531
+ scrollTo: methodOp(function (x, y) { scrollToCoords(this, x, y); }),
8532
+ getScrollInfo: function() {
8533
+ var scroller = this.display.scroller;
8534
+ return {left: scroller.scrollLeft, top: scroller.scrollTop,
8535
+ height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight,
8536
+ width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth,
8537
+ clientHeight: displayHeight(this), clientWidth: displayWidth(this)}
8538
+ },
8539
+
8540
+ scrollIntoView: methodOp(function(range$$1, margin) {
8541
+ if (range$$1 == null) {
8542
+ range$$1 = {from: this.doc.sel.primary().head, to: null};
8543
+ if (margin == null) { margin = this.options.cursorScrollMargin; }
8544
+ } else if (typeof range$$1 == "number") {
8545
+ range$$1 = {from: Pos(range$$1, 0), to: null};
8546
+ } else if (range$$1.from == null) {
8547
+ range$$1 = {from: range$$1, to: null};
8548
+ }
8549
+ if (!range$$1.to) { range$$1.to = range$$1.from; }
8550
+ range$$1.margin = margin || 0;
8551
+
8552
+ if (range$$1.from.line != null) {
8553
+ scrollToRange(this, range$$1);
8554
+ } else {
8555
+ scrollToCoordsRange(this, range$$1.from, range$$1.to, range$$1.margin);
8556
+ }
8557
+ }),
8558
+
8559
+ setSize: methodOp(function(width, height) {
8560
+ var this$1 = this;
8561
+
8562
+ var interpret = function (val) { return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val; };
8563
+ if (width != null) { this.display.wrapper.style.width = interpret(width); }
8564
+ if (height != null) { this.display.wrapper.style.height = interpret(height); }
8565
+ if (this.options.lineWrapping) { clearLineMeasurementCache(this); }
8566
+ var lineNo$$1 = this.display.viewFrom;
8567
+ this.doc.iter(lineNo$$1, this.display.viewTo, function (line) {
8568
+ if (line.widgets) { for (var i = 0; i < line.widgets.length; i++)
8569
+ { if (line.widgets[i].noHScroll) { regLineChange(this$1, lineNo$$1, "widget"); break } } }
8570
+ ++lineNo$$1;
8571
+ });
8572
+ this.curOp.forceUpdate = true;
8573
+ signal(this, "refresh", this);
8574
+ }),
8575
+
8576
+ operation: function(f){return runInOp(this, f)},
8577
+ startOperation: function(){return startOperation(this)},
8578
+ endOperation: function(){return endOperation(this)},
8579
+
8580
+ refresh: methodOp(function() {
8581
+ var oldHeight = this.display.cachedTextHeight;
8582
+ regChange(this);
8583
+ this.curOp.forceUpdate = true;
8584
+ clearCaches(this);
8585
+ scrollToCoords(this, this.doc.scrollLeft, this.doc.scrollTop);
8586
+ updateGutterSpace(this);
8587
+ if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5)
8588
+ { estimateLineHeights(this); }
8589
+ signal(this, "refresh", this);
8590
+ }),
8591
+
8592
+ swapDoc: methodOp(function(doc) {
8593
+ var old = this.doc;
8594
+ old.cm = null;
8595
+ attachDoc(this, doc);
8596
+ clearCaches(this);
8597
+ this.display.input.reset();
8598
+ scrollToCoords(this, doc.scrollLeft, doc.scrollTop);
8599
+ this.curOp.forceScroll = true;
8600
+ signalLater(this, "swapDoc", this, old);
8601
+ return old
8602
+ }),
8603
+
8604
+ phrase: function(phraseText) {
8605
+ var phrases = this.options.phrases;
8606
+ return phrases && Object.prototype.hasOwnProperty.call(phrases, phraseText) ? phrases[phraseText] : phraseText
8607
+ },
8608
+
8609
+ getInputField: function(){return this.display.input.getField()},
8610
+ getWrapperElement: function(){return this.display.wrapper},
8611
+ getScrollerElement: function(){return this.display.scroller},
8612
+ getGutterElement: function(){return this.display.gutters}
8613
+ };
8614
+ eventMixin(CodeMirror);
8615
+
8616
+ CodeMirror.registerHelper = function(type, name, value) {
8617
+ if (!helpers.hasOwnProperty(type)) { helpers[type] = CodeMirror[type] = {_global: []}; }
8618
+ helpers[type][name] = value;
8619
+ };
8620
+ CodeMirror.registerGlobalHelper = function(type, name, predicate, value) {
8621
+ CodeMirror.registerHelper(type, name, value);
8622
+ helpers[type]._global.push({pred: predicate, val: value});
8623
+ };
8624
+ }
8625
+
8626
+ // Used for horizontal relative motion. Dir is -1 or 1 (left or
8627
+ // right), unit can be "char", "column" (like char, but doesn't
8628
+ // cross line boundaries), "word" (across next word), or "group" (to
8629
+ // the start of next group of word or non-word-non-whitespace
8630
+ // chars). The visually param controls whether, in right-to-left
8631
+ // text, direction 1 means to move towards the next index in the
8632
+ // string, or towards the character to the right of the current
8633
+ // position. The resulting position will have a hitSide=true
8634
+ // property if it reached the end of the document.
8635
+ function findPosH(doc, pos, dir, unit, visually) {
8636
+ var oldPos = pos;
8637
+ var origDir = dir;
8638
+ var lineObj = getLine(doc, pos.line);
8639
+ function findNextLine() {
8640
+ var l = pos.line + dir;
8641
+ if (l < doc.first || l >= doc.first + doc.size) { return false }
8642
+ pos = new Pos(l, pos.ch, pos.sticky);
8643
+ return lineObj = getLine(doc, l)
8644
+ }
8645
+ function moveOnce(boundToLine) {
8646
+ var next;
8647
+ if (visually) {
8648
+ next = moveVisually(doc.cm, lineObj, pos, dir);
8649
+ } else {
8650
+ next = moveLogically(lineObj, pos, dir);
8651
+ }
8652
+ if (next == null) {
8653
+ if (!boundToLine && findNextLine())
8654
+ { pos = endOfLine(visually, doc.cm, lineObj, pos.line, dir); }
8655
+ else
8656
+ { return false }
8657
+ } else {
8658
+ pos = next;
8659
+ }
8660
+ return true
8661
+ }
8662
+
8663
+ if (unit == "char") {
8664
+ moveOnce();
8665
+ } else if (unit == "column") {
8666
+ moveOnce(true);
8667
+ } else if (unit == "word" || unit == "group") {
8668
+ var sawType = null, group = unit == "group";
8669
+ var helper = doc.cm && doc.cm.getHelper(pos, "wordChars");
8670
+ for (var first = true;; first = false) {
8671
+ if (dir < 0 && !moveOnce(!first)) { break }
8672
+ var cur = lineObj.text.charAt(pos.ch) || "\n";
8673
+ var type = isWordChar(cur, helper) ? "w"
8674
+ : group && cur == "\n" ? "n"
8675
+ : !group || /\s/.test(cur) ? null
8676
+ : "p";
8677
+ if (group && !first && !type) { type = "s"; }
8678
+ if (sawType && sawType != type) {
8679
+ if (dir < 0) {dir = 1; moveOnce(); pos.sticky = "after";}
8680
+ break
8681
+ }
8682
+
8683
+ if (type) { sawType = type; }
8684
+ if (dir > 0 && !moveOnce(!first)) { break }
8685
+ }
8686
+ }
8687
+ var result = skipAtomic(doc, pos, oldPos, origDir, true);
8688
+ if (equalCursorPos(oldPos, result)) { result.hitSide = true; }
8689
+ return result
8690
+ }
8691
+
8692
+ // For relative vertical movement. Dir may be -1 or 1. Unit can be
8693
+ // "page" or "line". The resulting position will have a hitSide=true
8694
+ // property if it reached the end of the document.
8695
+ function findPosV(cm, pos, dir, unit) {
8696
+ var doc = cm.doc, x = pos.left, y;
8697
+ if (unit == "page") {
8698
+ var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
8699
+ var moveAmount = Math.max(pageSize - .5 * textHeight(cm.display), 3);
8700
+ y = (dir > 0 ? pos.bottom : pos.top) + dir * moveAmount;
8701
+
8702
+ } else if (unit == "line") {
8703
+ y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
8704
+ }
8705
+ var target;
8706
+ for (;;) {
8707
+ target = coordsChar(cm, x, y);
8708
+ if (!target.outside) { break }
8709
+ if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break }
8710
+ y += dir * 5;
8711
+ }
8712
+ return target
8713
+ }
8714
+
8715
+ // CONTENTEDITABLE INPUT STYLE
8716
+
8717
+ var ContentEditableInput = function(cm) {
8718
+ this.cm = cm;
8719
+ this.lastAnchorNode = this.lastAnchorOffset = this.lastFocusNode = this.lastFocusOffset = null;
8720
+ this.polling = new Delayed();
8721
+ this.composing = null;
8722
+ this.gracePeriod = false;
8723
+ this.readDOMTimeout = null;
8724
+ };
8725
+
8726
+ ContentEditableInput.prototype.init = function (display) {
8727
+ var this$1 = this;
8728
+
8729
+ var input = this, cm = input.cm;
8730
+ var div = input.div = display.lineDiv;
8731
+ disableBrowserMagic(div, cm.options.spellcheck);
8732
+
8733
+ on(div, "paste", function (e) {
8734
+ if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
8735
+ // IE doesn't fire input events, so we schedule a read for the pasted content in this way
8736
+ if (ie_version <= 11) { setTimeout(operation(cm, function () { return this$1.updateFromDOM(); }), 20); }
8737
+ });
8738
+
8739
+ on(div, "compositionstart", function (e) {
8740
+ this$1.composing = {data: e.data, done: false};
8741
+ });
8742
+ on(div, "compositionupdate", function (e) {
8743
+ if (!this$1.composing) { this$1.composing = {data: e.data, done: false}; }
8744
+ });
8745
+ on(div, "compositionend", function (e) {
8746
+ if (this$1.composing) {
8747
+ if (e.data != this$1.composing.data) { this$1.readFromDOMSoon(); }
8748
+ this$1.composing.done = true;
8749
+ }
8750
+ });
8751
+
8752
+ on(div, "touchstart", function () { return input.forceCompositionEnd(); });
8753
+
8754
+ on(div, "input", function () {
8755
+ if (!this$1.composing) { this$1.readFromDOMSoon(); }
8756
+ });
8757
+
8758
+ function onCopyCut(e) {
8759
+ if (signalDOMEvent(cm, e)) { return }
8760
+ if (cm.somethingSelected()) {
8761
+ setLastCopied({lineWise: false, text: cm.getSelections()});
8762
+ if (e.type == "cut") { cm.replaceSelection("", null, "cut"); }
8763
+ } else if (!cm.options.lineWiseCopyCut) {
8764
+ return
8765
+ } else {
8766
+ var ranges = copyableRanges(cm);
8767
+ setLastCopied({lineWise: true, text: ranges.text});
8768
+ if (e.type == "cut") {
8769
+ cm.operation(function () {
8770
+ cm.setSelections(ranges.ranges, 0, sel_dontScroll);
8771
+ cm.replaceSelection("", null, "cut");
8772
+ });
8773
+ }
8774
+ }
8775
+ if (e.clipboardData) {
8776
+ e.clipboardData.clearData();
8777
+ var content = lastCopied.text.join("\n");
8778
+ // iOS exposes the clipboard API, but seems to discard content inserted into it
8779
+ e.clipboardData.setData("Text", content);
8780
+ if (e.clipboardData.getData("Text") == content) {
8781
+ e.preventDefault();
8782
+ return
8783
+ }
8784
+ }
8785
+ // Old-fashioned briefly-focus-a-textarea hack
8786
+ var kludge = hiddenTextarea(), te = kludge.firstChild;
8787
+ cm.display.lineSpace.insertBefore(kludge, cm.display.lineSpace.firstChild);
8788
+ te.value = lastCopied.text.join("\n");
8789
+ var hadFocus = document.activeElement;
8790
+ selectInput(te);
8791
+ setTimeout(function () {
8792
+ cm.display.lineSpace.removeChild(kludge);
8793
+ hadFocus.focus();
8794
+ if (hadFocus == div) { input.showPrimarySelection(); }
8795
+ }, 50);
8796
+ }
8797
+ on(div, "copy", onCopyCut);
8798
+ on(div, "cut", onCopyCut);
8799
+ };
8800
+
8801
+ ContentEditableInput.prototype.prepareSelection = function () {
8802
+ var result = prepareSelection(this.cm, false);
8803
+ result.focus = this.cm.state.focused;
8804
+ return result
8805
+ };
8806
+
8807
+ ContentEditableInput.prototype.showSelection = function (info, takeFocus) {
8808
+ if (!info || !this.cm.display.view.length) { return }
8809
+ if (info.focus || takeFocus) { this.showPrimarySelection(); }
8810
+ this.showMultipleSelections(info);
8811
+ };
8812
+
8813
+ ContentEditableInput.prototype.getSelection = function () {
8814
+ return this.cm.display.wrapper.ownerDocument.getSelection()
8815
+ };
8816
+
8817
+ ContentEditableInput.prototype.showPrimarySelection = function () {
8818
+ var sel = this.getSelection(), cm = this.cm, prim = cm.doc.sel.primary();
8819
+ var from = prim.from(), to = prim.to();
8820
+
8821
+ if (cm.display.viewTo == cm.display.viewFrom || from.line >= cm.display.viewTo || to.line < cm.display.viewFrom) {
8822
+ sel.removeAllRanges();
8823
+ return
8824
+ }
8825
+
8826
+ var curAnchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
8827
+ var curFocus = domToPos(cm, sel.focusNode, sel.focusOffset);
8828
+ if (curAnchor && !curAnchor.bad && curFocus && !curFocus.bad &&
8829
+ cmp(minPos(curAnchor, curFocus), from) == 0 &&
8830
+ cmp(maxPos(curAnchor, curFocus), to) == 0)
8831
+ { return }
8832
+
8833
+ var view = cm.display.view;
8834
+ var start = (from.line >= cm.display.viewFrom && posToDOM(cm, from)) ||
8835
+ {node: view[0].measure.map[2], offset: 0};
8836
+ var end = to.line < cm.display.viewTo && posToDOM(cm, to);
8837
+ if (!end) {
8838
+ var measure = view[view.length - 1].measure;
8839
+ var map$$1 = measure.maps ? measure.maps[measure.maps.length - 1] : measure.map;
8840
+ end = {node: map$$1[map$$1.length - 1], offset: map$$1[map$$1.length - 2] - map$$1[map$$1.length - 3]};
8841
+ }
8842
+
8843
+ if (!start || !end) {
8844
+ sel.removeAllRanges();
8845
+ return
8846
+ }
8847
+
8848
+ var old = sel.rangeCount && sel.getRangeAt(0), rng;
8849
+ try { rng = range(start.node, start.offset, end.offset, end.node); }
8850
+ catch(e) {} // Our model of the DOM might be outdated, in which case the range we try to set can be impossible
8851
+ if (rng) {
8852
+ if (!gecko && cm.state.focused) {
8853
+ sel.collapse(start.node, start.offset);
8854
+ if (!rng.collapsed) {
8855
+ sel.removeAllRanges();
8856
+ sel.addRange(rng);
8857
+ }
8858
+ } else {
8859
+ sel.removeAllRanges();
8860
+ sel.addRange(rng);
8861
+ }
8862
+ if (old && sel.anchorNode == null) { sel.addRange(old); }
8863
+ else if (gecko) { this.startGracePeriod(); }
8864
+ }
8865
+ this.rememberSelection();
8866
+ };
8867
+
8868
+ ContentEditableInput.prototype.startGracePeriod = function () {
8869
+ var this$1 = this;
8870
+
8871
+ clearTimeout(this.gracePeriod);
8872
+ this.gracePeriod = setTimeout(function () {
8873
+ this$1.gracePeriod = false;
8874
+ if (this$1.selectionChanged())
8875
+ { this$1.cm.operation(function () { return this$1.cm.curOp.selectionChanged = true; }); }
8876
+ }, 20);
8877
+ };
8878
+
8879
+ ContentEditableInput.prototype.showMultipleSelections = function (info) {
8880
+ removeChildrenAndAdd(this.cm.display.cursorDiv, info.cursors);
8881
+ removeChildrenAndAdd(this.cm.display.selectionDiv, info.selection);
8882
+ };
8883
+
8884
+ ContentEditableInput.prototype.rememberSelection = function () {
8885
+ var sel = this.getSelection();
8886
+ this.lastAnchorNode = sel.anchorNode; this.lastAnchorOffset = sel.anchorOffset;
8887
+ this.lastFocusNode = sel.focusNode; this.lastFocusOffset = sel.focusOffset;
8888
+ };
8889
+
8890
+ ContentEditableInput.prototype.selectionInEditor = function () {
8891
+ var sel = this.getSelection();
8892
+ if (!sel.rangeCount) { return false }
8893
+ var node = sel.getRangeAt(0).commonAncestorContainer;
8894
+ return contains(this.div, node)
8895
+ };
8896
+
8897
+ ContentEditableInput.prototype.focus = function () {
8898
+ if (this.cm.options.readOnly != "nocursor") {
8899
+ if (!this.selectionInEditor())
8900
+ { this.showSelection(this.prepareSelection(), true); }
8901
+ this.div.focus();
8902
+ }
8903
+ };
8904
+ ContentEditableInput.prototype.blur = function () { this.div.blur(); };
8905
+ ContentEditableInput.prototype.getField = function () { return this.div };
8906
+
8907
+ ContentEditableInput.prototype.supportsTouch = function () { return true };
8908
+
8909
+ ContentEditableInput.prototype.receivedFocus = function () {
8910
+ var input = this;
8911
+ if (this.selectionInEditor())
8912
+ { this.pollSelection(); }
8913
+ else
8914
+ { runInOp(this.cm, function () { return input.cm.curOp.selectionChanged = true; }); }
8915
+
8916
+ function poll() {
8917
+ if (input.cm.state.focused) {
8918
+ input.pollSelection();
8919
+ input.polling.set(input.cm.options.pollInterval, poll);
8920
+ }
8921
+ }
8922
+ this.polling.set(this.cm.options.pollInterval, poll);
8923
+ };
8924
+
8925
+ ContentEditableInput.prototype.selectionChanged = function () {
8926
+ var sel = this.getSelection();
8927
+ return sel.anchorNode != this.lastAnchorNode || sel.anchorOffset != this.lastAnchorOffset ||
8928
+ sel.focusNode != this.lastFocusNode || sel.focusOffset != this.lastFocusOffset
8929
+ };
8930
+
8931
+ ContentEditableInput.prototype.pollSelection = function () {
8932
+ if (this.readDOMTimeout != null || this.gracePeriod || !this.selectionChanged()) { return }
8933
+ var sel = this.getSelection(), cm = this.cm;
8934
+ // On Android Chrome (version 56, at least), backspacing into an
8935
+ // uneditable block element will put the cursor in that element,
8936
+ // and then, because it's not editable, hide the virtual keyboard.
8937
+ // Because Android doesn't allow us to actually detect backspace
8938
+ // presses in a sane way, this code checks for when that happens
8939
+ // and simulates a backspace press in this case.
8940
+ if (android && chrome && this.cm.options.gutters.length && isInGutter(sel.anchorNode)) {
8941
+ this.cm.triggerOnKeyDown({type: "keydown", keyCode: 8, preventDefault: Math.abs});
8942
+ this.blur();
8943
+ this.focus();
8944
+ return
8945
+ }
8946
+ if (this.composing) { return }
8947
+ this.rememberSelection();
8948
+ var anchor = domToPos(cm, sel.anchorNode, sel.anchorOffset);
8949
+ var head = domToPos(cm, sel.focusNode, sel.focusOffset);
8950
+ if (anchor && head) { runInOp(cm, function () {
8951
+ setSelection(cm.doc, simpleSelection(anchor, head), sel_dontScroll);
8952
+ if (anchor.bad || head.bad) { cm.curOp.selectionChanged = true; }
8953
+ }); }
8954
+ };
8955
+
8956
+ ContentEditableInput.prototype.pollContent = function () {
8957
+ if (this.readDOMTimeout != null) {
8958
+ clearTimeout(this.readDOMTimeout);
8959
+ this.readDOMTimeout = null;
8960
+ }
8961
+
8962
+ var cm = this.cm, display = cm.display, sel = cm.doc.sel.primary();
8963
+ var from = sel.from(), to = sel.to();
8964
+ if (from.ch == 0 && from.line > cm.firstLine())
8965
+ { from = Pos(from.line - 1, getLine(cm.doc, from.line - 1).length); }
8966
+ if (to.ch == getLine(cm.doc, to.line).text.length && to.line < cm.lastLine())
8967
+ { to = Pos(to.line + 1, 0); }
8968
+ if (from.line < display.viewFrom || to.line > display.viewTo - 1) { return false }
8969
+
8970
+ var fromIndex, fromLine, fromNode;
8971
+ if (from.line == display.viewFrom || (fromIndex = findViewIndex(cm, from.line)) == 0) {
8972
+ fromLine = lineNo(display.view[0].line);
8973
+ fromNode = display.view[0].node;
8974
+ } else {
8975
+ fromLine = lineNo(display.view[fromIndex].line);
8976
+ fromNode = display.view[fromIndex - 1].node.nextSibling;
8977
+ }
8978
+ var toIndex = findViewIndex(cm, to.line);
8979
+ var toLine, toNode;
8980
+ if (toIndex == display.view.length - 1) {
8981
+ toLine = display.viewTo - 1;
8982
+ toNode = display.lineDiv.lastChild;
8983
+ } else {
8984
+ toLine = lineNo(display.view[toIndex + 1].line) - 1;
8985
+ toNode = display.view[toIndex + 1].node.previousSibling;
8986
+ }
8987
+
8988
+ if (!fromNode) { return false }
8989
+ var newText = cm.doc.splitLines(domTextBetween(cm, fromNode, toNode, fromLine, toLine));
8990
+ var oldText = getBetween(cm.doc, Pos(fromLine, 0), Pos(toLine, getLine(cm.doc, toLine).text.length));
8991
+ while (newText.length > 1 && oldText.length > 1) {
8992
+ if (lst(newText) == lst(oldText)) { newText.pop(); oldText.pop(); toLine--; }
8993
+ else if (newText[0] == oldText[0]) { newText.shift(); oldText.shift(); fromLine++; }
8994
+ else { break }
8995
+ }
8996
+
8997
+ var cutFront = 0, cutEnd = 0;
8998
+ var newTop = newText[0], oldTop = oldText[0], maxCutFront = Math.min(newTop.length, oldTop.length);
8999
+ while (cutFront < maxCutFront && newTop.charCodeAt(cutFront) == oldTop.charCodeAt(cutFront))
9000
+ { ++cutFront; }
9001
+ var newBot = lst(newText), oldBot = lst(oldText);
9002
+ var maxCutEnd = Math.min(newBot.length - (newText.length == 1 ? cutFront : 0),
9003
+ oldBot.length - (oldText.length == 1 ? cutFront : 0));
9004
+ while (cutEnd < maxCutEnd &&
9005
+ newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1))
9006
+ { ++cutEnd; }
9007
+ // Try to move start of change to start of selection if ambiguous
9008
+ if (newText.length == 1 && oldText.length == 1 && fromLine == from.line) {
9009
+ while (cutFront && cutFront > from.ch &&
9010
+ newBot.charCodeAt(newBot.length - cutEnd - 1) == oldBot.charCodeAt(oldBot.length - cutEnd - 1)) {
9011
+ cutFront--;
9012
+ cutEnd++;
9013
+ }
9014
+ }
9015
+
9016
+ newText[newText.length - 1] = newBot.slice(0, newBot.length - cutEnd).replace(/^\u200b+/, "");
9017
+ newText[0] = newText[0].slice(cutFront).replace(/\u200b+$/, "");
9018
+
9019
+ var chFrom = Pos(fromLine, cutFront);
9020
+ var chTo = Pos(toLine, oldText.length ? lst(oldText).length - cutEnd : 0);
9021
+ if (newText.length > 1 || newText[0] || cmp(chFrom, chTo)) {
9022
+ replaceRange(cm.doc, newText, chFrom, chTo, "+input");
9023
+ return true
9024
+ }
9025
+ };
9026
+
9027
+ ContentEditableInput.prototype.ensurePolled = function () {
9028
+ this.forceCompositionEnd();
9029
+ };
9030
+ ContentEditableInput.prototype.reset = function () {
9031
+ this.forceCompositionEnd();
9032
+ };
9033
+ ContentEditableInput.prototype.forceCompositionEnd = function () {
9034
+ if (!this.composing) { return }
9035
+ clearTimeout(this.readDOMTimeout);
9036
+ this.composing = null;
9037
+ this.updateFromDOM();
9038
+ this.div.blur();
9039
+ this.div.focus();
9040
+ };
9041
+ ContentEditableInput.prototype.readFromDOMSoon = function () {
9042
+ var this$1 = this;
9043
+
9044
+ if (this.readDOMTimeout != null) { return }
9045
+ this.readDOMTimeout = setTimeout(function () {
9046
+ this$1.readDOMTimeout = null;
9047
+ if (this$1.composing) {
9048
+ if (this$1.composing.done) { this$1.composing = null; }
9049
+ else { return }
9050
+ }
9051
+ this$1.updateFromDOM();
9052
+ }, 80);
9053
+ };
9054
+
9055
+ ContentEditableInput.prototype.updateFromDOM = function () {
9056
+ var this$1 = this;
9057
+
9058
+ if (this.cm.isReadOnly() || !this.pollContent())
9059
+ { runInOp(this.cm, function () { return regChange(this$1.cm); }); }
9060
+ };
9061
+
9062
+ ContentEditableInput.prototype.setUneditable = function (node) {
9063
+ node.contentEditable = "false";
9064
+ };
9065
+
9066
+ ContentEditableInput.prototype.onKeyPress = function (e) {
9067
+ if (e.charCode == 0 || this.composing) { return }
9068
+ e.preventDefault();
9069
+ if (!this.cm.isReadOnly())
9070
+ { operation(this.cm, applyTextInput)(this.cm, String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode), 0); }
9071
+ };
9072
+
9073
+ ContentEditableInput.prototype.readOnlyChanged = function (val) {
9074
+ this.div.contentEditable = String(val != "nocursor");
9075
+ };
9076
+
9077
+ ContentEditableInput.prototype.onContextMenu = function () {};
9078
+ ContentEditableInput.prototype.resetPosition = function () {};
9079
+
9080
+ ContentEditableInput.prototype.needsContentAttribute = true;
9081
+
9082
+ function posToDOM(cm, pos) {
9083
+ var view = findViewForLine(cm, pos.line);
9084
+ if (!view || view.hidden) { return null }
9085
+ var line = getLine(cm.doc, pos.line);
9086
+ var info = mapFromLineView(view, line, pos.line);
9087
+
9088
+ var order = getOrder(line, cm.doc.direction), side = "left";
9089
+ if (order) {
9090
+ var partPos = getBidiPartAt(order, pos.ch);
9091
+ side = partPos % 2 ? "right" : "left";
9092
+ }
9093
+ var result = nodeAndOffsetInLineMap(info.map, pos.ch, side);
9094
+ result.offset = result.collapse == "right" ? result.end : result.start;
9095
+ return result
9096
+ }
9097
+
9098
+ function isInGutter(node) {
9099
+ for (var scan = node; scan; scan = scan.parentNode)
9100
+ { if (/CodeMirror-gutter-wrapper/.test(scan.className)) { return true } }
9101
+ return false
9102
+ }
9103
+
9104
+ function badPos(pos, bad) { if (bad) { pos.bad = true; } return pos }
9105
+
9106
+ function domTextBetween(cm, from, to, fromLine, toLine) {
9107
+ var text = "", closing = false, lineSep = cm.doc.lineSeparator(), extraLinebreak = false;
9108
+ function recognizeMarker(id) { return function (marker) { return marker.id == id; } }
9109
+ function close() {
9110
+ if (closing) {
9111
+ text += lineSep;
9112
+ if (extraLinebreak) { text += lineSep; }
9113
+ closing = extraLinebreak = false;
9114
+ }
9115
+ }
9116
+ function addText(str) {
9117
+ if (str) {
9118
+ close();
9119
+ text += str;
9120
+ }
9121
+ }
9122
+ function walk(node) {
9123
+ if (node.nodeType == 1) {
9124
+ var cmText = node.getAttribute("cm-text");
9125
+ if (cmText) {
9126
+ addText(cmText);
9127
+ return
9128
+ }
9129
+ var markerID = node.getAttribute("cm-marker"), range$$1;
9130
+ if (markerID) {
9131
+ var found = cm.findMarks(Pos(fromLine, 0), Pos(toLine + 1, 0), recognizeMarker(+markerID));
9132
+ if (found.length && (range$$1 = found[0].find(0)))
9133
+ { addText(getBetween(cm.doc, range$$1.from, range$$1.to).join(lineSep)); }
9134
+ return
9135
+ }
9136
+ if (node.getAttribute("contenteditable") == "false") { return }
9137
+ var isBlock = /^(pre|div|p|li|table|br)$/i.test(node.nodeName);
9138
+ if (!/^br$/i.test(node.nodeName) && node.textContent.length == 0) { return }
9139
+
9140
+ if (isBlock) { close(); }
9141
+ for (var i = 0; i < node.childNodes.length; i++)
9142
+ { walk(node.childNodes[i]); }
9143
+
9144
+ if (/^(pre|p)$/i.test(node.nodeName)) { extraLinebreak = true; }
9145
+ if (isBlock) { closing = true; }
9146
+ } else if (node.nodeType == 3) {
9147
+ addText(node.nodeValue.replace(/\u200b/g, "").replace(/\u00a0/g, " "));
9148
+ }
9149
+ }
9150
+ for (;;) {
9151
+ walk(from);
9152
+ if (from == to) { break }
9153
+ from = from.nextSibling;
9154
+ extraLinebreak = false;
9155
+ }
9156
+ return text
9157
+ }
9158
+
9159
+ function domToPos(cm, node, offset) {
9160
+ var lineNode;
9161
+ if (node == cm.display.lineDiv) {
9162
+ lineNode = cm.display.lineDiv.childNodes[offset];
9163
+ if (!lineNode) { return badPos(cm.clipPos(Pos(cm.display.viewTo - 1)), true) }
9164
+ node = null; offset = 0;
9165
+ } else {
9166
+ for (lineNode = node;; lineNode = lineNode.parentNode) {
9167
+ if (!lineNode || lineNode == cm.display.lineDiv) { return null }
9168
+ if (lineNode.parentNode && lineNode.parentNode == cm.display.lineDiv) { break }
9169
+ }
9170
+ }
9171
+ for (var i = 0; i < cm.display.view.length; i++) {
9172
+ var lineView = cm.display.view[i];
9173
+ if (lineView.node == lineNode)
9174
+ { return locateNodeInLineView(lineView, node, offset) }
9175
+ }
9176
+ }
9177
+
9178
+ function locateNodeInLineView(lineView, node, offset) {
9179
+ var wrapper = lineView.text.firstChild, bad = false;
9180
+ if (!node || !contains(wrapper, node)) { return badPos(Pos(lineNo(lineView.line), 0), true) }
9181
+ if (node == wrapper) {
9182
+ bad = true;
9183
+ node = wrapper.childNodes[offset];
9184
+ offset = 0;
9185
+ if (!node) {
9186
+ var line = lineView.rest ? lst(lineView.rest) : lineView.line;
9187
+ return badPos(Pos(lineNo(line), line.text.length), bad)
9188
+ }
9189
+ }
9190
+
9191
+ var textNode = node.nodeType == 3 ? node : null, topNode = node;
9192
+ if (!textNode && node.childNodes.length == 1 && node.firstChild.nodeType == 3) {
9193
+ textNode = node.firstChild;
9194
+ if (offset) { offset = textNode.nodeValue.length; }
9195
+ }
9196
+ while (topNode.parentNode != wrapper) { topNode = topNode.parentNode; }
9197
+ var measure = lineView.measure, maps = measure.maps;
9198
+
9199
+ function find(textNode, topNode, offset) {
9200
+ for (var i = -1; i < (maps ? maps.length : 0); i++) {
9201
+ var map$$1 = i < 0 ? measure.map : maps[i];
9202
+ for (var j = 0; j < map$$1.length; j += 3) {
9203
+ var curNode = map$$1[j + 2];
9204
+ if (curNode == textNode || curNode == topNode) {
9205
+ var line = lineNo(i < 0 ? lineView.line : lineView.rest[i]);
9206
+ var ch = map$$1[j] + offset;
9207
+ if (offset < 0 || curNode != textNode) { ch = map$$1[j + (offset ? 1 : 0)]; }
9208
+ return Pos(line, ch)
9209
+ }
9210
+ }
9211
+ }
9212
+ }
9213
+ var found = find(textNode, topNode, offset);
9214
+ if (found) { return badPos(found, bad) }
9215
+
9216
+ // FIXME this is all really shaky. might handle the few cases it needs to handle, but likely to cause problems
9217
+ for (var after = topNode.nextSibling, dist = textNode ? textNode.nodeValue.length - offset : 0; after; after = after.nextSibling) {
9218
+ found = find(after, after.firstChild, 0);
9219
+ if (found)
9220
+ { return badPos(Pos(found.line, found.ch - dist), bad) }
9221
+ else
9222
+ { dist += after.textContent.length; }
9223
+ }
9224
+ for (var before = topNode.previousSibling, dist$1 = offset; before; before = before.previousSibling) {
9225
+ found = find(before, before.firstChild, -1);
9226
+ if (found)
9227
+ { return badPos(Pos(found.line, found.ch + dist$1), bad) }
9228
+ else
9229
+ { dist$1 += before.textContent.length; }
9230
+ }
9231
+ }
9232
+
9233
+ // TEXTAREA INPUT STYLE
9234
+
9235
+ var TextareaInput = function(cm) {
9236
+ this.cm = cm;
9237
+ // See input.poll and input.reset
9238
+ this.prevInput = "";
9239
+
9240
+ // Flag that indicates whether we expect input to appear real soon
9241
+ // now (after some event like 'keypress' or 'input') and are
9242
+ // polling intensively.
9243
+ this.pollingFast = false;
9244
+ // Self-resetting timeout for the poller
9245
+ this.polling = new Delayed();
9246
+ // Used to work around IE issue with selection being forgotten when focus moves away from textarea
9247
+ this.hasSelection = false;
9248
+ this.composing = null;
9249
+ };
9250
+
9251
+ TextareaInput.prototype.init = function (display) {
9252
+ var this$1 = this;
9253
+
9254
+ var input = this, cm = this.cm;
9255
+ this.createField(display);
9256
+ var te = this.textarea;
9257
+
9258
+ display.wrapper.insertBefore(this.wrapper, display.wrapper.firstChild);
9259
+
9260
+ // Needed to hide big blue blinking cursor on Mobile Safari (doesn't seem to work in iOS 8 anymore)
9261
+ if (ios) { te.style.width = "0px"; }
9262
+
9263
+ on(te, "input", function () {
9264
+ if (ie && ie_version >= 9 && this$1.hasSelection) { this$1.hasSelection = null; }
9265
+ input.poll();
9266
+ });
9267
+
9268
+ on(te, "paste", function (e) {
9269
+ if (signalDOMEvent(cm, e) || handlePaste(e, cm)) { return }
9270
+
9271
+ cm.state.pasteIncoming = true;
9272
+ input.fastPoll();
9273
+ });
9274
+
9275
+ function prepareCopyCut(e) {
9276
+ if (signalDOMEvent(cm, e)) { return }
9277
+ if (cm.somethingSelected()) {
9278
+ setLastCopied({lineWise: false, text: cm.getSelections()});
9279
+ } else if (!cm.options.lineWiseCopyCut) {
9280
+ return
9281
+ } else {
9282
+ var ranges = copyableRanges(cm);
9283
+ setLastCopied({lineWise: true, text: ranges.text});
9284
+ if (e.type == "cut") {
9285
+ cm.setSelections(ranges.ranges, null, sel_dontScroll);
9286
+ } else {
9287
+ input.prevInput = "";
9288
+ te.value = ranges.text.join("\n");
9289
+ selectInput(te);
9290
+ }
9291
+ }
9292
+ if (e.type == "cut") { cm.state.cutIncoming = true; }
9293
+ }
9294
+ on(te, "cut", prepareCopyCut);
9295
+ on(te, "copy", prepareCopyCut);
9296
+
9297
+ on(display.scroller, "paste", function (e) {
9298
+ if (eventInWidget(display, e) || signalDOMEvent(cm, e)) { return }
9299
+ cm.state.pasteIncoming = true;
9300
+ input.focus();
9301
+ });
9302
+
9303
+ // Prevent normal selection in the editor (we handle our own)
9304
+ on(display.lineSpace, "selectstart", function (e) {
9305
+ if (!eventInWidget(display, e)) { e_preventDefault(e); }
9306
+ });
9307
+
9308
+ on(te, "compositionstart", function () {
9309
+ var start = cm.getCursor("from");
9310
+ if (input.composing) { input.composing.range.clear(); }
9311
+ input.composing = {
9312
+ start: start,
9313
+ range: cm.markText(start, cm.getCursor("to"), {className: "CodeMirror-composing"})
9314
+ };
9315
+ });
9316
+ on(te, "compositionend", function () {
9317
+ if (input.composing) {
9318
+ input.poll();
9319
+ input.composing.range.clear();
9320
+ input.composing = null;
9321
+ }
9322
+ });
9323
+ };
9324
+
9325
+ TextareaInput.prototype.createField = function (_display) {
9326
+ // Wraps and hides input textarea
9327
+ this.wrapper = hiddenTextarea();
9328
+ // The semihidden textarea that is focused when the editor is
9329
+ // focused, and receives input.
9330
+ this.textarea = this.wrapper.firstChild;
9331
+ };
9332
+
9333
+ TextareaInput.prototype.prepareSelection = function () {
9334
+ // Redraw the selection and/or cursor
9335
+ var cm = this.cm, display = cm.display, doc = cm.doc;
9336
+ var result = prepareSelection(cm);
9337
+
9338
+ // Move the hidden textarea near the cursor to prevent scrolling artifacts
9339
+ if (cm.options.moveInputWithCursor) {
9340
+ var headPos = cursorCoords(cm, doc.sel.primary().head, "div");
9341
+ var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect();
9342
+ result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
9343
+ headPos.top + lineOff.top - wrapOff.top));
9344
+ result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
9345
+ headPos.left + lineOff.left - wrapOff.left));
9346
+ }
9347
+
9348
+ return result
9349
+ };
9350
+
9351
+ TextareaInput.prototype.showSelection = function (drawn) {
9352
+ var cm = this.cm, display = cm.display;
9353
+ removeChildrenAndAdd(display.cursorDiv, drawn.cursors);
9354
+ removeChildrenAndAdd(display.selectionDiv, drawn.selection);
9355
+ if (drawn.teTop != null) {
9356
+ this.wrapper.style.top = drawn.teTop + "px";
9357
+ this.wrapper.style.left = drawn.teLeft + "px";
9358
+ }
9359
+ };
9360
+
9361
+ // Reset the input to correspond to the selection (or to be empty,
9362
+ // when not typing and nothing is selected)
9363
+ TextareaInput.prototype.reset = function (typing) {
9364
+ if (this.contextMenuPending || this.composing) { return }
9365
+ var cm = this.cm;
9366
+ if (cm.somethingSelected()) {
9367
+ this.prevInput = "";
9368
+ var content = cm.getSelection();
9369
+ this.textarea.value = content;
9370
+ if (cm.state.focused) { selectInput(this.textarea); }
9371
+ if (ie && ie_version >= 9) { this.hasSelection = content; }
9372
+ } else if (!typing) {
9373
+ this.prevInput = this.textarea.value = "";
9374
+ if (ie && ie_version >= 9) { this.hasSelection = null; }
9375
+ }
9376
+ };
9377
+
9378
+ TextareaInput.prototype.getField = function () { return this.textarea };
9379
+
9380
+ TextareaInput.prototype.supportsTouch = function () { return false };
9381
+
9382
+ TextareaInput.prototype.focus = function () {
9383
+ if (this.cm.options.readOnly != "nocursor" && (!mobile || activeElt() != this.textarea)) {
9384
+ try { this.textarea.focus(); }
9385
+ catch (e) {} // IE8 will throw if the textarea is display: none or not in DOM
9386
+ }
9387
+ };
9388
+
9389
+ TextareaInput.prototype.blur = function () { this.textarea.blur(); };
9390
+
9391
+ TextareaInput.prototype.resetPosition = function () {
9392
+ this.wrapper.style.top = this.wrapper.style.left = 0;
9393
+ };
9394
+
9395
+ TextareaInput.prototype.receivedFocus = function () { this.slowPoll(); };
9396
+
9397
+ // Poll for input changes, using the normal rate of polling. This
9398
+ // runs as long as the editor is focused.
9399
+ TextareaInput.prototype.slowPoll = function () {
9400
+ var this$1 = this;
9401
+
9402
+ if (this.pollingFast) { return }
9403
+ this.polling.set(this.cm.options.pollInterval, function () {
9404
+ this$1.poll();
9405
+ if (this$1.cm.state.focused) { this$1.slowPoll(); }
9406
+ });
9407
+ };
9408
+
9409
+ // When an event has just come in that is likely to add or change
9410
+ // something in the input textarea, we poll faster, to ensure that
9411
+ // the change appears on the screen quickly.
9412
+ TextareaInput.prototype.fastPoll = function () {
9413
+ var missed = false, input = this;
9414
+ input.pollingFast = true;
9415
+ function p() {
9416
+ var changed = input.poll();
9417
+ if (!changed && !missed) {missed = true; input.polling.set(60, p);}
9418
+ else {input.pollingFast = false; input.slowPoll();}
9419
+ }
9420
+ input.polling.set(20, p);
9421
+ };
9422
+
9423
+ // Read input from the textarea, and update the document to match.
9424
+ // When something is selected, it is present in the textarea, and
9425
+ // selected (unless it is huge, in which case a placeholder is
9426
+ // used). When nothing is selected, the cursor sits after previously
9427
+ // seen text (can be empty), which is stored in prevInput (we must
9428
+ // not reset the textarea when typing, because that breaks IME).
9429
+ TextareaInput.prototype.poll = function () {
9430
+ var this$1 = this;
9431
+
9432
+ var cm = this.cm, input = this.textarea, prevInput = this.prevInput;
9433
+ // Since this is called a *lot*, try to bail out as cheaply as
9434
+ // possible when it is clear that nothing happened. hasSelection
9435
+ // will be the case when there is a lot of text in the textarea,
9436
+ // in which case reading its value would be expensive.
9437
+ if (this.contextMenuPending || !cm.state.focused ||
9438
+ (hasSelection(input) && !prevInput && !this.composing) ||
9439
+ cm.isReadOnly() || cm.options.disableInput || cm.state.keySeq)
9440
+ { return false }
9441
+
9442
+ var text = input.value;
9443
+ // If nothing changed, bail.
9444
+ if (text == prevInput && !cm.somethingSelected()) { return false }
9445
+ // Work around nonsensical selection resetting in IE9/10, and
9446
+ // inexplicable appearance of private area unicode characters on
9447
+ // some key combos in Mac (#2689).
9448
+ if (ie && ie_version >= 9 && this.hasSelection === text ||
9449
+ mac && /[\uf700-\uf7ff]/.test(text)) {
9450
+ cm.display.input.reset();
9451
+ return false
9452
+ }
9453
+
9454
+ if (cm.doc.sel == cm.display.selForContextMenu) {
9455
+ var first = text.charCodeAt(0);
9456
+ if (first == 0x200b && !prevInput) { prevInput = "\u200b"; }
9457
+ if (first == 0x21da) { this.reset(); return this.cm.execCommand("undo") }
9458
+ }
9459
+ // Find the part of the input that is actually new
9460
+ var same = 0, l = Math.min(prevInput.length, text.length);
9461
+ while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) { ++same; }
9462
+
9463
+ runInOp(cm, function () {
9464
+ applyTextInput(cm, text.slice(same), prevInput.length - same,
9465
+ null, this$1.composing ? "*compose" : null);
9466
+
9467
+ // Don't leave long text in the textarea, since it makes further polling slow
9468
+ if (text.length > 1000 || text.indexOf("\n") > -1) { input.value = this$1.prevInput = ""; }
9469
+ else { this$1.prevInput = text; }
9470
+
9471
+ if (this$1.composing) {
9472
+ this$1.composing.range.clear();
9473
+ this$1.composing.range = cm.markText(this$1.composing.start, cm.getCursor("to"),
9474
+ {className: "CodeMirror-composing"});
9475
+ }
9476
+ });
9477
+ return true
9478
+ };
9479
+
9480
+ TextareaInput.prototype.ensurePolled = function () {
9481
+ if (this.pollingFast && this.poll()) { this.pollingFast = false; }
9482
+ };
9483
+
9484
+ TextareaInput.prototype.onKeyPress = function () {
9485
+ if (ie && ie_version >= 9) { this.hasSelection = null; }
9486
+ this.fastPoll();
9487
+ };
9488
+
9489
+ TextareaInput.prototype.onContextMenu = function (e) {
9490
+ var input = this, cm = input.cm, display = cm.display, te = input.textarea;
9491
+ var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
9492
+ if (!pos || presto) { return } // Opera is difficult.
9493
+
9494
+ // Reset the current text selection only if the click is done outside of the selection
9495
+ // and 'resetSelectionOnContextMenu' option is true.
9496
+ var reset = cm.options.resetSelectionOnContextMenu;
9497
+ if (reset && cm.doc.sel.contains(pos) == -1)
9498
+ { operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll); }
9499
+
9500
+ var oldCSS = te.style.cssText, oldWrapperCSS = input.wrapper.style.cssText;
9501
+ input.wrapper.style.cssText = "position: absolute";
9502
+ var wrapperBox = input.wrapper.getBoundingClientRect();
9503
+ te.style.cssText = "position: absolute; width: 30px; height: 30px;\n top: " + (e.clientY - wrapperBox.top - 5) + "px; left: " + (e.clientX - wrapperBox.left - 5) + "px;\n z-index: 1000; background: " + (ie ? "rgba(255, 255, 255, .05)" : "transparent") + ";\n outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";
9504
+ var oldScrollY;
9505
+ if (webkit) { oldScrollY = window.scrollY; } // Work around Chrome issue (#2712)
9506
+ display.input.focus();
9507
+ if (webkit) { window.scrollTo(null, oldScrollY); }
9508
+ display.input.reset();
9509
+ // Adds "Select all" to context menu in FF
9510
+ if (!cm.somethingSelected()) { te.value = input.prevInput = " "; }
9511
+ input.contextMenuPending = true;
9512
+ display.selForContextMenu = cm.doc.sel;
9513
+ clearTimeout(display.detectingSelectAll);
9514
+
9515
+ // Select-all will be greyed out if there's nothing to select, so
9516
+ // this adds a zero-width space so that we can later check whether
9517
+ // it got selected.
9518
+ function prepareSelectAllHack() {
9519
+ if (te.selectionStart != null) {
9520
+ var selected = cm.somethingSelected();
9521
+ var extval = "\u200b" + (selected ? te.value : "");
9522
+ te.value = "\u21da"; // Used to catch context-menu undo
9523
+ te.value = extval;
9524
+ input.prevInput = selected ? "" : "\u200b";
9525
+ te.selectionStart = 1; te.selectionEnd = extval.length;
9526
+ // Re-set this, in case some other handler touched the
9527
+ // selection in the meantime.
9528
+ display.selForContextMenu = cm.doc.sel;
9529
+ }
9530
+ }
9531
+ function rehide() {
9532
+ input.contextMenuPending = false;
9533
+ input.wrapper.style.cssText = oldWrapperCSS;
9534
+ te.style.cssText = oldCSS;
9535
+ if (ie && ie_version < 9) { display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos); }
9536
+
9537
+ // Try to detect the user choosing select-all
9538
+ if (te.selectionStart != null) {
9539
+ if (!ie || (ie && ie_version < 9)) { prepareSelectAllHack(); }
9540
+ var i = 0, poll = function () {
9541
+ if (display.selForContextMenu == cm.doc.sel && te.selectionStart == 0 &&
9542
+ te.selectionEnd > 0 && input.prevInput == "\u200b") {
9543
+ operation(cm, selectAll)(cm);
9544
+ } else if (i++ < 10) {
9545
+ display.detectingSelectAll = setTimeout(poll, 500);
9546
+ } else {
9547
+ display.selForContextMenu = null;
9548
+ display.input.reset();
9549
+ }
9550
+ };
9551
+ display.detectingSelectAll = setTimeout(poll, 200);
9552
+ }
9553
+ }
9554
+
9555
+ if (ie && ie_version >= 9) { prepareSelectAllHack(); }
9556
+ if (captureRightClick) {
9557
+ e_stop(e);
9558
+ var mouseup = function () {
9559
+ off(window, "mouseup", mouseup);
9560
+ setTimeout(rehide, 20);
9561
+ };
9562
+ on(window, "mouseup", mouseup);
9563
+ } else {
9564
+ setTimeout(rehide, 50);
9565
+ }
9566
+ };
9567
+
9568
+ TextareaInput.prototype.readOnlyChanged = function (val) {
9569
+ if (!val) { this.reset(); }
9570
+ this.textarea.disabled = val == "nocursor";
9571
+ };
9572
+
9573
+ TextareaInput.prototype.setUneditable = function () {};
9574
+
9575
+ TextareaInput.prototype.needsContentAttribute = false;
9576
+
9577
+ function fromTextArea(textarea, options) {
9578
+ options = options ? copyObj(options) : {};
9579
+ options.value = textarea.value;
9580
+ if (!options.tabindex && textarea.tabIndex)
9581
+ { options.tabindex = textarea.tabIndex; }
9582
+ if (!options.placeholder && textarea.placeholder)
9583
+ { options.placeholder = textarea.placeholder; }
9584
+ // Set autofocus to true if this textarea is focused, or if it has
9585
+ // autofocus and no other element is focused.
9586
+ if (options.autofocus == null) {
9587
+ var hasFocus = activeElt();
9588
+ options.autofocus = hasFocus == textarea ||
9589
+ textarea.getAttribute("autofocus") != null && hasFocus == document.body;
9590
+ }
9591
+
9592
+ function save() {textarea.value = cm.getValue();}
9593
+
9594
+ var realSubmit;
9595
+ if (textarea.form) {
9596
+ on(textarea.form, "submit", save);
9597
+ // Deplorable hack to make the submit method do the right thing.
9598
+ if (!options.leaveSubmitMethodAlone) {
9599
+ var form = textarea.form;
9600
+ realSubmit = form.submit;
9601
+ try {
9602
+ var wrappedSubmit = form.submit = function () {
9603
+ save();
9604
+ form.submit = realSubmit;
9605
+ form.submit();
9606
+ form.submit = wrappedSubmit;
9607
+ };
9608
+ } catch(e) {}
9609
+ }
9610
+ }
9611
+
9612
+ options.finishInit = function (cm) {
9613
+ cm.save = save;
9614
+ cm.getTextArea = function () { return textarea; };
9615
+ cm.toTextArea = function () {
9616
+ cm.toTextArea = isNaN; // Prevent this from being ran twice
9617
+ save();
9618
+ textarea.parentNode.removeChild(cm.getWrapperElement());
9619
+ textarea.style.display = "";
9620
+ if (textarea.form) {
9621
+ off(textarea.form, "submit", save);
9622
+ if (typeof textarea.form.submit == "function")
9623
+ { textarea.form.submit = realSubmit; }
9624
+ }
9625
+ };
9626
+ };
9627
+
9628
+ textarea.style.display = "none";
9629
+ var cm = CodeMirror(function (node) { return textarea.parentNode.insertBefore(node, textarea.nextSibling); },
9630
+ options);
9631
+ return cm
9632
+ }
9633
+
9634
+ function addLegacyProps(CodeMirror) {
9635
+ CodeMirror.off = off;
9636
+ CodeMirror.on = on;
9637
+ CodeMirror.wheelEventPixels = wheelEventPixels;
9638
+ CodeMirror.Doc = Doc;
9639
+ CodeMirror.splitLines = splitLinesAuto;
9640
+ CodeMirror.countColumn = countColumn;
9641
+ CodeMirror.findColumn = findColumn;
9642
+ CodeMirror.isWordChar = isWordCharBasic;
9643
+ CodeMirror.Pass = Pass;
9644
+ CodeMirror.signal = signal;
9645
+ CodeMirror.Line = Line;
9646
+ CodeMirror.changeEnd = changeEnd;
9647
+ CodeMirror.scrollbarModel = scrollbarModel;
9648
+ CodeMirror.Pos = Pos;
9649
+ CodeMirror.cmpPos = cmp;
9650
+ CodeMirror.modes = modes;
9651
+ CodeMirror.mimeModes = mimeModes;
9652
+ CodeMirror.resolveMode = resolveMode;
9653
+ CodeMirror.getMode = getMode;
9654
+ CodeMirror.modeExtensions = modeExtensions;
9655
+ CodeMirror.extendMode = extendMode;
9656
+ CodeMirror.copyState = copyState;
9657
+ CodeMirror.startState = startState;
9658
+ CodeMirror.innerMode = innerMode;
9659
+ CodeMirror.commands = commands;
9660
+ CodeMirror.keyMap = keyMap;
9661
+ CodeMirror.keyName = keyName;
9662
+ CodeMirror.isModifierKey = isModifierKey;
9663
+ CodeMirror.lookupKey = lookupKey;
9664
+ CodeMirror.normalizeKeyMap = normalizeKeyMap;
9665
+ CodeMirror.StringStream = StringStream;
9666
+ CodeMirror.SharedTextMarker = SharedTextMarker;
9667
+ CodeMirror.TextMarker = TextMarker;
9668
+ CodeMirror.LineWidget = LineWidget;
9669
+ CodeMirror.e_preventDefault = e_preventDefault;
9670
+ CodeMirror.e_stopPropagation = e_stopPropagation;
9671
+ CodeMirror.e_stop = e_stop;
9672
+ CodeMirror.addClass = addClass;
9673
+ CodeMirror.contains = contains;
9674
+ CodeMirror.rmClass = rmClass;
9675
+ CodeMirror.keyNames = keyNames;
9676
+ }
9677
+
9678
+ // EDITOR CONSTRUCTOR
9679
+
9680
+ defineOptions(CodeMirror);
9681
+
9682
+ addEditorMethods(CodeMirror);
9683
+
9684
+ // Set up methods on CodeMirror's prototype to redirect to the editor's document.
9685
+ var dontDelegate = "iter insert remove copy getEditor constructor".split(" ");
9686
+ for (var prop in Doc.prototype) { if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0)
9687
+ { CodeMirror.prototype[prop] = (function(method) {
9688
+ return function() {return method.apply(this.doc, arguments)}
9689
+ })(Doc.prototype[prop]); } }
9690
+
9691
+ eventMixin(Doc);
9692
+ CodeMirror.inputStyles = {"textarea": TextareaInput, "contenteditable": ContentEditableInput};
9693
+
9694
+ // Extra arguments are stored as the mode's dependencies, which is
9695
+ // used by (legacy) mechanisms like loadmode.js to automatically
9696
+ // load a mode. (Preferred mechanism is the require/define calls.)
9697
+ CodeMirror.defineMode = function(name/*, mode, …*/) {
9698
+ if (!CodeMirror.defaults.mode && name != "null") { CodeMirror.defaults.mode = name; }
9699
+ defineMode.apply(this, arguments);
9700
+ };
9701
+
9702
+ CodeMirror.defineMIME = defineMIME;
9703
+
9704
+ // Minimal default mode.
9705
+ CodeMirror.defineMode("null", function () { return ({token: function (stream) { return stream.skipToEnd(); }}); });
9706
+ CodeMirror.defineMIME("text/plain", "null");
9707
+
9708
+ // EXTENSIONS
9709
+
9710
+ CodeMirror.defineExtension = function (name, func) {
9711
+ CodeMirror.prototype[name] = func;
9712
+ };
9713
+ CodeMirror.defineDocExtension = function (name, func) {
9714
+ Doc.prototype[name] = func;
9715
+ };
9716
+
9717
+ CodeMirror.fromTextArea = fromTextArea;
9718
+
9719
+ addLegacyProps(CodeMirror);
9720
+
9721
+ CodeMirror.version = "5.42.0";
9722
+
9723
+ return CodeMirror;
9724
+
9725
+ })));
js/codemirror-5.42.0/css.js ADDED
@@ -0,0 +1,832 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: https://codemirror.net/LICENSE
3
+
4
+ (function(mod) {
5
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
6
+ mod(require("../../lib/codemirror"));
7
+ else if (typeof define == "function" && define.amd) // AMD
8
+ define(["../../lib/codemirror"], mod);
9
+ else // Plain browser env
10
+ mod(CodeMirror);
11
+ })(function(CodeMirror) {
12
+ "use strict";
13
+
14
+ CodeMirror.defineMode("css", function(config, parserConfig) {
15
+ var inline = parserConfig.inline
16
+ if (!parserConfig.propertyKeywords) parserConfig = CodeMirror.resolveMode("text/css");
17
+
18
+ var indentUnit = config.indentUnit,
19
+ tokenHooks = parserConfig.tokenHooks,
20
+ documentTypes = parserConfig.documentTypes || {},
21
+ mediaTypes = parserConfig.mediaTypes || {},
22
+ mediaFeatures = parserConfig.mediaFeatures || {},
23
+ mediaValueKeywords = parserConfig.mediaValueKeywords || {},
24
+ propertyKeywords = parserConfig.propertyKeywords || {},
25
+ nonStandardPropertyKeywords = parserConfig.nonStandardPropertyKeywords || {},
26
+ fontProperties = parserConfig.fontProperties || {},
27
+ counterDescriptors = parserConfig.counterDescriptors || {},
28
+ colorKeywords = parserConfig.colorKeywords || {},
29
+ valueKeywords = parserConfig.valueKeywords || {},
30
+ allowNested = parserConfig.allowNested,
31
+ lineComment = parserConfig.lineComment,
32
+ supportsAtComponent = parserConfig.supportsAtComponent === true;
33
+
34
+ var type, override;
35
+ function ret(style, tp) { type = tp; return style; }
36
+
37
+ // Tokenizers
38
+
39
+ function tokenBase(stream, state) {
40
+ var ch = stream.next();
41
+ if (tokenHooks[ch]) {
42
+ var result = tokenHooks[ch](stream, state);
43
+ if (result !== false) return result;
44
+ }
45
+ if (ch == "@") {
46
+ stream.eatWhile(/[\w\\\-]/);
47
+ return ret("def", stream.current());
48
+ } else if (ch == "=" || (ch == "~" || ch == "|") && stream.eat("=")) {
49
+ return ret(null, "compare");
50
+ } else if (ch == "\"" || ch == "'") {
51
+ state.tokenize = tokenString(ch);
52
+ return state.tokenize(stream, state);
53
+ } else if (ch == "#") {
54
+ stream.eatWhile(/[\w\\\-]/);
55
+ return ret("atom", "hash");
56
+ } else if (ch == "!") {
57
+ stream.match(/^\s*\w*/);
58
+ return ret("keyword", "important");
59
+ } else if (/\d/.test(ch) || ch == "." && stream.eat(/\d/)) {
60
+ stream.eatWhile(/[\w.%]/);
61
+ return ret("number", "unit");
62
+ } else if (ch === "-") {
63
+ if (/[\d.]/.test(stream.peek())) {
64
+ stream.eatWhile(/[\w.%]/);
65
+ return ret("number", "unit");
66
+ } else if (stream.match(/^-[\w\\\-]+/)) {
67
+ stream.eatWhile(/[\w\\\-]/);
68
+ if (stream.match(/^\s*:/, false))
69
+ return ret("variable-2", "variable-definition");
70
+ return ret("variable-2", "variable");
71
+ } else if (stream.match(/^\w+-/)) {
72
+ return ret("meta", "meta");
73
+ }
74
+ } else if (/[,+>*\/]/.test(ch)) {
75
+ return ret(null, "select-op");
76
+ } else if (ch == "." && stream.match(/^-?[_a-z][_a-z0-9-]*/i)) {
77
+ return ret("qualifier", "qualifier");
78
+ } else if (/[:;{}\[\]\(\)]/.test(ch)) {
79
+ return ret(null, ch);
80
+ } else if (((ch == "u" || ch == "U") && stream.match(/rl(-prefix)?\(/i)) ||
81
+ ((ch == "d" || ch == "D") && stream.match("omain(", true, true)) ||
82
+ ((ch == "r" || ch == "R") && stream.match("egexp(", true, true))) {
83
+ stream.backUp(1);
84
+ state.tokenize = tokenParenthesized;
85
+ return ret("property", "word");
86
+ } else if (/[\w\\\-]/.test(ch)) {
87
+ stream.eatWhile(/[\w\\\-]/);
88
+ return ret("property", "word");
89
+ } else {
90
+ return ret(null, null);
91
+ }
92
+ }
93
+
94
+ function tokenString(quote) {
95
+ return function(stream, state) {
96
+ var escaped = false, ch;
97
+ while ((ch = stream.next()) != null) {
98
+ if (ch == quote && !escaped) {
99
+ if (quote == ")") stream.backUp(1);
100
+ break;
101
+ }
102
+ escaped = !escaped && ch == "\\";
103
+ }
104
+ if (ch == quote || !escaped && quote != ")") state.tokenize = null;
105
+ return ret("string", "string");
106
+ };
107
+ }
108
+
109
+ function tokenParenthesized(stream, state) {
110
+ stream.next(); // Must be '('
111
+ if (!stream.match(/\s*[\"\')]/, false))
112
+ state.tokenize = tokenString(")");
113
+ else
114
+ state.tokenize = null;
115
+ return ret(null, "(");
116
+ }
117
+
118
+ // Context management
119
+
120
+ function Context(type, indent, prev) {
121
+ this.type = type;
122
+ this.indent = indent;
123
+ this.prev = prev;
124
+ }
125
+
126
+ function pushContext(state, stream, type, indent) {
127
+ state.context = new Context(type, stream.indentation() + (indent === false ? 0 : indentUnit), state.context);
128
+ return type;
129
+ }
130
+
131
+ function popContext(state) {
132
+ if (state.context.prev)
133
+ state.context = state.context.prev;
134
+ return state.context.type;
135
+ }
136
+
137
+ function pass(type, stream, state) {
138
+ return states[state.context.type](type, stream, state);
139
+ }
140
+ function popAndPass(type, stream, state, n) {
141
+ for (var i = n || 1; i > 0; i--)
142
+ state.context = state.context.prev;
143
+ return pass(type, stream, state);
144
+ }
145
+
146
+ // Parser
147
+
148
+ function wordAsValue(stream) {
149
+ var word = stream.current().toLowerCase();
150
+ if (valueKeywords.hasOwnProperty(word))
151
+ override = "atom";
152
+ else if (colorKeywords.hasOwnProperty(word))
153
+ override = "keyword";
154
+ else
155
+ override = "variable";
156
+ }
157
+
158
+ var states = {};
159
+
160
+ states.top = function(type, stream, state) {
161
+ if (type == "{") {
162
+ return pushContext(state, stream, "block");
163
+ } else if (type == "}" && state.context.prev) {
164
+ return popContext(state);
165
+ } else if (supportsAtComponent && /@component/i.test(type)) {
166
+ return pushContext(state, stream, "atComponentBlock");
167
+ } else if (/^@(-moz-)?document$/i.test(type)) {
168
+ return pushContext(state, stream, "documentTypes");
169
+ } else if (/^@(media|supports|(-moz-)?document|import)$/i.test(type)) {
170
+ return pushContext(state, stream, "atBlock");
171
+ } else if (/^@(font-face|counter-style)/i.test(type)) {
172
+ state.stateArg = type;
173
+ return "restricted_atBlock_before";
174
+ } else if (/^@(-(moz|ms|o|webkit)-)?keyframes$/i.test(type)) {
175
+ return "keyframes";
176
+ } else if (type && type.charAt(0) == "@") {
177
+ return pushContext(state, stream, "at");
178
+ } else if (type == "hash") {
179
+ override = "builtin";
180
+ } else if (type == "word") {
181
+ override = "tag";
182
+ } else if (type == "variable-definition") {
183
+ return "maybeprop";
184
+ } else if (type == "interpolation") {
185
+ return pushContext(state, stream, "interpolation");
186
+ } else if (type == ":") {
187
+ return "pseudo";
188
+ } else if (allowNested && type == "(") {
189
+ return pushContext(state, stream, "parens");
190
+ }
191
+ return state.context.type;
192
+ };
193
+
194
+ states.block = function(type, stream, state) {
195
+ if (type == "word") {
196
+ var word = stream.current().toLowerCase();
197
+ if (propertyKeywords.hasOwnProperty(word)) {
198
+ override = "property";
199
+ return "maybeprop";
200
+ } else if (nonStandardPropertyKeywords.hasOwnProperty(word)) {
201
+ override = "string-2";
202
+ return "maybeprop";
203
+ } else if (allowNested) {
204
+ override = stream.match(/^\s*:(?:\s|$)/, false) ? "property" : "tag";
205
+ return "block";
206
+ } else {
207
+ override += " error";
208
+ return "maybeprop";
209
+ }
210
+ } else if (type == "meta") {
211
+ return "block";
212
+ } else if (!allowNested && (type == "hash" || type == "qualifier")) {
213
+ override = "error";
214
+ return "block";
215
+ } else {
216
+ return states.top(type, stream, state);
217
+ }
218
+ };
219
+
220
+ states.maybeprop = function(type, stream, state) {
221
+ if (type == ":") return pushContext(state, stream, "prop");
222
+ return pass(type, stream, state);
223
+ };
224
+
225
+ states.prop = function(type, stream, state) {
226
+ if (type == ";") return popContext(state);
227
+ if (type == "{" && allowNested) return pushContext(state, stream, "propBlock");
228
+ if (type == "}" || type == "{") return popAndPass(type, stream, state);
229
+ if (type == "(") return pushContext(state, stream, "parens");
230
+
231
+ if (type == "hash" && !/^#([0-9a-fA-f]{3,4}|[0-9a-fA-f]{6}|[0-9a-fA-f]{8})$/.test(stream.current())) {
232
+ override += " error";
233
+ } else if (type == "word") {
234
+ wordAsValue(stream);
235
+ } else if (type == "interpolation") {
236
+ return pushContext(state, stream, "interpolation");
237
+ }
238
+ return "prop";
239
+ };
240
+
241
+ states.propBlock = function(type, _stream, state) {
242
+ if (type == "}") return popContext(state);
243
+ if (type == "word") { override = "property"; return "maybeprop"; }
244
+ return state.context.type;
245
+ };
246
+
247
+ states.parens = function(type, stream, state) {
248
+ if (type == "{" || type == "}") return popAndPass(type, stream, state);
249
+ if (type == ")") return popContext(state);
250
+ if (type == "(") return pushContext(state, stream, "parens");
251
+ if (type == "interpolation") return pushContext(state, stream, "interpolation");
252
+ if (type == "word") wordAsValue(stream);
253
+ return "parens";
254
+ };
255
+
256
+ states.pseudo = function(type, stream, state) {
257
+ if (type == "meta") return "pseudo";
258
+
259
+ if (type == "word") {
260
+ override = "variable-3";
261
+ return state.context.type;
262
+ }
263
+ return pass(type, stream, state);
264
+ };
265
+
266
+ states.documentTypes = function(type, stream, state) {
267
+ if (type == "word" && documentTypes.hasOwnProperty(stream.current())) {
268
+ override = "tag";
269
+ return state.context.type;
270
+ } else {
271
+ return states.atBlock(type, stream, state);
272
+ }
273
+ };
274
+
275
+ states.atBlock = function(type, stream, state) {
276
+ if (type == "(") return pushContext(state, stream, "atBlock_parens");
277
+ if (type == "}" || type == ";") return popAndPass(type, stream, state);
278
+ if (type == "{") return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top");
279
+
280
+ if (type == "interpolation") return pushContext(state, stream, "interpolation");
281
+
282
+ if (type == "word") {
283
+ var word = stream.current().toLowerCase();
284
+ if (word == "only" || word == "not" || word == "and" || word == "or")
285
+ override = "keyword";
286
+ else if (mediaTypes.hasOwnProperty(word))
287
+ override = "attribute";
288
+ else if (mediaFeatures.hasOwnProperty(word))
289
+ override = "property";
290
+ else if (mediaValueKeywords.hasOwnProperty(word))
291
+ override = "keyword";
292
+ else if (propertyKeywords.hasOwnProperty(word))
293
+ override = "property";
294
+ else if (nonStandardPropertyKeywords.hasOwnProperty(word))
295
+ override = "string-2";
296
+ else if (valueKeywords.hasOwnProperty(word))
297
+ override = "atom";
298
+ else if (colorKeywords.hasOwnProperty(word))
299
+ override = "keyword";
300
+ else
301
+ override = "error";
302
+ }
303
+ return state.context.type;
304
+ };
305
+
306
+ states.atComponentBlock = function(type, stream, state) {
307
+ if (type == "}")
308
+ return popAndPass(type, stream, state);
309
+ if (type == "{")
310
+ return popContext(state) && pushContext(state, stream, allowNested ? "block" : "top", false);
311
+ if (type == "word")
312
+ override = "error";
313
+ return state.context.type;
314
+ };
315
+
316
+ states.atBlock_parens = function(type, stream, state) {
317
+ if (type == ")") return popContext(state);
318
+ if (type == "{" || type == "}") return popAndPass(type, stream, state, 2);
319
+ return states.atBlock(type, stream, state);
320
+ };
321
+
322
+ states.restricted_atBlock_before = function(type, stream, state) {
323
+ if (type == "{")
324
+ return pushContext(state, stream, "restricted_atBlock");
325
+ if (type == "word" && state.stateArg == "@counter-style") {
326
+ override = "variable";
327
+ return "restricted_atBlock_before";
328
+ }
329
+ return pass(type, stream, state);
330
+ };
331
+
332
+ states.restricted_atBlock = function(type, stream, state) {
333
+ if (type == "}") {
334
+ state.stateArg = null;
335
+ return popContext(state);
336
+ }
337
+ if (type == "word") {
338
+ if ((state.stateArg == "@font-face" && !fontProperties.hasOwnProperty(stream.current().toLowerCase())) ||
339
+ (state.stateArg == "@counter-style" && !counterDescriptors.hasOwnProperty(stream.current().toLowerCase())))
340
+ override = "error";
341
+ else
342
+ override = "property";
343
+ return "maybeprop";
344
+ }
345
+ return "restricted_atBlock";
346
+ };
347
+
348
+ states.keyframes = function(type, stream, state) {
349
+ if (type == "word") { override = "variable"; return "keyframes"; }
350
+ if (type == "{") return pushContext(state, stream, "top");
351
+ return pass(type, stream, state);
352
+ };
353
+
354
+ states.at = function(type, stream, state) {
355
+ if (type == ";") return popContext(state);
356
+ if (type == "{" || type == "}") return popAndPass(type, stream, state);
357
+ if (type == "word") override = "tag";
358
+ else if (type == "hash") override = "builtin";
359
+ return "at";
360
+ };
361
+
362
+ states.interpolation = function(type, stream, state) {
363
+ if (type == "}") return popContext(state);
364
+ if (type == "{" || type == ";") return popAndPass(type, stream, state);
365
+ if (type == "word") override = "variable";
366
+ else if (type != "variable" && type != "(" && type != ")") override = "error";
367
+ return "interpolation";
368
+ };
369
+
370
+ return {
371
+ startState: function(base) {
372
+ return {tokenize: null,
373
+ state: inline ? "block" : "top",
374
+ stateArg: null,
375
+ context: new Context(inline ? "block" : "top", base || 0, null)};
376
+ },
377
+
378
+ token: function(stream, state) {
379
+ if (!state.tokenize && stream.eatSpace()) return null;
380
+ var style = (state.tokenize || tokenBase)(stream, state);
381
+ if (style && typeof style == "object") {
382
+ type = style[1];
383
+ style = style[0];
384
+ }
385
+ override = style;
386
+ if (type != "comment")
387
+ state.state = states[state.state](type, stream, state);
388
+ return override;
389
+ },
390
+
391
+ indent: function(state, textAfter) {
392
+ var cx = state.context, ch = textAfter && textAfter.charAt(0);
393
+ var indent = cx.indent;
394
+ if (cx.type == "prop" && (ch == "}" || ch == ")")) cx = cx.prev;
395
+ if (cx.prev) {
396
+ if (ch == "}" && (cx.type == "block" || cx.type == "top" ||
397
+ cx.type == "interpolation" || cx.type == "restricted_atBlock")) {
398
+ // Resume indentation from parent context.
399
+ cx = cx.prev;
400
+ indent = cx.indent;
401
+ } else if (ch == ")" && (cx.type == "parens" || cx.type == "atBlock_parens") ||
402
+ ch == "{" && (cx.type == "at" || cx.type == "atBlock")) {
403
+ // Dedent relative to current context.
404
+ indent = Math.max(0, cx.indent - indentUnit);
405
+ }
406
+ }
407
+ return indent;
408
+ },
409
+
410
+ electricChars: "}",
411
+ blockCommentStart: "/*",
412
+ blockCommentEnd: "*/",
413
+ blockCommentContinue: " * ",
414
+ lineComment: lineComment,
415
+ fold: "brace"
416
+ };
417
+ });
418
+
419
+ function keySet(array) {
420
+ var keys = {};
421
+ for (var i = 0; i < array.length; ++i) {
422
+ keys[array[i].toLowerCase()] = true;
423
+ }
424
+ return keys;
425
+ }
426
+
427
+ var documentTypes_ = [
428
+ "domain", "regexp", "url", "url-prefix"
429
+ ], documentTypes = keySet(documentTypes_);
430
+
431
+ var mediaTypes_ = [
432
+ "all", "aural", "braille", "handheld", "print", "projection", "screen",
433
+ "tty", "tv", "embossed"
434
+ ], mediaTypes = keySet(mediaTypes_);
435
+
436
+ var mediaFeatures_ = [
437
+ "width", "min-width", "max-width", "height", "min-height", "max-height",
438
+ "device-width", "min-device-width", "max-device-width", "device-height",
439
+ "min-device-height", "max-device-height", "aspect-ratio",
440
+ "min-aspect-ratio", "max-aspect-ratio", "device-aspect-ratio",
441
+ "min-device-aspect-ratio", "max-device-aspect-ratio", "color", "min-color",
442
+ "max-color", "color-index", "min-color-index", "max-color-index",
443
+ "monochrome", "min-monochrome", "max-monochrome", "resolution",
444
+ "min-resolution", "max-resolution", "scan", "grid", "orientation",
445
+ "device-pixel-ratio", "min-device-pixel-ratio", "max-device-pixel-ratio",
446
+ "pointer", "any-pointer", "hover", "any-hover"
447
+ ], mediaFeatures = keySet(mediaFeatures_);
448
+
449
+ var mediaValueKeywords_ = [
450
+ "landscape", "portrait", "none", "coarse", "fine", "on-demand", "hover",
451
+ "interlace", "progressive"
452
+ ], mediaValueKeywords = keySet(mediaValueKeywords_);
453
+
454
+ var propertyKeywords_ = [
455
+ "align-content", "align-items", "align-self", "alignment-adjust",
456
+ "alignment-baseline", "anchor-point", "animation", "animation-delay",
457
+ "animation-direction", "animation-duration", "animation-fill-mode",
458
+ "animation-iteration-count", "animation-name", "animation-play-state",
459
+ "animation-timing-function", "appearance", "azimuth", "backface-visibility",
460
+ "background", "background-attachment", "background-blend-mode", "background-clip",
461
+ "background-color", "background-image", "background-origin", "background-position",
462
+ "background-repeat", "background-size", "baseline-shift", "binding",
463
+ "bleed", "bookmark-label", "bookmark-level", "bookmark-state",
464
+ "bookmark-target", "border", "border-bottom", "border-bottom-color",
465
+ "border-bottom-left-radius", "border-bottom-right-radius",
466
+ "border-bottom-style", "border-bottom-width", "border-collapse",
467
+ "border-color", "border-image", "border-image-outset",
468
+ "border-image-repeat", "border-image-slice", "border-image-source",
469
+ "border-image-width", "border-left", "border-left-color",
470
+ "border-left-style", "border-left-width", "border-radius", "border-right",
471
+ "border-right-color", "border-right-style", "border-right-width",
472
+ "border-spacing", "border-style", "border-top", "border-top-color",
473
+ "border-top-left-radius", "border-top-right-radius", "border-top-style",
474
+ "border-top-width", "border-width", "bottom", "box-decoration-break",
475
+ "box-shadow", "box-sizing", "break-after", "break-before", "break-inside",
476
+ "caption-side", "caret-color", "clear", "clip", "color", "color-profile", "column-count",
477
+ "column-fill", "column-gap", "column-rule", "column-rule-color",
478
+ "column-rule-style", "column-rule-width", "column-span", "column-width",
479
+ "columns", "content", "counter-increment", "counter-reset", "crop", "cue",
480
+ "cue-after", "cue-before", "cursor", "direction", "display",
481
+ "dominant-baseline", "drop-initial-after-adjust",
482
+ "drop-initial-after-align", "drop-initial-before-adjust",
483
+ "drop-initial-before-align", "drop-initial-size", "drop-initial-value",
484
+ "elevation", "empty-cells", "fit", "fit-position", "flex", "flex-basis",
485
+ "flex-direction", "flex-flow", "flex-grow", "flex-shrink", "flex-wrap",
486
+ "float", "float-offset", "flow-from", "flow-into", "font", "font-feature-settings",
487
+ "font-family", "font-kerning", "font-language-override", "font-size", "font-size-adjust",
488
+ "font-stretch", "font-style", "font-synthesis", "font-variant",
489
+ "font-variant-alternates", "font-variant-caps", "font-variant-east-asian",
490
+ "font-variant-ligatures", "font-variant-numeric", "font-variant-position",
491
+ "font-weight", "grid", "grid-area", "grid-auto-columns", "grid-auto-flow",
492
+ "grid-auto-rows", "grid-column", "grid-column-end", "grid-column-gap",
493
+ "grid-column-start", "grid-gap", "grid-row", "grid-row-end", "grid-row-gap",
494
+ "grid-row-start", "grid-template", "grid-template-areas", "grid-template-columns",
495
+ "grid-template-rows", "hanging-punctuation", "height", "hyphens",
496
+ "icon", "image-orientation", "image-rendering", "image-resolution",
497
+ "inline-box-align", "justify-content", "justify-items", "justify-self", "left", "letter-spacing",
498
+ "line-break", "line-height", "line-stacking", "line-stacking-ruby",
499
+ "line-stacking-shift", "line-stacking-strategy", "list-style",
500
+ "list-style-image", "list-style-position", "list-style-type", "margin",
501
+ "margin-bottom", "margin-left", "margin-right", "margin-top",
502
+ "marks", "marquee-direction", "marquee-loop",
503
+ "marquee-play-count", "marquee-speed", "marquee-style", "max-height",
504
+ "max-width", "min-height", "min-width", "mix-blend-mode", "move-to", "nav-down", "nav-index",
505
+ "nav-left", "nav-right", "nav-up", "object-fit", "object-position",
506
+ "opacity", "order", "orphans", "outline",
507
+ "outline-color", "outline-offset", "outline-style", "outline-width",
508
+ "overflow", "overflow-style", "overflow-wrap", "overflow-x", "overflow-y",
509
+ "padding", "padding-bottom", "padding-left", "padding-right", "padding-top",
510
+ "page", "page-break-after", "page-break-before", "page-break-inside",
511
+ "page-policy", "pause", "pause-after", "pause-before", "perspective",
512
+ "perspective-origin", "pitch", "pitch-range", "place-content", "place-items", "place-self", "play-during", "position",
513
+ "presentation-level", "punctuation-trim", "quotes", "region-break-after",
514
+ "region-break-before", "region-break-inside", "region-fragment",
515
+ "rendering-intent", "resize", "rest", "rest-after", "rest-before", "richness",
516
+ "right", "rotation", "rotation-point", "ruby-align", "ruby-overhang",
517
+ "ruby-position", "ruby-span", "shape-image-threshold", "shape-inside", "shape-margin",
518
+ "shape-outside", "size", "speak", "speak-as", "speak-header",
519
+ "speak-numeral", "speak-punctuation", "speech-rate", "stress", "string-set",
520
+ "tab-size", "table-layout", "target", "target-name", "target-new",
521
+ "target-position", "text-align", "text-align-last", "text-decoration",
522
+ "text-decoration-color", "text-decoration-line", "text-decoration-skip",
523
+ "text-decoration-style", "text-emphasis", "text-emphasis-color",
524
+ "text-emphasis-position", "text-emphasis-style", "text-height",
525
+ "text-indent", "text-justify", "text-outline", "text-overflow", "text-shadow",
526
+ "text-size-adjust", "text-space-collapse", "text-transform", "text-underline-position",
527
+ "text-wrap", "top", "transform", "transform-origin", "transform-style",
528
+ "transition", "transition-delay", "transition-duration",
529
+ "transition-property", "transition-timing-function", "unicode-bidi",
530
+ "user-select", "vertical-align", "visibility", "voice-balance", "voice-duration",
531
+ "voice-family", "voice-pitch", "voice-range", "voice-rate", "voice-stress",
532
+ "voice-volume", "volume", "white-space", "widows", "width", "will-change", "word-break",
533
+ "word-spacing", "word-wrap", "z-index",
534
+ // SVG-specific
535
+ "clip-path", "clip-rule", "mask", "enable-background", "filter", "flood-color",
536
+ "flood-opacity", "lighting-color", "stop-color", "stop-opacity", "pointer-events",
537
+ "color-interpolation", "color-interpolation-filters",
538
+ "color-rendering", "fill", "fill-opacity", "fill-rule", "image-rendering",
539
+ "marker", "marker-end", "marker-mid", "marker-start", "shape-rendering", "stroke",
540
+ "stroke-dasharray", "stroke-dashoffset", "stroke-linecap", "stroke-linejoin",
541
+ "stroke-miterlimit", "stroke-opacity", "stroke-width", "text-rendering",
542
+ "baseline-shift", "dominant-baseline", "glyph-orientation-horizontal",
543
+ "glyph-orientation-vertical", "text-anchor", "writing-mode"
544
+ ], propertyKeywords = keySet(propertyKeywords_);
545
+
546
+ var nonStandardPropertyKeywords_ = [
547
+ "scrollbar-arrow-color", "scrollbar-base-color", "scrollbar-dark-shadow-color",
548
+ "scrollbar-face-color", "scrollbar-highlight-color", "scrollbar-shadow-color",
549
+ "scrollbar-3d-light-color", "scrollbar-track-color", "shape-inside",
550
+ "searchfield-cancel-button", "searchfield-decoration", "searchfield-results-button",
551
+ "searchfield-results-decoration", "zoom"
552
+ ], nonStandardPropertyKeywords = keySet(nonStandardPropertyKeywords_);
553
+
554
+ var fontProperties_ = [
555
+ "font-family", "src", "unicode-range", "font-variant", "font-feature-settings",
556
+ "font-stretch", "font-weight", "font-style"
557
+ ], fontProperties = keySet(fontProperties_);
558
+
559
+ var counterDescriptors_ = [
560
+ "additive-symbols", "fallback", "negative", "pad", "prefix", "range",
561
+ "speak-as", "suffix", "symbols", "system"
562
+ ], counterDescriptors = keySet(counterDescriptors_);
563
+
564
+ var colorKeywords_ = [
565
+ "aliceblue", "antiquewhite", "aqua", "aquamarine", "azure", "beige",
566
+ "bisque", "black", "blanchedalmond", "blue", "blueviolet", "brown",
567
+ "burlywood", "cadetblue", "chartreuse", "chocolate", "coral", "cornflowerblue",
568
+ "cornsilk", "crimson", "cyan", "darkblue", "darkcyan", "darkgoldenrod",
569
+ "darkgray", "darkgreen", "darkkhaki", "darkmagenta", "darkolivegreen",
570
+ "darkorange", "darkorchid", "darkred", "darksalmon", "darkseagreen",
571
+ "darkslateblue", "darkslategray", "darkturquoise", "darkviolet",
572
+ "deeppink", "deepskyblue", "dimgray", "dodgerblue", "firebrick",
573
+ "floralwhite", "forestgreen", "fuchsia", "gainsboro", "ghostwhite",
574
+ "gold", "goldenrod", "gray", "grey", "green", "greenyellow", "honeydew",
575
+ "hotpink", "indianred", "indigo", "ivory", "khaki", "lavender",
576
+ "lavenderblush", "lawngreen", "lemonchiffon", "lightblue", "lightcoral",
577
+ "lightcyan", "lightgoldenrodyellow", "lightgray", "lightgreen", "lightpink",
578
+ "lightsalmon", "lightseagreen", "lightskyblue", "lightslategray",
579
+ "lightsteelblue", "lightyellow", "lime", "limegreen", "linen", "magenta",
580
+ "maroon", "mediumaquamarine", "mediumblue", "mediumorchid", "mediumpurple",
581
+ "mediumseagreen", "mediumslateblue", "mediumspringgreen", "mediumturquoise",
582
+ "mediumvioletred", "midnightblue", "mintcream", "mistyrose", "moccasin",
583
+ "navajowhite", "navy", "oldlace", "olive", "olivedrab", "orange", "orangered",
584
+ "orchid", "palegoldenrod", "palegreen", "paleturquoise", "palevioletred",
585
+ "papayawhip", "peachpuff", "peru", "pink", "plum", "powderblue",
586
+ "purple", "rebeccapurple", "red", "rosybrown", "royalblue", "saddlebrown",
587
+ "salmon", "sandybrown", "seagreen", "seashell", "sienna", "silver", "skyblue",
588
+ "slateblue", "slategray", "snow", "springgreen", "steelblue", "tan",
589
+ "teal", "thistle", "tomato", "turquoise", "violet", "wheat", "white",
590
+ "whitesmoke", "yellow", "yellowgreen"
591
+ ], colorKeywords = keySet(colorKeywords_);
592
+
593
+ var valueKeywords_ = [
594
+ "above", "absolute", "activeborder", "additive", "activecaption", "afar",
595
+ "after-white-space", "ahead", "alias", "all", "all-scroll", "alphabetic", "alternate",
596
+ "always", "amharic", "amharic-abegede", "antialiased", "appworkspace",
597
+ "arabic-indic", "armenian", "asterisks", "attr", "auto", "auto-flow", "avoid", "avoid-column", "avoid-page",
598
+ "avoid-region", "background", "backwards", "baseline", "below", "bidi-override", "binary",
599
+ "bengali", "blink", "block", "block-axis", "bold", "bolder", "border", "border-box",
600
+ "both", "bottom", "break", "break-all", "break-word", "bullets", "button", "button-bevel",
601
+ "buttonface", "buttonhighlight", "buttonshadow", "buttontext", "calc", "cambodian",
602
+ "capitalize", "caps-lock-indicator", "caption", "captiontext", "caret",
603
+ "cell", "center", "checkbox", "circle", "cjk-decimal", "cjk-earthly-branch",
604
+ "cjk-heavenly-stem", "cjk-ideographic", "clear", "clip", "close-quote",
605
+ "col-resize", "collapse", "color", "color-burn", "color-dodge", "column", "column-reverse",
606
+ "compact", "condensed", "contain", "content", "contents",
607
+ "content-box", "context-menu", "continuous", "copy", "counter", "counters", "cover", "crop",
608
+ "cross", "crosshair", "currentcolor", "cursive", "cyclic", "darken", "dashed", "decimal",
609
+ "decimal-leading-zero", "default", "default-button", "dense", "destination-atop",
610
+ "destination-in", "destination-out", "destination-over", "devanagari", "difference",
611
+ "disc", "discard", "disclosure-closed", "disclosure-open", "document",
612
+ "dot-dash", "dot-dot-dash",
613
+ "dotted", "double", "down", "e-resize", "ease", "ease-in", "ease-in-out", "ease-out",
614
+ "element", "ellipse", "ellipsis", "embed", "end", "ethiopic", "ethiopic-abegede",
615
+ "ethiopic-abegede-am-et", "ethiopic-abegede-gez", "ethiopic-abegede-ti-er",
616
+ "ethiopic-abegede-ti-et", "ethiopic-halehame-aa-er",
617
+ "ethiopic-halehame-aa-et", "ethiopic-halehame-am-et",
618
+ "ethiopic-halehame-gez", "ethiopic-halehame-om-et",
619
+ "ethiopic-halehame-sid-et", "ethiopic-halehame-so-et",
620
+ "ethiopic-halehame-ti-er", "ethiopic-halehame-ti-et", "ethiopic-halehame-tig",
621
+ "ethiopic-numeric", "ew-resize", "exclusion", "expanded", "extends", "extra-condensed",
622
+ "extra-expanded", "fantasy", "fast", "fill", "fixed", "flat", "flex", "flex-end", "flex-start", "footnotes",
623
+ "forwards", "from", "geometricPrecision", "georgian", "graytext", "grid", "groove",
624
+ "gujarati", "gurmukhi", "hand", "hangul", "hangul-consonant", "hard-light", "hebrew",
625
+ "help", "hidden", "hide", "higher", "highlight", "highlighttext",
626
+ "hiragana", "hiragana-iroha", "horizontal", "hsl", "hsla", "hue", "icon", "ignore",
627
+ "inactiveborder", "inactivecaption", "inactivecaptiontext", "infinite",
628
+ "infobackground", "infotext", "inherit", "initial", "inline", "inline-axis",
629
+ "inline-block", "inline-flex", "inline-grid", "inline-table", "inset", "inside", "intrinsic", "invert",
630
+ "italic", "japanese-formal", "japanese-informal", "justify", "kannada",
631
+ "katakana", "katakana-iroha", "keep-all", "khmer",
632
+ "korean-hangul-formal", "korean-hanja-formal", "korean-hanja-informal",
633
+ "landscape", "lao", "large", "larger", "left", "level", "lighter", "lighten",
634
+ "line-through", "linear", "linear-gradient", "lines", "list-item", "listbox", "listitem",
635
+ "local", "logical", "loud", "lower", "lower-alpha", "lower-armenian",
636
+ "lower-greek", "lower-hexadecimal", "lower-latin", "lower-norwegian",
637
+ "lower-roman", "lowercase", "ltr", "luminosity", "malayalam", "match", "matrix", "matrix3d",
638
+ "media-controls-background", "media-current-time-display",
639
+ "media-fullscreen-button", "media-mute-button", "media-play-button",
640
+ "media-return-to-realtime-button", "media-rewind-button",
641
+ "media-seek-back-button", "media-seek-forward-button", "media-slider",
642
+ "media-sliderthumb", "media-time-remaining-display", "media-volume-slider",
643
+ "media-volume-slider-container", "media-volume-sliderthumb", "medium",
644
+ "menu", "menulist", "menulist-button", "menulist-text",
645
+ "menulist-textfield", "menutext", "message-box", "middle", "min-intrinsic",
646
+ "mix", "mongolian", "monospace", "move", "multiple", "multiply", "myanmar", "n-resize",
647
+ "narrower", "ne-resize", "nesw-resize", "no-close-quote", "no-drop",
648
+ "no-open-quote", "no-repeat", "none", "normal", "not-allowed", "nowrap",
649
+ "ns-resize", "numbers", "numeric", "nw-resize", "nwse-resize", "oblique", "octal", "opacity", "open-quote",
650
+ "optimizeLegibility", "optimizeSpeed", "oriya", "oromo", "outset",
651
+ "outside", "outside-shape", "overlay", "overline", "padding", "padding-box",
652
+ "painted", "page", "paused", "persian", "perspective", "plus-darker", "plus-lighter",
653
+ "pointer", "polygon", "portrait", "pre", "pre-line", "pre-wrap", "preserve-3d",
654
+ "progress", "push-button", "radial-gradient", "radio", "read-only",
655
+ "read-write", "read-write-plaintext-only", "rectangle", "region",
656
+ "relative", "repeat", "repeating-linear-gradient",
657
+ "repeating-radial-gradient", "repeat-x", "repeat-y", "reset", "reverse",
658
+ "rgb", "rgba", "ridge", "right", "rotate", "rotate3d", "rotateX", "rotateY",
659
+ "rotateZ", "round", "row", "row-resize", "row-reverse", "rtl", "run-in", "running",
660
+ "s-resize", "sans-serif", "saturation", "scale", "scale3d", "scaleX", "scaleY", "scaleZ", "screen",
661
+ "scroll", "scrollbar", "scroll-position", "se-resize", "searchfield",
662
+ "searchfield-cancel-button", "searchfield-decoration",
663
+ "searchfield-results-button", "searchfield-results-decoration", "self-start", "self-end",
664
+ "semi-condensed", "semi-expanded", "separate", "serif", "show", "sidama",
665
+ "simp-chinese-formal", "simp-chinese-informal", "single",
666
+ "skew", "skewX", "skewY", "skip-white-space", "slide", "slider-horizontal",
667
+ "slider-vertical", "sliderthumb-horizontal", "sliderthumb-vertical", "slow",
668
+ "small", "small-caps", "small-caption", "smaller", "soft-light", "solid", "somali",
669
+ "source-atop", "source-in", "source-out", "source-over", "space", "space-around", "space-between", "space-evenly", "spell-out", "square",
670
+ "square-button", "start", "static", "status-bar", "stretch", "stroke", "sub",
671
+ "subpixel-antialiased", "super", "sw-resize", "symbolic", "symbols", "system-ui", "table",
672
+ "table-caption", "table-cell", "table-column", "table-column-group",
673
+ "table-footer-group", "table-header-group", "table-row", "table-row-group",
674
+ "tamil",
675
+ "telugu", "text", "text-bottom", "text-top", "textarea", "textfield", "thai",
676
+ "thick", "thin", "threeddarkshadow", "threedface", "threedhighlight",
677
+ "threedlightshadow", "threedshadow", "tibetan", "tigre", "tigrinya-er",
678
+ "tigrinya-er-abegede", "tigrinya-et", "tigrinya-et-abegede", "to", "top",
679
+ "trad-chinese-formal", "trad-chinese-informal", "transform",
680
+ "translate", "translate3d", "translateX", "translateY", "translateZ",
681
+ "transparent", "ultra-condensed", "ultra-expanded", "underline", "unset", "up",
682
+ "upper-alpha", "upper-armenian", "upper-greek", "upper-hexadecimal",
683
+ "upper-latin", "upper-norwegian", "upper-roman", "uppercase", "urdu", "url",
684
+ "var", "vertical", "vertical-text", "visible", "visibleFill", "visiblePainted",
685
+ "visibleStroke", "visual", "w-resize", "wait", "wave", "wider",
686
+ "window", "windowframe", "windowtext", "words", "wrap", "wrap-reverse", "x-large", "x-small", "xor",
687
+ "xx-large", "xx-small"
688
+ ], valueKeywords = keySet(valueKeywords_);
689
+
690
+ var allWords = documentTypes_.concat(mediaTypes_).concat(mediaFeatures_).concat(mediaValueKeywords_)
691
+ .concat(propertyKeywords_).concat(nonStandardPropertyKeywords_).concat(colorKeywords_)
692
+ .concat(valueKeywords_);
693
+ CodeMirror.registerHelper("hintWords", "css", allWords);
694
+
695
+ function tokenCComment(stream, state) {
696
+ var maybeEnd = false, ch;
697
+ while ((ch = stream.next()) != null) {
698
+ if (maybeEnd && ch == "/") {
699
+ state.tokenize = null;
700
+ break;
701
+ }
702
+ maybeEnd = (ch == "*");
703
+ }
704
+ return ["comment", "comment"];
705
+ }
706
+
707
+ CodeMirror.defineMIME("text/css", {
708
+ documentTypes: documentTypes,
709
+ mediaTypes: mediaTypes,
710
+ mediaFeatures: mediaFeatures,
711
+ mediaValueKeywords: mediaValueKeywords,
712
+ propertyKeywords: propertyKeywords,
713
+ nonStandardPropertyKeywords: nonStandardPropertyKeywords,
714
+ fontProperties: fontProperties,
715
+ counterDescriptors: counterDescriptors,
716
+ colorKeywords: colorKeywords,
717
+ valueKeywords: valueKeywords,
718
+ tokenHooks: {
719
+ "/": function(stream, state) {
720
+ if (!stream.eat("*")) return false;
721
+ state.tokenize = tokenCComment;
722
+ return tokenCComment(stream, state);
723
+ }
724
+ },
725
+ name: "css"
726
+ });
727
+
728
+ CodeMirror.defineMIME("text/x-scss", {
729
+ mediaTypes: mediaTypes,
730
+ mediaFeatures: mediaFeatures,
731
+ mediaValueKeywords: mediaValueKeywords,
732
+ propertyKeywords: propertyKeywords,
733
+ nonStandardPropertyKeywords: nonStandardPropertyKeywords,
734
+ colorKeywords: colorKeywords,
735
+ valueKeywords: valueKeywords,
736
+ fontProperties: fontProperties,
737
+ allowNested: true,
738
+ lineComment: "//",
739
+ tokenHooks: {
740
+ "/": function(stream, state) {
741
+ if (stream.eat("/")) {
742
+ stream.skipToEnd();
743
+ return ["comment", "comment"];
744
+ } else if (stream.eat("*")) {
745
+ state.tokenize = tokenCComment;
746
+ return tokenCComment(stream, state);
747
+ } else {
748
+ return ["operator", "operator"];
749
+ }
750
+ },
751
+ ":": function(stream) {
752
+ if (stream.match(/\s*\{/, false))
753
+ return [null, null]
754
+ return false;
755
+ },
756
+ "$": function(stream) {
757
+ stream.match(/^[\w-]+/);
758
+ if (stream.match(/^\s*:/, false))
759
+ return ["variable-2", "variable-definition"];
760
+ return ["variable-2", "variable"];
761
+ },
762
+ "#": function(stream) {
763
+ if (!stream.eat("{")) return false;
764
+ return [null, "interpolation"];
765
+ }
766
+ },
767
+ name: "css",
768
+ helperType: "scss"
769
+ });
770
+
771
+ CodeMirror.defineMIME("text/x-less", {
772
+ mediaTypes: mediaTypes,
773
+ mediaFeatures: mediaFeatures,
774
+ mediaValueKeywords: mediaValueKeywords,
775
+ propertyKeywords: propertyKeywords,
776
+ nonStandardPropertyKeywords: nonStandardPropertyKeywords,
777
+ colorKeywords: colorKeywords,
778
+ valueKeywords: valueKeywords,
779
+ fontProperties: fontProperties,
780
+ allowNested: true,
781
+ lineComment: "//",
782
+ tokenHooks: {
783
+ "/": function(stream, state) {
784
+ if (stream.eat("/")) {
785
+ stream.skipToEnd();
786
+ return ["comment", "comment"];
787
+ } else if (stream.eat("*")) {
788
+ state.tokenize = tokenCComment;
789
+ return tokenCComment(stream, state);
790
+ } else {
791
+ return ["operator", "operator"];
792
+ }
793
+ },
794
+ "@": function(stream) {
795
+ if (stream.eat("{")) return [null, "interpolation"];
796
+ if (stream.match(/^(charset|document|font-face|import|(-(moz|ms|o|webkit)-)?keyframes|media|namespace|page|supports)\b/i, false)) return false;
797
+ stream.eatWhile(/[\w\\\-]/);
798
+ if (stream.match(/^\s*:/, false))
799
+ return ["variable-2", "variable-definition"];
800
+ return ["variable-2", "variable"];
801
+ },
802
+ "&": function() {
803
+ return ["atom", "atom"];
804
+ }
805
+ },
806
+ name: "css",
807
+ helperType: "less"
808
+ });
809
+
810
+ CodeMirror.defineMIME("text/x-gss", {
811
+ documentTypes: documentTypes,
812
+ mediaTypes: mediaTypes,
813
+ mediaFeatures: mediaFeatures,
814
+ propertyKeywords: propertyKeywords,
815
+ nonStandardPropertyKeywords: nonStandardPropertyKeywords,
816
+ fontProperties: fontProperties,
817
+ counterDescriptors: counterDescriptors,
818
+ colorKeywords: colorKeywords,
819
+ valueKeywords: valueKeywords,
820
+ supportsAtComponent: true,
821
+ tokenHooks: {
822
+ "/": function(stream, state) {
823
+ if (!stream.eat("*")) return false;
824
+ state.tokenize = tokenCComment;
825
+ return tokenCComment(stream, state);
826
+ }
827
+ },
828
+ name: "css",
829
+ helperType: "gss"
830
+ });
831
+
832
+ });
js/common.js ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function ($) {
2
+ // Copy of wp-admin/js/common.js makeNoticesDismissible()
3
+ $("[data-wpautoterms-dismissible]").each(function () {
4
+ var $el = $(this);
5
+ var btnText = $el.data('wpautoterms-dismissible') || commonL10n.dismiss || '';
6
+ var $button = $('<button type="button" class="wpautoterms-dismiss-button">' +
7
+ '<span class="wpautoterms-dismiss-icon">' + btnText + '</span>' +
8
+ '</button>');
9
+ var action = $el.data('wpautoterms-action-id') || false;
10
+ var data = $el.data('wpautoterms-action-data') || false;
11
+ $button.on('click.wp-dismiss-notice', function (event) {
12
+ event.preventDefault();
13
+ $el.fadeTo(100, 0, function () {
14
+ $el.slideUp(100, function () {
15
+ $el.remove();
16
+ });
17
+ });
18
+ if (action !== false) {
19
+ var args = {
20
+ action: action,
21
+ nonce: wpautotermsCommon.nonce[action],
22
+ };
23
+ if (data !== false) {
24
+ if (typeof data === "object") {
25
+ Object.assign(args, data);
26
+ }
27
+ }
28
+ console.log(args);
29
+ $.post(ajaxurl, args);
30
+ }
31
+ });
32
+
33
+ $el.append($button);
34
+ });
35
+ });
js/compliancekits-page.js CHANGED
@@ -6,7 +6,7 @@ jQuery(document).ready(function () {
6
  var s = jQuery("#status_" + id);
7
  jQuery.post(ajaxurl, {
8
  action: id,
9
- nonce: wpautotermsComplianceKits.boxData[id].nonce
10
  }).done(function (response) {
11
  if (typeof response !== "object") {
12
  alert(response);
@@ -15,7 +15,7 @@ jQuery(document).ready(function () {
15
  s.text(wpautotermsComplianceKits.statusText[response.enabled]).toggleClass('enabled', response.enabled)
16
  .toggleClass('disabled', !response.enabled);
17
  wpautoterms.setNotice(wpautotermsComplianceKits.boxData[id].noticeText[response.enabled],
18
- "updated notice");
19
  }
20
  }).fail(function (error) {
21
  console.log(error);
6
  var s = jQuery("#status_" + id);
7
  jQuery.post(ajaxurl, {
8
  action: id,
9
+ nonce: wpautotermsCommon.nonce[id]
10
  }).done(function (response) {
11
  if (typeof response !== "object") {
12
  alert(response);
15
  s.text(wpautotermsComplianceKits.statusText[response.enabled]).toggleClass('enabled', response.enabled)
16
  .toggleClass('disabled', !response.enabled);
17
  wpautoterms.setNotice(wpautotermsComplianceKits.boxData[id].noticeText[response.enabled],
18
+ "updated notice is-dismissible");
19
  }
20
  }).fail(function (error) {
21
  console.log(error);
js/contact-form.js CHANGED
@@ -138,4 +138,16 @@ jQuery(document).ready(function () {
138
  createCounters(FORM);
139
 
140
  validate();
 
 
 
 
 
 
 
 
 
 
 
 
141
  });
138
  createCounters(FORM);
139
 
140
  validate();
141
+ jQuery("[data-type=accordion]").accordion();
142
+ var CONTACT_BUTTON = jQuery("#wpautoterms_contact_button");
143
+ var HIDE_BUTTON = jQuery("#wpautoterms_form_container_hide");
144
+ var CONTACT_FORM = jQuery("#wpautoterms_form_container");
145
+ CONTACT_BUTTON.click(function () {
146
+ CONTACT_BUTTON.hide();
147
+ CONTACT_FORM.show();
148
+ });
149
+ HIDE_BUTTON.click(function () {
150
+ CONTACT_BUTTON.show();
151
+ CONTACT_FORM.hide();
152
+ });
153
  });
js/css-hints.js ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function () {
2
+ var targets = {};
3
+
4
+ function onClick(e) {
5
+ e.preventDefault();
6
+ e.stopPropagation();
7
+ var ds = e.target.dataset;
8
+ var value = ds.value + " {\n}";
9
+ if (typeof targets[ds.target] === "undefined") {
10
+ var target = jQuery("#" + ds.target);
11
+ var text = target.val();
12
+ if (text.length > 0) {
13
+ text += "\n";
14
+ }
15
+ target.val(text + value);
16
+ target.scrollTop(target[0].scrollHeight);
17
+ } else {
18
+ var cm = targets[ds.target];
19
+ if (cm.getValue().length > 0) {
20
+ value = "\n" + value;
21
+ }
22
+ cm.replaceRange(value, CodeMirror.Pos(cm.lastLine()));
23
+ }
24
+ }
25
+
26
+ function isValidKey(code) {
27
+ return (code > 47 && code < 58) // 0-9
28
+ || (code > 64 && code < 91) // a-z
29
+ || (code > 95 && code < 112) // numpad
30
+ || (code > 185 && code < 193) // ;=,-./`
31
+ // || (code > 218 && code < 223); // [\]'
32
+ }
33
+
34
+ function autocomplete(cm, e) {
35
+ if (!cm.state.completionActive && isValidKey(e.keyCode)) {
36
+ CodeMirror.commands.autocomplete(cm, null, {completeSingle: false});
37
+ }
38
+ }
39
+
40
+ jQuery("[data-control=css-hint]").click(onClick);
41
+ jQuery("[data-codemirror]").each(function (_, x) {
42
+ var target = x.id;
43
+ var cm = CodeMirror.fromTextArea(x, {
44
+ lineNumbers: true,
45
+ mode: "css",
46
+ hintOptions: {hint: CodeMirror.hint.css},
47
+ styleActiveLine: true,
48
+ matchBrackets: true,
49
+ autoCloseBrackets: true,
50
+ highlightSelectionMatches: {showToken: true, annotateScrollbar: true}
51
+ });
52
+ cm.on("keyup", autocomplete);
53
+ targets[target] = cm;
54
+ });
55
+ });
js/kits.js ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ var wpautoterms = wpautoterms || {};
2
+ wpautoterms.NOTICE_TEMPLATE = '<div$CLASSES><p><strong>$NOTICE</strong></p></div>';
3
+ wpautoterms.NOTICE_AREA = jQuery("#wpautoterms_notice");
4
+
5
+ wpautoterms.setNotice = function (notice, classes) {
6
+ classes = classes || "";
7
+ if (classes.length) {
8
+ classes = ' class="' + classes + '"';
9
+ }
10
+ wpautoterms.NOTICE_AREA.html(wpautoterms.NOTICE_TEMPLATE.replace("$NOTICE", notice).replace("$CLASSES", classes));
11
+ jQuery(document).trigger('wp-updates-notice-added');
12
+ };
js/post-new.js CHANGED
@@ -18,7 +18,7 @@ jQuery(document).ready(function ($) {
18
  if ($("[data-type='permanent-dismiss'][data-name='" + el.data('name') + "']").prop('checked')) {
19
  $.post(ajaxurl, {
20
  action: 'settings_warning_disable',
21
- nonce: wpautotermsPostNew.settings_warning_disable_nonce,
22
  state: 1
23
  })
24
  }
18
  if ($("[data-type='permanent-dismiss'][data-name='" + el.data('name') + "']").prop('checked')) {
19
  $.post(ajaxurl, {
20
  action: 'settings_warning_disable',
21
+ nonce: wpautotermsCommon.nonce['settings_warning_disable'],
22
  state: 1
23
  })
24
  }
js/wpautoterms.js CHANGED
@@ -13,7 +13,6 @@ jQuery(document).ready(function ($) {
13
  return typeof v === "undefined" ? def : v;
14
  }
15
 
16
- var oldTopValue = parseInt(getShadowProperty("body", ":before", "top", 0));
17
  var oldBottomValue = parseInt(getShadowProperty("body", ":after", "bottom", 0));
18
  var topContainer = jQuery("#wpautoterms-top-fixed-container");
19
  var bottomContainer = jQuery("#wpautoterms-bottom-fixed-container");
@@ -54,7 +53,7 @@ jQuery(document).ready(function ($) {
54
 
55
  $(".wpautoterms-notice-close").click(function () {
56
  var t = jQuery(this);
57
- setCookie(t.attr("cookie"), t.attr("value"), 365);
58
  var p1 = jQuery(this).parent();
59
  var p2 = p1.parent();
60
  p1.remove();
13
  return typeof v === "undefined" ? def : v;
14
  }
15
 
 
16
  var oldBottomValue = parseInt(getShadowProperty("body", ":after", "bottom", 0));
17
  var topContainer = jQuery("#wpautoterms-top-fixed-container");
18
  var bottomContainer = jQuery("#wpautoterms-bottom-fixed-container");
53
 
54
  $(".wpautoterms-notice-close").click(function () {
55
  var t = jQuery(this);
56
+ setCookie(t.data("cookie"), t.data("value"), 365);
57
  var p1 = jQuery(this).parent();
58
  var p2 = p1.parent();
59
  p1.remove();
templates/cookies-notice.php CHANGED
@@ -1,2 +1,9 @@
1
- <div class="wpautoterms-cookies-notice"><?php echo $message; ?>
2
- <a href="javascript:void(0);" class="wpautoterms-notice-close" value="<?php echo esc_attr($cookie_value); ?>" cookie="<?php echo esc_attr($cookie_name); ?>"><?php echo $close; ?></a></div>
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use \wpautoterms\frontend\notice\Cookies_Notice;
4
+
5
+ ?>
6
+ <div class="<?php echo esc_attr( Cookies_Notice::CLASS_COOKIES_NOTICE ); ?>"><?php echo $message; ?>
7
+ <a href="javascript:void(0);" class="<?php echo esc_attr( Cookies_Notice::CLASS_CLOSE_BUTTON ); ?>"
8
+ data-value="<?php echo esc_attr( $cookie_value ); ?>" data-cookie="<?php echo esc_attr( $cookie_name ); ?>">
9
+ <?php echo $close; ?></a></div>
templates/links.php CHANGED
@@ -1,4 +1,7 @@
1
  <?php
 
 
 
2
  if ( ! defined( 'ABSPATH' ) ) {
3
  exit;
4
  }
@@ -6,7 +9,7 @@ if ( empty( $posts ) ) {
6
  return;
7
  }
8
  ?>
9
- <div class="wpautoterms-footer"><p>
10
  <?php
11
  $links = array();
12
  $target = $new_page ? ' target="_blank"' : '';
@@ -14,6 +17,7 @@ if ( empty( $posts ) ) {
14
  $links[] = '<a href="' . esc_url( get_post_permalink( $post->ID ) ) . '"' . $target . '>' .
15
  esc_html( $post->post_title ) . '</a>';
16
  }
17
- echo join( '<span class="separator"> ' . get_option( WPAUTOTERMS_OPTION_PREFIX . 'links_separator' ) . ' </span>', $links );
 
18
  ?></p>
19
  </div>
1
  <?php
2
+
3
+ use wpautoterms\frontend\Links;
4
+
5
  if ( ! defined( 'ABSPATH' ) ) {
6
  exit;
7
  }
9
  return;
10
  }
11
  ?>
12
+ <div class="<?php echo esc_attr( Links::FOOTER_CLASS ); ?>"><p>
13
  <?php
14
  $links = array();
15
  $target = $new_page ? ' target="_blank"' : '';
17
  $links[] = '<a href="' . esc_url( get_post_permalink( $post->ID ) ) . '"' . $target . '>' .
18
  esc_html( $post->post_title ) . '</a>';
19
  }
20
+ echo join( '<span class="' . esc_attr( Links::SEPARATOR_CLASS ) . '"> ' .
21
+ get_option( WPAUTOTERMS_OPTION_PREFIX . 'links_separator' ) . ' </span>', $links );
22
  ?></p>
23
  </div>
templates/options/css-textarea-option.php ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wpautoterms-flex">
2
+ <div class="wpautoterms-w-3">
3
+ <textarea name="<?php echo $name; ?>" class="<?php echo $classes; ?>" id="<?php echo $name; ?>"<?php
4
+ echo empty( $attrs ) ? '' : ' ' . $attrs;
5
+ ?>><?php echo esc_html( $value ); ?></textarea><?php
6
+ include __DIR__ . DIRECTORY_SEPARATOR . 'option-suffix.php';
7
+ ?>
8
+
9
+ <div class="wpautoterms-custom-css-available-selectors">
10
+ <p class="wpautoterms-title"><strong><?php _e( 'Available CSS selectors:', WPAUTOTERMS_SLUG ); ?></strong></p>
11
+ <ul class="wpautoterms-list">
12
+ <?php if ( ! empty( $container_classes ) ) { ?>
13
+ <li>
14
+ <span class="wpautoterms-selector-type"><?php _e( 'Container IDs:', WPAUTOTERMS_SLUG ); ?></span>
15
+ <?php
16
+ foreach ( $container_classes as $cc ) {
17
+ ?><a class="wpautoterms-selector" href="#" data-control="css-hint" data-value="<?php echo esc_attr( $cc ); ?>"
18
+ data-target="<?php echo $name; ?>"><?php
19
+ echo $cc;
20
+ ?></a>
21
+ <?php
22
+ }
23
+ ?>
24
+ </li>
25
+ <?php
26
+ }
27
+ if ( ! empty( $class_hints ) ) {
28
+ foreach ( $class_hints as $ch_key => $ch_val ) {
29
+ ?>
30
+ <li>
31
+ <span class="wpautoterms-selector-type"><?php echo $ch_key; ?></span>
32
+ <a href="#" data-control="css-hint" class="wpautoterms-selector" data-value="<?php echo esc_attr( $ch_val ); ?>"
33
+ data-target="<?php echo $name; ?>"><?php
34
+ echo $ch_val;
35
+ ?></a>
36
+ </li>
37
+ <?php
38
+ }
39
+ }
40
+ ?>
41
+ </ul>
42
+ </div>
43
+ </div>
44
+ </div>
templates/pages/contact.php DELETED
@@ -1,147 +0,0 @@
1
- <?php
2
-
3
- use wpautoterms\admin\action\Send_Message;
4
- use wpautoterms\admin\Options;
5
-
6
- if ( ! defined( 'ABSPATH' ) ) {
7
- exit;
8
- }
9
- $current_user = wp_get_current_user();
10
- $data = $page->action->get_data();
11
- $site_name = Options::get_option( Options::SITE_NAME );
12
- $site_url = Options::get_option( Options::SITE_URL );
13
- $email = $current_user->user_email;
14
- $site_info = Send_Message::DEFAULT_SITE_INFO;
15
- $text = '';
16
- $is_error = isset( $_GET['error'] ) ? (bool) $_GET['error'] : false;
17
- $message = isset( $_GET['message'] ) ? esc_html( $_GET['message'] ) : '';
18
- if ( ! empty( $data ) ) {
19
- if ( isset( $data['site_name'] ) ) {
20
- $site_name = $data['site_name'];
21
- }
22
- if ( isset( $data['site_url'] ) ) {
23
- $site_url = $data['site_url'];
24
- }
25
- if ( isset( $data['email'] ) ) {
26
- $email = $data['email'];
27
- }
28
- if ( isset( $data['text'] ) ) {
29
- $text = $data['text'];
30
- }
31
- if ( isset( $data['site_info'] ) ) {
32
- $site_info = $data['site_info'];
33
- }
34
- }
35
- ?>
36
- <div class="wrap">
37
- <h2><?php echo $page->title(); ?></h2>
38
- <div id="wpautoterms_notice">
39
- <?php
40
- if ( ! empty( $message ) ) {
41
- echo '<div class="updated ' . ( $is_error ? 'error' : 'notice' ) .
42
- ' is-dismissible"><p><strong>' . $message . '</strong></p></div>';
43
- } ?>
44
- </div>
45
- <div id="poststuff">
46
- <div class="postbox-container">
47
- <form action="<?php echo esc_url( $page->api_endpoint() ); ?>" method="post"
48
- id="wpautoterms_contact">
49
- <input type="hidden" name="site_info" value=""/>
50
- <input type="hidden" name="locale" value="<?php echo esc_attr( get_locale() ); ?>"/>
51
- <input type="hidden" name="ret_url" value="<?php
52
- echo esc_url( admin_url( 'edit.php?post_type=' . \wpautoterms\cpt\CPT::type() . '&page=' . $page->id() ) ); ?>">
53
- <table class="form-table">
54
- <tbody>
55
- <tr>
56
- <th scope="row"><label for="site_name">Site name</label></th>
57
- <td><input data-pending="1" type="text" name="site_name" id="site_name" value="<?php
58
- echo esc_attr( $site_name );
59
- ?>"/>
60
- </td>
61
- </tr>
62
- <tr>
63
- <th scope="row"><label for="site_url">Site URL</label></th>
64
- <td><input data-pending="1" type="text" name="site_url" id="site_url" value="<?php
65
- echo esc_attr( $site_url );
66
- ?>"/>
67
- <span class="wpautoterms-hidden wpautoterms-option-required" data-name="site_url"
68
- data-type="notice"><?php _e( 'Wrong URL', WPAUTOTERMS_SLUG ); ?></span>
69
- </td>
70
- </tr>
71
- <tr>
72
- <th scope="row"><label for="email">Your email</label></th>
73
- <td><input data-pending="1" type="text" name="email" id="email" value="<?php
74
- echo esc_attr( $email );
75
- ?>"/>
76
- <span class="wpautoterms-hidden wpautoterms-option-required" data-name="email"
77
- data-type="notice"><?php _e( 'Wrong email address', WPAUTOTERMS_SLUG ); ?></span>
78
- </td>
79
- </tr>
80
- <tr>
81
- <th scope="row"><label for="site_info_preview">Site info</label></th>
82
- <td><select data-pending="1" name="site_info_preview" id="site_info_preview"><?php
83
- foreach ( $page->action->site_info_options() as $option => $label ) {
84
- ?>
85
- <option value="<?php echo $option; ?>"<?php
86
- if ( $site_info === $option ) {
87
- echo ' selected';
88
- };
89
- ?>><?php echo $label; ?></option>
90
- <?php
91
- }
92
- ?>
93
- </select>
94
- <span data-type="notice">
95
- <?php _e( 'Consider choosing extended if you are submitting a bug.', WPAUTOTERMS_SLUG ); ?>
96
- </span>
97
- <div class="wpautoterms-hidden wpautoterms-option-info" data-name="site_info_preview"
98
- data-type="info"></div>
99
- </td>
100
- </tr>
101
- <tr>
102
- <th scope="row"><label for="text">Text</label></th>
103
- <td>
104
- <div class="wpautoterms-wrapper">
105
- <textarea name="text" id="text" class="wpautoterms-resize-both"
106
- data-pending="1"><?php echo esc_html( $text ); ?></textarea>
107
- <div>
108
- <div class="wpautoterms-hidden wpautoterms-option-info wpautoterms-pull-right wpautoterms-clear"
109
- data-target="[name='text']" data-type="char-counter" data-max="<?php
110
- echo $page->action->max_text_length();
111
- ?>"></div>
112
- </div>
113
- </div>
114
- </td>
115
- </tr>
116
- </tbody>
117
- </table>
118
- <div class="wpautoterms-hidden wpautoterms-form-errors" data-name="form"
119
- data-type="notice"><?php _e( 'Please fill in the required information in order to send the message.', WPAUTOTERMS_SLUG ); ?></div>
120
- <div><?php _e( 'You will be redirected to WPAutoTerms website to complete this form submission.', WPAUTOTERMS_SLUG ); ?></div>
121
-
122
- <p class="submit">
123
- <input name="submit_button" data-pending="1" class="button button-primary" value="Send message"
124
- type="submit">
125
- <span class="wpautoterms-hidden" id="wpautoterms_sending">
126
- <?php _e( 'Sending...', WPAUTOTERMS_SLUG ); ?>
127
- </span>
128
- </p>
129
- </form>
130
- </div>
131
- </div>
132
- </div>
133
- <script type="text/html" id="tmpl-wpautoterms-site-info">
134
- <?php _e( 'What will be sent:', WPAUTOTERMS_SLUG ); ?>
135
- <strong id="wpautoterms_short_info">{{ data.preview }}</strong>
136
- <# if (data.full!==null){ #>
137
- <a href="#" data-type="expander"
138
- data-target="#wpautoterms_full_info,#wpautoterms_short_info,#wpautoterms_hide_title,#wpautoterms_show_title">
139
- <span id="wpautoterms_show_title"><?php _e( 'Show all', WPAUTOTERMS_SLUG ); ?></span>
140
- <span class="wpautoterms-hidden"
141
- id="wpautoterms_hide_title"><?php _e( '(hide)', WPAUTOTERMS_SLUG ); ?></span>
142
- </a>
143
- <div class="wpautoterms-hidden" id="wpautoterms_full_info">
144
- <pre id="site_info_text">{{ data.full }}</pre>
145
- </div>
146
- <# } #>
147
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
templates/pages/help-q-a.php ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <h3 class="question-title">How can I include links to my legal pages in my website footer?</h3>
2
+ <div class="question-answer">
3
+ <p>By default, links to published legal pages are <strong>automatically added</strong> to your website footer automatically through the "Links to Legal Pages" Compliance Kit.</p>
4
+ <p>You can customize how the links to your legal pages look like by going to WP AutoTerms > Compliance Kits > Links to Legal Pages.</p>
5
+ </div>
6
+
7
+ <h3 class="question-title">How can I disable the links to my legal pages that have appeared in my website footer?</h3>
8
+ <div class="question-answer">
9
+ <p>You can disable the links by disabling the "Links to Legal Pages" Compliance Kit.</p>
10
+ <p>To do so, go to WP AutoTerms > Compliance Kits > Links to Legal Pages and disable it.</p>
11
+ </div>
12
+
13
+ <h3 class="question-title">How can I update the design of my legal page?</h3>
14
+ <div class="question-answer">
15
+ <p>All legal pages generated with WP AutoTerms are using your current theme's `page.php` template.</p>
16
+ <p>If you'd like to control the design of your legal page, you can:</p>
17
+ <ol>
18
+ <li>Create a new Page Template.<br /> <small>Please read <a href="https://developer.wordpress.org/themes/template-files-section/page-template-files/#creating-custom-page-templates-for-global-use">Creating Custom Page Templates for Global Use</a>.</small></li>
19
+ <li>Assign the new Page Template by going to WP AutoTerms > All Legal Pages > Select your legal page > Select the new Page Template from the "Page Attributes" widget.</li>
20
+ </ol>
21
+ </div>
templates/pages/help.php ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use wpautoterms\admin\action\Send_Message;
4
+ use wpautoterms\admin\Options;
5
+
6
+ if ( ! defined( 'ABSPATH' ) ) {
7
+ exit;
8
+ }
9
+ $current_user = wp_get_current_user();
10
+ $data = $page->action->get_data();
11
+ $site_name = Options::get_option( Options::SITE_NAME );
12
+ $site_url = Options::get_option( Options::SITE_URL );
13
+ $email = $current_user->user_email;
14
+ $site_info = Send_Message::DEFAULT_SITE_INFO;
15
+ $text = '';
16
+ $is_error = isset( $_GET['error'] ) ? (bool) $_GET['error'] : false;
17
+ $message = isset( $_GET['message'] ) ? esc_html( $_GET['message'] ) : '';
18
+ if ( ! empty( $data ) ) {
19
+ if ( isset( $data['site_name'] ) ) {
20
+ $site_name = $data['site_name'];
21
+ }
22
+ if ( isset( $data['site_url'] ) ) {
23
+ $site_url = $data['site_url'];
24
+ }
25
+ if ( isset( $data['email'] ) ) {
26
+ $email = $data['email'];
27
+ }
28
+ if ( isset( $data['text'] ) ) {
29
+ $text = $data['text'];
30
+ }
31
+ if ( isset( $data['site_info'] ) ) {
32
+ $site_info = $data['site_info'];
33
+ }
34
+ }
35
+ ?>
36
+ <div class="wrap">
37
+ <h2><?php echo $page->title(); ?></h2>
38
+
39
+ <div id="wpautoterms_notice">
40
+ <?php
41
+ if ( ! empty( $message ) ) {
42
+ echo '<div class="updated ' . ( $is_error ? 'error' : 'notice' ) .
43
+ ' is-dismissible"><p><strong>' . $message . '</strong></p></div>';
44
+ } ?>
45
+ </div>
46
+
47
+ <div id="poststuff">
48
+ <div class="wpautoterms-help-page-container">
49
+ <div data-type="accordion" class="wpautoterms-help-page-help">
50
+ <?php
51
+ include "help-q-a.php";
52
+ ?>
53
+ </div>
54
+
55
+ <div class="wpautoterms-help-page-form-button">
56
+ <span class="wpautoterms-help-page-no-answer-text"><?php _e( 'Couldn\'t find your answer?', WPAUTOTERMS_SLUG ); ?></span>
57
+ <input type="button" id="wpautoterms_contact_button" class="button button-primary" value="<?php _e( 'Send us a message', WPAUTOTERMS_SLUG ); ?>">
58
+ </div>
59
+
60
+ <div id="wpautoterms_form_container" class="wpautoterms-help-page-form">
61
+ <h3>
62
+ <?php _e( 'Send Us a Message', WPAUTOTERMS_SLUG ); ?>
63
+ <a href="#" id="wpautoterms_form_container_hide">
64
+ <small class="wpautoterms-small"><?php esc_html_e( 'hide', WPAUTOTERMS_SLUG ); ?></small>
65
+ </a>
66
+ </h3>
67
+ <form action="<?php echo esc_url( $page->api_endpoint() ); ?>" method="post"
68
+ id="wpautoterms_contact">
69
+ <input type="hidden" name="site_info" value=""/>
70
+ <input type="hidden" name="locale" value="<?php echo esc_attr( get_locale() ); ?>"/>
71
+ <input type="hidden" name="ret_url" value="<?php
72
+ echo esc_url( admin_url( 'edit.php?post_type=' . \wpautoterms\cpt\CPT::type() . '&page=' . $page->id() ) ); ?>">
73
+ <table class="form-table">
74
+ <tbody>
75
+ <tr>
76
+ <th scope="row"><label for="site_name">Site Name</label></th>
77
+ <td><input data-pending="1" type="text" name="site_name" id="site_name" value="<?php
78
+ echo esc_attr( $site_name );
79
+ ?>"/>
80
+ </td>
81
+ </tr>
82
+ <tr>
83
+ <th scope="row"><label for="site_url">Site URL</label></th>
84
+ <td><input data-pending="1" type="text" name="site_url" id="site_url" value="<?php
85
+ echo esc_attr( $site_url );
86
+ ?>"/>
87
+ <span class="wpautoterms-hidden wpautoterms-option-required" data-name="site_url"
88
+ data-type="notice"><?php _e( 'Wrong URL', WPAUTOTERMS_SLUG ); ?></span>
89
+ </td>
90
+ </tr>
91
+ <tr>
92
+ <th scope="row"><label for="email">Email Address</label></th>
93
+ <td><input data-pending="1" type="text" name="email" id="email" value="<?php
94
+ echo esc_attr( $email );
95
+ ?>"/>
96
+ <span class="wpautoterms-hidden wpautoterms-option-required" data-name="email"
97
+ data-type="notice"><?php _e( 'Wrong email address', WPAUTOTERMS_SLUG ); ?></span>
98
+ </td>
99
+ </tr>
100
+ <tr>
101
+ <th scope="row"><label for="site_info_preview">Site Information</label></th>
102
+ <td><select data-pending="1" name="site_info_preview" id="site_info_preview"><?php
103
+ foreach ( $page->action->site_info_options() as $option => $label ) {
104
+ ?>
105
+ <option value="<?php echo $option; ?>"<?php
106
+ if ( $site_info === $option ) {
107
+ echo ' selected';
108
+ };
109
+ ?>><?php echo ucwords($label); ?></option>
110
+ <?php
111
+ }
112
+ ?>
113
+ </select>
114
+ <p class="wpautoterms-help-page-site-info-notice" data-type="notice">
115
+ <?php _e( 'Please choose Extended if you are submitting a bug so we can troubleshoot it.', WPAUTOTERMS_SLUG ); ?>
116
+ </p>
117
+ <div class="wpautoterms-hidden wpautoterms-option-info" data-name="site_info_preview" data-type="info"></div>
118
+ </td>
119
+ </tr>
120
+ <tr>
121
+ <th scope="row"><label for="text">Message</label></th>
122
+ <td>
123
+ <textarea name="text" id="text" data-pending="1"><?php echo esc_html( $text ); ?></textarea>
124
+ <div>
125
+ <div class="wpautoterms-hidden wpautoterms-option-info wpautoterms-pull-right wpautoterms-clear"
126
+ data-target="[name='text']" data-type="char-counter" data-max="<?php
127
+ echo $page->action->max_text_length();
128
+ ?>"></div>
129
+ </div>
130
+ </td>
131
+ </tr>
132
+ </tbody>
133
+ </table>
134
+ <div class="wpautoterms-hidden wpautoterms-form-errors" data-name="form"
135
+ data-type="notice"><?php _e( 'Please fill in the required information in order to send the message.', WPAUTOTERMS_SLUG ); ?></div>
136
+ <div><?php _e( 'You will be redirected to WPAutoTerms website to complete this form submission.', WPAUTOTERMS_SLUG ); ?></div>
137
+
138
+ <p class="submit">
139
+ <input name="submit_button" data-pending="1" class="button button-primary" value="<?php _e( 'Send Message', WPAUTOTERMS_SLUG ); ?>"
140
+ type="submit">
141
+ <span class="wpautoterms-hidden" id="wpautoterms_sending">
142
+ <?php _e( 'Sending...', WPAUTOTERMS_SLUG ); ?>
143
+ </span>
144
+ </p>
145
+ </form>
146
+ </div>
147
+ </div>
148
+ </div>
149
+
150
+ </div>
151
+ <script type="text/html" id="tmpl-wpautoterms-site-info">
152
+ <?php _e( 'What will be sent:', WPAUTOTERMS_SLUG ); ?>
153
+ <strong id="wpautoterms_short_info">{{ data.preview }}</strong>
154
+ <# if (data.full!==null){ #>
155
+ <a href="#" data-type="expander"
156
+ data-target="#wpautoterms_full_info,#wpautoterms_short_info,#wpautoterms_hide_title,#wpautoterms_show_title">
157
+ <span id="wpautoterms_show_title"><?php _e( 'Show all', WPAUTOTERMS_SLUG ); ?></span>
158
+ <span class="wpautoterms-hidden"
159
+ id="wpautoterms_hide_title"><?php _e( '(hide)', WPAUTOTERMS_SLUG ); ?></span>
160
+ </a>
161
+ <div class="wpautoterms-hidden" id="wpautoterms_full_info">
162
+ <pre id="site_info_text">{{ data.full }}</pre>
163
+ </div>
164
+ <# } #>
165
+ </script>
templates/review-banner.php ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div class="wpautoterms-review-banner notice notice-info wpautoterms-is-dismissible" data-wpautoterms-dismissible="<?php
2
+ esc_attr_e( 'Don\'t show this again', WPAUTOTERMS_SLUG ); ?>"
3
+ data-wpautoterms-action-id="<?php echo esc_attr( $action_id ); ?>"
4
+ data-wpautoterms-action-data="<?php echo esc_attr( '{"state":1}' ) ?>">
5
+ <h4><?php esc_html_e( 'Do you like WP AutoTerms?', WPAUTOTERMS_SLUG ); ?></h4>
6
+ <p>
7
+ <?php esc_html_e( 'We\'d appreciate your honest feedback of our plugin on WP Official Plugins Directory.', WPAUTOTERMS_SLUG ); ?>
8
+ </p>
9
+ <p>
10
+ <a target="_blank" class="button-primary"
11
+ href="https://wordpress.org/support/plugin/auto-terms-of-service-and-privacy-policy/reviews/#new-post">
12
+ <?php esc_html_e( 'OK, I\'ll leave a review', WPAUTOTERMS_SLUG ); ?>
13
+ </a>
14
+ </p>
15
+ </div>
templates/update-notice.php CHANGED
@@ -1,2 +1,9 @@
1
- <div class="wpautoterms-update-notice"><?php echo $message; ?>
2
- <a href="javascript:void(0);" class="wpautoterms-notice-close" value="<?php echo esc_attr($cookie_value); ?>" cookie="<?php echo esc_attr($cookie_name); ?>"><?php echo $close; ?></a></div>
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ use wpautoterms\frontend\notice\Update_Notice;
4
+
5
+ ?>
6
+ <div class="<?php echo esc_attr( Update_Notice::BLOCK_CLASS ); ?>"><?php echo $message; ?>
7
+ <a href="javascript:void(0);" class="<?php echo esc_attr( Update_Notice::CLOSE_CLASS ) ?>"
8
+ value="<?php echo esc_attr( $cookie_value ); ?>"
9
+ cookie="<?php echo esc_attr( $cookie_name ); ?>"><?php echo $close; ?></a></div>
uninstall.php CHANGED
@@ -1,14 +1,10 @@
1
  <?php
2
 
3
- namespace wpautoterms;
4
-
5
- function uninstall() {
6
- if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
7
- die;
8
- }
9
-
10
- require_once dirname( __FILE__ ) . '/wpautoterms.php';
11
-
12
- delete_option( WPAUTOTERMS_OPTION_PREFIX . WPAUTOTERMS_OPTION_ACTIVATED );
13
- flush_rewrite_rules();
14
  }
 
 
 
 
 
1
  <?php
2
 
3
+ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
4
+ die;
 
 
 
 
 
 
 
 
 
5
  }
6
+
7
+ require_once join( DIRECTORY_SEPARATOR, array( __DIR__, 'includes', 'cpt', 'cpt.php' ) );
8
+ wpautoterms\cpt\CPT::unregister_roles();
9
+ delete_option( WPAUTOTERMS_OPTION_PREFIX . WPAUTOTERMS_OPTION_ACTIVATED );
10
+ flush_rewrite_rules();