Formidable Forms – Form Builder for WordPress - Version 5.0.17

Version Description

  • The embedded CodeMirror code for compatibility with versions of WordPress before 4.9 has been removed.
  • New: The ctype PHP extension is no longer a requirement.
  • Fix: The custom CSS page would appear without any textarea on some configurations where CodeMirror may be disabled.
  • Fix: Removed padding styles from radio buttons because of a conflict with the Sensational theme.
Download this release

Release Info

Developer formidableforms
Plugin Icon 128x128 Formidable Forms – Form Builder for WordPress
Version 5.0.17
Comparing to
See all releases

Code changes from version 5.0.16 to 5.0.17

classes/controllers/FrmFormActionsController.php CHANGED
@@ -229,8 +229,8 @@ class FrmFormActionsController {
229
  $data['data-message'] = $action_control->action_options['message'];
230
  }
231
 
232
- $requires = self::action_requires( $upgrading );
233
- if ( $requires ) {
234
  $data['data-requires'] = $requires;
235
  }
236
  }
@@ -246,29 +246,6 @@ class FrmFormActionsController {
246
  include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php';
247
  }
248
 
249
- /**
250
- * @since 5.0.06
251
- *
252
- * @param array $upgrading
253
- * @return string|false
254
- */
255
- private static function action_requires( $upgrading ) {
256
- if ( ! isset( $upgrading['categories'] ) || ! is_array( $upgrading['categories'] ) ) {
257
- return false;
258
- }
259
- $plans = array( 'Business', 'Elite', 'Basic' );
260
- $plus_plans = array( 'Creator', 'Personal', 'Plus' );
261
- foreach ( $upgrading['categories'] as $category ) {
262
- if ( in_array( $category, $plans, true ) ) {
263
- return $category;
264
- }
265
- if ( in_array( $category, $plus_plans, true ) ) {
266
- return 'Plus';
267
- }
268
- }
269
- return false;
270
- }
271
-
272
  public static function get_form_actions( $action = 'all' ) {
273
  $temp_actions = self::$registered_actions;
274
  if ( empty( $temp_actions ) ) {
229
  $data['data-message'] = $action_control->action_options['message'];
230
  }
231
 
232
+ $requires = FrmFormsHelper::get_plan_required( $upgrading );
233
+ if ( $requires && 'free' !== $requires ) {
234
  $data['data-requires'] = $requires;
235
  }
236
  }
246
  include FrmAppHelper::plugin_path() . '/classes/views/frm-form-actions/_action_icon.php';
247
  }
248
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
249
  public static function get_form_actions( $action = 'all' ) {
250
  $temp_actions = self::$registered_actions;
251
  if ( empty( $temp_actions ) ) {
classes/controllers/FrmFormsController.php CHANGED
@@ -1123,6 +1123,18 @@ class FrmFormsController {
1123
  'html_class' => 'frm_show_upgrade frm_noallow',
1124
  'data' => FrmAppHelper::get_landing_page_upgrade_data_params(),
1125
  ),
 
 
 
 
 
 
 
 
 
 
 
 
1126
  'html' => array(
1127
  'name' => __( 'Customize HTML', 'formidable' ),
1128
  'class' => __CLASS__,
@@ -1131,8 +1143,10 @@ class FrmFormsController {
1131
  ),
1132
  );
1133
 
1134
- if ( ! FrmAppHelper::show_landing_pages() ) {
1135
- unset( $sections['landing'] );
 
 
1136
  }
1137
 
1138
  $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values );
1123
  'html_class' => 'frm_show_upgrade frm_noallow',
1124
  'data' => FrmAppHelper::get_landing_page_upgrade_data_params(),
1125
  ),
1126
+ 'chat' => array(
1127
+ 'name' => __( 'Conversational Forms', 'formidable' ),
1128
+ 'icon' => 'frm_icon_font frm_chat_forms_icon',
1129
+ 'html_class' => 'frm_show_upgrade frm_noallow',
1130
+ 'data' => FrmAppHelper::get_upgrade_data_params(
1131
+ 'chat',
1132
+ array(
1133
+ 'upgrade' => __( 'Conversational Forms', 'formidable' ),
1134
+ 'message' => __( 'Ask one question at a time for automated conversations.', 'formidable' ),
1135
+ )
1136
+ ),
1137
+ ),
1138
  'html' => array(
1139
  'name' => __( 'Customize HTML', 'formidable' ),
1140
  'class' => __CLASS__,
1143
  ),
1144
  );
1145
 
1146
+ foreach ( array( 'landing', 'chat' ) as $feature ) {
1147
+ if ( ! FrmAppHelper::show_new_feature( $feature ) ) {
1148
+ unset( $sections[ $feature ] );
1149
+ }
1150
  }
1151
 
1152
  $sections = apply_filters( 'frm_add_form_settings_section', $sections, $values );
classes/controllers/FrmStylesController.php CHANGED
@@ -293,6 +293,11 @@ class FrmStylesController {
293
  return self::manage( $message, $forms );
294
  }
295
 
 
 
 
 
 
296
  public static function custom_css( $message = '', $style = null ) {
297
  if ( function_exists( 'wp_enqueue_code_editor' ) ) {
298
  $id = 'frm_codemirror_box';
@@ -306,13 +311,11 @@ class FrmStylesController {
306
  )
307
  );
308
  } else {
309
- _deprecated_function( 'Codemirror v4.7', 'WordPress 4.9', 'Update WordPress' );
310
- $id = 'frm_custom_css_box';
311
- $settings = array();
312
- $codemirror = '4.7';
313
- wp_enqueue_style( 'codemirror', FrmAppHelper::plugin_url() . '/css/codemirror.css', array(), $codemirror );
314
- wp_enqueue_script( 'codemirror', FrmAppHelper::plugin_url() . '/js/codemirror/codemirror.js', array(), $codemirror );
315
- wp_enqueue_script( 'codemirror-css', FrmAppHelper::plugin_url() . '/js/codemirror/css.js', array( 'codemirror' ), $codemirror );
316
  }
317
 
318
  if ( ! isset( $style ) ) {
@@ -320,7 +323,7 @@ class FrmStylesController {
320
  $style = $frm_style->get_default_style();
321
  }
322
 
323
- include( FrmAppHelper::plugin_path() . '/classes/views/styles/custom_css.php' );
324
  }
325
 
326
  public static function save_css() {
293
  return self::manage( $message, $forms );
294
  }
295
 
296
+ /**
297
+ * @param string $message
298
+ * @param FrmStyle|null $style
299
+ * @return void
300
+ */
301
  public static function custom_css( $message = '', $style = null ) {
302
  if ( function_exists( 'wp_enqueue_code_editor' ) ) {
303
  $id = 'frm_codemirror_box';
311
  )
312
  );
313
  } else {
314
+ $settings = false;
315
+ }
316
+
317
+ if ( empty( $settings ) ) {
318
+ $id = 'frm_custom_css_box';
 
 
319
  }
320
 
321
  if ( ! isset( $style ) ) {
323
  $style = $frm_style->get_default_style();
324
  }
325
 
326
+ include FrmAppHelper::plugin_path() . '/classes/views/styles/custom_css.php';
327
  }
328
 
329
  public static function save_css() {
classes/helpers/FrmAppHelper.php CHANGED
@@ -11,7 +11,7 @@ class FrmAppHelper {
11
  /**
12
  * @since 2.0
13
  */
14
- public static $plug_version = '5.0.16';
15
 
16
  /**
17
  * @since 1.07.02
@@ -3224,8 +3224,7 @@ class FrmAppHelper {
3224
  * @return bool
3225
  */
3226
  public static function show_landing_pages() {
3227
- $link = FrmAddonsController::install_link( 'landing' );
3228
- return array_key_exists( 'class', $link );
3229
  }
3230
 
3231
  /**
@@ -3233,21 +3232,79 @@ class FrmAppHelper {
3233
  *
3234
  * @return array
3235
  */
3236
- public static function get_landing_page_upgrade_data_params() {
3237
- $link = self::pro_is_installed() ? FrmAddonsController::install_link( 'landing' ) : array();
3238
  $params = array(
3239
- 'medium' => 'landing-preview',
3240
  'upgrade' => __( 'Form Landing Pages', 'formidable' ),
 
3241
  );
3242
- if ( $link && ! empty( $link['url'] ) ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3243
  $params['oneclick'] = json_encode( $link );
 
 
 
 
3244
  } else {
3245
- $params['requires'] = 'Plus';
3246
- $params['message'] = __( 'Easily manage a landing page for your form. Upgrade to get form landing pages.', 'formidable' );
3247
  }
 
3248
  return $params;
3249
  }
3250
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3251
  /**
3252
  * @since 4.07
3253
  * @deprecated 4.09.01
11
  /**
12
  * @since 2.0
13
  */
14
+ public static $plug_version = '5.0.17';
15
 
16
  /**
17
  * @since 1.07.02
3224
  * @return bool
3225
  */
3226
  public static function show_landing_pages() {
3227
+ return self::show_new_feature( 'landing' );
 
3228
  }
3229
 
3230
  /**
3232
  *
3233
  * @return array
3234
  */
3235
+ public static function get_landing_page_upgrade_data_params( $medium = 'landing' ) {
 
3236
  $params = array(
3237
+ 'medium' => $medium,
3238
  'upgrade' => __( 'Form Landing Pages', 'formidable' ),
3239
+ 'message' => __( 'Easily manage a landing page for your form. Upgrade to get form landing pages.', 'formidable' ),
3240
  );
3241
+ return self::get_upgrade_data_params( 'landing', $params );
3242
+ }
3243
+
3244
+ /**
3245
+ * @since 5.0.17
3246
+ *
3247
+ * @param string $plugin
3248
+ * @return string|false
3249
+ */
3250
+ private static function get_plan_required( $plugin ) {
3251
+ $link = FrmAddonsController::install_link( $plugin );
3252
+ return FrmFormsHelper::get_plan_required( $link );
3253
+ }
3254
+
3255
+ /**
3256
+ * @since 5.0.17
3257
+ *
3258
+ * @param string
3259
+ * @return bool
3260
+ */
3261
+ public static function show_new_feature( $feature ) {
3262
+ $link = FrmAddonsController::install_link( $feature );
3263
+ return array_key_exists( 'status', $link ) || array_key_exists( 'class', $link );
3264
+ }
3265
+
3266
+ /**
3267
+ * @since 5.0.17
3268
+ *
3269
+ * @param string $plugin
3270
+ * @param array $params
3271
+ * @return array
3272
+ */
3273
+ public static function get_upgrade_data_params( $plugin, $params ) {
3274
+ $link = FrmAddonsController::install_link( $plugin );
3275
+ if ( ! $link ) {
3276
+ return $params;
3277
+ }
3278
+
3279
+ if ( ! empty( $link['url'] ) && self::pro_is_installed() ) {
3280
  $params['oneclick'] = json_encode( $link );
3281
+ unset( $params['message'] );
3282
+ if ( ! isset( $params['medium'] ) ) {
3283
+ $params['medium'] = $plugin;
3284
+ }
3285
  } else {
3286
+ $params['requires'] = FrmFormsHelper::get_plan_required( $link, false );
 
3287
  }
3288
+
3289
  return $params;
3290
  }
3291
 
3292
+ /**
3293
+ * Returns true if every character in text is a hexadecimal 'digit', that is a decimal digit or a character from [A-Fa-f], false otherwise.
3294
+ * Not every server installs the ctype extension, so use a fallback if the function does not exist.
3295
+ *
3296
+ * @since 5.0.17
3297
+ *
3298
+ * @param string $text
3299
+ * @return bool
3300
+ */
3301
+ public static function ctype_xdigit( $text ) {
3302
+ if ( function_exists( 'ctype_xdigit' ) ) {
3303
+ return ctype_xdigit( $text );
3304
+ }
3305
+ return is_string( $text ) && '' !== $text && ! preg_match( '/[^A-Fa-f0-9]/', $text );
3306
+ }
3307
+
3308
  /**
3309
  * @since 4.07
3310
  * @deprecated 4.09.01
classes/helpers/FrmFormsHelper.php CHANGED
@@ -816,7 +816,7 @@ BEFORE_HTML;
816
  $class .= ' frm_center_submit';
817
  }
818
 
819
- $class = apply_filters( 'frm_add_form_style_class', $class, $style );
820
 
821
  return $class;
822
  }
@@ -1409,19 +1409,22 @@ BEFORE_HTML;
1409
 
1410
  /**
1411
  * @since 4.0
 
 
 
1412
  */
1413
  public static function get_plan_required( &$item ) {
1414
- if ( ! isset( $item['categories'] ) || ! empty( $item['url'] ) ) {
1415
  return false;
1416
  }
1417
 
1418
- $plans = array( 'free', 'Basic', 'Personal', 'Business', 'Elite' );
1419
 
1420
  foreach ( $item['categories'] as $k => $category ) {
1421
  if ( in_array( $category, $plans, true ) ) {
1422
  unset( $item['categories'][ $k ] );
1423
 
1424
- if ( $category === 'Personal' ) {
1425
  // Show the current package name.
1426
  $category = 'Plus';
1427
  }
816
  $class .= ' frm_center_submit';
817
  }
818
 
819
+ $class = apply_filters( 'frm_add_form_style_class', $class, $style, compact( 'form' ) );
820
 
821
  return $class;
822
  }
1409
 
1410
  /**
1411
  * @since 4.0
1412
+ *
1413
+ * @param array $item
1414
+ * @return string|false
1415
  */
1416
  public static function get_plan_required( &$item ) {
1417
+ if ( ! isset( $item['categories'] ) || ! is_array( $item['categories'] ) || ! empty( $item['url'] ) ) {
1418
  return false;
1419
  }
1420
 
1421
+ $plans = array( 'free', 'Basic', 'Personal', 'Plus', 'Creator', 'Business', 'Elite' );
1422
 
1423
  foreach ( $item['categories'] as $k => $category ) {
1424
  if ( in_array( $category, $plans, true ) ) {
1425
  unset( $item['categories'][ $k ] );
1426
 
1427
+ if ( in_array( $category, array( 'Creator', 'Personal' ), true ) ) {
1428
  // Show the current package name.
1429
  $category = 'Plus';
1430
  }
classes/models/FrmTableHTMLGenerator.php CHANGED
@@ -185,8 +185,8 @@ class FrmTableHTMLGenerator {
185
  private function get_color_markup( $color_markup ) {
186
  $color_markup = trim( $color_markup );
187
 
188
- //check if each character in string is valid hex digit
189
- if ( ctype_xdigit( $color_markup ) ) {
190
  $color_markup = '#' . $color_markup;
191
  }
192
 
185
  private function get_color_markup( $color_markup ) {
186
  $color_markup = trim( $color_markup );
187
 
188
+ // Check if each character in string is valid hex digit
189
+ if ( FrmAppHelper::ctype_xdigit( $color_markup ) ) {
190
  $color_markup = '#' . $color_markup;
191
  }
192
 
classes/views/frm-form-actions/_action_inside.php CHANGED
@@ -80,20 +80,28 @@ if ( ! FrmAppHelper::pro_is_installed() ) {
80
 
81
  // Show Form Action Automation indicator.
82
  if ( ! function_exists( 'load_frm_autoresponder' ) ) {
83
- $install_data = '';
84
- $class = ' frm_noallow';
85
- $upgrading = FrmAddonsController::install_link( 'autoresponder' );
 
 
 
 
 
86
  if ( isset( $upgrading['url'] ) ) {
87
- $install_data = json_encode( $upgrading );
88
- $class = '';
 
 
89
  }
90
  ?>
91
  <h3>
92
- <a href="javascript:void(0)" class="frm_show_upgrade<?php echo esc_attr( $class ); ?>" data-upgrade="<?php esc_attr_e( 'Form action automations', 'formidable' ); ?>" data-requires="Elite" data-medium="action-automation" data-oneclick="<?php echo esc_attr( $install_data ); ?>">
93
  <?php esc_html_e( 'Setup Automation', 'formidable' ); ?>
94
  </a>
95
  </h3>
96
  <?php
 
97
  }
98
 
99
  // Show link to install logs.
80
 
81
  // Show Form Action Automation indicator.
82
  if ( ! function_exists( 'load_frm_autoresponder' ) ) {
83
+ $upgrading = FrmAddonsController::install_link( 'autoresponder' );
84
+ $params = array(
85
+ 'href' => 'javascript:void(0)',
86
+ 'class' => 'frm_show_upgrade',
87
+ 'data-upgrade' => __( 'Form action automations', 'formidable' ),
88
+ 'data-medium' => 'action-automation',
89
+ );
90
+
91
  if ( isset( $upgrading['url'] ) ) {
92
+ $params['data-oneclick'] = json_encode( $upgrading );
93
+ } else {
94
+ $params['class'] .= ' frm_noallow';
95
+ $params['data-requires'] = FrmFormsHelper::get_plan_required( $upgrading );
96
  }
97
  ?>
98
  <h3>
99
+ <a <?php FrmAppHelper::array_to_html_params( $params, true ); ?>>
100
  <?php esc_html_e( 'Setup Automation', 'formidable' ); ?>
101
  </a>
102
  </h3>
103
  <?php
104
+ unset( $params );
105
  }
106
 
107
  // Show link to install logs.
classes/views/frm-forms/landing-page-preview-option.php CHANGED
@@ -2,7 +2,7 @@
2
  if ( ! defined( 'ABSPATH' ) ) {
3
  die( 'You are not allowed to call this page directly.' );
4
  }
5
- $data = FrmAppHelper::get_landing_page_upgrade_data_params();
6
  $data_keys = array_keys( $data );
7
  $params = array();
8
  foreach ( $data_keys as $key ) {
2
  if ( ! defined( 'ABSPATH' ) ) {
3
  die( 'You are not allowed to call this page directly.' );
4
  }
5
+ $data = FrmAppHelper::get_landing_page_upgrade_data_params( 'landing-preview' );
6
  $data_keys = array_keys( $data );
7
  $params = array();
8
  foreach ( $data_keys as $key ) {
classes/views/styles/custom_css.php CHANGED
@@ -9,10 +9,10 @@ if ( ! defined( 'ABSPATH' ) ) {
9
  <?php
10
  FrmAppHelper::get_admin_header(
11
  array(
12
- 'label' => __( 'Custom CSS', 'formidable' ),
13
- 'hide_title' => false,
14
- 'publish' => array( 'FrmStylesHelper::save_button', array() ),
15
- 'nav' => FrmStylesHelper::get_style_menu( 'custom_css' ),
16
  )
17
  );
18
  ?>
@@ -29,7 +29,7 @@ if ( ! defined( 'ABSPATH' ) ) {
29
  <?php esc_html_e( 'You can add custom css here or in your theme style.css. Any CSS added here will be used anywhere the Formidable CSS is loaded.', 'formidable' ); ?>
30
  </p>
31
 
32
- <?php include( FrmAppHelper::plugin_path() . '/classes/views/shared/errors.php' ); ?>
33
  <input type="hidden" name="ID" value="<?php echo esc_attr( $style->ID ); ?>" />
34
  <input type="hidden" name="<?php echo esc_attr( $frm_style->get_field_name( 'post_title', '' ) ); ?>" value="<?php echo esc_attr( $style->post_title ); ?>" />
35
  <input type="hidden" name="<?php echo esc_attr( $frm_style->get_field_name( 'menu_order', '' ) ); ?>" value="<?php echo esc_attr( $style->menu_order ); ?>" />
@@ -37,10 +37,10 @@ if ( ! defined( 'ABSPATH' ) ) {
37
  <input type="hidden" name="frm_action" value="save_css" />
38
  <?php wp_nonce_field( 'frm_custom_css_nonce', 'frm_custom_css' ); ?>
39
 
40
- <textarea name="<?php echo esc_attr( $frm_style->get_field_name( 'custom_css' ) ); ?>" id="<?php echo esc_attr( $id ); ?>" class="<?php echo esc_attr( 'false' === wp_get_current_user()->syntax_highlighting ? '' : 'hide-if-js' ); ?>"><?php echo FrmAppHelper::esc_textarea( $style->post_content['custom_css'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></textarea>
41
 
42
  <?php
43
- if ( ! empty( $settings ) && $id == 'frm_codemirror_box' ) {
44
  wp_add_inline_script(
45
  'code-editor',
46
  sprintf(
@@ -51,7 +51,7 @@ if ( ! defined( 'ABSPATH' ) ) {
51
  }
52
 
53
  foreach ( $style->post_content as $k => $v ) {
54
- if ( $k == 'custom_css' ) {
55
  continue;
56
  }
57
  ?>
9
  <?php
10
  FrmAppHelper::get_admin_header(
11
  array(
12
+ 'label' => __( 'Custom CSS', 'formidable' ),
13
+ 'hide_title' => false,
14
+ 'publish' => array( 'FrmStylesHelper::save_button', array() ),
15
+ 'nav' => FrmStylesHelper::get_style_menu( 'custom_css' ),
16
  )
17
  );
18
  ?>
29
  <?php esc_html_e( 'You can add custom css here or in your theme style.css. Any CSS added here will be used anywhere the Formidable CSS is loaded.', 'formidable' ); ?>
30
  </p>
31
 
32
+ <?php require FrmAppHelper::plugin_path() . '/classes/views/shared/errors.php'; ?>
33
  <input type="hidden" name="ID" value="<?php echo esc_attr( $style->ID ); ?>" />
34
  <input type="hidden" name="<?php echo esc_attr( $frm_style->get_field_name( 'post_title', '' ) ); ?>" value="<?php echo esc_attr( $style->post_title ); ?>" />
35
  <input type="hidden" name="<?php echo esc_attr( $frm_style->get_field_name( 'menu_order', '' ) ); ?>" value="<?php echo esc_attr( $style->menu_order ); ?>" />
37
  <input type="hidden" name="frm_action" value="save_css" />
38
  <?php wp_nonce_field( 'frm_custom_css_nonce', 'frm_custom_css' ); ?>
39
 
40
+ <textarea name="<?php echo esc_attr( $frm_style->get_field_name( 'custom_css' ) ); ?>" id="<?php echo esc_attr( $id ); ?>" class="<?php echo empty( $settings ) ? '' : 'hide-if-js'; ?>"><?php echo FrmAppHelper::esc_textarea( $style->post_content['custom_css'] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></textarea>
41
 
42
  <?php
43
+ if ( ! empty( $settings ) ) {
44
  wp_add_inline_script(
45
  'code-editor',
46
  sprintf(
51
  }
52
 
53
  foreach ( $style->post_content as $k => $v ) {
54
+ if ( $k === 'custom_css' ) {
55
  continue;
56
  }
57
  ?>
css/codemirror.css CHANGED
@@ -1,309 +1 @@
1
- /* BASICS */
2
-
3
- .CodeMirror {
4
- /* Set height, width, borders, and global font properties here */
5
- font-family: monospace;
6
- height: 300px;
7
- }
8
- .CodeMirror-scroll {
9
- /* Set scrolling behaviour here */
10
- overflow: auto;
11
- }
12
-
13
- /* PADDING */
14
-
15
- .CodeMirror-lines {
16
- padding: 4px 0; /* Vertical padding around content */
17
- }
18
- .CodeMirror pre {
19
- padding: 0 4px; /* Horizontal padding of content */
20
- }
21
-
22
- .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
23
- background-color: white; /* The little square between H and V scrollbars */
24
- }
25
-
26
- /* GUTTER */
27
-
28
- .CodeMirror-gutters {
29
- border-right: 1px solid #ddd;
30
- background-color: #f7f7f7;
31
- white-space: nowrap;
32
- }
33
- .CodeMirror-linenumbers {}
34
- .CodeMirror-linenumber {
35
- padding: 0 3px 0 5px;
36
- min-width: 20px;
37
- text-align: right;
38
- color: #999;
39
- -moz-box-sizing: content-box;
40
- box-sizing: content-box;
41
- }
42
-
43
- .CodeMirror-guttermarker { color: black; }
44
- .CodeMirror-guttermarker-subtle { color: #999; }
45
-
46
- /* CURSOR */
47
-
48
- .CodeMirror div.CodeMirror-cursor {
49
- border-left: 1px solid black;
50
- }
51
- /* Shown when moving in bi-directional text */
52
- .CodeMirror div.CodeMirror-secondarycursor {
53
- border-left: 1px solid silver;
54
- }
55
- .CodeMirror.cm-keymap-fat-cursor div.CodeMirror-cursor {
56
- width: auto;
57
- border: 0;
58
- background: #7e7;
59
- }
60
- .CodeMirror.cm-keymap-fat-cursor div.CodeMirror-cursors {
61
- z-index: 1;
62
- }
63
-
64
- .cm-animate-fat-cursor {
65
- width: auto;
66
- border: 0;
67
- -webkit-animation: blink 1.06s steps(1) infinite;
68
- -moz-animation: blink 1.06s steps(1) infinite;
69
- animation: blink 1.06s steps(1) infinite;
70
- }
71
- @-moz-keyframes blink {
72
- 0% { background: #7e7; }
73
- 50% { background: none; }
74
- 100% { background: #7e7; }
75
- }
76
- @-webkit-keyframes blink {
77
- 0% { background: #7e7; }
78
- 50% { background: none; }
79
- 100% { background: #7e7; }
80
- }
81
- @keyframes blink {
82
- 0% { background: #7e7; }
83
- 50% { background: none; }
84
- 100% { background: #7e7; }
85
- }
86
-
87
- /* Can style cursor different in overwrite (non-insert) mode */
88
- div.CodeMirror-overwrite div.CodeMirror-cursor {}
89
-
90
- .cm-tab { display: inline-block; text-decoration: inherit; }
91
-
92
- .CodeMirror-ruler {
93
- border-left: 1px solid #ccc;
94
- position: absolute;
95
- }
96
-
97
- /* DEFAULT THEME */
98
-
99
- .cm-s-default .cm-keyword {color: #708;}
100
- .cm-s-default .cm-atom {color: #219;}
101
- .cm-s-default .cm-number {color: #164;}
102
- .cm-s-default .cm-def {color: #00f;}
103
- .cm-s-default .cm-variable,
104
- .cm-s-default .cm-punctuation,
105
- .cm-s-default .cm-property,
106
- .cm-s-default .cm-operator {}
107
- .cm-s-default .cm-variable-2 {color: #05a;}
108
- .cm-s-default .cm-variable-3 {color: #085;}
109
- .cm-s-default .cm-comment {color: #a50;}
110
- .cm-s-default .cm-string {color: #a11;}
111
- .cm-s-default .cm-string-2 {color: #f50;}
112
- .cm-s-default .cm-meta {color: #555;}
113
- .cm-s-default .cm-qualifier {color: #555;}
114
- .cm-s-default .cm-builtin {color: #30a;}
115
- .cm-s-default .cm-bracket {color: #997;}
116
- .cm-s-default .cm-tag {color: #170;}
117
- .cm-s-default .cm-attribute {color: #00c;}
118
- .cm-s-default .cm-header {color: blue;}
119
- .cm-s-default .cm-quote {color: #090;}
120
- .cm-s-default .cm-hr {color: #999;}
121
- .cm-s-default .cm-link {color: #00c;}
122
-
123
- .cm-negative {color: #d44;}
124
- .cm-positive {color: #292;}
125
- .cm-header, .cm-strong {font-weight: bold;}
126
- .cm-em {font-style: italic;}
127
- .cm-link {text-decoration: underline;}
128
-
129
- .cm-s-default .cm-error {color: #f00;}
130
- .cm-invalidchar {color: #f00;}
131
-
132
- /* Default styles for common addons */
133
-
134
- div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
135
- div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
136
- .CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
137
- .CodeMirror-activeline-background {background: #e8f2ff;}
138
-
139
- /* STOP */
140
-
141
- /* The rest of this file contains styles related to the mechanics of
142
- the editor. You probably shouldn't touch them. */
143
-
144
- .CodeMirror {
145
- line-height: 1;
146
- position: relative;
147
- overflow: hidden;
148
- background: white;
149
- color: black;
150
- }
151
-
152
- .CodeMirror-scroll {
153
- /* 30px is the magic margin used to hide the element's real scrollbars */
154
- /* See overflow: hidden in .CodeMirror */
155
- margin-bottom: -30px; margin-right: -30px;
156
- padding-bottom: 30px;
157
- height: 100%;
158
- outline: none; /* Prevent dragging from highlighting the element */
159
- position: relative;
160
- -moz-box-sizing: content-box;
161
- box-sizing: content-box;
162
- }
163
- .CodeMirror-sizer {
164
- position: relative;
165
- border-right: 30px solid transparent;
166
- -moz-box-sizing: content-box;
167
- box-sizing: content-box;
168
- }
169
-
170
- /* The fake, visible scrollbars. Used to force redraw during scrolling
171
- before actuall scrolling happens, thus preventing shaking and
172
- flickering artifacts. */
173
- .CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
174
- position: absolute;
175
- z-index: 6;
176
- display: none;
177
- }
178
- .CodeMirror-vscrollbar {
179
- right: 0; top: 0;
180
- overflow-x: hidden;
181
- overflow-y: scroll;
182
- }
183
- .CodeMirror-hscrollbar {
184
- bottom: 0; left: 0;
185
- overflow-y: hidden;
186
- overflow-x: scroll;
187
- }
188
- .CodeMirror-scrollbar-filler {
189
- right: 0; bottom: 0;
190
- }
191
- .CodeMirror-gutter-filler {
192
- left: 0; bottom: 0;
193
- }
194
-
195
- .CodeMirror-gutters {
196
- position: absolute; left: 0; top: 0;
197
- padding-bottom: 30px;
198
- z-index: 3;
199
- }
200
- .CodeMirror-gutter {
201
- white-space: normal;
202
- height: 100%;
203
- -moz-box-sizing: content-box;
204
- box-sizing: content-box;
205
- padding-bottom: 30px;
206
- margin-bottom: -32px;
207
- display: inline-block;
208
- /* Hack to make IE7 behave */
209
- *zoom:1;
210
- *display:inline;
211
- }
212
- .CodeMirror-gutter-elt {
213
- position: absolute;
214
- cursor: default;
215
- z-index: 4;
216
- }
217
-
218
- .CodeMirror-lines {
219
- cursor: text;
220
- min-height: 1px; /* prevents collapsing before first draw */
221
- }
222
- .CodeMirror pre {
223
- /* Reset some styles that the rest of the page might have set */
224
- -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
225
- border-width: 0;
226
- background: transparent;
227
- font-family: inherit;
228
- font-size: inherit;
229
- margin: 0;
230
- white-space: pre;
231
- word-wrap: normal;
232
- line-height: inherit;
233
- color: inherit;
234
- z-index: 2;
235
- position: relative;
236
- overflow: visible;
237
- }
238
- .CodeMirror-wrap pre {
239
- word-wrap: break-word;
240
- white-space: pre-wrap;
241
- word-break: normal;
242
- }
243
-
244
- .CodeMirror-linebackground {
245
- position: absolute;
246
- left: 0; right: 0; top: 0; bottom: 0;
247
- z-index: 0;
248
- }
249
-
250
- .CodeMirror-linewidget {
251
- position: relative;
252
- z-index: 2;
253
- overflow: auto;
254
- }
255
-
256
- .CodeMirror-widget {}
257
-
258
- .CodeMirror-wrap .CodeMirror-scroll {
259
- overflow-x: hidden;
260
- }
261
-
262
- .CodeMirror-measure {
263
- position: absolute;
264
- width: 100%;
265
- height: 0;
266
- overflow: hidden;
267
- visibility: hidden;
268
- }
269
- .CodeMirror-measure pre { position: static; }
270
-
271
- .CodeMirror div.CodeMirror-cursor {
272
- position: absolute;
273
- border-right: none;
274
- width: 0;
275
- }
276
-
277
- div.CodeMirror-cursors {
278
- visibility: hidden;
279
- position: relative;
280
- z-index: 3;
281
- }
282
- .CodeMirror-focused div.CodeMirror-cursors {
283
- visibility: visible;
284
- }
285
-
286
- .CodeMirror-selected { background: #d9d9d9; }
287
- .CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
288
- .CodeMirror-crosshair { cursor: crosshair; }
289
-
290
- .cm-searching {
291
- background: #ffa;
292
- background: rgba(255, 255, 0, .4);
293
- }
294
-
295
- /* IE7 hack to prevent it from returning funny offsetTops on the spans */
296
- .CodeMirror span { *vertical-align: text-bottom; }
297
-
298
- /* Used to force a border model for a node */
299
- .cm-force-border { padding-right: .1px; }
300
-
301
- @media print {
302
- /* Hide the cursor when printing */
303
- .CodeMirror div.CodeMirror-cursors {
304
- visibility: hidden;
305
- }
306
- }
307
-
308
- /* Help users use markselection to safely style text background */
309
- span.CodeMirror-selectedtext { background: none; }
1
+ /* This file has been deprecated as of v5.0.17. Please upgrade to WordPress 4.9 to use Codemirror. */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
css/custom_theme.css.php CHANGED
@@ -801,6 +801,7 @@ a.frm_save_draft{
801
  border-color: var(--border-color);
802
  vertical-align: middle;
803
  position: initial; /* override Bootstrap */
 
804
  }
805
 
806
  .with_frm_style .frm_radio input[type=radio]:before,
801
  border-color: var(--border-color);
802
  vertical-align: middle;
803
  position: initial; /* override Bootstrap */
804
+ padding: 0;
805
  }
806
 
807
  .with_frm_style .frm_radio input[type=radio]:before,
formidable.php CHANGED
@@ -2,7 +2,7 @@
2
  /*
3
  Plugin Name: Formidable Forms
4
  Description: Quickly and easily create drag-and-drop forms
5
- Version: 5.0.16
6
  Plugin URI: https://formidableforms.com/
7
  Author URI: https://formidableforms.com/
8
  Author: Strategy11
2
  /*
3
  Plugin Name: Formidable Forms
4
  Description: Quickly and easily create drag-and-drop forms
5
+ Version: 5.0.17
6
  Plugin URI: https://formidableforms.com/
7
  Author URI: https://formidableforms.com/
8
  Author: Strategy11
js/codemirror/codemirror.js CHANGED
@@ -1,7830 +1 @@
1
- // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
- // Distributed under an MIT license: http://codemirror.net/LICENSE
3
-
4
- // This is CodeMirror (http://codemirror.net), a code editor
5
- // implemented in JavaScript on top of the browser's DOM.
6
- //
7
- // You can find some technical background for some of the code below
8
- // at http://marijnhaverbeke.nl/blog/#cm-internals .
9
-
10
- (function(mod) {
11
- if (typeof exports == "object" && typeof module == "object") // CommonJS
12
- module.exports = mod();
13
- else if (typeof define == "function" && define.amd) // AMD
14
- return define([], mod);
15
- else // Plain browser env
16
- this.CodeMirror = mod();
17
- })(function() {
18
- "use strict";
19
-
20
- // BROWSER SNIFFING
21
-
22
- // Kludges for bugs and behavior differences that can't be feature
23
- // detected are enabled based on userAgent etc sniffing.
24
-
25
- var gecko = /gecko\/\d/i.test(navigator.userAgent);
26
- // ie_uptoN means Internet Explorer version N or lower
27
- var ie_upto10 = /MSIE \d/.test(navigator.userAgent);
28
- var ie_11up = /Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
29
- var ie = ie_upto10 || ie_11up;
30
- var ie_version = ie && (ie_upto10 ? document.documentMode || 6 : ie_11up[1]);
31
- var webkit = /WebKit\//.test(navigator.userAgent);
32
- var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(navigator.userAgent);
33
- var chrome = /Chrome\//.test(navigator.userAgent);
34
- var presto = /Opera\//.test(navigator.userAgent);
35
- var safari = /Apple Computer/.test(navigator.vendor);
36
- var khtml = /KHTML\//.test(navigator.userAgent);
37
- var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent);
38
- var phantom = /PhantomJS/.test(navigator.userAgent);
39
-
40
- var ios = /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent);
41
- // This is woefully incomplete. Suggestions for alternative methods welcome.
42
- var mobile = ios || /Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent);
43
- var mac = ios || /Mac/.test(navigator.platform);
44
- var windows = /win/i.test(navigator.platform);
45
-
46
- var presto_version = presto && navigator.userAgent.match(/Version\/(\d*\.\d*)/);
47
- if (presto_version) presto_version = Number(presto_version[1]);
48
- if (presto_version && presto_version >= 15) { presto = false; webkit = true; }
49
- // Some browsers use the wrong event properties to signal cmd/ctrl on OS X
50
- var flipCtrlCmd = mac && (qtwebkit || presto && (presto_version == null || presto_version < 12.11));
51
- var captureRightClick = gecko || (ie && ie_version >= 9);
52
-
53
- // Optimize some code when these features are not used.
54
- var sawReadOnlySpans = false, sawCollapsedSpans = false;
55
-
56
- // EDITOR CONSTRUCTOR
57
-
58
- // A CodeMirror instance represents an editor. This is the object
59
- // that user code is usually dealing with.
60
-
61
- function CodeMirror(place, options) {
62
- if (!(this instanceof CodeMirror)) return new CodeMirror(place, options);
63
-
64
- this.options = options = options ? copyObj(options) : {};
65
- // Determine effective options based on given values and defaults.
66
- copyObj(defaults, options, false);
67
- setGuttersForLineNumbers(options);
68
-
69
- var doc = options.value;
70
- if (typeof doc == "string") doc = new Doc(doc, options.mode);
71
- this.doc = doc;
72
-
73
- var display = this.display = new Display(place, doc);
74
- display.wrapper.CodeMirror = this;
75
- updateGutters(this);
76
- themeChanged(this);
77
- if (options.lineWrapping)
78
- this.display.wrapper.className += " CodeMirror-wrap";
79
- if (options.autofocus && !mobile) focusInput(this);
80
-
81
- this.state = {
82
- keyMaps: [], // stores maps added by addKeyMap
83
- overlays: [], // highlighting overlays, as added by addOverlay
84
- modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
85
- overwrite: false, focused: false,
86
- suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
87
- pasteIncoming: false, cutIncoming: false, // help recognize paste/cut edits in readInput
88
- draggingText: false,
89
- highlight: new Delayed() // stores highlight worker timeout
90
- };
91
-
92
- // Override magic textarea content restore that IE sometimes does
93
- // on our hidden textarea on reload
94
- if (ie && ie_version < 11) setTimeout(bind(resetInput, this, true), 20);
95
-
96
- registerEventHandlers(this);
97
- ensureGlobalHandlers();
98
-
99
- startOperation(this);
100
- this.curOp.forceUpdate = true;
101
- attachDoc(this, doc);
102
-
103
- if ((options.autofocus && !mobile) || activeElt() == display.input)
104
- setTimeout(bind(onFocus, this), 20);
105
- else
106
- onBlur(this);
107
-
108
- for (var opt in optionHandlers) if (optionHandlers.hasOwnProperty(opt))
109
- optionHandlers[opt](this, options[opt], Init);
110
- maybeUpdateLineNumberWidth(this);
111
- for (var i = 0; i < initHooks.length; ++i) initHooks[i](this);
112
- endOperation(this);
113
- }
114
-
115
- // DISPLAY CONSTRUCTOR
116
-
117
- // The display handles the DOM integration, both for input reading
118
- // and content drawing. It holds references to DOM nodes and
119
- // display-related state.
120
-
121
- function Display(place, doc) {
122
- var d = this;
123
-
124
- // The semihidden textarea that is focused when the editor is
125
- // focused, and receives input.
126
- var input = d.input = elt("textarea", null, null, "position: absolute; padding: 0; width: 1px; height: 1em; outline: none");
127
- // The textarea is kept positioned near the cursor to prevent the
128
- // fact that it'll be scrolled into view on input from scrolling
129
- // our fake cursor out of view. On webkit, when wrap=off, paste is
130
- // very slow. So make the area wide instead.
131
- if (webkit) input.style.width = "1000px";
132
- else input.setAttribute("wrap", "off");
133
- // If border: 0; -- iOS fails to open keyboard (issue #1287)
134
- if (ios) input.style.border = "1px solid black";
135
- input.setAttribute("autocorrect", "off"); input.setAttribute("autocapitalize", "off"); input.setAttribute("spellcheck", "false");
136
-
137
- // Wraps and hides input textarea
138
- d.inputDiv = elt("div", [input], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
139
- // The fake scrollbar elements.
140
- d.scrollbarH = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar");
141
- d.scrollbarV = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar");
142
- // Covers bottom-right square when both scrollbars are present.
143
- d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
144
- // Covers bottom of gutter when coverGutterNextToScrollbar is on
145
- // and h scrollbar is present.
146
- d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler");
147
- // Will contain the actual code, positioned to cover the viewport.
148
- d.lineDiv = elt("div", null, "CodeMirror-code");
149
- // Elements are added to these to represent selection and cursors.
150
- d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
151
- d.cursorDiv = elt("div", null, "CodeMirror-cursors");
152
- // A visibility: hidden element used to find the size of things.
153
- d.measure = elt("div", null, "CodeMirror-measure");
154
- // When lines outside of the viewport are measured, they are drawn in this.
155
- d.lineMeasure = elt("div", null, "CodeMirror-measure");
156
- // Wraps everything that needs to exist inside the vertically-padded coordinate system
157
- d.lineSpace = elt("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
158
- null, "position: relative; outline: none");
159
- // Moved around its parent to cover visible view.
160
- d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative");
161
- // Set to the height of the document, allowing scrolling.
162
- d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
163
- // Behavior of elts with overflow: auto and padding is
164
- // inconsistent across browsers. This is used to ensure the
165
- // scrollable area is big enough.
166
- d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerCutOff + "px; width: 1px;");
167
- // Will contain the gutters, if any.
168
- d.gutters = elt("div", null, "CodeMirror-gutters");
169
- d.lineGutter = null;
170
- // Actual scrollable element.
171
- d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll");
172
- d.scroller.setAttribute("tabIndex", "-1");
173
- // The element in which the editor lives.
174
- d.wrapper = elt("div", [d.inputDiv, d.scrollbarH, d.scrollbarV,
175
- d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
176
-
177
- // Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
178
- if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; }
179
- // Needed to hide big blue blinking cursor on Mobile Safari
180
- if (ios) input.style.width = "0px";
181
- if (!webkit) d.scroller.draggable = true;
182
- // Needed to handle Tab key in KHTML
183
- if (khtml) { d.inputDiv.style.height = "1px"; d.inputDiv.style.position = "absolute"; }
184
- // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
185
- if (ie && ie_version < 8) d.scrollbarH.style.minHeight = d.scrollbarV.style.minWidth = "18px";
186
-
187
- if (place.appendChild) place.appendChild(d.wrapper);
188
- else place(d.wrapper);
189
-
190
- // Current rendered range (may be bigger than the view window).
191
- d.viewFrom = d.viewTo = doc.first;
192
- // Information about the rendered lines.
193
- d.view = [];
194
- // Holds info about a single rendered line when it was rendered
195
- // for measurement, while not in view.
196
- d.externalMeasured = null;
197
- // Empty space (in pixels) above the view
198
- d.viewOffset = 0;
199
- d.lastSizeC = 0;
200
- d.updateLineNumbers = null;
201
-
202
- // Used to only resize the line number gutter when necessary (when
203
- // the amount of lines crosses a boundary that makes its width change)
204
- d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
205
- // See readInput and resetInput
206
- d.prevInput = "";
207
- // Set to true when a non-horizontal-scrolling line widget is
208
- // added. As an optimization, line widget aligning is skipped when
209
- // this is false.
210
- d.alignWidgets = false;
211
- // Flag that indicates whether we expect input to appear real soon
212
- // now (after some event like 'keypress' or 'input') and are
213
- // polling intensively.
214
- d.pollingFast = false;
215
- // Self-resetting timeout for the poller
216
- d.poll = new Delayed();
217
-
218
- d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
219
-
220
- // Tracks when resetInput has punted to just putting a short
221
- // string into the textarea instead of the full selection.
222
- d.inaccurateSelection = false;
223
-
224
- // Tracks the maximum line length so that the horizontal scrollbar
225
- // can be kept static when scrolling.
226
- d.maxLine = null;
227
- d.maxLineLength = 0;
228
- d.maxLineChanged = false;
229
-
230
- // Used for measuring wheel scrolling granularity
231
- d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null;
232
-
233
- // True when shift is held down.
234
- d.shift = false;
235
-
236
- // Used to track whether anything happened since the context menu
237
- // was opened.
238
- d.selForContextMenu = null;
239
- }
240
-
241
- // STATE UPDATES
242
-
243
- // Used to get the editor into a consistent state again when options change.
244
-
245
- function loadMode(cm) {
246
- cm.doc.mode = CodeMirror.getMode(cm.options, cm.doc.modeOption);
247
- resetModeState(cm);
248
- }
249
-
250
- function resetModeState(cm) {
251
- cm.doc.iter(function(line) {
252
- if (line.stateAfter) line.stateAfter = null;
253
- if (line.styles) line.styles = null;
254
- });
255
- cm.doc.frontier = cm.doc.first;
256
- startWorker(cm, 100);
257
- cm.state.modeGen++;
258
- if (cm.curOp) regChange(cm);
259
- }
260
-
261
- function wrappingChanged(cm) {
262
- if (cm.options.lineWrapping) {
263
- addClass(cm.display.wrapper, "CodeMirror-wrap");
264
- cm.display.sizer.style.minWidth = "";
265
- } else {
266
- rmClass(cm.display.wrapper, "CodeMirror-wrap");
267
- findMaxLine(cm);
268
- }
269
- estimateLineHeights(cm);
270
- regChange(cm);
271
- clearCaches(cm);
272
- setTimeout(function(){updateScrollbars(cm);}, 100);
273
- }
274
-
275
- // Returns a function that estimates the height of a line, to use as
276
- // first approximation until the line becomes visible (and is thus
277
- // properly measurable).
278
- function estimateHeight(cm) {
279
- var th = textHeight(cm.display), wrapping = cm.options.lineWrapping;
280
- var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);
281
- return function(line) {
282
- if (lineIsHidden(cm.doc, line)) return 0;
283
-
284
- var widgetsHeight = 0;
285
- if (line.widgets) for (var i = 0; i < line.widgets.length; i++) {
286
- if (line.widgets[i].height) widgetsHeight += line.widgets[i].height;
287
- }
288
-
289
- if (wrapping)
290
- return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th;
291
- else
292
- return widgetsHeight + th;
293
- };
294
- }
295
-
296
- function estimateLineHeights(cm) {
297
- var doc = cm.doc, est = estimateHeight(cm);
298
- doc.iter(function(line) {
299
- var estHeight = est(line);
300
- if (estHeight != line.height) updateLineHeight(line, estHeight);
301
- });
302
- }
303
-
304
- function keyMapChanged(cm) {
305
- var map = keyMap[cm.options.keyMap], style = map.style;
306
- cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-keymap-\S+/g, "") +
307
- (style ? " cm-keymap-" + style : "");
308
- }
309
-
310
- function themeChanged(cm) {
311
- cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
312
- cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
313
- clearCaches(cm);
314
- }
315
-
316
- function guttersChanged(cm) {
317
- updateGutters(cm);
318
- regChange(cm);
319
- setTimeout(function(){alignHorizontally(cm);}, 20);
320
- }
321
-
322
- // Rebuild the gutter elements, ensure the margin to the left of the
323
- // code matches their width.
324
- function updateGutters(cm) {
325
- var gutters = cm.display.gutters, specs = cm.options.gutters;
326
- removeChildren(gutters);
327
- for (var i = 0; i < specs.length; ++i) {
328
- var gutterClass = specs[i];
329
- var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass));
330
- if (gutterClass == "CodeMirror-linenumbers") {
331
- cm.display.lineGutter = gElt;
332
- gElt.style.width = (cm.display.lineNumWidth || 1) + "px";
333
- }
334
- }
335
- gutters.style.display = i ? "" : "none";
336
- updateGutterSpace(cm);
337
- }
338
-
339
- function updateGutterSpace(cm) {
340
- var width = cm.display.gutters.offsetWidth;
341
- cm.display.sizer.style.marginLeft = width + "px";
342
- cm.display.scrollbarH.style.left = cm.options.fixedGutter ? width + "px" : 0;
343
- }
344
-
345
- // Compute the character length of a line, taking into account
346
- // collapsed ranges (see markText) that might hide parts, and join
347
- // other lines onto it.
348
- function lineLength(line) {
349
- if (line.height == 0) return 0;
350
- var len = line.text.length, merged, cur = line;
351
- while (merged = collapsedSpanAtStart(cur)) {
352
- var found = merged.find(0, true);
353
- cur = found.from.line;
354
- len += found.from.ch - found.to.ch;
355
- }
356
- cur = line;
357
- while (merged = collapsedSpanAtEnd(cur)) {
358
- var found = merged.find(0, true);
359
- len -= cur.text.length - found.from.ch;
360
- cur = found.to.line;
361
- len += cur.text.length - found.to.ch;
362
- }
363
- return len;
364
- }
365
-
366
- // Find the longest line in the document.
367
- function findMaxLine(cm) {
368
- var d = cm.display, doc = cm.doc;
369
- d.maxLine = getLine(doc, doc.first);
370
- d.maxLineLength = lineLength(d.maxLine);
371
- d.maxLineChanged = true;
372
- doc.iter(function(line) {
373
- var len = lineLength(line);
374
- if (len > d.maxLineLength) {
375
- d.maxLineLength = len;
376
- d.maxLine = line;
377
- }
378
- });
379
- }
380
-
381
- // Make sure the gutters options contains the element
382
- // "CodeMirror-linenumbers" when the lineNumbers option is true.
383
- function setGuttersForLineNumbers(options) {
384
- var found = indexOf(options.gutters, "CodeMirror-linenumbers");
385
- if (found == -1 && options.lineNumbers) {
386
- options.gutters = options.gutters.concat(["CodeMirror-linenumbers"]);
387
- } else if (found > -1 && !options.lineNumbers) {
388
- options.gutters = options.gutters.slice(0);
389
- options.gutters.splice(found, 1);
390
- }
391
- }
392
-
393
- // SCROLLBARS
394
-
395
- function hScrollbarTakesSpace(cm) {
396
- return cm.display.scroller.clientHeight - cm.display.wrapper.clientHeight < scrollerCutOff - 3;
397
- }
398
-
399
- // Prepare DOM reads needed to update the scrollbars. Done in one
400
- // shot to minimize update/measure roundtrips.
401
- function measureForScrollbars(cm) {
402
- var scroll = cm.display.scroller;
403
- return {
404
- clientHeight: scroll.clientHeight,
405
- barHeight: cm.display.scrollbarV.clientHeight,
406
- scrollWidth: scroll.scrollWidth, clientWidth: scroll.clientWidth,
407
- hScrollbarTakesSpace: hScrollbarTakesSpace(cm),
408
- barWidth: cm.display.scrollbarH.clientWidth,
409
- docHeight: Math.round(cm.doc.height + paddingVert(cm.display))
410
- };
411
- }
412
-
413
- // Re-synchronize the fake scrollbars with the actual size of the
414
- // content.
415
- function updateScrollbars(cm, measure) {
416
- if (!measure) measure = measureForScrollbars(cm);
417
- var d = cm.display, sWidth = scrollbarWidth(d.measure);
418
- var scrollHeight = measure.docHeight + scrollerCutOff;
419
- var needsH = measure.scrollWidth > measure.clientWidth;
420
- if (needsH && measure.scrollWidth <= measure.clientWidth + 1 &&
421
- sWidth > 0 && !measure.hScrollbarTakesSpace)
422
- needsH = false; // (Issue #2562)
423
- var needsV = scrollHeight > measure.clientHeight;
424
-
425
- if (needsV) {
426
- d.scrollbarV.style.display = "block";
427
- d.scrollbarV.style.bottom = needsH ? sWidth + "px" : "0";
428
- // A bug in IE8 can cause this value to be negative, so guard it.
429
- d.scrollbarV.firstChild.style.height =
430
- Math.max(0, scrollHeight - measure.clientHeight + (measure.barHeight || d.scrollbarV.clientHeight)) + "px";
431
- } else {
432
- d.scrollbarV.style.display = "";
433
- d.scrollbarV.firstChild.style.height = "0";
434
- }
435
- if (needsH) {
436
- d.scrollbarH.style.display = "block";
437
- d.scrollbarH.style.right = needsV ? sWidth + "px" : "0";
438
- d.scrollbarH.firstChild.style.width =
439
- (measure.scrollWidth - measure.clientWidth + (measure.barWidth || d.scrollbarH.clientWidth)) + "px";
440
- } else {
441
- d.scrollbarH.style.display = "";
442
- d.scrollbarH.firstChild.style.width = "0";
443
- }
444
- if (needsH && needsV) {
445
- d.scrollbarFiller.style.display = "block";
446
- d.scrollbarFiller.style.height = d.scrollbarFiller.style.width = sWidth + "px";
447
- } else d.scrollbarFiller.style.display = "";
448
- if (needsH && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
449
- d.gutterFiller.style.display = "block";
450
- d.gutterFiller.style.height = sWidth + "px";
451
- d.gutterFiller.style.width = d.gutters.offsetWidth + "px";
452
- } else d.gutterFiller.style.display = "";
453
-
454
- if (!cm.state.checkedOverlayScrollbar && measure.clientHeight > 0) {
455
- if (sWidth === 0) {
456
- var w = mac && !mac_geMountainLion ? "12px" : "18px";
457
- d.scrollbarV.style.minWidth = d.scrollbarH.style.minHeight = w;
458
- var barMouseDown = function(e) {
459
- if (e_target(e) != d.scrollbarV && e_target(e) != d.scrollbarH)
460
- operation(cm, onMouseDown)(e);
461
- };
462
- on(d.scrollbarV, "mousedown", barMouseDown);
463
- on(d.scrollbarH, "mousedown", barMouseDown);
464
- }
465
- cm.state.checkedOverlayScrollbar = true;
466
- }
467
- }
468
-
469
- // Compute the lines that are visible in a given viewport (defaults
470
- // the the current scroll position). viewport may contain top,
471
- // height, and ensure (see op.scrollToPos) properties.
472
- function visibleLines(display, doc, viewport) {
473
- var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop;
474
- top = Math.floor(top - paddingTop(display));
475
- var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight;
476
-
477
- var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom);
478
- // Ensure is a {from: {line, ch}, to: {line, ch}} object, and
479
- // forces those lines into the viewport (if possible).
480
- if (viewport && viewport.ensure) {
481
- var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line;
482
- if (ensureFrom < from)
483
- return {from: ensureFrom,
484
- to: lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight)};
485
- if (Math.min(ensureTo, doc.lastLine()) >= to)
486
- return {from: lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight),
487
- to: ensureTo};
488
- }
489
- return {from: from, to: Math.max(to, from + 1)};
490
- }
491
-
492
- // LINE NUMBERS
493
-
494
- // Re-align line numbers and gutter marks to compensate for
495
- // horizontal scrolling.
496
- function alignHorizontally(cm) {
497
- var display = cm.display, view = display.view;
498
- if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) return;
499
- var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft;
500
- var gutterW = display.gutters.offsetWidth, left = comp + "px";
501
- for (var i = 0; i < view.length; i++) if (!view[i].hidden) {
502
- if (cm.options.fixedGutter && view[i].gutter)
503
- view[i].gutter.style.left = left;
504
- var align = view[i].alignable;
505
- if (align) for (var j = 0; j < align.length; j++)
506
- align[j].style.left = left;
507
- }
508
- if (cm.options.fixedGutter)
509
- display.gutters.style.left = (comp + gutterW) + "px";
510
- }
511
-
512
- // Used to ensure that the line number gutter is still the right
513
- // size for the current document size. Returns true when an update
514
- // is needed.
515
- function maybeUpdateLineNumberWidth(cm) {
516
- if (!cm.options.lineNumbers) return false;
517
- var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display;
518
- if (last.length != display.lineNumChars) {
519
- var test = display.measure.appendChild(elt("div", [elt("div", last)],
520
- "CodeMirror-linenumber CodeMirror-gutter-elt"));
521
- var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
522
- display.lineGutter.style.width = "";
523
- display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding);
524
- display.lineNumWidth = display.lineNumInnerWidth + padding;
525
- display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
526
- display.lineGutter.style.width = display.lineNumWidth + "px";
527
- updateGutterSpace(cm);
528
- return true;
529
- }
530
- return false;
531
- }
532
-
533
- function lineNumberFor(options, i) {
534
- return String(options.lineNumberFormatter(i + options.firstLineNumber));
535
- }
536
-
537
- // Computes display.scroller.scrollLeft + display.gutters.offsetWidth,
538
- // but using getBoundingClientRect to get a sub-pixel-accurate
539
- // result.
540
- function compensateForHScroll(display) {
541
- return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left;
542
- }
543
-
544
- // DISPLAY DRAWING
545
-
546
- function DisplayUpdate(cm, viewport, force) {
547
- var display = cm.display;
548
-
549
- this.viewport = viewport;
550
- // Store some values that we'll need later (but don't want to force a relayout for)
551
- this.visible = visibleLines(display, cm.doc, viewport);
552
- this.editorIsHidden = !display.wrapper.offsetWidth;
553
- this.wrapperHeight = display.wrapper.clientHeight;
554
- this.oldViewFrom = display.viewFrom; this.oldViewTo = display.viewTo;
555
- this.oldScrollerWidth = display.scroller.clientWidth;
556
- this.force = force;
557
- this.dims = getDimensions(cm);
558
- }
559
-
560
- // Does the actual updating of the line display. Bails out
561
- // (returning false) when there is nothing to be done and forced is
562
- // false.
563
- function updateDisplayIfNeeded(cm, update) {
564
- var display = cm.display, doc = cm.doc;
565
- if (update.editorIsHidden) {
566
- resetView(cm);
567
- return false;
568
- }
569
-
570
- // Bail out if the visible area is already rendered and nothing changed.
571
- if (!update.force &&
572
- update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
573
- (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
574
- countDirtyView(cm) == 0)
575
- return false;
576
-
577
- if (maybeUpdateLineNumberWidth(cm)) {
578
- resetView(cm);
579
- update.dims = getDimensions(cm);
580
- }
581
-
582
- // Compute a suitable new viewport (from & to)
583
- var end = doc.first + doc.size;
584
- var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first);
585
- var to = Math.min(end, update.visible.to + cm.options.viewportMargin);
586
- if (display.viewFrom < from && from - display.viewFrom < 20) from = Math.max(doc.first, display.viewFrom);
587
- if (display.viewTo > to && display.viewTo - to < 20) to = Math.min(end, display.viewTo);
588
- if (sawCollapsedSpans) {
589
- from = visualLineNo(cm.doc, from);
590
- to = visualLineEndNo(cm.doc, to);
591
- }
592
-
593
- var different = from != display.viewFrom || to != display.viewTo ||
594
- display.lastSizeC != update.wrapperHeight;
595
- adjustView(cm, from, to);
596
-
597
- display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom));
598
- // Position the mover div to align with the current scroll position
599
- cm.display.mover.style.top = display.viewOffset + "px";
600
-
601
- var toUpdate = countDirtyView(cm);
602
- if (!different && toUpdate == 0 && !update.force &&
603
- (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
604
- return false;
605
-
606
- // For big changes, we hide the enclosing element during the
607
- // update, since that speeds up the operations on most browsers.
608
- var focused = activeElt();
609
- if (toUpdate > 4) display.lineDiv.style.display = "none";
610
- patchDisplay(cm, display.updateLineNumbers, update.dims);
611
- if (toUpdate > 4) display.lineDiv.style.display = "";
612
- // There might have been a widget with a focused element that got
613
- // hidden or updated, if so re-focus it.
614
- if (focused && activeElt() != focused && focused.offsetHeight) focused.focus();
615
-
616
- // Prevent selection and cursors from interfering with the scroll
617
- // width.
618
- removeChildren(display.cursorDiv);
619
- removeChildren(display.selectionDiv);
620
-
621
- if (different) {
622
- display.lastSizeC = update.wrapperHeight;
623
- startWorker(cm, 400);
624
- }
625
-
626
- display.updateLineNumbers = null;
627
-
628
- return true;
629
- }
630
-
631
- function postUpdateDisplay(cm, update) {
632
- var force = update.force, viewport = update.viewport;
633
- for (var first = true;; first = false) {
634
- if (first && cm.options.lineWrapping && update.oldScrollerWidth != cm.display.scroller.clientWidth) {
635
- force = true;
636
- } else {
637
- force = false;
638
- // Clip forced viewport to actual scrollable area.
639
- if (viewport && viewport.top != null)
640
- viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - scrollerCutOff -
641
- cm.display.scroller.clientHeight, viewport.top)};
642
- // Updated line heights might result in the drawn area not
643
- // actually covering the viewport. Keep looping until it does.
644
- update.visible = visibleLines(cm.display, cm.doc, viewport);
645
- if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo)
646
- break;
647
- }
648
- if (!updateDisplayIfNeeded(cm, update)) break;
649
- updateHeightsInViewport(cm);
650
- var barMeasure = measureForScrollbars(cm);
651
- updateSelection(cm);
652
- setDocumentHeight(cm, barMeasure);
653
- updateScrollbars(cm, barMeasure);
654
- }
655
-
656
- signalLater(cm, "update", cm);
657
- if (cm.display.viewFrom != update.oldViewFrom || cm.display.viewTo != update.oldViewTo)
658
- signalLater(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo);
659
- }
660
-
661
- function updateDisplaySimple(cm, viewport) {
662
- var update = new DisplayUpdate(cm, viewport);
663
- if (updateDisplayIfNeeded(cm, update)) {
664
- updateHeightsInViewport(cm);
665
- postUpdateDisplay(cm, update);
666
- var barMeasure = measureForScrollbars(cm);
667
- updateSelection(cm);
668
- setDocumentHeight(cm, barMeasure);
669
- updateScrollbars(cm, barMeasure);
670
- }
671
- }
672
-
673
- function setDocumentHeight(cm, measure) {
674
- cm.display.sizer.style.minHeight = cm.display.heightForcer.style.top = measure.docHeight + "px";
675
- cm.display.gutters.style.height = Math.max(measure.docHeight, measure.clientHeight - scrollerCutOff) + "px";
676
- }
677
-
678
- function checkForWebkitWidthBug(cm, measure) {
679
- // Work around Webkit bug where it sometimes reserves space for a
680
- // non-existing phantom scrollbar in the scroller (Issue #2420)
681
- if (cm.display.sizer.offsetWidth + cm.display.gutters.offsetWidth < cm.display.scroller.clientWidth - 1) {
682
- cm.display.sizer.style.minHeight = cm.display.heightForcer.style.top = "0px";
683
- cm.display.gutters.style.height = measure.docHeight + "px";
684
- }
685
- }
686
-
687
- // Read the actual heights of the rendered lines, and update their
688
- // stored heights to match.
689
- function updateHeightsInViewport(cm) {
690
- var display = cm.display;
691
- var prevBottom = display.lineDiv.offsetTop;
692
- for (var i = 0; i < display.view.length; i++) {
693
- var cur = display.view[i], height;
694
- if (cur.hidden) continue;
695
- if (ie && ie_version < 8) {
696
- var bot = cur.node.offsetTop + cur.node.offsetHeight;
697
- height = bot - prevBottom;
698
- prevBottom = bot;
699
- } else {
700
- var box = cur.node.getBoundingClientRect();
701
- height = box.bottom - box.top;
702
- }
703
- var diff = cur.line.height - height;
704
- if (height < 2) height = textHeight(display);
705
- if (diff > .001 || diff < -.001) {
706
- updateLineHeight(cur.line, height);
707
- updateWidgetHeight(cur.line);
708
- if (cur.rest) for (var j = 0; j < cur.rest.length; j++)
709
- updateWidgetHeight(cur.rest[j]);
710
- }
711
- }
712
- }
713
-
714
- // Read and store the height of line widgets associated with the
715
- // given line.
716
- function updateWidgetHeight(line) {
717
- if (line.widgets) for (var i = 0; i < line.widgets.length; ++i)
718
- line.widgets[i].height = line.widgets[i].node.offsetHeight;
719
- }
720
-
721
- // Do a bulk-read of the DOM positions and sizes needed to draw the
722
- // view, so that we don't interleave reading and writing to the DOM.
723
- function getDimensions(cm) {
724
- var d = cm.display, left = {}, width = {};
725
- var gutterLeft = d.gutters.clientLeft;
726
- for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
727
- left[cm.options.gutters[i]] = n.offsetLeft + n.clientLeft + gutterLeft;
728
- width[cm.options.gutters[i]] = n.clientWidth;
729
- }
730
- return {fixedPos: compensateForHScroll(d),
731
- gutterTotalWidth: d.gutters.offsetWidth,
732
- gutterLeft: left,
733
- gutterWidth: width,
734
- wrapperWidth: d.wrapper.clientWidth};
735
- }
736
-
737
- // Sync the actual display DOM structure with display.view, removing
738
- // nodes for lines that are no longer in view, and creating the ones
739
- // that are not there yet, and updating the ones that are out of
740
- // date.
741
- function patchDisplay(cm, updateNumbersFrom, dims) {
742
- var display = cm.display, lineNumbers = cm.options.lineNumbers;
743
- var container = display.lineDiv, cur = container.firstChild;
744
-
745
- function rm(node) {
746
- var next = node.nextSibling;
747
- // Works around a throw-scroll bug in OS X Webkit
748
- if (webkit && mac && cm.display.currentWheelTarget == node)
749
- node.style.display = "none";
750
- else
751
- node.parentNode.removeChild(node);
752
- return next;
753
- }
754
-
755
- var view = display.view, lineN = display.viewFrom;
756
- // Loop over the elements in the view, syncing cur (the DOM nodes
757
- // in display.lineDiv) with the view as we go.
758
- for (var i = 0; i < view.length; i++) {
759
- var lineView = view[i];
760
- if (lineView.hidden) {
761
- } else if (!lineView.node) { // Not drawn yet
762
- var node = buildLineElement(cm, lineView, lineN, dims);
763
- container.insertBefore(node, cur);
764
- } else { // Already drawn
765
- while (cur != lineView.node) cur = rm(cur);
766
- var updateNumber = lineNumbers && updateNumbersFrom != null &&
767
- updateNumbersFrom <= lineN && lineView.lineNumber;
768
- if (lineView.changes) {
769
- if (indexOf(lineView.changes, "gutter") > -1) updateNumber = false;
770
- updateLineForChanges(cm, lineView, lineN, dims);
771
- }
772
- if (updateNumber) {
773
- removeChildren(lineView.lineNumber);
774
- lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)));
775
- }
776
- cur = lineView.node.nextSibling;
777
- }
778
- lineN += lineView.size;
779
- }
780
- while (cur) cur = rm(cur);
781
- }
782
-
783
- // When an aspect of a line changes, a string is added to
784
- // lineView.changes. This updates the relevant part of the line's
785
- // DOM structure.
786
- function updateLineForChanges(cm, lineView, lineN, dims) {
787
- for (var j = 0; j < lineView.changes.length; j++) {
788
- var type = lineView.changes[j];
789
- if (type == "text") updateLineText(cm, lineView);
790
- else if (type == "gutter") updateLineGutter(cm, lineView, lineN, dims);
791
- else if (type == "class") updateLineClasses(lineView);
792
- else if (type == "widget") updateLineWidgets(lineView, dims);
793
- }
794
- lineView.changes = null;
795
- }
796
-
797
- // Lines with gutter elements, widgets or a background class need to
798
- // be wrapped, and have the extra elements added to the wrapper div
799
- function ensureLineWrapped(lineView) {
800
- if (lineView.node == lineView.text) {
801
- lineView.node = elt("div", null, null, "position: relative");
802
- if (lineView.text.parentNode)
803
- lineView.text.parentNode.replaceChild(lineView.node, lineView.text);
804
- lineView.node.appendChild(lineView.text);
805
- if (ie && ie_version < 8) lineView.node.style.zIndex = 2;
806
- }
807
- return lineView.node;
808
- }
809
-
810
- function updateLineBackground(lineView) {
811
- var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass;
812
- if (cls) cls += " CodeMirror-linebackground";
813
- if (lineView.background) {
814
- if (cls) lineView.background.className = cls;
815
- else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null; }
816
- } else if (cls) {
817
- var wrap = ensureLineWrapped(lineView);
818
- lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild);
819
- }
820
- }
821
-
822
- // Wrapper around buildLineContent which will reuse the structure
823
- // in display.externalMeasured when possible.
824
- function getLineContent(cm, lineView) {
825
- var ext = cm.display.externalMeasured;
826
- if (ext && ext.line == lineView.line) {
827
- cm.display.externalMeasured = null;
828
- lineView.measure = ext.measure;
829
- return ext.built;
830
- }
831
- return buildLineContent(cm, lineView);
832
- }
833
-
834
- // Redraw the line's text. Interacts with the background and text
835
- // classes because the mode may output tokens that influence these
836
- // classes.
837
- function updateLineText(cm, lineView) {
838
- var cls = lineView.text.className;
839
- var built = getLineContent(cm, lineView);
840
- if (lineView.text == lineView.node) lineView.node = built.pre;
841
- lineView.text.parentNode.replaceChild(built.pre, lineView.text);
842
- lineView.text = built.pre;
843
- if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
844
- lineView.bgClass = built.bgClass;
845
- lineView.textClass = built.textClass;
846
- updateLineClasses(lineView);
847
- } else if (cls) {
848
- lineView.text.className = cls;
849
- }
850
- }
851
-
852
- function updateLineClasses(lineView) {
853
- updateLineBackground(lineView);
854
- if (lineView.line.wrapClass)
855
- ensureLineWrapped(lineView).className = lineView.line.wrapClass;
856
- else if (lineView.node != lineView.text)
857
- lineView.node.className = "";
858
- var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass;
859
- lineView.text.className = textClass || "";
860
- }
861
-
862
- function updateLineGutter(cm, lineView, lineN, dims) {
863
- if (lineView.gutter) {
864
- lineView.node.removeChild(lineView.gutter);
865
- lineView.gutter = null;
866
- }
867
- var markers = lineView.line.gutterMarkers;
868
- if (cm.options.lineNumbers || markers) {
869
- var wrap = ensureLineWrapped(lineView);
870
- var gutterWrap = lineView.gutter =
871
- wrap.insertBefore(elt("div", null, "CodeMirror-gutter-wrapper", "position: absolute; left: " +
872
- (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px"),
873
- lineView.text);
874
- if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
875
- lineView.lineNumber = gutterWrap.appendChild(
876
- elt("div", lineNumberFor(cm.options, lineN),
877
- "CodeMirror-linenumber CodeMirror-gutter-elt",
878
- "left: " + dims.gutterLeft["CodeMirror-linenumbers"] + "px; width: "
879
- + cm.display.lineNumInnerWidth + "px"));
880
- if (markers) for (var k = 0; k < cm.options.gutters.length; ++k) {
881
- var id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id];
882
- if (found)
883
- gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt", "left: " +
884
- dims.gutterLeft[id] + "px; width: " + dims.gutterWidth[id] + "px"));
885
- }
886
- }
887
- }
888
-
889
- function updateLineWidgets(lineView, dims) {
890
- if (lineView.alignable) lineView.alignable = null;
891
- for (var node = lineView.node.firstChild, next; node; node = next) {
892
- var next = node.nextSibling;
893
- if (node.className == "CodeMirror-linewidget")
894
- lineView.node.removeChild(node);
895
- }
896
- insertLineWidgets(lineView, dims);
897
- }
898
-
899
- // Build a line's DOM representation from scratch
900
- function buildLineElement(cm, lineView, lineN, dims) {
901
- var built = getLineContent(cm, lineView);
902
- lineView.text = lineView.node = built.pre;
903
- if (built.bgClass) lineView.bgClass = built.bgClass;
904
- if (built.textClass) lineView.textClass = built.textClass;
905
-
906
- updateLineClasses(lineView);
907
- updateLineGutter(cm, lineView, lineN, dims);
908
- insertLineWidgets(lineView, dims);
909
- return lineView.node;
910
- }
911
-
912
- // A lineView may contain multiple logical lines (when merged by
913
- // collapsed spans). The widgets for all of them need to be drawn.
914
- function insertLineWidgets(lineView, dims) {
915
- insertLineWidgetsFor(lineView.line, lineView, dims, true);
916
- if (lineView.rest) for (var i = 0; i < lineView.rest.length; i++)
917
- insertLineWidgetsFor(lineView.rest[i], lineView, dims, false);
918
- }
919
-
920
- function insertLineWidgetsFor(line, lineView, dims, allowAbove) {
921
- if (!line.widgets) return;
922
- var wrap = ensureLineWrapped(lineView);
923
- for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
924
- var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget");
925
- if (!widget.handleMouseEvents) node.ignoreEvents = true;
926
- positionLineWidget(widget, node, lineView, dims);
927
- if (allowAbove && widget.above)
928
- wrap.insertBefore(node, lineView.gutter || lineView.text);
929
- else
930
- wrap.appendChild(node);
931
- signalLater(widget, "redraw");
932
- }
933
- }
934
-
935
- function positionLineWidget(widget, node, lineView, dims) {
936
- if (widget.noHScroll) {
937
- (lineView.alignable || (lineView.alignable = [])).push(node);
938
- var width = dims.wrapperWidth;
939
- node.style.left = dims.fixedPos + "px";
940
- if (!widget.coverGutter) {
941
- width -= dims.gutterTotalWidth;
942
- node.style.paddingLeft = dims.gutterTotalWidth + "px";
943
- }
944
- node.style.width = width + "px";
945
- }
946
- if (widget.coverGutter) {
947
- node.style.zIndex = 5;
948
- node.style.position = "relative";
949
- if (!widget.noHScroll) node.style.marginLeft = -dims.gutterTotalWidth + "px";
950
- }
951
- }
952
-
953
- // POSITION OBJECT
954
-
955
- // A Pos instance represents a position within the text.
956
- var Pos = CodeMirror.Pos = function(line, ch) {
957
- if (!(this instanceof Pos)) return new Pos(line, ch);
958
- this.line = line; this.ch = ch;
959
- };
960
-
961
- // Compare two positions, return 0 if they are the same, a negative
962
- // number when a is less, and a positive number otherwise.
963
- var cmp = CodeMirror.cmpPos = function(a, b) { return a.line - b.line || a.ch - b.ch; };
964
-
965
- function copyPos(x) {return Pos(x.line, x.ch);}
966
- function maxPos(a, b) { return cmp(a, b) < 0 ? b : a; }
967
- function minPos(a, b) { return cmp(a, b) < 0 ? a : b; }
968
-
969
- // SELECTION / CURSOR
970
-
971
- // Selection objects are immutable. A new one is created every time
972
- // the selection changes. A selection is one or more non-overlapping
973
- // (and non-touching) ranges, sorted, and an integer that indicates
974
- // which one is the primary selection (the one that's scrolled into
975
- // view, that getCursor returns, etc).
976
- function Selection(ranges, primIndex) {
977
- this.ranges = ranges;
978
- this.primIndex = primIndex;
979
- }
980
-
981
- Selection.prototype = {
982
- primary: function() { return this.ranges[this.primIndex]; },
983
- equals: function(other) {
984
- if (other == this) return true;
985
- if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) return false;
986
- for (var i = 0; i < this.ranges.length; i++) {
987
- var here = this.ranges[i], there = other.ranges[i];
988
- if (cmp(here.anchor, there.anchor) != 0 || cmp(here.head, there.head) != 0) return false;
989
- }
990
- return true;
991
- },
992
- deepCopy: function() {
993
- for (var out = [], i = 0; i < this.ranges.length; i++)
994
- out[i] = new Range(copyPos(this.ranges[i].anchor), copyPos(this.ranges[i].head));
995
- return new Selection(out, this.primIndex);
996
- },
997
- somethingSelected: function() {
998
- for (var i = 0; i < this.ranges.length; i++)
999
- if (!this.ranges[i].empty()) return true;
1000
- return false;
1001
- },
1002
- contains: function(pos, end) {
1003
- if (!end) end = pos;
1004
- for (var i = 0; i < this.ranges.length; i++) {
1005
- var range = this.ranges[i];
1006
- if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0)
1007
- return i;
1008
- }
1009
- return -1;
1010
- }
1011
- };
1012
-
1013
- function Range(anchor, head) {
1014
- this.anchor = anchor; this.head = head;
1015
- }
1016
-
1017
- Range.prototype = {
1018
- from: function() { return minPos(this.anchor, this.head); },
1019
- to: function() { return maxPos(this.anchor, this.head); },
1020
- empty: function() {
1021
- return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch;
1022
- }
1023
- };
1024
-
1025
- // Take an unsorted, potentially overlapping set of ranges, and
1026
- // build a selection out of it. 'Consumes' ranges array (modifying
1027
- // it).
1028
- function normalizeSelection(ranges, primIndex) {
1029
- var prim = ranges[primIndex];
1030
- ranges.sort(function(a, b) { return cmp(a.from(), b.from()); });
1031
- primIndex = indexOf(ranges, prim);
1032
- for (var i = 1; i < ranges.length; i++) {
1033
- var cur = ranges[i], prev = ranges[i - 1];
1034
- if (cmp(prev.to(), cur.from()) >= 0) {
1035
- var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to());
1036
- var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head;
1037
- if (i <= primIndex) --primIndex;
1038
- ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to));
1039
- }
1040
- }
1041
- return new Selection(ranges, primIndex);
1042
- }
1043
-
1044
- function simpleSelection(anchor, head) {
1045
- return new Selection([new Range(anchor, head || anchor)], 0);
1046
- }
1047
-
1048
- // Most of the external API clips given positions to make sure they
1049
- // actually exist within the document.
1050
- function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1));}
1051
- function clipPos(doc, pos) {
1052
- if (pos.line < doc.first) return Pos(doc.first, 0);
1053
- var last = doc.first + doc.size - 1;
1054
- if (pos.line > last) return Pos(last, getLine(doc, last).text.length);
1055
- return clipToLen(pos, getLine(doc, pos.line).text.length);
1056
- }
1057
- function clipToLen(pos, linelen) {
1058
- var ch = pos.ch;
1059
- if (ch == null || ch > linelen) return Pos(pos.line, linelen);
1060
- else if (ch < 0) return Pos(pos.line, 0);
1061
- else return pos;
1062
- }
1063
- function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size;}
1064
- function clipPosArray(doc, array) {
1065
- for (var out = [], i = 0; i < array.length; i++) out[i] = clipPos(doc, array[i]);
1066
- return out;
1067
- }
1068
-
1069
- // SELECTION UPDATES
1070
-
1071
- // The 'scroll' parameter given to many of these indicated whether
1072
- // the new cursor position should be scrolled into view after
1073
- // modifying the selection.
1074
-
1075
- // If shift is held or the extend flag is set, extends a range to
1076
- // include a given position (and optionally a second position).
1077
- // Otherwise, simply returns the range between the given positions.
1078
- // Used for cursor motion and such.
1079
- function extendRange(doc, range, head, other) {
1080
- if (doc.cm && doc.cm.display.shift || doc.extend) {
1081
- var anchor = range.anchor;
1082
- if (other) {
1083
- var posBefore = cmp(head, anchor) < 0;
1084
- if (posBefore != (cmp(other, anchor) < 0)) {
1085
- anchor = head;
1086
- head = other;
1087
- } else if (posBefore != (cmp(head, other) < 0)) {
1088
- head = other;
1089
- }
1090
- }
1091
- return new Range(anchor, head);
1092
- } else {
1093
- return new Range(other || head, head);
1094
- }
1095
- }
1096
-
1097
- // Extend the primary selection range, discard the rest.
1098
- function extendSelection(doc, head, other, options) {
1099
- setSelection(doc, new Selection([extendRange(doc, doc.sel.primary(), head, other)], 0), options);
1100
- }
1101
-
1102
- // Extend all selections (pos is an array of selections with length
1103
- // equal the number of selections)
1104
- function extendSelections(doc, heads, options) {
1105
- for (var out = [], i = 0; i < doc.sel.ranges.length; i++)
1106
- out[i] = extendRange(doc, doc.sel.ranges[i], heads[i], null);
1107
- var newSel = normalizeSelection(out, doc.sel.primIndex);
1108
- setSelection(doc, newSel, options);
1109
- }
1110
-
1111
- // Updates a single range in the selection.
1112
- function replaceOneSelection(doc, i, range, options) {
1113
- var ranges = doc.sel.ranges.slice(0);
1114
- ranges[i] = range;
1115
- setSelection(doc, normalizeSelection(ranges, doc.sel.primIndex), options);
1116
- }
1117
-
1118
- // Reset the selection to a single range.
1119
- function setSimpleSelection(doc, anchor, head, options) {
1120
- setSelection(doc, simpleSelection(anchor, head), options);
1121
- }
1122
-
1123
- // Give beforeSelectionChange handlers a change to influence a
1124
- // selection update.
1125
- function filterSelectionChange(doc, sel) {
1126
- var obj = {
1127
- ranges: sel.ranges,
1128
- update: function(ranges) {
1129
- this.ranges = [];
1130
- for (var i = 0; i < ranges.length; i++)
1131
- this.ranges[i] = new Range(clipPos(doc, ranges[i].anchor),
1132
- clipPos(doc, ranges[i].head));
1133
- }
1134
- };
1135
- signal(doc, "beforeSelectionChange", doc, obj);
1136
- if (doc.cm) signal(doc.cm, "beforeSelectionChange", doc.cm, obj);
1137
- if (obj.ranges != sel.ranges) return normalizeSelection(obj.ranges, obj.ranges.length - 1);
1138
- else return sel;
1139
- }
1140
-
1141
- function setSelectionReplaceHistory(doc, sel, options) {
1142
- var done = doc.history.done, last = lst(done);
1143
- if (last && last.ranges) {
1144
- done[done.length - 1] = sel;
1145
- setSelectionNoUndo(doc, sel, options);
1146
- } else {
1147
- setSelection(doc, sel, options);
1148
- }
1149
- }
1150
-
1151
- // Set a new selection.
1152
- function setSelection(doc, sel, options) {
1153
- setSelectionNoUndo(doc, sel, options);
1154
- addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options);
1155
- }
1156
-
1157
- function setSelectionNoUndo(doc, sel, options) {
1158
- if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange"))
1159
- sel = filterSelectionChange(doc, sel);
1160
-
1161
- var bias = options && options.bias ||
1162
- (cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1);
1163
- setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true));
1164
-
1165
- if (!(options && options.scroll === false) && doc.cm)
1166
- ensureCursorVisible(doc.cm);
1167
- }
1168
-
1169
- function setSelectionInner(doc, sel) {
1170
- if (sel.equals(doc.sel)) return;
1171
-
1172
- doc.sel = sel;
1173
-
1174
- if (doc.cm) {
1175
- doc.cm.curOp.updateInput = doc.cm.curOp.selectionChanged = true;
1176
- signalCursorActivity(doc.cm);
1177
- }
1178
- signalLater(doc, "cursorActivity", doc);
1179
- }
1180
-
1181
- // Verify that the selection does not partially select any atomic
1182
- // marked ranges.
1183
- function reCheckSelection(doc) {
1184
- setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false), sel_dontScroll);
1185
- }
1186
-
1187
- // Return a selection that does not partially select any atomic
1188
- // ranges.
1189
- function skipAtomicInSelection(doc, sel, bias, mayClear) {
1190
- var out;
1191
- for (var i = 0; i < sel.ranges.length; i++) {
1192
- var range = sel.ranges[i];
1193
- var newAnchor = skipAtomic(doc, range.anchor, bias, mayClear);
1194
- var newHead = skipAtomic(doc, range.head, bias, mayClear);
1195
- if (out || newAnchor != range.anchor || newHead != range.head) {
1196
- if (!out) out = sel.ranges.slice(0, i);
1197
- out[i] = new Range(newAnchor, newHead);
1198
- }
1199
- }
1200
- return out ? normalizeSelection(out, sel.primIndex) : sel;
1201
- }
1202
-
1203
- // Ensure a given position is not inside an atomic range.
1204
- function skipAtomic(doc, pos, bias, mayClear) {
1205
- var flipped = false, curPos = pos;
1206
- var dir = bias || 1;
1207
- doc.cantEdit = false;
1208
- search: for (;;) {
1209
- var line = getLine(doc, curPos.line);
1210
- if (line.markedSpans) {
1211
- for (var i = 0; i < line.markedSpans.length; ++i) {
1212
- var sp = line.markedSpans[i], m = sp.marker;
1213
- if ((sp.from == null || (m.inclusiveLeft ? sp.from <= curPos.ch : sp.from < curPos.ch)) &&
1214
- (sp.to == null || (m.inclusiveRight ? sp.to >= curPos.ch : sp.to > curPos.ch))) {
1215
- if (mayClear) {
1216
- signal(m, "beforeCursorEnter");
1217
- if (m.explicitlyCleared) {
1218
- if (!line.markedSpans) break;
1219
- else {--i; continue;}
1220
- }
1221
- }
1222
- if (!m.atomic) continue;
1223
- var newPos = m.find(dir < 0 ? -1 : 1);
1224
- if (cmp(newPos, curPos) == 0) {
1225
- newPos.ch += dir;
1226
- if (newPos.ch < 0) {
1227
- if (newPos.line > doc.first) newPos = clipPos(doc, Pos(newPos.line - 1));
1228
- else newPos = null;
1229
- } else if (newPos.ch > line.text.length) {
1230
- if (newPos.line < doc.first + doc.size - 1) newPos = Pos(newPos.line + 1, 0);
1231
- else newPos = null;
1232
- }
1233
- if (!newPos) {
1234
- if (flipped) {
1235
- // Driven in a corner -- no valid cursor position found at all
1236
- // -- try again *with* clearing, if we didn't already
1237
- if (!mayClear) return skipAtomic(doc, pos, bias, true);
1238
- // Otherwise, turn off editing until further notice, and return the start of the doc
1239
- doc.cantEdit = true;
1240
- return Pos(doc.first, 0);
1241
- }
1242
- flipped = true; newPos = pos; dir = -dir;
1243
- }
1244
- }
1245
- curPos = newPos;
1246
- continue search;
1247
- }
1248
- }
1249
- }
1250
- return curPos;
1251
- }
1252
- }
1253
-
1254
- // SELECTION DRAWING
1255
-
1256
- // Redraw the selection and/or cursor
1257
- function drawSelection(cm) {
1258
- var display = cm.display, doc = cm.doc, result = {};
1259
- var curFragment = result.cursors = document.createDocumentFragment();
1260
- var selFragment = result.selection = document.createDocumentFragment();
1261
-
1262
- for (var i = 0; i < doc.sel.ranges.length; i++) {
1263
- var range = doc.sel.ranges[i];
1264
- var collapsed = range.empty();
1265
- if (collapsed || cm.options.showCursorWhenSelecting)
1266
- drawSelectionCursor(cm, range, curFragment);
1267
- if (!collapsed)
1268
- drawSelectionRange(cm, range, selFragment);
1269
- }
1270
-
1271
- // Move the hidden textarea near the cursor to prevent scrolling artifacts
1272
- if (cm.options.moveInputWithCursor) {
1273
- var headPos = cursorCoords(cm, doc.sel.primary().head, "div");
1274
- var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect();
1275
- result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
1276
- headPos.top + lineOff.top - wrapOff.top));
1277
- result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
1278
- headPos.left + lineOff.left - wrapOff.left));
1279
- }
1280
-
1281
- return result;
1282
- }
1283
-
1284
- function showSelection(cm, drawn) {
1285
- removeChildrenAndAdd(cm.display.cursorDiv, drawn.cursors);
1286
- removeChildrenAndAdd(cm.display.selectionDiv, drawn.selection);
1287
- if (drawn.teTop != null) {
1288
- cm.display.inputDiv.style.top = drawn.teTop + "px";
1289
- cm.display.inputDiv.style.left = drawn.teLeft + "px";
1290
- }
1291
- }
1292
-
1293
- function updateSelection(cm) {
1294
- showSelection(cm, drawSelection(cm));
1295
- }
1296
-
1297
- // Draws a cursor for the given range
1298
- function drawSelectionCursor(cm, range, output) {
1299
- var pos = cursorCoords(cm, range.head, "div", null, null, !cm.options.singleCursorHeightPerLine);
1300
-
1301
- var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"));
1302
- cursor.style.left = pos.left + "px";
1303
- cursor.style.top = pos.top + "px";
1304
- cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
1305
-
1306
- if (pos.other) {
1307
- // Secondary cursor, shown when on a 'jump' in bi-directional text
1308
- var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"));
1309
- otherCursor.style.display = "";
1310
- otherCursor.style.left = pos.other.left + "px";
1311
- otherCursor.style.top = pos.other.top + "px";
1312
- otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px";
1313
- }
1314
- }
1315
-
1316
- // Draws the given range as a highlighted selection
1317
- function drawSelectionRange(cm, range, output) {
1318
- var display = cm.display, doc = cm.doc;
1319
- var fragment = document.createDocumentFragment();
1320
- var padding = paddingH(cm.display), leftSide = padding.left, rightSide = display.lineSpace.offsetWidth - padding.right;
1321
-
1322
- function add(left, top, width, bottom) {
1323
- if (top < 0) top = 0;
1324
- top = Math.round(top);
1325
- bottom = Math.round(bottom);
1326
- fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left +
1327
- "px; top: " + top + "px; width: " + (width == null ? rightSide - left : width) +
1328
- "px; height: " + (bottom - top) + "px"));
1329
- }
1330
-
1331
- function drawForLine(line, fromArg, toArg) {
1332
- var lineObj = getLine(doc, line);
1333
- var lineLen = lineObj.text.length;
1334
- var start, end;
1335
- function coords(ch, bias) {
1336
- return charCoords(cm, Pos(line, ch), "div", lineObj, bias);
1337
- }
1338
-
1339
- iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) {
1340
- var leftPos = coords(from, "left"), rightPos, left, right;
1341
- if (from == to) {
1342
- rightPos = leftPos;
1343
- left = right = leftPos.left;
1344
- } else {
1345
- rightPos = coords(to - 1, "right");
1346
- if (dir == "rtl") { var tmp = leftPos; leftPos = rightPos; rightPos = tmp; }
1347
- left = leftPos.left;
1348
- right = rightPos.right;
1349
- }
1350
- if (fromArg == null && from == 0) left = leftSide;
1351
- if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
1352
- add(left, leftPos.top, null, leftPos.bottom);
1353
- left = leftSide;
1354
- if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top);
1355
- }
1356
- if (toArg == null && to == lineLen) right = rightSide;
1357
- if (!start || leftPos.top < start.top || leftPos.top == start.top && leftPos.left < start.left)
1358
- start = leftPos;
1359
- if (!end || rightPos.bottom > end.bottom || rightPos.bottom == end.bottom && rightPos.right > end.right)
1360
- end = rightPos;
1361
- if (left < leftSide + 1) left = leftSide;
1362
- add(left, rightPos.top, right - left, rightPos.bottom);
1363
- });
1364
- return {start: start, end: end};
1365
- }
1366
-
1367
- var sFrom = range.from(), sTo = range.to();
1368
- if (sFrom.line == sTo.line) {
1369
- drawForLine(sFrom.line, sFrom.ch, sTo.ch);
1370
- } else {
1371
- var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line);
1372
- var singleVLine = visualLine(fromLine) == visualLine(toLine);
1373
- var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end;
1374
- var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start;
1375
- if (singleVLine) {
1376
- if (leftEnd.top < rightStart.top - 2) {
1377
- add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
1378
- add(leftSide, rightStart.top, rightStart.left, rightStart.bottom);
1379
- } else {
1380
- add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
1381
- }
1382
- }
1383
- if (leftEnd.bottom < rightStart.top)
1384
- add(leftSide, leftEnd.bottom, null, rightStart.top);
1385
- }
1386
-
1387
- output.appendChild(fragment);
1388
- }
1389
-
1390
- // Cursor-blinking
1391
- function restartBlink(cm) {
1392
- if (!cm.state.focused) return;
1393
- var display = cm.display;
1394
- clearInterval(display.blinker);
1395
- var on = true;
1396
- display.cursorDiv.style.visibility = "";
1397
- if (cm.options.cursorBlinkRate > 0)
1398
- display.blinker = setInterval(function() {
1399
- display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden";
1400
- }, cm.options.cursorBlinkRate);
1401
- else if (cm.options.cursorBlinkRate < 0)
1402
- display.cursorDiv.style.visibility = "hidden";
1403
- }
1404
-
1405
- // HIGHLIGHT WORKER
1406
-
1407
- function startWorker(cm, time) {
1408
- if (cm.doc.mode.startState && cm.doc.frontier < cm.display.viewTo)
1409
- cm.state.highlight.set(time, bind(highlightWorker, cm));
1410
- }
1411
-
1412
- function highlightWorker(cm) {
1413
- var doc = cm.doc;
1414
- if (doc.frontier < doc.first) doc.frontier = doc.first;
1415
- if (doc.frontier >= cm.display.viewTo) return;
1416
- var end = +new Date + cm.options.workTime;
1417
- var state = copyState(doc.mode, getStateBefore(cm, doc.frontier));
1418
- var changedLines = [];
1419
-
1420
- doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function(line) {
1421
- if (doc.frontier >= cm.display.viewFrom) { // Visible
1422
- var oldStyles = line.styles;
1423
- var highlighted = highlightLine(cm, line, state, true);
1424
- line.styles = highlighted.styles;
1425
- var oldCls = line.styleClasses, newCls = highlighted.classes;
1426
- if (newCls) line.styleClasses = newCls;
1427
- else if (oldCls) line.styleClasses = null;
1428
- var ischange = !oldStyles || oldStyles.length != line.styles.length ||
1429
- oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass);
1430
- for (var i = 0; !ischange && i < oldStyles.length; ++i) ischange = oldStyles[i] != line.styles[i];
1431
- if (ischange) changedLines.push(doc.frontier);
1432
- line.stateAfter = copyState(doc.mode, state);
1433
- } else {
1434
- processLine(cm, line.text, state);
1435
- line.stateAfter = doc.frontier % 5 == 0 ? copyState(doc.mode, state) : null;
1436
- }
1437
- ++doc.frontier;
1438
- if (+new Date > end) {
1439
- startWorker(cm, cm.options.workDelay);
1440
- return true;
1441
- }
1442
- });
1443
- if (changedLines.length) runInOp(cm, function() {
1444
- for (var i = 0; i < changedLines.length; i++)
1445
- regLineChange(cm, changedLines[i], "text");
1446
- });
1447
- }
1448
-
1449
- // Finds the line to start with when starting a parse. Tries to
1450
- // find a line with a stateAfter, so that it can start with a
1451
- // valid state. If that fails, it returns the line with the
1452
- // smallest indentation, which tends to need the least context to
1453
- // parse correctly.
1454
- function findStartLine(cm, n, precise) {
1455
- var minindent, minline, doc = cm.doc;
1456
- var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100);
1457
- for (var search = n; search > lim; --search) {
1458
- if (search <= doc.first) return doc.first;
1459
- var line = getLine(doc, search - 1);
1460
- if (line.stateAfter && (!precise || search <= doc.frontier)) return search;
1461
- var indented = countColumn(line.text, null, cm.options.tabSize);
1462
- if (minline == null || minindent > indented) {
1463
- minline = search - 1;
1464
- minindent = indented;
1465
- }
1466
- }
1467
- return minline;
1468
- }
1469
-
1470
- function getStateBefore(cm, n, precise) {
1471
- var doc = cm.doc, display = cm.display;
1472
- if (!doc.mode.startState) return true;
1473
- var pos = findStartLine(cm, n, precise), state = pos > doc.first && getLine(doc, pos-1).stateAfter;
1474
- if (!state) state = startState(doc.mode);
1475
- else state = copyState(doc.mode, state);
1476
- doc.iter(pos, n, function(line) {
1477
- processLine(cm, line.text, state);
1478
- var save = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo;
1479
- line.stateAfter = save ? copyState(doc.mode, state) : null;
1480
- ++pos;
1481
- });
1482
- if (precise) doc.frontier = pos;
1483
- return state;
1484
- }
1485
-
1486
- // POSITION MEASUREMENT
1487
-
1488
- function paddingTop(display) {return display.lineSpace.offsetTop;}
1489
- function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight;}
1490
- function paddingH(display) {
1491
- if (display.cachedPaddingH) return display.cachedPaddingH;
1492
- var e = removeChildrenAndAdd(display.measure, elt("pre", "x"));
1493
- var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle;
1494
- var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)};
1495
- if (!isNaN(data.left) && !isNaN(data.right)) display.cachedPaddingH = data;
1496
- return data;
1497
- }
1498
-
1499
- // Ensure the lineView.wrapping.heights array is populated. This is
1500
- // an array of bottom offsets for the lines that make up a drawn
1501
- // line. When lineWrapping is on, there might be more than one
1502
- // height.
1503
- function ensureLineHeights(cm, lineView, rect) {
1504
- var wrapping = cm.options.lineWrapping;
1505
- var curWidth = wrapping && cm.display.scroller.clientWidth;
1506
- if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
1507
- var heights = lineView.measure.heights = [];
1508
- if (wrapping) {
1509
- lineView.measure.width = curWidth;
1510
- var rects = lineView.text.firstChild.getClientRects();
1511
- for (var i = 0; i < rects.length - 1; i++) {
1512
- var cur = rects[i], next = rects[i + 1];
1513
- if (Math.abs(cur.bottom - next.bottom) > 2)
1514
- heights.push((cur.bottom + next.top) / 2 - rect.top);
1515
- }
1516
- }
1517
- heights.push(rect.bottom - rect.top);
1518
- }
1519
- }
1520
-
1521
- // Find a line map (mapping character offsets to text nodes) and a
1522
- // measurement cache for the given line number. (A line view might
1523
- // contain multiple lines when collapsed ranges are present.)
1524
- function mapFromLineView(lineView, line, lineN) {
1525
- if (lineView.line == line)
1526
- return {map: lineView.measure.map, cache: lineView.measure.cache};
1527
- for (var i = 0; i < lineView.rest.length; i++)
1528
- if (lineView.rest[i] == line)
1529
- return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i]};
1530
- for (var i = 0; i < lineView.rest.length; i++)
1531
- if (lineNo(lineView.rest[i]) > lineN)
1532
- return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i], before: true};
1533
- }
1534
-
1535
- // Render a line into the hidden node display.externalMeasured. Used
1536
- // when measurement is needed for a line that's not in the viewport.
1537
- function updateExternalMeasurement(cm, line) {
1538
- line = visualLine(line);
1539
- var lineN = lineNo(line);
1540
- var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN);
1541
- view.lineN = lineN;
1542
- var built = view.built = buildLineContent(cm, view);
1543
- view.text = built.pre;
1544
- removeChildrenAndAdd(cm.display.lineMeasure, built.pre);
1545
- return view;
1546
- }
1547
-
1548
- // Get a {top, bottom, left, right} box (in line-local coordinates)
1549
- // for a given character.
1550
- function measureChar(cm, line, ch, bias) {
1551
- return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias);
1552
- }
1553
-
1554
- // Find a line view that corresponds to the given line number.
1555
- function findViewForLine(cm, lineN) {
1556
- if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo)
1557
- return cm.display.view[findViewIndex(cm, lineN)];
1558
- var ext = cm.display.externalMeasured;
1559
- if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size)
1560
- return ext;
1561
- }
1562
-
1563
- // Measurement can be split in two steps, the set-up work that
1564
- // applies to the whole line, and the measurement of the actual
1565
- // character. Functions like coordsChar, that need to do a lot of
1566
- // measurements in a row, can thus ensure that the set-up work is
1567
- // only done once.
1568
- function prepareMeasureForLine(cm, line) {
1569
- var lineN = lineNo(line);
1570
- var view = findViewForLine(cm, lineN);
1571
- if (view && !view.text)
1572
- view = null;
1573
- else if (view && view.changes)
1574
- updateLineForChanges(cm, view, lineN, getDimensions(cm));
1575
- if (!view)
1576
- view = updateExternalMeasurement(cm, line);
1577
-
1578
- var info = mapFromLineView(view, line, lineN);
1579
- return {
1580
- line: line, view: view, rect: null,
1581
- map: info.map, cache: info.cache, before: info.before,
1582
- hasHeights: false
1583
- };
1584
- }
1585
-
1586
- // Given a prepared measurement object, measures the position of an
1587
- // actual character (or fetches it from the cache).
1588
- function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
1589
- if (prepared.before) ch = -1;
1590
- var key = ch + (bias || ""), found;
1591
- if (prepared.cache.hasOwnProperty(key)) {
1592
- found = prepared.cache[key];
1593
- } else {