Code Snippets - Version 2.0

Version Description

Highlights:

  • Better import/export functionality
  • New settings page with code editor settings
  • Code rewritten for cleaner and more efficient code
  • Lots of new translations

  • Removed old admin style support

  • Removed backwards-compatible support

  • Added braces to single-line conditionals in line with new coding standards

  • Split up large classes into separate functions

  • Improved plugin file structure

  • Replaced uninstall hook with single file method

  • Added link to Code Snippets importer under Snippets admin menu

  • Added settings component and admin page

  • Added support for different CodeMirror themes

  • Integrated tags component into main plugin. Current users of the Code Snippets Tags plugin can safely uninstall it.

  • Added Auto Close Brackets CodeMirror addon (props to TronicLabs)

  • Fixed incompatibility errors with PHP 5.2

  • Added Serbo-Croatian translation by Borisa Djuraskovic from Web Hosting Hub

  • Fixed empty MO translation files

  • Added Highlight Selection Matches CodeMirror addon (props to TronicLabs)

  • Added Chinese translation thanks to Jincheng Shan

  • Updated CodeMirror library to version 4.6

  • Added Russian translation by Alexander Samsonov

  • Added Slovak translation by [Jn Fajk] from WordPress Slovakia

  • Added setting to always save and activate snippets by default

  • Updated CodeMirror library to version 5.0

  • Rewritten import/export functionality to use DOMDocument

  • Merged Code_Snippets_Export_PHP class into Code_Snippets_Export class

  • Removed duplicate MySQL primary key indexing

Download this release

Release Info

Developer bungeshea
Plugin Icon Code Snippets
Version 2.0
Comparing to
See all releases

Code changes from version 1.9.1.1 to 2.0

Files changed (66) hide show
  1. code-snippets.php +119 -1219
  2. css/build/edit-snippet.css +53 -0
  3. css/build/manage-snippets.css +80 -0
  4. css/build/menu-icon.css +16 -0
  5. css/edit-snippet.scss +51 -0
  6. css/font/code-snippets.eot +0 -0
  7. css/font/code-snippets.svg +11 -0
  8. css/font/code-snippets.ttf +0 -0
  9. css/font/code-snippets.woff +0 -0
  10. css/manage-snippets.scss +84 -0
  11. css/menu-icon.scss +19 -0
  12. css/min/edit-snippet.css +1 -0
  13. css/min/manage-snippets.css +1 -0
  14. css/min/menu-icon.css +1 -0
  15. includes/admin.php +224 -0
  16. includes/caps.php +60 -0
  17. includes/class-export.php +254 -190
  18. includes/db.php +146 -0
  19. includes/edit/admin-help.php +47 -0
  20. includes/edit/admin-messages.php +36 -0
  21. includes/edit/admin.php +146 -0
  22. includes/edit/edit.php +370 -0
  23. includes/editor.php +40 -0
  24. includes/import/admin-help.php +41 -0
  25. includes/import/admin-messages.php +32 -0
  26. includes/import/admin.php +45 -0
  27. includes/import/import.php +115 -0
  28. includes/manage/admin-help.php +41 -0
  29. includes/manage/admin-messages.php +42 -0
  30. includes/manage/admin.php +51 -0
  31. includes/manage/class-list-table.php +815 -0
  32. includes/manage/manage.php +106 -0
  33. includes/settings/admin.php +54 -0
  34. includes/settings/editor-preview.php +156 -0
  35. includes/settings/settings-fields.php +41 -0
  36. includes/settings/settings.php +243 -0
  37. includes/snippet-ops.php +493 -0
  38. includes/upgrade.php +61 -0
  39. js/vendor/jquery.tagit.css +67 -0
  40. js/vendor/tag-it.min.js +16 -0
  41. js/vendor/tagit.ui-zendesk.css +56 -0
  42. languages/code-snippets-de_DE.mo +0 -0
  43. languages/code-snippets-it_IT.mo +0 -0
  44. languages/code-snippets-it_IT.po +502 -0
  45. languages/code-snippets-ja_JP.mo +0 -0
  46. languages/code-snippets-ja_JP.po +569 -0
  47. languages/code-snippets-ru_RU.mo +0 -0
  48. languages/code-snippets-ru_RU.po +610 -0
  49. languages/code-snippets-sk_SK.mo +0 -0
  50. languages/code-snippets-sk_SK.po +596 -0
  51. languages/code-snippets-sr_RS.mo +0 -0
  52. languages/code-snippets-sr_RS.po +571 -0
  53. languages/code-snippets-zh_CN.mo +0 -0
  54. languages/code-snippets-zh_CN.po +517 -0
  55. languages/code-snippets.mo +0 -0
  56. languages/code-snippets.pot +675 -419
  57. license.txt +7 -7
  58. readme.txt +355 -319
  59. uninstall.php +74 -0
  60. vendor/codemirror/addon/edit/matchbrackets.js +120 -87
  61. vendor/codemirror/addon/search/search.js +164 -133
  62. vendor/codemirror/addon/search/searchcursor.js +189 -143
  63. vendor/codemirror/lib/codemirror.css +309 -263
  64. vendor/codemirror/lib/codemirror.js +8045 -5942
  65. vendor/codemirror/mode/clike/clike.js +489 -362
  66. vendor/codemirror/mode/php/php.js +129 -132
code-snippets.php CHANGED
@@ -1,1219 +1,119 @@
1
- <?php
2
-
3
- /**
4
- * Code Snippets - An easy, clean and simple way to add code snippets to your site.
5
- *
6
- * If you're interested in helping to develop Code Snippets, or perhaps
7
- * contribute to the localization, please see http://code-snippets.bungeshea.com
8
- *
9
- * @package Code_Snippets
10
- * @version 1.9.1.1
11
- * @author Shea Bunge <http://bungeshea.com/>
12
- * @copyright Copyright (c) 2012-2014, Shea Bunge
13
- * @link http://code-snippets.bungeshea.com
14
- * @license http://opensource.org/licenses/MIT
15
- */
16
-
17
- /*
18
- Plugin Name: Code Snippets
19
- Plugin URI: http://code-snippets.bungeshea.com
20
- Description: An easy, clean and simple way to add code snippets to your site. No need to edit to your theme's functions.php file again!
21
- Author: Shea Bunge
22
- Author URI: http://bungeshea.com
23
- Version: 1.9.1.1
24
- License: MIT
25
- License URI: license.txt
26
- Text Domain: code-snippets
27
- Domain Path: /languages/
28
- */
29
-
30
- /* Exit if accessed directly */
31
- if ( ! defined( 'ABSPATH' ) )
32
- exit;
33
-
34
- if ( ! class_exists( 'Code_Snippets' ) ) :
35
-
36
- /**
37
- * The main class for our plugin.
38
- * It all happens here, folks
39
- *
40
- * Please use the global variable $code_snippets to access
41
- * the methods or variables in this class. Anything you need
42
- * to access should be publicly available there
43
- *
44
- * @since 1.0
45
- * @package Code_Snippets
46
- * @access private
47
- */
48
- final class Code_Snippets {
49
-
50
- /**
51
- * The version number for this release of the plugin.
52
- * This will later be used for upgrades and enqueueing files
53
- *
54
- * This should be set to the 'Plugin Version' value,
55
- * as defined above in the plugin header
56
- *
57
- * @since 1.0
58
- * @access public
59
- * @var string A PHP-standardized version number string
60
- */
61
- public $version = '1.9.1.1';
62
-
63
- /**
64
- * Variables to hold plugin paths
65
- *
66
- * @since 1.0
67
- * @access public
68
- * @var string
69
- */
70
- public $file, $basename, $plugin_dir, $plugin_url = '';
71
-
72
- /**
73
- * Stores an instance of the list table class
74
- *
75
- * @var object
76
- * @since 1.5
77
- * @access public
78
- * @see Code_Snippets_List_Table
79
- */
80
- public $list_table;
81
-
82
- /**
83
- * Stores an instance of the administration class
84
- *
85
- * @var object
86
- * @since Code_Snippets 1.7.1
87
- * @access public
88
- * @see Code_Snippets_Admin
89
- */
90
- public $admin;
91
-
92
- /**
93
- * Used by maybe_create_tables() for bailing early
94
- *
95
- * @var boolean
96
- * @access protected
97
- */
98
- static $tables_created = false;
99
-
100
- /**
101
- * Stores the snippet table names
102
- *
103
- * It's better to use $wpdb->snippets and
104
- * $wpdb->ms_snippets, but these are maintained
105
- * as references for backwards-compatibility
106
- *
107
- * @var string
108
- * @access public
109
- */
110
- public $table, $ms_table = '';
111
-
112
- /**
113
- * These are now deprecated in favor of those in
114
- * the Code_Snippets_Admin class, but maintained as
115
- * references so we don't break existing code
116
- *
117
- * @since 1.0
118
- * @deprecated Moved to the Code_Snippets_Admin class in 1.7.1
119
- * @access public
120
- * @var string
121
- */
122
- public $admin_manage, $admin_single, $admin_import,
123
- $admin_manage_url, $admin_single_url, $admin_import_url = '';
124
-
125
- /**
126
- * The constructor function for our class
127
- *
128
- * This method is called just as this plugin is included,
129
- * so other plugins may not have loaded yet. Only do stuff
130
- * here that really can't wait
131
- *
132
- * @since 1.0
133
- * @access private
134
- * @return void
135
- */
136
- function __construct() {
137
-
138
- /* Initialize the variables holding the snippet table names */
139
- $this->set_table_vars();
140
-
141
- /* Add backwards-compatibly for the CS_SAFE_MODE constant */
142
- if ( defined( 'CS_SAFE_MODE' ) && ! defined( 'CODE_SNIPPETS_SAFE_MODE' ) ) {
143
- define( 'CODE_SNIPPETS_SAFE_MODE', CS_SAFE_MODE );
144
- }
145
-
146
- /* Execute the snippets once the plugins are loaded */
147
- add_action( 'plugins_loaded', array( $this, 'run_snippets' ), 1 );
148
-
149
- /* Hook our initialize function to the plugins_loaded action */
150
- add_action( 'plugins_loaded', array( $this, 'init' ) );
151
-
152
- }
153
-
154
- /**
155
- * Load the plugin completely
156
- *
157
- * This method is called *after* other plugins
158
- * have been run
159
- *
160
- * @since 1.7
161
- * @access public
162
- * @return void
163
- */
164
- public function init() {
165
-
166
- /* Initialize core variables */
167
- $this->setup_vars();
168
-
169
- /* Check if we need to change some stuff */
170
- $this->upgrade();
171
-
172
- /*
173
- * Load up the localization file if we're using WordPress in a different language.
174
- * Place it in this plugin's "languages" folder and name it "code-snippets-[value in wp-config].mo"
175
- *
176
- * If you wish to contribute a language file to be included in the Code Snippets package,
177
- * please see create an issue on GitHub: https://github.com/bungeshea/code-snippets/issues
178
- */
179
- load_plugin_textdomain( 'code-snippets', false, dirname( $this->basename ) . '/languages/' );
180
-
181
- /* Cleanup the plugin data on uninstall */
182
- register_uninstall_hook( $this->file, array( __CLASS__, 'uninstall' ) );
183
-
184
- /* Load the global functions file */
185
- $this->get_include( 'functions' );
186
-
187
- /* Add and remove capabilities from Super Admins if their statuses change */
188
- add_action( 'grant_super_admin', array( $this, 'add_ms_cap_to_user' ) );
189
- add_action( 'remove_super_admin', array( $this, 'remove_ms_cap_from_user' ) );
190
-
191
- /* Let extension plugins know that it's okay to load */
192
- do_action( 'code_snippets_init' );
193
- }
194
-
195
- /**
196
- * Initialize variables
197
- *
198
- * @since 1.2
199
- * @access private
200
- * @return void
201
- */
202
- function setup_vars() {
203
-
204
- /* Plugin directory variables */
205
- $this->file = __FILE__;
206
- $this->basename = plugin_basename( $this->file );
207
- $this->plugin_dir = plugin_dir_path( $this->file );
208
- $this->plugin_url = plugin_dir_url ( $this->file );
209
-
210
- /* Roles and capabilities variables */
211
- $this->role = apply_filters( 'code_snippets_role', 'administrator' );
212
- $this->cap = apply_filters( 'code_snippets_cap', 'manage_snippets' );
213
- $this->network_cap = apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' );
214
-
215
- if ( is_admin() ) {
216
-
217
- /* Load our administration class */
218
- $this->get_include( 'class-admin' );
219
- $this->admin = new Code_Snippets_Admin;
220
-
221
- /* Remap deprecated variables */
222
- $this->admin_manage_url = &$this->admin->manage_url;
223
- $this->admin_single_url = &$this->admin->single_url;
224
- $this->admin_import_url = &$this->admin->import_url;
225
-
226
- $this->admin_manage = &$this->admin->manage_page;
227
- $this->admin_single = &$this->admin->single_page;
228
- $this->admin_import = &$this->admin->import_page;
229
- }
230
- }
231
-
232
- /**
233
- * Require a PHP file from the includes directory
234
- * @since 1.8
235
- * @param string $slug The file slug (filename with no path or extension) to load
236
- * @return void
237
- */
238
- public function get_include( $slug ) {
239
- require_once $this->plugin_dir . "includes/{$slug}.php";
240
- }
241
-
242
- /**
243
- * Register the snippet table names with WordPress
244
- *
245
- * @since 1.7
246
- * @access public
247
- * @uses $wpdb
248
- * @return void
249
- */
250
- public function set_table_vars() {
251
- global $wpdb;
252
-
253
- /* Register the snippet table names with WordPress */
254
- $wpdb->tables[] = 'snippets';
255
- $wpdb->ms_global_tables[] = 'ms_snippets';
256
-
257
- /* Setup initial table variables */
258
- $wpdb->snippets = $wpdb->prefix . 'snippets';
259
- $wpdb->ms_snippets = $wpdb->base_prefix . 'ms_snippets';
260
-
261
- /* Add a pointer to the old variables */
262
- $this->table = &$wpdb->snippets;
263
- $this->ms_table = &$wpdb->ms_snippets;
264
- }
265
-
266
- /**
267
- * Return the appropriate snippet table name
268
- *
269
- * @since 1.6
270
- * @access public
271
- * @param string $scope Retrieve the multisite table name or the site table name?
272
- * @param boolean $check_screen Query the current screen if no scope passed?
273
- * @return string The snippet table name
274
- */
275
- public function get_table_name( $scope = '', $check_screen = true ) {
276
- global $wpdb;
277
-
278
- /* If multisite is not active, always return the site-wide table name */
279
- if ( ! is_multisite() ) {
280
- $network = false;
281
- }
282
-
283
- /* If the scope is 'multisite' or 'network', return the network-wide table name */
284
- elseif ( in_array( $scope, array( 'multisite', 'network' ) ) ) {
285
- $network = true;
286
- }
287
-
288
- /* If no scope is set, query the current screen to see if in network admin */
289
- elseif ( empty( $scope ) && $check_screen && function_exists( 'get_current_screen' ) ) {
290
- $network = get_current_screen()->is_network;
291
- }
292
-
293
- /* If none of the above conditions match, just use the site-wide table name */
294
- else {
295
- $network = false;
296
- }
297
-
298
- /* Retrieve the table name from $wpdb depending on the above conditionals */
299
- return ( $network ? $wpdb->ms_snippets : $wpdb->snippets );
300
- }
301
-
302
- /**
303
- * Create the snippet tables if they do not already exist
304
- *
305
- * @since 1.7.1
306
- * @access public
307
- *
308
- * @uses $this->create_table() To create a single snippet table
309
- * @staticvar boolean $tables_created Used to check if we've already done this or not
310
- * @param boolean $redo Skip the already-done-this check
311
- * @param boolean $always_create_table Always create the site-wide table if it doesn't exist
312
- * @return void
313
- */
314
- public function maybe_create_tables( $redo = false, $always_create_table = false ) {
315
-
316
- /* Bail early if we've done this already */
317
- if ( ! $redo && true === self::$tables_created )
318
- return;
319
-
320
- global $wpdb;
321
-
322
- /* Set the table name variables if not yet defined */
323
- if ( ! isset( $wpdb->snippets, $wpdb->ms_snippets ) ) {
324
- $this->set_table_vars();
325
- }
326
-
327
- /* Always create the network-wide snippet table */
328
- if ( is_multisite() ) {
329
- $this->create_table( $wpdb->ms_snippets );
330
- }
331
-
332
- /* Create the site-specific table if we're on the main site */
333
- if ( $always_create_table || is_main_site() ) {
334
- $this->create_table( $wpdb->snippets );
335
- }
336
-
337
- /* Set the flag so we don't have to do this again */
338
- self::$tables_created = true;
339
- }
340
-
341
- /**
342
- * Create the snippet tables if they do not already exist
343
- *
344
- * @since Code Snippets 1.2
345
- * @deprecated Code Snippets 1.7.1
346
- * @access public
347
- * @return void
348
- */
349
- public function create_tables() {
350
- _deprecated_function(
351
- '$code_snippets->create_tables()',
352
- 'Code Snippets 1.7.1',
353
- '$code_snippets->maybe_create_tables()'
354
- );
355
- $this->maybe_create_tables();
356
- }
357
-
358
- /**
359
- * Create a single snippet table
360
- * if one of the same name does not already exist
361
- *
362
- * @since 1.6
363
- * @access private
364
- *
365
- * @uses dbDelta() To add the table to the database
366
- *
367
- * @param string $table_name The name of the table to create
368
- * @param boolean $force_creation Skip the table exists check
369
- * @return void
370
- */
371
- function create_table( $table_name, $force_creation = false ) {
372
- require_once ABSPATH . 'wp-admin/includes/upgrade.php';
373
-
374
- global $wpdb;
375
-
376
- if ( ! $force_creation && $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->snippets'" ) === $wpdb->snippets ) {
377
- return; // bail if the table already exists
378
- }
379
-
380
- /* Set the database charset */
381
-
382
- $charset_collate = '';
383
-
384
- if ( ! empty( $wpdb->charset ) ) {
385
- $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
386
- }
387
-
388
- if ( ! empty( $wpdb->collate ) ) {
389
- $charset_collate .= " COLLATE $wpdb->collate";
390
- }
391
-
392
- /* Set the snippet data columns */
393
-
394
- $table_columns = apply_filters( 'code_snippets/database_table_columns', array(
395
- 'name tinytext not null',
396
- 'description text',
397
- 'code longtext not null',
398
- ) );
399
-
400
- $table_columns_sql = implode( ",\n", $table_columns ); // convert the array into SQL code
401
-
402
- /* Create the database table */
403
-
404
- $sql = "CREATE TABLE $table_name (
405
- id bigint(20) unsigned not null auto_increment,
406
- {$table_columns_sql},
407
- active tinyint(1) not null default 0,
408
- PRIMARY KEY (id),
409
- KEY id (id)
410
-
411
- ) {$charset_collate};";
412
-
413
- dbDelta( apply_filters( 'code_snippets/table_sql', $sql ) );
414
-
415
- do_action( 'code_snippets/create_table', $table_name );
416
- }
417
-
418
- /**
419
- * Preform upgrade tasks such as deleting and updating options
420
- *
421
- * @since 1.2
422
- * @access private
423
- * @return void
424
- */
425
- function upgrade() {
426
- global $wpdb;
427
-
428
- /* Get the current plugin version from the database */
429
-
430
- $current_version = get_option( 'code_snippets_version' );
431
-
432
- if ( ! $current_version && get_option( 'cs_db_version' ) ) {
433
- $current_version = get_option( 'cs_db_version' );
434
- delete_option( 'cs_db_version' );
435
- add_option( 'code_snippets_version', $current_version );
436
- }
437
-
438
- $previous_version = ( $current_version ? $current_version : $this->version );
439
-
440
- /* Skip this if we're on the latest version */
441
- if ( version_compare( $current_version, $this->version, '<' ) ) {
442
-
443
- /* Remove capabilities that were deprecated in 1.9 */
444
- if ( version_compare( $current_version, '1.9', '<' ) ) {
445
- $role = get_role( $this->role );
446
-
447
- $role->remove_cap( 'install_network_snippets' );
448
- $role->remove_cap( 'edit_network_snippets' );
449
- }
450
-
451
- /* Data in database is unescaped in 1.8; slashes removed in 1.9 */
452
- if ( version_compare( $current_version, '1.9', '<' ) ) {
453
-
454
- $tables = array();
455
-
456
- if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->snippets'" ) === $wpdb->snippets ) {
457
- $tables[] = $wpdb->snippets;
458
- }
459
-
460
- if ( is_multisite() && is_main_site() && $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->ms_snippets'" ) === $wpdb->ms_snippets ) {
461
- $tables[] = $wpdb->ms_snippets;
462
- }
463
-
464
- foreach ( $tables as $table ) {
465
- $snippets = $wpdb->get_results( "SELECT * FROM $table" );
466
-
467
- foreach ( $snippets as $snippet ) {
468
-
469
- $snippet->name = stripslashes( $snippet->name );
470
- $snippet->code = stripslashes( $snippet->code );
471
- $snippet->description = stripslashes( $snippet->description );
472
-
473
- if ( version_compare( $current_version, '1.8', '<' ) ) {
474
- $snippet->name = htmlspecialchars_decode( $snippet->name );
475
- $snippet->code = htmlspecialchars_decode( $snippet->code );
476
- $snippet->description = htmlspecialchars_decode( $snippet->description );
477
- }
478
-
479
- $wpdb->update( $table,
480
- array(
481
- 'name' => $snippet->name,
482
- 'code' => $snippet->code,
483
- 'description' => $snippet->description
484
- ),
485
- array( 'id' => $snippet->id ),
486
- array( '%s' ),
487
- array( '%d' )
488
- );
489
- }
490
- } // end $table foreach
491
-
492
- } // end < 1.8 version check
493
-
494
- /* Register the capabilities once only */
495
- if ( version_compare( $current_version, '1.5', '<' ) ) {
496
- $this->add_cap();
497
- }
498
-
499
- if ( version_compare( $previous_version, '1.2', '<' ) ) {
500
- /* The 'Complete Uninstall' option was removed in version 1.2 */
501
- delete_option( 'cs_complete_uninstall' );
502
- }
503
-
504
- /* Update the current version stored in the database */
505
- update_option( 'code_snippets_version', $this->version );
506
- }
507
-
508
- /* Multisite-only upgrades */
509
-
510
- if ( is_multisite() && is_main_site() ) {
511
-
512
- $current_ms_version = get_site_option( 'code_snippets_version' );
513
-
514
- if ( version_compare( $current_ms_version, $this->version, '<' ) ) {
515
-
516
- /* Remove capabilities that were deprecated in 1.9 */
517
- if ( version_compare( $current_version, '1.9', '<' ) ) {
518
- $supers = get_super_admins();
519
-
520
- foreach ( $supers as $admin ) {
521
- $user = new WP_User( 0, $admin );
522
- $user->remove_cap( 'install_network_snippets' );
523
- $user->remove_cap( 'edit_network_snippets' );
524
- }
525
- }
526
-
527
- /* Add custom capabilities introduced in 1.5 */
528
- if ( version_compare( $current_ms_version, '1.5', '<' ) ) {
529
- $this->setup_ms_roles( true );
530
- }
531
-
532
- /* Migrate recently_network_activated_snippets to the site options */
533
- if ( get_option( 'recently_network_activated_snippets' ) ) {
534
-
535
- add_site_option(
536
- 'recently_activated_snippets',
537
- get_option( 'recently_network_activated_snippets', array() )
538
- );
539
-
540
- delete_option( 'recently_network_activated_snippets' );
541
- }
542
-
543
- }
544
-
545
- update_site_option( 'code_snippets_version', $this->version );
546
- }
547
-
548
- }
549
-
550
- /**
551
- * Register the user roles and capabilities
552
- *
553
- * @since 1.9 Removed uninstall functionality into a separate method
554
- * @since 1.5
555
- * @access private
556
- * @return void
557
- */
558
- function add_cap() {
559
-
560
- /* Retrieve the role object */
561
- $role = get_role( $this->role );
562
-
563
- /* Add the capability */
564
- $role->add_cap( $this->cap );
565
- }
566
-
567
- /**
568
- * Deregister the user roles and capabilities
569
- *
570
- * @since 1.9
571
- * @access private
572
- * @return void
573
- */
574
- function remove_cap() {
575
-
576
- /* Retrieve the role object */
577
- $role = get_role( $this->role );
578
-
579
- /* Remove the capability */
580
- $role->remove_cap( $this->cap );
581
- }
582
-
583
- /**
584
- * Register or deregister the multisite user roles and capabilities
585
- *
586
- * @since 1.5
587
- * @access private
588
- * @param boolean $install true to add the capabilities, false to remove
589
- * @return void
590
- */
591
- function setup_ms_roles( $install = true ) {
592
-
593
- if ( ! is_multisite() )
594
- return;
595
-
596
- $supers = get_super_admins();
597
-
598
- foreach ( $supers as $admin ) {
599
- $user = new WP_User( 0, $admin );
600
-
601
- if ( $install )
602
- $user->add_cap( $this->network_cap );
603
- else
604
- $user->remove_cap( $this->network_cap );
605
- }
606
-
607
- }
608
-
609
- /**
610
- * Add the multisite capabilities to a user
611
- *
612
- * @since 1.9
613
- * @param integer $user_id The ID of the user to add the cap to
614
- * @return void
615
- */
616
- function add_ms_cap_to_user( $user_id ) {
617
-
618
- /* Get the user from the ID */
619
- $user = new WP_User( $user_id );
620
-
621
- /* Add the capability */
622
- $user->add_cap( $this->network_cap );
623
- }
624
-
625
- /**
626
- * Remove the multisite capabilities from a user
627
- *
628
- * @since 1.9
629
- * @param integer $user_id The ID of the user to remove the cap from
630
- * @return void
631
- */
632
- function remove_ms_cap_from_user( $user_id ) {
633
-
634
- /* Get the user from the ID */
635
- $user = new WP_User( $user_id );
636
-
637
- /* Remove the capability */
638
- $user->remove_cap( $this->network_cap );
639
- }
640
-
641
- /**
642
- * Check if the current user can perform some action on snippets or not
643
- *
644
- * @uses current_user_can() To check if the current user can perform a task
645
- * @uses $this->get_cap() To get the required capability
646
- *
647
- * @param string $deprecated Deprecated in 1.9
648
- * @return boolean Whether the current user can perform this task or not
649
- *
650
- * @since 1.9 Removed multiple capability support
651
- * @since 1.7.1.1 Moved logic to $this->get_cap() method
652
- * @since 1.7.1
653
- * @access public
654
- */
655
- public function user_can( $deprecated = '' ) {
656
- return current_user_can( $this->get_cap() );
657
- }
658
-
659
- /**
660
- * Get the required capability to perform a certain action on snippets.
661
- * Does not check if the user has this capability or not.
662
- *
663
- * If multisite, checks if *Enable Administration Menus: Snippets* is active
664
- * under the *Settings > Network Settings* network admin menu
665
- *
666
- * @param string $deprecated Deprecated in 1.9
667
- * @since 1.9 Removed first parameter
668
- * @since 1.7.1.1
669
- * @access public
670
- * @return void
671
- */
672
- public function get_cap( $deprecated = '' ) {
673
-
674
- if ( is_multisite() ) {
675
- $menu_perms = get_site_option( 'menu_items', array() );
676
-
677
- /* If multisite is enabled and the snippet menu is not activated,
678
- restrict snippet operations to super admins only */
679
- if ( ! empty( $menu_perms['snippets'] ) ) {
680
- return $this->cap;
681
- } else {
682
- /* The snippet menu is not activated, only allow super admins */
683
- return $this->network_cap;
684
- }
685
- }
686
-
687
- return $this->cap;
688
- }
689
-
690
- /**
691
- * Converts an array of snippet data into a snippet object
692
- *
693
- * @since 1.7
694
- * @access public
695
- *
696
- * @param mixed $data The snippet data to convert
697
- * @return object The resulting snippet object
698
- */
699
- public function build_snippet_object( $data = null ) {
700
-
701
- $snippet = new stdClass;
702
-
703
- /* Define an empty snippet object (or one with default values ) */
704
- $snippet->id = 0;
705
- $snippet->name = '';
706
- $snippet->description = '';
707
- $snippet->code = '';
708
- $snippet->active = 0;
709
- $snippet = apply_filters( 'code_snippets/build_default_snippet', $snippet );
710
-
711
- if ( ! isset( $data ) ) {
712
- return $snippet;
713
- }
714
- elseif ( is_object( $data ) ) {
715
- /* If we already have a snippet object, merge it with the default */
716
- return (object) array_merge( (array) $snippet, (array) $data );
717
- }
718
- elseif ( is_array( $data ) ) {
719
-
720
- if ( isset( $data['id'] ) )
721
- $snippet->id = $data['id'];
722
- elseif ( isset( $data['snippet_id'] ) )
723
- $snippet->id = $data['snippet_id'];
724
-
725
- if ( isset( $data['name'] ) )
726
- $snippet->name = $data['name'];
727
- elseif ( isset( $data['snippet_name'] ) )
728
- $snippet->name = $data['snippet_name'];
729
-
730
- if ( isset( $data['description'] ) )
731
- $snippet->description = $data['description'];
732
- elseif ( isset( $data['snippet_description'] ) )
733
- $snippet->description = $data['snippet_description'];
734
-
735
- if ( isset( $data['code'] ) )
736
- $snippet->code = $data['code'];
737
- elseif ( isset( $data['snippet_code'] ) )
738
- $snippet->code = $data['snippet_code'];
739
-
740
-
741
- if ( isset( $data['active' ] ) )
742
- $snippet->active = $data['active'];
743
- elseif ( isset( $data['snippet_active'] ) )
744
- $snippet->active = $data['snippet_active'];
745
-
746
- return apply_filters( 'code_snippets/build_snippet_object', $snippet, $data );
747
- }
748
-
749
- return $snippet;
750
- }
751
-
752
- /**
753
- * Retrieve a list of snippets from the database
754
- *
755
- * @since 1.7
756
- * @access public
757
- *
758
- * @uses $wpdb To query the database for snippets
759
- * @uses $this->get_table_name() To dynamically retrieve the snippet table name
760
- *
761
- * @param string $scope Retrieve multisite-wide or site-wide snippets?
762
- * @return array An array of snippet objects
763
- */
764
- public function get_snippets( $scope = '' ) {
765
- global $wpdb;
766
-
767
- $table = $this->get_table_name( $scope );
768
- $snippets = $wpdb->get_results( "SELECT * FROM $table", ARRAY_A );
769
-
770
- foreach ( $snippets as $index => $snippet ) {
771
- $snippets[ $index ] = $this->unescape_snippet_data( $snippet );
772
- }
773
-
774
- return apply_filters( 'code_snippets/get_snippets', $snippets, $scope );
775
- }
776
-
777
- /**
778
- * Escape snippet data for inserting into the database
779
- *
780
- * @since 1.7
781
- * @access public
782
- *
783
- * @param mixed $snippet An object or array containing the data to escape
784
- * @return object The resulting snippet object, with data escaped
785
- */
786
- public function escape_snippet_data( $snippet ) {
787
-
788
- $snippet = $this->build_snippet_object( $snippet );
789
-
790
- /* Remove <?php and <? from beginning of snippet */
791
- $snippet->code = preg_replace( '|^[\s]*<\?(php)?|', '', $snippet->code );
792
-
793
- /* Remove ?> from end of snippet */
794
- $snippet->code = preg_replace( '|\?>[\s]*$|', '', $snippet->code );
795
-
796
- /* Escape the data */
797
- $snippet->id = absint ( $snippet->id );
798
-
799
- return apply_filters( 'code_snippets/escape_snippet_data', $snippet );
800
- }
801
-
802
- /**
803
- * Unescape snippet data after retrieval from the database
804
- * ready for use
805
- *
806
- * @since 1.7
807
- * @access public
808
- *
809
- * @param mixed $snippet An object or array containing the data to unescape
810
- * @return object The resulting snippet object, with data unescaped
811
- */
812
- public function unescape_snippet_data( $snippet ) {
813
- $snippet = $this->build_snippet_object( $snippet );
814
- return apply_filters( 'code_snippets/unescape_snippet_data', $snippet );
815
- }
816
-
817
- /**
818
- * Retrieve a single snippets from the database.
819
- * Will return empty snippet object if no snippet
820
- * ID is specified
821
- *
822
- * @since 1.7
823
- * @access public
824
- *
825
- * @uses $wpdb To query the database for snippets
826
- * @uses $this->get_table_name() To dynamically retrieve the snippet table name
827
- *
828
- * @param int $id The ID of the snippet to retrieve. 0 to build a new snippet
829
- * @param string $scope Retrieve a multisite-wide or site-wide snippet?
830
- * @return object A single snippet object
831
- */
832
- public function get_snippet( $id = 0, $scope = '' ) {
833
- global $wpdb;
834
- $table = $this->get_table_name( $scope );
835
- $id = absint( $id );
836
-
837
- if ( 0 !== $id ) {
838
- /* Retrieve the snippet from the database */
839
- $snippet = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE id = %d", $id ) );
840
- /* Unescape the snippet data, ready for use */
841
- $snippet = $this->unescape_snippet_data( $snippet );
842
- } else {
843
- /* Get an empty snippet object */
844
- $snippet = $this->build_snippet_object();
845
- }
846
- return apply_filters( 'code_snippets/get_snippet', $snippet, $id, $scope );
847
- }
848
-
849
- /**
850
- * Activates a snippet
851
- *
852
- * @since 1.5
853
- * @access public
854
- *
855
- * @uses $wpdb To set the snippets' active status
856
- *
857
- * @param array $ids The ids of the snippets to activate
858
- * @param string $scope Are the snippets multisite-wide or site-wide?
859
- * @return void
860
- */
861
- public function activate( $ids, $scope = '' ) {
862
- global $wpdb;
863
-
864
- $ids = (array) $ids;
865
-
866
- $table = $this->get_table_name( $scope );
867
-
868
- foreach ( $ids as $id ) {
869
- $wpdb->update(
870
- $table,
871
- array( 'active' => '1' ),
872
- array( 'id' => $id ),
873
- array( '%d' ),
874
- array( '%d' )
875
- );
876
-
877
- do_action( 'code_snippets/activate_snippet', $id, $scope );
878
- }
879
-
880
- do_action( 'code_snippets/activate', $ids, $scope );
881
- }
882
-
883
- /**
884
- * Deactivates selected snippets
885
- *
886
- * @since 1.5
887
- * @access public
888
- *
889
- * @uses $wpdb To set the snippets' active status
890
- *
891
- * @param array $ids The IDs of the snippets to deactivate
892
- * @param string $scope Are the snippets multisite-wide or site-wide?
893
- * @return void
894
- */
895
- public function deactivate( $ids, $scope = '' ) {
896
- global $wpdb;
897
-
898
- $ids = (array) $ids;
899
- $recently_active = array();
900
-
901
- $table = $this->get_table_name( $scope );
902
-
903
- foreach ( $ids as $id ) {
904
- $wpdb->update(
905
- $table,
906
- array( 'active' => '0' ),
907
- array( 'id' => $id ),
908
- array( '%d' ),
909
- array( '%d' )
910
- );
911
- $recently_active = array( $id => time() ) + (array) $recently_active;
912
-
913
- do_action( 'code_snippets/deactivate_snippet', $id, $scope );
914
- }
915
-
916
- if ( $table === $wpdb->ms_snippets )
917
- update_site_option(
918
- 'recently_activated_snippets',
919
- $recently_active + (array) get_site_option( 'recently_activated_snippets' )
920
- );
921
- elseif ( $table === $wpdb->snippets )
922
- update_option(
923
- 'recently_activated_snippets',
924
- $recently_active + (array) get_option( 'recently_activated_snippets' )
925
- );
926
-
927
- do_action( 'code_snippets/deactivate', $ids, $scope );
928
- }
929
-
930
- /**
931
- * Deletes a snippet from the database
932
- *
933
- * @since 1.5
934
- * @access public
935
- *
936
- * @uses $wpdb To access the database
937
- * @uses $this->get_table_name() To dynamically retrieve the name of the snippet table
938
- *
939
- * @param int $id The ID of the snippet to delete
940
- * @param string $scope Delete from site-wide or network-wide table?
941
- */
942
- public function delete_snippet( $id, $scope = '' ) {
943
- global $wpdb;
944
-
945
- $wpdb->delete(
946
- $this->get_table_name( $scope ),
947
- array( 'id' => $id ),
948
- array( '%d' )
949
- );
950
-
951
- do_action( 'code_snippets/delete_snippet', $id, $scope );
952
- }
953
-
954
- /**
955
- * Saves a snippet to the database.
956
- *
957
- * @since 1.5
958
- * @access public
959
- *
960
- * @uses $wpdb To update/add the snippet to the database
961
- * @uses $this->get_table_name() To dynamically retrieve the name of the snippet table
962
- *
963
- * @param object $snippet The snippet to add/update to the database
964
- * @param string $scope Save the snippet to the site-wide or network-wide table?
965
- * @return int|boolean The ID of the snippet on success, false on failure
966
- */
967
- public function save_snippet( $snippet, $scope = '' ) {
968
- global $wpdb;
969
-
970
- $snippet = $this->escape_snippet_data( $snippet );
971
- $table = $this->get_table_name( $scope );
972
- $data = array();
973
-
974
- foreach ( get_object_vars( $snippet ) as $field => $value ) {
975
- if ( 'id' === $field )
976
- continue;
977
-
978
- if ( is_array( $value ) )
979
- $value = maybe_serialize( $value );
980
-
981
- $data[ $field ] = $value;
982
- }
983
-
984
- if ( isset( $snippet->id ) && 0 !== $snippet->id ) {
985
-
986
- $wpdb->update( $table, $data, array( 'id' => $snippet->id ), null, array( '%d' ) );
987
- do_action( 'code_snippets/update_snippet', $snippet, $table );
988
- return $snippet->id;
989
-
990
- } else {
991
-
992
- $wpdb->insert( $table, $data, '%s' );
993
- do_action( 'code_snippets/create_snippet', $snippet, $table );
994
- return $wpdb->insert_id;
995
- }
996
- }
997
-
998
- /**
999
- * Imports snippets from an XML file
1000
- *
1001
- * @since 1.5
1002
- * @access public
1003
- *
1004
- * @uses $this->save_snippet() To add the snippets to the database
1005
- *
1006
- * @param string $file The path to the XML file to import
1007
- * @param string $scope Import into network-wide table or site-wide table?
1008
- * @return integer|boolean The number of snippets imported on success, false on failure
1009
- */
1010
- public function import( $file, $scope = '' ) {
1011
-
1012
- if ( ! file_exists( $file ) || ! is_file( $file ) )
1013
- return false;
1014
-
1015
- $xml = simplexml_load_file( $file );
1016
-
1017
- if ( ! is_object( $xml ) || ! method_exists( $xml, 'children' ) )
1018
- return false;
1019
-
1020
- foreach ( $xml->children() as $snippet ) {
1021
- /* force manual build of object to strip out unsupported fields
1022
- by converting snippet object into an array */
1023
- $snippet = get_object_vars( $snippet );
1024
- $snippet = array_map( 'htmlspecialchars_decode', $snippet );
1025
- $this->save_snippet( $snippet, $scope );
1026
- }
1027
-
1028
- do_action( 'code_snippets/import', $xml, $scope );
1029
-
1030
- return $xml->count();
1031
- }
1032
-
1033
- /**
1034
- * Exports snippets as an XML file
1035
- *
1036
- * @since 1.5
1037
- * @access public
1038
- *
1039
- * @uses Code_Snippets_Export To export selected snippets
1040
- * @uses $this->get_table_name() To dynamically retrieve the name of the snippet table
1041
- *
1042
- * @param array $ids The IDs of the snippets to export
1043
- * @param string $scope Is the snippet a network-wide or site-wide snippet?
1044
- * @return void
1045
- */
1046
- public function export( $ids, $scope = '' ) {
1047
-
1048
- $table = $this->get_table_name( $scope );
1049
-
1050
- if ( ! class_exists( 'Code_Snippets_Export' ) )
1051
- $this->get_include( 'class-export' );
1052
-
1053
- $class = new Code_Snippets_Export( $ids, $table );
1054
- $class->do_export();
1055
- }
1056
-
1057
- /**
1058
- * Exports snippets as a PHP file
1059
- *
1060
- * @since 1.5
1061
- * @access public
1062
- *
1063
- * @uses Code_Snippets_Export_PHP To export selected snippets
1064
- * @uses $this->get_table_name() To dynamically retrieve the name of the snippet table
1065
- *
1066
- * @param array $ids The IDs of the snippets to export
1067
- * @param string $scope Is the snippet a network-wide or site-wide snippet?
1068
- * @return void
1069
- */
1070
- public function export_php( $ids, $scope = '' ) {
1071
-
1072
- $table = $this->get_table_name( $scope );
1073
-
1074
- if ( ! class_exists( 'Code_Snippets_Export' ) )
1075
- $this->get_include( 'class-export' );
1076
-
1077
- if ( ! class_exists( 'Code_Snippets_Export_PHP' ) ) {
1078
- $this->get_include( 'class-export-php' );
1079
- }
1080
-
1081
- $class = new Code_Snippets_Export_PHP( $ids, $table );
1082
- $class->do_export();
1083
- }
1084
-
1085
- /**
1086
- * Execute a snippet
1087
- *
1088
- * Code must NOT be escaped, as
1089
- * it will be executed directly
1090
- *
1091
- * @since 1.5
1092
- * @access public
1093
- *
1094
- * @param string $code The snippet code to execute
1095
- * @return mixed The result of the code execution
1096
- */
1097
- public function execute_snippet( $code ) {
1098
-
1099
- if ( empty( $code ) )
1100
- return;
1101
-
1102
- ob_start();
1103
- $result = eval( $code );
1104
- $output = ob_get_contents();
1105
- ob_end_clean();
1106
-
1107
- do_action( 'code_snippets/execute_snippet', $code );
1108
- return $result;
1109
- }
1110
-
1111
- /**
1112
- * Run the active snippets
1113
- *
1114
- * @since 1.0
1115
- * @access public
1116
- *
1117
- * @uses $wpdb To grab the active snippets from the database
1118
- * @uses $this->execute_snippet() To execute a snippet
1119
- *
1120
- * @return boolean true on success, false on failure
1121
- */
1122
- public function run_snippets() {
1123
-
1124
- /* Bail early if safe mode is active */
1125
- if ( defined( 'CODE_SNIPPETS_SAFE_MODE' ) && CODE_SNIPPETS_SAFE_MODE )
1126
- return false;
1127
-
1128
- global $wpdb;
1129
-
1130
- if ( ! isset( $wpdb->snippets, $wpdb->ms_snippets ) )
1131
- $this->set_table_vars();
1132
-
1133
- /* Check if the snippets table exists */
1134
- if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->snippets'" ) === $wpdb->snippets )
1135
- $sql = "SELECT code FROM {$wpdb->snippets} WHERE active=1";
1136
-
1137
- /* Check if the multisite snippets table exists */
1138
- if ( is_multisite() && $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->ms_snippets'" ) === $wpdb->ms_snippets ) {
1139
- $sql = ( isset( $sql ) ? $sql . "\nUNION ALL\n" : '' );
1140
- $sql .= "SELECT code FROM {$wpdb->ms_snippets} WHERE active=1;";
1141
- }
1142
-
1143
- if ( ! empty( $sql ) ) {
1144
-
1145
- /* Grab the active snippets from the database */
1146
- $active_snippets = $wpdb->get_col( $sql );
1147
-
1148
- foreach ( $active_snippets as $snippet ) {
1149
- /* Execute the PHP code */
1150
- $this->execute_snippet( $snippet );
1151
- }
1152
-
1153
- return true;
1154
- }
1155
-
1156
- /* If we're made it this far without returning true, assume failure */
1157
- return false;
1158
- }
1159
-
1160
- /**
1161
- * Cleans up data created by the Code_Snippets class
1162
- *
1163
- * @since 1.2
1164
- * @access private
1165
- *
1166
- * @uses $wpdb To remove tables from the database
1167
- * @uses $code_snippets->get_table_name() To find out which table to drop
1168
- * @uses is_multisite() To check the type of installation
1169
- * @uses switch_to_blog() To switch between blogs
1170
- * @uses restore_current_blog() To switch between blogs
1171
- * @uses delete_option() To remove site options
1172
- *
1173
- * @return void
1174
- */
1175
- static function uninstall() {
1176
- global $wpdb, $code_snippets;
1177
- if ( is_multisite() ) {
1178
- $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
1179
- if ( $blog_ids ) {
1180
- foreach ( $blog_ids as $blog_id ) {
1181
- switch_to_blog( $blog_id );
1182
- $wpdb->query( "DROP TABLE IF EXISTS $wpdb->snippets" );
1183
- delete_option( 'cs_db_version' );
1184
- delete_option( 'recently_activated_snippets' );
1185
- delete_option( 'code_snippets_version' );
1186
- $code_snippets->remove_cap();
1187
- }
1188
- restore_current_blog();
1189
- }
1190
- $wpdb->query( "DROP TABLE IF EXISTS $wpdb->ms_snippets" );
1191
- delete_site_option( 'code_snippets_version' );
1192
- delete_site_option( 'recently_activated_snippets' );
1193
- $code_snippets->setup_ms_roles( false );
1194
- } else {
1195
- $wpdb->query( "DROP TABLE IF EXISTS $wpdb->snippets" );
1196
- delete_option( 'code_snippets_version' );
1197
- delete_option( 'recently_activated_snippets' );
1198
- $code_snippets->remove_cap();
1199
- }
1200
- }
1201
-
1202
- }
1203
-
1204
- /**
1205
- * The global variable in which the Code_Snippets class is stored
1206
- *
1207
- * @var object
1208
- * @since 1.0
1209
- * @access public
1210
- * @see Code_Snippets
1211
- */
1212
- global $code_snippets;
1213
- $code_snippets = new Code_Snippets;
1214
-
1215
- /* Set up a pointer in the old variable (for backwards-compatibility) */
1216
- global $cs;
1217
- $cs = &$code_snippets;
1218
-
1219
- endif; // class exists check
1
+ <?php
2
+
3
+ /**
4
+ * Code Snippets - An easy, clean and simple way to add code snippets to your site.
5
+ *
6
+ * If you're interested in helping to develop Code Snippets, or perhaps
7
+ * contribute to the localization, please see http://code-snippets.bungeshea.com
8
+ *
9
+ * @package Code_Snippets
10
+ * @version 2.0
11
+ * @author Shea Bunge <http://bungeshea.com/>
12
+ * @copyright Copyright (c) 2012-2014, Shea Bunge
13
+ * @link http://code-snippets.bungeshea.com
14
+ * @license http://opensource.org/licenses/MIT
15
+ */
16
+
17
+ /*
18
+ Plugin Name: Code Snippets
19
+ Plugin URI: http://code-snippets.bungeshea.com
20
+ Description: An easy, clean and simple way to add code snippets to your site. No need to edit to your theme's functions.php file again!
21
+ Author: Shea Bunge
22
+ Author URI: http://bungeshea.com
23
+ Version: 2.0
24
+ License: MIT
25
+ License URI: license.txt
26
+ Text Domain: code-snippets
27
+ Domain Path: /languages/
28
+ */
29
+
30
+ /* Exit if accessed directly */
31
+ if ( ! defined( 'ABSPATH' ) ) {
32
+ exit;
33
+ }
34
+
35
+ /**
36
+ * The version number for this release of the plugin.
37
+ * This will later be used for upgrades and enqueueing files
38
+ *
39
+ * This should be set to the 'Plugin Version' value,
40
+ * as defined above in the plugin header
41
+ *
42
+ * @since 2.0
43
+ * @var string A PHP-standardized version number string
44
+ */
45
+ define( 'CODE_SNIPPETS_VERSION', '2.0' );
46
+
47
+ /**
48
+ * The full path to the main file of this plugin
49
+ *
50
+ * This can later be passed to functions such as
51
+ * plugin_dir_path(), plugins_url() and plugin_basename()
52
+ * to retrieve information about plugin paths
53
+ *
54
+ * @since 2.0
55
+ * @var string
56
+ */
57
+ define( 'CODE_SNIPPETS_FILE', __FILE__ );
58
+
59
+ /**
60
+ * Load plugin files
61
+ */
62
+ foreach ( array(
63
+
64
+ /* Database operations functions */
65
+ 'db.php',
66
+
67
+ /* Capability functions */
68
+ 'caps.php',
69
+
70
+ /* Snippet operations functions */
71
+ 'snippet-ops.php',
72
+
73
+ /* Upgrade function */
74
+ 'upgrade.php',
75
+
76
+ /* General Administration functions */
77
+ 'admin.php',
78
+
79
+ /* CodeMirror editor functions */
80
+ 'editor.php',
81
+
82
+ /* Manage snippets component */
83
+ 'manage/manage.php',
84
+
85
+ /* Edit snippet component */
86
+ 'edit/edit.php',
87
+
88
+ /* Import snippets component */
89
+ 'import/import.php',
90
+
91
+ /* Settings component */
92
+ 'settings/editor-preview.php',
93
+ 'settings/settings-fields.php',
94
+ 'settings/settings.php',
95
+ 'settings/admin.php',
96
+
97
+ ) as $include ) {
98
+
99
+ require plugin_dir_path( __FILE__ ) . "includes/$include";
100
+ }
101
+
102
+ /* Initialize database table variables */
103
+ set_snippet_table_vars();
104
+
105
+ /* Execute the snippets once the plugins are loaded */
106
+ add_action( 'plugins_loaded', 'execute_active_snippets', 1 );
107
+
108
+ /**
109
+ * Load up the localization file if we're using WordPress in a different language.
110
+ * Place it in this plugin's "languages" folder and name it "code-snippets-[value in wp-config].mo"
111
+ *
112
+ * If you wish to contribute a language file to be included in the Code Snippets package,
113
+ * please see create an issue on GitHub: https://github.com/bungeshea/code-snippets/issues
114
+ */
115
+ function code_snippets_load_textdomain() {
116
+ load_plugin_textdomain( 'code-snippets', false, dirname( basename( __FILE__ ) ) . '/languages/' );
117
+ }
118
+
119
+ add_action( 'plugins_loaded', 'code_snippets_load_textdomain' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
css/build/edit-snippet.css ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Custom styling for the single snippet admin page
3
+ */
4
+
5
+ h3 {
6
+ /* Provide some decent space between the fields and titles */
7
+ margin: 1em 0;
8
+ }
9
+
10
+ label {
11
+ /* What's with the pointer mouse on labels? */
12
+ cursor: auto;
13
+ }
14
+
15
+ /* Position the description heading on the same level as the editor buttons */
16
+
17
+ label[for='snippet_description'] h3 div {
18
+ position: absolute;
19
+ }
20
+
21
+ /* Add spacing in between the action buttons */
22
+
23
+ .submit .button {
24
+ margin-right: 0.5em;
25
+ }
26
+
27
+ /**
28
+ * Customize the CodeMirror editor
29
+ * to look nice and support auto-resizing
30
+ */
31
+
32
+ .CodeMirror {
33
+ width: 100%;
34
+ height: auto;
35
+ min-height: 300px;
36
+ border: 1px solid #dfdfdf;
37
+ border-radius: 3px;
38
+ background-color: white;
39
+ }
40
+
41
+ .CodeMirror-scroll {
42
+ overflow-x: auto;
43
+ overflow-y: hidden;
44
+ }
45
+
46
+ .CodeMirror-sizer {
47
+ min-height: 300px !important;
48
+ }
49
+
50
+ .CodeMirror-focused .cm-matchhighlight {
51
+ color: white !important;
52
+ outline: 1px solid green;
53
+ }
css/build/manage-snippets.css ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Custom styling for the snippets table
3
+ */
4
+
5
+ .snippets th,
6
+ .snippets td {
7
+ color: black;
8
+ }
9
+
10
+ .snippets tr {
11
+ background: white;
12
+ }
13
+
14
+ .snippets .row-actions {
15
+ color: #dddddd;
16
+ }
17
+
18
+ .snippets .clear-filters {
19
+ vertical-align: middle;
20
+ }
21
+
22
+ .snippets tfoot th {
23
+ border-top: none !important;
24
+ }
25
+
26
+ .snippets tfoot th.check-column {
27
+ padding: 13px 0 0 3px;
28
+ }
29
+
30
+ .snippets thead th.check-column,
31
+ .snippets tfoot th.check-column,
32
+ .snippets .inactive th.check-column {
33
+ padding-left: 5px;
34
+ }
35
+
36
+ .snippets .column-description p {
37
+ color: #333333;
38
+ }
39
+
40
+ .snippets .inactive a {
41
+ color: #557799;
42
+ }
43
+
44
+ .snippets .inactive td,
45
+ .snippets .inactive th,
46
+ .snippets .active td,
47
+ .snippets .active th {
48
+ padding: 10px 9px;
49
+ border: none;
50
+ -webkit-box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.1);
51
+ box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.1);
52
+ }
53
+
54
+ .snippets .active td,
55
+ .snippets .active th {
56
+ background-color: rgba(120, 200, 230, 0.06);
57
+ }
58
+
59
+ .snippets .active th.check-column {
60
+ border-left: 2px solid #2ea2cc;
61
+ }
62
+
63
+ .snippets tr.active + tr.inactive th,
64
+ .snippets tr.active + tr.inactive td {
65
+ border-top: 1px solid rgba(0, 0, 0, 0.03);
66
+ -webkit-box-shadow: inset 0px 1px 0 rgba(0, 0, 0, 0.02), inset 0 -1px 0 #e1e1e1;
67
+ box-shadow: inset 0px 1px 0 rgba(0, 0, 0, 0.02), inset 0 -1px 0 #e1e1e1;
68
+ }
69
+
70
+ .snippets a.delete:hover,
71
+ .snippets #all-snippets-table a.delete:hover,
72
+ .snippets #search-snippets-table a.delete:hover {
73
+ border-bottom: 1px solid red;
74
+ color: red;
75
+ }
76
+
77
+ #wpbody-content .snippets .column-name {
78
+ white-space: nowrap;
79
+ /* prevents wrapping of snippet title */
80
+ }
css/build/menu-icon.css ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Add the snippets icon to the admin menu
3
+ */
4
+
5
+ @font-face {
6
+ font-family: 'code-snippets';
7
+ src: url('../font/code-snippets.eot');
8
+ src: url('../font/code-snippets.eot?#iefix') format('embedded-opentype'), url('../font/code-snippets.ttf') format('truetype'), url('../font/code-snippets.woff') format('woff'), url('../font/code-snippets.svg#code-snippets') format('svg');
9
+ font-weight: normal;
10
+ font-style: normal;
11
+ }
12
+
13
+ #toplevel_page_snippets div.wp-menu-image:before {
14
+ font-family: 'code-snippets' !important;
15
+ content: '\e600';
16
+ }
css/edit-snippet.scss ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Custom styling for the single snippet admin page
3
+ */
4
+
5
+ h3 {
6
+ /* Provide some decent space between the fields and titles */
7
+ margin: 1em 0;
8
+ }
9
+
10
+ label {
11
+ /* What's with the pointer mouse on labels? */
12
+ cursor: auto;
13
+ }
14
+
15
+ /* Position the description heading on the same level as the editor buttons */
16
+ label[for='snippet_description'] h3 div {
17
+ position: absolute;
18
+ }
19
+
20
+ /* Add spacing in between the action buttons */
21
+ .submit .button {
22
+ margin-right: .5em;
23
+ }
24
+
25
+ /**
26
+ * Customize the CodeMirror editor
27
+ * to look nice and support auto-resizing
28
+ */
29
+ .CodeMirror {
30
+ width: 100%;
31
+ height: auto;
32
+ min-height: 300px;
33
+
34
+ border: 1px solid #dfdfdf;
35
+ border-radius: 3px;
36
+ background-color: #fff;;
37
+ }
38
+
39
+ .CodeMirror-scroll {
40
+ overflow-x: auto;
41
+ overflow-y: hidden;
42
+ }
43
+
44
+ .CodeMirror-sizer {
45
+ min-height: 300px !important;
46
+ }
47
+
48
+ .CodeMirror-focused .cm-matchhighlight {
49
+ color: white !important;
50
+ outline: 1px solid green;
51
+ }
css/font/code-snippets.eot ADDED
Binary file
css/font/code-snippets.svg ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ <?xml version="1.0" standalone="no"?>
2
+ <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
3
+ <svg xmlns="http://www.w3.org/2000/svg">
4
+ <metadata>Generated by IcoMoon</metadata>
5
+ <defs>
6
+ <font id="code-snippets" horiz-adv-x="1024">
7
+ <font-face units-per-em="1024" ascent="960" descent="-64" />
8
+ <missing-glyph horiz-adv-x="1024" />
9
+ <glyph unicode="&#x20;" d="" horiz-adv-x="512" />
10
+ <glyph unicode="&#xe600;" d="M191.968 495.776h158.912c23.68 0 42.656-19.2 42.656-42.656 0-11.488-4.48-21.984-11.968-29.632l0.192-0.448-108.768-108.736c-75.104-75.136-75.104-196.512 0-271.584 74.88-74.848 196.448-74.848 271.552 0 74.88 75.104 74.88 196.48 0 271.584-21.76 21.504-47.36 37.12-74.464 46.272l28.608 28.576h365.248c87.040 0 157.856 74.016 159.968 166.4 0 1.472 0.224 2.752 0 4.256-2.112 23.904-22.368 42.656-46.912 42.656h-264.96l191.328 191.328c17.504 17.504 18.56 45.024 3.2 63.36-1.024 1.28-2.080 2.144-3.2 3.2-66.528 63.552-169.152 65.92-230.56 4.48l-262.368-262.368h-46.528c12.8 25.6 20.032 54.624 20.032 85.344 0 106.016-85.952 192-192 192-106.016 0-191.968-85.984-191.968-192 0.032-106.080 85.984-192.032 192-192.032zM277.312 687.744c0-47.136-38.176-85.344-85.344-85.344-47.136 0-85.312 38.176-85.312 85.344s38.176 85.344 85.312 85.344c47.168 0 85.344-38.208 85.344-85.344zM469.088 238.688c33.28-33.248 33.28-87.264 0-120.512-33.28-33.472-87.264-33.472-120.736 0-33.28 33.248-33.28 87.264 0 120.512 33.472 33.504 87.456 33.504 120.736 0z" />
11
+ </font></defs></svg>
css/font/code-snippets.ttf ADDED
Binary file
css/font/code-snippets.woff ADDED
Binary file
css/manage-snippets.scss ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Custom styling for the snippets table
3
+ */
4
+
5
+ .snippets {
6
+
7
+ th, td {
8
+ color: #000;
9
+ }
10
+
11
+ tr {
12
+ background: #fff;
13
+ }
14
+
15
+ .row-actions {
16
+ color: #ddd;
17
+ }
18
+
19
+ .clear-filters {
20
+ vertical-align: middle;
21
+ }
22
+
23
+ tfoot th {
24
+ border-top: none !important;
25
+
26
+ &.check-column {
27
+ padding: 13px 0 0 3px;
28
+ }
29
+ }
30
+
31
+ thead th.check-column,
32
+ tfoot th.check-column,
33
+ .inactive th.check-column {
34
+ padding-left: 5px;
35
+ }
36
+
37
+ .column-description p {
38
+ color: #333;
39
+ }
40
+
41
+ .inactive {
42
+
43
+ a {
44
+ color: #579;
45
+ }
46
+ }
47
+
48
+ .inactive, .active {
49
+ td, th {
50
+ padding: 10px 9px;
51
+ border: none;
52
+ box-shadow: inset 0 -1px 0 rgba(0,0,0,0.1);
53
+ }
54
+ }
55
+
56
+ .active {
57
+
58
+ td, th {
59
+ background-color: rgba(120,200,230,0.06);
60
+ }
61
+
62
+ th.check-column {
63
+ border-left: 2px solid #2ea2cc;
64
+ }
65
+
66
+ }
67
+
68
+ tr.active + tr.inactive th,
69
+ tr.active + tr.inactive td {
70
+ border-top: 1px solid rgba(0,0,0,0.03);
71
+ box-shadow: inset 0px 1px 0 rgba(0,0,0,0.02), inset 0 -1px 0 #e1e1e1;
72
+ }
73
+
74
+ &, #all-snippets-table, #search-snippets-table {
75
+ a.delete:hover {
76
+ border-bottom: 1px solid #f00;
77
+ color: #f00;
78
+ }
79
+ }
80
+
81
+ #wpbody-content & .column-name {
82
+ white-space: nowrap; /* prevents wrapping of snippet title */
83
+ }
84
+ }
css/menu-icon.scss ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Add the snippets icon to the admin menu
3
+ */
4
+
5
+ @font-face {
6
+ font-family: 'code-snippets';
7
+ src: url('../font/code-snippets.eot');
8
+ src: url('../font/code-snippets.eot?#iefix') format('embedded-opentype'),
9
+ url('../font/code-snippets.ttf') format('truetype'),
10
+ url('../font/code-snippets.woff') format('woff'),
11
+ url('../font/code-snippets.svg#code-snippets') format('svg');
12
+ font-weight: normal;
13
+ font-style: normal;
14
+ }
15
+
16
+ #toplevel_page_snippets div.wp-menu-image:before {
17
+ font-family: 'code-snippets' !important;
18
+ content: '\e600';
19
+ }
css/min/edit-snippet.css ADDED
@@ -0,0 +1 @@
 
1
+ h3{margin:1em 0}label{cursor:auto}label[for='snippet_description'] h3 div{position:absolute}.submit .button{margin-right:.5em}.CodeMirror{width:100%;height:auto;min-height:300px;border:1px solid #dfdfdf;border-radius:3px;background-color:#fff}.CodeMirror-scroll{overflow-x:auto;overflow-y:hidden}.CodeMirror-sizer{min-height:300px!important}.CodeMirror-focused .cm-matchhighlight{color:#fff!important;outline:1px solid green}
css/min/manage-snippets.css ADDED
@@ -0,0 +1 @@
 
1
+ .snippets th,.snippets td{color:#000}.snippets tr{background:#fff}.snippets .row-actions{color:#ddd}.snippets .clear-filters{vertical-align:middle}.snippets tfoot th{border-top:none!important}.snippets tfoot th.check-column{padding:13px 0 0 3px}.snippets thead th.check-column,.snippets tfoot th.check-column,.snippets .inactive th.check-column{padding-left:5px}.snippets .column-description p{color:#333}.snippets .inactive a{color:#579}.snippets .inactive td,.snippets .inactive th,.snippets .active td,.snippets .active th{padding:10px 9px;border:none;-webkit-box-shadow:inset 0 -1px 0 rgba(0,0,0,.1);box-shadow:inset 0 -1px 0 rgba(0,0,0,.1)}.snippets .active td,.snippets .active th{background-color:rgba(120,200,230,.06)}.snippets .active th.check-column{border-left:2px solid #2ea2cc}.snippets tr.active+tr.inactive th,.snippets tr.active+tr.inactive td{border-top:1px solid rgba(0,0,0,.03);-webkit-box-shadow:inset 0 1px 0 rgba(0,0,0,.02),inset 0 -1px 0 #e1e1e1;box-shadow:inset 0 1px 0 rgba(0,0,0,.02),inset 0 -1px 0 #e1e1e1}.snippets a.delete:hover,.snippets #all-snippets-table a.delete:hover,.snippets #search-snippets-table a.delete:hover{border-bottom:1px solid red;color:red}#wpbody-content .snippets .column-name{white-space:nowrap}
css/min/menu-icon.css ADDED
@@ -0,0 +1 @@
 
1
+ @font-face{font-family:'code-snippets';src:url('../font/code-snippets.eot');src:url('../font/code-snippets.eot?#iefix') format('embedded-opentype'),url('../font/code-snippets.ttf') format('truetype'),url('../font/code-snippets.woff') format('woff'),url('../font/code-snippets.svg#code-snippets') format('svg');font-weight:400;font-style:normal}#toplevel_page_snippets div.wp-menu-image:before{font-family:'code-snippets'!important;content:'\e600'}
includes/admin.php ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Load the functions for handling the administration interface
5
+ *
6
+ * @package Code_Snippets
7
+ * @subpackage Administration
8
+ */
9
+
10
+ /* Bail if not in admin area */
11
+ if ( ! is_admin() ) {
12
+ return;
13
+ }
14
+
15
+ /**
16
+ * Fetch the admin menu slug for a snippets menu
17
+ * @param string $menu The menu to retrieve the slug for
18
+ * @return string The menu's slug
19
+ */
20
+ function code_snippets_get_menu_slug( $menu = '' ) {
21
+ $add = array( 'single', 'add', 'add-new', 'add-snippet', 'new-snippet', 'add-new-snippet' );
22
+ $edit = array( 'edit', 'edit-snippet' );
23
+ $import = array( 'import', 'import-snippets' );
24
+ $settings = array( 'settings', 'snippets-settings' );
25
+
26
+ if ( in_array( $menu, $edit ) ) {
27
+ return 'edit-snippet';
28
+ } elseif ( in_array( $menu, $add ) ) {
29
+ return 'add-snippet';
30
+ } elseif ( in_array( $menu, $import ) ) {
31
+ return 'import-snippets';
32
+ } elseif ( in_array( $menu, $settings ) ) {
33
+ return 'snippets-settings';
34
+ } else {
35
+ return 'snippets';
36
+ }
37
+ }
38
+
39
+ /**
40
+ * Fetch the URL to a snippets admin menu
41
+ * @param string $menu The menu to retrieve the URL to
42
+ * @return string The menu's URL
43
+ */
44
+ function code_snippets_get_menu_url( $menu = '', $context = 'self' ) {
45
+ $slug = code_snippets_get_menu_slug( $menu );
46
+ $url = 'admin.php?page=' . $slug;
47
+
48
+ if ( 'network' === $context ) {
49
+ return network_admin_url( $url );
50
+ } elseif ( 'admin' === $context ) {
51
+ return admin_url( $url );
52
+ } else {
53
+ return self_admin_url( $url );
54
+ }
55
+ }
56
+
57
+ /**
58
+ * Fetch the admin menu hook for a snippets menu
59
+ * @param string $menu The menu to retrieve the hook for
60
+ * @return string The menu's hook
61
+ */
62
+ function code_snippets_get_menu_hook( $menu = '' ) {
63
+ $slug = code_snippets_get_menu_slug( $menu );
64
+ return get_plugin_page_hookname( $slug, 'snippets' );
65
+ }
66
+
67
+ /**
68
+ * Allow super admins to control site admin access to
69
+ * snippet admin menus
70
+ *
71
+ * Adds a checkbox to the *Settings > Network Settings*
72
+ * network admin menu
73
+ *
74
+ * @since 1.7.1
75
+ * @access private
76
+ *
77
+ * @param array $menu_items The current mu menu items
78
+ * @return array The modified mu menu items
79
+ */
80
+ function code_snippets_mu_menu_items( $menu_items ) {
81
+ $menu_items['snippets'] = __( 'Snippets', 'code-snippets' );
82
+ return $menu_items;
83
+ }
84
+
85
+ add_filter( 'mu_menu_items', 'code_snippets_mu_menu_items' );
86
+
87
+ /**
88
+ * Enqueue the icon stylesheet globally in the admin
89
+ *
90
+ * @since 1.0
91
+ * @access private
92
+ * @uses wp_enqueue_style() To add the stylesheet to the queue
93
+ * @uses get_user_option() To check if MP6 mode is active
94
+ * @uses plugins_url() To retrieve a URL to assets
95
+ */
96
+ function code_snippets_load_admin_icon_style() {
97
+
98
+ wp_enqueue_style(
99
+ 'menu-icon-snippets',
100
+ plugins_url( 'css/min/menu-icon.css', CODE_SNIPPETS_FILE ),
101
+ false,
102
+ CODE_SNIPPETS_VERSION
103
+ );
104
+ }
105
+
106
+ add_action( 'admin_enqueue_scripts', 'code_snippets_load_admin_icon_style' );
107
+
108
+ /**
109
+ * Adds a link pointing to the Manage Snippets page
110
+ *
111
+ * @since 2.0
112
+ * @access private
113
+ * @param array $links The existing plugin action links
114
+ * @return array The modified plugin action links
115
+ */
116
+ function code_snippets_plugin_settings_link( $links ) {
117
+ array_unshift( $links, sprintf(
118
+ '<a href="%1$s" title="%2$s">%3$s</a>',
119
+ code_snippets_get_menu_url(),
120
+ __( 'Manage your existing snippets', 'code-snippets' ),
121
+ __( 'Manage', 'code-snippets' )
122
+ ) );
123
+ return $links;
124
+ }
125
+
126
+ add_filter( 'plugin_action_links_' . plugin_basename( CODE_SNIPPETS_FILE ), 'code_snippets_plugin_settings_link' );
127
+
128
+ /**
129
+ * Adds extra links related to the plugin
130
+ *
131
+ * @since 2.0
132
+ * @access private
133
+ * @param array $links The existing plugin info links
134
+ * @param string $file The plugin the links are for
135
+ * @return array The modified plugin info links
136
+ */
137
+ function code_snippets_plugin_meta( $links, $file ) {
138
+
139
+ /* We only want to affect the Code Snippets plugin listing */
140
+ if ( $file !== plugin_basename( CODE_SNIPPETS_FILE ) ) {
141
+ return $links;
142
+ }
143
+
144
+ $format = '<a href="%1$s" title="%2$s">%3$s</a>';
145
+
146
+ /* array_merge appends the links to the end */
147
+ return array_merge( $links, array(
148
+ sprintf( $format,
149
+ 'http://wordpress.org/plugins/code-snippets/',
150
+ __( 'Visit the WordPress.org plugin page', 'code-snippets' ),
151
+ __( 'About', 'code-snippets' )
152
+ ),
153
+ sprintf( $format,
154
+ 'http://wordpress.org/support/plugin/code-snippets/',
155
+ __( 'Visit the support forums', 'code-snippets' ),
156
+ __( 'Support', 'code-snippets' )
157
+ ),
158
+ sprintf( $format,
159
+ 'http://code-snippets.bungeshea.com/donate/',
160
+ __("Support this plugin's development", 'code-snippets' ),
161
+ __( 'Donate', 'code-snippets' )
162
+ )
163
+ ) );
164
+ }
165
+
166
+ add_filter( 'plugin_row_meta', 'code_snippets_plugin_meta', 10, 2 );
167
+
168
+ /**
169
+ * Print a notice inviting people to participate in the Code Snippets Survey
170
+ *
171
+ * @since 1.9
172
+ * @return void
173
+ */
174
+ function code_snippets_survey_message() {
175
+ global $current_user;
176
+
177
+ $key = 'ignore_code_snippets_survey_message';
178
+
179
+ /* Bail now if the user has dismissed the message */
180
+ if ( get_user_meta( $current_user->ID, $key ) ) {
181
+ return;
182
+ }
183
+ elseif ( isset( $_GET[ $key ], $_REQUEST['_wpnonce'] ) && wp_verify_nonce( $_REQUEST['_wpnonce'], $key ) ) {
184
+ add_user_meta( $current_user->ID, $key, true, true );
185
+ return;
186
+ }
187
+
188
+ ?>
189
+
190
+ <br />
191
+
192
+ <div class="updated"><p>
193
+
194
+ <?php _e( "<strong>Have feedback on Code Snippets?</strong> Please take the time to answer a short survey on how you use this plugin and what you'd like to see changed or added in the future.", 'code-snippets' ); ?>
195
+
196
+ <a href="http://code-snippets.bungeshea.com/survey/" class="button secondary" target="_blank" style="margin: auto .5em;">
197
+ <?php _e( 'Take the survey now', 'code-snippets' ); ?>
198
+ </a>
199
+
200
+ <a href="<?php echo wp_nonce_url( add_query_arg( $key, true ), $key ); ?>">Dismiss</a>
201
+
202
+ </p></div>
203
+
204
+ <?php
205
+ }
206
+
207
+ add_action( 'code_snippets/admin/manage', 'code_snippets_survey_message' );
208
+
209
+ /**
210
+ * Remove the old CodeMirror version used by the Debug Bar Console
211
+ * plugin that is messing up the snippet editor
212
+ * @since 1.9
213
+ */
214
+ function code_snippets_remove_debug_bar_codemirror() {
215
+ global $pagenow;
216
+
217
+ /* Try to discern if we are on the single snippet page as best as we can at this early time */
218
+ is_admin() && 'admin.php' === $pagenow && isset( $_GET['page' ] ) && 'snippet' === $_GET['page']
219
+
220
+ /* Remove the action and stop all Debug Bar Console scripts */
221
+ && remove_action( 'debug_bar_enqueue_scripts', 'debug_bar_console_scripts' );
222
+ }
223
+
224
+ add_action( 'init', 'code_snippets_remove_debug_bar_codemirror' );
includes/caps.php ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Get the required capability to perform a certain action on snippets.
5
+ * Does not check if the user has this capability or not.
6
+ *
7
+ * If multisite, checks if *Enable Administration Menus: Snippets* is active
8
+ * under the *Settings > Network Settings* network admin menu
9
+ *
10
+ * @since 2.0
11
+ * @return string The capability required to manage snippets
12
+ */
13
+ function get_snippets_cap() {
14
+
15
+ if ( is_multisite() ) {
16
+ $menu_perms = get_site_option( 'menu_items', array() );
17
+
18
+ /* If multisite is enabled and the snippet menu is not activated,
19
+ restrict snippet operations to super admins only */
20
+ if ( empty( $menu_perms['snippets'] ) ) {
21
+ return apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' );
22
+ }
23
+ }
24
+
25
+ return apply_filters( 'code_snippets_cap', 'manage_snippets' );
26
+ }
27
+
28
+ /**
29
+ * Add the multisite capabilities to a user
30
+ *
31
+ * @since 2.0
32
+ * @param integer $user_id The ID of the user to add the cap to
33
+ */
34
+ function grant_network_snippets_cap( $user_id ) {
35
+
36
+ /* Get the user from the ID */
37
+ $user = new WP_User( $user_id );
38
+
39
+ /* Add the capability */
40
+ $user->add_cap( apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' ) );
41
+ }
42
+
43
+ add_action( 'grant_super_admin', 'grant_network_snippets_cap' );
44
+
45
+ /**
46
+ * Remove the multisite capabilities from a user
47
+ *
48
+ * @since 2.0
49
+ * @param integer $user_id The ID of the user to remove the cap from
50
+ */
51
+ function remove_network_snippets_cap( $user_id ) {
52
+
53
+ /* Get the user from the ID */
54
+ $user = new WP_User( $user_id );
55
+
56
+ /* Remove the capability */
57
+ $user->remove_cap( apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' ) );
58
+ }
59
+
60
+ add_action( 'remove_super_admin', 'remove_network_snippets_cap' );
includes/class-export.php CHANGED
@@ -1,190 +1,254 @@
1
- <?php
2
-
3
- /**
4
- * This file handles exporting snippets in XML format
5
- *
6
- * It's better to call the $code_snippets->export_php()
7
- * method than directly using this class
8
- *
9
- * @since 1.9
10
- * @package Code_Snippets
11
- * @subpackage Export
12
- */
13
-
14
- if ( ! class_exists( 'Code_Snippets_Export' ) ) :
15
-
16
- /**
17
- * Exports selected snippets to a XML or PHP file.
18
- *
19
- * @since 1.3
20
- * @param array $ids The IDs of the snippets to export
21
- * @param string $format The format of the export file
22
- * @return void
23
- */
24
- class Code_Snippets_Export {
25
-
26
- /**
27
- * The IDs
28
- * @var array
29
- */
30
- public $snippet_ids = array();
31
-
32
- /**
33
- * The name of the table to fetch snippets from
34
- * @var string
35
- */
36
- protected $table_name = '';
37
-
38
- /**
39
- * Constructor function
40
- * @param array $ids The IDs of the snippets to export
41
- * @param string $table The name of the table to fetch snippets from
42
- */
43
- function __construct( $ids, $table ) {
44
- $this->snippet_ids = (array) $ids;
45
- $this->table_name = $table;
46
- $this->exclude_fields = apply_filters( 'code_snippets/export/exclude_from_export', array( 'id', 'active' ) );
47
- }
48
-
49
- /**
50
- * Build the export file name
51
- * @return string
52
- */
53
- function get_filename() {
54
- global $code_snippets;
55
-
56
- if ( 1 == count( $this->snippet_ids ) ) {
57
- /* If there is only snippet to export, use its name instead of the site name */
58
- $snippet = $code_snippets->get_snippet( $this->snippet_ids[0] );
59
- $sitename = strtolower( $snippet->name );
60
- } else {
61
- /* Otherwise, use the site name as set in Settings > General */
62
- $sitename = strtolower( get_bloginfo( 'name' ) );
63
- }
64
-
65
- /* Filter and sanitize the filename */
66
- $filename = sanitize_file_name( apply_filters(
67
- 'code_snippets/export/filename',
68
- "{$sitename}.code-snippets.xml",
69
- $sitename
70
- ) );
71
-
72
- return $filename;
73
- }
74
-
75
- /**
76
- * Set HTTP headers and render the file header
77
- */
78
- protected function do_header() {
79
- global $code_snippets;
80
- header( 'Content-Type: text/xml; charset=' . get_bloginfo('charset') );
81
-
82
- echo '<?xml version="1.0" encoding="' . get_bloginfo('charset') . "\" ?>\n";
83
-
84
- ?>
85
- <!-- This is a code snippets export file generated by the Code Snippets WordPress plugin. -->
86
- <!-- http://wordpress.org/plugins/code-snippets -->
87
-
88
- <!-- To import these snippets a WordPress site follow these steps: -->
89
- <!-- 1. Log in to that site as an administrator. -->
90
- <!-- 2. Install the Code Snippets plugin using the directions provided at the above link. -->
91
- <!-- 3. Go to 'Tools: Import' in the WordPress admin panel. -->
92
- <!-- 4. Click on the "Code Snippets" importer in the list -->
93
- <!-- 5. Upload this file using the form provided on that page. -->
94
- <!-- 6. Code Snippets will then import all of the snippets and associated information -->
95
- <!-- contained in this file into your site. -->
96
- <!-- 7. You will then have to visit the 'Snippets: Manage' admin menu and activate desired snippets -->
97
-
98
- <?php
99
-
100
- /* Run the generator line through the standard WordPress filter */
101
- $gen = sprintf (
102
- '<!-- generator="Code Snippets/%s" created="%s" -->',
103
- $code_snippets->version,
104
- date('Y-m-d H:i')
105
- );
106
- $type = 'code_snippets_export';
107
- echo apply_filters( "get_the_generator_$type", $gen, $type );
108
-
109
- /* Begin the file */
110
- echo '<snippets>';
111
-
112
- }
113
-
114
- /**
115
- * Render the items
116
- */
117
- protected function do_items() {
118
- global $wpdb;
119
-
120
- /* Loop through the snippets */
121
-
122
- foreach ( $this->snippet_ids as $id ) {
123
-
124
- /* Grab the snippet from the database */
125
- $snippet = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$this->table_name} WHERE id = %d", $id ), ARRAY_A );
126
-
127
- /* Remove slashes */
128
- $snippet = stripslashes_deep( $snippet );
129
-
130
- /* Output the item */
131
- $this->do_item( $snippet );
132
- do_action( 'code_snippets/export/after_snippet', $id, $this->get_filename() );
133
- }
134
- }
135
-
136
- /**
137
- * Render a single item
138
- * @param array $snippet
139
- */
140
- protected function do_item( $snippet ) {
141
- echo "\n\t" . '<snippet>';
142
-
143
- foreach ( $snippet as $field => $value ) {
144
-
145
- /* Don't export certain fields */
146
- if ( in_array( $field, $this->exclude_fields ) )
147
- continue;
148
-
149
- /* Output the field and value as indented XML */
150
- if ( $value = apply_filters( "code_snippets/export/$field", $value ) ) {
151
- $value = htmlspecialchars( $value );
152
- echo "\n\t\t<$field>$value</$field>";
153
- }
154
- }
155
- echo "\n\t" . '</snippet>';
156
- }
157
-
158
- /**
159
- * Render the file footer
160
- */
161
- protected function do_footer() {
162
- echo "\n</snippets>";
163
- }
164
-
165
- /**
166
- * Export the snippets
167
- */
168
- public function do_export() {
169
-
170
- /* HTTP header */
171
- $filename = $this->get_filename();
172
- header( 'Content-Disposition: attachment; filename=' . $filename );
173
-
174
- /* File header */
175
- $this->do_header();
176
- do_action( 'code_snippets/export/after_header', $this->snippet_ids, $filename );
177
-
178
- /* Items */
179
- $this->do_items();
180
- do_action( 'code_snippets/export/after_snippets', $this->snippet_ids, $filename );
181
-
182
- /* Footer */
183
- $this->do_footer();
184
- do_action( 'code_snippets/export/after_footer', $this->snippet_ids, $filename );
185
-
186
- exit;
187
- }
188
- }
189
-
190
- endif; // function exists check
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * This file handles exporting snippets in XML format
5
+ *
6
+ * It's better to call the export_snippets()
7
+ * function than directly using this class
8
+ *
9
+ * @since 1.9
10
+ * @package Code_Snippets
11
+ * @subpackage Export
12
+ */
13
+
14
+ if ( ! class_exists( 'Code_Snippets_Export' ) ) :
15
+
16
+ /**
17
+ * Exports selected snippets to a XML or PHP file.
18
+ *
19
+ * @since 1.3
20
+ * @param array $ids The IDs of the snippets to export
21
+ * @param string $format The format of the export file
22
+ * @return void
23
+ */
24
+ class Code_Snippets_Export {
25
+
26
+ /**
27
+ * The IDs
28
+ * @var array
29
+ */
30
+ public $snippet_ids = array();
31
+
32
+ /**
33
+ * The name of the table to fetch snippets from
34
+ * @var string
35
+ */
36
+ protected $table_name = '';
37
+
38
+ /**
39
+ * The export file format.
40
+ * Either 'xml' or 'php'
41
+ * @var object
42
+ */
43
+ public $format;
44
+
45
+ /**
46
+ * The DOM document.
47
+ * Only used in XML exports
48
+ * @var object
49
+ */
50
+ public $dom;
51
+
52
+ /**
53
+ * The DOM document root element
54
+ * Only used in XML exports
55
+ * @var object
56
+ */
57
+ public $root;
58
+
59
+ /**
60
+ * Constructor function
61
+ * @param array $ids The IDs of the snippets to export
62
+ * @param string $table The name of the table to fetch snippets from
63
+ * @param string $format The format of the export file
64
+ */
65
+ function __construct( $ids, $table, $format = 'xml' ) {
66
+ $this->snippet_ids = (array) $ids;
67
+ $this->table_name = $table;
68
+ $this->format = 'php' === $format ? 'php' : 'xml';
69
+ $this->exclude_fields = apply_filters( 'code_snippets/export/exclude_from_export', array( 'id', 'active' ) );
70
+ }
71
+
72
+ /**
73
+ * Build the export file name
74
+ * @return string
75
+ */
76
+ function get_filename() {
77
+
78
+ if ( 1 == count( $this->snippet_ids ) ) {
79
+ /* If there is only snippet to export, use its name instead of the site name */
80
+ $snippet = get_snippet( $this->snippet_ids[0], $this->table_name );
81
+ $sitename = strtolower( $snippet->name );
82
+ } else {
83
+ /* Otherwise, use the site name as set in Settings > General */
84
+ $sitename = strtolower( get_bloginfo( 'name' ) );
85
+ }
86
+
87
+ /* Filter and sanitize the filename */
88
+ $filename = sanitize_file_name( apply_filters(
89
+ 'code_snippets/export/filename',
90
+ "{$sitename}.code-snippets.{$this->format}",
91
+ $sitename
92
+ ) );
93
+
94
+ return $filename;
95
+ }
96
+
97
+ /**
98
+ * Append header comments to the DOM document
99
+ */
100
+ protected function do_header_comments() {
101
+
102
+ /* Array of translated comment lines */
103
+ $lines = array(
104
+ __( 'This is a code snippets export file generated by the Code Snippets WordPress plugin.', 'code-snippets' ),
105
+ __( 'http://wordpress.org/plugins/code-snippets', 'code-snippets' ),
106
+ __( 'To import these snippets a WordPress site follow these steps:', 'code-snippets' ),
107
+ __( '1. Log in to that site as an administrator.', 'code-snippets' ),
108
+ __( '2. Install the Code Snippets plugin using the directions provided at the above link.', 'code-snippets' ),
109
+ __( "3. Go to 'Tools: Import' in the WordPress admin panel.", 'code-snippets' ),
110
+ __( '4. Click on the "Code Snippets" importer in the list', 'code-snippets' ),
111
+ __( '5. Upload this file using the form provided on that page.', 'code-snippets' ),
112
+ __( '6. Code Snippets will then import all of the snippets and associated information contained in this file into your site.', 'code-snippets' ),
113
+ __( "7. You will then have to visit the 'Snippets: Manage' admin menu and activate desired snippets.", 'code-snippets' ),
114
+ );
115
+
116
+ /* Add each line as a comment element */
117
+ foreach ( $lines as $line ) {
118
+ $comment = $this->dom->createComment( " $line " );
119
+ $this->dom->appendChild( $comment );
120
+ }
121
+
122
+ /* Build a generator line, like the WordPress export files */
123
+ $gen = sprintf (
124
+ 'generator="Code Snippets/%s" created="%s"',
125
+ CODE_SNIPPETS_VERSION,
126
+ date('Y-m-d H:i')
127
+ );
128
+
129
+ /* Run the generator line through the standard WordPress filter */
130
+ $type = 'code_snippets_export';
131
+ $gen = apply_filters( "get_the_generator_$type", $gen, $type );
132
+
133
+ /* Add it to the file as a comment */
134
+ $gen = $this->dom->createComment( " $gen " );
135
+ $this->dom->appendChild( $gen );
136
+ }
137
+
138
+
139
+
140
+ /**
141
+ * Process all snippet items
142
+ */
143
+ protected function do_items() {
144
+ global $wpdb;
145
+
146
+ if ( 'xml' === $this->format ) {
147
+
148
+ /* Create the root element */
149
+ $this->root = $this->dom->createElement( 'snippets' );
150
+ $this->root = $this->dom->appendChild( $this->root );
151
+ }
152
+
153
+ /* Loop through the snippets */
154
+ foreach ( $this->snippet_ids as $id ) {
155
+
156
+ /* Grab the snippet from the database */
157
+ $snippet = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$this->table_name} WHERE id = %d", $id ), ARRAY_A );
158
+
159
+ /* Process the snippet item */
160
+ if ( 'php' === $this->format ) {
161
+ $this->do_item_php( $snippet );
162
+ } else {
163
+ $this->do_item( $snippet );
164
+ }
165
+ }
166
+ }
167
+
168
+ /**
169
+ * Append a single snippet item to the document
170
+ * @param array $snippet
171
+ */
172
+ protected function do_item( $snippet ) {
173
+ $item = $this->dom->createElement( 'snippet' );
174
+ $item = $this->root->appendChild( $item );
175
+
176
+ foreach ( $snippet as $field_name => $field_value ) {
177
+
178
+ /* Don't export certain fields */
179
+ if ( in_array( $field_name, $this->exclude_fields ) ) {
180
+ continue;
181
+ }
182
+
183
+ /* Create a new element for each field */
184
+ $field = $this->dom->createElement( $field_name );
185
+ $field = $item->appendChild( $field );
186
+
187
+ /* Add the field's content */
188
+ $value = $this->dom->createTextNode( $field_value );
189
+ $value = $field->appendChild( $value );
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Format single snippet item as PHP code
195
+ * @param array $snippet
196
+ */
197
+ protected function do_item_php( $snippet ) {
198
+
199
+ echo "\n/**\n * {$snippet['name']}\n";
200
+
201
+ if ( ! empty( $snippet['description'] ) ) {
202
+
203
+ /* Convert description to PhpDoc */
204
+ $desc = strip_tags( str_replace( "\n", "\n * ", $snippet['description'] ) );
205
+
206
+ echo " *\n * $desc\n";
207
+ }
208
+
209
+ echo " */\n{$snippet['code']}\n";
210
+ }
211
+
212
+ /**
213
+ * Export the snippets
214
+ */
215
+ public function do_export() {
216
+
217
+ /* Make the page act like a downloadable file instead of being shown in the browser */
218
+ $filename = $this->get_filename();
219
+ header( 'Content-Disposition: attachment; filename=' . $filename );
220
+
221
+ if ( 'xml' === $this->format ) {
222
+
223
+ /* Set the HTTP content type header */
224
+ header( 'Content-Type: text/xml; charset=' . get_bloginfo( 'charset' ) );
225
+
226
+ /* Create DOM document and root element */
227
+ $this->dom = new DOMDocument( '1.0', get_bloginfo( 'charset' ) );
228
+ $this->dom->formatOutput = true;
229
+
230
+ /* Add file header comments */
231
+ $this->do_header_comments();
232
+ }
233
+
234
+ elseif ( 'php' === $this->format ) {
235
+ echo '<?php';
236
+ }
237
+
238
+ /* Process the snippet items */
239
+ $this->do_items();
240
+
241
+ if ( 'xml' === $this->format ) {
242
+
243
+ /* Filter DOM document */
244
+ apply_filters( 'code_snippets/export_dom_document', $this->dom, $this->snippet_ids, $filename );
245
+
246
+ /* Send the document to the browser */
247
+ echo $this->dom->saveXML();
248
+ }
249
+
250
+ exit;
251
+ }
252
+ }
253
+
254
+ endif; // class exists check
includes/db.php ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Functions used to manage the database tables
5
+ */
6
+
7
+ /**
8
+ * Register the snippet table names with WordPress
9
+ *
10
+ * @since 2.0
11
+ * @uses $wpdb
12
+ */
13
+ function set_snippet_table_vars() {
14
+ global $wpdb;
15
+
16
+ /* Register the snippet table names with WordPress */
17
+ $wpdb->tables[] = 'snippets';
18
+ $wpdb->ms_global_tables[] = 'ms_snippets';
19
+
20
+ /* Setup initial table variables */
21
+ $wpdb->snippets = $wpdb->prefix . 'snippets';
22
+ $wpdb->ms_snippets = $wpdb->base_prefix . 'ms_snippets';
23
+ }
24
+
25
+ /**
26
+ * Return the appropriate snippet table name
27
+ *
28
+ * @since 2.0
29
+ * @param string|boolean|null $multisite Retrieve the multisite table name or the site table name?
30
+ * @return string The snippet table name
31
+ */
32
+ function get_snippets_table_name( $multisite = null ) {
33
+ global $wpdb;
34
+
35
+ /* If $multisite is null, try to base it on the current admin page */
36
+ if ( ! isset( $multisite ) && function_exists( 'get_current_screen' ) ) {
37
+ $multisite = get_current_screen()->is_network;
38
+ }
39
+
40
+ /* If the first parameter is a string, assume it is a table name */
41
+ elseif ( is_string( $multisite ) ) {
42
+ return $multisite;
43
+ }
44
+
45
+ /* If multisite is not active, always return the site-wide table name */
46
+ if ( ! is_multisite() ) {
47
+ $multisire = false;
48
+ }
49
+
50
+ /* Retrieve the table name from $wpdb depending on the above conditionals */
51
+ return ( $multisite ? $wpdb->ms_snippets : $wpdb->snippets );
52
+ }
53
+
54
+ /**
55
+ * Create the snippet tables if they do not already exist
56
+ *
57
+ * @since 1.7.1
58
+ * @staticvar boolean $tables_created Used to check if we've already done this or not
59
+ * @param boolean $redo Skip the already-done-this check
60
+ * @param boolean $always_create_table Always create the site-wide table if it doesn't exist
61
+ */
62
+ function create_code_snippets_tables( $redo = false, $always_create_table = false ) {
63
+
64
+ /* Bail early if we've done this already */
65
+ if ( ! $redo && true === wp_cache_get( 'snippet_tables_created', 'code_snippets' ) ) {
66
+ return;
67
+ }
68
+
69
+ global $wpdb;
70
+
71
+ /* Set the table name variables if not yet defined */
72
+ if ( ! isset( $wpdb->snippets, $wpdb->ms_snippets ) ) {
73
+ set_snippets_table_vars();
74
+ }
75
+
76
+ /* Always create the network-wide snippet table */
77
+ if ( is_multisite() ) {
78
+ create_code_snippets_table( $wpdb->ms_snippets );
79
+ }
80
+
81
+ /* Create the site-specific table if we're on the main site */
82
+ if ( $always_create_table || is_main_site() ) {
83
+ create_code_snippets_table( $wpdb->snippets );
84
+ }
85
+
86
+ /* Set the flag so we don't have to do this again */
87
+ wp_cache_set( 'snippet_tables_created', true, 'code_snippets' );
88
+ }
89
+
90
+ /**
91
+ * Create a single snippet table
92
+ * if one of the same name does not already exist
93
+ *
94
+ * @since 1.6
95
+ * @access private
96
+ *
97
+ * @uses dbDelta() To add the table to the database
98
+ *
99
+ * @param string $table_name The name of the table to create
100
+ * @param boolean $force_creation Skip the table exists check
101
+ */
102
+ function create_code_snippets_table( $table_name, $force_creation = false ) {
103
+ require_once ABSPATH . 'wp-admin/includes/upgrade.php';
104
+
105
+ global $wpdb;
106
+
107
+ if ( ! $force_creation && $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->snippets'" ) === $wpdb->snippets ) {
108
+ return; // bail if the table already exists
109
+ }
110
+
111
+ /* Set the database charset */
112
+
113
+ $charset_collate = '';
114
+
115
+ if ( ! empty( $wpdb->charset ) ) {
116
+ $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
117
+ }
118
+
119
+ if ( ! empty( $wpdb->collate ) ) {
120
+ $charset_collate .= " COLLATE $wpdb->collate";
121
+ }
122
+
123
+ /* Set the snippet data columns */
124
+
125
+ $table_columns = apply_filters( 'code_snippets/database_table_columns', array(
126
+ 'name tinytext not null',
127
+ 'description text',
128
+ 'code longtext not null',
129
+ 'tags longtext',
130
+ ) );
131
+
132
+ $table_columns_sql = implode( ",\n", $table_columns ); // convert the array into SQL code
133
+
134
+ /* Create the database table */
135
+
136
+ $sql = "CREATE TABLE $table_name (
137
+ id bigint(20) unsigned not null auto_increment,
138
+ {$table_columns_sql},
139
+ active tinyint(1) not null default 0,
140
+ PRIMARY KEY (id)
141
+ ) {$charset_collate};";
142
+
143
+ dbDelta( apply_filters( 'code_snippets/table_sql', $sql ) );
144
+
145
+ do_action( 'code_snippets/create_table', $table_name );
146
+ }
includes/edit/admin-help.php ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Register and handle the help tabs for the
5
+ * single snippet admin page
6
+ *
7
+ * @package Code_Snippets
8
+ * @subpackage Contextual_Help
9
+ */
10
+
11
+ $screen = get_current_screen();
12
+
13
+ $screen->add_help_tab( array(
14
+ 'id' => 'overview',
15
+ 'title' => __( 'Overview', 'code-snippets' ),
16
+ 'content' =>
17
+ '<p>' . __( 'Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. Here you can add a new snippet, or edit an existing one.', 'code-snippets' ) . '</p>',
18
+ ) );
19
+
20
+ $screen->add_help_tab( array(
21
+ 'id' => 'finding',
22
+ 'title' => __( 'Finding Snippets', 'code-snippets' ),
23
+ 'content' =>
24
+ '<p>' . __( 'Here are some links to websites which host a large number of snippets that you can add to your site.
25
+ <ul>
26
+ <li><a href="http://wp-snippets.com" title="WordPress Snippets">WP-Snippets</a></li>
27
+ <li><a href="http://wpsnipp.com" title="WP Snipp">WP Snipp</a></li>
28
+ <li><a href="http://www.catswhocode.com/blog/snippets" title="Cats Who Code Snippet Library">Cats Who Code</a></li>
29
+ <li><a href="http://www.wpfunction.me">WP Function Me</a></li>
30
+ </ul>', 'code-snippets' ) .
31
+ __( 'More places to find snippets, as well as a selection of example snippets, can be found in the <a href="http://code-snippets.bungeshea.com/docs/finding-snippets/">plugin documentation</a>', 'code-snippets' ) . '</p>'
32
+ ) );
33
+
34
+ $screen->add_help_tab( array(
35
+ 'id' => 'adding',
36
+ 'title' => __( 'Adding Snippets', 'code-snippets' ),
37
+ 'content' =>
38
+ '<p>' . __( 'You need to fill out the name and code fields for your snippet to be added. While the description field will add more information about how your snippet works, what is does and where you found it, it is completely optional.', 'code-snippets' ) . '</p>' .
39
+ '<p>' . __( 'Please be sure to check that your snippet is valid PHP code and will not produce errors before adding it through this page. While doing so will not become active straight away, it will help to minimise the chance of a faulty snippet becoming active on your site.', 'code-snippets' ) . '</p>'
40
+ ) );
41
+
42
+ $screen->set_help_sidebar(
43
+ '<p><strong>' . __( 'For more information:', 'code-snippets' ) . '</strong></p>' .
44
+ '<p>' . __( '<a href="http://wordpress.org/plugins/code-snippets" target="_blank">WordPress Extend</a>', 'code-snippets' ) . '</p>' .
45
+ '<p>' . __( '<a href="http://wordpress.org/support/plugin/code-snippets" target="_blank">Support Forums</a>', 'code-snippets' ) . '</p>' .
46
+ '<p>' . __( '<a href="http://code-snippets.bungeshea.com/" target="_blank">Project Website</a>', 'code-snippets' ) . '</p>'
47
+ );
includes/edit/admin-messages.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Status and error messages for the single snippet page
5
+ *
6
+ * @package Code_Snippets
7
+ * @subpackage Admin_Messages
8
+ */
9
+
10
+ $_f = '<div id="message" class="%2$s fade"><p>%1$s</p></div>';
11
+
12
+ if ( isset( $_REQUEST['invalid'] ) && $_REQUEST['invalid'] ) :
13
+
14
+ printf ( $_f, __( 'An error occurred when saving the snippet.', 'code-snippets' ), 'error' );
15
+
16
+ elseif ( isset( $_REQUEST['activated'], $_REQUEST['updated'] ) && $_REQUEST['activated'] && $_REQUEST['updated'] ) :
17
+
18
+ printf ( $_f, __( 'Snippet <strong>updated</strong> and <strong>activated</strong>.', 'code-snippets' ), 'updated' );
19
+
20
+ elseif ( isset( $_REQUEST['activated'], $_REQUEST['added'] ) && $_REQUEST['activated'] && $_REQUEST['added'] ) :
21
+
22
+ printf ( $_f, __( 'Snippet <strong>added</strong> and <strong>activated</strong>.', 'code-snippets' ), 'updated' );
23
+
24
+ elseif ( isset( $_REQUEST['deactivated'], $_REQUEST['updated'] ) && $_REQUEST['deactivated'] && $_REQUEST['updated'] ) :
25
+
26
+ printf ( $_f, __( 'Snippet <strong>updated</strong> and <strong>deactivated</strong>.', 'code-snippets' ), 'updated' );
27
+
28
+ elseif ( isset( $_REQUEST['updated'] ) && $_REQUEST['updated'] ) :
29
+
30
+ printf ( $_f, __( 'Snippet <strong>updated</strong>.', 'code-snippets' ), 'updated' );
31
+
32
+ elseif ( isset( $_REQUEST['added'] ) && $_REQUEST['added'] ) :
33
+
34
+ printf ( $_f, __( 'Snippet <strong>added</strong>.', 'code-snippets' ), 'updated' );
35
+
36
+ endif;
includes/edit/admin.php ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * HTML code for the Add New/Edit Snippet page
5
+ *
6
+ * @package Code_Snippets
7
+ * @subpackage Edit
8
+ */
9
+
10
+ /* Bail if accessed directly */
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ return;
13
+ }
14
+
15
+ global $pagenow;
16
+
17
+ $table = get_snippets_table_name();
18
+ $edit_id = code_snippets_get_menu_slug( 'edit' ) === $_REQUEST['page'] ? absint( $_REQUEST['id'] ) : 0;
19
+ $snippet = get_snippet( $edit_id );
20
+
21
+ ?>
22
+ <div class="wrap">
23
+ <?php screen_icon(); ?>
24
+ <h2><?php
25
+ if ( $edit_id ) {
26
+ esc_html_e( 'Edit Snippet', 'code-snippets' );
27
+
28
+ if ( current_user_can( get_snippets_cap() ) ) {
29
+ printf( ' <a href="%1$s" class="add-new-h2">%2$s</a>',
30
+ code_snippets_get_menu_url( 'add' ),
31
+ esc_html_x( 'Add New', 'snippet', 'code-snippets' )
32
+ );
33
+ }
34
+ } else {
35
+ esc_html_e( 'Add New Snippet', 'code-snippets' );
36
+ }
37
+ ?></h2>
38
+
39
+ <form method="post" action="" style="margin-top: 10px;">
40
+ <?php
41
+
42
+ /* Output the hidden fields */
43
+
44
+ if ( 0 !== $snippet->id ) {
45
+ printf ( '<input type="hidden" name="snippet_id" value="%d" />', $snippet->id );
46
+ }
47
+
48
+ printf ( '<input type="hidden" name="snippet_active" value="%d" />', $snippet->active );
49
+ ?>
50
+ <div id="titlediv">
51
+ <div id="titlewrap">
52
+ <label for="title" style="display: none;"><?php _e( 'Name (short title)', 'code-snippets' ); ?></label>
53
+ <input id="title" type="text" autocomplete="off" name="snippet_name" value="<?php echo $snippet->name; ?>" placeholder="<?php _e( 'Name (short title)', 'code-snippets' ); ?>" />
54
+ </div>
55
+ </div>
56
+
57
+ <label for="snippet_code">
58
+ <h3><?php _e( 'Code', 'code-snippets' ); ?></h3>
59
+ </label>
60
+
61
+ <textarea id="snippet_code" name="snippet_code" rows="20" spellcheck="false" style="font-family: monospace; width: 100%;"><?php echo esc_textarea( $snippet->code ); ?></textarea>
62
+
63
+ <?php
64
+
65
+ /* Allow addon plugins (and us!) to add fields and content to this page */
66
+ do_action( 'code_snippets/admin/single', $snippet );
67
+
68
+ /* Add a nonce for security */
69
+ wp_nonce_field( 'save_snippet' );
70
+ ?>
71
+
72
+ <p class="submit">
73
+ <?php
74
+
75
+ /* Make the 'Save and Activate' button the default if the setting is enabled */
76
+ if ( ! $snippet->active && code_snippets_get_setting( 'general', 'activate_by_default' ) ) {
77
+
78
+ submit_button(
79
+ __( 'Save Changes and Activate', 'code-snippets' ),
80
+ 'primary', 'save_snippet_activate', false
81
+ );
82
+
83
+ submit_button( null, 'secondary', 'save_snippet', false );
84
+
85
+ } else {
86
+
87
+ /* Save Snippet button */
88
+ submit_button( null, 'primary', 'save_snippet', false );
89
+
90
+ /* Save Snippet and Activate/Deactivate button */
91
+ if ( ! $snippet->active ) {
92
+ submit_button(
93
+ __( 'Save Changes and Activate', 'code-snippets' ),
94
+ 'secondary', 'save_snippet_activate', false
95
+ );
96
+
97
+ } else {
98
+ submit_button(
99
+ __( 'Save Changes and Deactivate', 'code-snippets' ),
100
+ 'secondary', 'save_snippet_deactivate', false
101
+ );
102
+ }
103
+ }
104
+
105
+ if ( 0 !== $snippet->id ) {
106
+
107
+ /* Export button */
108
+
109
+ submit_button( __( 'Export', 'code-snippets' ), 'secondary', 'export_snippet', false );
110
+
111
+ /* Delete button */
112
+
113
+ $confirm_delete_js = esc_js(
114
+ sprintf (
115
+ 'return confirm("%s");',
116
+ __( "You are about to permanently delete this snippet.\n'Cancel' to stop, 'OK' to delete.", 'code-snippets' )
117
+ )
118
+ );
119
+
120
+ submit_button(
121
+ __( 'Delete', 'code-snippets' ),
122
+ 'secondary', 'delete_snippet', false,
123
+ sprintf ( 'onclick="%s"', $confirm_delete_js )
124
+ );
125
+ }
126
+
127
+ ?>
128
+ </p>
129
+
130
+ </form>
131
+ </div>
132
+
133
+ <script>
134
+ /**
135
+ * Loads CodeMirror on the snippet editor
136
+ */
137
+ (function() {
138
+
139
+ var atts = <?php
140
+ $atts = array( 'mode' => 'text/x-php' );
141
+ echo code_snippets_get_editor_atts( $atts, true );
142
+ ?>;
143
+ var editor = CodeMirror.fromTextArea(document.getElementById('snippet_code'), atts);
144
+
145
+ })();
146
+ </script>
includes/edit/edit.php ADDED
@@ -0,0 +1,370 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Functions to handle the single snippet menu
5
+ *
6
+ * @package Code_Snippets
7
+ * @subpackage Administration
8
+ */
9
+
10
+ /**
11
+ * Fetch the admin menu slug for a snippets menu
12
+ * @param integer $id The snippet
13
+ * @return string The URL to the edit snippet page for that snippet
14
+ */
15
+ function get_snippet_edit_url( $snippet_id ) {
16
+ return add_query_arg(
17
+ 'id', absint( $snippet_id ),
18
+ code_snippets_get_menu_url( 'edit' )
19
+ );
20
+ }
21
+
22
+ /**
23
+ * Register the single snippet admin menu
24
+ *
25
+ * @since 2.0
26
+ * @access private
27
+ * @uses add_submenu_page() To register a sub-menu
28
+ */
29
+ function code_snippets_add_single_menu() {
30
+
31
+ /* Add New Snippet menu */
32
+ $add_hook = add_submenu_page(
33
+ code_snippets_get_menu_slug(),
34
+ __( 'Add New Snippet', 'code-snippets' ),
35
+ __( 'Add New', 'code-snippets' ),
36
+ get_snippets_cap(),
37
+ code_snippets_get_menu_slug( 'add' ),
38
+ 'code_snippets_render_single_menu'
39
+ );
40
+
41
+ /* Check if we are currently editing a snippet */
42
+ if ( isset( $_REQUEST['page'] ) && code_snippets_get_menu_slug( 'edit' ) === $_REQUEST['page'] ) {
43
+
44
+ $edit_hook = add_submenu_page(
45
+ code_snippets_get_menu_slug(),
46
+ __( 'Edit Snippet', 'code-snippets' ),
47
+ __( 'Edit Snippet', 'code-snippets' ),
48
+ get_snippets_cap(),
49
+ code_snippets_get_menu_slug( 'edit' ),
50
+ 'code_snippets_render_single_menu'
51
+ );
52
+
53
+ add_action( 'load-' . $edit_hook, 'code_snippets_load_single_menu' );
54
+ }
55
+
56
+ add_action( 'load-' . $add_hook, 'code_snippets_load_single_menu' );
57
+ }
58
+
59
+ add_action( 'admin_menu', 'code_snippets_add_single_menu', 5 );
60
+ add_action( 'network_admin_menu', 'code_snippets_add_single_menu', 5 );
61
+
62
+ /**
63
+ * Displays the single snippet menu
64
+ *
65
+ * @since 2.0
66
+ */
67
+ function code_snippets_render_single_menu() {
68
+ require plugin_dir_path( __FILE__ ) . 'admin-messages.php';
69
+ require plugin_dir_path( __FILE__ ) . 'admin.php';
70
+ }
71
+
72
+ /**
73
+ * Loads the help tabs for the Edit Snippets page
74
+ *
75
+ * @since 1.0
76
+ * @access private
77
+ * @uses wp_redirect To pass the results to the page
78
+ */
79
+ function code_snippets_load_single_menu() {
80
+
81
+ /* Make sure the user has permission to be here */
82
+ if ( ! current_user_can( get_snippets_cap() ) ) {
83
+ wp_die( __( 'You are not authorized to access this page.', 'code-snippets' ) );
84
+ }
85
+
86
+ /* Create the snippet tables if they don't exist */
87
+ create_code_snippets_tables( true, true );
88
+
89
+ /* Load the screen help tabs */
90
+ require plugin_dir_path( __FILE__ ) . 'admin-help.php';
91
+
92
+ /* Enqueue the code editor and other scripts and styles */
93
+ add_filter( 'admin_enqueue_scripts', 'code_snippets_enqueue_codemirror' );
94
+
95
+ /* Don't allow visiting the edit snippet page without a valid ID */
96
+ if ( code_snippets_get_menu_slug( 'edit' ) === $_REQUEST['page'] ) {
97
+ if ( ! isset( $_REQUEST['id'] ) || 0 == $_REQUEST['id'] ) {
98
+ wp_redirect( code_snippets_get_menu_url( 'add' ) );
99
+ exit;
100
+ }
101
+ }
102
+
103
+ /* Make sure the nonce validates before we do any snippet ops */
104
+ if ( ! isset( $_REQUEST['_wpnonce'] ) || ! wp_verify_nonce( $_REQUEST['_wpnonce'], 'save_snippet' ) ) {
105
+ return;
106
+ }
107
+
108
+ /* Save the snippet if one has been submitted */
109
+ if ( isset( $_POST['save_snippet'] ) || isset( $_POST['save_snippet_activate'] ) || isset( $_POST['save_snippet_deactivate'] ) ) {
110
+
111
+ /* Activate or deactivate the snippet before saving if we clicked the button */
112
+ if ( isset( $_POST['save_snippet_activate'] ) ) {
113
+ $_POST['snippet_active'] = 1;
114
+ } elseif ( isset( $_POST['save_snippet_deactivate'] ) ) {
115
+ $_POST['snippet_active'] = 0;
116
+ }
117
+
118
+ /* Save the snippet to the database */
119
+ $result = save_snippet( stripslashes_deep( $_POST ) );
120
+
121
+ /* Build the status message and redirect */
122
+ $query_args = array();
123
+
124
+ if ( $result && isset( $_POST['save_snippet_activate'] ) ) {
125
+ /* Snippet was activated addition to saving*/
126
+ $query_args['activated'] = true;
127
+ }
128
+ elseif ( $result && isset( $_POST['save_snippet_deactivate'] ) ) {
129
+ /* Snippet was deactivated addition to saving*/
130
+ $query_args['deactivated'] = true;
131
+ }
132
+
133
+ if ( ! $result || $result < 1 ) {
134
+ /* An error occurred */
135
+ $query_args['invalid'] = true;
136
+ }
137
+ elseif ( isset( $_POST['snippet_id'] ) ) {
138
+ /* Existing snippet was updated */
139
+ $query_args['id'] = $result;
140
+ $query_args['updated'] = true;
141
+ }
142
+ else {
143
+ /* New snippet was added */
144
+ $query_args['id'] = $result;
145
+ $query_args['added'] = true;
146
+ }
147
+
148
+ /* Redirect to edit snippet page */
149
+ wp_redirect( add_query_arg( $query_args, code_snippets_get_menu_url( 'edit' ) ) );
150
+ }
151
+
152
+ /* Delete the snippet if the button was clicked */
153
+ elseif ( isset( $_POST['snippet_id'], $_POST['delete_snippet'] ) ) {
154
+ delete_snippet( $_POST['snippet_id'] );
155
+ wp_redirect( add_query_arg( 'delete', true, $this->manage_url ) );
156
+ }
157
+
158
+ /* Export the snippet if the button was clicked */
159
+ elseif ( isset( $_POST['snippet_id'], $_POST['export_snippet'] ) ) {
160
+ export_snippet( $_POST['snippet_id'] );
161
+ }
162
+ }
163
+
164
+ /**
165
+ * Add a description editor to the single snippet page
166
+ *
167
+ * @since 1.7
168
+ * @access private
169
+ * @param object $snippet The snippet being used for this page
170
+ */
171
+ function code_snippets_description_editor_box( $snippet ) {
172
+
173
+ ?>
174
+
175
+ <label for="snippet_description">
176
+ <h3><div><?php _e( 'Description', 'code-snippets' ); ?></div></h3>
177
+ </label>
178
+
179
+ <?php
180
+
181
+ remove_editor_styles(); // stop custom theme styling interfering with the editor
182
+
183
+ wp_editor(
184
+ $snippet->description,
185
+ 'description',
186
+ apply_filters( 'code_snippets/admin/description_editor_settings', array(
187
+ 'textarea_name' => 'snippet_description',
188
+ 'textarea_rows' => 10,
189
+ 'teeny' => true,
190
+ 'media_buttons' => false,
191
+ ) )
192
+ );
193
+ }
194
+
195
+ add_action( 'code_snippets/admin/single', 'code_snippets_description_editor_box', 5 );
196
+
197
+ /**
198
+ * Output the interface for editing snippet tags
199
+ * @since 2.0
200
+ * @param object $snippet The snippet currently being edited
201
+ */
202
+ function code_snippets_tags_editor( $snippet ) {
203
+ ?>
204
+ <label for="snippet_tags" style="cursor: auto;">
205
+ <h3><?php esc_html_e( 'Tags', 'code-snippets' ); ?></h3>
206
+ </label>
207
+
208
+ <input type="text" id="snippet_tags" name="snippet_tags" style="width: 100%;"
209
+ placeholder="Enter a list of tags; separated by commas" value="<?php echo implode( ', ', $snippet->tags ); ?>" />
210
+
211
+ <script type="text/javascript">
212
+ jQuery('#snippet_tags').tagit({
213
+ availableTags: ['<?php echo implode( "','", get_all_snippet_tags() ); ?>'],
214
+ allowSpaces: true,
215
+ removeConfirmation: true
216
+ });
217
+ </script>
218
+ <?php
219
+ }
220
+
221
+ add_action( 'code_snippets/admin/single', 'code_snippets_tags_editor' );
222
+
223
+ /**
224
+ * Registers and loads the code editor's assets
225
+ *
226
+ * @since 1.7
227
+ * @access private
228
+ *
229
+ * @uses wp_register_script()
230
+ * @uses wp_register_style()
231
+ * @uses wp_enqueue_script() To add the scripts to the queue
232
+ * @uses wp_enqueue_style() To add the stylesheets to the queue
233
+ *
234
+ * @param string $hook The current page hook, to be compared with the single snippet page hook
235
+ */
236
+ function code_snippets_enqueue_codemirror() {
237
+
238
+ /* Remove other CodeMirror styles */
239
+ wp_deregister_style( 'codemirror' );
240
+ wp_deregister_style( 'wpeditor' );
241
+
242
+ /* CodeMirror */
243
+
244
+ $codemirror_version = '5.0';
245
+ $codemirror_url = plugins_url( 'vendor/codemirror/', CODE_SNIPPETS_FILE );
246
+
247
+ wp_enqueue_style(
248
+ 'code-snippets-codemirror',
249
+ $codemirror_url . 'lib/codemirror.css',
250
+ false,
251
+ $codemirror_version
252
+ );
253
+
254
+ wp_enqueue_script(
255
+ 'code-snippets-codemirror',
256
+ $codemirror_url . 'lib/codemirror.js',
257
+ false,
258
+ $codemirror_version
259
+ );
260
+
261
+ /* CodeMirror Modes */
262
+
263
+ wp_enqueue_script(
264
+ 'code-snippets-codemirror-mode-clike',
265
+ $codemirror_url . 'mode/clike/clike.js',
266
+ array( 'code-snippets-codemirror' ),
267
+ $codemirror_version
268
+ );
269
+
270
+ wp_enqueue_script(
271
+ 'code-snippets-codemirror-mode-php',
272
+ $codemirror_url . 'mode/php/php.js',
273
+ array( 'code-snippets-codemirror', 'code-snippets-codemirror-mode-clike' ),
274
+ $codemirror_version
275
+ );
276
+
277
+
278
+ /* CodeMirror Addons */
279
+
280
+ wp_enqueue_script(
281
+ 'code-snippets-codemirror-addon-searchcursor',
282
+ $codemirror_url . 'addon/search/searchcursor.js',
283
+ array( 'code-snippets-codemirror' ),
284
+ $codemirror_version
285
+ );
286
+
287
+ wp_enqueue_script(
288
+ 'code-snippets-codemirror-addon-search',
289
+ $codemirror_url . 'addon/search/search.js',
290
+ array( 'code-snippets-codemirror', 'code-snippets-codemirror-addon-searchcursor' ),
291
+ $codemirror_version
292
+ );
293
+
294
+ wp_enqueue_script(
295
+ 'code-snippets-codemirror-addon-matchbrackets',
296
+ $codemirror_url . 'addon/edit/matchbrackets.js',
297
+ array( 'code-snippets-codemirror' ),
298
+ $codemirror_version
299
+ );
300
+
301
+ wp_enqueue_script(
302
+ 'code-snippets-codemirror-addon-closebrackets',
303
+ $codemirror_url . 'addon/edit/closebrackets.js',
304
+ array( 'code-snippets-codemirror' ),
305
+ $codemirror_version
306
+ );
307
+
308
+ wp_enqueue_script(
309
+ 'code-snippets-codemirror-addon-match-highlighter',
310
+ $codemirror_url . 'addon/search/match-highlighter.js',
311
+ array( 'code-snippets-codemirror', 'code-snippets-codemirror-addon-searchcursor' ),
312
+ $codemirror_version
313
+ );
314
+
315
+ /* Plugin Assets */
316
+
317
+ wp_enqueue_style(
318
+ 'code-snippets-edit',
319
+ plugins_url( 'css/min/edit-snippet.css', CODE_SNIPPETS_FILE ),
320
+ false,
321
+ CODE_SNIPPETS_VERSION
322
+ );
323
+
324
+ /* CodeMirror Theme */
325
+
326
+ $theme = code_snippets_get_setting( 'editor', 'theme' );
327
+
328
+ if ( 'default' !== $theme ) {
329
+
330
+ wp_enqueue_style(
331
+ 'code-snippets-codemirror-theme-' . $theme,
332
+ $codemirror_url . "theme/$theme.css",
333
+ array( 'code-snippets-codemirror' ),
334
+ $codemirror_version
335
+ );
336
+ }
337
+
338
+ /* Tag It UI */
339
+
340
+ $tagit_version = '2.0';
341
+
342
+ wp_enqueue_script(
343
+ 'code-snippets-tag-it',
344
+ plugins_url( 'js/vendor/tag-it.min.js', CODE_SNIPPETS_FILE ),
345
+ array(
346
+ 'jquery-ui-core',
347
+ 'jquery-ui-widget',
348
+ 'jquery-ui-position',
349
+ 'jquery-ui-autocomplete',
350
+ 'jquery-effects-blind',
351
+ 'jquery-effects-highlight',
352
+ ),
353
+ $tagit_version
354
+ );
355
+
356
+ wp_enqueue_style(
357
+ 'code-snippets-tagit',
358
+ plugins_url( 'js/vendor/jquery.tagit.css', CODE_SNIPPETS_FILE ),
359
+ false,
360
+ $tagit_version
361
+ );
362
+
363
+ wp_enqueue_style(
364
+ 'code-snippets-tagit-zendesk-ui',
365
+ plugins_url( 'js/vendor/tagit.ui-zendesk.css', CODE_SNIPPETS_FILE ),
366
+ array( 'code-snippets-tagit' ),
367
+ $tagit_version
368
+ );
369
+
370
+ }
includes/editor.php ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Get the attributes for the code editor
5
+ * @param array $override_atts Pass an array of attributes to override the saved ones
6
+ * @param boolean $json_encode Encode the data as JSON
7
+ * @return array|string Array if $json_encode is false, JSON string if it is true
8
+ */
9
+ function code_snippets_get_editor_atts( $override_atts, $json_encode ) {
10
+ $settings = code_snippets_get_settings();
11
+ $settings = $settings['editor'];
12
+
13
+ $fields = code_snippets_get_settings_fields();
14
+ $fields = $fields['editor'];
15
+
16
+ $saved_atts = array(
17
+ 'matchBrackets' => true,
18
+ );
19
+
20
+ foreach ( $fields as $field ) {
21
+ $saved_atts[ $field['codemirror'] ] = $settings[ $field['id'] ];
22
+
23
+ }
24
+
25
+ $atts = wp_parse_args( $override_atts, $saved_atts );
26
+ $atts = apply_filters( 'code_snippets_codemirror_atts', $atts );
27
+
28
+ if ( $json_encode ) {
29
+
30
+ /* JSON_UNESCAPED_SLASHES was added in PHP 5.4 */
31
+ if ( version_compare( phpversion(), '5.4.0', '>=' ) ) {
32
+ $atts = json_encode( $atts, JSON_UNESCAPED_SLASHES );
33
+ } else {
34
+ /* Use a fallback for < 5.4 */
35
+ $atts = str_replace('\\/', '/', json_encode( $atts ) );
36
+ }
37
+ }
38
+
39
+ return $atts;
40
+ }
includes/import/admin-help.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Register and handle the help tabs for the
5
+ * import snippets admin page
6
+ *
7
+ * @package Code_Snippets
8
+ * @subpackage Import
9
+ */
10
+
11
+ $screen = get_current_screen();
12
+ $manage_url = code_snippets_get_menu_url( 'manage' );
13
+
14
+ $screen->add_help_tab( array(
15
+ 'id' => 'overview',
16
+ 'title' => __( 'Overview', 'code-snippets' ),
17
+ 'content' =>
18
+ '<p>' . __( 'Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. Here you can load snippets from a Code Snippets (.xml) import file into the database with your existing snippets.', 'code-snippets' ) . '</p>'
19
+ ) );
20
+
21
+ $screen->add_help_tab( array(
22
+ 'id' => 'import',
23
+ 'title' => __( 'Importing', 'code-snippets' ),
24
+ 'content' =>
25
+ '<p>' . __( 'You can load your snippets from a code snippets (.xml) export file using this page.', 'code-snippets' ) .
26
+ sprintf( __( 'Snippets will be added to the database along with your existing snippets. Regardless of whether the snippets were active on the previous site, imported snippets are always inactive until activated using the <a href="%s">Manage Snippets</a> page.</p>', 'code-snippets' ), $manage_url ) . '</p>'
27
+ ) );
28
+
29
+ $screen->add_help_tab( array(
30
+ 'id' => 'export',
31
+ 'title' => __( 'Exporting', 'code-snippets' ),
32
+ 'content' =>
33
+ '<p>' . sprintf( __( 'You can save your snippets to a Code Snippets (.xml) export file using the <a href="%s">Manage Snippets</a> page.', 'code-snippets' ), $manage_url ) . '</p>'
34
+ ) );
35
+
36
+ $screen->set_help_sidebar(
37
+ '<p><strong>' . __( 'For more information:', 'code-snippets' ) . '</strong></p>' .
38
+ '<p>' . __( '<a href="http://wordpress.org/plugins/code-snippets" target="_blank">WordPress Extend</a>', 'code-snippets' ) . '</p>' .
39
+ '<p>' . __( '<a href="http://wordpress.org/support/plugin/code-snippets" target="_blank">Support Forums</a>', 'code-snippets' ) . '</p>' .
40
+ '<p>' . __( '<a href="http://code-snippets.bungeshea.com/" target="_blank">Project Website</a>', 'code-snippets' ) . '</p>'
41
+ );
includes/import/admin-messages.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Status and error messages for the import snippets page
5
+ *
6
+ * @package Code_Snippets
7
+ * @subpackage Admin_Messages
8
+ */
9
+
10
+ if ( isset( $_REQUEST['imported'] ) && 0 !== intval( $_REQUEST['imported'] ) ) {
11
+
12
+ echo '<div id="message" class="updated fade"><p>';
13
+
14
+ printf(
15
+ _n(
16
+ 'Successfully imported <strong>%d</strong> snippet. <a href="%s">Have fun!</a>',
17
+ 'Successfully imported <strong>%d</strong> snippets. <a href="%s">Have fun!</a>',
18
+ $_REQUEST['imported'],
19
+ 'code-snippets'
20
+ ),
21
+ $_REQUEST['imported'],
22
+ code_snippets_get_menu_url( 'manage' )
23
+ );
24
+
25
+ echo '</p></div>';
26
+ }
27
+ elseif ( isset( $_REQUEST['error'] ) && $_REQUEST['error'] ) {
28
+ printf (
29
+ '<div id="message" class="error fade"><p>%s</p></div>',
30
+ __( 'An error occurred when processing the import file.', 'code-snippets' )
31
+ );
32
+ }
includes/import/admin.php ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * HTML code for the Import Snippets page
5
+ *
6
+ * @package Code_Snippets
7
+ * @subpackage Import
8
+ */
9
+
10
+ /* Bail if accessed directly */
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ return;
13
+ }
14
+
15
+ ?>
16
+ <div class="wrap">
17
+ <?php screen_icon(); ?>
18
+ <h2><?php _e( 'Import Snippets', 'code-snippets' ); ?></h2>
19
+
20
+ <div class="narrow">
21
+
22
+ <p><?php _e( 'Howdy! Upload your Code Snippets export file and we&#8217;ll import the snippets to this site.', 'code-snippets' ); ?></p>
23
+
24
+ <p><?php printf( __( 'You will need to go to the <a href="%s">Manage Snippets</a> page to activate the imported snippets.', 'code-snippets' ), code_snippets_get_menu_url( 'manage' ) ); ?></p>
25
+
26
+ <p><?php _e( 'Choose a Code Snippets (.xml) file to upload, then click Upload file and import.', 'code-snippets' ); ?></p>
27
+
28
+ <form enctype="multipart/form-data" method="post" action="" id="import-upload-form" name="code_snippets_import">
29
+ <p>
30
+ <input type="hidden" name="action" value="save" />
31
+ <input type="hidden" name="max_file_size" value="8388608" />
32
+
33
+ <label for="upload"><?php _e( 'Choose a file from your computer:', 'code-snippets' ); ?></label>
34
+ <?php _e( '(Maximum size: 8MB)', 'code-snippets' ); ?>
35
+ <input type="file" id="upload" name="code_snippets_import_file" size="25" accept="text/xml" />
36
+ </p>
37
+
38
+ <?php
39
+ do_action( 'code_snippets/admin/import_form' );
40
+ submit_button( __( 'Upload file and import', 'code-snippets' ) );
41
+ ?>
42
+
43
+ </form>
44
+ </div>
45
+ </div>
includes/import/import.php ADDED
@@ -0,0 +1,115 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Functions to handle the import snippets menu
5
+ *
6
+ * @package Code_Snippets
7
+ * @subpackage Administration
8
+ */
9
+
10
+ /**
11
+ * Add the importer to the Tools > Import menu
12
+ *
13
+ * @since 1.6
14
+ * @access private
15
+ */
16
+ function code_snippets_register_importer() {
17
+
18
+ /* Only register the importer if the current user can manage snippets */
19
+ if ( defined( 'WP_LOAD_IMPORTERS' ) && current_user_can( get_snippets_cap() ) ) {
20
+
21
+ /* Load Importer API */
22
+ require_once ABSPATH . 'wp-admin/includes/import.php';
23
+
24
+ if ( ! class_exists( 'WP_Importer' ) ) {
25
+ $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
26
+ if ( file_exists( $class_wp_importer ) ) {
27
+ require_once $class_wp_importer;
28
+ }
29
+ }
30
+
31
+ /* Register the Code Snippets importer with WordPress */
32
+ register_importer(
33
+ 'code-snippets',
34
+ __( 'Code Snippets', 'code-snippets' ),
35
+ __( 'Import snippets from a code snippets export file', 'code-snippets' ),
36
+ 'code_snippets_render_import_menu'
37
+ );
38
+ }
39
+
40
+ add_action( 'load-importer-code-snippets', 'code_snippets_load_import_menu' );
41
+ }
42
+
43
+ add_action( 'admin_init', 'code_snippets_register_importer' );
44
+
45
+ /**
46
+ * Add an Import Snippets page to the admin menu.
47
+ *
48
+ * @since 1.6
49
+ * @uses add_submenu_page() To register the menu page
50
+ */
51
+ function code_snippets_add_import_menu() {
52
+
53
+ $hook = add_submenu_page(
54
+ code_snippets_get_menu_slug(),
55
+ __( 'Import Snippets', 'code-snippets' ),
56
+ __( 'Import', 'code-snippets' ),
57
+ get_snippets_cap(),
58
+ code_snippets_get_menu_slug( 'import' ),
59
+ 'code_snippets_render_import_menu'
60
+ );
61
+
62
+ add_action( 'load-' . $hook, 'code_snippets_load_import_menu' );
63
+ }
64
+
65
+ add_action( 'admin_menu', 'code_snippets_add_import_menu' );
66
+ add_action( 'network_admin_menu', 'code_snippets_add_import_menu' );
67
+
68
+ /**
69
+ * Displays the import snippets page
70
+ *
71
+ * @since 2.0
72
+ */
73
+ function code_snippets_render_import_menu() {
74
+ require_once plugin_dir_path( __FILE__ ) . 'admin-messages.php';
75
+ require_once plugin_dir_path( __FILE__ ) . 'admin.php';
76
+ }
77
+
78
+ /**
79
+ * Processes import files and loads the help tabs for the Import Snippets page
80
+ *
81
+ * @since 1.3
82
+ *
83
+ * @uses import_snippets() To process the import file
84
+ * @uses wp_redirect() To pass the import results to the page
85
+ * @uses add_query_arg() To append the results to the current URI
86
+ */
87
+ function code_snippets_load_import_menu() {
88
+ $network = get_current_screen()->is_network;
89
+
90
+ /* Make sure the user has permission to be here */
91
+ if ( ! current_user_can( get_snippets_cap() ) ) {
92
+ wp_die( __( 'You are not access this page.', 'code-snippets' ) );
93
+ }
94
+
95
+ /* Create the snippet tables if they don't exist */
96
+ create_code_snippets_tables( true, true );
97
+
98
+ /* Process import files */
99
+
100
+ if ( isset( $_FILES['code_snippets_import_file']['tmp_name'] ) ) {
101
+
102
+ /* Import the snippets. The result is the number of snippets that were imported */
103
+ $result = import_snippets( $_FILES['code_snippets_import_file']['tmp_name'], $network );
104
+
105
+ /* Send the amount of imported snippets to the page */
106
+ if ( false === $result ) {
107
+ wp_redirect( add_query_arg( 'error', true ) );
108
+ } else {
109
+ wp_redirect( add_query_arg( 'imported', $result ) );
110
+ }
111
+ }
112
+
113
+ /* Load the screen help tabs */
114
+ require plugin_dir_path( __FILE__ ) . 'admin-help.php';
115
+ }
includes/manage/admin-help.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Register and handle the help tabs for the
5
+ * manage snippets admin page
6
+ *
7
+ * @package Code_Snippets
8
+ * @subpackage Manage
9
+ */
10
+
11
+ $screen = get_current_screen();
12
+
13
+ $screen->add_help_tab( array(
14
+ 'id' => 'overview',
15
+ 'title' => __( 'Overview', 'code-snippets' ),
16
+ 'content' =>
17
+ '<p>' . __( 'Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. Here you can manage your existing snippets and preform tasks on them such as activating, deactivating, deleting and exporting.', 'code-snippets' ) . '</p>'
18
+ ) );
19
+
20
+ $screen->add_help_tab( array(
21
+ 'id' => 'safe-mode',
22
+ 'title' => __( 'Safe Mode', 'code-snippets' ),
23
+ 'content' =>
24
+ '<p>' . __( 'Be sure to check your snippets for errors before you activate them, as a faulty snippet could bring your whole blog down. If your site starts doing strange things, deactivate all your snippets and activate them one at a time.', 'code-snippets' ) . '</p>' .
25
+ '<p>' . __("If something goes wrong with a snippet and you can't use WordPress, you can cause all snippets to stop executing by adding <code>define('CODE_SNIPPETS_SAFE_MODE', true);</code> to your <code>wp-config.php</code> file. After you have deactivated the offending snippet, you can turn off safe mode by removing this line or replacing <strong>true</strong> with <strong>false</strong>.", 'code-snippets' ) . '</p>'
26
+ ) );
27
+
28
+ $screen->add_help_tab( array(
29
+ 'id' => 'uninstall',
30
+ 'title' => __( 'Uninstall', 'code-snippets' ),
31
+ 'content' =>
32
+ '<p>' . sprintf( __( 'When you delete Code Snippets through the Plugins menu in WordPress it will clear up the <code>%1$s</code> table and a few other bits of data stored in the database. If you want to keep this data (ie: you are only temporally uninstalling Code Snippets) then remove the <code>%2$s</code> folder using FTP.', 'code-snippets' ), get_snippets_table_name(), dirname( CODE_SNIPPETS_FILE ) ) .
33
+ '<p>' . __("Even if you're sure that you don't want to use Code Snippets ever again on this WordPress installation, you may want to use the export feature to back up your snippets.", 'code-snippets' ) . '</p>'
34
+ ) );
35
+
36
+ $screen->set_help_sidebar(
37
+ '<p><strong>' . __( 'For more information:', 'code-snippets' ) . '</strong></p>' .
38
+ '<p>' . __( '<a href="http://wordpress.org/plugins/code-snippets" target="_blank">WordPress Extend</a></p>', 'code-snippets' ) . '</p>' .
39
+ '<p>' . __( '<a href="http://wordpress.org/support/plugin/code-snippets" target="_blank">Support Forums</a>', 'code-snippets' ) . '</p>' .
40
+ '<p>' . __( '<a href="http://code-snippets.bungeshea.com/" target="_blank">Project Website</a>', 'code-snippets' ) . '</p>'
41
+ );
includes/manage/admin-messages.php ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Status and error messages for the manage snippets page
5
+ *
6
+ * @package Code_Snippets
7
+ * @subpackage Manage
8
+ */
9
+
10
+ $_f = '<div id="message" class="%2$s fade"><p>%1$s</p></div>';
11
+
12
+ if ( defined( 'CODE_SNIPPETS_SAFE_MODE' ) && CODE_SNIPPETS_SAFE_MODE ) :
13
+
14
+ printf ( $_f, __( '<strong>Warning:</strong> Safe mode is active and snippets will not execute! Remove the <code>CODE_SNIPPETS_SAFE_MODE</code> constant from <code>wp-config.php</code> to turn off safe mode. <a href="http://code-snippets.bungeshea.com/docs/safe-mode/" target="_blank">Help</a>', 'code-snippets' ), 'error' );
15
+
16
+ endif;
17
+
18
+ if ( isset( $_REQUEST['activate'] ) ) :
19
+
20
+ printf ( $_f, __( 'Snippet <strong>activated</strong>.', 'code-snippets' ), 'updated' );
21
+
22
+ elseif ( isset( $_REQUEST['activate-multi'] ) ) :
23
+
24
+ printf ( $_f, __( 'Selected snippets <strong>activated</strong>.', 'code-snippets' ), 'updated' );
25
+
26
+ elseif ( isset( $_REQUEST['deactivate'] ) ) :
27
+
28
+ printf ( $_f, __( 'Snippet <strong>deactivated</strong>.', 'code-snippets' ), 'updated' );
29
+
30
+ elseif ( isset( $_REQUEST['deactivate-multi'] ) ) :
31
+
32
+ printf ( $_f, __( 'Selected snippets <strong>deactivated</strong>.', 'code-snippets' ), 'updated' );
33
+
34
+ elseif ( isset( $_REQUEST['delete'] ) ) :
35
+
36
+ printf ( $_f, __( 'Snippet <strong>deleted</strong>.', 'code-snippets' ), 'updated' );
37
+
38
+ elseif ( isset( $_REQUEST['delete-multi'] ) ) :
39
+
40
+ printf ( $_f, __( 'Selected snippets <strong>deleted</strong>.', 'code-snippets' ), 'updated' );
41
+
42
+ endif;
includes/manage/admin.php ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * HTML code for the Manage Snippets page
5
+ *
6
+ * @package Code_Snippets
7
+ * @subpackage Manage
8
+ */
9
+
10
+ /* Bail if accessed directly */
11
+ if ( ! defined( 'ABSPATH' ) ) {
12
+ return;
13
+ }
14
+
15
+ global $code_snippets_list_table;
16
+ ?>
17
+
18
+ <div class="wrap">
19
+ <?php screen_icon(); ?>
20
+ <h2><?php
21
+ esc_html_e( 'Snippets', 'code-snippets' );
22
+
23
+ if ( current_user_can( get_snippets_cap() ) ) {
24
+
25
+ printf ( '<a href="%2$s" class="add-new-h2">%1$s</a>',
26
+ esc_html_x( 'Add New', 'snippet', 'code-snippets' ),
27
+ code_snippets_get_menu_url( 'add' )
28
+ );
29
+ }
30
+
31
+ $code_snippets_list_table->search_notice();
32
+ ?></h2>
33
+
34
+ <?php $code_snippets_list_table->views(); ?>
35
+
36
+ <form method="get" action="">
37
+ <?php
38
+ $code_snippets_list_table->required_form_fields( 'search_box' );
39
+ $code_snippets_list_table->search_box( __( 'Search Installed Snippets', 'code-snippets' ), 'search_id' );
40
+ ?>
41
+ </form>
42
+ <form method="post" action="">
43
+ <?php
44
+ $code_snippets_list_table->required_form_fields();
45
+ $code_snippets_list_table->display();
46
+ ?>
47
+ </form>
48
+
49
+ <?php do_action( 'code_snippets/admin/manage' ); ?>
50
+
51
+ </div>
includes/manage/class-list-table.php ADDED
@@ -0,0 +1,815 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Contains the class for handling the snippets table
5
+ *
6
+ * @package Code_Snippets
7
+ * @subpackage Administration
8
+ */
9
+
10
+ /* The WP_List_Table base class is not included by default, so we need to load it */
11
+ if ( ! class_exists( 'WP_List_Table' ) ) {
12
+ require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
13
+ }
14
+
15
+ /**
16
+ * This class handles the table for the manage snippets menu
17
+ *
18
+ * @since 1.5
19
+ * @access private
20
+ * @package Code_Snippets
21
+ */
22
+ class Code_Snippets_List_Table extends WP_List_Table {
23
+
24
+ /**#@+
25
+ * @since 1.5
26
+ * @access private
27
+ */
28
+
29
+ /**
30
+ * The constructor function for our class.
31
+ * Adds hooks, initializes variables, setups class.
32
+ */
33
+ function __construct() {
34
+ global $status, $page;
35
+ $screen = get_current_screen();
36
+
37
+ /* Determine the status */
38
+ $status = 'all';
39
+ if ( isset( $_REQUEST['status'] ) && in_array( $_REQUEST['status'], array( 'active', 'inactive', 'recently_activated' ) ) )
40
+ $status = $_REQUEST['status'];
41
+
42
+ /* Add the search query to the URL */
43
+ if ( isset( $_REQUEST['s'] ) ) {
44
+ $_SERVER['REQUEST_URI'] = add_query_arg( 's', stripslashes($_REQUEST['s'] ) );
45
+ }
46
+
47
+ /* Add a snippets per page screen option */
48
+ $page = $this->get_pagenum();
49
+
50
+ add_screen_option( 'per_page', array(
51
+ 'label' => __( 'Snippets per page', 'code-snippets' ),
52
+ 'default' => 10,
53
+ 'option' => 'snippets_per_page'
54
+ ) );
55
+
56
+ add_filter( 'set-screen-option', array( $this, 'set_screen_option' ), 10, 3 );
57
+
58
+ /* Set the table columns hidden in Screen Options by default */
59
+ add_filter( "get_user_option_manage{$screen->id}columnshidden", array( $this, 'get_default_hidden_columns' ), 15 );
60
+
61
+ /* Strip once-off query args from the URL */
62
+ $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'activate', 'activate-multi', 'deactivate', 'deactivate-multi', 'delete', 'delete-multi' ) );
63
+
64
+ /* Add filters to format the snippet description in the same way the post content is formatted */
65
+ $filters = array( 'wptexturize', 'convert_smilies', 'convert_chars', 'wpautop', 'shortcode_unautop', 'capital_P_dangit' );
66
+
67
+ foreach ( $filters as $filter ) {
68
+ add_filter( 'code_snippets/list_table/print_snippet_description', $filter );
69
+ }
70
+
71
+ /* Setup the class */
72
+ parent::__construct( array(
73
+ 'singular' => 'snippet',
74
+ 'plural' => 'snippets',
75
+ 'ajax' => true,
76
+ ) );
77
+ }
78
+
79
+ /**
80
+ * Handles saving the user's snippets per page preference
81
+ *
82
+ * @param unknown $status
83
+ * @param string $option
84
+ * @param unknown $value
85
+ * @return unknown
86
+ */
87
+ function set_screen_option( $status, $option, $value ) {
88
+ if ( 'snippets_per_page' === $option ) {
89
+ return $value;
90
+ }
91
+
92
+ return $status;
93
+ }
94
+
95
+ /**
96
+ * Define the output of all columns that have no callback function
97
+ * @param object $snippet The snippet object used for the current row
98
+ * @param string $column_name The name of the column being printed
99
+ * @return string The content of the column to output
100
+ */
101
+ function column_default( $snippet, $column_name ) {
102
+
103
+ switch( $column_name ) {
104
+ case 'id':
105
+ return $snippet->id;
106
+ case 'description':
107
+ if ( ! empty( $snippet->description ) ) {
108
+ return apply_filters( 'code_snippets/list_table/print_snippet_description', $snippet->description );
109
+ } else {
110
+ return '&#8212;';
111
+ }
112
+ default:
113
+ return do_action( "code_snippets/list_table/column_{$column_name}", $snippet );
114
+ }
115
+ }
116
+
117
+ /**
118
+ * Builds content of the snippet name column
119
+ * @param object $snippet The snippet object being used for the current row
120
+ * @return string The content of the column to output
121
+ */
122
+ function column_name( $snippet ) {
123
+
124
+ /* Build row actions */
125
+
126
+ $actions = array();
127
+ $screen = get_current_screen();
128
+
129
+ if ( $snippet->active ) {
130
+ $actions['deactivate'] = sprintf(
131
+ '<a href="%2$s">%1$s</a>',
132
+ $screen->is_network ? __( 'Network Deactivate', 'code-snippets' ) : __( 'Deactivate', 'code-snippets' ),
133
+ add_query_arg( array(
134
+ 'action' => 'deactivate',
135
+ 'id' => $snippet->id
136
+ ) )
137
+ );
138
+ } else {
139
+ $actions['activate'] = sprintf(
140
+ '<a href="%2$s">%1$s</a>',
141
+ $screen->is_network ? __( 'Network Activate', 'code-snippets' ) : __( 'Activate', 'code-snippets' ),
142
+ add_query_arg( array(
143
+ 'action' => 'activate',
144
+ 'id' => $snippet->id
145
+ ) )
146
+ );
147
+ }
148
+
149
+ $actions['edit'] = sprintf(
150
+ '<a href="%2$s">%1$s</a>',
151
+ __( 'Edit', 'code-snippets' ),
152
+ get_snippet_edit_url( $snippet->id )
153
+ );
154
+
155
+ $actions['export'] = sprintf(
156
+ '<a href="%2$s">%1$s</a>',
157
+ __( 'Export', 'code-snippets' ),
158
+ add_query_arg( array(
159
+ 'action' => 'export',
160
+ 'id' => $snippet->id
161
+ ) )
162
+ );
163
+
164
+ $actions['delete'] = sprintf(
165
+ '<a href="%2$s" class="delete" onclick="%3$s">%1$s</a>',
166
+ __( 'Delete', 'code-snippets' ),
167
+ add_query_arg( array(
168
+ 'action' => 'delete',
169
+ 'id' => $snippet->id
170
+ ) ),
171
+ esc_js( sprintf(
172
+ 'return confirm("%s");',
173
+ __("You are about to permanently delete the selected item.
174
+ 'Cancel' to stop, 'OK' to delete.", 'code-snippets' )
175
+ ) )
176
+ );
177
+
178
+ if ( ! empty( $snippet->name ) ) {
179
+ $title = $snippet->name;
180
+ } else {
181
+ $title = sprintf ( __( 'Untitled #%d', 'code-snippets' ), $snippet->id );
182
+ }
183
+
184
+ $row_actions = $this->row_actions( $actions,
185
+ apply_filters( 'code_snippets/list_table/row_actions_always_visiable', false )
186
+ );
187
+
188
+ /* Return the name contents */
189
+ return apply_filters(
190
+ 'code_snippets/list_table/column_name',
191
+ sprintf ( '<a href="%2$s"><strong>%1$s</strong></a>', $title,
192
+ get_snippet_edit_url( $snippet->id )
193
+ ) . $row_actions,
194
+ $snippet
195
+ );
196
+ }
197
+
198
+ /**
199
+ * Builds the checkbox column content
200
+ * @param object $snippet The snippet object being used for the current row
201
+ * @return string The column content to be printed
202
+ */
203
+ function column_cb( $snippet ) {
204
+ return apply_filters(
205
+ 'code_snippets/list_table/column_cb',
206
+ sprintf( '<input type="checkbox" name="ids[]" value="%s" />', $snippet->id ),
207
+ $snippet
208
+ );
209
+ }
210
+
211
+ /**
212
+ * Output the content of the tags column
213
+ * This function is used once for each row
214
+ * @since 2.0
215
+ * @param object $snippet
216
+ */
217
+ function column_tags( $snippet ) {
218
+
219
+ if ( ! empty( $snippet->tags ) ) {
220
+
221
+ foreach ( $snippet->tags as $tag ) {
222
+ $out[] = sprintf( '<a href="%s">%s</a>',
223
+ add_query_arg( 'tag', esc_attr( $tag ) ),
224
+ esc_html( $tag )
225
+ );
226
+ }
227
+ echo join( ', ', $out );
228
+ } else {
229
+ echo '&#8212;';
230
+ }
231
+ }
232
+
233
+ /**
234
+ * Define the column headers for the table
235
+ * @return array The column headers, ID paired with label
236
+ */
237
+ function get_columns() {
238
+ $columns = array(
239
+ 'cb' => '<input type="checkbox" />',
240
+ 'name' => __( 'Name', 'code-snippets' ),
241
+ 'id' => __( 'ID', 'code-snippets' ),
242
+ 'description' => __( 'Description', 'code-snippets' ),
243
+ 'tags' => __( 'Tags', 'code-snippets' ),
244
+ );
245
+ return apply_filters( 'code_snippets/list_table/columns', $columns );
246
+ }
247
+
248
+ /**
249
+ * Define the columns that can be sorted
250
+ * @return array The IDs of the columns that can be sorted
251
+ */
252
+ function get_sortable_columns() {
253
+ $sortable_columns = array(
254
+ 'id' => array( 'id', true ),
255
+ 'name' => array( 'name', false ),
256
+ );
257
+ return apply_filters( 'code_snippets/list_table/sortable_columns', $sortable_columns );
258
+ }
259
+
260
+ /**
261
+ * Define the columns that are hidden by default
262
+ * @param unknown $result
263
+ * @return unknown
264
+ */
265
+ function get_default_hidden_columns( $result ) {
266
+ if ( ! $result ) {
267
+ return array( 'id' );
268
+ } else {
269
+ return $result;
270
+ }
271
+ }
272
+
273
+ /**
274
+ * Define the bulk actions to include in the drop-down menus
275
+ * @return array An array of menu items with the ID paired to the label
276
+ */
277
+ function get_bulk_actions() {
278
+ $screen = get_current_screen();
279
+ $actions = array(
280
+ 'activate-selected' => $screen->is_network ? __( 'Network Activate', 'code-snippets' ) : __( 'Activate', 'code-snippets' ),
281
+ 'deactivate-selected' => $screen->is_network ? __( 'Network Deactivate', 'code-snippets' ) : __( 'Deactivate', 'code-snippets' ),
282
+ 'export-selected' => __( 'Export', 'code-snippets' ),
283
+ 'delete-selected' => __( 'Delete', 'code-snippets' ),
284
+ 'export-php-selected' => __( 'Export to PHP', 'code-snippets' ),
285
+ );
286
+ return apply_filters( 'code_snippets/list_table/bulk_actions', $actions );
287
+ }
288
+
289
+ /**
290
+ * Retrieve the classes for the table
291
+ *
292
+ * We override this in order to add 'snippets' as a class
293
+ * for custom styling
294
+ *
295
+ * @return array The classes to include on the table element
296
+ */
297
+ function get_table_classes() {
298
+ $classes = array( 'widefat', $this->_args['plural'] );
299
+ return apply_filters( 'code_snippets/list_table/table_classes', $classes );
300
+ }
301
+
302
+ /**
303
+ * Retrieve the 'views' of the table
304
+ *
305
+ * Example: active, inactive, recently active
306
+ *
307
+ * @return array A list of the view labels linked to the view
308
+ */
309
+ function get_views() {
310
+ global $totals, $status;
311
+
312
+ $status_links = array();
313
+ foreach ( $totals as $type => $count ) {
314
+
315
+ if ( ! $count ) {
316
+ continue;
317
+ }
318
+
319
+ switch ( $type ) {
320
+ case 'all':
321
+ $text = _n( 'All <span class="count">(%s)</span>', 'All <span class="count">(%s)</span>', $count, 'code-snippets' );
322
+ break;
323
+ case 'active':
324
+ $text = _n( 'Active <span class="count">(%s)</span>', 'Active <span class="count">(%s)</span>', $count, 'code-snippets' );
325
+ break;
326
+ case 'recently_activated':
327
+ $text = _n( 'Recently Active <span class="count">(%s)</span>', 'Recently Active <span class="count">(%s)</span>', $count, 'code-snippets' );
328
+ break;
329
+ case 'inactive':
330
+ $text = _n( 'Inactive <span class="count">(%s)</span>', 'Inactive <span class="count">(%s)</span>', $count, 'code-snippets' );
331
+ break;
332
+ }
333
+
334
+ $status_links[$type] = sprintf( '<a href="%s"%s>%s</a>',
335
+ add_query_arg( 'status', $type ),
336
+ ( $type === $status ) ? ' class="current"' : '',
337
+ sprintf( $text, number_format_i18n( $count ) )
338
+ );
339
+
340
+ }
341
+
342
+ return apply_filters( 'code_snippets/list_table/views', $status_links );
343
+ }
344
+
345
+ /**
346
+ * Gets the tags of the snippets currently being viewed in the table
347
+ * @since 2.0
348
+ */
349
+ function get_current_tags() {
350
+ global $snippets, $status;
351
+
352
+ /* If we're not viewing a snippets table, get all used tags instead */
353
+ if ( ! isset( $snippets, $status ) ) {
354
+ return get_all_snippet_tags();
355
+ }
356
+
357
+ $tags = array();
358
+
359
+ /* Merge all tags into a single array */
360
+ foreach ( $snippets[ $status ] as $snippet ) {
361
+ $tags = array_merge( $snippet->tags, $tags );
362
+ }
363
+
364
+ /* Remove duplicate tags */
365
+ return array_values( array_unique( $tags, SORT_REGULAR ) );
366
+ }
367
+
368
+ /**
369
+ * Add filters and extra actions above and below the table
370
+ * @param string $which Are the actions displayed on the table top or bottom
371
+ */
372
+ function extra_tablenav( $which ) {
373
+ global $status, $wpdb;
374
+
375
+ $screen = get_current_screen();
376
+
377
+ if ( 'top' === $which ) {
378
+
379
+ /* Tags dropdown filter */
380
+ $tags = $this->get_current_tags();
381
+
382
+ if ( count( $tags ) ) {
383
+ $query = isset( $_GET['tag'] ) ? $_GET['tag'] : '';
384
+
385
+ echo '<div class="alignleft actions">';
386
+ echo '<select name="tag">';
387
+
388
+ printf ( "<option %s value=''>%s</option>\n",
389
+ selected( $query, '', false ),
390
+ __( 'Show all tags', 'code-snippets' )
391
+ );
392
+
393
+ foreach ( $tags as $tag ) {
394
+
395
+ printf( "<option %s value='%s'>%s</option>\n",
396
+ selected( $query, $tag, false ),
397
+ esc_attr( $tag ),
398
+ $tag
399
+ );
400
+ }
401
+
402
+ echo '</select>';
403
+
404
+ submit_button( __( 'Filter', 'code-snippets' ), 'button', false, false );
405
+ echo '</div>';
406
+ }
407
+ }
408
+
409
+ echo '<div class="alignleft actions">';
410
+
411
+ if ( 'recently_activated' === $status )
412
+ submit_button( __( 'Clear List', 'code-snippets' ), 'secondary', 'clear-recent-list', false );
413
+
414
+ do_action( 'code_snippets/list_table/actions', $which );
415
+
416
+ echo '</div>';
417
+ }
418
+
419
+ /**
420
+ * Output form fields needed to preserve important
421
+ * query vars over form submissions
422
+ *
423
+ * @param string $context In what context are the fields being outputted?
424
+ */
425
+ function required_form_fields( $context = 'main' ) {
426
+
427
+ $vars = apply_filters(
428
+ 'code_snippets/list_table/required_form_fields',
429
+ array( 'page', 's', 'status', 'paged', 'tag' ),
430
+ $context
431
+ );
432
+
433
+ if ( 'search_box' === $context ) {
434
+ /* Remove the 's' var if we're doing this for the search box */
435
+ $vars = array_diff( $vars, array( 's' ) );
436
+ }
437
+
438
+ foreach ( $vars as $var ) {
439
+ if ( ! empty( $_REQUEST[ $var ] ) ) {
440
+ printf ( '<input type="hidden" name="%s" value="%s" />', $var, $_REQUEST[ $var ] );
441
+ print "\n";
442
+ }
443
+ }
444
+
445
+ do_action( 'code_snippets/list_table/print_required_form_fields', $context );
446
+ }
447
+
448
+
449
+ /**
450
+ * Clear the recently activated snippets list if we've clicked the button
451
+ * @return string The action to execute
452
+ */
453
+ function current_action() {
454
+ if ( isset( $_POST['clear-recent-list'] ) ) {
455
+ $action = 'clear-recent-list';
456
+ } else {
457
+ $action = parent::current_action();
458
+ }
459
+ return apply_filters( 'code_snippets/list_table/current_action', $action );
460
+ }
461
+
462
+ /**
463
+ * Processes a bulk action
464
+ *
465
+ * @uses activate_snippet() To activate snippets
466
+ * @uses deactivate_snippet() To deactivate snippets
467
+ * @uses delete_snippet() To delete snippets
468
+ * @uses export_snippet() To export selected snippets
469
+ * @uses wp_redirect() To pass the results to the current page
470
+ * @uses add_query_arg() To append the results to the current URI
471
+ */
472
+ function process_bulk_actions() {
473
+ $network = get_current_screen()->is_network;
474
+
475
+ if ( isset( $_GET['action'], $_GET['id'] ) ) :
476
+
477
+ $id = absint( $_GET['id'] );
478
+ $action = sanitize_key( $_GET['action'] );
479
+ $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'action', 'id' ) );
480
+
481
+ if ( 'activate' === $action ) {
482
+ activate_snippet( $id, $network );
483
+ }
484
+ elseif ( 'deactivate' === $action ) {
485
+ deactivate_snippet( $id, $network );
486
+ }
487
+ elseif ( 'delete' === $action ) {
488
+ delete_snippet( $id, $network );
489
+ }
490
+ elseif ( 'export' === $action ) {
491
+ export_snippets( $id, $network );
492
+ }
493
+ elseif ( 'export-php' === $action ) {
494
+ export_snippets( $id, $network, 'php');
495
+ }
496
+
497
+ if ( ! in_array( $action, array( 'export', 'export-php' ) ) ) {
498
+ wp_redirect( apply_filters(
499
+ "code_snippets/{$action}_redirect",
500
+ add_query_arg( $action, true )
501
+ ) );
502
+ }
503
+
504
+ endif;
505
+
506
+ if ( ! isset( $_POST['ids'] ) ) {
507
+ return;
508
+ }
509
+
510
+ $ids = $_POST['ids'];
511
+
512
+ $_SERVER['REQUEST_URI'] = remove_query_arg( array( 'activate', 'deactivate', 'delete', 'activate-multi', 'deactivate-multi', 'delete-multi' ) );
513
+
514
+ switch( $this->current_action() ) {
515
+
516
+ case 'activate-selected':
517
+ foreach ( $ids as $id ) {
518
+ activate_snippet( $id, $network );
519
+ }
520
+ wp_redirect( add_query_arg( 'activate-multi', true ) );
521
+ break;
522
+
523
+ case 'deactivate-selected':
524
+ foreach ( $ids as $id ) {
525
+ deactivate_snippet( $id, $network );
526
+ }
527
+ wp_redirect( add_query_arg( 'deactivate-multi', true ) );
528
+ break;
529
+
530
+ case 'export-selected':
531
+ export_snippets( $ids, $network );
532
+ break;
533
+
534
+ case 'export-php-selected':
535
+ export_snippets( $ids, $network, 'php');
536
+ break;
537
+
538
+ case 'delete-selected':
539
+ foreach( $ids as $id ) {
540
+ delete_snippet( $id, $network );
541
+ }
542
+ wp_redirect( add_query_arg( 'delete-multi', true ) );
543
+ break;
544
+
545
+ case 'clear-recent-list':
546
+ if ( $network ) {
547
+ update_site_option( 'recently_activated_snippets', array() );
548
+ } else {
549
+ update_option( 'recently_activated_snippets', array() );
550
+ }
551
+ break;
552
+ }
553
+ }
554
+
555
+ /**
556
+ * Message to display if no snippets are found
557
+ */
558
+ function no_items() {
559
+ printf(
560
+ __( 'You do not appear to have any snippets available at this time. <a href="%s">Add New&rarr;</a>', 'code-snippets' ),
561
+ code_snippets_get_menu_url( 'add' )
562
+ );
563
+ }
564
+
565
+ /**
566
+ * Prepares the items to later display in the table.
567
+ * Should run before any headers are sent.
568
+ */
569
+ function prepare_items() {
570
+ global $status, $snippets, $totals, $page, $orderby, $order, $s;
571
+
572
+ wp_reset_vars( array( 'orderby', 'order', 's' ) );
573
+
574
+ $screen = get_current_screen();
575
+ $user = get_current_user_id();
576
+
577
+ /* First, lets process the bulk actions */
578
+ $this->process_bulk_actions();
579
+
580
+ $snippets = array(
581
+ 'all' => apply_filters( 'code_snippets/list_table/get_snippets', get_snippets( $screen->is_network ) ),
582
+ 'active' => array(),
583
+ 'inactive' => array(),
584
+ 'recently_activated' => array(),
585
+ );
586
+
587
+ /* Filter snippets by tag */
588
+ if ( isset( $_POST['tag'] ) ) {
589
+
590
+ if ( ! empty( $_POST['tag'] ) ) {
591
+ wp_redirect( add_query_arg( 'tag', $_POST['tag'] ) );
592
+ }
593
+ else {
594
+ wp_redirect( remove_query_arg( 'tag' ) );
595
+ }
596
+ }
597
+
598
+ if ( ! empty( $_GET['tag'] ) ) {
599
+ $snippets['all'] = array_filter( $snippets['all'], array( $this, '_tags_filter_callback' ) );
600
+ }
601
+
602
+ /* Filter snippets based on search query */
603
+ if ( $s ) {
604
+ $snippets['all'] = array_filter( $snippets['all'], array( $this, '_search_callback' ) );
605
+ }
606
+
607
+ if ( $screen->is_network ) {
608
+ $recently_activated = get_site_option( 'recently_activated_snippets', array() );
609
+ } else {
610
+ $recently_activated = get_option( 'recently_activated_snippets', array() );
611
+ }
612
+
613
+ $one_week = 7*24*60*60;
614
+ foreach ( $recently_activated as $key => $time ) {
615
+
616
+ if ( $time + $one_week < time() ) {
617
+ unset( $recently_activated[$key] );
618
+ }
619
+ }
620
+
621
+ if ( $screen->is_network ) {
622
+ update_site_option( 'recently_activated_snippets', $recently_activated );
623
+ } else {
624
+ update_option( 'recently_activated_snippets', $recently_activated );
625
+ }
626
+
627
+ foreach ( (array) $snippets['all'] as $snippet ) {
628
+ /* Filter into individual sections */
629
+ if ( $snippet->active ) {
630
+ $snippets['active'][] = $snippet;
631
+ } else {
632
+ if ( isset( $recently_activated[ $snippet->id ] ) ) // Was the snippet recently activated?
633
+ $snippets['recently_activated'][] = $snippet;
634
+ $snippets['inactive'][] = $snippet;
635
+ }
636
+ }
637
+
638
+ $totals = array();
639
+ foreach ( $snippets as $type => $list ) {
640
+ $totals[ $type ] = count( $list );
641
+ }
642
+
643
+ if ( empty( $snippets[ $status ] ) ) {
644
+ $status = 'all';
645
+ }
646
+
647
+ $data = $snippets[ $status ];
648
+
649
+ /*
650
+ * First, lets decide how many records per page to show
651
+ * by getting the user's setting in the Screen Options
652
+ * panel.
653
+ */
654
+ $sort_by = $screen->get_option( 'per_page', 'option' );
655
+ $screen_option = $screen->get_option( 'per_page', 'option' );
656
+ $per_page = get_user_meta( $user, $screen_option, true );
657
+
658
+ if ( empty ( $per_page ) || $per_page < 1 ) {
659
+ $per_page = $screen->get_option( 'per_page', 'default' );
660
+ }
661
+
662
+ $per_page = (int) $per_page;
663
+
664
+ $this->_column_headers = $this->get_column_info();
665
+
666
+ /**
667
+ * This checks for sorting input and sorts the data in our array accordingly.
668
+ *
669
+ * @ignore
670
+ */
671
+ function usort_reorder( $a, $b ) {
672
+
673
+ /* If no sort, default to ID */
674
+ $orderby = (
675
+ ! empty( $_REQUEST['orderby'] )
676
+ ? $_REQUEST['orderby']
677
+ : apply_filters( 'code_snippets/list_table/default_orderby', 'id' )
678
+ );
679
+
680
+ /* If no order, default to ascending */
681
+ $order = (
682
+ ! empty( $_REQUEST['order'] )
683
+ ? $_REQUEST['order']
684
+ : apply_filters( 'code_snippets/list_table/default_order', 'asc' )
685
+ );
686
+
687
+ /* Determine sort order */
688
+ if ( 'id' === $orderby ) {
689
+ $result = $a->$orderby - $b->$orderby; // get the result for numerical data
690
+ } else {
691
+ $result = strcmp( $a->$orderby, $b->$orderby ); // get the result for string data
692
+ }
693
+
694
+ /* Send final sort direction to usort */
695
+ return ( 'asc' === $order ) ? $result : -$result;
696
+ }
697
+
698
+ usort( $data, 'usort_reorder' );
699
+
700
+ /*
701
+ * Let's figure out what page the user is currently
702
+ * looking at.
703
+ */
704
+ $current_page = $this->get_pagenum();
705
+
706
+ /*
707
+ * Let's check how many items are in our data array.
708
+ */
709
+ $total_items = count( $data );
710
+
711
+ /*
712
+ * The WP_List_Table class does not handle pagination for us, so we need
713
+ * to ensure that the data is trimmed to only the current page.
714
+ */
715
+ $data = array_slice( $data, ( ( $current_page - 1 ) * $per_page ), $per_page );
716
+
717
+ /*
718
+ * Now we can add our *sorted* data to the items property, where
719
+ * it can be used by the rest of the class.
720
+ */
721
+ $this->items = $data;
722
+
723
+ /*
724
+ * We also have to register our pagination options & calculations.
725
+ */
726
+ $this->set_pagination_args( array(
727
+ 'total_items' => $total_items, // WE have to calculate the total number of items
728
+ 'per_page' => $per_page, // WE have to determine how many items to show on a page
729
+ 'total_pages' => ceil($total_items/$per_page) // WE have to calculate the total number of pages
730
+ ) );
731
+ }
732
+
733
+ /**
734
+ * Used internally
735
+ * @ignore
736
+ */
737
+ function _search_callback( $snippet ) {
738
+ static $term;
739
+ if ( is_null( $term ) ) {
740
+ $term = stripslashes( $_REQUEST['s'] );
741
+ }
742
+
743
+ foreach ( $snippet as $value ) {
744
+
745
+ if ( is_string( $value ) ) {
746
+ if ( false !== stripos( $value, $term ) ) {
747
+ return true;
748
+ }
749
+ }
750
+ elseif ( is_array( $value ) ) {
751
+ if ( false !== in_array( $term, $value ) ) {
752
+ return true;
753
+ }
754
+ }
755
+ }
756
+
757
+ return false;
758
+ }
759
+
760
+
761
+ /**
762
+ * Used internally
763
+ * @ignore
764
+ */
765
+ function _tags_filter_callback( $snippet ) {
766
+ $tags = explode( ',', $_GET['tag'] );
767
+
768
+ foreach ( $tags as $tag ) {
769
+ if ( in_array( $tag, $snippet->tags ) ) {
770
+ return true;
771
+ }
772
+ }
773
+ }
774
+
775
+ /**
776
+ * Display a notice showing the current search terms
777
+ *
778
+ * @since 1.7
779
+ * @access public
780
+ */
781
+ public function search_notice() {
782
+ if ( ! empty( $_REQUEST['s'] ) || ! empty( $_GET['tag'] ) ) {
783
+
784
+ echo '<span class="subtitle">' . __( 'Search results', 'code-snippets' );
785
+
786
+ if ( ! empty ( $_REQUEST['s'] ) ) {
787
+ echo sprintf ( __( ' for &#8220;%s&#8221;', 'code-snippets' ), esc_html( $_REQUEST['s'] ) );
788
+ }
789
+
790
+ if ( ! empty( $_GET['tag'] ) ) {
791
+ echo sprintf ( __(' in tag &#8220;%s&#8221;', 'code-snippets' ), $_GET['tag'] );
792
+ }
793
+
794
+ echo '</span>';
795
+
796
+ printf (
797
+ '&nbsp;<a class="button clear-filters" href="%s">' . __( 'Clear Filters', 'code-snippets' ) . '</a>',
798
+ remove_query_arg( array( 's', 'tag' ) )
799
+ );
800
+ }
801
+ }
802
+
803
+ /**
804
+ * Outputs content for a single row of the table
805
+ * @param object $snippet The snippet being used for the current row
806
+ */
807
+ function single_row( $snippet ) {
808
+ static $row_class = '';
809
+ $row_class = ( $snippet->active ? 'active' : 'inactive' );
810
+ printf ( '<tr class="%s">', $row_class );
811
+ $this->single_row_columns( $snippet );
812
+ echo '</tr>';
813
+ }
814
+
815
+ } // end of class
includes/manage/manage.php ADDED
@@ -0,0 +1,106 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Functions to handle the manage snippets menu
5
+ *
6
+ * @package Code_Snippets
7
+ * @subpackage Manage
8
+ */
9
+
10
+ /**
11
+ * Register the top-level 'Snippets' menu and associated 'Manage' subpage
12
+ *
13
+ * @since 1.0
14
+ * @access private
15
+ *
16
+ * @uses add_menu_page() To register a top-level menu
17
+ * @uses add_submenu_page() To register a sub-menu
18
+ */
19
+ function code_snippets_add_manage_menu() {
20
+
21
+ $hook = add_menu_page(
22
+ __( 'Snippets', 'code-snippets' ),
23
+ __( 'Snippets', 'code-snippets' ),
24
+ get_snippets_cap(),
25
+ code_snippets_get_menu_slug(),
26
+ 'code_snippets_render_manage_menu',
27
+ 'div', // icon is added through CSS
28
+ is_network_admin() ? 21 : 67
29
+ );
30
+
31
+ add_submenu_page(
32
+ code_snippets_get_menu_slug(),
33
+ __( 'Snippets', 'code-snippets' ),
34
+ __( 'Manage', 'code-snippets' ),
35
+ get_snippets_cap(),
36
+ code_snippets_get_menu_slug(),
37
+ 'code_snippets_render_manage_menu'
38
+ );
39
+
40
+ add_action( 'load-' . $hook, 'code_snippets_load_manage_menu' );
41
+ }
42
+
43
+ add_action( 'admin_menu', 'code_snippets_add_manage_menu', 5 );
44
+ add_action( 'network_admin_menu', 'code_snippets_add_manage_menu', 5 );
45
+
46
+ /**
47
+ * Displays the manage snippets menu
48
+ *
49
+ * @since 2.0
50
+ */
51
+ function code_snippets_render_manage_menu() {
52
+ require plugin_dir_path( __FILE__ ) . 'admin-messages.php';
53
+ require plugin_dir_path( __FILE__ ) . 'admin.php';
54
+ }
55
+
56
+ /**
57
+ * Initializes the list table class and loads the help tabs
58
+ * for the Manage Snippets page
59
+ *
60
+ * @since 1.0
61
+ * @access private
62
+ */
63
+ function code_snippets_load_manage_menu() {
64
+
65
+ /* Make sure the user has permission to be here */
66
+ if ( ! current_user_can( get_snippets_cap() ) ) {
67
+ wp_die( __( 'You are not authorized to access this page.', 'code-snippets' ) );
68
+ }
69
+
70
+ /* Load stylesheet for this page */
71
+ add_action( 'admin_enqueue_scripts', 'code_snippets_manage_menu_assets' );
72
+
73
+ /* Create the snippet tables if they don't exist */
74
+ create_code_snippets_tables( true, true );
75
+
76
+ /* Load the screen help tabs */
77
+ require plugin_dir_path( __FILE__ ) . 'admin-help.php';
78
+
79
+ /* Initialize the snippet table class */
80
+ require_once plugin_dir_path( __FILE__ ) . 'class-list-table.php';
81
+ global $code_snippets_list_table;
82
+ $code_snippets_list_table = new Code_Snippets_List_Table();
83
+ $code_snippets_list_table->prepare_items();
84
+ }
85
+
86
+ /**
87
+ * Enqueue the manage menu stylesheet
88
+ *
89
+ * @since 2.0
90
+ * @uses wp_enqueue_style() To add the stylesheet to the queue
91
+ * @param string $hook The current page hook, to be compared with the manage snippets page hook
92
+ */
93
+ function code_snippets_manage_menu_assets( $hook ) {
94
+
95
+ /* Only load the stylesheet on the manage snippets page */
96
+ if ( $hook !== code_snippets_get_menu_hook() ) {
97
+ return;
98
+ }
99
+
100
+ wp_enqueue_style(
101
+ 'code-snippets-manage',
102
+ plugins_url( 'css/min/manage-snippets.css', CODE_SNIPPETS_FILE ),
103
+ false,
104
+ CODE_SNIPPETS_VERSION
105
+ );
106
+ }
includes/settings/admin.php ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * This file handles the settings admin menu
5
+ * @package Code_Snippets
6
+ */
7
+
8
+ /**
9
+ * Register the setting sub-menu
10
+ *
11
+ * @since 2.0
12
+ * @access private
13
+ *
14
+ * @uses add_submenu_page() To register a sub-menu
15
+ */
16
+ function code_snippets_add_settings_menu() {
17
+
18
+ add_submenu_page(
19
+ code_snippets_get_menu_slug(),
20
+ __( 'Snippets Settings', 'code-snippets' ),
21
+ __( 'Settings', 'code-snippets' ),
22
+ get_snippets_cap(),
23
+ code_snippets_get_menu_slug( 'settings' ),
24
+ 'code_snippets_render_settings_menu'
25
+ );
26
+ }
27
+
28
+ add_action( 'admin_menu', 'code_snippets_add_settings_menu' );
29
+
30
+ /**
31
+ * Displays the settings menu
32
+ *
33
+ * @since 2.0
34
+ */
35
+ function code_snippets_render_settings_menu() {
36
+ ?>
37
+ <div class="wrap">
38
+
39
+ <?php screen_icon(); ?>
40
+ <h2><?php esc_html_e( 'Settings', 'code-snippets' ); ?></h2>
41
+
42
+ <?php settings_errors( 'code-snippets-settings-notices' ); ?>
43
+
44
+ <form action="options.php" method="post">
45
+ <?php settings_fields( 'code-snippets' ); ?>
46
+ <table class="form-table">
47
+ <?php do_settings_sections( 'code-snippets' ); ?>
48
+ </table>
49
+ <?php submit_button(); ?>
50
+ </form>
51
+
52
+ </div>
53
+ <?php
54
+ }
includes/settings/editor-preview.php ADDED
@@ -0,0 +1,156 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ function code_snippets_editor_settings_preview_assets( $hook ) {
4
+
5
+ /* Only load on the settings page */
6
+ if ( code_snippets_get_menu_hook( 'settings' ) !== $hook ) {
7
+ return;
8
+ }
9
+
10
+ /* Enqueue scripts for the editor preview */
11
+ code_snippets_enqueue_codemirror();
12
+
13
+ /* Enqueue ALL themes */
14
+ $themes_dir = plugin_dir_path( CODE_SNIPPETS_FILE ) . 'vendor/codemirror/theme/';
15
+ $themes = glob( $themes_dir . '*.css' );
16
+
17
+ foreach ( $themes as $theme ) {
18
+ $theme = str_replace( $themes_dir, '', $theme );
19
+ $theme = str_replace( '.css', '', $theme );
20
+
21
+ wp_enqueue_style(
22
+ 'code-snippets-codemirror-theme-' . $theme,
23
+ plugins_url( "vendor/codemirror/theme/$theme.css", CODE_SNIPPETS_FILE ),
24
+ array( 'code-snippets-codemirror' )
25
+ );
26
+ }
27
+
28
+ /* Enqueue jQuery */
29
+ wp_enqueue_script( 'jquery' );
30
+ }
31
+
32
+ add_action( 'admin_enqueue_scripts', 'code_snippets_editor_settings_preview_assets' );
33
+
34
+ /**
35
+ * Render a theme select field
36
+ */
37
+ function code_snippets_codemirror_theme_select_field( $atts ) {
38
+
39
+ $saved_value = code_snippets_get_setting( $atts['section'], $atts['id'] );
40
+
41
+ echo '<select name="code_snippets_settings[editor][theme]">';
42
+
43
+ echo '<option value="default"' . selected( 'default', $saved_value, false ) . '>default</option>';
44
+
45
+ /* Fetch all theme CSS files */
46
+ $themes_dir = plugin_dir_path( CODE_SNIPPETS_FILE ) . 'vendor/codemirror/theme/';
47
+ $themes = glob( $themes_dir . '*.css' );
48
+
49
+ /* Print dropdown entry for each theme */
50
+ foreach ( $themes as $theme ) {
51
+
52
+ /* Extract theme name from path */
53
+ $theme = str_replace( $themes_dir, '', $theme );
54
+ $theme = str_replace( '.css', '', $theme );
55
+
56
+ /* Skip mobile themes */
57
+ if ( 'ambiance-mobile' === $theme ) {
58
+ continue;
59
+ }
60
+
61
+ printf (
62
+ '<option value="%1$s"%2$s>%1$s</option>',
63
+ $theme,
64
+ selected( $theme, $saved_value, false )
65
+ );
66
+ }
67
+
68
+ echo '</select>';
69
+ }
70
+
71
+ function code_snippets_settings_editor_preview() {
72
+
73
+ $example_content = "
74
+ function example_custom_admin_footer_text( \$text ) {
75
+ return 'Thank you for visiting <a href=\"' . get_home_url() . '\">' . get_bloginfo( 'name' ) . '</a>.';
76
+ }
77
+
78
+ add_filter( 'admin_footer_text', 'example_custom_admin_footer_text' );";
79
+
80
+ $atts = array(
81
+ 'mode' => 'text/x-php',
82
+ 'value' => $example_content
83
+ );
84
+
85
+ ?>
86
+
87
+ <div style="max-width: 800px" id="code_snippets_editor_preview"></div>
88
+
89
+ <script>
90
+ (function( $ ) {
91
+ 'use strict';
92
+
93
+ $(function() {
94
+
95
+ // Load CodeMirror
96
+ var atts = <?php echo code_snippets_get_editor_atts( $atts, true ); ?>;
97
+ var editor = CodeMirror(document.getElementById('code_snippets_editor_preview'), atts);
98
+
99
+ // Dynamically change editor settings
100
+
101
+ <?php
102
+
103
+ $fields = code_snippets_get_settings_fields();
104
+ $fields = $fields['editor'];
105
+
106
+ $types = wp_list_pluck( $fields, 'type', 'id' );
107
+ $codemirror_atts = wp_list_pluck( $fields, 'codemirror', 'id' );
108
+
109
+ foreach ( $codemirror_atts as $setting => $att_name ) {
110
+
111
+ switch ( $types[ $setting ] ) {
112
+
113
+ case 'codemirror_theme_select':
114
+ ?>
115
+
116
+ $( 'select[name="code_snippets_settings[editor][<?php echo $setting; ?>]"]' ).change( function () {
117
+ editor.setOption( '<?php echo $att_name; ?>', $(this).val() );
118
+ } );
119
+
120
+ <?php
121
+ break;
122
+
123
+ case 'checkbox':
124
+ ?>
125
+
126
+ $( 'input[name="code_snippets_settings[editor][<?php echo $setting; ?>]"]' ).change( function () {
127
+ editor.setOption( '<?php echo $att_name; ?>', $(this).is(':checked') );
128
+ } );
129
+
130
+ <?php
131
+ break;
132
+
133
+
134
+ case 'number':
135
+ ?>
136
+
137
+ $( 'input[name="code_snippets_settings[editor][<?php echo $setting; ?>]"]' ).change( function () {
138
+ editor.setOption( '<?php echo $att_name; ?>', $(this).val() );
139
+ } );
140
+
141
+ <?php
142
+ break;
143
+
144
+ }
145
+
146
+ }
147
+
148
+ ?>
149
+
150
+ });
151
+
152
+ }(jQuery));
153
+ </script>
154
+
155
+ <?php
156
+ }
includes/settings/settings-fields.php ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * This file handles outputting the settings fields
5
+ * @package Code_Snippets
6
+ */
7
+
8
+ /**
9
+ * Render a checkbox field for a setting
10
+ * @param array $atts The setting field's attributes
11
+ */
12
+ function code_snippets_checkbox_field( $atts ) {
13
+ $saved_value = code_snippets_get_setting( $atts['section'], $atts['id'] );
14
+ $input_name = sprintf( 'code_snippets_settings[%s][%s]', $atts['section'], $atts['id'] );
15
+
16
+ $output = sprintf (
17
+ '<input type="checkbox" name="%s"%s>',
18
+ $input_name,
19
+ checked( $saved_value, true, false )
20
+ );
21
+
22
+ if ( isset( $atts['label'] ) ) {
23
+ printf ( '<label for="%s">%s %s</label>', $input_name, $output, $atts['label'] );
24
+ } else {
25
+ echo $output;
26
+ }
27
+ }
28
+
29
+ /**
30
+ * Render a number select field for an editor setting
31
+ * @param array $atts The setting field's attributes
32
+ */
33
+ function code_snippets_number_field( $atts ) {
34
+
35
+ printf (
36
+ '<input type="number" name="code_snippets_settings[%s][%s]" value="%s">',
37
+ $atts['section'],
38
+ $atts['id'],
39
+ code_snippets_get_setting( $atts['section'], $atts['id'] )
40
+ );
41
+ }
includes/settings/settings.php ADDED
@@ -0,0 +1,243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * This file registers the settings
5
+ * @package Code_Snippets
6
+ */
7
+
8
+ /**
9
+ * Retrieve the default setting values
10
+ * @return array
11
+ */
12
+ function code_snippets_get_default_settings() {
13
+ $fields = code_snippets_get_settings_fields();
14
+ $defaults = array();
15
+
16
+ foreach ( $fields as $section_id => $section_fields ) {
17
+ $defaults[ $section_id ] = wp_list_pluck( $section_fields, 'default', 'id' );
18
+ }
19
+
20
+ return $defaults;
21
+ }
22
+
23
+ /*
24
+ * Retrieve the setting values from the database.
25
+ * If a setting does not exist in the database, the default value will be returned.
26
+ * @return array
27
+ */
28
+ function code_snippets_get_settings() {
29
+ $saved = get_option( 'code_snippets_settings', array() );
30
+ $default = code_snippets_get_default_settings();
31
+ return wp_parse_args( $saved, $default );
32
+ }
33
+
34
+ /**
35
+ * Retrieve an individual setting field value
36
+ * @param string $section The ID of the section the setting belongs to
37
+ * @param string $field The ID of the setting field
38
+ * @return array
39
+ */
40
+ function code_snippets_get_setting( $section, $field ) {
41
+ $settings = code_snippets_get_settings();
42
+ return $settings[ $section ][ $field ];
43
+ }
44
+
45
+ /**
46
+ * Retrieve the settings sections
47
+ * @return array
48
+ */
49
+ function code_snippets_get_settings_sections() {
50
+ $sections = array(
51
+ 'general' => __( 'General', 'code-snippets' ),
52
+ 'editor' => __( 'Editor', 'code-snippets' ),
53
+ );
54
+
55
+ return apply_filters( 'code_snippets_settings_sections', $sections );
56
+ }
57
+
58
+ /**
59
+ * Retrieve the settings fields
60
+ * @return array
61
+ */
62
+ function code_snippets_get_settings_fields() {
63
+ $settings = array();
64
+
65
+ $settings['general'] = array(
66
+ array(
67
+ 'id' => 'activate_by_default',
68
+ 'name' =>__( 'Activate by Default', 'code-snippets' ),
69
+ 'type' => 'checkbox',
70
+ 'label' => __( "Make the 'Save and Activate' button the default action when saving a snippet.", 'code-snippets' ),
71
+ 'default' => false,
72
+ ),
73
+ );
74
+
75
+ /* Editor settings section */
76
+
77
+ $settings['editor'] = array(
78
+ array(
79
+ 'id' => 'theme',
80
+ 'name' => __( 'Theme', 'code-snippets' ),
81
+ 'type' => 'codemirror_theme_select',
82
+ 'default' => 'default',
83
+ 'codemirror' => 'theme',
84
+ ),
85
+
86
+ array(
87
+ 'id' => 'indent_with_tabs',
88
+ 'name' => __( 'Indent With Tabs', 'code-snippets' ),
89
+ 'type' => 'checkbox',
90
+ 'label' => __( 'Use hard tabs (not spaces) for indentation.', 'code-snippets' ),
91
+ 'default' => true,
92
+ 'codemirror' => 'indentWithTabs',
93
+ ),
94
+
95
+ array(
96
+ 'id' => 'tab_size',
97
+ 'name' => __( 'Tab Size', 'code-snippets' ),
98
+ 'type' => 'number',
99
+ 'label' => __( 'The width of a tab character.', 'code-snippets' ),
100
+ 'default' => 4,
101
+ 'codemirror' => 'tabSize',
102
+ ),
103
+
104
+ array(
105
+ 'id' => 'indent_unit',
106
+ 'name' => __( 'Indent Unit', 'code-snippets' ),
107
+ 'type' => 'number',
108
+ 'label' => __( 'How many spaces a block should be indented.', 'code-snippets' ),
109
+ 'default' => 2,
110
+ 'codemirror' => 'indentUnit',
111
+ ),
112
+
113
+ array(
114
+ 'id' => 'wrap_lines',
115
+ 'name' => __( 'Wrap Lines', 'code-snippets' ),
116
+ 'type' => 'checkbox',
117
+ 'label' => __( 'Whether the editor should scroll or wrap for long lines.', 'code-snippets' ),
118
+ 'default' => true,
119
+ 'codemirror' => 'lineWrapping',
120
+ ),
121
+
122
+ array(
123
+ 'id' => 'line_numbers',
124
+ 'name' => __( 'Line Numbers', 'code-snippets' ),
125
+ 'type' => 'checkbox',
126
+ 'label' => __( 'Show line numbers to the left of the editor.', 'code-snippets' ),
127
+ 'default' => true,
128
+ 'codemirror' => 'lineNumbers',
129
+ ),
130
+
131
+ array(
132
+ 'id' => 'auto_close_brackets',
133
+ 'name' => __( 'Auto Close Brackets', 'code-snippets' ),
134
+ 'type' => 'checkbox',
135
+ 'label' => __( 'Auto-close brackets and quotes when typed.', 'code-snippets' ),
136
+ 'default' => true,
137
+ 'codemirror' => 'autoCloseBrackets',
138
+ ),
139
+
140
+ array(
141
+ 'id' => 'highlight_selection_matches',
142
+ 'name' => __( 'Highlight Selection Matches', 'code-snippets' ),
143
+ 'label' => __( 'Highlight all instances of a currently selected word.', 'code-snippets' ),
144
+ 'type' => 'checkbox',
145
+ 'default' => true,
146
+ 'codemirror' => 'highlightSelectionMatches',
147
+ ),
148
+ );
149
+
150
+ return apply_filters( 'code_snippets_settings_fields', $settings );
151
+ }
152
+
153
+ /**
154
+ * Register settings sections, fields, etc
155
+ */
156
+ function code_snippets_register_settings() {
157
+
158
+ /* Register the setting */
159
+ register_setting( 'code-snippets', 'code_snippets_settings', 'code_snippets_settings_validate' );
160
+
161
+ /* Register settings sections */
162
+ foreach ( code_snippets_get_settings_sections() as $section_id => $section_name ) {
163
+ add_settings_section(
164
+ 'code-snippets-' . $section_id,
165
+ $section_name,
166
+ '__return_empty_string',
167
+ 'code-snippets'
168
+ );
169
+ }
170
+
171
+ /* Register settings fields */
172
+ foreach ( code_snippets_get_settings_fields() as $section_id => $fields ) {
173
+
174
+ foreach ( $fields as $field ) {
175
+ add_settings_field(
176
+ 'code_snippets_' . $field['id'],
177
+ $field['name'],
178
+ "code_snippets_{$field['type']}_field",
179
+ 'code-snippets',
180
+ 'code-snippets-' . $section_id,
181
+ array_merge( $field, array( 'section' => $section_id ) )
182
+ );
183
+ }
184
+
185
+ }
186
+
187
+ /* Add editor preview as a field */
188
+ add_settings_field(
189
+ 'code_snippets_' . $field['id'],
190
+ __( 'Editor Preview', 'code-snippets' ),
191
+ 'code_snippets_settings_editor_preview',
192
+ 'code-snippets',
193
+ 'code-snippets-editor'
194
+ );
195
+ }
196
+
197
+ add_action( 'admin_init', 'code_snippets_register_settings' );
198
+
199
+ /**
200
+ * Validate the settings
201
+ * @param array $input
202
+ * @return array
203
+ */
204
+ function code_snippets_settings_validate( array $input ) {
205
+ $settings = code_snippets_get_settings();
206
+ $settings_fields = code_snippets_get_settings_fields();
207
+
208
+ // Don't directly loop through $input as it does not include as deselected checkboxes
209
+ foreach ( $settings_fields as $section_id => $fields ) {
210
+
211
+ // Loop through fields
212
+ foreach ( $fields as $field ) {
213
+ $field_id = $field['id'];
214
+
215
+ // Checkbox field
216
+ if ( 'checkbox' === $field['type'] ) {
217
+
218
+ $settings[ $section_id ][ $field_id ] = (
219
+ isset( $input[ $section_id ][ $field_id ] ) &&
220
+ 'on' === $input[ $section_id ][ $field_id ]
221
+ );
222
+
223
+ // Number field
224
+ } elseif ( 'number' == $field['type'] ) {
225
+ $settings[ $section_id ][ $field_id ] = absint( $input[ $section_id ][ $field_id ] );
226
+
227
+ // Other fields
228
+ } else {
229
+ $settings[ $section_id ][ $field_id ] = $input[ $section_id ][ $field_id ];
230
+ }
231
+ }
232
+ }
233
+
234
+ /* Add an updated message */
235
+ add_settings_error(
236
+ 'code-snippets-settings-notices',
237
+ 'settings-saved',
238
+ __( 'Settings saved.', 'code-snippets' ),
239
+ 'updated'
240
+ );
241
+
242
+ return $settings;
243
+ }
includes/snippet-ops.php ADDED
@@ -0,0 +1,493 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Functions to preform snippet operations
5
+ *
6
+ * @package Code_Snippets
7
+ */
8
+
9
+ /**
10
+ * Converts an array of snippet data into a snippet object
11
+ *
12
+ * @since 2.0
13
+ * @param mixed $data The snippet data to convert
14
+ * @return object The resulting snippet object
15
+ */
16
+ function build_snippet_object( $data = null ) {
17
+
18
+ $snippet = new stdClass;
19
+
20
+ /* Define an empty snippet object with default values */
21
+ $snippet->id = 0;
22
+ $snippet->name = '';
23
+ $snippet->description = '';
24
+ $snippet->code = '';
25
+ $snippet->tags = array();
26
+ $snippet->active = 0;
27
+ $snippet = apply_filters( 'code_snippets/build_default_snippet', $snippet );
28
+
29
+ if ( ! isset( $data ) ) {
30
+ return $snippet;
31
+ }
32
+ elseif ( is_object( $data ) ) {
33
+
34
+ /* If we already have a snippet object, merge it with the default */
35
+ return (object) array_merge( (array) $snippet, (array) $data );
36
+ }
37
+ elseif ( is_array( $data ) ) {
38
+
39
+ foreach ( $data as $field => $value ) {
40
+
41
+ /* Remove 'snippet_' prefix */
42
+ if ( 'snippet_' === substr( $field, 0, 8 ) ) {
43
+ $field = substr( $field, 8 );
44
+ }
45
+
46
+ /* Check the field is whitelisted */
47
+ if ( ! isset( $snippet->$field ) ) {
48
+ continue;
49
+ }
50
+
51
+ /* Update the field */
52
+ $snippet->$field = $value;
53
+ }
54
+
55
+ return apply_filters( 'code_snippets/build_snippet_object', $snippet, $data );
56
+ }
57
+
58
+ return $snippet;
59
+ }
60
+
61
+ /**
62
+ * Retrieve a list of snippets from the database
63
+ *
64
+ * @since 2.0
65
+ *
66
+ * @uses $wpdb To query the database for snippets
67
+ * @uses get_snippets_table_name() To dynamically retrieve the snippet table name
68
+ *
69
+ * @param boolean|null $multisite Retrieve multisite-wide or site-wide snippets?
70
+ * @return array An array of snippet objects
71
+ */
72
+ function get_snippets( $multisite = null ) {
73
+ global $wpdb;
74
+
75
+ $table = get_snippets_table_name( $multisite );
76
+ $snippets = $wpdb->get_results( "SELECT * FROM $table", ARRAY_A );
77
+
78
+ foreach ( $snippets as $index => $snippet ) {
79
+ $snippets[ $index ] = unescape_snippet_data( $snippet );
80
+ }
81
+
82
+ return apply_filters( 'code_snippets/get_snippets', $snippets, $multisite );
83
+ }
84
+
85
+ /**
86
+ * Gets all of the used tags from the database
87
+ * @since 2.0
88
+ */
89
+ function get_all_snippet_tags() {
90
+ global $wpdb;
91
+
92
+ /* Grab all tags from the database */
93
+ $tags = array();
94
+ $table = get_snippets_table_name();
95
+ $all_tags = $wpdb->get_col( "SELECT `tags` FROM $table" );
96
+
97
+ /* Merge all tags into a single array */
98
+ foreach ( $all_tags as $snippet_tags ) {
99
+ $snippet_tags = maybe_unserialize( $snippet_tags );
100
+ $snippet_tags = code_snippets_build_tags_array( $snippet_tags );
101
+ $tags = array_merge( $snippet_tags, $tags );
102
+ }
103
+
104
+ /* Remove duplicate tags */
105
+ return array_values( array_unique( $tags, SORT_REGULAR ) );
106
+ }
107
+
108
+ /**
109
+ * Make sure that the tags are a valid array
110
+ * @since 2.0
111
+ *
112
+ * @param mixed $tags The tags to convert into an array
113
+ * @return array The converted tags
114
+ */
115
+ function code_snippets_build_tags_array( $tags ) {
116
+
117
+ /* If there are no tags set, create a default empty array */
118
+ if ( empty( $tags ) ) {
119
+ $tags = array();
120
+ }
121
+
122
+ /* If the tags are set as a string, convert them into an array */
123
+ elseif ( is_string( $tags ) ) {
124
+ $tags = str_replace( ', ', ',', $tags );
125
+ $tags = explode( ',', $tags );
126
+ }
127
+
128
+ /* If we still don't have an array, just convert whatever we do have into one */
129
+ if ( ! is_array( $tags ) ) {
130
+ $tags = (array) $tags;
131
+ }
132
+
133
+ return $tags;
134
+ }
135
+
136
+ /**
137
+ * Escape snippet data for inserting into the database
138
+ *
139
+ * @since 2.0
140
+ * @param mixed $snippet An object or array containing the data to escape
141
+ * @return object The resulting snippet object, with data escaped
142
+ */
143
+ function escape_snippet_data( $snippet ) {
144
+
145
+ $snippet = build_snippet_object( $snippet );
146
+
147
+ /* Remove <?php and <? from beginning of snippet */
148
+ $snippet->code = preg_replace( '|^[\s]*<\?(php)?|', '', $snippet->code );
149
+
150
+ /* Remove ?> from end of snippet */
151
+ $snippet->code = preg_replace( '|\?>[\s]*$|', '', $snippet->code );
152
+
153
+ /* Escape the data */
154
+ $snippet->id = absint( $snippet->id );
155
+
156
+ /* Store tags as a string, with tags separated by commas */
157
+ $snippet->tags = code_snippets_build_tags_array( $snippet->tags );
158
+ $snippet->tags = implode( ', ', $snippet->tags );
159
+
160
+ return apply_filters( 'code_snippets/escape_snippet_data', $snippet );
161
+ }
162
+
163
+ /**
164
+ * Unescape snippet data after retrieval from the database
165
+ * ready for use
166
+ *
167
+ * @since 2.0
168
+ * @param mixed $snippet An object or array containing the data to unescape
169
+ * @return object The resulting snippet object, with data unescaped
170
+ */
171
+ function unescape_snippet_data( $snippet ) {
172
+ $snippet = build_snippet_object( $snippet );
173
+
174
+ /* Ensure the tags are a valid array */
175
+ $snippet->tags = code_snippets_build_tags_array( $snippet->tags );
176
+
177
+ return apply_filters( 'code_snippets/unescape_snippet_data', $snippet );
178
+ }
179
+
180
+ /**
181
+ * Retrieve a single snippets from the database.
182
+ * Will return empty snippet object if no snippet
183
+ * ID is specified
184
+ *
185
+ * @since 2.0
186
+ *
187
+ * @uses $wpdb To query the database for snippets
188
+ * @uses get_snippets_table_name() To dynamically retrieve the snippet table name
189
+ *
190
+ * @param int $id The ID of the snippet to retrieve. 0 to build a new snippet
191
+ * @param boolean|null $multisite Retrieve a multisite-wide or site-wide snippet?
192
+ * @return object A single snippet object
193
+ */
194
+ function get_snippet( $id = 0, $multisite = null ) {
195
+ global $wpdb;
196
+
197
+ $id = absint( $id );
198
+ $table = get_snippets_table_name( $multisite );
199
+
200
+ if ( 0 !== $id ) {
201
+
202
+ /* Retrieve the snippet from the database */
203
+ $snippet = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM $table WHERE id = %d", $id ) );
204
+
205
+ /* Unescape the snippet data, ready for use */
206
+ $snippet = unescape_snippet_data( $snippet );
207
+
208
+ } else {
209
+
210
+ /* Get an empty snippet object */
211
+ $snippet = build_snippet_object();
212
+ }
213
+ return apply_filters( 'code_snippets/get_snippet', $snippet, $id, $multisite );
214
+ }
215
+
216
+ /**
217
+ * Activates a snippet
218
+ *
219
+ * @since 2.0
220
+ *
221
+ * @uses $wpdb To set the snippet's active status
222
+ *
223
+ * @param array $id The ID of the snippet to activate
224
+ * @param boolean|null $multisite Are the snippets multisite-wide or site-wide?
225
+ */
226
+ function activate_snippet( $id, $multisite = null ) {
227
+ global $wpdb;
228
+ $table = get_snippets_table_name( $multisite );
229
+
230
+ $wpdb->update(
231
+ $table,
232
+ array( 'active' => '1' ),
233
+ array( 'id' => $id ),
234
+ array( '%d' ),
235
+ array( '%d' )
236
+ );
237
+
238
+ do_action( 'code_snippets/activate_snippet', $id, $multisite );
239
+ }
240
+
241
+ /**
242
+ * Deactivate a snippet
243
+ *
244
+ * @since 2.0
245
+ *
246
+ * @uses $wpdb To set the snippets' active status
247
+ *
248
+ * @param array $id The ID of the snippet to deactivate
249
+ * @param boolean|null $multisite Are the snippets multisite-wide or site-wide?
250
+ */
251
+ function deactivate_snippet( $id, $multisite = null ) {
252
+ global $wpdb;
253
+ $table = get_snippets_table_name( $multisite );
254
+
255
+ /* Set the snippet to active */
256
+
257
+ $wpdb->update(
258
+ $table,
259
+ array( 'active' => '0' ),
260
+ array( 'id' => $id ),
261
+ array( '%d' ),
262
+ array( '%d' )
263
+ );
264
+
265
+ /* Update the recently active list */
266
+
267
+ $recently_active = array( $id => time() );
268
+
269
+ if ( $table === $wpdb->ms_snippets ) {
270
+
271
+ update_site_option(
272
+ 'recently_activated_snippets',
273
+ $recently_active + (array) get_site_option( 'recently_activated_snippets' )
274
+ );
275
+ } elseif ( $table === $wpdb->snippets ) {
276
+
277
+ update_option(
278
+ 'recently_activated_snippets',
279
+ $recently_active + (array) get_option( 'recently_activated_snippets' )
280
+ );
281
+ }
282
+
283
+ do_action( 'code_snippets/deactivate_snippet', $id, $multisite );
284
+ }
285
+
286
+ /**
287
+ * Deletes a snippet from the database
288
+ *
289
+ * @since 2.0
290
+ * @uses $wpdb To access the database
291
+ * @uses get_snippets_table_name() To dynamically retrieve the name of the snippet table
292
+ *
293
+ * @param int $id The ID of the snippet to delete
294
+ * @param boolean|null $multisite Delete from site-wide or network-wide table?
295
+ */
296
+ function delete_snippet( $id, $multisite = null ) {
297
+ global $wpdb;
298
+
299
+ $wpdb->delete(
300
+ get_snippets_table_name( $multisite ),
301
+ array( 'id' => $id ),
302
+ array( '%d' )
303
+ );
304
+
305
+ do_action( 'code_snippets/delete_snippet', $id, $multisite );
306
+ }
307
+
308
+ /**
309
+ * Saves a snippet to the database.
310
+ *
311
+ * @since 2.0
312
+ * @uses $wpdb To update/add the snippet to the database
313
+ * @uses get_snippets_table_name() To dynamically retrieve the name of the snippet table
314
+ *
315
+ * @param object $snippet The snippet to add/update to the database
316
+ * @param boolean|null $multisite Save the snippet to the site-wide or network-wide table?
317
+ * @return int|boolean The ID of the snippet on success, false on failure
318
+ */
319
+ function save_snippet( $snippet, $multisite = null ) {
320
+ global $wpdb;
321
+
322
+ $data = array();
323
+ $table = get_snippets_table_name( $multisite );
324
+ $snippet = escape_snippet_data( $snippet );
325
+
326
+ foreach ( get_object_vars( $snippet ) as $field => $value ) {
327
+ if ( 'id' === $field ) {
328
+ continue;
329
+ }
330
+
331
+ if ( is_array( $value ) ) {
332
+ $value = maybe_serialize( $value );
333
+ }
334
+
335
+ $data[ $field ] = $value;
336
+ }
337
+
338
+ if ( isset( $snippet->id ) && 0 !== $snippet->id ) {
339
+
340
+ $wpdb->update( $table, $data, array( 'id' => $snippet->id ), null, array( '%d' ) );
341
+ do_action( 'code_snippets/update_snippet', $snippet, $table );
342
+ return $snippet->id;
343
+
344
+ } else {
345
+
346
+ $wpdb->insert( $table, $data, '%s' );
347
+ do_action( 'code_snippets/create_snippet', $snippet, $table );
348
+ return $wpdb->insert_id;
349
+ }
350
+ }
351
+
352
+ /**
353
+ * Imports snippets from an XML file
354
+ *
355
+ * @since 2.0
356
+ * @uses save_snippet() To add the snippets to the database
357
+ *
358
+ * @param string $file The path to the XML file to import
359
+ * @param boolean|null $multisite Import into network-wide table or site-wide table?
360
+ * @return integer|boolean The number of snippets imported on success, false on failure
361
+ */
362
+ function import_snippets( $file, $multisite = null ) {
363
+
364
+ if ( ! file_exists( $file ) || ! is_file( $file ) ) {
365
+ return false;
366
+ }
367
+
368
+ $dom = new DOMDocument( '1.0', get_bloginfo( 'charset' ) );
369
+ $dom->load( $file );
370
+
371
+ $snippets_xml = $dom->getElementsByTagName( 'snippet' );
372
+ $fields = array( 'name', 'description', 'code', 'tags' );
373
+ $count = 0;
374
+
375
+ /* Loop through all snippets */
376
+ foreach ( $snippets_xml as $snippet_xml ) {
377
+ $snippet = new stdClass;
378
+
379
+ /* Build a snippet object by looping through the field names */
380
+ foreach ( $fields as $field_name ) {
381
+
382
+ /* Fetch the field element from the document */
383
+ $field = $snippet_xml->getElementsByTagName( $field_name )->item(0);
384
+
385
+ /* If the field element exists, add it to the snippet object */
386
+ if ( isset( $field->nodeValue ) ) {
387
+ $snippet->$field_name = $field->nodeValue;
388
+ }
389
+ }
390
+
391
+ /* Save the snippet and increase the counter if successful */
392
+ if ( save_snippet( $snippet, $multisite ) ) {
393
+ $count += 1;
394
+ }
395
+ }
396
+
397
+ do_action( 'code_snippets/import', $dom, $multisite );
398
+ return $count;
399
+ }
400
+
401
+ /**
402
+ * Exports snippets as an XML file
403
+ *
404
+ * @since 2.0
405
+ * @uses Code_Snippets_Export To export selected snippets
406
+ * @uses get_snippets_table_name() To dynamically retrieve the name of the snippet table
407
+ *
408
+ * @param array $ids The IDs of the snippets to export
409
+ * @param boolean|null $multisite Is the snippet a network-wide or site-wide snippet?
410
+ * @param string $format Export to xml or php?
411
+ */
412
+ function export_snippets( $ids, $multisite = null, $format = 'xml' ) {
413
+ $table = get_snippets_table_name( $multisite );
414
+
415
+ if ( ! class_exists( 'Code_Snippets_Export' ) ) {
416
+ require_once plugin_dir_path( CODE_SNIPPETS_FILE ) . 'includes/class-export.php';
417
+ }
418
+
419
+ $class = new Code_Snippets_Export( $ids, $table, $format );
420
+ $class->do_export();
421
+ }
422
+
423
+ /**
424
+ * Execute a snippet
425
+ *
426
+ * Code must NOT be escaped, as
427
+ * it will be executed directly
428
+ *
429
+ * @since 2.0
430
+ * @param string $code The snippet code to execute
431
+ * @return mixed The result of the code execution
432
+ */
433
+ function execute_snippet( $code ) {
434
+
435
+ if ( empty( $code ) ) {
436
+ return false;
437
+ }
438
+
439
+ ob_start();
440
+ $result = eval( $code );
441
+ $output = ob_get_contents();
442
+ ob_end_clean();
443
+
444
+ do_action( 'code_snippets/execute_snippet', $code );
445
+ return $result;
446
+ }
447
+
448
+ /**
449
+ * Run the active snippets
450
+ *
451
+ * @since 2.0
452
+ * @return boolean true on success, false on failure
453
+ */
454
+ function execute_active_snippets() {
455
+
456
+ /* Bail early if safe mode is active */
457
+ if ( defined( 'CODE_SNIPPETS_SAFE_MODE' ) && CODE_SNIPPETS_SAFE_MODE ) {
458
+ return false;
459
+ }
460
+
461
+ global $wpdb;
462
+
463
+ if ( ! isset( $wpdb->snippets, $wpdb->ms_snippets ) ) {
464
+ set_snippet_table_vars();
465
+ }
466
+
467
+ /* Check if the snippets table exists */
468
+ if ( $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->snippets'" ) === $wpdb->snippets ) {
469
+ $sql = "SELECT code FROM {$wpdb->snippets} WHERE active=1";
470
+ }
471
+
472
+ /* Check if the multisite snippets table exists */
473
+ if ( is_multisite() && $wpdb->get_var( "SHOW TABLES LIKE '$wpdb->ms_snippets'" ) === $wpdb->ms_snippets ) {
474
+ $sql = ( isset( $sql ) ? $sql . "\nUNION ALL\n" : '' );
475
+ $sql .= "SELECT code FROM {$wpdb->ms_snippets} WHERE active=1;";
476
+ }
477
+
478
+ if ( ! empty( $sql ) ) {
479
+
480
+ /* Grab the active snippets from the database */
481
+ $active_snippets = $wpdb->get_col( $sql );
482
+
483
+ foreach ( $active_snippets as $snippet_code ) {
484
+ /* Execute the PHP code */
485
+ execute_snippet( $snippet_code );
486
+ }
487
+
488
+ return true;
489
+ }
490
+
491
+ /* If we're made it this far without returning true, assume failure */
492
+ return false;
493
+ }
includes/upgrade.php ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /* Bail on direct access */
4
+ if ( ! defined( 'ABSPATH' ) ) {
5
+ return;
6
+ }
7
+
8
+ /**
9
+ * Preform upgrade tasks such as deleting and updating options
10
+ * @since 2.0
11
+ */
12
+ function code_snippets_upgrader() {
13
+
14
+ /* Get the current plugin version from the database */
15
+ $prev_version = get_option( 'code_snippets_version' );
16
+
17
+ /* Check if this is the first plugin run */
18
+ if ( ! $prev_version ) {
19
+
20
+ /* Register capabilities */
21
+ $role = get_role( apply_filters( 'code_snippets_role', 'administrator' ) );
22
+ $role->add_cap( apply_filters( 'code_snippets_cap', 'manage_snippets' ) );
23
+ }
24
+
25
+ /* Check if we have upgraded from an older version */
26
+ if ( version_compare( $prev_version, CODE_SNIPPETS_VERSION, '<' ) ) {
27
+
28
+ /* Update the plugin version stored in the database */
29
+ update_option( 'code_snippets_version', CODE_SNIPPETS_VERSION );
30
+ }
31
+
32
+ /* Run multisite-only upgrades */
33
+
34
+ if ( is_multisite() && is_main_site() ) {
35
+
36
+ /* Get the current plugin version from the database */
37
+ $prev_ms_version = get_site_option( 'code_snippets_version' );
38
+
39
+ /* Check if this is the first plugin run */
40
+ if ( ! $prev_ms_version ) {
41
+
42
+ /* Register multisite capabilities */
43
+ $network_cap = apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' );
44
+ $supers = get_super_admins();
45
+
46
+ foreach ( $supers as $admin ) {
47
+ $user = new WP_User( 0, $admin );
48
+ $user->add_cap( $network_cap );
49
+ }
50
+ }
51
+
52
+ /* Check if we have upgraded from an older version */
53
+ if ( version_compare( $prev_ms_version, CODE_SNIPPETS_VERSION, '<' ) ) {
54
+
55
+ /* Update the plugin version stored in the database */
56
+ update_site_option( 'code_snippets_version', CODE_SNIPPETS_VERSION );
57
+ }
58
+ }
59
+ }
60
+
61
+ add_action( 'plugins_loaded', 'code_snippets_upgrader', 0 );
js/vendor/jquery.tagit.css ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ul.tagit {
2
+ padding: 1px 5px;
3
+ overflow: auto;
4
+ margin-left: inherit; /* usually we don't want the regular ul margins. */
5
+ margin-right: inherit;
6
+ }
7
+ ul.tagit li {
8
+ display: block;
9
+ float: left;
10
+ margin: 2px 5px 2px 0;
11
+ }
12
+ ul.tagit li.tagit-choice {
13
+ position: relative;
14
+ line-height: inherit;
15
+ }
16
+
17
+ ul.tagit li.tagit-choice-read-only {
18
+ padding: .2em .5em .2em .5em;
19
+ }
20
+
21
+ ul.tagit li.tagit-choice-editable {
22
+ padding: .2em 18px .2em .5em;
23
+ }
24
+
25
+ ul.tagit li.tagit-new {
26
+ padding: .25em 4px .25em 0;
27
+ }
28
+
29
+ ul.tagit li.tagit-choice a.tagit-label {
30
+ cursor: pointer;
31
+ text-decoration: none;
32
+ }
33
+ ul.tagit li.tagit-choice .tagit-close {
34
+ cursor: pointer;
35
+ position: absolute;
36
+ right: .1em;
37
+ top: 50%;
38
+ margin-top: -8px;
39
+ line-height: 17px;
40
+ }
41
+
42
+ /* used for some custom themes that don't need image icons */
43
+ ul.tagit li.tagit-choice .tagit-close .text-icon {
44
+ display: none;
45
+ }
46
+
47
+ ul.tagit li.tagit-choice input {
48
+ display: block;
49
+ float: left;
50
+ margin: 2px 5px 2px 0;
51
+ }
52
+ ul.tagit input[type="text"] {
53
+ -moz-box-sizing: border-box;
54
+ -webkit-box-sizing: border-box;
55
+ box-sizing: border-box;
56
+
57
+ -moz-box-shadow: none;
58
+ -webkit-box-shadow: none;
59
+ box-shadow: none;
60
+
61
+ border: none;
62
+ margin: 0;
63
+ padding: 0;
64
+ width: inherit;
65
+ background-color: inherit;
66
+ outline: none;
67
+ }
js/vendor/tag-it.min.js ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ (function(b){b.widget("ui.tagit",{options:{allowDuplicates:!1,caseSensitive:!0,fieldName:"tags",placeholderText:null,readOnly:!1,removeConfirmation:!1,tagLimit:null,availableTags:[],autocomplete:{},showAutocompleteOnFocus:!1,allowSpaces:!1,singleField:!1,singleFieldDelimiter:",",singleFieldNode:null,animate:!0,tabIndex:null,beforeTagAdded:null,afterTagAdded:null,beforeTagRemoved:null,afterTagRemoved:null,onTagClicked:null,onTagLimitExceeded:null,onTagAdded:null,onTagRemoved:null,tagSource:null},_create:function(){var a=
2
+ this;this.element.is("input")?(this.tagList=b("<ul></ul>").insertAfter(this.element),this.options.singleField=!0,this.options.singleFieldNode=this.element,this.element.css("display","none")):this.tagList=this.element.find("ul, ol").andSelf().last();this.tagInput=b('<input type="text" />').addClass("ui-widget-content");this.options.readOnly&&this.tagInput.attr("disabled","disabled");this.options.tabIndex&&this.tagInput.attr("tabindex",this.options.tabIndex);this.options.placeholderText&&this.tagInput.attr("placeholder",
3
+ this.options.placeholderText);this.options.autocomplete.source||(this.options.autocomplete.source=function(a,c){var d=a.term.toLowerCase(),e=b.grep(this.options.availableTags,function(a){return 0===a.toLowerCase().indexOf(d)});c(this._subtractArray(e,this.assignedTags()))});this.options.showAutocompleteOnFocus&&(this.tagInput.focus(function(){a._showAutocomplete()}),"undefined"===typeof this.options.autocomplete.minLength&&(this.options.autocomplete.minLength=0));b.isFunction(this.options.autocomplete.source)&&
4
+ (this.options.autocomplete.source=b.proxy(this.options.autocomplete.source,this));b.isFunction(this.options.tagSource)&&(this.options.tagSource=b.proxy(this.options.tagSource,this));this.tagList.addClass("tagit").addClass("ui-widget ui-widget-content ui-corner-all").append(b('<li class="tagit-new"></li>').append(this.tagInput)).click(function(c){var d=b(c.target);d.hasClass("tagit-label")?(d=d.closest(".tagit-choice"),d.hasClass("removed")||a._trigger("onTagClicked",c,{tag:d,tagLabel:a.tagLabel(d)})):
5
+ a.tagInput.focus()});var d=!1;if(this.options.singleField)if(this.options.singleFieldNode){var c=b(this.options.singleFieldNode),e=c.val().split(this.options.singleFieldDelimiter);c.val("");b.each(e,function(b,c){a.createTag(c,null,!0);d=!0})}else this.options.singleFieldNode=b('<input type="hidden" style="display:none;" value="" name="'+this.options.fieldName+'" />'),this.tagList.after(this.options.singleFieldNode);d||this.tagList.children("li").each(function(){b(this).hasClass("tagit-new")||(a.createTag(b(this).text(),
6
+ b(this).attr("class"),!0),b(this).remove())});this.tagInput.keydown(function(c){if(c.which==b.ui.keyCode.BACKSPACE&&""===a.tagInput.val()){var d=a._lastTag();!a.options.removeConfirmation||d.hasClass("remove")?a.removeTag(d):a.options.removeConfirmation&&d.addClass("remove ui-state-highlight")}else a.options.removeConfirmation&&a._lastTag().removeClass("remove ui-state-highlight");if(c.which===b.ui.keyCode.COMMA||c.which===b.ui.keyCode.ENTER||c.which==b.ui.keyCode.TAB&&""!==a.tagInput.val()||c.which==
7
+ b.ui.keyCode.SPACE&&!0!==a.options.allowSpaces&&('"'!=b.trim(a.tagInput.val()).replace(/^s*/,"").charAt(0)||'"'==b.trim(a.tagInput.val()).charAt(0)&&'"'==b.trim(a.tagInput.val()).charAt(b.trim(a.tagInput.val()).length-1)&&0!==b.trim(a.tagInput.val()).length-1))c.which===b.ui.keyCode.ENTER&&""===a.tagInput.val()||c.preventDefault(),a.createTag(a._cleanedInput()),a.tagInput.autocomplete("close")}).blur(function(){a.tagInput.data("autocomplete-open")||a.createTag(a._cleanedInput())});if(this.options.availableTags||
8
+ this.options.tagSource||this.options.autocomplete.source)c={select:function(b,c){a.createTag(c.item.value);return!1}},b.extend(c,this.options.autocomplete),c.source=this.options.tagSource||c.source,this.tagInput.autocomplete(c).bind("autocompleteopen",function(){a.tagInput.data("autocomplete-open",!0)}).bind("autocompleteclose",function(){a.tagInput.data("autocomplete-open",!1)})},_cleanedInput:function(){return b.trim(this.tagInput.val().replace(/^"(.*)"$/,"$1"))},_lastTag:function(){return this.tagList.find(".tagit-choice:last:not(.removed)")},
9
+ _tags:function(){return this.tagList.find(".tagit-choice:not(.removed)")},assignedTags:function(){var a=this,d=[];this.options.singleField?(d=b(this.options.singleFieldNode).val().split(this.options.singleFieldDelimiter),""===d[0]&&(d=[])):this._tags().each(function(){d.push(a.tagLabel(this))});return d},_updateSingleTagsField:function(a){b(this.options.singleFieldNode).val(a.join(this.options.singleFieldDelimiter)).trigger("change")},_subtractArray:function(a,d){for(var c=[],e=0;e<a.length;e++)-1==
10
+ b.inArray(a[e],d)&&c.push(a[e]);return c},tagLabel:function(a){return this.options.singleField?b(a).find(".tagit-label:first").text():b(a).find("input:first").val()},_showAutocomplete:function(){this.tagInput.autocomplete("search","")},_findTagByLabel:function(a){var d=this,c=null;this._tags().each(function(){if(d._formatStr(a)==d._formatStr(d.tagLabel(this)))return c=b(this),!1});return c},_isNew:function(a){return!this._findTagByLabel(a)},_formatStr:function(a){return this.options.caseSensitive?
11
+ a:b.trim(a.toLowerCase())},_effectExists:function(a){return Boolean(b.effects&&(b.effects[a]||b.effects.effect&&b.effects.effect[a]))},createTag:function(a,d,c){var e=this;a=b.trim(a);this.options.preprocessTag&&(a=this.options.preprocessTag(a));if(""===a)return!1;if(!this.options.allowDuplicates&&!this._isNew(a))return a=this._findTagByLabel(a),!1!==this._trigger("onTagExists",null,{existingTag:a,duringInitialization:c})&&this._effectExists("highlight")&&a.effect("highlight"),!1;if(this.options.tagLimit&&
12
+ this._tags().length>=this.options.tagLimit)return this._trigger("onTagLimitExceeded",null,{duringInitialization:c}),!1;var g=b(this.options.onTagClicked?'<a class="tagit-label"></a>':'<span class="tagit-label"></span>').text(a),f=b("<li></li>").addClass("tagit-choice ui-widget-content ui-state-default ui-corner-all").addClass(d).append(g);this.options.readOnly?f.addClass("tagit-choice-read-only"):(f.addClass("tagit-choice-editable"),d=b("<span></span>").addClass("ui-icon ui-icon-close"),d=b('<a><span class="text-icon">\u00d7</span></a>').addClass("tagit-close").append(d).click(function(){e.removeTag(f)}),
13
+ f.append(d));this.options.singleField||(g=g.html(),f.append('<input type="hidden" style="display:none;" value="'+g+'" name="'+this.options.fieldName+'" />'));!1!==this._trigger("beforeTagAdded",null,{tag:f,tagLabel:this.tagLabel(f),duringInitialization:c})&&(this.options.singleField&&(g=this.assignedTags(),g.push(a),this._updateSingleTagsField(g)),this._trigger("onTagAdded",null,f),this.tagInput.val(""),this.tagInput.parent().before(f),this._trigger("afterTagAdded",null,{tag:f,tagLabel:this.tagLabel(f),
14
+ duringInitialization:c}),this.options.showAutocompleteOnFocus&&!c&&setTimeout(function(){e._showAutocomplete()},0))},removeTag:function(a,d){d="undefined"===typeof d?this.options.animate:d;a=b(a);this._trigger("onTagRemoved",null,a);if(!1!==this._trigger("beforeTagRemoved",null,{tag:a,tagLabel:this.tagLabel(a)})){if(this.options.singleField){var c=this.assignedTags(),e=this.tagLabel(a),c=b.grep(c,function(a){return a!=e});this._updateSingleTagsField(c)}if(d){a.addClass("removed");var c=this._effectExists("blind")?
15
+ ["blind",{direction:"horizontal"},"fast"]:["fast"],g=this;c.push(function(){a.remove();g._trigger("afterTagRemoved",null,{tag:a,tagLabel:g.tagLabel(a)})});a.fadeOut("fast").hide.apply(a,c).dequeue()}else a.remove(),this._trigger("afterTagRemoved",null,{tag:a,tagLabel:this.tagLabel(a)})}},removeTagByLabel:function(a,b){var c=this._findTagByLabel(a);if(!c)throw"No such tag exists with the name '"+a+"'";this.removeTag(c,b)},removeAll:function(){var a=this;this._tags().each(function(b,c){a.removeTag(c,
16
+ !1)})}})})(jQuery);
js/vendor/tagit.ui-zendesk.css ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ /* Optional scoped theme for tag-it which mimics the zendesk widget. */
3
+
4
+
5
+ ul.tagit {
6
+ border-style: solid;
7
+ border-width: 1px;
8
+ border-color: #C6C6C6;
9
+ background: #fff;
10
+ }
11
+ ul.tagit li.tagit-choice {
12
+ -moz-border-radius: 6px;
13
+ border-radius: 6px;
14
+ -webkit-border-radius: 6px;
15
+ border: 1px solid #CAD8F3;
16
+
17
+ background: none;
18
+ background-color: #DEE7F8;
19
+
20
+ font-weight: normal;
21
+ }
22
+ ul.tagit li.tagit-choice .tagit-label:not(a) {
23
+ color: #555;
24
+ }
25
+ ul.tagit li.tagit-choice a.tagit-close {
26
+ text-decoration: none;
27
+ }
28
+ ul.tagit li.tagit-choice .tagit-close {
29
+ right: .4em;
30
+ }
31
+ ul.tagit li.tagit-choice .ui-icon {
32
+ display: none;
33
+ }
34
+ ul.tagit li.tagit-choice .tagit-close .text-icon {
35
+ display: inline;
36
+ font-family: arial, sans-serif;
37
+ font-size: 16px;
38
+ line-height: 16px;
39
+ color: #777;
40
+ }
41
+ ul.tagit li.tagit-choice:hover, ul.tagit li.tagit-choice.remove {
42
+ background-color: #bbcef1;
43
+ border-color: #6d95e0;
44
+ }
45
+ ul.tagit li.tagit-choice a.tagLabel:hover,
46
+ ul.tagit li.tagit-choice a.tagit-close .text-icon:hover {
47
+ color: #222;
48
+ }
49
+ ul.tagit input[type="text"] {
50
+ color: #333333;
51
+ background: none;
52
+ }
53
+ .ui-widget {
54
+ font-size: 1.1em;
55
+ }
56
+
languages/code-snippets-de_DE.mo CHANGED
Binary file
languages/code-snippets-it_IT.mo ADDED
Binary file
languages/code-snippets-it_IT.po ADDED
@@ -0,0 +1,502 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is distributed under the same license as the Code Snippets package.
2
+ # Marco <troniclabs.crew@gmail.com>, 2014.
3
+ msgid ""
4
+ msgstr ""
5
+ "Project-Id-Version: Code Snippets\n"
6
+ "PO-Revision-Date: 2014-08-08 09:26+0200\n"
7
+ "Last-Translator: Marco <troniclabs.crew@gmail.com>\n"
8
+ "Language-Team: Tronic Labs\n"
9
+ "Language: it\n"
10
+ "MIME-Version: 1.0\n"
11
+ "Content-Type: text/plain; charset=UTF-8\n"
12
+ "Content-Transfer-Encoding: 8bit\n"
13
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
14
+ "X-Generator: Virtaal 0.7.1\n"
15
+
16
+ #: code-snippets.php:0 code-snippets.php:262
17
+ msgid "Code Snippets"
18
+ msgstr "Code Snippets"
19
+
20
+ #: code-snippets.php:0
21
+ msgid "An easy, clean and simple way to add code snippets to your site. No need to edit to your theme's functions.php file again!"
22
+ msgstr ""
23
+ "Un facile, semplice e pulito modo di aggiungere Snippet, frammenti di codice "
24
+ "al tuo sito. Senza editare il tuo tema e il tuo file functions.php."
25
+
26
+ #: code-snippets.php:0
27
+ msgid "Shea Bunge"
28
+ msgstr "Shea Bunge"
29
+
30
+ #: code-snippets.php:0
31
+ msgid "http://bungeshea.com"
32
+ msgstr "http://bungeshea.com"
33
+
34
+ #: code-snippets.php:577 code-snippets.php:578 code-snippets.php:588
35
+ #: includes/admin/manage.php:36
36
+ msgid "Snippets"
37
+ msgstr "Snippets"
38
+
39
+ #: code-snippets.php:612 code-snippets.php:1145 includes/admin/single.php:45
40
+ msgid "Add New Snippet"
41
+ msgstr "Aggiungi nuovo Snippet"
42
+
43
+ #: code-snippets.php:613
44
+ msgid "Add New"
45
+ msgstr "Aggiungi Nuovo"
46
+
47
+ #: code-snippets.php:641 includes/admin/import.php:34
48
+ msgid "Import Snippets"
49
+ msgstr "Importa Snippet"
50
+
51
+ #: code-snippets.php:642
52
+ msgid "Import"
53
+ msgstr "Importa"
54
+
55
+ #: code-snippets.php:601 code-snippets.php:1146 includes/admin/single.php:37
56
+ msgid "Edit Snippet"
57
+ msgstr "Edita Snippet"
58
+
59
+ #: code-snippets.php:1465
60
+ msgid "Manage your existing snippets"
61
+ msgstr "Gestisci i tuoi snippets esistenti"
62
+
63
+ #: code-snippets.php:589 code-snippets.php:1466
64
+ msgid "Manage"
65
+ msgstr "Gestisci"
66
+
67
+ #: code-snippets.php:1486
68
+ msgid "Visit the WordPress.org plugin page"
69
+ msgstr "Visita la pagina del plugin su WordPress.org"
70
+
71
+ #: code-snippets.php:1487
72
+ msgid "About"
73
+ msgstr "Info"
74
+
75
+ #: code-snippets.php:1491
76
+ msgid "Visit the support forums"
77
+ msgstr "Visita il forum di supporto"
78
+
79
+ #: code-snippets.php:1492
80
+ msgid "Support"
81
+ msgstr "Supporto"
82
+
83
+ #: code-snippets.php:1496
84
+ msgid "Support this plugin's development"
85
+ msgstr "Supporta lo sviluppo di questo plugin"
86
+
87
+ #: code-snippets.php:1497
88
+ msgid "Donate"
89
+ msgstr "Donazione"
90
+
91
+ #: includes/admin/import.php:38
92
+ msgid "Howdy! Upload your Code Snippets export file and we&#8217;ll import the snippets to this site."
93
+ msgstr ""
94
+ "Wella! Carica i tuoi Snippets di codice dal file esportato e li importeremo "
95
+ "nel tuo sito. "
96
+
97
+ #: includes/admin/import.php:40
98
+ msgid "You will need to go to the <a href=\"%s\">Manage Snippets</a> page to activate the imported snippets."
99
+ msgstr ""
100
+ "Dovrai andare nella pagina <a href=\"%s\">Gestisci Snippets</a> per attivare "
101
+ "gli snippets importati."
102
+
103
+ #: includes/admin/import.php:42
104
+ msgid "Choose a Code Snippets (.xml) file to upload, then click Upload file and import."
105
+ msgstr ""
106
+ "Scegli un file di Codice Snippets (.xml) da caricare, quindi clicca su "
107
+ "Carica file e Importa."
108
+
109
+ #: includes/admin/import.php:46
110
+ msgid "Choose a file from your computer:"
111
+ msgstr "Scegli un file dal computer:"
112
+
113
+ #: includes/admin/import.php:46
114
+ msgid "(Maximum size: 8MB)"
115
+ msgstr "(Grandezza massima: 8MB)"
116
+
117
+ #: includes/admin/import.php:55
118
+ msgid "Upload file and import"
119
+ msgstr "Carica un file e importa"
120
+
121
+ #: includes/admin/manage.php:21
122
+ msgid "Snippet <strong>activated</strong>."
123
+ msgstr "Snippet <strong>attivato</strong>."
124
+
125
+ #: includes/admin/manage.php:23
126
+ msgid "Selected snippets <strong>activated</strong>."
127
+ msgstr "Snippet selezionato <strong>attivato</strong>."
128
+
129
+ #: includes/admin/manage.php:25
130
+ msgid "Snippet <strong>deactivated</strong>."
131
+ msgstr "Snippet <strong>disattivato</strong>."
132
+
133
+ #: includes/admin/manage.php:27
134
+ msgid "Selected snippets <strong>deactivated</strong>."
135
+ msgstr "Snippet selezionato <strong>disattivato</strong>."
136
+
137
+ #: includes/admin/manage.php:29
138
+ msgid "Snippet <strong>deleted</strong>."
139
+ msgstr "Snippet <strong>cancellato</strong>."
140
+
141
+ #: includes/admin/manage.php:31
142
+ msgid "Selected snippets <strong>deleted</strong>."
143
+ msgstr "Snippet selezionato <strong>cancellato</strong>."
144
+
145
+ #: includes/admin/manage.php:38 includes/admin/single.php:42
146
+ msgctxt "snippet"
147
+ msgid "Add New"
148
+ msgstr "Aggiungi Nuovo"
149
+
150
+ #: includes/admin/manage.php:47
151
+ msgid "Search Installed Snippets"
152
+ msgstr "Cerca Snippets Installati"
153
+
154
+ #: includes/admin/single.php:22
155
+ msgid "Please provide a name for the snippet and its code."
156
+ msgstr "Per favore dai un nome allo snippet e al suo codice."
157
+
158
+ #: includes/admin/single.php:28
159
+ msgid "Snippet <strong>updated</strong>."
160
+ msgstr "Snippet <strong>aggiornato</strong>."
161
+
162
+ #: includes/admin/single.php:30
163
+ msgid "Snippet <strong>added</strong>."
164
+ msgstr "Snippet <strong>aggiunto</strong>."
165
+
166
+ #: includes/admin/single.php:55 includes/admin/single.php:56
167
+ msgid "Name (short title)"
168
+ msgstr "Nome (titolo corto)"
169
+
170
+ #: includes/admin/single.php:61
171
+ msgid "Code"
172
+ msgstr "Codice"
173
+
174
+ #: code-snippets.php:1433 includes/class-list-table.php:189
175
+ msgid "Description"
176
+ msgstr "Descizione"
177
+
178
+ #: code-snippets.php:1434
179
+ msgid "(Optional)"
180
+ msgstr "(Opzionale)"
181
+
182
+ #: includes/class-list-table.php:36
183
+ msgid "Snippets per page"
184
+ msgstr "Snippets per pagina"
185
+
186
+ #: code-snippets.php:1118 includes/class-list-table.php:127
187
+ #: includes/class-list-table.php:213
188
+ msgid "Network Deactivate"
189
+ msgstr "Network Disattivato"
190
+
191
+ #: code-snippets.php:1118 includes/class-list-table.php:127
192
+ #: includes/class-list-table.php:213
193
+ msgid "Deactivate"
194
+ msgstr "Disattivato"
195
+
196
+ #: code-snippets.php:1127 includes/class-list-table.php:137
197
+ #: includes/class-list-table.php:212
198
+ msgid "Network Activate"
199
+ msgstr "Network Attivato"
200
+
201
+ #: code-snippets.php:1127 includes/class-list-table.php:137
202
+ #: includes/class-list-table.php:212
203
+ msgid "Activate"
204
+ msgstr "Attivato"
205
+
206
+ #: includes/class-list-table.php:187
207
+ msgid "Name"
208
+ msgstr "Nome"
209
+
210
+ #: includes/class-list-table.php:188
211
+ msgid "ID"
212
+ msgstr "ID"
213
+
214
+ #: includes/class-list-table.php:147 includes/class-list-table.php:214
215
+ msgid "Export"
216
+ msgstr "Esporta"
217
+
218
+ #: includes/class-list-table.php:155 includes/class-list-table.php:215
219
+ msgid "Delete"
220
+ msgstr "Cancella"
221
+
222
+ #: includes/class-list-table.php:216
223
+ msgid "Export to PHP"
224
+ msgstr "Esporta in PHP"
225
+
226
+ #: includes/class-list-table.php:236
227
+ msgid "All <span class=\"count\">(%s)</span>"
228
+ msgid_plural "All <span class=\"count\">(%s)</span>"
229
+ msgstr[0] "Tutto <span class=\"count\">(%s)</span>"
230
+ msgstr[1] "Tutti <span class=\"count\">(%s)</span>"
231
+
232
+ #: includes/class-list-table.php:239
233
+ msgid "Active <span class=\"count\">(%s)</span>"
234
+ msgid_plural "Active <span class=\"count\">(%s)</span>"
235
+ msgstr[0] "Attivo <span class=\"count\">(%s)</span>"
236
+ msgstr[1] "Attivi <span class=\"count\">(%s)</span>"
237
+
238
+ #: includes/class-list-table.php:242
239
+ msgid "Recently Active <span class=\"count\">(%s)</span>"
240
+ msgid_plural "Recently Active <span class=\"count\">(%s)</span>"
241
+ msgstr[0] "Recentemente Attivo <span class=\"count\">(%s)</span>"
242
+ msgstr[1] "Recentemente Attivi <span class=\"count\">(%s)</span>"
243
+
244
+ #: includes/class-list-table.php:245
245
+ msgid "Inactive <span class=\"count\">(%s)</span>"
246
+ msgid_plural "Inactive <span class=\"count\">(%s)</span>"
247
+ msgstr[0] "Inattivo <span class=\"count\">(%s)</span>"
248
+ msgstr[1] "Inattivi <span class=\"count\">(%s)</span>"
249
+
250
+ #: includes/class-list-table.php:279
251
+ msgid "Clear List"
252
+ msgstr "Cancella Lista"
253
+
254
+ #: includes/class-list-table.php:374
255
+ msgid "You do not appear to have any snippets available at this time. <a href=\"%s\">Add New&rarr;</a>"
256
+ msgstr ""
257
+ "Sembra che tu non abbia nessuno snippets disponibile fino ad ora. <a href=\"%"
258
+ "s\">Aggiungi Nuovo&rarr;</a>"
259
+
260
+ #: includes/help/import.php:5 includes/help/manage.php:5
261
+ #: includes/help/single.php:5
262
+ msgid "Overview"
263
+ msgstr "Panoramica"
264
+
265
+ #: includes/help/import.php:7
266
+ msgid "Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. Here you can load snippets from a Code Snippets (.xml) import file into the database with your existing snippets."
267
+ msgstr ""
268
+ "Gli Snippets sono simili ai Plugin - tutti e due espandono le funzionalità "
269
+ "di WordPress. Gli Snippets sono più leggeri, giusto poche righe di codice, e "
270
+ "non appesantiscono il server. Qui tu puoi caricare snippet da un file di "
271
+ "codice Snippets (.xml) ed importarli nel database aggiungendoli a gli altri "
272
+ "esistenti."
273
+
274
+ #: includes/help/import.php:12
275
+ msgid "Importing"
276
+ msgstr "Importando"
277
+
278
+ #: includes/help/import.php:15
279
+ msgid "Snippets will be added to the database along with your existing snippets. Regardless of whether the snippets were active on the previous site, imported snippets are always inactive until activated using the <a href=\"%s\">Manage Snippets</a> page.</p>"
280
+ msgstr ""
281
+ "Gli Snippets saranno aggiunti al database insieme ai quelli esistenti. "
282
+ "Indipendentemente dal fatto che gli snippets erano attivi sul sito "
283
+ "precedente, gli snippets importati sono sempre inattivi finché non vengono "
284
+ "attivati utilizzando la <a href=\"%s\">Gestisci Snippets</a> pagina.</p>"
285
+
286
+ #: includes/help/import.php:20
287
+ msgid "Exporting"
288
+ msgstr "Esportando"
289
+
290
+ #: includes/help/import.php:22
291
+ msgid "You can save your snippets to a Code Snippets (.xml) export file using the <a href=\"%s\">Manage Snippets</a> page."
292
+ msgstr ""
293
+ "Tu puoi salvare i tuoi snippets in un file di codice Snippets (.xml) usando "
294
+ "la <a href=\"%s\">Gestisci Snippets</a> pagina."
295
+
296
+ #: includes/help/import.php:26 includes/help/manage.php:27
297
+ #: includes/help/single.php:31
298
+ msgid "For more information:"
299
+ msgstr "Per maggiori informazioni:"
300
+
301
+ #: includes/help/import.php:27 includes/help/single.php:32
302
+ msgid "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank\">WordPress Extend</a>"
303
+ msgstr ""
304
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" "
305
+ "target=\"_blank\">WordPress Extend</a>"
306
+
307
+ #: includes/help/import.php:28 includes/help/manage.php:29
308
+ #: includes/help/single.php:33
309
+ msgid "<a href=\"http://wordpress.org/support/plugin/code-snippets\" target=\"_blank\">Support Forums</a>"
310
+ msgstr ""
311
+ "<a href=\"http://wordpress.org/support/plugin/code-snippets\" "
312
+ "target=\"_blank\">Support Forums</a>"
313
+
314
+ #: includes/help/manage.php:7
315
+ msgid "Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. Here you can manage your existing snippets and preform tasks on them such as activating, deactivating, deleting and exporting."
316
+ msgstr ""
317
+ "Gli Snippets sono simili ai Plugin - tutti e due espandono le funzionalità "
318
+ "di WordPress. Gli Snippets sono più leggeri, giusto poche righe di codice, e "
319
+ "non appesantiscono il server. Qui tu puoi gestire i tuoi snippets, "
320
+ "attivarli, disattivarli, cancellarli ed esportarli."
321
+
322
+ #: includes/help/manage.php:12
323
+ msgid "Safe Mode"
324
+ msgstr "Modalità Sicura"
325
+
326
+ #: includes/help/manage.php:14
327
+ msgid "Be sure to check your snippets for errors before you activate them, as a faulty snippet could bring your whole blog down. If your site starts doing strange things, deactivate all your snippets and activate them one at a time."
328
+ msgstr ""
329
+ "Assicuratevi di controllare i vostri snippets da errori prima di attivarli, "
330
+ "uno snippet difettoso potrebbe bloccare tutto il tuo blog. Se il tuo sito "
331
+ "inizia a fare cose strane, disattivare tutti gli snippets e attivarli uno "
332
+ "alla volta."
333
+
334
+ #: includes/help/manage.php:20
335
+ msgid "Uninstall"
336
+ msgstr "Disinstalla"
337
+
338
+ #: includes/help/manage.php:22
339
+ msgid "When you delete Code Snippets through the Plugins menu in WordPress it will clear up the <code>%1$s</code> table and a few other bits of data stored in the database. If you want to keep this data (ie: you are only temporally uninstalling Code Snippets) then remove the <code>%2$s</code> folder using FTP."
340
+ msgstr ""
341
+ "Quando tu disinstalli il Code Snippets dal Plugins menu in WordPress, esso "
342
+ "cancellerà la <code>%1$s</code> tavola e pochi altri bit di dati "
343
+ "memorizzati nel tuo database. Se tu vuoi mantenere questi dati (es. tu stai "
344
+ "solo temporaneamente disinstallando il Code Snippets) allora rimuovi la "
345
+ "<code>%2$s</code> cartella usando lo FTP."
346
+
347
+ #: includes/help/manage.php:23
348
+ msgid "Even if you're sure that you don't want to use Code Snippets ever again on this WordPress installation, you may want to use the export feature to back up your snippets."
349
+ msgstr ""
350
+ "Anche se sei sicuro che non vuoi più utilizzare Code Snippets in WordPress, "
351
+ "è possibile utilizzare la funzione di esportazione per il backup degli "
352
+ "snippets."
353
+
354
+ #: includes/help/manage.php:28
355
+ msgid "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank\">WordPress Extend</a></p>"
356
+ msgstr ""
357
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" "
358
+ "target=\"_blank\">WordPress Extend</a></p>"
359
+
360
+ #: includes/help/single.php:7
361
+ msgid "Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. Here you can add a new snippet, or edit an existing one."
362
+ msgstr ""
363
+ "Gli Snippets sono simili ai Plugin - tutti e due espandono le funzionalità "
364
+ "di WordPress. Gli Snippets sono più leggeri, giusto poche righe di codice, e "
365
+ "non appesantiscono il server. Qui tu puoi aggiungere un nuovo snippet o "
366
+ "modificarne uno esistente."
367
+
368
+ #: includes/help/single.php:11
369
+ msgid "Finding Snippets"
370
+ msgstr "Cercando Snippets"
371
+
372
+ #: includes/help/single.php:13
373
+ msgid ""
374
+ "Here are some links to websites which host a large number of snippets that you can add to your site.\n"
375
+ "\t\t<ul>\n"
376
+ "\t\t\t<li><a href=\"http://wp-snippets.com\" title=\"WordPress Snippets\">WP-Snippets</a></li>\n"
377
+ "\t\t\t<li><a href=\"http://wpsnipp.com\" title=\"WP Snipp\">WP Snipp</a></li>\n"
378
+ "\t\t\t<li><a href=\"http://www.catswhocode.com/blog/snippets\" title=\"Cats Who Code Snippet Library\">Cats Who Code</a></li>\n"
379
+ "\t\t\t<li><a href=\"http://www.wpfunction.me\">WP Function Me</a></li>\n"
380
+ "\t\t</ul>"
381
+ msgstr ""
382
+ "Qui ci sono alcuni link a siti web che ospitano un largo numero di snippets "
383
+ "che puoi aggiungere al tuo sito.\n"
384
+ "\t\t<ul>\n"
385
+ "\t\t\t<li><a href=\"http://wp-snippets.com\" title=\"WordPress Snippets\">WP-"
386
+ "Snippets</a></li>\n"
387
+ "\t\t\t<li><a href=\"http://wpsnipp.com\" title=\"WP Snipp\">WP Snipp</a></li>\n"
388
+ "\t\t\t<li><a href=\"http://www.catswhocode.com/blog/snippets\" title=\"Cats Who "
389
+ "Code Snippet Library\">Cats Who Code</a></li>\n"
390
+ "\t\t\t<li><a href=\"http://www.wpfunction.me\">WP Function Me</a></li>"
391
+
392
+ #: includes/help/single.php:24
393
+ msgid "Adding Snippets"
394
+ msgstr "Aggiungendo Snippets"
395
+
396
+ #: includes/help/single.php:26
397
+ msgid "You need to fill out the name and code fields for your snippet to be added. While the description field will add more information about how your snippet works, what is does and where you found it, it is completely optional."
398
+ msgstr ""
399
+ "Devi riempire il campo del nome e il codice per aggiungere lo snippet. "
400
+ "Mentre il campo della descrizione aggiungerà più informazioni riguardo a "
401
+ "come lavora il tuo snippet, cosa fa e dove lo ritroviamo, ed è completamente "
402
+ "opzionale. "
403
+
404
+ #: includes/help/single.php:27
405
+ msgid "Please be sure to check that your snippet is valid PHP code and will not produce errors before adding it through this page. While doing so will not become active straight away, it will help to minimise the chance of a faulty snippet becoming active on your site."
406
+ msgstr ""
407
+ "Per favore accertati che lo snippet abbia un codice PHP valido e non produca "
408
+ "errori aggiungendolo a questa pagina. Facendo così, e non attivandolo "
409
+ "immediatamente, ci assicureremo di minimizzare le probabilità che uno "
410
+ "snippet difettoso sia attivato nel sito. "
411
+
412
+ #: code-snippets.php:0
413
+ msgid "http://code-snippets.bungeshea.com"
414
+ msgstr "http://code-snippets.bungeshea.com"
415
+
416
+ #: code-snippets.php:263
417
+ msgid "Import snippets from a <strong>Code Snippets</strong> export file"
418
+ msgstr "Importa snippets da un file <strong>Code Snippets</strong> esportato"
419
+
420
+ #: includes/admin/import.php:20
421
+ msgid "Imported <strong>%d</strong> snippet."
422
+ msgid_plural "Imported <strong>%d</strong> snippets."
423
+ msgstr[0] "Importato <strong>%d</strong> snippet."
424
+ msgstr[1] "Importati <strong>%d</strong> snippets."
425
+
426
+ #: includes/help/import.php:29 includes/help/manage.php:30
427
+ #: includes/help/single.php:34
428
+ msgid "<a href=\"http://code-snippets.bungeshea.com/\" target=\"_blank\">Project Website</a>"
429
+ msgstr ""
430
+ "<a href=\"http://code-snippets.bungeshea.com/\" target=\"_blank\">Project "
431
+ "Website</a>"
432
+
433
+ #: includes/help/manage.php:15
434
+ msgid "If something goes wrong with a snippet and you can't use WordPress, you can cause all snippets to stop executing by adding <code>define('CODE_SNIPPETS_SAFE_MODE', true);</code> to your <code>wp-config.php</code> file. After you have deactivated the offending snippet, you can turn off safe mode by removing this line or replacing <strong>true</strong> with <strong>false</strong>."
435
+ msgstr ""
436
+ "Se qualcosa va storto con uno snippet e non puoi più usare WordPress, puoi "
437
+ "bloccare la esecuzione di tutti gli snippets aggiungendo "
438
+ "<code>define('CODE_SNIPPETS_SAFE_MODE', true);</code> al tuo file <code>wp-"
439
+ "config.php</code>. Dopo aver disattivato lo snippet difettoso, puoi uscire "
440
+ "dalla modalità sicura rimuovendo la linea oppure cambiando "
441
+ "<strong>true</strong> con <strong>false</strong>."
442
+
443
+ #: includes/help/single.php:20
444
+ msgid "More places to find snippets, as well as a selection of example snippets, can be found in the <a href=\"http://code-snippets.bungeshea.com/docs/finding-snippets/\">plugin documentation</a>"
445
+ msgstr ""
446
+ "Un po' di posti dove cercare snippets, una selezione e alcuni esempi li pui "
447
+ "trovare nella <a href=\"http://code-snippets.bungeshea.com/docs/finding-"
448
+ "snippets/\">documentazione del plugin</a>"
449
+
450
+ #: code-snippets.php:0
451
+ msgid "1.7"
452
+ msgstr "1.7"
453
+
454
+ #: code-snippets.php:602 includes/class-list-table.php:142
455
+ msgid "Edit"
456
+ msgstr "Modifica"
457
+
458
+ #: code-snippets.php:1227
459
+ msgid "Sorry, you're not allowed to edit snippets"
460
+ msgstr "Scusa, tu non sei abilitato a modificare questo snippets"
461
+
462
+ #: includes/admin/single.php:24
463
+ msgid "Snippet <strong>updated</strong> and <strong>activated</strong>."
464
+ msgstr "Snippet <strong>aggiornato</strong> e <strong>attivato</strong>."
465
+
466
+ #: includes/admin/single.php:26
467
+ msgid "Snippet <strong>added</strong> and <strong>activated</strong>."
468
+ msgstr "Snippet <strong>aggiunto</strong> e <strong>attivato</strong>."
469
+
470
+ #: includes/class-list-table.php:163
471
+ msgid ""
472
+ "You are about to permanently delete the selected item.\n"
473
+ "\t\t\t\t'Cancel' to stop, 'OK' to delete."
474
+ msgstr ""
475
+ "Tu stai per cancellare in modo permanente questo elemento.\n"
476
+ "\t\t\t\t'Cancella' per fermarti, 'OK' per cancellare."
477
+
478
+ #: includes/class-list-table.php:270
479
+ msgid "Filter"
480
+ msgstr "Filtro"
481
+
482
+ #: includes/class-list-table.php:541
483
+ msgid "Search results"
484
+ msgstr "Risultati ricerca"
485
+
486
+ #: includes/class-list-table.php:544
487
+ msgid " for &#8220;%s&#8221;"
488
+ msgstr " per &#8220;%s&#8221;"
489
+
490
+ #: includes/class-list-table.php:550
491
+ msgid "Clear Filters"
492
+ msgstr "Cancella Filtri"
493
+
494
+ #: includes/help/import.php:14
495
+ msgid "You can load your snippets from a code snippets (.xml) export file using this page."
496
+ msgstr ""
497
+ "Tu non puoi caricare i tuoi snippets da un file di codice snippets (.xml) "
498
+ "usando questa pagina."
499
+
500
+ #: includes/admin/single.php:74
501
+ msgid "Save Changes &amp; Activate"
502
+ msgstr "Salva Cambiamenti e Attivare"
languages/code-snippets-ja_JP.mo ADDED
Binary file
languages/code-snippets-ja_JP.po ADDED
@@ -0,0 +1,569 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is distributed under the same license as the Code Snippets package.
2
+ msgid ""
3
+ msgstr ""
4
+ "PO-Revision-Date: 2013-11-30 10:44+0900\n"
5
+ "MIME-Version: 1.0\n"
6
+ "Content-Type: text/plain; charset=UTF-8\n"
7
+ "Content-Transfer-Encoding: 8bit\n"
8
+ "Plural-Forms: nplurals=2; plural=n != 1;\n"
9
+ "X-Generator: Poedit 1.5.7\n"
10
+ "Project-Id-Version: Code Snippets\n"
11
+ "POT-Creation-Date: \n"
12
+ "Last-Translator: \n"
13
+ "Language-Team: \n"
14
+
15
+ #: code-snippets.php:0 code-snippets.php:262
16
+ msgid "Code Snippets"
17
+ msgstr "Code Snippets"
18
+
19
+ #: code-snippets.php:0
20
+ msgid ""
21
+ "An easy, clean and simple way to add code snippets to your site. No need to "
22
+ "edit to your theme's functions.php file again!"
23
+ msgstr ""
24
+ "簡単に、あなたのサイトにコードスニペットを追加する方法です。もうテーマの"
25
+ "functions.phpを編集する必要はありません!"
26
+
27
+ #: code-snippets.php:0
28
+ msgid "Shea Bunge"
29
+ msgstr "Shea Bunge"
30
+
31
+ #: code-snippets.php:0
32
+ msgid "http://bungeshea.com"
33
+ msgstr "http://bungeshea.com"
34
+
35
+ #: code-snippets.php:577 code-snippets.php:578 code-snippets.php:588
36
+ #: includes/admin/manage.php:36
37
+ msgid "Snippets"
38
+ msgstr "スニペット"
39
+
40
+ #: code-snippets.php:612 code-snippets.php:1145 includes/admin/single.php:45
41
+ msgid "Add New Snippet"
42
+ msgstr "スニペット新規追加"
43
+
44
+ #: code-snippets.php:613
45
+ msgid "Add New"
46
+ msgstr "新規追加"
47
+
48
+ #: code-snippets.php:641 includes/admin/import.php:34
49
+ msgid "Import Snippets"
50
+ msgstr "スニペットインポート"
51
+
52
+ #: code-snippets.php:642
53
+ msgid "Import"
54
+ msgstr "インポート"
55
+
56
+ #: code-snippets.php:601 code-snippets.php:1146 includes/admin/single.php:37
57
+ msgid "Edit Snippet"
58
+ msgstr "スニペット編集"
59
+
60
+ #: code-snippets.php:1465
61
+ msgid "Manage your existing snippets"
62
+ msgstr "登録されているスニペットを管理"
63
+
64
+ #: code-snippets.php:589 code-snippets.php:1466
65
+ msgid "Manage"
66
+ msgstr "管理"
67
+
68
+ #: code-snippets.php:1486
69
+ msgid "Visit the WordPress.org plugin page"
70
+ msgstr "WordPress.orgプラグインページへ"
71
+
72
+ #: code-snippets.php:1487
73
+ msgid "About"
74
+ msgstr "このプラグインについて"
75
+
76
+ #: code-snippets.php:1491
77
+ msgid "Visit the support forums"
78
+ msgstr "サポートフォーラムへ"
79
+
80
+ #: code-snippets.php:1492
81
+ msgid "Support"
82
+ msgstr "サポート"
83
+
84
+ #: code-snippets.php:1496
85
+ msgid "Support this plugin's development"
86
+ msgstr "このプラグインの開発をサポート"
87
+
88
+ #: code-snippets.php:1497
89
+ msgid "Donate"
90
+ msgstr "寄付"
91
+
92
+ #: includes/admin/import.php:38
93
+ msgid ""
94
+ "Howdy! Upload your Code Snippets export file and we&#8217;ll import the "
95
+ "snippets to this site."
96
+ msgstr ""
97
+ "こんにちは!あなたのコードスニペットエクスポートファイルをアップロードして、"
98
+ "このサイトにスニペットをインポートします。"
99
+
100
+ #: includes/admin/import.php:40
101
+ msgid ""
102
+ "You will need to go to the <a href=\"%s\">Manage Snippets</a> page to "
103
+ "activate the imported snippets."
104
+ msgstr ""
105
+ "<a href=\"%s\">スニペットの管理</a> ページでインポートしたスニペットを有効に"
106
+ "する必要があります。"
107
+
108
+ #: includes/admin/import.php:42
109
+ msgid ""
110
+ "Choose a Code Snippets (.xml) file to upload, then click Upload file and "
111
+ "import."
112
+ msgstr ""
113
+ "アップロードするスニペットファイル(.xml)を選択し、クリックしてファイルをアッ"
114
+ "プロードし、インポートして下さい。"
115
+
116
+ #: includes/admin/import.php:46
117
+ msgid "Choose a file from your computer:"
118
+ msgstr "ファイルをコンピュータから選択:"
119
+
120
+ #: includes/admin/import.php:46
121
+ msgid "(Maximum size: 8MB)"
122
+ msgstr "(最大ファイルサイズ: 8MB)"
123
+
124
+ #: includes/admin/import.php:55
125
+ msgid "Upload file and import"
126
+ msgstr "ファイルをアップロードし、インポート"
127
+
128
+ #: includes/admin/manage.php:21
129
+ msgid "Snippet <strong>activated</strong>."
130
+ msgstr "スニペットを <strong>有効化</strong>。"
131
+
132
+ #: includes/admin/manage.php:23
133
+ msgid "Selected snippets <strong>activated</strong>."
134
+ msgstr "選択されたスニペットを <strong>有効化</strong>。"
135
+
136
+ #: includes/admin/manage.php:25
137
+ msgid "Snippet <strong>deactivated</strong>."
138
+ msgstr "スニペットを <strong>停止</strong>。"
139
+
140
+ #: includes/admin/manage.php:27
141
+ msgid "Selected snippets <strong>deactivated</strong>."
142
+ msgstr "選択したスニペットを <strong>停止</strong>。"
143
+
144
+ #: includes/admin/manage.php:29
145
+ msgid "Snippet <strong>deleted</strong>."
146
+ msgstr "スニペットを <strong>削除</strong>。"
147
+
148
+ #: includes/admin/manage.php:31
149
+ msgid "Selected snippets <strong>deleted</strong>."
150
+ msgstr "選択されたスニペットを <strong>削除</strong>。"
151
+
152
+ #: includes/admin/manage.php:38 includes/admin/single.php:42
153
+ msgctxt "snippet"
154
+ msgid "Add New"
155
+ msgstr "新規追加"
156
+
157
+ #: includes/admin/manage.php:47
158
+ msgid "Search Installed Snippets"
159
+ msgstr "インストールされているスニペットを検索"
160
+
161
+ #: includes/admin/single.php:22
162
+ msgid "Please provide a name for the snippet and its code."
163
+ msgstr "スニペットもしくはコードに名前をつけて下さい。"
164
+
165
+ #: includes/admin/single.php:28
166
+ msgid "Snippet <strong>updated</strong>."
167
+ msgstr "スニペットを <strong>更新</strong>。"
168
+
169
+ #: includes/admin/single.php:30
170
+ msgid "Snippet <strong>added</strong>."
171
+ msgstr "スニペットを <strong>追加</strong>。"
172
+
173
+ #: includes/admin/single.php:55 includes/admin/single.php:56
174
+ msgid "Name (short title)"
175
+ msgstr "名前 (短いタイトル)"
176
+
177
+ #: includes/admin/single.php:61
178
+ msgid "Code"
179
+ msgstr "コード"
180
+
181
+ #: code-snippets.php:1433 includes/class-list-table.php:189
182
+ msgid "Description"
183
+ msgstr "説明"
184
+
185
+ #: code-snippets.php:1434
186
+ msgid "(Optional)"
187
+ msgstr "(オプション)"
188
+
189
+ #: includes/class-list-table.php:36
190
+ msgid "Snippets per page"
191
+ msgstr "1ページあたりのスニペット表示件数"
192
+
193
+ #: code-snippets.php:1118 includes/class-list-table.php:127
194
+ #: includes/class-list-table.php:213
195
+ msgid "Network Deactivate"
196
+ msgstr "ネットワーク 無効"
197
+
198
+ #: code-snippets.php:1118 includes/class-list-table.php:127
199
+ #: includes/class-list-table.php:213
200
+ msgid "Deactivate"
201
+ msgstr "無効"
202
+
203
+ #: code-snippets.php:1127 includes/class-list-table.php:137
204
+ #: includes/class-list-table.php:212
205
+ msgid "Network Activate"
206
+ msgstr "ネットワーク 有効"
207
+
208
+ #: code-snippets.php:1127 includes/class-list-table.php:137
209
+ #: includes/class-list-table.php:212
210
+ msgid "Activate"
211
+ msgstr "有効"
212
+
213
+ #: includes/class-list-table.php:187
214
+ msgid "Name"
215
+ msgstr "名前"
216
+
217
+ #: includes/class-list-table.php:188
218
+ msgid "ID"
219
+ msgstr "ID"
220
+
221
+ #: includes/class-list-table.php:147 includes/class-list-table.php:214
222
+ msgid "Export"
223
+ msgstr "エクスポート"
224
+
225
+ #: includes/class-list-table.php:155 includes/class-list-table.php:215
226
+ msgid "Delete"
227
+ msgstr "削除"
228
+
229
+ #: includes/class-list-table.php:216
230
+ msgid "Export to PHP"
231
+ msgstr "PHPにエクスポート"
232
+
233
+ #: includes/class-list-table.php:236
234
+ msgid "All <span class=\"count\">(%s)</span>"
235
+ msgid_plural "All <span class=\"count\">(%s)</span>"
236
+ msgstr[0] "全て <span class=\"count\">(%s)</span>"
237
+ msgstr[1] "全て <span class=\"count\">(%s)</span>"
238
+
239
+ #: includes/class-list-table.php:239
240
+ msgid "Active <span class=\"count\">(%s)</span>"
241
+ msgid_plural "Active <span class=\"count\">(%s)</span>"
242
+ msgstr[0] "有効 <span class=\"count\">(%s)</span>"
243
+ msgstr[1] "有効 <span class=\"count\">(%s)</span>"
244
+
245
+ #: includes/class-list-table.php:242
246
+ msgid "Recently Active <span class=\"count\">(%s)</span>"
247
+ msgid_plural "Recently Active <span class=\"count\">(%s)</span>"
248
+ msgstr[0] "最近まで使用 <span class=\"count\">(%s)</span>"
249
+ msgstr[1] "最近の有効 <span class=\"count\">(%s)</span>"
250
+
251
+ #: includes/class-list-table.php:245
252
+ msgid "Inactive <span class=\"count\">(%s)</span>"
253
+ msgid_plural "Inactive <span class=\"count\">(%s)</span>"
254
+ msgstr[0] "停止 <span class=\"count\">(%s)</span>"
255
+ msgstr[1] "停止 <span class=\"count\">(%s)</span>"
256
+
257
+ #: includes/class-list-table.php:279
258
+ msgid "Clear List"
259
+ msgstr "一覧をクリア"
260
+
261
+ #: includes/class-list-table.php:374
262
+ msgid ""
263
+ "You do not appear to have any snippets available at this time. <a href=\"%s"
264
+ "\">Add New&rarr;</a>"
265
+ msgstr "表示するスニペットがまだありません。<a href=\"%s\">新規追加&rarr;</a>"
266
+
267
+ #: includes/help/import.php:5 includes/help/manage.php:5
268
+ #: includes/help/single.php:5
269
+ msgid "Overview"
270
+ msgstr "概要"
271
+
272
+ #: includes/help/import.php:7
273
+ msgid ""
274
+ "Snippets are similar to plugins - they both extend and expand the "
275
+ "functionality of WordPress. Snippets are more light-weight, just a few lines "
276
+ "of code, and do not put as much load on your server. Here you can load "
277
+ "snippets from a Code Snippets (.xml) import file into the database with your "
278
+ "existing snippets."
279
+ msgstr ""
280
+ "スニペットはプラグインに似ています。両方ともWordPressの機能を拡張します。スニ"
281
+ "ペットは、より軽量、わずか数行のコードであり、サーバに負荷をかけません。ここ"
282
+ "であなたが持つスニペットを Code Snippets のインポートファイル(.xml) からデー"
283
+ "タベースに登録できます。"
284
+
285
+ #: includes/help/import.php:12
286
+ msgid "Importing"
287
+ msgstr "インポート中"
288
+
289
+ #: includes/help/import.php:15
290
+ msgid ""
291
+ "Snippets will be added to the database along with your existing snippets. "
292
+ "Regardless of whether the snippets were active on the previous site, "
293
+ "imported snippets are always inactive until activated using the <a href=\"%s"
294
+ "\">Manage Snippets</a> page.</p>"
295
+ msgstr ""
296
+ "スニペットは、既存のスニペットと一緒にデータベースに追加されます。<a href="
297
+ "\"%s\">スニペット管理</a> ページを使用して有効化されるまで、スニペットは、以"
298
+ "前のサイト上でアクティブになっていたかどうかにかかわらず、インポートされたス"
299
+ "ニペットは常に停止状態となります。</p>"
300
+
301
+ #: includes/help/import.php:20
302
+ msgid "Exporting"
303
+ msgstr "エクスポート中"
304
+
305
+ #: includes/help/import.php:22
306
+ msgid ""
307
+ "You can save your snippets to a Code Snippets (.xml) export file using the "
308
+ "<a href=\"%s\">Manage Snippets</a> page."
309
+ msgstr ""
310
+ "<a href=\"%s\">スニペット管理</a> ページでスニペットをCode Snippetsエクスポー"
311
+ "トファイル(.xml)に保存することができます。"
312
+
313
+ #: includes/help/import.php:26 includes/help/manage.php:27
314
+ #: includes/help/single.php:31
315
+ msgid "For more information:"
316
+ msgstr "より多くの情報:"
317
+
318
+ #: includes/help/import.php:27 includes/help/single.php:32
319
+ msgid ""
320
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
321
+ "\">WordPress Extend</a>"
322
+ msgstr ""
323
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
324
+ "\">WordPress Extend</a>"
325
+
326
+ #: includes/help/import.php:28 includes/help/manage.php:29
327
+ #: includes/help/single.php:33
328
+ msgid ""
329
+ "<a href=\"http://wordpress.org/support/plugin/code-snippets\" target=\"_blank"
330
+ "\">Support Forums</a>"
331
+ msgstr ""
332
+ "<a href=\"http://wordpress.org/support/plugin/code-snippets\" target=\"_blank"
333
+ "\">サポートフォラム</a>"
334
+
335
+ #: includes/help/manage.php:7
336
+ msgid ""
337
+ "Snippets are similar to plugins - they both extend and expand the "
338
+ "functionality of WordPress. Snippets are more light-weight, just a few lines "
339
+ "of code, and do not put as much load on your server. Here you can manage "
340
+ "your existing snippets and preform tasks on them such as activating, "
341
+ "deactivating, deleting and exporting."
342
+ msgstr ""
343
+ "スニペットはプラグインに似ています。両方ともWordPressの機能を拡張します。スニ"
344
+ "ペットは、より軽量、わずか数行のコードであり、サーバに負荷をかけません。ここ"
345
+ "では、既存のスニペットなどの有効化、停止、削除、エクスポートなど、それらのタ"
346
+ "スクを管理することができます。"
347
+
348
+ #: includes/help/manage.php:12
349
+ msgid "Safe Mode"
350
+ msgstr "セーフモード"
351
+
352
+ #: includes/help/manage.php:14
353
+ msgid ""
354
+ "Be sure to check your snippets for errors before you activate them, as a "
355
+ "faulty snippet could bring your whole blog down. If your site starts doing "
356
+ "strange things, deactivate all your snippets and activate them one at a time."
357
+ msgstr ""
358
+ "サイト全体が障害のあるスニペットで停止しないように、それらを有効化する前にス"
359
+ "ニペットを確認して下さい。サイトが奇妙な動作をした場合は、すべてのスニペット"
360
+ "を無効化し、それらを一度に1をアクティブにします。"
361
+
362
+ #: includes/help/manage.php:20
363
+ msgid "Uninstall"
364
+ msgstr "アンインストール"
365
+
366
+ #: includes/help/manage.php:22
367
+ msgid ""
368
+ "When you delete Code Snippets through the Plugins menu in WordPress it will "
369
+ "clear up the <code>%1$s</code> table and a few other bits of data stored in "
370
+ "the database. If you want to keep this data (ie: you are only temporally "
371
+ "uninstalling Code Snippets) then remove the <code>%2$s</code> folder using "
372
+ "FTP."
373
+ msgstr ""
374
+ "あなたがワードプレスでのプラグインメニューからコードスニペットを削除すると"
375
+ "き、<code>%1$s</code>テーブルと、データベースに格納されたデータのいくつかをク"
376
+ "リアします。(例:あなただけの一時的コードスニペットをアンインストールする)"
377
+ "このデータを保持する場合は、FTPを使用して <code>%2$s</code> フォルダを削除し"
378
+ "ます。"
379
+
380
+ #: includes/help/manage.php:23
381
+ msgid ""
382
+ "Even if you're sure that you don't want to use Code Snippets ever again on "
383
+ "this WordPress installation, you may want to use the export feature to back "
384
+ "up your snippets."
385
+ msgstr ""
386
+ "インストールされたスニペットコードをこのWordPressで使用しないとしても、スニ"
387
+ "ペットをエクスポート機能でバックアップして使用することができます。"
388
+
389
+ #: includes/help/manage.php:28
390
+ msgid ""
391
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
392
+ "\">WordPress Extend</a></p>"
393
+ msgstr ""
394
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
395
+ "\">WordPress Extend</a></p>"
396
+
397
+ #: includes/help/single.php:7
398
+ msgid ""
399
+ "Snippets are similar to plugins - they both extend and expand the "
400
+ "functionality of WordPress. Snippets are more light-weight, just a few lines "
401
+ "of code, and do not put as much load on your server. Here you can add a new "
402
+ "snippet, or edit an existing one."
403
+ msgstr ""
404
+ "スニペットはプラグインに似ています。両方ともWordPressの機能を拡張します。スニ"
405
+ "ペットは、より軽量、わずか数行のコードであり、サーバに負荷をかけません。ここ"
406
+ "では、新しいスニペットを追加するか、既存のものを編集することができます。"
407
+
408
+ #: includes/help/single.php:11
409
+ msgid "Finding Snippets"
410
+ msgstr "スニペットを探す"
411
+
412
+ #: includes/help/single.php:13
413
+ msgid ""
414
+ "Here are some links to websites which host a large number of snippets that "
415
+ "you can add to your site.\n"
416
+ "\t\t<ul>\n"
417
+ "\t\t\t<li><a href=\"http://wp-snippets.com\" title=\"WordPress Snippets\">WP-"
418
+ "Snippets</a></li>\n"
419
+ "\t\t\t<li><a href=\"http://wpsnipp.com\" title=\"WP Snipp\">WP Snipp</a></"
420
+ "li>\n"
421
+ "\t\t\t<li><a href=\"http://www.catswhocode.com/blog/snippets\" title=\"Cats "
422
+ "Who Code Snippet Library\">Cats Who Code</a></li>\n"
423
+ "\t\t\t<li><a href=\"http://www.wpfunction.me\">WP Function Me</a></li>\n"
424
+ "\t\t</ul>"
425
+ msgstr ""
426
+ "ここにあなたのサイトに追加できるスニペットをホストしているWebサイトを挙げま"
427
+ "す。\n"
428
+ "\t\t<ul>\n"
429
+ "\t\t\t<li><a href=\"http://wp-snippets.com\" title=\"WordPress Snippets\">WP-"
430
+ "Snippets</a></li>\n"
431
+ "\t\t\t<li><a href=\"http://wpsnipp.com\" title=\"WP Snipp\">WP Snipp</a></"
432
+ "li>\n"
433
+ "\t\t\t<li><a href=\"http://www.catswhocode.com/blog/snippets\" title=\"Cats "
434
+ "Who Code Snippet Library\">Cats Who Code</a></li>\n"
435
+ "\t\t\t<li><a href=\"http://www.wpfunction.me\">WP Function Me</a></li>\n"
436
+ "\t\t</ul>"
437
+
438
+ #: includes/help/single.php:24
439
+ msgid "Adding Snippets"
440
+ msgstr "スニペットを追加"
441
+
442
+ #: includes/help/single.php:26
443
+ msgid ""
444
+ "You need to fill out the name and code fields for your snippet to be added. "
445
+ "While the description field will add more information about how your snippet "
446
+ "works, what is does and where you found it, it is completely optional."
447
+ msgstr ""
448
+ "あなたは、追加するスニペットの名前とコードのフィールドに必要事項を記入する必"
449
+ "要があります。説明フィールドには、あなたのスニペットがどのように機能するかに"
450
+ "ついての詳細情報を記入しますが、これは任意です。"
451
+
452
+ #: includes/help/single.php:27
453
+ msgid ""
454
+ "Please be sure to check that your snippet is valid PHP code and will not "
455
+ "produce errors before adding it through this page. While doing so will not "
456
+ "become active straight away, it will help to minimise the chance of a faulty "
457
+ "snippet becoming active on your site."
458
+ msgstr ""
459
+ "このページで追加するスニペットのPHPコードがエラーを起こさないことを確認して下"
460
+ "さい。そうすることですぐに有効になりませんが、障害のあるスニペットは、サイト"
461
+ "上で有効になる可能性を最小限に抑えるのに役立ちます。"
462
+
463
+ #: code-snippets.php:0
464
+ msgid "http://code-snippets.bungeshea.com"
465
+ msgstr "http://code-snippets.bungeshea.com"
466
+
467
+ #: code-snippets.php:263
468
+ msgid "Import snippets from a <strong>Code Snippets</strong> export file"
469
+ msgstr ""
470
+ "スニペットを<strong>Code Snippets</strong>のエクスポートファイルからインポー"
471
+ "ト"
472
+
473
+ #: includes/admin/import.php:20
474
+ msgid "Imported <strong>%d</strong> snippet."
475
+ msgid_plural "Imported <strong>%d</strong> snippets."
476
+ msgstr[0] "スニペットを <strong>%d</strong> 件インポートしました。"
477
+ msgstr[1] "スニペットを <strong>%d</strong> 件インポートしました。"
478
+
479
+ #: includes/help/import.php:29 includes/help/manage.php:30
480
+ #: includes/help/single.php:34
481
+ msgid ""
482
+ "<a href=\"http://code-snippets.bungeshea.com/\" target=\"_blank\">Project "
483
+ "Website</a>"
484
+ msgstr ""
485
+ "<a href=\"http://code-snippets.bungeshea.com/\" target=\"_blank\">プロジェク"
486
+ "トサイト</a>"
487
+
488
+ #: includes/help/manage.php:15
489
+ msgid ""
490
+ "If something goes wrong with a snippet and you can't use WordPress, you can "
491
+ "cause all snippets to stop executing by adding <code>define"
492
+ "('CODE_SNIPPETS_SAFE_MODE', true);</code> to your <code>wp-config.php</code> "
493
+ "file. After you have deactivated the offending snippet, you can turn off "
494
+ "safe mode by removing this line or replacing <strong>true</strong> with "
495
+ "<strong>false</strong>."
496
+ msgstr ""
497
+ "もしもスニペットに何か問題があってWordPressが使えなくなったら、<code>wp-"
498
+ "config.php</code>ファイルに <code>define('CODE_SNIPPETS_SAFE_MODE', true);</"
499
+ "code> と記述することでスニペットの実行を停止します。あなたが問題のスニペット"
500
+ "を無効にした後は、この行を削除するか、<strong>true</strong> を "
501
+ "<strong>false</strong> に置き換えることでセーフモードをオフにすることができま"
502
+ "す。"
503
+
504
+ #: includes/help/single.php:20
505
+ msgid ""
506
+ "More places to find snippets, as well as a selection of example snippets, "
507
+ "can be found in the <a href=\"http://code-snippets.bungeshea.com/docs/"
508
+ "finding-snippets/\">plugin documentation</a>"
509
+ msgstr ""
510
+ "スニペットの例は、<a href=\"http://code-snippets.bungeshea.com/docs/finding-"
511
+ "snippets/\">プラグインドキュメント</a> に記載されています。"
512
+
513
+ #: code-snippets.php:0
514
+ msgid "1.7"
515
+ msgstr "1.7"
516
+
517
+ #: code-snippets.php:602 includes/class-list-table.php:142
518
+ msgid "Edit"
519
+ msgstr "編集"
520
+
521
+ #: code-snippets.php:1227
522
+ msgid "Sorry, you're not allowed to edit snippets"
523
+ msgstr "申し訳ありません、スニペット編集の許可がないようです"
524
+
525
+ #: includes/admin/single.php:24
526
+ msgid "Snippet <strong>updated</strong> and <strong>activated</strong>."
527
+ msgstr ""
528
+ "スニペットを <strong>更新</strong> し、 <strong>有効化</strong>しました。"
529
+
530
+ #: includes/admin/single.php:26
531
+ msgid "Snippet <strong>added</strong> and <strong>activated</strong>."
532
+ msgstr ""
533
+ "スニペットを <strong>追加</strong> し、 <strong>有効化</strong>しました。"
534
+
535
+ #: includes/class-list-table.php:163
536
+ msgid ""
537
+ "You are about to permanently delete the selected item.\n"
538
+ "\t\t\t\t'Cancel' to stop, 'OK' to delete."
539
+ msgstr ""
540
+ "あなたは永久に選択した項目を削除しようとしています。\n"
541
+ "\t\t\t\t 削除するには、'OK'を、中止するには 'Cancel'をクリックして下さい。"
542
+
543
+ #: includes/class-list-table.php:270
544
+ msgid "Filter"
545
+ msgstr "検索条件"
546
+
547
+ #: includes/class-list-table.php:541
548
+ msgid "Search results"
549
+ msgstr "検索結果"
550
+
551
+ #: includes/class-list-table.php:544
552
+ msgid " for &#8220;%s&#8221;"
553
+ msgstr " for &#8220;%s&#8221;"
554
+
555
+ #: includes/class-list-table.php:550
556
+ msgid "Clear Filters"
557
+ msgstr "検索条件を解除"
558
+
559
+ #: includes/help/import.php:14
560
+ msgid ""
561
+ "You can load your snippets from a code snippets (.xml) export file using "
562
+ "this page."
563
+ msgstr ""
564
+ "このページでスニペットコードをエクスポートファイル(.xml)から読み込むことがで"
565
+ "きます。"
566
+
567
+ #: includes/admin/single.php:74
568
+ msgid "Save Changes &amp; Activate"
569
+ msgstr "変更を保存 &amp; 有効化"
languages/code-snippets-ru_RU.mo ADDED
Binary file
languages/code-snippets-ru_RU.po ADDED
@@ -0,0 +1,610 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is distributed under the same license as the Code Snippets package.
2
+ msgid ""
3
+ msgstr ""
4
+ "Project-Id-Version: Code Snippets\n"
5
+ "POT-Creation-Date: 2014-10-11 15:52+0300\n"
6
+ "PO-Revision-Date: 2014-10-11 16:25+0300\n"
7
+ "Last-Translator: Flector <rlector@gmail.com>\n"
8
+ "Language-Team: Flector <rlector@gmail.com>\n"
9
+ "Language: ru\n"
10
+ "MIME-Version: 1.0\n"
11
+ "Content-Type: text/plain; charset=UTF-8\n"
12
+ "Content-Transfer-Encoding: 8bit\n"
13
+ "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n"
14
+ "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
15
+ "X-Generator: Poedit 1.6.9\n"
16
+ "X-Poedit-SourceCharset: UTF-8\n"
17
+ "X-Poedit-Basepath: ../\n"
18
+ "X-Poedit-KeywordsList: __;_e;__ngettext:1,2;_n:1,2;_x:1,2c;_n;_nx:4c,1,2;"
19
+ "_nx_noop:4c,1,2;_ex:1,2c;__ngettext_noop:1,2;_n_noop:1,2;_x;esc_html_x;"
20
+ "esc_html_e\n"
21
+ "X-Poedit-SearchPath-0: .\n"
22
+
23
+ #: admin/help/import.php:16 admin/help/manage.php:16 admin/help/single.php:15
24
+ msgid "Overview"
25
+ msgstr "Обзор"
26
+
27
+ #: admin/help/import.php:18
28
+ msgid ""
29
+ "Snippets are similar to plugins - they both extend and expand the "
30
+ "functionality of WordPress. Snippets are more light-weight, just a few lines "
31
+ "of code, and do not put as much load on your server. Here you can load "
32
+ "snippets from a Code Snippets (.xml) import file into the database with your "
33
+ "existing snippets."
34
+ msgstr ""
35
+ "Сниппеты похожи на плагины - и те и другие расширяют функциональность движка "
36
+ "WordPress. Сниппеты зачастую маленькие, состоят лишь из нескольких строк "
37
+ "кода и не вызывают нагрузки на ваш сервер. Здесь вы можете загрузить ваши "
38
+ "сниппеты из файла экспорта плагина (.xml), чтобы добавить их на ваш сайт."
39
+
40
+ #: admin/help/import.php:23
41
+ msgid "Importing"
42
+ msgstr "Импортирование"
43
+
44
+ #: admin/help/import.php:25
45
+ msgid ""
46
+ "You can load your snippets from a code snippets (.xml) export file using "
47
+ "this page."
48
+ msgstr "Вы можете загрузить ваши сниппеты из файла экспорта (.xml)."
49
+
50
+ #: admin/help/import.php:26
51
+ #, php-format
52
+ msgid ""
53
+ "Snippets will be added to the database along with your existing snippets. "
54
+ "Regardless of whether the snippets were active on the previous site, "
55
+ "imported snippets are always inactive until activated using the <a href=\"%s"
56
+ "\">Manage Snippets</a> page.</p>"
57
+ msgstr ""
58
+ "Сниппеты будут добавлены в вашу базу (они не будут работать до тех пор, пока "
59
+ "вы их не активируете на странице <a href=\"%s\">Управление сниппетами</a>)</"
60
+ "p>"
61
+
62
+ #: admin/help/import.php:31
63
+ msgid "Exporting"
64
+ msgstr "Экспортирование"
65
+
66
+ #: admin/help/import.php:33
67
+ #, php-format
68
+ msgid ""
69
+ "You can save your snippets to a Code Snippets (.xml) export file using the "
70
+ "<a href=\"%s\">Manage Snippets</a> page."
71
+ msgstr ""
72
+ "Вы можете сохранить ваши сниппеты в файл экспорта (.xml) на странице <a href="
73
+ "\"%s\">Управление сниппетами</a>."
74
+
75
+ #: admin/help/import.php:37 admin/help/manage.php:38 admin/help/single.php:43
76
+ msgid "For more information:"
77
+ msgstr "Больше информации:"
78
+
79
+ #: admin/help/import.php:38 admin/help/single.php:44
80
+ msgid ""
81
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
82
+ "\">WordPress Extend</a>"
83
+ msgstr ""
84
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
85
+ "\">Страница плагина</a>"
86
+
87
+ #: admin/help/import.php:39 admin/help/manage.php:40 admin/help/single.php:45
88
+ msgid ""
89
+ "<a href=\"http://wordpress.org/support/plugin/code-snippets\" target=\"_blank"
90
+ "\">Support Forums</a>"
91
+ msgstr ""
92
+ "<a href=\"http://wordpress.org/support/plugin/code-snippets\" target=\"_blank"
93
+ "\">Форумы поддержки</a>"
94
+
95
+ #: admin/help/import.php:40 admin/help/manage.php:41 admin/help/single.php:46
96
+ msgid ""
97
+ "<a href=\"http://code-snippets.bungeshea.com/\" target=\"_blank\">Project "
98
+ "Website</a>"
99
+ msgstr ""
100
+ "<a href=\"http://code-snippets.bungeshea.com/\" target=\"_blank\">Сайт "
101
+ "плагина</a>"
102
+
103
+ #: admin/help/manage.php:18
104
+ msgid ""
105
+ "Snippets are similar to plugins - they both extend and expand the "
106
+ "functionality of WordPress. Snippets are more light-weight, just a few lines "
107
+ "of code, and do not put as much load on your server. Here you can manage "
108
+ "your existing snippets and preform tasks on them such as activating, "
109
+ "deactivating, deleting and exporting."
110
+ msgstr ""
111
+ "Сниппеты похожи на плагины - и те и другие расширяют функциональность движка "
112
+ "WordPress. Сниппеты зачастую маленькие, состоят лишь из нескольких строк "
113
+ "кода и не вызывают нагрузки на ваш сервер. Здесь вы можете управлять вашими "
114
+ "сниппетами (добавлять, редактировать, активировать и деактивировать)."
115
+
116
+ #: admin/help/manage.php:23
117
+ msgid "Safe Mode"
118
+ msgstr "Safe Mode"
119
+
120
+ #: admin/help/manage.php:25
121
+ msgid ""
122
+ "Be sure to check your snippets for errors before you activate them, as a "
123
+ "faulty snippet could bring your whole blog down. If your site starts doing "
124
+ "strange things, deactivate all your snippets and activate them one at a time."
125
+ msgstr ""
126
+ "Прежде чем активировать сниппеты убедитесь, что они не содержат ошибок. "
127
+ "Некорректные сниппеты могут испортить вам сайт!"
128
+
129
+ #: admin/help/manage.php:26
130
+ msgid ""
131
+ "If something goes wrong with a snippet and you can't use WordPress, you can "
132
+ "cause all snippets to stop executing by adding "
133
+ "<code>define('CODE_SNIPPETS_SAFE_MODE', true);</code> to your <code>wp-"
134
+ "config.php</code> file. After you have deactivated the offending snippet, "
135
+ "you can turn off safe mode by removing this line or replacing <strong>true</"
136
+ "strong> with <strong>false</strong>."
137
+ msgstr ""
138
+ "В случае любых проблем со сниппетами плагина вы можете их все "
139
+ "деактивировать, добавив строчку <code>define('CODE_SNIPPETS_SAFE_MODE', "
140
+ "true);</code> в ваш файл конфигурации <code>wp-config.php</code> . После "
141
+ "этого вы сможете деактивировать глючный сниппет, а потом снова включить "
142
+ "плагин, удалив указанную строчку."
143
+
144
+ #: admin/help/manage.php:31
145
+ msgid "Uninstall"
146
+ msgstr "Удаление"
147
+
148
+ #: admin/help/manage.php:33
149
+ #, php-format
150
+ msgid ""
151
+ "When you delete Code Snippets through the Plugins menu in WordPress it will "
152
+ "clear up the <code>%1$s</code> table and a few other bits of data stored in "
153
+ "the database. If you want to keep this data (ie: you are only temporally "
154
+ "uninstalling Code Snippets) then remove the <code>%2$s</code> folder using "
155
+ "FTP."
156
+ msgstr ""
157
+ "При удалении плагина через меню \"Плагины\" в админке блога таблица <code>"
158
+ "%1$s</code> в базе данных будет удалена. Если вы хотите сохранить настройки "
159
+ "(сниппеты) плагина, то удаляйте плагин (<code>%2$s</code>) через FTP, а не "
160
+ "через админку. Только в этом случае ваши сниппеты не будут потеряны (но вы, "
161
+ "конечно, можете сделать экспорт сниппетов во внешний .xml файл)."
162
+
163
+ #: admin/help/manage.php:34
164
+ msgid ""
165
+ "Even if you're sure that you don't want to use Code Snippets ever again on "
166
+ "this WordPress installation, you may want to use the export feature to back "
167
+ "up your snippets."
168
+ msgstr ""
169
+ "Даже если вы уверены, что не будете использовать данный плагин, то все равно "
170
+ "на всякий случай сделайте экспорт всех сниппетов кода."
171
+
172
+ #: admin/help/manage.php:39
173
+ msgid ""
174
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
175
+ "\">WordPress Extend</a></p>"
176
+ msgstr ""
177
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
178
+ "\">Страница плагина</a></p>"
179
+
180
+ #: admin/help/single.php:17
181
+ msgid ""
182
+ "Snippets are similar to plugins - they both extend and expand the "
183
+ "functionality of WordPress. Snippets are more light-weight, just a few lines "
184
+ "of code, and do not put as much load on your server. Here you can add a new "
185
+ "snippet, or edit an existing one."
186
+ msgstr ""
187
+ "Сниппеты похожи на плагины - и те и другие расширяют функциональность движка "
188
+ "WordPress. Сниппеты зачастую маленькие, состоят лишь из нескольких строк "
189
+ "кода и не вызывают нагрузки на ваш сервер. Здесь вы можете добавить новый "
190
+ "сниппет или отредактировать уже существующий."
191
+
192
+ #: admin/help/single.php:22
193
+ msgid "Finding Snippets"
194
+ msgstr "Поиск сниппетов"
195
+
196
+ #: admin/help/single.php:24
197
+ msgid ""
198
+ "Here are some links to websites which host a large number of snippets that "
199
+ "you can add to your site.\n"
200
+ "\t\t<ul>\n"
201
+ "\t\t\t<li><a href=\"http://wp-snippets.com\" title=\"WordPress Snippets\">WP-"
202
+ "Snippets</a></li>\n"
203
+ "\t\t\t<li><a href=\"http://wpsnipp.com\" title=\"WP Snipp\">WP Snipp</a></"
204
+ "li>\n"
205
+ "\t\t\t<li><a href=\"http://www.catswhocode.com/blog/snippets\" title=\"Cats "
206
+ "Who Code Snippet Library\">Cats Who Code</a></li>\n"
207
+ "\t\t\t<li><a href=\"http://www.wpfunction.me\">WP Function Me</a></li>\n"
208
+ "\t\t</ul>"
209
+ msgstr ""
210
+ "Здесь указаны ссылки на некоторые сайты со сниппетами:\n"
211
+ "\t\t<ul>\n"
212
+ "\t\t\t<li><a href=\"http://www.wphook.ru\" title=\"WPHook.ru\">WPHook.ru</"
213
+ "a></li>\n"
214
+ "\t\t\t<li><a href=\"http://wp-snippets.com\" title=\"WordPress Snippets\">WP-"
215
+ "Snippets</a></li>\n"
216
+ "\t\t\t<li><a href=\"http://wpsnipp.com\" title=\"WP Snipp\">WP Snipp</a></"
217
+ "li>\n"
218
+ "\t\t\t<li><a href=\"http://www.catswhocode.com/blog/snippets\" title=\"Cats "
219
+ "Who Code Snippet Library\">Cats Who Code</a></li>\n"
220
+ "\t\t\t<li><a href=\"http://www.wpfunction.me\">WP Function Me</a></li>\n"
221
+ "\t\t</ul>"
222
+
223
+ #: admin/help/single.php:31
224
+ msgid ""
225
+ "More places to find snippets, as well as a selection of example snippets, "
226
+ "can be found in the <a href=\"http://code-snippets.bungeshea.com/docs/"
227
+ "finding-snippets/\">plugin documentation</a>"
228
+ msgstr ""
229
+ "Другие ссылки вы можете найти на <a href=\"http://code-snippets.bungeshea."
230
+ "com/docs/finding-snippets/\">странице плагина</a>"
231
+
232
+ #: admin/help/single.php:36
233
+ msgid "Adding Snippets"
234
+ msgstr "Добавление сниппетов"
235
+
236
+ #: admin/help/single.php:38
237
+ msgid ""
238
+ "You need to fill out the name and code fields for your snippet to be added. "
239
+ "While the description field will add more information about how your snippet "
240
+ "works, what is does and where you found it, it is completely optional."
241
+ msgstr "Вы должны заполнить имя и "
242
+
243
+ #: admin/help/single.php:39
244
+ msgid ""
245
+ "Please be sure to check that your snippet is valid PHP code and will not "
246
+ "produce errors before adding it through this page. While doing so will not "
247
+ "become active straight away, it will help to minimise the chance of a faulty "
248
+ "snippet becoming active on your site."
249
+ msgstr ""
250
+ "Пожалуйста, убедитесь в том, что добавляемый вами сниппет является "
251
+ "корректным PHP кодом, так как иначе могут возникнуть проблемы с "
252
+ "работоспособностью вашего сайта."
253
+
254
+ #: admin/messages/import.php:18
255
+ #, php-format
256
+ msgid ""
257
+ "Successfully imported <strong>%d</strong> snippet. <a href=\"%s\">Have fun!</"
258
+ "a>"
259
+ msgid_plural ""
260
+ "Successfully imported <strong>%d</strong> snippets. <a href=\"%s\">Have fun!"
261
+ "</a>"
262
+ msgstr[0] ""
263
+ "Удачно импортирован <strong>%d</strong> сниппет. <a href=\"%s\">Удачи!</a>"
264
+ msgstr[1] ""
265
+ "Удачно импортировано <strong>%d</strong> сниппета. <a href=\"%s\">Удачи!</a>"
266
+ msgstr[2] ""
267
+ "Удачно импортировано <strong>%d</strong> сниппетов. <a href=\"%s\">Удачи!</a>"
268
+
269
+ #: admin/messages/import.php:32
270
+ msgid "An error occurred when processing the import file."
271
+ msgstr "Произошла ошибка при импортировании сниппета."
272
+
273
+ #: admin/messages/manage.php:14
274
+ msgid ""
275
+ "<strong>Warning:</strong> Safe mode is active and snippets will not execute! "
276
+ "Remove the <code>CODE_SNIPPETS_SAFE_MODE</code> constant from <code>wp-"
277
+ "config.php</code> to turn off safe mode. <a href=\"http://code-snippets."
278
+ "bungeshea.com/docs/safe-mode/\" target=\"_blank\">Help</a>"
279
+ msgstr ""
280
+ "<strong>Внимание:</strong> активирован режим Safe mode и поэтому сниппеты не "
281
+ "будут выполняться! Удалите константу <code>CODE_SNIPPETS_SAFE_MODE</code> из "
282
+ "файла <code>wp-config.php</code>, чтобы выключить режим Safe mode. <a href="
283
+ "\"http://code-snippets.bungeshea.com/docs/safe-mode/\" target=\"_blank"
284
+ "\">Помощь</a>"
285
+
286
+ #: admin/messages/manage.php:20
287
+ msgid "Snippet <strong>activated</strong>."
288
+ msgstr "Сниппет <strong>активирован</strong>."
289
+
290
+ #: admin/messages/manage.php:24
291
+ msgid "Selected snippets <strong>activated</strong>."
292
+ msgstr "Выбранные сниппеты <strong>активированы</strong>."
293
+
294
+ #: admin/messages/manage.php:28
295
+ msgid "Snippet <strong>deactivated</strong>."
296
+ msgstr "Сниппет <strong>деактивирован</strong>."
297
+
298
+ #: admin/messages/manage.php:32
299
+ msgid "Selected snippets <strong>deactivated</strong>."
300
+ msgstr "Выбранные сниппеты <strong>деактивированы</strong>."
301
+
302
+ #: admin/messages/manage.php:36
303
+ msgid "Snippet <strong>deleted</strong>."
304
+ msgstr "Сниппет <strong>удален</strong>."
305
+
306
+ #: admin/messages/manage.php:40
307
+ msgid "Selected snippets <strong>deleted</strong>."
308
+ msgstr "Выбранные сниппеты <strong>удалены</strong>."
309
+
310
+ #: admin/messages/single.php:14
311
+ msgid "An error occurred when saving the snippet."
312
+ msgstr "Произошла ошибка при сохранении сниппета."
313
+
314
+ #: admin/messages/single.php:18
315
+ msgid "Snippet <strong>updated</strong> and <strong>activated</strong>."
316
+ msgstr "Сниппет <strong>обновлен</strong> и <strong>активирован</strong>."
317
+
318
+ #: admin/messages/single.php:22
319
+ msgid "Snippet <strong>added</strong> and <strong>activated</strong>."
320
+ msgstr "Сниппет <strong>добавлен</strong> и <strong>активирован</strong>."
321
+
322
+ #: admin/messages/single.php:26
323
+ msgid "Snippet <strong>updated</strong> and <strong>deactivated</strong>."
324
+ msgstr "Сниппет <strong>обновлен</strong> и <strong>деактивирован</strong>."
325
+
326
+ #: admin/messages/single.php:30
327
+ msgid "Snippet <strong>updated</strong>."
328
+ msgstr "Сниппет <strong>обновлен</strong>."
329
+
330
+ #: admin/messages/single.php:34
331
+ msgid "Snippet <strong>added</strong>."
332
+ msgstr "Сниппет <strong>добавлен</strong>."
333
+
334
+ #: admin/views/import.php:20 includes/class-admin.php:327
335
+ msgid "Import Snippets"
336
+ msgstr "Импортирование сниппетов"
337
+
338
+ #: admin/views/import.php:24
339
+ msgid ""
340
+ "Howdy! Upload your Code Snippets export file and we&#8217;ll import the "
341
+ "snippets to this site."
342
+ msgstr ""
343
+ "Привет! Загрузите файл экспорта, чтобы импортировать сниппеты на этот сайт."
344
+
345
+ #: admin/views/import.php:26
346
+ #, php-format
347
+ msgid ""
348
+ "You will need to go to the <a href=\"%s\">Manage Snippets</a> page to "
349
+ "activate the imported snippets."
350
+ msgstr ""
351
+ "Вы должны будете зайти в <a href=\"%s\">Управление сниппетами</a>, чтобы "
352
+ "активировать импортированные сниппеты."
353
+
354
+ #: admin/views/import.php:28
355
+ msgid ""
356
+ "Choose a Code Snippets (.xml) file to upload, then click Upload file and "
357
+ "import."
358
+ msgstr ""
359
+ "Выберите файл экспорта (.xml), а затем кликните на \"Загрузить файл и "
360
+ "импортировать\"."
361
+
362
+ #: admin/views/import.php:35
363
+ msgid "Choose a file from your computer:"
364
+ msgstr "Выберите файл на вашем компьютере:"
365
+
366
+ #: admin/views/import.php:36
367
+ msgid "(Maximum size: 8MB)"
368
+ msgstr "(Максимальный размер: 8MB)"
369
+
370
+ #: admin/views/import.php:42
371
+ msgid "Upload file and import"
372
+ msgstr "Загрузить файл и импортировать"
373
+
374
+ #: admin/views/manage.php:21 includes/class-admin.php:152
375
+ #: includes/class-admin.php:276 includes/class-admin.php:277
376
+ #: includes/class-admin.php:287
377
+ msgid "Snippets"
378
+ msgstr "Сниппеты"
379
+
380
+ #: admin/views/manage.php:26 admin/views/single.php:34
381
+ #: includes/class-admin.php:300
382
+ msgid "Add New"
383
+ msgstr "Добавить новый"
384
+
385
+ #: admin/views/manage.php:39
386
+ msgid "Search Installed Snippets"
387
+ msgstr "Искать установленные сниппеты"
388
+
389
+ #: admin/views/single.php:29 includes/class-admin.php:299
390
+ msgid "Edit Snippet"
391
+ msgstr "Редактирование сниппета"
392
+
393
+ #: admin/views/single.php:37 includes/class-admin.php:299
394
+ msgid "Add New Snippet"
395
+ msgstr "Добавление нового сниппета"
396
+
397
+ #: admin/views/single.php:53 admin/views/single.php:54
398
+ msgid "Name (short title)"
399
+ msgstr "Имя (короткое название на английском)"
400
+
401
+ #: admin/views/single.php:59
402
+ msgid "Code"
403
+ msgstr "Код"
404
+
405
+ #: admin/views/single.php:85
406
+ msgid "Save Changes &amp; Activate"
407
+ msgstr "Сохранить изменения &amp; Активировать"
408
+
409
+ #: admin/views/single.php:91
410
+ msgid "Save Changes &amp; Deactivate"
411
+ msgstr "Сохранить изменения &amp; Деактивировать"
412
+
413
+ #: admin/views/single.php:100 includes/class-list-table.php:166
414
+ #: includes/class-list-table.php:265
415
+ msgid "Export"
416
+ msgstr "Экспорт"
417
+
418
+ #: admin/views/single.php:107 includes/class-list-table.php:182
419
+ msgid "Вы действительно хотите удалить выбранный сниппет?"
420
+ msgstr "Вы действительно хотите удалить выбранный сниппет?"
421
+
422
+ #: admin/views/single.php:112 includes/class-list-table.php:175
423
+ #: includes/class-list-table.php:266
424
+ msgid "Delete"
425
+ msgstr "Удалить"
426
+
427
+ #: includes/class-admin.php:185
428
+ msgid "Code Snippets"
429
+ msgstr "Code Snippets"
430
+
431
+ #: includes/class-admin.php:186
432
+ msgid "Import snippets from a Code Snippets export file"
433
+ msgstr "Импортировать сниппеты из файла экспорта плагина \"Code Snippets\"."
434
+
435
+ #: includes/class-admin.php:246
436
+ msgid "You are not authorized to access this page."
437
+ msgstr "У вас нет доступа к этой странице."
438
+
439
+ #: includes/class-admin.php:288 includes/class-admin.php:695
440
+ msgid "Manage"
441
+ msgstr "Управление сниппетами"
442
+
443
+ #: includes/class-admin.php:300 includes/class-list-table.php:160
444
+ msgid "Edit"
445
+ msgstr "Редактировать"
446
+
447
+ #: includes/class-admin.php:328
448
+ msgid "Import"
449
+ msgstr "Импорт"
450
+
451
+ #: includes/class-admin.php:663 includes/class-list-table.php:227
452
+ msgid "Description"
453
+ msgstr "Описание"
454
+
455
+ #: includes/class-admin.php:694
456
+ msgid "Manage your existing snippets"
457
+ msgstr "Управление вашими сниппетами"
458
+
459
+ #: includes/class-admin.php:722
460
+ msgid "Visit the WordPress.org plugin page"
461
+ msgstr "Посетить страницу плагина на WordPress.org"
462
+
463
+ #: includes/class-admin.php:723
464
+ msgid "About"
465
+ msgstr "О плагине"
466
+
467
+ #: includes/class-admin.php:727
468
+ msgid "Visit the support forums"
469
+ msgstr "Посетить форумы поддержки"
470
+
471
+ #: includes/class-admin.php:728
472
+ msgid "Support"
473
+ msgstr "Поддержка"
474
+
475
+ #: includes/class-admin.php:732
476
+ msgid "Support this plugin's development"
477
+ msgstr "Поддержите развитие плагина"
478
+
479
+ #: includes/class-admin.php:733
480
+ msgid "Donate"
481
+ msgstr "Пожертвования"
482
+
483
+ #: includes/class-admin.php:764
484
+ msgid ""
485
+ "<strong>Have feedback on Code Snippets?</strong> Please take the time to "
486
+ "answer a short survey on how you use this plugin and what you'd like to see "
487
+ "changed or added in the future."
488
+ msgstr ""
489
+ "<strong>У вас есть замечания по работе Code Snippets?</strong> Тогда "
490
+ "пожалуйста заполните анкету на сайте плагина."
491
+
492
+ #: includes/class-admin.php:767
493
+ msgid "Take the survey now"
494
+ msgstr "Оставить отзыв"
495
+
496
+ #: includes/class-list-table.php:49
497
+ msgid "Snippets per page"
498
+ msgstr "Сниппетов на страницу"
499
+
500
+ #: includes/class-list-table.php:141 includes/class-list-table.php:264
501
+ msgid "Network Deactivate"
502
+ msgstr "Деактивировать в сети"
503
+
504
+ #: includes/class-list-table.php:141 includes/class-list-table.php:264
505
+ msgid "Deactivate"
506
+ msgstr "Деактивировать"
507
+
508
+ #: includes/class-list-table.php:150 includes/class-list-table.php:263
509
+ msgid "Network Activate"
510
+ msgstr "Активировать в сети"
511
+
512
+ #: includes/class-list-table.php:150 includes/class-list-table.php:263
513
+ msgid "Activate"
514
+ msgstr "Активировать"
515
+
516
+ #: includes/class-list-table.php:189
517
+ #, php-format
518
+ msgid "Untitled #%d"
519
+ msgstr "Untitled #%d"
520
+
521
+ #: includes/class-list-table.php:225
522
+ msgid "Name"
523
+ msgstr "Имя"
524
+
525
+ #: includes/class-list-table.php:226
526
+ msgid "ID"
527
+ msgstr "ID"
528
+
529
+ #: includes/class-list-table.php:267
530
+ msgid "Export to PHP"
531
+ msgstr "Экспорт в PHP"
532
+
533
+ #: includes/class-list-table.php:303
534
+ #, php-format
535
+ msgid "All <span class=\"count\">(%s)</span>"
536
+ msgid_plural "All <span class=\"count\">(%s)</span>"
537
+ msgstr[0] "Все <span class=\"count\">(%s)</span>"
538
+ msgstr[1] "Все <span class=\"count\">(%s)</span>"
539
+ msgstr[2] "Все <span class=\"count\">(%s)</span>"
540
+
541
+ #: includes/class-list-table.php:306
542
+ #, php-format
543
+ msgid "Active <span class=\"count\">(%s)</span>"
544
+ msgid_plural "Active <span class=\"count\">(%s)</span>"
545
+ msgstr[0] "Активные <span class=\"count\">(%s)</span>"
546
+ msgstr[1] "Активные <span class=\"count\">(%s)</span>"
547
+ msgstr[2] "Активные <span class=\"count\">(%s)</span>"
548
+
549
+ #: includes/class-list-table.php:309
550
+ #, php-format
551
+ msgid "Recently Active <span class=\"count\">(%s)</span>"
552
+ msgid_plural "Recently Active <span class=\"count\">(%s)</span>"
553
+ msgstr[0] "Недавно активные <span class=\"count\">(%s)</span>"
554
+ msgstr[1] "Недавно активные <span class=\"count\">(%s)</span>"
555
+ msgstr[2] "Недавно активные <span class=\"count\">(%s)</span>"
556
+
557
+ #: includes/class-list-table.php:312
558
+ #, php-format
559
+ msgid "Inactive <span class=\"count\">(%s)</span>"
560
+ msgid_plural "Inactive <span class=\"count\">(%s)</span>"
561
+ msgstr[0] "Неактивные <span class=\"count\">(%s)</span>"
562
+ msgstr[1] "Неактивные <span class=\"count\">(%s)</span>"
563
+ msgstr[2] "Неактивные <span class=\"count\">(%s)</span>"
564
+
565
+ #: includes/class-list-table.php:341
566
+ msgid "Filter"
567
+ msgstr "Фильтр"
568
+
569
+ #: includes/class-list-table.php:349
570
+ msgid "Clear List"
571
+ msgstr "Очистить лист"
572
+
573
+ #: includes/class-list-table.php:491
574
+ #, php-format
575
+ msgid ""
576
+ "You do not appear to have any snippets available at this time. <a href=\"%s"
577
+ "\">Add New&rarr;</a>"
578
+ msgstr "Нет доступных сниппетов. <a href=\"%s\">Добавить новый&rarr;</a>"
579
+
580
+ #: includes/class-list-table.php:675
581
+ msgid "Search results"
582
+ msgstr "Результаты поиска"
583
+
584
+ #: includes/class-list-table.php:678
585
+ #, php-format
586
+ msgid " for &#8220;%s&#8221;"
587
+ msgstr " по запросу &#8220;%s&#8221;"
588
+
589
+ #: includes/class-list-table.php:684
590
+ msgid "Clear Filters"
591
+ msgstr "Очистить фильтры"
592
+
593
+ #~ msgid ""
594
+ #~ "You are about to permanently delete the selected item.\n"
595
+ #~ "\t\t\t\t'Cancel' to stop, 'OK' to delete."
596
+ #~ msgstr ""
597
+ #~ "Вы действительно хотите удалить выбранный сниппет?\n"
598
+ #~ "\t\t\t\t"
599
+
600
+ #~ msgid ""
601
+ #~ "You are about to permanently delete this snippet.\n"
602
+ #~ "'Cancel' to stop, 'OK' to delete."
603
+ #~ msgstr "Вы действительно хотите удалить выбранный сниппет?\n"
604
+
605
+ #, fuzzy
606
+ #~ msgid "Все <span class=\"count\">(%s)</span>"
607
+ #~ msgid_plural "Все <span class=\"count\">(%s)</span>"
608
+ #~ msgstr[0] "All <span class=\"count\">(%s)</span>"
609
+ #~ msgstr[1] "All <span class=\"count\">(%s)</span>"
610
+ #~ msgstr[2] "All <span class=\"count\">(%s)</span>"
languages/code-snippets-sk_SK.mo ADDED
Binary file
languages/code-snippets-sk_SK.po ADDED
@@ -0,0 +1,596 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Code Snippets SK\n"
4
+ "POT-Creation-Date: 2014-12-09 06:55+0100\n"
5
+ "PO-Revision-Date: 2014-12-09 07:10+0100\n"
6
+ "Last-Translator: Jan Fajcak <ja@fajo.name>\n"
7
+ "Language-Team: WordPress Slovensko <info@wp.sk>\n"
8
+ "Language: sk\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Generator: Poedit 1.7.1\n"
13
+ "X-Poedit-KeywordsList: __;_e;esc_html_e;gettext;gettext_noop\n"
14
+ "X-Poedit-Basepath: .\n"
15
+ "Plural-Forms: nplurals=3; plural=(n==1) ? 0 : (n>=2 && n<=4) ? 1 : 2;\n"
16
+ "X-Poedit-SourceCharset: UTF-8\n"
17
+ "X-Poedit-SearchPath-0: .\n"
18
+ "X-Poedit-SearchPath-1: ..\n"
19
+
20
+ #: ../admin/help/import.php:16 ../admin/help/manage.php:16
21
+ #: ../admin/help/single.php:15
22
+ msgid "Overview"
23
+ msgstr "Prehľad"
24
+
25
+ #: ../admin/help/import.php:18
26
+ msgid ""
27
+ "Snippets are similar to plugins - they both extend and expand the "
28
+ "functionality of WordPress. Snippets are more light-weight, just a few lines "
29
+ "of code, and do not put as much load on your server. Here you can load "
30
+ "snippets from a Code Snippets (.xml) import file into the database with your "
31
+ "existing snippets."
32
+ msgstr ""
33
+ "Snippety sa podobajú modulom- oba rozširujú a prehlbujú funkčnosť WordPress. "
34
+ "Snippety sú jednoduché kusy kódu veľké len pár riadkov, ktoré svojim objemom "
35
+ "nezaťažujú server. Tu môžete nahrať snippety z Code Snippets (.xml) súboru "
36
+ "do databáze k už existujúcim snippetom."
37
+
38
+ #: ../admin/help/import.php:23
39
+ msgid "Importing"
40
+ msgstr "Import"
41
+
42
+ #: ../admin/help/import.php:25
43
+ msgid ""
44
+ "You can load your snippets from a code snippets (.xml) export file using "
45
+ "this page."
46
+ msgstr ""
47
+ "Môžete nahrať vaše snippety zo súboru Code Snippets (.xml) prostredníctvom "
48
+ "tejto stránky."
49
+
50
+ #: ../admin/help/import.php:26
51
+ #, php-format
52
+ msgid ""
53
+ "Snippets will be added to the database along with your existing snippets. "
54
+ "Regardless of whether the snippets were active on the previous site, "
55
+ "imported snippets are always inactive until activated using the <a href=\"%s"
56
+ "\">Manage Snippets</a> page.</p>"
57
+ msgstr ""
58
+ "Snippety budú pridané do databáze k už existujúcim snippetom. Bez ohľadu na "
59
+ "to, že na predchádzajúcom webe boli aktívne, po importe je potrebné ich opäť "
60
+ "aktivovať na stránke <a href=\"%s\">Spravovať snippety</a>.</p>"
61
+
62
+ #: ../admin/help/import.php:31
63
+ msgid "Exporting"
64
+ msgstr "Export"
65
+
66
+ #: ../admin/help/import.php:33
67
+ #, php-format
68
+ msgid ""
69
+ "You can save your snippets to a Code Snippets (.xml) export file using the "
70
+ "<a href=\"%s\">Manage Snippets</a> page."
71
+ msgstr ""
72
+ "Vaše snippety môžete uložiť pomocou súboru Code Snippets (.xml) na stránke "
73
+ "<a href=\"%s\">Spravovať snippety</a>."
74
+
75
+ #: ../admin/help/import.php:37 ../admin/help/manage.php:38
76
+ #: ../admin/help/single.php:43
77
+ msgid "For more information:"
78
+ msgstr "Viac informácií:"
79
+
80
+ #: ../admin/help/import.php:38 ../admin/help/single.php:44
81
+ msgid ""
82
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
83
+ "\">WordPress Extend</a>"
84
+ msgstr ""
85
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
86
+ "\">WordPress Extend</a>"
87
+
88
+ #: ../admin/help/import.php:39 ../admin/help/manage.php:40
89
+ #: ../admin/help/single.php:45
90
+ msgid ""
91
+ "<a href=\"http://wordpress.org/support/plugin/code-snippets\" target=\"_blank"
92
+ "\">Support Forums</a>"
93
+ msgstr ""
94
+ "<a href=\"http://wordpress.org/support/plugin/code-snippets\" target=\"_blank"
95
+ "\">Fórum podpory</a>"
96
+
97
+ #: ../admin/help/import.php:40 ../admin/help/manage.php:41
98
+ #: ../admin/help/single.php:46
99
+ msgid ""
100
+ "<a href=\"http://code-snippets.bungeshea.com/\" target=\"_blank\">Project "
101
+ "Website</a>"
102
+ msgstr ""
103
+ "<a href=\"http://code-snippets.bungeshea.com/\" target=\"_blank\">Webová "
104
+ "stránka projektu</a>"
105
+
106
+ #: ../admin/help/manage.php:18
107
+ msgid ""
108
+ "Snippets are similar to plugins - they both extend and expand the "
109
+ "functionality of WordPress. Snippets are more light-weight, just a few lines "
110
+ "of code, and do not put as much load on your server. Here you can manage "
111
+ "your existing snippets and preform tasks on them such as activating, "
112
+ "deactivating, deleting and exporting."
113
+ msgstr ""
114
+ "Snippety sa podobajú modulom- oba rozširujú a prehlbujú funkčnosť WordPress. "
115
+ "Snippety sú jednoduché kusy kódu veľké len pár riadkov, ktoré svojim objemom "
116
+ "nezaťažujú server. Tu môžete spravovať svoje snippety: aktivovať ich a "
117
+ "deaktivovať, mazať alebo exportovať."
118
+
119
+ #: ../admin/help/manage.php:23
120
+ msgid "Safe Mode"
121
+ msgstr "Safe Mode"
122
+
123
+ #: ../admin/help/manage.php:25
124
+ msgid ""
125
+ "Be sure to check your snippets for errors before you activate them, as a "
126
+ "faulty snippet could bring your whole blog down. If your site starts doing "
127
+ "strange things, deactivate all your snippets and activate them one at a time."
128
+ msgstr ""
129
+ "Pred aktivovaním vašich snippetov sa uistite, že neobsahujú žiadne chyby, "
130
+ "inak riskujete pád vašich stránok. Ak sa začne diať niečo neočakávané, "
131
+ "deaktivujte všetky snippety a aktivujte ich ešte raz."
132
+
133
+ #: ../admin/help/manage.php:26
134
+ msgid ""
135
+ "If something goes wrong with a snippet and you can't use WordPress, you can "
136
+ "cause all snippets to stop executing by adding "
137
+ "<code>define('CODE_SNIPPETS_SAFE_MODE', true);</code> to your <code>wp-"
138
+ "config.php</code> file. After you have deactivated the offending snippet, "
139
+ "you can turn off safe mode by removing this line or replacing <strong>true</"
140
+ "strong> with <strong>false</strong>."
141
+ msgstr ""
142
+ "Ak došlo k problému a nie je možné použiť WordPress, môžete zastaviť všetky "
143
+ "snippety vložením <code>define('CODE_SNIPPETS_SAFE_MODE', true);</code> do "
144
+ "súboru <code>wp-config.php</code>. Potom, ako deaktivujete problémový "
145
+ "snippet, môžete tento kus kódu opäť odobrať alebo prepísať hodnotu "
146
+ "<strong>true</strong> na <strong>false</strong>."
147
+
148
+ #: ../admin/help/manage.php:31
149
+ msgid "Uninstall"
150
+ msgstr "Odinštalovať"
151
+
152
+ #: ../admin/help/manage.php:33
153
+ #, php-format
154
+ msgid ""
155
+ "When you delete Code Snippets through the Plugins menu in WordPress it will "
156
+ "clear up the <code>%1$s</code> table and a few other bits of data stored in "
157
+ "the database. If you want to keep this data (ie: you are only temporally "
158
+ "uninstalling Code Snippets) then remove the <code>%2$s</code> folder using "
159
+ "FTP."
160
+ msgstr ""
161
+ "Keď zmažete modul Code Snippets štandardnou cestou cez položku Moduly v "
162
+ "administrácii WordPress, bude zmazaná aj tabuľka <code>%1$s</code> a ďalšie "
163
+ "dáta, uložené v databáze. Ak chcete tieto dáta uchovať (napr. odinštalujete "
164
+ "Code Snippets len dočasne), potom odstráňte zložku <code>%2$s</code> cez FTP "
165
+ "ručne."
166
+
167
+ #: ../admin/help/manage.php:34
168
+ msgid ""
169
+ "Even if you're sure that you don't want to use Code Snippets ever again on "
170
+ "this WordPress installation, you may want to use the export feature to back "
171
+ "up your snippets."
172
+ msgstr ""
173
+ "Ak máte istotu, že už v tejto inštalácii nechcete používať Code Snippets, "
174
+ "môžete vaše snippety pomocou funkcie Export zálohovať."
175
+
176
+ #: ../admin/help/manage.php:39
177
+ msgid ""
178
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
179
+ "\">WordPress Extend</a></p>"
180
+ msgstr ""
181
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
182
+ "\">WordPress Extend</a></p>"
183
+
184
+ #: ../admin/help/single.php:17
185
+ msgid ""
186
+ "Snippets are similar to plugins - they both extend and expand the "
187
+ "functionality of WordPress. Snippets are more light-weight, just a few lines "
188
+ "of code, and do not put as much load on your server. Here you can add a new "
189
+ "snippet, or edit an existing one."
190
+ msgstr ""
191
+ "Snippety sa podobajú modulom- oba rozširujú a prehlbujú funkčnosť WordPress. "
192
+ "Snippety sú jednoduché kusy kódu veľké len pár riadkov, ktoré svojim objemom "
193
+ "nezaťažujú server. Tu môžete pridávať nové snippety, alebo upravovať už "
194
+ "existujúce."
195
+
196
+ #: ../admin/help/single.php:22
197
+ msgid "Finding Snippets"
198
+ msgstr "Nájsť snippety"
199
+
200
+ #: ../admin/help/single.php:24
201
+ msgid ""
202
+ "Here are some links to websites which host a large number of snippets that "
203
+ "you can add to your site.\n"
204
+ "\t\t<ul>\n"
205
+ "\t\t\t<li><a href=\"http://wp-snippets.com\" title=\"WordPress Snippets\">WP-"
206
+ "Snippets</a></li>\n"
207
+ "\t\t\t<li><a href=\"http://wpsnipp.com\" title=\"WP Snipp\">WP Snipp</a></"
208
+ "li>\n"
209
+ "\t\t\t<li><a href=\"http://www.catswhocode.com/blog/snippets\" title=\"Cats "
210
+ "Who Code Snippet Library\">Cats Who Code</a></li>\n"
211
+ "\t\t\t<li><a href=\"http://www.wpfunction.me\">WP Function Me</a></li>\n"
212
+ "\t\t</ul>"
213
+ msgstr ""
214
+ "Tu je niekoľko odkazov na weby, kde môžete nájsť množstvo snippetov, "
215
+ "použiteľných aj na vašich stránkach.\n"
216
+ "\t\t<ul>\n"
217
+ "\t\t\t<li><a href=\"http://wp-snippets.com\" title=\"WordPress Snippets\">WP-"
218
+ "Snippets</a></li>\n"
219
+ "\t\t\t<li><a href=\"http://wpsnipp.com\" title=\"WP Snipp\">WP Snipp</a></"
220
+ "li>\n"
221
+ "\t\t\t<li><a href=\"http://www.catswhocode.com/blog/snippets\" title=\"Cats "
222
+ "Who Code Snippet Library\">Cats Who Code</a></li>\n"
223
+ "\t\t\t<li><a href=\"http://www.wpfunction.me\">WP Function Me</a></li>\n"
224
+ "\t\t</ul>"
225
+
226
+ #: ../admin/help/single.php:31
227
+ msgid ""
228
+ "More places to find snippets, as well as a selection of example snippets, "
229
+ "can be found in the <a href=\"http://code-snippets.bungeshea.com/docs/"
230
+ "finding-snippets/\">plugin documentation</a>"
231
+ msgstr ""
232
+ "Viac miest, kde nájdete snippety a niekoľko ukážok snippetov nájdete v <a "
233
+ "href=\"http://code-snippets.bungeshea.com/docs/finding-snippets/"
234
+ "\">dokumentácii modulu</a>"
235
+
236
+ #: ../admin/help/single.php:36
237
+ msgid "Adding Snippets"
238
+ msgstr "Ako pridať snippet?"
239
+
240
+ #: ../admin/help/single.php:38
241
+ msgid ""
242
+ "You need to fill out the name and code fields for your snippet to be added. "
243
+ "While the description field will add more information about how your snippet "
244
+ "works, what is does and where you found it, it is completely optional."
245
+ msgstr "Je potrebné vyplniť názov snippetu a vložiť jeho kód."
246
+
247
+ #: ../admin/help/single.php:39
248
+ msgid ""
249
+ "Please be sure to check that your snippet is valid PHP code and will not "
250
+ "produce errors before adding it through this page. While doing so will not "
251
+ "become active straight away, it will help to minimise the chance of a faulty "
252
+ "snippet becoming active on your site."
253
+ msgstr ""
254
+ "Prosím skontrolujte, či vaše snippety obsahujú overený PHP kód a nespôsobia "
255
+ "na tejto stránke chyby. Keďže nebudú hneď aktívne, nemusíte sa obávať "
256
+ "možného pádu stránky po ich nahratí."
257
+
258
+ #: ../admin/messages/import.php:32
259
+ msgid "An error occurred when processing the import file."
260
+ msgstr "Pri importe došlo ku chybe."
261
+
262
+ #: ../admin/messages/manage.php:14
263
+ msgid ""
264
+ "<strong>Warning:</strong> Safe mode is active and snippets will not execute! "
265
+ "Remove the <code>CODE_SNIPPETS_SAFE_MODE</code> constant from <code>wp-"
266
+ "config.php</code> to turn off safe mode. <a href=\"http://code-snippets."
267
+ "bungeshea.com/docs/safe-mode/\" target=\"_blank\">Help</a>"
268
+ msgstr ""
269
+ "<strong>Upozornenie:</strong> Safe mode je aktívny a snippety nebudú "
270
+ "fungovať! Odstráňte konštantu <code>CODE_SNIPPETS_SAFE_MODE</code> z "
271
+ "<code>wp-config.php</code> pre vypnutie safe mode. <a href=\"http://code-"
272
+ "snippets.bungeshea.com/docs/safe-mode/\" target=\"_blank\">Pomoc</a>"
273
+
274
+ #: ../admin/messages/manage.php:20
275
+ msgid "Snippet <strong>activated</strong>."
276
+ msgstr "Snippet <strong>aktivovaný</strong>."
277
+
278
+ #: ../admin/messages/manage.php:24
279
+ msgid "Selected snippets <strong>activated</strong>."
280
+ msgstr "Vybrané snippety <strong>aktivované</strong>."
281
+
282
+ #: ../admin/messages/manage.php:28
283
+ msgid "Snippet <strong>deactivated</strong>."
284
+ msgstr "Snippet <strong>deaktivovaný</strong>."
285
+
286
+ #: ../admin/messages/manage.php:32
287
+ msgid "Selected snippets <strong>deactivated</strong>."
288
+ msgstr "Vybrané snippety <strong>deaktivované</strong>."
289
+
290
+ #: ../admin/messages/manage.php:36
291
+ msgid "Snippet <strong>deleted</strong>."
292
+ msgstr "Snippet <strong>zmazaný</strong>."
293
+
294
+ #: ../admin/messages/manage.php:40
295
+ msgid "Selected snippets <strong>deleted</strong>."
296
+ msgstr "Vybrané snippety <strong>zmazané</strong>."
297
+
298
+ #: ../admin/messages/single.php:14
299
+ msgid "An error occurred when saving the snippet."
300
+ msgstr "Pri ukladaní snippetu došlo ku chybe."
301
+
302
+ #: ../admin/messages/single.php:18
303
+ msgid "Snippet <strong>updated</strong> and <strong>activated</strong>."
304
+ msgstr "Snippet <strong>aktualizovaný</strong> a <strong>aktivovaný</strong>."
305
+
306
+ #: ../admin/messages/single.php:22
307
+ msgid "Snippet <strong>added</strong> and <strong>activated</strong>."
308
+ msgstr "Snippet <strong>pridaný</strong> a <strong>aktivovaný</strong>."
309
+
310
+ #: ../admin/messages/single.php:26
311
+ msgid "Snippet <strong>updated</strong> and <strong>deactivated</strong>."
312
+ msgstr ""
313
+ "Snippet <strong>aktualizovaný</strong> a <strong>deaktivovaný</strong>."
314
+
315
+ #: ../admin/messages/single.php:30
316
+ msgid "Snippet <strong>updated</strong>."
317
+ msgstr "Snippet <strong>aktualizovaný</strong>."
318
+
319
+ #: ../admin/messages/single.php:34
320
+ msgid "Snippet <strong>added</strong>."
321
+ msgstr "Snippet <strong>pridaný</strong>."
322
+
323
+ #: ../admin/views/import.php:20 ../includes/class-admin.php:327
324
+ msgid "Import Snippets"
325
+ msgstr "Importovať snippety"
326
+
327
+ #: ../admin/views/import.php:24
328
+ msgid ""
329
+ "Howdy! Upload your Code Snippets export file and we&#8217;ll import the "
330
+ "snippets to this site."
331
+ msgstr ""
332
+ "Nahrajte súbor Code Snippets (.xml) a naimportujte snippety na túto stránku."
333
+
334
+ #: ../admin/views/import.php:26
335
+ #, php-format
336
+ msgid ""
337
+ "You will need to go to the <a href=\"%s\">Manage Snippets</a> page to "
338
+ "activate the imported snippets."
339
+ msgstr ""
340
+ "Po ukončení importu musíte ísť na stránku <a href=\"%s\">Spravovať snippety</"
341
+ "a> a aktivovať importované snippety."
342
+
343
+ #: ../admin/views/import.php:28
344
+ msgid ""
345
+ "Choose a Code Snippets (.xml) file to upload, then click Upload file and "
346
+ "import."
347
+ msgstr ""
348
+ "Zvoľte súbor Code Snippets (.xml) a kliknite na tlačidlo Nahrať súbor a "
349
+ "importovať."
350
+
351
+ #: ../admin/views/import.php:35
352
+ msgid "Choose a file from your computer:"
353
+ msgstr "Zvoľte súbor vo vašom počítači:"
354
+
355
+ #: ../admin/views/import.php:36
356
+ msgid "(Maximum size: 8MB)"
357
+ msgstr "(Maximálna veľkosť: 8MB)"
358
+
359
+ #: ../admin/views/import.php:42
360
+ msgid "Upload file and import"
361
+ msgstr "Nahrať súbor a importovať"
362
+
363
+ #: ../admin/views/manage.php:21 ../includes/class-admin.php:152
364
+ #: ../includes/class-admin.php:276 ../includes/class-admin.php:277
365
+ #: ../includes/class-admin.php:287
366
+ msgid "Snippets"
367
+ msgstr "Snippety"
368
+
369
+ #: ../admin/views/manage.php:39
370
+ msgid "Search Installed Snippets"
371
+ msgstr "Hľadať nainštalované snippety"
372
+
373
+ #: ../admin/views/single.php:29 ../includes/class-admin.php:299
374
+ msgid "Edit Snippet"
375
+ msgstr "Upraviť snippety"
376
+
377
+ #: ../admin/views/single.php:37 ../includes/class-admin.php:299
378
+ msgid "Add New Snippet"
379
+ msgstr "Pridať nový snippet"
380
+
381
+ #: ../admin/views/single.php:53 ../admin/views/single.php:54
382
+ msgid "Name (short title)"
383
+ msgstr "Názov (krátky nadpis)"
384
+
385
+ #: ../admin/views/single.php:59
386
+ msgid "Code"
387
+ msgstr "Kód"
388
+
389
+ #: ../admin/views/single.php:85
390
+ msgid "Save Changes &amp; Activate"
391
+ msgstr "Uložiť zmeny a aktivovať"
392
+
393
+ #: ../admin/views/single.php:91
394
+ msgid "Save Changes &amp; Deactivate"
395
+ msgstr "Uložiť zmeny a deaktivovať"
396
+
397
+ #: ../admin/views/single.php:100 ../includes/class-list-table.php:166
398
+ #: ../includes/class-list-table.php:266
399
+ msgid "Export"
400
+ msgstr "Export"
401
+
402
+ #: ../admin/views/single.php:107
403
+ msgid ""
404
+ "You are about to permanently delete this snippet.\n"
405
+ "'Cancel' to stop, 'OK' to delete."
406
+ msgstr ""
407
+ "Chcete navždy zmazať tento snippet. \n"
408
+ "'Cancel' pre zrušenie, 'OK' pre zmazanie."
409
+
410
+ #: ../admin/views/single.php:112 ../includes/class-list-table.php:175
411
+ #: ../includes/class-list-table.php:267
412
+ msgid "Delete"
413
+ msgstr "Zmazať"
414
+
415
+ #: ../includes/class-admin.php:185
416
+ msgid "Code Snippets"
417
+ msgstr "Code Snippets"
418
+
419
+ #: ../includes/class-admin.php:186
420
+ msgid "Import snippets from a Code Snippets export file"
421
+ msgstr "Importovať snippety zo súboru Code Snippets"
422
+
423
+ #: ../includes/class-admin.php:246
424
+ msgid "You are not authorized to access this page."
425
+ msgstr "Nemáte prístup na túto stránku."
426
+
427
+ #: ../includes/class-admin.php:288 ../includes/class-admin.php:695
428
+ msgid "Manage"
429
+ msgstr "Spravovať"
430
+
431
+ #: ../includes/class-admin.php:300 ../includes/class-list-table.php:160
432
+ msgid "Edit"
433
+ msgstr "Upraviť"
434
+
435
+ #: ../includes/class-admin.php:300
436
+ msgid "Add New"
437
+ msgstr "Pridať nový"
438
+
439
+ #: ../includes/class-admin.php:328
440
+ msgid "Import"
441
+ msgstr "Import"
442
+
443
+ #: ../includes/class-admin.php:663 ../includes/class-list-table.php:228
444
+ msgid "Description"
445
+ msgstr "Popis"
446
+
447
+ #: ../includes/class-admin.php:694
448
+ msgid "Manage your existing snippets"
449
+ msgstr "Spravovať existujúce snippety"
450
+
451
+ #: ../includes/class-admin.php:722
452
+ msgid "Visit the WordPress.org plugin page"
453
+ msgstr "Navštíviť stránku modulu na WordPress.org"
454
+
455
+ #: ../includes/class-admin.php:723
456
+ msgid "About"
457
+ msgstr "O module"
458
+
459
+ #: ../includes/class-admin.php:727
460
+ msgid "Visit the support forums"
461
+ msgstr "Navštíviť fórum podpory"
462
+
463
+ #: ../includes/class-admin.php:728
464
+ msgid "Support"
465
+ msgstr "Podpora"
466
+
467
+ #: ../includes/class-admin.php:732
468
+ msgid "Support this plugin's development"
469
+ msgstr "Podporiť vývoj tohoto modulu"
470
+
471
+ #: ../includes/class-admin.php:733
472
+ msgid "Donate"
473
+ msgstr "Podporiť"
474
+
475
+ #: ../includes/class-admin.php:764
476
+ msgid ""
477
+ "<strong>Have feedback on Code Snippets?</strong> Please take the time to "
478
+ "answer a short survey on how you use this plugin and what you'd like to see "
479
+ "changed or added in the future."
480
+ msgstr ""
481
+ "<strong>Máte spätnú väzbu na Code Snippets?</strong>Prosím, nájdite si čas a "
482
+ "zúčastnite sa prieskumu o tom, ako používate tento modul a čo by ste na ňom "
483
+ "v budúcnosti zmenili, alebo čím ho doplnili."
484
+
485
+ #: ../includes/class-admin.php:767
486
+ msgid "Take the survey now"
487
+ msgstr "Zúčastnite sa prieskumu"
488
+
489
+ #: ../includes/class-list-table.php:49
490
+ msgid "Snippets per page"
491
+ msgstr "Počet snippetov na stránke"
492
+
493
+ #: ../includes/class-list-table.php:141 ../includes/class-list-table.php:265
494
+ msgid "Network Deactivate"
495
+ msgstr "Sieť deaktivovaná"
496
+
497
+ #: ../includes/class-list-table.php:141 ../includes/class-list-table.php:265
498
+ msgid "Deactivate"
499
+ msgstr "Deaktivovať"
500
+
501
+ #: ../includes/class-list-table.php:150 ../includes/class-list-table.php:264
502
+ msgid "Network Activate"
503
+ msgstr "Sieť aktivovaná"
504
+
505
+ #: ../includes/class-list-table.php:150 ../includes/class-list-table.php:264
506
+ msgid "Activate"
507
+ msgstr "Aktivovať"
508
+
509
+ #: ../includes/class-list-table.php:182
510
+ msgid ""
511
+ "You are about to permanently delete the selected item.\n"
512
+ "\t\t\t\t'Cancel' to stop, 'OK' to delete."
513
+ msgstr ""
514
+ "Chcete navždy zmazať túto položku. \n"
515
+ "\t\t\t\t'Cancel' pre zrušenie, 'OK' úre zmazanie."
516
+
517
+ #: ../includes/class-list-table.php:190
518
+ #, php-format
519
+ msgid "Untitled #%d"
520
+ msgstr "Bez názvu #%d"
521
+
522
+ #: ../includes/class-list-table.php:226
523
+ msgid "Name"
524
+ msgstr "Názov"
525
+
526
+ #: ../includes/class-list-table.php:227
527
+ msgid "ID"
528
+ msgstr "ID"
529
+
530
+ #: ../includes/class-list-table.php:268
531
+ msgid "Export to PHP"
532
+ msgstr "Export do PHP"
533
+
534
+ #: ../includes/class-list-table.php:342
535
+ msgid "Filter"
536
+ msgstr "Filter"
537
+
538
+ #: ../includes/class-list-table.php:350
539
+ msgid "Clear List"
540
+ msgstr "Vyčistiť zoznam"
541
+
542
+ #: ../includes/class-list-table.php:492
543
+ #, php-format
544
+ msgid ""
545
+ "You do not appear to have any snippets available at this time. <a href=\"%s"
546
+ "\">Add New&rarr;</a>"
547
+ msgstr ""
548
+ "Momentálne nemáte k dispozícii žiadne snippety. <a href=\"%s\">Pridať nový "
549
+ "&rarr;</a>"
550
+
551
+ #: ../includes/class-list-table.php:676
552
+ msgid "Search results"
553
+ msgstr "Výsledky hľadania"
554
+
555
+ #: ../includes/class-list-table.php:679
556
+ #, php-format
557
+ msgid " for &#8220;%s&#8221;"
558
+ msgstr "pre &#8220;%s&#8221;"
559
+
560
+ #: ../includes/class-list-table.php:685
561
+ msgid "Clear Filters"
562
+ msgstr "Vyčistiť filtre"
563
+
564
+ #~ msgid "Manage Snippets"
565
+ #~ msgstr "Spravovať snippety"
566
+
567
+ #~ msgid "Sorry, you&#8217;re not allowed to edit snippets"
568
+ #~ msgstr "Prepáčte, ale nemáte oprávnenie na úpravu snippetov"
569
+
570
+ #~ msgid "Please provide a name for the snippet and its code."
571
+ #~ msgstr "Prosím, uveďte názov snippetu a vložte jeho kód."
572
+
573
+ #~ msgid ""
574
+ #~ "Enter or paste the snippet code without the <code>&lt;?php</code> and "
575
+ #~ "<code>?&gt;</code> tags."
576
+ #~ msgstr ""
577
+ #~ "Napíšte alebo skopírujte kód snippetu bez značiek <code>&lt;?php</code> a "
578
+ #~ "<code>?&gt;</code>."
579
+
580
+ #~ msgid "(Optional)"
581
+ #~ msgstr "(voliteľné)"
582
+
583
+ #~ msgid "Save"
584
+ #~ msgstr "Uložiť"
585
+
586
+ #~ msgid "Cancel"
587
+ #~ msgstr "Zrušiť"
588
+
589
+ #~ msgid ""
590
+ #~ "Make sure that you don't add the <code>&lt;?php</code>, <code>&lt;?</"
591
+ #~ "code> or <code>?&gt;</code> the beginning and end of the code. You can "
592
+ #~ "however use these tags in the code to stop and start PHP sections"
593
+ #~ msgstr ""
594
+ #~ "Uistite sa, že ste nevložili <code>&lt;?php</code>, <code>&lt;?</code> "
595
+ #~ "alebo <code>?&gt;</code> v priebehu alebo na konci kódu. Tieto značky "
596
+ #~ "však môžete použiť pre zastavenie alebo spustenie úsekov PHP."
languages/code-snippets-sr_RS.mo ADDED
Binary file
languages/code-snippets-sr_RS.po ADDED
@@ -0,0 +1,571 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is distributed under the same license as the Code Snippets package.
2
+ msgid ""
3
+ msgstr ""
4
+ "PO-Revision-Date: 2014-08-11 10:18+0100\n"
5
+ "MIME-Version: 1.0\n"
6
+ "Content-Type: text/plain; charset=UTF-8\n"
7
+ "Content-Transfer-Encoding: 8bit\n"
8
+ "Plural-Forms: nplurals=2; plural=n != 1;\n"
9
+ "X-Generator: Poedit 1.5.5\n"
10
+ "Project-Id-Version: Code Snippets\n"
11
+ "POT-Creation-Date: \n"
12
+ "Last-Translator: jelena kovacevic <jecajeca260@gmail.com>\n"
13
+ "Language-Team: \n"
14
+
15
+ #: code-snippets.php:0 code-snippets.php:262
16
+ msgid "Code Snippets"
17
+ msgstr "Code Snippets"
18
+
19
+ #: code-snippets.php:0
20
+ msgid ""
21
+ "An easy, clean and simple way to add code snippets to your site. No need to "
22
+ "edit to your theme's functions.php file again!"
23
+ msgstr ""
24
+ "Lak, jednostavan i jasan način da svom sajtu dodate dodate isečke koda! Nema "
25
+ "potrebe da ponovo uređujete .php datoteku sa funkcijama teme! "
26
+
27
+ #: code-snippets.php:0
28
+ msgid "Shea Bunge"
29
+ msgstr "Shea Bunge"
30
+
31
+ #: code-snippets.php:0
32
+ msgid "http://bungeshea.com"
33
+ msgstr "http://bungeshea.com"
34
+
35
+ #: code-snippets.php:577 code-snippets.php:578 code-snippets.php:588
36
+ #: includes/admin/manage.php:36
37
+ msgid "Snippets"
38
+ msgstr "Isečci"
39
+
40
+ #: code-snippets.php:612 code-snippets.php:1145 includes/admin/single.php:45
41
+ msgid "Add New Snippet"
42
+ msgstr "Dodaj novi isečak"
43
+
44
+ #: code-snippets.php:613
45
+ msgid "Add New"
46
+ msgstr "Dodaj novi"
47
+
48
+ #: code-snippets.php:641 includes/admin/import.php:34
49
+ msgid "Import Snippets"
50
+ msgstr "Uvezi isečke"
51
+
52
+ #: code-snippets.php:642
53
+ msgid "Import"
54
+ msgstr "Uvezi"
55
+
56
+ #: code-snippets.php:601 code-snippets.php:1146 includes/admin/single.php:37
57
+ msgid "Edit Snippet"
58
+ msgstr "Uredi isečak"
59
+
60
+ #: code-snippets.php:1465
61
+ msgid "Manage your existing snippets"
62
+ msgstr "Upravljaj svojim postojećim isečcima"
63
+
64
+ #: code-snippets.php:589 code-snippets.php:1466
65
+ msgid "Manage"
66
+ msgstr "Upravljaj"
67
+
68
+ #: code-snippets.php:1486
69
+ msgid "Visit the WordPress.org plugin page"
70
+ msgstr "Posetite stranicu WordPress.org plugin"
71
+
72
+ #: code-snippets.php:1487
73
+ msgid "About"
74
+ msgstr "O"
75
+
76
+ #: code-snippets.php:1491
77
+ msgid "Visit the support forums"
78
+ msgstr "Posetite forume za podršku"
79
+
80
+ #: code-snippets.php:1492
81
+ msgid "Support"
82
+ msgstr "Podrška"
83
+
84
+ #: code-snippets.php:1496
85
+ msgid "Support this plugin's development"
86
+ msgstr "Podržite razvoj ovog plugin-a"
87
+
88
+ #: code-snippets.php:1497
89
+ msgid "Donate"
90
+ msgstr "Donirajte"
91
+
92
+ #: includes/admin/import.php:38
93
+ msgid ""
94
+ "Howdy! Upload your Code Snippets export file and we&#8217;ll import the "
95
+ "snippets to this site."
96
+ msgstr ""
97
+ "Ćao! Otpremite svoju izvoznu datoteku sa isečcima koda, a mi&#8217 ćemo "
98
+ "uvesti isečke na sajt."
99
+
100
+ #: includes/admin/import.php:40
101
+ msgid ""
102
+ "You will need to go to the <a href=\"%s\">Manage Snippets</a> page to "
103
+ "activate the imported snippets."
104
+ msgstr ""
105
+ "Da biste aktivirali uvezene isečke, idite na stranicu: <a href=\"%s\">Manage "
106
+ "Snippets</a>. "
107
+
108
+ #: includes/admin/import.php:42
109
+ msgid ""
110
+ "Choose a Code Snippets (.xml) file to upload, then click Upload file and "
111
+ "import."
112
+ msgstr ""
113
+ "Izaberite (.xml) datoteku sa isečcima koda za otpremanje, a zatim kliknite "
114
+ "na Otpremi datoteku i Uvezi."
115
+
116
+ #: includes/admin/import.php:46
117
+ msgid "Choose a file from your computer:"
118
+ msgstr "Izaberite datoteku sa svog kompjutera:"
119
+
120
+ #: includes/admin/import.php:46
121
+ msgid "(Maximum size: 8MB)"
122
+ msgstr "(Maksimalna veličina: 8MB)"
123
+
124
+ #: includes/admin/import.php:55
125
+ msgid "Upload file and import"
126
+ msgstr "Otpremi datoteku i uvezi"
127
+
128
+ #: includes/admin/manage.php:21
129
+ msgid "Snippet <strong>activated</strong>."
130
+ msgstr "Isečak <strong>aktiviran</strong>."
131
+
132
+ #: includes/admin/manage.php:23
133
+ msgid "Selected snippets <strong>activated</strong>."
134
+ msgstr "Odabrani isečci <strong>aktivirani</strong>."
135
+
136
+ #: includes/admin/manage.php:25
137
+ msgid "Snippet <strong>deactivated</strong>."
138
+ msgstr "Isečak <strong>deaktiviran</strong>."
139
+
140
+ #: includes/admin/manage.php:27
141
+ msgid "Selected snippets <strong>deactivated</strong>."
142
+ msgstr "Odabrani isečci <strong>deaktivirani</strong>."
143
+
144
+ #: includes/admin/manage.php:29
145
+ msgid "Snippet <strong>deleted</strong>."
146
+ msgstr "Isečak <strong>obrisan</strong>."
147
+
148
+ #: includes/admin/manage.php:31
149
+ msgid "Selected snippets <strong>deleted</strong>."
150
+ msgstr "Odabrani isečci <strong>obrisani</strong>."
151
+
152
+ #: includes/admin/manage.php:38 includes/admin/single.php:42
153
+ msgctxt "snippet"
154
+ msgid "Add New"
155
+ msgstr "Dodaj novi"
156
+
157
+ #: includes/admin/manage.php:47
158
+ msgid "Search Installed Snippets"
159
+ msgstr "Pretraži instalirane isečke"
160
+
161
+ #: includes/admin/single.php:22
162
+ msgid "Please provide a name for the snippet and its code."
163
+ msgstr "Unesite naziv isečka i njegov kod."
164
+
165
+ #: includes/admin/single.php:28
166
+ msgid "Snippet <strong>updated</strong>."
167
+ msgstr "Isečak <strong>ažuriran</strong>."
168
+
169
+ #: includes/admin/single.php:30
170
+ msgid "Snippet <strong>added</strong>."
171
+ msgstr "Isećak <strong>dodat</strong>."
172
+
173
+ #: includes/admin/single.php:55 includes/admin/single.php:56
174
+ msgid "Name (short title)"
175
+ msgstr "Naziv (kratak naslov)"
176
+
177
+ #: includes/admin/single.php:61
178
+ msgid "Code"
179
+ msgstr "Kod"
180
+
181
+ #: code-snippets.php:1433 includes/class-list-table.php:189
182
+ msgid "Description"
183
+ msgstr "Opsi"
184
+
185
+ #: code-snippets.php:1434
186
+ msgid "(Optional)"
187
+ msgstr "(Opcioni)"
188
+
189
+ #: includes/class-list-table.php:36
190
+ msgid "Snippets per page"
191
+ msgstr "Isečci po stranici"
192
+
193
+ #: code-snippets.php:1118 includes/class-list-table.php:127
194
+ #: includes/class-list-table.php:213
195
+ msgid "Network Deactivate"
196
+ msgstr "Deaktiviraj mrežu"
197
+
198
+ #: code-snippets.php:1118 includes/class-list-table.php:127
199
+ #: includes/class-list-table.php:213
200
+ msgid "Deactivate"
201
+ msgstr "Deaktiviraj"
202
+
203
+ #: code-snippets.php:1127 includes/class-list-table.php:137
204
+ #: includes/class-list-table.php:212
205
+ msgid "Network Activate"
206
+ msgstr "Aktiviraj mrežu"
207
+
208
+ #: code-snippets.php:1127 includes/class-list-table.php:137
209
+ #: includes/class-list-table.php:212
210
+ msgid "Activate"
211
+ msgstr "Aktiviraj"
212
+
213
+ #: includes/class-list-table.php:187
214
+ msgid "Name"
215
+ msgstr "Naziv"
216
+
217
+ #: includes/class-list-table.php:188
218
+ msgid "ID"
219
+ msgstr "ID"
220
+
221
+ #: includes/class-list-table.php:147 includes/class-list-table.php:214
222
+ msgid "Export"
223
+ msgstr "Izvezi"
224
+
225
+ #: includes/class-list-table.php:155 includes/class-list-table.php:215
226
+ msgid "Delete"
227
+ msgstr "Obriši"
228
+
229
+ #: includes/class-list-table.php:216
230
+ msgid "Export to PHP"
231
+ msgstr "Izvezi u PHP"
232
+
233
+ #: includes/class-list-table.php:236
234
+ msgid "All <span class=\"count\">(%s)</span>"
235
+ msgid_plural "All <span class=\"count\">(%s)</span>"
236
+ msgstr[0] ""
237
+ msgstr[1] ""
238
+
239
+ #: includes/class-list-table.php:239
240
+ msgid "Active <span class=\"count\">(%s)</span>"
241
+ msgid_plural "Active <span class=\"count\">(%s)</span>"
242
+ msgstr[0] ""
243
+ msgstr[1] ""
244
+
245
+ #: includes/class-list-table.php:242
246
+ msgid "Recently Active <span class=\"count\">(%s)</span>"
247
+ msgid_plural "Recently Active <span class=\"count\">(%s)</span>"
248
+ msgstr[0] ""
249
+ msgstr[1] ""
250
+
251
+ #: includes/class-list-table.php:245
252
+ msgid "Inactive <span class=\"count\">(%s)</span>"
253
+ msgid_plural "Inactive <span class=\"count\">(%s)</span>"
254
+ msgstr[0] ""
255
+ msgstr[1] ""
256
+
257
+ #: includes/class-list-table.php:279
258
+ msgid "Clear List"
259
+ msgstr "Obriši listu"
260
+
261
+ #: includes/class-list-table.php:374
262
+ msgid ""
263
+ "You do not appear to have any snippets available at this time. <a href=\"%s"
264
+ "\">Add New&rarr;</a>"
265
+ msgstr ""
266
+ "Čini se da trenutno nemate raspoložive isečke. <a href=\"%s\">Add New&rarr;"
267
+ "</a>"
268
+
269
+ #: includes/help/import.php:5 includes/help/manage.php:5
270
+ #: includes/help/single.php:5
271
+ msgid "Overview"
272
+ msgstr "Pregled"
273
+
274
+ #: includes/help/import.php:7
275
+ msgid ""
276
+ "Snippets are similar to plugins - they both extend and expand the "
277
+ "functionality of WordPress. Snippets are more light-weight, just a few lines "
278
+ "of code, and do not put as much load on your server. Here you can load "
279
+ "snippets from a Code Snippets (.xml) import file into the database with your "
280
+ "existing snippets."
281
+ msgstr ""
282
+ "Isečci liče na plugin-ove - i jedni i drugi proširuju funkcije WordPress-a. "
283
+ "Isečci su lakši - sadrže samo nekoliko linija koda i ne opterećuju server. "
284
+ "Ovde možete učitati isečke iz Code Snippets (.xml) datoteke za uvoz u bazu "
285
+ "podataka sa svojim postojećim isečcima."
286
+
287
+ #: includes/help/import.php:12
288
+ msgid "Importing"
289
+ msgstr "Uvoz u toku..."
290
+
291
+ #: includes/help/import.php:15
292
+ msgid ""
293
+ "Snippets will be added to the database along with your existing snippets. "
294
+ "Regardless of whether the snippets were active on the previous site, "
295
+ "imported snippets are always inactive until activated using the <a href=\"%s"
296
+ "\">Manage Snippets</a> page.</p>"
297
+ msgstr ""
298
+ "Isečci će biti dodati bazi podataka zajedno s vašim postojećim isečcima. Bez "
299
+ "obzira na to da li su isečci bili aktivni na prethodnom sajtu, uvezeni "
300
+ "isečci uvek su neaktivni sve dok se ne aktiviraju uz pomoć stranice: <a href="
301
+ "\"%s\">Manage Snippets</a>."
302
+
303
+ #: includes/help/import.php:20
304
+ msgid "Exporting"
305
+ msgstr "Izvoz u toku..."
306
+
307
+ #: includes/help/import.php:22
308
+ msgid ""
309
+ "You can save your snippets to a Code Snippets (.xml) export file using the "
310
+ "<a href=\"%s\">Manage Snippets</a> page."
311
+ msgstr ""
312
+ "Možete sačuvati svoje isečke u Code Snippets (.xml) datoteci sa isečcima uz "
313
+ "pomoć stranice <a href=\"%s\">Manage Snippets</a>."
314
+
315
+ #: includes/help/import.php:26 includes/help/manage.php:27
316
+ #: includes/help/single.php:31
317
+ msgid "For more information:"
318
+ msgstr "Za više informacija:"
319
+
320
+ #: includes/help/import.php:27 includes/help/single.php:32
321
+ msgid ""
322
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
323
+ "\">WordPress Extend</a>"
324
+ msgstr ""
325
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
326
+ "\">WordPress Extend</a>"
327
+
328
+ #: includes/help/import.php:28 includes/help/manage.php:29
329
+ #: includes/help/single.php:33
330
+ msgid ""
331
+ "<a href=\"http://wordpress.org/support/plugin/code-snippets\" target=\"_blank"
332
+ "\">Support Forums</a>"
333
+ msgstr ""
334
+ "<a href=\"http://wordpress.org/support/plugin/code-snippets\" target=\"_blank"
335
+ "\">Support Forums</a>"
336
+
337
+ #: includes/help/manage.php:7
338
+ msgid ""
339
+ "Snippets are similar to plugins - they both extend and expand the "
340
+ "functionality of WordPress. Snippets are more light-weight, just a few lines "
341
+ "of code, and do not put as much load on your server. Here you can manage "
342
+ "your existing snippets and preform tasks on them such as activating, "
343
+ "deactivating, deleting and exporting."
344
+ msgstr ""
345
+ "Isečci liče na plugin-ove - i jedni i drugi proširuju funkcije WordPress-a. "
346
+ "Isečci su lakši - sadrže samo nekoliko linija koda i ne opterećuju server. "
347
+ "Ovde možete upravljati svojim postojećim isečcima i izvoditi operacije na "
348
+ "njima, kao što su: aktiviranje, deaktiviranje, brisanje i izvoz."
349
+
350
+ #: includes/help/manage.php:12
351
+ msgid "Safe Mode"
352
+ msgstr "Bezbedan režim"
353
+
354
+ #: includes/help/manage.php:14
355
+ msgid ""
356
+ "Be sure to check your snippets for errors before you activate them, as a "
357
+ "faulty snippet could bring your whole blog down. If your site starts doing "
358
+ "strange things, deactivate all your snippets and activate them one at a time."
359
+ msgstr ""
360
+ "Proverite da li u vašim isečcima ima grešaka pre nego što ih aktivirate jer "
361
+ "isečak sa greškom može da vam sruši ceo blog. Ako vam se sajt čudno ponaša, "
362
+ "deaktivirajte sve isečke i aktivirajte jedan po jedan."
363
+
364
+ #: includes/help/manage.php:20
365
+ msgid "Uninstall"
366
+ msgstr "Deinstaliraj"
367
+
368
+ #: includes/help/manage.php:22
369
+ msgid ""
370
+ "When you delete Code Snippets through the Plugins menu in WordPress it will "
371
+ "clear up the <code>%1$s</code> table and a few other bits of data stored in "
372
+ "the database. If you want to keep this data (ie: you are only temporally "
373
+ "uninstalling Code Snippets) then remove the <code>%2$s</code> folder using "
374
+ "FTP."
375
+ msgstr ""
376
+ "Kad brišete isečke koda kroz Plugins meni u WordPress-u, obrisaće vam se "
377
+ "<code>%1$s</code> tabela i još nekoliko bitova podataka sačuvanih u bazi "
378
+ "podataka. Ako želite da zadržite ove podatke (tj. ako samo privremeno "
379
+ "deinstalirate Code Snippets), uklonite <code>%2$s</code> folder koristeći "
380
+ "FTP."
381
+
382
+ #: includes/help/manage.php:23
383
+ msgid ""
384
+ "Even if you're sure that you don't want to use Code Snippets ever again on "
385
+ "this WordPress installation, you may want to use the export feature to back "
386
+ "up your snippets."
387
+ msgstr ""
388
+ "Čak i ako ste sigurni kako nikad više nećete poželeti da koristite Code "
389
+ "Snippets na ovoj WordPress instalaciji, možda ćete hteti da koristite "
390
+ "funkciju izvoza da biste obezbedili podršku za svoje isečke. "
391
+
392
+ #: includes/help/manage.php:28
393
+ msgid ""
394
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
395
+ "\">WordPress Extend</a></p>"
396
+ msgstr ""
397
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
398
+ "\">WordPress Extend</a></p>"
399
+
400
+ #: includes/help/single.php:7
401
+ msgid ""
402
+ "Snippets are similar to plugins - they both extend and expand the "
403
+ "functionality of WordPress. Snippets are more light-weight, just a few lines "
404
+ "of code, and do not put as much load on your server. Here you can add a new "
405
+ "snippet, or edit an existing one."
406
+ msgstr ""
407
+ "Isečci liče na plugin-ove - i jedni i drugi proširuju funkcije WordPress-a. "
408
+ "Isečci su lakši - sadrže samo nekoliko linija koda i ne opterećuju server. "
409
+ "Ovde možete dodati novi isečak ili urediti postojeći."
410
+
411
+ #: includes/help/single.php:11
412
+ msgid "Finding Snippets"
413
+ msgstr "Pretraživanje isečaka"
414
+
415
+ #: includes/help/single.php:13
416
+ msgid ""
417
+ "Here are some links to websites which host a large number of snippets that "
418
+ "you can add to your site.\n"
419
+ "\t\t<ul>\n"
420
+ "\t\t\t<li><a href=\"http://wp-snippets.com\" title=\"WordPress Snippets\">WP-"
421
+ "Snippets</a></li>\n"
422
+ "\t\t\t<li><a href=\"http://wpsnipp.com\" title=\"WP Snipp\">WP Snipp</a></"
423
+ "li>\n"
424
+ "\t\t\t<li><a href=\"http://www.catswhocode.com/blog/snippets\" title=\"Cats "
425
+ "Who Code Snippet Library\">Cats Who Code</a></li>\n"
426
+ "\t\t\t<li><a href=\"http://www.wpfunction.me\">WP Function Me</a></li>\n"
427
+ "\t\t</ul>"
428
+ msgstr ""
429
+ "Navedeni su linkovi za web sajtove sa velikim brojem isečaka koje možete "
430
+ "dodati svom sajtu: .\n"
431
+ "\t\t<ul>\n"
432
+ "\t\t\t<li><a href=\"http://wp-snippets.com\" title=\"WordPress Snippets\">WP-"
433
+ "Snippets</a></li>\n"
434
+ "\t\t\t<li><a href=\"http://wpsnipp.com\" title=\"WP Snipp\">WP Snipp</a></"
435
+ "li>\n"
436
+ "\t\t\t<li><a href=\"http://www.catswhocode.com/blog/snippets\" title=\"Cats "
437
+ "Who Code Snippet Library\">Cats Who Code</a></li>\n"
438
+ "\t\t\t<li><a href=\"http://www.wpfunction.me\">WP Function Me</a></li>\n"
439
+ "\t\t</ul>"
440
+
441
+ #: includes/help/single.php:24
442
+ msgid "Adding Snippets"
443
+ msgstr "Dodavanje isečaka"
444
+
445
+ #: includes/help/single.php:26
446
+ msgid ""
447
+ "You need to fill out the name and code fields for your snippet to be added. "
448
+ "While the description field will add more information about how your snippet "
449
+ "works, what is does and where you found it, it is completely optional."
450
+ msgstr ""
451
+ "Morate popuniti polja sa nazivom i kodom za isečak koji želite da dodate. "
452
+ "Iako opisno polje sadrži više podataka o tome kako vaš isečak funkcioniše, "
453
+ "šta radi i gde ga možete naći, potpuno je proizvoljno."
454
+
455
+ #: includes/help/single.php:27
456
+ msgid ""
457
+ "Please be sure to check that your snippet is valid PHP code and will not "
458
+ "produce errors before adding it through this page. While doing so will not "
459
+ "become active straight away, it will help to minimise the chance of a faulty "
460
+ "snippet becoming active on your site."
461
+ msgstr ""
462
+ "Proverite da li vam je isečak važeći PHP kod i uverite se da neće praviti "
463
+ "greške pre nego što ga dodate putem ove stranice. Dok to radite, neće odmah "
464
+ "postati aktivan; pomoći će vam da smanjite na minimum šanse da se na vašem "
465
+ "sajtu aktivira isečak sa greškom. "
466
+
467
+ #: code-snippets.php:0
468
+ msgid "http://code-snippets.bungeshea.com"
469
+ msgstr "http://code-snippets.bungeshea.com"
470
+
471
+ #: code-snippets.php:263
472
+ msgid "Import snippets from a <strong>Code Snippets</strong> export file"
473
+ msgstr "Uvezi isečke iz <strong>Code Snippets</strong> datoteke za izvoz."
474
+
475
+ #: includes/admin/import.php:20
476
+ msgid "Imported <strong>%d</strong> snippet."
477
+ msgid_plural "Imported <strong>%d</strong> snippets."
478
+ msgstr[0] ""
479
+ msgstr[1] ""
480
+
481
+ #: includes/help/import.php:29 includes/help/manage.php:30
482
+ #: includes/help/single.php:34
483
+ msgid ""
484
+ "<a href=\"http://code-snippets.bungeshea.com/\" target=\"_blank\">Project "
485
+ "Website</a>"
486
+ msgstr ""
487
+ "<a href=\"http://code-snippets.bungeshea.com/\" target=\"_blank\">Project "
488
+ "Website</a>"
489
+
490
+ #: includes/help/manage.php:15
491
+ msgid ""
492
+ "If something goes wrong with a snippet and you can't use WordPress, you can "
493
+ "cause all snippets to stop executing by adding <code>define"
494
+ "('CODE_SNIPPETS_SAFE_MODE', true);</code> to your <code>wp-config.php</code> "
495
+ "file. After you have deactivated the offending snippet, you can turn off "
496
+ "safe mode by removing this line or replacing <strong>true</strong> with "
497
+ "<strong>false</strong>."
498
+ msgstr ""
499
+ "Ako se nešto u vezi sa isečkom pokvari i ne možete da koristite WordPress, "
500
+ "možete deaktivirati sve isečke tako što ćete uneti: <code>define"
501
+ "('CODE_SNIPPETS_SAFE_MODE', true);</code> u svoju <code>wp-config.php</code> "
502
+ "datoteku. Kad deaktivirate pogrešan isečak, možete isključiti bezbedan režim "
503
+ "tako što ćete ukloniti ovu liniju ili zameniti <strong>true</strong> sa "
504
+ "<strong>false</strong>."
505
+
506
+ #: includes/help/single.php:20
507
+ msgid ""
508
+ "More places to find snippets, as well as a selection of example snippets, "
509
+ "can be found in the <a href=\"http://code-snippets.bungeshea.com/docs/"
510
+ "finding-snippets/\">plugin documentation</a>"
511
+ msgstr ""
512
+ "Više mesta za pronalaženje isečaka, kao i odabrane primere isečaka, možete "
513
+ "naći na: <a href=\"http://code-snippets.bungeshea.com/docs/finding-snippets/"
514
+ "\">plugin documentation</a>"
515
+
516
+ #: code-snippets.php:0
517
+ msgid "1.7"
518
+ msgstr "1.7"
519
+
520
+ #: code-snippets.php:602 includes/class-list-table.php:142
521
+ msgid "Edit"
522
+ msgstr "Uredi"
523
+
524
+ #: code-snippets.php:1227
525
+ msgid "Sorry, you're not allowed to edit snippets"
526
+ msgstr "Žao nam je, nije vam dozvoljeno da uređujete isečke."
527
+
528
+ #: includes/admin/single.php:24
529
+ msgid "Snippet <strong>updated</strong> and <strong>activated</strong>."
530
+ msgstr "Isečak <strong>ažuriran</strong> i <strong>aktiviran</strong>."
531
+
532
+ #: includes/admin/single.php:26
533
+ msgid "Snippet <strong>added</strong> and <strong>activated</strong>."
534
+ msgstr "Isečak <strong>dodat </strong> i <strong>aktiviran</strong>."
535
+
536
+ #: includes/class-list-table.php:163
537
+ msgid ""
538
+ "You are about to permanently delete the selected item.\n"
539
+ "\t\t\t\t'Cancel' to stop, 'OK' to delete."
540
+ msgstr ""
541
+ "Spremate se da trajno obrišete odabranu jedinicu. \n"
542
+ "\t\t\t\t Kliknite na 'Poništi' da biste otkazali ili na 'OK' da biste "
543
+ "obrisali. "
544
+
545
+ #: includes/class-list-table.php:270
546
+ msgid "Filter"
547
+ msgstr "Filter"
548
+
549
+ #: includes/class-list-table.php:541
550
+ msgid "Search results"
551
+ msgstr "Rezultati pretrage"
552
+
553
+ #: includes/class-list-table.php:544
554
+ msgid " for &#8220;%s&#8221;"
555
+ msgstr "za &#8220;%s&#8221;"
556
+
557
+ #: includes/class-list-table.php:550
558
+ msgid "Clear Filters"
559
+ msgstr "Obriši filtere"
560
+
561
+ #: includes/help/import.php:14
562
+ msgid ""
563
+ "You can load your snippets from a code snippets (.xml) export file using "
564
+ "this page."
565
+ msgstr ""
566
+ "Možete otpremiti svoje isečke iz code snippets (.xml) datoteke za izvoz uz "
567
+ "pomoć sledeće stranice. "
568
+
569
+ #: includes/admin/single.php:74
570
+ msgid "Save Changes &amp; Activate"
571
+ msgstr "Sačuvaj izmene &amp; Aktiviraj "
languages/code-snippets-zh_CN.mo ADDED
Binary file
languages/code-snippets-zh_CN.po ADDED
@@ -0,0 +1,517 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # This file is distributed under the same license as the Code Snippets package.
2
+ msgid ""
3
+ msgstr ""
4
+ "PO-Revision-Date: 2014-09-06 15:42+0800\n"
5
+ "MIME-Version: 1.0\n"
6
+ "Content-Type: text/plain; charset=UTF-8\n"
7
+ "Content-Transfer-Encoding: 8bit\n"
8
+ "Plural-Forms: nplurals=2; plural=n != 1;\n"
9
+ "X-Generator: Poedit 1.6.9\n"
10
+ "Project-Id-Version: Code Snippets\n"
11
+ "POT-Creation-Date: \n"
12
+ "Last-Translator: \n"
13
+ "Language-Team: Jincheng Shan <hi@shanjincheng.com>\n"
14
+ "Language: zh_Hans_CN\n"
15
+ "X-Poedit-SourceCharset: UTF-8\n"
16
+
17
+ #: code-snippets.php:0 code-snippets.php:262
18
+ msgid "Code Snippets"
19
+ msgstr "Code Snippets"
20
+
21
+ #: code-snippets.php:0
22
+ msgid ""
23
+ "An easy, clean and simple way to add code snippets to your site. No need to "
24
+ "edit to your theme's functions.php file again!"
25
+ msgstr ""
26
+ "以简单、简洁、简约的方式添加代码片段到您的站点。再也没有必要去编辑主题的 "
27
+ "functions.php 文件!"
28
+
29
+ #: code-snippets.php:0
30
+ msgid "Shea Bunge"
31
+ msgstr "Shea Bunge"
32
+
33
+ #: code-snippets.php:0
34
+ msgid "http://bungeshea.com"
35
+ msgstr "http://bungeshea.com"
36
+
37
+ #: code-snippets.php:577 code-snippets.php:578 code-snippets.php:588
38
+ #: includes/admin/manage.php:36
39
+ msgid "Snippets"
40
+ msgstr "片段"
41
+
42
+ #: code-snippets.php:612 code-snippets.php:1145 includes/admin/single.php:45
43
+ msgid "Add New Snippet"
44
+ msgstr "添加片段"
45
+
46
+ #: code-snippets.php:613
47
+ msgid "Add New"
48
+ msgstr "添加"
49
+
50
+ #: code-snippets.php:641 includes/admin/import.php:34
51
+ msgid "Import Snippets"
52
+ msgstr "导入片段"
53
+
54
+ #: code-snippets.php:642
55
+ msgid "Import"
56
+ msgstr "导入"
57
+
58
+ #: code-snippets.php:601 code-snippets.php:1146 includes/admin/single.php:37
59
+ msgid "Edit Snippet"
60
+ msgstr "编辑片段"
61
+
62
+ #: code-snippets.php:1465
63
+ msgid "Manage your existing snippets"
64
+ msgstr "管理现有片段"
65
+
66
+ #: code-snippets.php:589 code-snippets.php:1466
67
+ msgid "Manage"
68
+ msgstr "管理"
69
+
70
+ #: code-snippets.php:1486
71
+ msgid "Visit the WordPress.org plugin page"
72
+ msgstr "访问往于 WordPress.org 的插件页面"
73
+
74
+ #: code-snippets.php:1487
75
+ msgid "About"
76
+ msgstr "关于"
77
+
78
+ #: code-snippets.php:1491
79
+ msgid "Visit the support forums"
80
+ msgstr "访问帮助论坛"
81
+
82
+ #: code-snippets.php:1492
83
+ msgid "Support"
84
+ msgstr "支持"
85
+
86
+ #: code-snippets.php:1496
87
+ msgid "Support this plugin's development"
88
+ msgstr "帮助此插件的开发"
89
+
90
+ #: code-snippets.php:1497
91
+ msgid "Donate"
92
+ msgstr "捐助"
93
+
94
+ #: includes/admin/import.php:38
95
+ msgid ""
96
+ "Howdy! Upload your Code Snippets export file and we&#8217;ll import the "
97
+ "snippets to this site."
98
+ msgstr "您好!请上传你的 Code Snippets 导出文件,我们会导入片段到此站点。"
99
+
100
+ #: includes/admin/import.php:40
101
+ msgid ""
102
+ "You will need to go to the <a href=\"%s\">Manage Snippets</a> page to "
103
+ "activate the imported snippets."
104
+ msgstr "您需要访问 <a href=\"%s\">管理片段</a> 页面来激活导入的片段。"
105
+
106
+ #: includes/admin/import.php:42
107
+ msgid ""
108
+ "Choose a Code Snippets (.xml) file to upload, then click Upload file and "
109
+ "import."
110
+ msgstr "选择一个 Code Snippets 导出文件(.xml)上传,并点击上传文件来导入。"
111
+
112
+ #: includes/admin/import.php:46
113
+ msgid "Choose a file from your computer:"
114
+ msgstr "选择一个您电脑上的文件:"
115
+
116
+ #: includes/admin/import.php:46
117
+ msgid "(Maximum size: 8MB)"
118
+ msgstr "(最大上传文件大小:8 MB)"
119
+
120
+ #: includes/admin/import.php:55
121
+ msgid "Upload file and import"
122
+ msgstr "上传文件并导入"
123
+
124
+ #: includes/admin/manage.php:21
125
+ msgid "Snippet <strong>activated</strong>."
126
+ msgstr "片段 <strong>已激活</strong>。"
127
+
128
+ #: includes/admin/manage.php:23
129
+ msgid "Selected snippets <strong>activated</strong>."
130
+ msgstr "选择的片段 <strong>已激活</strong>。"
131
+
132
+ #: includes/admin/manage.php:25
133
+ msgid "Snippet <strong>deactivated</strong>."
134
+ msgstr "片段 <strong>已禁用</strong>。"
135
+
136
+ #: includes/admin/manage.php:27
137
+ msgid "Selected snippets <strong>deactivated</strong>."
138
+ msgstr "选择的片段 <strong>已禁用</strong>。"
139
+
140
+ #: includes/admin/manage.php:29
141
+ msgid "Snippet <strong>deleted</strong>."
142
+ msgstr "片段 <strong>已删除</strong>。"
143
+
144
+ #: includes/admin/manage.php:31
145
+ msgid "Selected snippets <strong>deleted</strong>."
146
+ msgstr "选择的片段 <strong>已删除</strong>。"
147
+
148
+ #: includes/admin/manage.php:38 includes/admin/single.php:42
149
+ msgctxt "snippet"
150
+ msgid "Add New"
151
+ msgstr "添加片段"
152
+
153
+ #: includes/admin/manage.php:47
154
+ msgid "Search Installed Snippets"
155
+ msgstr "搜索已安装的片段"
156
+
157
+ #: includes/admin/single.php:22
158
+ msgid "Please provide a name for the snippet and its code."
159
+ msgstr "请为片段命名。"
160
+
161
+ #: includes/admin/single.php:28
162
+ msgid "Snippet <strong>updated</strong>."
163
+ msgstr "片段 <strong>已上传</strong>。"
164
+
165
+ #: includes/admin/single.php:30
166
+ msgid "Snippet <strong>added</strong>."
167
+ msgstr "片段 <strong>已添加</strong>。"
168
+
169
+ #: includes/admin/single.php:55 includes/admin/single.php:56
170
+ msgid "Name (short title)"
171
+ msgstr "名称(简称)"
172
+
173
+ #: includes/admin/single.php:61
174
+ msgid "Code"
175
+ msgstr "代码"
176
+
177
+ #: code-snippets.php:1433 includes/class-list-table.php:189
178
+ msgid "Description"
179
+ msgstr "简介"
180
+
181
+ #: code-snippets.php:1434
182
+ msgid "(Optional)"
183
+ msgstr "(可选)"
184
+
185
+ #: includes/class-list-table.php:36
186
+ msgid "Snippets per page"
187
+ msgstr "每页显示的片段数"
188
+
189
+ #: code-snippets.php:1118 includes/class-list-table.php:127
190
+ #: includes/class-list-table.php:213
191
+ msgid "Network Deactivate"
192
+ msgstr "网络禁用"
193
+
194
+ #: code-snippets.php:1118 includes/class-list-table.php:127
195
+ #: includes/class-list-table.php:213
196
+ msgid "Deactivate"
197
+ msgstr "禁用"
198
+
199
+ #: code-snippets.php:1127 includes/class-list-table.php:137
200
+ #: includes/class-list-table.php:212
201
+ msgid "Network Activate"
202
+ msgstr "网络启用"
203
+
204
+ #: code-snippets.php:1127 includes/class-list-table.php:137
205
+ #: includes/class-list-table.php:212
206
+ msgid "Activate"
207
+ msgstr "启用"
208
+
209
+ #: includes/class-list-table.php:187
210
+ msgid "Name"
211
+ msgstr "名称"
212
+
213
+ #: includes/class-list-table.php:188
214
+ msgid "ID"
215
+ msgstr "ID"
216
+
217
+ #: includes/class-list-table.php:147 includes/class-list-table.php:214
218
+ msgid "Export"
219
+ msgstr "导出"
220
+
221
+ #: includes/class-list-table.php:155 includes/class-list-table.php:215
222
+ msgid "Delete"
223
+ msgstr "删除"
224
+
225
+ #: includes/class-list-table.php:216
226
+ msgid "Export to PHP"
227
+ msgstr "导出到 PHP"
228
+
229
+ #: includes/class-list-table.php:236
230
+ msgid "All <span class=\"count\">(%s)</span>"
231
+ msgid_plural "All <span class=\"count\">(%s)</span>"
232
+ msgstr[0] "所有<span class=\"count\">(%s)</span>"
233
+ msgstr[1] "所有<span class=\"count\">(%s)</span>"
234
+
235
+ #: includes/class-list-table.php:239
236
+ msgid "Active <span class=\"count\">(%s)</span>"
237
+ msgid_plural "Active <span class=\"count\">(%s)</span>"
238
+ msgstr[0] "启用<span class=\"count\">(%s)</span>"
239
+ msgstr[1] "启用<span class=\"count\">(%s)</span>"
240
+
241
+ #: includes/class-list-table.php:242
242
+ msgid "Recently Active <span class=\"count\">(%s)</span>"
243
+ msgid_plural "Recently Active <span class=\"count\">(%s)</span>"
244
+ msgstr[0] "最近启用<span class=\"count\">(%s)</span>"
245
+ msgstr[1] "最近启用<span class=\"count\">(%s)</span>"
246
+
247
+ #: includes/class-list-table.php:245
248
+ msgid "Inactive <span class=\"count\">(%s)</span>"
249
+ msgid_plural "Inactive <span class=\"count\">(%s)</span>"
250
+ msgstr[0] "禁用<span class=\"count\">(%s)</span>"
251
+ msgstr[1] "禁用<span class=\"count\">(%s)</span>"
252
+
253
+ #: includes/class-list-table.php:279
254
+ msgid "Clear List"
255
+ msgstr "清除列表"
256
+
257
+ #: includes/class-list-table.php:374
258
+ msgid ""
259
+ "You do not appear to have any snippets available at this time. <a href=\"%s"
260
+ "\">Add New&rarr;</a>"
261
+ msgstr "目前还没有一个可用的代码片段。<a href=\"%s\">添加&rarr;</a>"
262
+
263
+ #: includes/help/import.php:5 includes/help/manage.php:5
264
+ #: includes/help/single.php:5
265
+ msgid "Overview"
266
+ msgstr "概述"
267
+
268
+ #: includes/help/import.php:7
269
+ msgid ""
270
+ "Snippets are similar to plugins - they both extend and expand the "
271
+ "functionality of WordPress. Snippets are more light-weight, just a few lines "
272
+ "of code, and do not put as much load on your server. Here you can load "
273
+ "snippets from a Code Snippets (.xml) import file into the database with your "
274
+ "existing snippets."
275
+ msgstr ""
276
+
277
+ #: includes/help/import.php:12
278
+ msgid "Importing"
279
+ msgstr "导入"
280
+
281
+ #: includes/help/import.php:15
282
+ msgid ""
283
+ "Snippets will be added to the database along with your existing snippets. "
284
+ "Regardless of whether the snippets were active on the previous site, "
285
+ "imported snippets are always inactive until activated using the <a href=\"%s"
286
+ "\">Manage Snippets</a> page.</p>"
287
+ msgstr ""
288
+
289
+ #: includes/help/import.php:20
290
+ msgid "Exporting"
291
+ msgstr "导出"
292
+
293
+ #: includes/help/import.php:22
294
+ msgid ""
295
+ "You can save your snippets to a Code Snippets (.xml) export file using the "
296
+ "<a href=\"%s\">Manage Snippets</a> page."
297
+ msgstr ""
298
+
299
+ #: includes/help/import.php:26 includes/help/manage.php:27
300
+ #: includes/help/single.php:31
301
+ msgid "For more information:"
302
+ msgstr "更多信息:"
303
+
304
+ #: includes/help/import.php:27 includes/help/single.php:32
305
+ msgid ""
306
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
307
+ "\">WordPress Extend</a>"
308
+ msgstr ""
309
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
310
+ "\">WordPress 插件页面</a>"
311
+
312
+ #: includes/help/import.php:28 includes/help/manage.php:29
313
+ #: includes/help/single.php:33
314
+ msgid ""
315
+ "<a href=\"http://wordpress.org/support/plugin/code-snippets\" target=\"_blank"
316
+ "\">Support Forums</a>"
317
+ msgstr ""
318
+ "<a href=\"http://wordpress.org/support/plugin/code-snippets\" target=\"_blank"
319
+ "\">帮助论坛</a>"
320
+
321
+ #: includes/help/manage.php:7
322
+ msgid ""
323
+ "Snippets are similar to plugins - they both extend and expand the "
324
+ "functionality of WordPress. Snippets are more light-weight, just a few lines "
325
+ "of code, and do not put as much load on your server. Here you can manage "
326
+ "your existing snippets and preform tasks on them such as activating, "
327
+ "deactivating, deleting and exporting."
328
+ msgstr ""
329
+
330
+ #: includes/help/manage.php:12
331
+ msgid "Safe Mode"
332
+ msgstr "安全模式"
333
+
334
+ #: includes/help/manage.php:14
335
+ msgid ""
336
+ "Be sure to check your snippets for errors before you activate them, as a "
337
+ "faulty snippet could bring your whole blog down. If your site starts doing "
338
+ "strange things, deactivate all your snippets and activate them one at a time."
339
+ msgstr ""
340
+
341
+ #: includes/help/manage.php:20
342
+ msgid "Uninstall"
343
+ msgstr "卸载"
344
+
345
+ #: includes/help/manage.php:22
346
+ msgid ""
347
+ "When you delete Code Snippets through the Plugins menu in WordPress it will "
348
+ "clear up the <code>%1$s</code> table and a few other bits of data stored in "
349
+ "the database. If you want to keep this data (ie: you are only temporally "
350
+ "uninstalling Code Snippets) then remove the <code>%2$s</code> folder using "
351
+ "FTP."
352
+ msgstr ""
353
+
354
+ #: includes/help/manage.php:23
355
+ msgid ""
356
+ "Even if you're sure that you don't want to use Code Snippets ever again on "
357
+ "this WordPress installation, you may want to use the export feature to back "
358
+ "up your snippets."
359
+ msgstr ""
360
+
361
+ #: includes/help/manage.php:28
362
+ msgid ""
363
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
364
+ "\">WordPress Extend</a></p>"
365
+ msgstr ""
366
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
367
+ "\">WordPress 插件页面</a></p>"
368
+
369
+ #: includes/help/single.php:7
370
+ msgid ""
371
+ "Snippets are similar to plugins - they both extend and expand the "
372
+ "functionality of WordPress. Snippets are more light-weight, just a few lines "
373
+ "of code, and do not put as much load on your server. Here you can add a new "
374
+ "snippet, or edit an existing one."
375
+ msgstr ""
376
+
377
+ #: includes/help/single.php:11
378
+ msgid "Finding Snippets"
379
+ msgstr "寻找片段"
380
+
381
+ #: includes/help/single.php:13
382
+ msgid ""
383
+ "Here are some links to websites which host a large number of snippets that "
384
+ "you can add to your site.\n"
385
+ "\t\t<ul>\n"
386
+ "\t\t\t<li><a href=\"http://wp-snippets.com\" title=\"WordPress Snippets\">WP-"
387
+ "Snippets</a></li>\n"
388
+ "\t\t\t<li><a href=\"http://wpsnipp.com\" title=\"WP Snipp\">WP Snipp</a></"
389
+ "li>\n"
390
+ "\t\t\t<li><a href=\"http://www.catswhocode.com/blog/snippets\" title=\"Cats "
391
+ "Who Code Snippet Library\">Cats Who Code</a></li>\n"
392
+ "\t\t\t<li><a href=\"http://www.wpfunction.me\">WP Function Me</a></li>\n"
393
+ "\t\t</ul>"
394
+ msgstr ""
395
+ "您可以将这里有着数量巨大的代码片段的网站中的片段添加到您的站点。\n"
396
+ "\t\t<ul>\n"
397
+ "\t\t\t<li><a href=\"http://wp-snippets.com\" title=\"WordPress Snippets\">WP-"
398
+ "Snippets</a></li>\n"
399
+ "\t\t\t<li><a href=\"http://wpsnipp.com\" title=\"WP Snipp\">WP Snipp</a></"
400
+ "li>\n"
401
+ "\t\t\t<li><a href=\"http://www.catswhocode.com/blog/snippets\" title=\"Cats "
402
+ "Who Code Snippet Library\">Cats Who Code</a></li>\n"
403
+ "\t\t\t<li><a href=\"http://www.wpfunction.me\">WP Function Me</a></li>\n"
404
+ "\t\t</ul>"
405
+
406
+ #: includes/help/single.php:24
407
+ msgid "Adding Snippets"
408
+ msgstr "添加片段"
409
+
410
+ #: includes/help/single.php:26
411
+ msgid ""
412
+ "You need to fill out the name and code fields for your snippet to be added. "
413
+ "While the description field will add more information about how your snippet "
414
+ "works, what is does and where you found it, it is completely optional."
415
+ msgstr ""
416
+
417
+ #: includes/help/single.php:27
418
+ msgid ""
419
+ "Please be sure to check that your snippet is valid PHP code and will not "
420
+ "produce errors before adding it through this page. While doing so will not "
421
+ "become active straight away, it will help to minimise the chance of a faulty "
422
+ "snippet becoming active on your site."
423
+ msgstr ""
424
+
425
+ #: code-snippets.php:0
426
+ msgid "http://code-snippets.bungeshea.com"
427
+ msgstr "http://code-snippets.bungeshea.com"
428
+
429
+ #: code-snippets.php:263
430
+ msgid "Import snippets from a <strong>Code Snippets</strong> export file"
431
+ msgstr "上传来自于 <strong>Code Snippets</strong> 导出文件的代码片段。"
432
+
433
+ #: includes/admin/import.php:20
434
+ msgid "Imported <strong>%d</strong> snippet."
435
+ msgid_plural "Imported <strong>%d</strong> snippets."
436
+ msgstr[0] "已上传 <strong>%d</strong> 个片段。"
437
+ msgstr[1] "已上传 <strong>%d</strong> 个片段。"
438
+
439
+ #: includes/help/import.php:29 includes/help/manage.php:30
440
+ #: includes/help/single.php:34
441
+ msgid ""
442
+ "<a href=\"http://code-snippets.bungeshea.com/\" target=\"_blank\">Project "
443
+ "Website</a>"
444
+ msgstr ""
445
+ "<a href=\"http://code-snippets.bungeshea.com/\" target=\"_blank\">项目站点</"
446
+ "a>"
447
+
448
+ #: includes/help/manage.php:15
449
+ msgid ""
450
+ "If something goes wrong with a snippet and you can't use WordPress, you can "
451
+ "cause all snippets to stop executing by adding "
452
+ "<code>define('CODE_SNIPPETS_SAFE_MODE', true);</code> to your <code>wp-"
453
+ "config.php</code> file. After you have deactivated the offending snippet, "
454
+ "you can turn off safe mode by removing this line or replacing <strong>true</"
455
+ "strong> with <strong>false</strong>."
456
+ msgstr ""
457
+
458
+ #: includes/help/single.php:20
459
+ msgid ""
460
+ "More places to find snippets, as well as a selection of example snippets, "
461
+ "can be found in the <a href=\"http://code-snippets.bungeshea.com/docs/"
462
+ "finding-snippets/\">plugin documentation</a>"
463
+ msgstr ""
464
+
465
+ #: code-snippets.php:0
466
+ msgid "1.7"
467
+ msgstr "1.7"
468
+
469
+ #: code-snippets.php:602 includes/class-list-table.php:142
470
+ msgid "Edit"
471
+ msgstr "编辑"
472
+
473
+ #: code-snippets.php:1227
474
+ msgid "Sorry, you're not allowed to edit snippets"
475
+ msgstr "对不起,您未被授予修改片段的权限。"
476
+
477
+ #: includes/admin/single.php:24
478
+ msgid "Snippet <strong>updated</strong> and <strong>activated</strong>."
479
+ msgstr "片段 <strong>已上传</strong> 并 <strong>已启用</strong>。"
480
+
481
+ #: includes/admin/single.php:26
482
+ msgid "Snippet <strong>added</strong> and <strong>activated</strong>."
483
+ msgstr "片段 <strong>已添加</strong> 并 <strong>已启用</strong>。"
484
+
485
+ #: includes/class-list-table.php:163
486
+ msgid ""
487
+ "You are about to permanently delete the selected item.\n"
488
+ "\t\t\t\t'Cancel' to stop, 'OK' to delete."
489
+ msgstr ""
490
+ "您即将彻底删除所选条目。\n"
491
+ "\t\t\t\t点击「取消」以停止, 「确认」以删除。"
492
+
493
+ #: includes/class-list-table.php:270
494
+ msgid "Filter"
495
+ msgstr "关键词"
496
+
497
+ #: includes/class-list-table.php:541
498
+ msgid "Search results"
499
+ msgstr "&#8220;%s&#8221"
500
+
501
+ #: includes/class-list-table.php:544
502
+ msgid " for &#8220;%s&#8221;"
503
+ msgstr "的搜索结果"
504
+
505
+ #: includes/class-list-table.php:550
506
+ msgid "Clear Filters"
507
+ msgstr "清除关键词"
508
+
509
+ #: includes/help/import.php:14
510
+ msgid ""
511
+ "You can load your snippets from a code snippets (.xml) export file using "
512
+ "this page."
513
+ msgstr "您可以于此页加载 Code Snippets 导出文件(.xml)中的代码片段。"
514
+
515
+ #: includes/admin/single.php:74
516
+ msgid "Save Changes &amp; Activate"
517
+ msgstr "保存设置并启用"
languages/code-snippets.mo ADDED
Binary file
languages/code-snippets.pot CHANGED
@@ -1,419 +1,675 @@
1
- # This file is distributed under the same license as the Code Snippets package.
2
- msgid ""
3
- msgstr ""
4
- "PO-Revision-Date: 2013-03-27 15:45:42+0000\n"
5
- "MIME-Version: 1.0\n"
6
- "Content-Type: text/plain; charset=UTF-8\n"
7
- "Content-Transfer-Encoding: 8bit\n"
8
- "Plural-Forms: nplurals=2; plural=n != 1;\n"
9
- "X-Generator: GlotPress/0.1\n"
10
- "Project-Id-Version: Code Snippets\n"
11
-
12
- #: code-snippets.php:0 code-snippets.php:262
13
- msgid "Code Snippets"
14
- msgstr ""
15
-
16
- #: code-snippets.php:0
17
- msgid "An easy, clean and simple way to add code snippets to your site. No need to edit to your theme's functions.php file again!"
18
- msgstr ""
19
-
20
- #: code-snippets.php:0
21
- msgid "Shea Bunge"
22
- msgstr ""
23
-
24
- #: code-snippets.php:0
25
- msgid "http://bungeshea.com"
26
- msgstr ""
27
-
28
- #: code-snippets.php:577 code-snippets.php:578 code-snippets.php:588
29
- #: includes/admin/manage.php:36
30
- msgid "Snippets"
31
- msgstr ""
32
-
33
- #: code-snippets.php:612 code-snippets.php:1145 includes/admin/single.php:45
34
- msgid "Add New Snippet"
35
- msgstr ""
36
-
37
- #: code-snippets.php:613
38
- msgid "Add New"
39
- msgstr ""
40
-
41
- #: code-snippets.php:641 includes/admin/import.php:34
42
- msgid "Import Snippets"
43
- msgstr ""
44
-
45
- #: code-snippets.php:642
46
- msgid "Import"
47
- msgstr ""
48
-
49
- #: code-snippets.php:601 code-snippets.php:1146 includes/admin/single.php:37
50
- msgid "Edit Snippet"
51
- msgstr ""
52
-
53
- #: code-snippets.php:1465
54
- msgid "Manage your existing snippets"
55
- msgstr ""
56
-
57
- #: code-snippets.php:589 code-snippets.php:1466
58
- msgid "Manage"
59
- msgstr ""
60
-
61
- #: code-snippets.php:1486
62
- msgid "Visit the WordPress.org plugin page"
63
- msgstr ""
64
-
65
- #: code-snippets.php:1487
66
- msgid "About"
67
- msgstr ""
68
-
69
- #: code-snippets.php:1491
70
- msgid "Visit the support forums"
71
- msgstr ""
72
-
73
- #: code-snippets.php:1492
74
- msgid "Support"
75
- msgstr ""
76
-
77
- #: code-snippets.php:1496
78
- msgid "Support this plugin's development"
79
- msgstr ""
80
-
81
- #: code-snippets.php:1497
82
- msgid "Donate"
83
- msgstr ""
84
-
85
- #: includes/admin/import.php:38
86
- msgid "Howdy! Upload your Code Snippets export file and we&#8217;ll import the snippets to this site."
87
- msgstr ""
88
-
89
- #: includes/admin/import.php:40
90
- msgid "You will need to go to the <a href=\"%s\">Manage Snippets</a> page to activate the imported snippets."
91
- msgstr ""
92
-
93
- #: includes/admin/import.php:42
94
- msgid "Choose a Code Snippets (.xml) file to upload, then click Upload file and import."
95
- msgstr ""
96
-
97
- #: includes/admin/import.php:46
98
- msgid "Choose a file from your computer:"
99
- msgstr ""
100
-
101
- #: includes/admin/import.php:46
102
- msgid "(Maximum size: 8MB)"
103
- msgstr ""
104
-
105
- #: includes/admin/import.php:55
106
- msgid "Upload file and import"
107
- msgstr ""
108
-
109
- #: includes/admin/manage.php:21
110
- msgid "Snippet <strong>activated</strong>."
111
- msgstr ""
112
-
113
- #: includes/admin/manage.php:23
114
- msgid "Selected snippets <strong>activated</strong>."
115
- msgstr ""
116
-
117
- #: includes/admin/manage.php:25
118
- msgid "Snippet <strong>deactivated</strong>."
119
- msgstr ""
120
-
121
- #: includes/admin/manage.php:27
122
- msgid "Selected snippets <strong>deactivated</strong>."
123
- msgstr ""
124
-
125
- #: includes/admin/manage.php:29
126
- msgid "Snippet <strong>deleted</strong>."
127
- msgstr ""
128
-
129
- #: includes/admin/manage.php:31
130
- msgid "Selected snippets <strong>deleted</strong>."
131
- msgstr ""
132
-
133
- #: includes/admin/manage.php:38 includes/admin/single.php:42
134
- msgctxt "snippet"
135
- msgid "Add New"
136
- msgstr ""
137
-
138
- #: includes/admin/manage.php:47
139
- msgid "Search Installed Snippets"
140
- msgstr ""
141
-
142
- #: includes/admin/single.php:22
143
- msgid "Please provide a name for the snippet and its code."
144
- msgstr ""
145
-
146
- #: includes/admin/single.php:28
147
- msgid "Snippet <strong>updated</strong>."
148
- msgstr ""
149
-
150
- #: includes/admin/single.php:30
151
- msgid "Snippet <strong>added</strong>."
152
- msgstr ""
153
-
154
- #: includes/admin/single.php:55 includes/admin/single.php:56
155
- msgid "Name (short title)"
156
- msgstr ""
157
-
158
- #: includes/admin/single.php:61
159
- msgid "Code"
160
- msgstr ""
161
-
162
- #: code-snippets.php:1433 includes/class-list-table.php:189
163
- msgid "Description"
164
- msgstr ""
165
-
166
- #: code-snippets.php:1434
167
- msgid "(Optional)"
168
- msgstr ""
169
-
170
- #: includes/class-list-table.php:36
171
- msgid "Snippets per page"
172
- msgstr ""
173
-
174
- #: code-snippets.php:1118 includes/class-list-table.php:127
175
- #: includes/class-list-table.php:213
176
- msgid "Network Deactivate"
177
- msgstr ""
178
-
179
- #: code-snippets.php:1118 includes/class-list-table.php:127
180
- #: includes/class-list-table.php:213
181
- msgid "Deactivate"
182
- msgstr ""
183
-
184
- #: code-snippets.php:1127 includes/class-list-table.php:137
185
- #: includes/class-list-table.php:212
186
- msgid "Network Activate"
187
- msgstr ""
188
-
189
- #: code-snippets.php:1127 includes/class-list-table.php:137
190
- #: includes/class-list-table.php:212
191
- msgid "Activate"
192
- msgstr ""
193
-
194
- #: includes/class-list-table.php:187
195
- msgid "Name"
196
- msgstr ""
197
-
198
- #: includes/class-list-table.php:188
199
- msgid "ID"
200
- msgstr ""
201
-
202
- #: includes/class-list-table.php:147 includes/class-list-table.php:214
203
- msgid "Export"
204
- msgstr ""
205
-
206
- #: includes/class-list-table.php:155 includes/class-list-table.php:215
207
- msgid "Delete"
208
- msgstr ""
209
-
210
- #: includes/class-list-table.php:216
211
- msgid "Export to PHP"
212
- msgstr ""
213
-
214
- #: includes/class-list-table.php:236
215
- msgid "All <span class=\"count\">(%s)</span>"
216
- msgid_plural "All <span class=\"count\">(%s)</span>"
217
- msgstr[0] ""
218
- msgstr[1] ""
219
-
220
- #: includes/class-list-table.php:239
221
- msgid "Active <span class=\"count\">(%s)</span>"
222
- msgid_plural "Active <span class=\"count\">(%s)</span>"
223
- msgstr[0] ""
224
- msgstr[1] ""
225
-
226
- #: includes/class-list-table.php:242
227
- msgid "Recently Active <span class=\"count\">(%s)</span>"
228
- msgid_plural "Recently Active <span class=\"count\">(%s)</span>"
229
- msgstr[0] ""
230
- msgstr[1] ""
231
-
232
- #: includes/class-list-table.php:245
233
- msgid "Inactive <span class=\"count\">(%s)</span>"
234
- msgid_plural "Inactive <span class=\"count\">(%s)</span>"
235
- msgstr[0] ""
236
- msgstr[1] ""
237
-
238
- #: includes/class-list-table.php:279
239
- msgid "Clear List"
240
- msgstr ""
241
-
242
- #: includes/class-list-table.php:374
243
- msgid "You do not appear to have any snippets available at this time. <a href=\"%s\">Add New&rarr;</a>"
244
- msgstr ""
245
-
246
- #: includes/help/import.php:5 includes/help/manage.php:5
247
- #: includes/help/single.php:5
248
- msgid "Overview"
249
- msgstr ""
250
-
251
- #: includes/help/import.php:7
252
- msgid "Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. Here you can load snippets from a Code Snippets (.xml) import file into the database with your existing snippets."
253
- msgstr ""
254
-
255
- #: includes/help/import.php:12
256
- msgid "Importing"
257
- msgstr ""
258
-
259
- #: includes/help/import.php:15
260
- msgid "Snippets will be added to the database along with your existing snippets. Regardless of whether the snippets were active on the previous site, imported snippets are always inactive until activated using the <a href=\"%s\">Manage Snippets</a> page.</p>"
261
- msgstr ""
262
-
263
- #: includes/help/import.php:20
264
- msgid "Exporting"
265
- msgstr ""
266
-
267
- #: includes/help/import.php:22
268
- msgid "You can save your snippets to a Code Snippets (.xml) export file using the <a href=\"%s\">Manage Snippets</a> page."
269
- msgstr ""
270
-
271
- #: includes/help/import.php:26 includes/help/manage.php:27
272
- #: includes/help/single.php:31
273
- msgid "For more information:"
274
- msgstr ""
275
-
276
- #: includes/help/import.php:27 includes/help/single.php:32
277
- msgid "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank\">WordPress Extend</a>"
278
- msgstr ""
279
-
280
- #: includes/help/import.php:28 includes/help/manage.php:29
281
- #: includes/help/single.php:33
282
- msgid "<a href=\"http://wordpress.org/support/plugin/code-snippets\" target=\"_blank\">Support Forums</a>"
283
- msgstr ""
284
-
285
- #: includes/help/manage.php:7
286
- msgid "Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. Here you can manage your existing snippets and preform tasks on them such as activating, deactivating, deleting and exporting."
287
- msgstr ""
288
-
289
- #: includes/help/manage.php:12
290
- msgid "Safe Mode"
291
- msgstr ""
292
-
293
- #: includes/help/manage.php:14
294
- msgid "Be sure to check your snippets for errors before you activate them, as a faulty snippet could bring your whole blog down. If your site starts doing strange things, deactivate all your snippets and activate them one at a time."
295
- msgstr ""
296
-
297
- #: includes/help/manage.php:20
298
- msgid "Uninstall"
299
- msgstr ""
300
-
301
- #: includes/help/manage.php:22
302
- msgid "When you delete Code Snippets through the Plugins menu in WordPress it will clear up the <code>%1$s</code> table and a few other bits of data stored in the database. If you want to keep this data (ie: you are only temporally uninstalling Code Snippets) then remove the <code>%2$s</code> folder using FTP."
303
- msgstr ""
304
-
305
- #: includes/help/manage.php:23
306
- msgid "Even if you're sure that you don't want to use Code Snippets ever again on this WordPress installation, you may want to use the export feature to back up your snippets."
307
- msgstr ""
308
-
309
- #: includes/help/manage.php:28
310
- msgid "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank\">WordPress Extend</a></p>"
311
- msgstr ""
312
-
313
- #: includes/help/single.php:7
314
- msgid "Snippets are similar to plugins - they both extend and expand the functionality of WordPress. Snippets are more light-weight, just a few lines of code, and do not put as much load on your server. Here you can add a new snippet, or edit an existing one."
315
- msgstr ""
316
-
317
- #: includes/help/single.php:11
318
- msgid "Finding Snippets"
319
- msgstr ""
320
-
321
- #: includes/help/single.php:13
322
- msgid ""
323
- "Here are some links to websites which host a large number of snippets that you can add to your site.\n"
324
- "\t\t<ul>\n"
325
- "\t\t\t<li><a href=\"http://wp-snippets.com\" title=\"WordPress Snippets\">WP-Snippets</a></li>\n"
326
- "\t\t\t<li><a href=\"http://wpsnipp.com\" title=\"WP Snipp\">WP Snipp</a></li>\n"
327
- "\t\t\t<li><a href=\"http://www.catswhocode.com/blog/snippets\" title=\"Cats Who Code Snippet Library\">Cats Who Code</a></li>\n"
328
- "\t\t\t<li><a href=\"http://www.wpfunction.me\">WP Function Me</a></li>\n"
329
- "\t\t</ul>"
330
- msgstr ""
331
-
332
- #: includes/help/single.php:24
333
- msgid "Adding Snippets"
334
- msgstr ""
335
-
336
- #: includes/help/single.php:26
337
- msgid "You need to fill out the name and code fields for your snippet to be added. While the description field will add more information about how your snippet works, what is does and where you found it, it is completely optional."
338
- msgstr ""
339
-
340
- #: includes/help/single.php:27
341
- msgid "Please be sure to check that your snippet is valid PHP code and will not produce errors before adding it through this page. While doing so will not become active straight away, it will help to minimise the chance of a faulty snippet becoming active on your site."
342
- msgstr ""
343
-
344
- #: code-snippets.php:0
345
- msgid "http://code-snippets.bungeshea.com"
346
- msgstr ""
347
-
348
- #: code-snippets.php:263
349
- msgid "Import snippets from a <strong>Code Snippets</strong> export file"
350
- msgstr ""
351
-
352
- #: includes/admin/import.php:20
353
- msgid "Imported <strong>%d</strong> snippet."
354
- msgid_plural "Imported <strong>%d</strong> snippets."
355
- msgstr[0] ""
356
- msgstr[1] ""
357
-
358
- #: includes/help/import.php:29 includes/help/manage.php:30
359
- #: includes/help/single.php:34
360
- msgid "<a href=\"http://code-snippets.bungeshea.com/\" target=\"_blank\">Project Website</a>"
361
- msgstr ""
362
-
363
- #: includes/help/manage.php:15
364
- msgid "If something goes wrong with a snippet and you can't use WordPress, you can cause all snippets to stop executing by adding <code>define('CODE_SNIPPETS_SAFE_MODE', true);</code> to your <code>wp-config.php</code> file. After you have deactivated the offending snippet, you can turn off safe mode by removing this line or replacing <strong>true</strong> with <strong>false</strong>."
365
- msgstr ""
366
-
367
- #: includes/help/single.php:20
368
- msgid "More places to find snippets, as well as a selection of example snippets, can be found in the <a href=\"http://code-snippets.bungeshea.com/docs/finding-snippets/\">plugin documentation</a>"
369
- msgstr ""
370
-
371
- #: code-snippets.php:0
372
- msgid "1.7"
373
- msgstr ""
374
-
375
- #: code-snippets.php:602 includes/class-list-table.php:142
376
- msgid "Edit"
377
- msgstr ""
378
-
379
- #: code-snippets.php:1227
380
- msgid "Sorry, you're not allowed to edit snippets"
381
- msgstr ""
382
-
383
- #: includes/admin/single.php:24
384
- msgid "Snippet <strong>updated</strong> and <strong>activated</strong>."
385
- msgstr ""
386
-
387
- #: includes/admin/single.php:26
388
- msgid "Snippet <strong>added</strong> and <strong>activated</strong>."
389
- msgstr ""
390
-
391
- #: includes/class-list-table.php:163
392
- msgid ""
393
- "You are about to permanently delete the selected item.\n"
394
- "\t\t\t\t'Cancel' to stop, 'OK' to delete."
395
- msgstr ""
396
-
397
- #: includes/class-list-table.php:270
398
- msgid "Filter"
399
- msgstr ""
400
-
401
- #: includes/class-list-table.php:541
402
- msgid "Search results"
403
- msgstr ""
404
-
405
- #: includes/class-list-table.php:544
406
- msgid " for &#8220;%s&#8221;"
407
- msgstr ""
408
-
409
- #: includes/class-list-table.php:550
410
- msgid "Clear Filters"
411
- msgstr ""
412
-
413
- #: includes/help/import.php:14
414
- msgid "You can load your snippets from a code snippets (.xml) export file using this page."
415
- msgstr ""
416
-
417
- #: includes/admin/single.php:74
418
- msgid "Save Changes &amp; Activate"
419
- msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SOME DESCRIPTIVE TITLE.
2
+ # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3
+ # This file is distributed under the same license as the PACKAGE package.
4
+ # FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5
+ #
6
+ #, fuzzy
7
+ msgid ""
8
+ msgstr ""
9
+ "Project-Id-Version: code-snippets 2.0.0-dev\n"
10
+ "Report-Msgid-Bugs-To: \n"
11
+ "POT-Creation-Date: 2015-02-23 22:28+1030\n"
12
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14
+ "Language-Team: LANGUAGE <LL@li.org>\n"
15
+ "Language: \n"
16
+ "MIME-Version: 1.0\n"
17
+ "Content-Type: text/plain; charset=CHARSET\n"
18
+ "Content-Transfer-Encoding: 8bit\n"
19
+
20
+ #: includes/admin.php:81 includes/manage/admin.php:21
21
+ #: includes/manage/manage.php:22 includes/manage/manage.php:23
22
+ #: includes/manage/manage.php:33
23
+ msgid "Snippets"
24
+ msgstr ""
25
+
26
+ #: includes/admin.php:120
27
+ msgid "Manage your existing snippets"
28
+ msgstr ""
29
+
30
+ #: includes/admin.php:121 includes/manage/manage.php:34
31
+ msgid "Manage"
32
+ msgstr ""
33
+
34
+ #: includes/admin.php:150
35
+ msgid "Visit the WordPress.org plugin page"
36
+ msgstr ""
37
+
38
+ #: includes/admin.php:151
39
+ msgid "About"
40
+ msgstr ""
41
+
42
+ #: includes/admin.php:155
43
+ msgid "Visit the support forums"
44
+ msgstr ""
45
+
46
+ #: includes/admin.php:156
47
+ msgid "Support"
48
+ msgstr ""
49
+
50
+ #: includes/admin.php:160
51
+ msgid "Support this plugin's development"
52
+ msgstr ""
53
+
54
+ #: includes/admin.php:161
55
+ msgid "Donate"
56
+ msgstr ""
57
+
58
+ #: includes/admin.php:194
59
+ msgid ""
60
+ "<strong>Have feedback on Code Snippets?</strong> Please take the time to "
61
+ "answer a short survey on how you use this plugin and what you'd like to see "
62
+ "changed or added in the future."
63
+ msgstr ""
64
+
65
+ #: includes/admin.php:197
66
+ msgid "Take the survey now"
67
+ msgstr ""
68
+
69
+ #: includes/class-export.php:104
70
+ msgid ""
71
+ "This is a code snippets export file generated by the Code Snippets WordPress "
72
+ "plugin."
73
+ msgstr ""
74
+
75
+ #: includes/class-export.php:105
76
+ msgid "http://wordpress.org/plugins/code-snippets"
77
+ msgstr ""
78
+
79
+ #: includes/class-export.php:106
80
+ msgid "To import these snippets a WordPress site follow these steps:"
81
+ msgstr ""
82
+
83
+ #: includes/class-export.php:107
84
+ msgid "1. Log in to that site as an administrator."
85
+ msgstr ""
86
+
87
+ #: includes/class-export.php:108
88
+ msgid ""
89
+ "2. Install the Code Snippets plugin using the directions provided at the "
90
+ "above link."
91
+ msgstr ""
92
+
93
+ #: includes/class-export.php:109
94
+ msgid "3. Go to 'Tools: Import' in the WordPress admin panel."
95
+ msgstr ""
96
+
97
+ #: includes/class-export.php:110
98
+ msgid "4. Click on the \"Code Snippets\" importer in the list"
99
+ msgstr ""
100
+
101
+ #: includes/class-export.php:111
102
+ msgid "5. Upload this file using the form provided on that page."
103
+ msgstr ""
104
+
105
+ #: includes/class-export.php:112
106
+ msgid ""
107
+ "6. Code Snippets will then import all of the snippets and associated "
108
+ "information contained in this file into your site."
109
+ msgstr ""
110
+
111
+ #: includes/class-export.php:113
112
+ msgid ""
113
+ "7. You will then have to visit the 'Snippets: Manage' admin menu and "
114
+ "activate desired snippets."
115
+ msgstr ""
116
+
117
+ #: includes/edit/admin-help.php:15 includes/import/admin-help.php:16
118
+ #: includes/manage/admin-help.php:15
119
+ msgid "Overview"
120
+ msgstr ""
121
+
122
+ #: includes/edit/admin-help.php:17
123
+ msgid ""
124
+ "Snippets are similar to plugins - they both extend and expand the "
125
+ "functionality of WordPress. Snippets are more light-weight, just a few lines "
126
+ "of code, and do not put as much load on your server. Here you can add a new "
127
+ "snippet, or edit an existing one."
128
+ msgstr ""
129
+
130
+ #: includes/edit/admin-help.php:22
131
+ msgid "Finding Snippets"
132
+ msgstr ""
133
+
134
+ #: includes/edit/admin-help.php:24
135
+ msgid ""
136
+ "Here are some links to websites which host a large number of snippets that "
137
+ "you can add to your site.\n"
138
+ "\t\t<ul>\n"
139
+ "\t\t\t<li><a href=\"http://wp-snippets.com\" title=\"WordPress Snippets\">WP-"
140
+ "Snippets</a></li>\n"
141
+ "\t\t\t<li><a href=\"http://wpsnipp.com\" title=\"WP Snipp\">WP Snipp</a></"
142
+ "li>\n"
143
+ "\t\t\t<li><a href=\"http://www.catswhocode.com/blog/snippets\" title=\"Cats "
144
+ "Who Code Snippet Library\">Cats Who Code</a></li>\n"
145
+ "\t\t\t<li><a href=\"http://www.wpfunction.me\">WP Function Me</a></li>\n"
146
+ "\t\t</ul>"
147
+ msgstr ""
148
+
149
+ #: includes/edit/admin-help.php:31
150
+ msgid ""
151
+ "More places to find snippets, as well as a selection of example snippets, "
152
+ "can be found in the <a href=\"http://code-snippets.bungeshea.com/docs/"
153
+ "finding-snippets/\">plugin documentation</a>"
154
+ msgstr ""
155
+
156
+ #: includes/edit/admin-help.php:36
157
+ msgid "Adding Snippets"
158
+ msgstr ""
159
+
160
+ #: includes/edit/admin-help.php:38
161
+ msgid ""
162
+ "You need to fill out the name and code fields for your snippet to be added. "
163
+ "While the description field will add more information about how your snippet "
164
+ "works, what is does and where you found it, it is completely optional."
165
+ msgstr ""
166
+
167
+ #: includes/edit/admin-help.php:39
168
+ msgid ""
169
+ "Please be sure to check that your snippet is valid PHP code and will not "
170
+ "produce errors before adding it through this page. While doing so will not "
171
+ "become active straight away, it will help to minimise the chance of a faulty "
172
+ "snippet becoming active on your site."
173
+ msgstr ""
174
+
175
+ #: includes/edit/admin-help.php:43 includes/import/admin-help.php:37
176
+ #: includes/manage/admin-help.php:37
177
+ msgid "For more information:"
178
+ msgstr ""
179
+
180
+ #: includes/edit/admin-help.php:44 includes/import/admin-help.php:38
181
+ msgid ""
182
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
183
+ "\">WordPress Extend</a>"
184
+ msgstr ""
185
+
186
+ #: includes/edit/admin-help.php:45 includes/import/admin-help.php:39
187
+ #: includes/manage/admin-help.php:39
188
+ msgid ""
189
+ "<a href=\"http://wordpress.org/support/plugin/code-snippets\" target=\"_blank"
190
+ "\">Support Forums</a>"
191
+ msgstr ""
192
+
193
+ #: includes/edit/admin-help.php:46 includes/import/admin-help.php:40
194
+ #: includes/manage/admin-help.php:40
195
+ msgid ""
196
+ "<a href=\"http://code-snippets.bungeshea.com/\" target=\"_blank\">Project "
197
+ "Website</a>"
198
+ msgstr ""
199
+
200
+ #: includes/edit/admin-messages.php:14
201
+ msgid "An error occurred when saving the snippet."
202
+ msgstr ""
203
+
204
+ #: includes/edit/admin-messages.php:18
205
+ msgid "Snippet <strong>updated</strong> and <strong>activated</strong>."
206
+ msgstr ""
207
+
208
+ #: includes/edit/admin-messages.php:22
209
+ msgid "Snippet <strong>added</strong> and <strong>activated</strong>."
210
+ msgstr ""
211
+
212
+ #: includes/edit/admin-messages.php:26
213
+ msgid "Snippet <strong>updated</strong> and <strong>deactivated</strong>."
214
+ msgstr ""
215
+
216
+ #: includes/edit/admin-messages.php:30
217
+ msgid "Snippet <strong>updated</strong>."
218
+ msgstr ""
219
+
220
+ #: includes/edit/admin-messages.php:34
221
+ msgid "Snippet <strong>added</strong>."
222
+ msgstr ""
223
+
224
+ #: includes/edit/admin.php:26 includes/edit/edit.php:46
225
+ #: includes/edit/edit.php:47
226
+ msgid "Edit Snippet"
227
+ msgstr ""
228
+
229
+ #: includes/edit/admin.php:31 includes/edit/edit.php:35
230
+ #: includes/manage/admin.php:26
231
+ msgid "Add New"
232
+ msgstr ""
233
+
234
+ #: includes/edit/admin.php:35 includes/edit/edit.php:34
235
+ msgid "Add New Snippet"
236
+ msgstr ""
237
+
238
+ #: includes/edit/admin.php:52 includes/edit/admin.php:53
239
+ msgid "Name (short title)"
240
+ msgstr ""
241
+
242
+ #: includes/edit/admin.php:58
243
+ msgid "Code"
244
+ msgstr ""
245
+
246
+ #: includes/edit/admin.php:79 includes/edit/admin.php:93
247
+ msgid "Save Changes and Activate"
248
+ msgstr ""
249
+
250
+ #: includes/edit/admin.php:99
251
+ msgid "Save Changes and Deactivate"
252
+ msgstr ""
253
+
254
+ #: includes/edit/admin.php:109 includes/manage/class-list-table.php:157
255
+ #: includes/manage/class-list-table.php:282
256
+ msgid "Export"
257
+ msgstr ""
258
+
259
+ #: includes/edit/admin.php:116
260
+ msgid ""
261
+ "You are about to permanently delete this snippet.\n"
262
+ "'Cancel' to stop, 'OK' to delete."
263
+ msgstr ""
264
+
265
+ #: includes/edit/admin.php:121 includes/manage/class-list-table.php:166
266
+ #: includes/manage/class-list-table.php:283
267
+ msgid "Delete"
268
+ msgstr ""
269
+
270
+ #: includes/edit/edit.php:83 includes/manage/manage.php:67
271
+ msgid "You are not authorized to access this page."
272
+ msgstr ""
273
+
274
+ #: includes/edit/edit.php:176 includes/manage/class-list-table.php:242
275
+ msgid "Description"
276
+ msgstr ""
277
+
278
+ #: includes/edit/edit.php:205 includes/manage/class-list-table.php:243
279
+ msgid "Tags"
280
+ msgstr ""
281
+
282
+ #: includes/import/admin-help.php:18
283
+ msgid ""
284
+ "Snippets are similar to plugins - they both extend and expand the "
285
+ "functionality of WordPress. Snippets are more light-weight, just a few lines "
286
+ "of code, and do not put as much load on your server. Here you can load "
287
+ "snippets from a Code Snippets (.xml) import file into the database with your "
288
+ "existing snippets."
289
+ msgstr ""
290
+
291
+ #: includes/import/admin-help.php:23
292
+ msgid "Importing"
293
+ msgstr ""
294
+
295
+ #: includes/import/admin-help.php:25
296
+ msgid ""
297
+ "You can load your snippets from a code snippets (.xml) export file using "
298
+ "this page."
299
+ msgstr ""
300
+
301
+ #: includes/import/admin-help.php:26
302
+ #, php-format
303
+ msgid ""
304
+ "Snippets will be added to the database along with your existing snippets. "
305
+ "Regardless of whether the snippets were active on the previous site, "
306
+ "imported snippets are always inactive until activated using the <a href=\"%s"
307
+ "\">Manage Snippets</a> page.</p>"
308
+ msgstr ""
309
+
310
+ #: includes/import/admin-help.php:31
311
+ msgid "Exporting"
312
+ msgstr ""
313
+
314
+ #: includes/import/admin-help.php:33
315
+ #, php-format
316
+ msgid ""
317
+ "You can save your snippets to a Code Snippets (.xml) export file using the "
318
+ "<a href=\"%s\">Manage Snippets</a> page."
319
+ msgstr ""
320
+
321
+ #: includes/import/admin-messages.php:16
322
+ #, php-format
323
+ msgid ""
324
+ "Successfully imported <strong>%d</strong> snippet. <a href=\"%s\">Have fun!</"
325
+ "a>"
326
+ msgstr ""
327
+
328
+ #: includes/import/admin-messages.php:30
329
+ msgid "An error occurred when processing the import file."
330
+ msgstr ""
331
+
332
+ #: includes/import/admin.php:18 includes/import/import.php:55
333
+ msgid "Import Snippets"
334
+ msgstr ""
335
+
336
+ #: includes/import/admin.php:22
337
+ msgid ""
338
+ "Howdy! Upload your Code Snippets export file and we&#8217;ll import the "
339
+ "snippets to this site."
340
+ msgstr ""
341
+
342
+ #: includes/import/admin.php:24
343
+ #, php-format
344
+ msgid ""
345
+ "You will need to go to the <a href=\"%s\">Manage Snippets</a> page to "
346
+ "activate the imported snippets."
347
+ msgstr ""
348
+
349
+ #: includes/import/admin.php:26
350
+ msgid ""
351
+ "Choose a Code Snippets (.xml) file to upload, then click Upload file and "
352
+ "import."
353
+ msgstr ""
354
+
355
+ #: includes/import/admin.php:33
356
+ msgid "Choose a file from your computer:"
357
+ msgstr ""
358
+
359
+ #: includes/import/admin.php:34
360
+ msgid "(Maximum size: 8MB)"
361
+ msgstr ""
362
+
363
+ #: includes/import/admin.php:40
364
+ msgid "Upload file and import"
365
+ msgstr ""
366
+
367
+ #: includes/import/import.php:34
368
+ msgid "Code Snippets"
369
+ msgstr ""
370
+
371
+ #: includes/import/import.php:35
372
+ msgid "Import snippets from a code snippets export file"
373
+ msgstr ""
374
+
375
+ #: includes/import/import.php:56
376
+ msgid "Import"
377
+ msgstr ""
378
+
379
+ #: includes/import/import.php:92
380
+ msgid "You are not access this page."
381
+ msgstr ""
382
+
383
+ #: includes/manage/admin-help.php:17
384
+ msgid ""
385
+ "Snippets are similar to plugins - they both extend and expand the "
386
+ "functionality of WordPress. Snippets are more light-weight, just a few lines "
387
+ "of code, and do not put as much load on your server. Here you can manage "
388
+ "your existing snippets and preform tasks on them such as activating, "
389
+ "deactivating, deleting and exporting."
390
+ msgstr ""
391
+
392
+ #: includes/manage/admin-help.php:22
393
+ msgid "Safe Mode"
394
+ msgstr ""
395
+
396
+ #: includes/manage/admin-help.php:24
397
+ msgid ""
398
+ "Be sure to check your snippets for errors before you activate them, as a "
399
+ "faulty snippet could bring your whole blog down. If your site starts doing "
400
+ "strange things, deactivate all your snippets and activate them one at a time."
401
+ msgstr ""
402
+
403
+ #: includes/manage/admin-help.php:25
404
+ msgid ""
405
+ "If something goes wrong with a snippet and you can't use WordPress, you can "
406
+ "cause all snippets to stop executing by adding "
407
+ "<code>define('CODE_SNIPPETS_SAFE_MODE', true);</code> to your <code>wp-"
408
+ "config.php</code> file. After you have deactivated the offending snippet, "
409
+ "you can turn off safe mode by removing this line or replacing <strong>true</"
410
+ "strong> with <strong>false</strong>."
411
+ msgstr ""
412
+
413
+ #: includes/manage/admin-help.php:30
414
+ msgid "Uninstall"
415
+ msgstr ""
416
+
417
+ #: includes/manage/admin-help.php:32
418
+ #, php-format
419
+ msgid ""
420
+ "When you delete Code Snippets through the Plugins menu in WordPress it will "
421
+ "clear up the <code>%1$s</code> table and a few other bits of data stored in "
422
+ "the database. If you want to keep this data (ie: you are only temporally "
423
+ "uninstalling Code Snippets) then remove the <code>%2$s</code> folder using "
424
+ "FTP."
425
+ msgstr ""
426
+
427
+ #: includes/manage/admin-help.php:33
428
+ msgid ""
429
+ "Even if you're sure that you don't want to use Code Snippets ever again on "
430
+ "this WordPress installation, you may want to use the export feature to back "
431
+ "up your snippets."
432
+ msgstr ""
433
+
434
+ #: includes/manage/admin-help.php:38
435
+ msgid ""
436
+ "<a href=\"http://wordpress.org/plugins/code-snippets\" target=\"_blank"
437
+ "\">WordPress Extend</a></p>"
438
+ msgstr ""
439
+
440
+ #: includes/manage/admin-messages.php:14
441
+ msgid ""
442
+ "<strong>Warning:</strong> Safe mode is active and snippets will not execute! "
443
+ "Remove the <code>CODE_SNIPPETS_SAFE_MODE</code> constant from <code>wp-"
444
+ "config.php</code> to turn off safe mode. <a href=\"http://code-snippets."
445
+ "bungeshea.com/docs/safe-mode/\" target=\"_blank\">Help</a>"
446
+ msgstr ""
447
+
448
+ #: includes/manage/admin-messages.php:20
449
+ msgid "Snippet <strong>activated</strong>."
450
+ msgstr ""
451
+
452
+ #: includes/manage/admin-messages.php:24
453
+ msgid "Selected snippets <strong>activated</strong>."
454
+ msgstr ""
455
+
456
+ #: includes/manage/admin-messages.php:28
457
+ msgid "Snippet <strong>deactivated</strong>."
458
+ msgstr ""
459
+
460
+ #: includes/manage/admin-messages.php:32
461
+ msgid "Selected snippets <strong>deactivated</strong>."
462
+ msgstr ""
463
+
464
+ #: includes/manage/admin-messages.php:36
465
+ msgid "Snippet <strong>deleted</strong>."
466
+ msgstr ""
467
+
468
+ #: includes/manage/admin-messages.php:40
469
+ msgid "Selected snippets <strong>deleted</strong>."
470
+ msgstr ""
471
+
472
+ #: includes/manage/admin.php:39
473
+ msgid "Search Installed Snippets"
474
+ msgstr ""
475
+
476
+ #: includes/manage/class-list-table.php:51
477
+ msgid "Snippets per page"
478
+ msgstr ""
479
+
480
+ #: includes/manage/class-list-table.php:132
481
+ #: includes/manage/class-list-table.php:281
482
+ msgid "Network Deactivate"
483
+ msgstr ""
484
+
485
+ #: includes/manage/class-list-table.php:132
486
+ #: includes/manage/class-list-table.php:281
487
+ msgid "Deactivate"
488
+ msgstr ""
489
+
490
+ #: includes/manage/class-list-table.php:141
491
+ #: includes/manage/class-list-table.php:280
492
+ msgid "Network Activate"
493
+ msgstr ""
494
+
495
+ #: includes/manage/class-list-table.php:141
496
+ #: includes/manage/class-list-table.php:280
497
+ msgid "Activate"
498
+ msgstr ""
499
+
500
+ #: includes/manage/class-list-table.php:151
501
+ msgid "Edit"
502
+ msgstr ""
503
+
504
+ #: includes/manage/class-list-table.php:173
505
+ msgid ""
506
+ "You are about to permanently delete the selected item.\n"
507
+ "\t\t\t\t'Cancel' to stop, 'OK' to delete."
508
+ msgstr ""
509
+
510
+ #: includes/manage/class-list-table.php:181
511
+ #, php-format
512
+ msgid "Untitled #%d"
513
+ msgstr ""
514
+
515
+ #: includes/manage/class-list-table.php:240
516
+ msgid "Name"
517
+ msgstr ""
518
+
519
+ #: includes/manage/class-list-table.php:241
520
+ msgid "ID"
521
+ msgstr ""
522
+
523
+ #: includes/manage/class-list-table.php:284
524
+ msgid "Export to PHP"
525
+ msgstr ""
526
+
527
+ #: includes/manage/class-list-table.php:321
528
+ #, php-format
529
+ msgid "All <span class=\"count\">(%s)</span>"
530
+ msgstr ""
531
+
532
+ #: includes/manage/class-list-table.php:324
533
+ #, php-format
534
+ msgid "Active <span class=\"count\">(%s)</span>"
535
+ msgstr ""
536
+
537
+ #: includes/manage/class-list-table.php:327
538
+ #, php-format
539
+ msgid "Recently Active <span class=\"count\">(%s)</span>"
540
+ msgstr ""
541
+
542
+ #: includes/manage/class-list-table.php:330
543
+ #, php-format
544
+ msgid "Inactive <span class=\"count\">(%s)</span>"
545
+ msgstr ""
546
+
547
+ #: includes/manage/class-list-table.php:390
548
+ msgid "Show all tags"
549
+ msgstr ""
550
+
551
+ #: includes/manage/class-list-table.php:404
552
+ msgid "Filter"
553
+ msgstr ""
554
+
555
+ #: includes/manage/class-list-table.php:412
556
+ msgid "Clear List"
557
+ msgstr ""
558
+
559
+ #: includes/manage/class-list-table.php:560
560
+ #, php-format
561
+ msgid ""
562
+ "You do not appear to have any snippets available at this time. <a href=\"%s"
563
+ "\">Add New&rarr;</a>"
564
+ msgstr ""
565
+
566
+ #: includes/manage/class-list-table.php:784
567
+ msgid "Search results"
568
+ msgstr ""
569
+
570
+ #: includes/manage/class-list-table.php:787
571
+ #, php-format
572
+ msgid " for &#8220;%s&#8221;"
573
+ msgstr ""
574
+
575
+ #: includes/manage/class-list-table.php:791
576
+ #, php-format
577
+ msgid " in tag &#8220;%s&#8221;"
578
+ msgstr ""
579
+
580
+ #: includes/manage/class-list-table.php:797
581
+ msgid "Clear Filters"
582
+ msgstr ""
583
+
584
+ #: includes/settings/admin.php:20
585
+ msgid "Snippets Settings"
586
+ msgstr ""
587
+
588
+ #: includes/settings/admin.php:21 includes/settings/admin.php:40
589
+ msgid "Settings"
590
+ msgstr ""
591
+
592
+ #: includes/settings/settings.php:51
593
+ msgid "General"
594
+ msgstr ""
595
+
596
+ #: includes/settings/settings.php:52
597
+ msgid "Editor"
598
+ msgstr ""
599
+
600
+ #: includes/settings/settings.php:68
601
+ msgid "Activate by Default"
602
+ msgstr ""
603
+
604
+ #: includes/settings/settings.php:70
605
+ msgid ""
606
+ "Make the 'Save and Activate' button the default action when saving a snippet."
607
+ msgstr ""
608
+
609
+ #: includes/settings/settings.php:80
610
+ msgid "Theme"
611
+ msgstr ""
612
+
613
+ #: includes/settings/settings.php:88
614
+ msgid "Indent With Tabs"
615
+ msgstr ""
616
+
617
+ #: includes/settings/settings.php:90
618
+ msgid "Use hard tabs (not spaces) for indentation."
619
+ msgstr ""
620
+
621
+ #: includes/settings/settings.php:97
622
+ msgid "Tab Size"
623
+ msgstr ""
624
+
625
+ #: includes/settings/settings.php:99
626
+ msgid "The width of a tab character."
627
+ msgstr ""
628
+
629
+ #: includes/settings/settings.php:106
630
+ msgid "Indent Unit"
631
+ msgstr ""
632
+
633
+ #: includes/settings/settings.php:108
634
+ msgid "How many spaces a block should be indented."
635
+ msgstr ""
636
+
637
+ #: includes/settings/settings.php:115
638
+ msgid "Wrap Lines"
639
+ msgstr ""
640
+
641
+ #: includes/settings/settings.php:117
642
+ msgid "Whether the editor should scroll or wrap for long lines."
643
+ msgstr ""
644
+
645
+ #: includes/settings/settings.php:124
646
+ msgid "Line Numbers"
647
+ msgstr ""
648
+
649
+ #: includes/settings/settings.php:126
650
+ msgid "Show line numbers to the left of the editor."
651
+ msgstr ""
652
+
653
+ #: includes/settings/settings.php:133
654
+ msgid "Auto Close Brackets"
655
+ msgstr ""
656
+
657
+ #: includes/settings/settings.php:135
658
+ msgid "Auto-close brackets and quotes when typed."
659
+ msgstr ""
660
+
661
+ #: includes/settings/settings.php:142
662
+ msgid "Highlight Selection Matches"
663
+ msgstr ""
664
+
665
+ #: includes/settings/settings.php:143
666
+ msgid "Highlight all instances of a currently selected word."
667
+ msgstr ""
668
+
669
+ #: includes/settings/settings.php:190
670
+ msgid "Editor Preview"
671
+ msgstr ""
672
+
673
+ #: includes/settings/settings.php:238
674
+ msgid "Settings saved."
675
+ msgstr ""
license.txt CHANGED
@@ -1,7 +1,7 @@
1
- Copyright (c) 2012-2014 Shea Bunge
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
-
5
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2012-2014 Shea Bunge
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
readme.txt CHANGED
@@ -1,319 +1,355 @@
1
- === Code Snippets ===
2
- Contributors: bungeshea
3
- Donate link: http://code-snippets.bungeshea.com/donate/
4
- Tags: code-snippets, snippets, code, php, network, multisite
5
- Requires at least: 3.3
6
- Tested up to: 4.1
7
- Stable tag: 1.9.1.1
8
- License: MIT
9
- License URI: license.txt
10
-
11
- An easy, clean and simple way to add code snippets to your site.
12
-
13
- == Description ==
14
-
15
- **Code Snippets** is an easy, clean and simple way to add code snippets to your site. No need to edit to your theme's `functions.php` file again!
16
-
17
- A snippet is a small chunk of PHP code that you can use to extend the functionality of a WordPress-powered website; essentially a mini-plugin with a *lot* less load on your site.
18
- Most snippet-hosting sites tell you to add snippet code to your active theme's `functions.php` file, which can get rather long and messy after a while.
19
- Code Snippets changes that by providing a GUI interface for adding snippets and **actually running them on your site** as if they were in your theme's `functions.php` file.
20
-
21
- You can use a graphical interface, similar to the Plugins menu, to manage, activate, deactivate, edit and delete your snippets. Easily organize your snippets by adding a name and description using the visual editor. Code Snippets includes built-in syntax highlighting and other features to help you write your code. Snippets can be exported for transfer to another side, either in XML for later importing by the Code Snippets plugin, or in PHP for creating your own plugin or theme.
22
-
23
- Although Code Snippets is designed to be easy-to-use and its interface looks, feels and acts as if it was a native part of WordPress, each screen includes a help tab, just in case you get stuck.
24
-
25
- An addon-plugin for Code Snippets is available: [Code Snippets Tags](http://wordpress.org/plugins/code-snippets-tags) will allow you to assign tags to your snippets and organize them in the table.
26
-
27
- Further information, documentation and updates are available on the [plugin homepage](http://code-snippets.bungeshea.com). You can also contribute to the code at [GitHub](https://github.com/bungeshea/code-snippets).
28
-
29
- [As featured on the WPMU blog](http://wpmu.org/wordpress-code-snippets)
30
-
31
- If you have any feedback, issues, or suggestions for improvements please leave a topic in the [Support Forum](http://wordpress.org/support/plugin/code-snippets). If you like the plugin, or it is useful to you in any way, please review it on [WordPress.org](http://wordpress.org/support/view/plugin-reviews/code-snippets).
32
-
33
- == Installation ==
34
-
35
- = Automatic installation =
36
-
37
- 1. Log into your WordPress admin
38
- 2. Click __Plugins__
39
- 3. Click __Add New__
40
- 4. Search for __Code Snippets__
41
- 5. Click __Install Now__ under "Code Snippets"
42
- 6. Activate the plugin
43
-
44
- = Manual installation =
45
-
46
- 1. Download the plugin
47
- 2. Extract the contents of the zip file
48
- 3. Upload the contents of the zip file to the `wp-content/plugins/` folder of your WordPress installation
49
- 4. Activate the Code Snippets plugin from 'Plugins' page.
50
-
51
- **Network Activating** Code Snippets through the Network Dashboard will enable a special interface for running snippets across the entire network.
52
-
53
- == Frequently Asked Questions ==
54
-
55
- Further documentation available on the [plugin website](http://code-snippets.bungeshea.com/docs/).
56
-
57
- = Do I need to include the &lt;?php, &lt;? or ?&gt; tags in my snippet? =
58
- No, just copy all the content inside those tags. If you accidentally forget (or just like being lazy), the tags will be stripped from the beginning and end of the snippet when you save it. You can, however, use those tags *inside* your snippets to start and end HTML sections.
59
-
60
- = Is there a way to add a snippet but not run it right away? =
61
- Yes. Just add it but do not activate it yet.
62
-
63
- = How can I insert my snippet into the post text editor? =
64
- Snippets that you add to this plugin are not meant to be inserted into the text editor. Instead, they are run on your site just as if they were added to your functions.php file.
65
-
66
- = Where did the Import menu go after upgrading to version 1.6? =
67
- As the import menu is not accessed neatly as much as the manage or add new menus, it has been moved under the *Tools > Import* menu. To access the import page, visit the *Tools > Import* menu in your WordPress dashboard and click on the **Code Snippets** link.
68
-
69
- = Help! I just activated a snippet, and my whole site broke! =
70
- You can try activating 'safe mode'. All snippets will not execute while safe mode is active, allowing you to access your site and deactivate the snippet that is causing the error. To activate safe mode, add the following line to your wp-config.php file, just before the line that reads `/* That's all, stop editing! Happy blogging. */`:
71
-
72
- define('CODE_SNIPPETS_SAFE_MODE', true);
73
-
74
- To turn safe mode off, either [comment out](http://php.net/manual/language.basic-syntax.comments.php) this line or delete it.
75
-
76
- = What do I use to write my snippets? =
77
- The [CodeMirror](http://codemirror.net) source-code editor will add line numbers, syntax highlighting, bracket matching, search, tabulate and other cool features to the code editor.
78
-
79
- = Can I preform search and replace commands in the code editor? =
80
-
81
- * __Ctrl-F / Cmd-F__ : Start searching
82
- * __Ctrl-G / Cmd-G__ : Find next
83
- * __Shift-Ctrl-G / Shift-Cmd-G__ : Find previous
84
- * __Shift-Ctrl-F / Cmd-Option-F__ : Replace
85
- * __Shift-Ctrl-R / Shift-Cmd-Option-F__ : Replace all
86
-
87
- = Will I lose my snippets if I change the theme or upgrade WordPress? =
88
- No, the snippets are added to the WordPress database so are independent of the theme and unaffected by WordPress upgrades.
89
-
90
- = Can the plugin be completely uninstalled? =
91
- Yes, when you delete Code Snippets using the 'Plugins' menu in WordPress it will clean up the database table and a few other bits of data. Be careful not to remove Code Snippets using the Plugins menu unless you want this to happen.
92
-
93
- = Can I copy any snippets I've created to another WordPress site? =
94
- Yes! You can individually export a single snippet using the link below the snippet name on the 'Manage Snippets' page or bulk export multiple snippets using the 'Bulk Actions' feature. Snippets can later be imported using the 'Import Snippets' page by uploading the export file.
95
-
96
- = Can I export my snippets to PHP for a site where I'm not using the Code Snippets plugin? =
97
- Yes. Click the checkboxes next to the snippets you want to export, and then choose **Export to PHP** from the Bulk Actions menu and click Apply. The generated PHP file will contain the exported snippets' code, as well as their name and description in comments.
98
-
99
- = Can I run network-wide snippets on a multisite installation? =
100
- You can run snippets across an entire multisite network by **Network Activating** Code Snippets through the Network Dashboard. You can also activate Code Snippets just on the main site, and then individually on other sites of your choice.
101
-
102
- = Is there anyway to add categories to snippets? =
103
- Users of Code Snippets version 1.7 and later can install the [Code Snippets Tags](http://wordpress.org/plugins/code-snippets-tags) plugin for the ability to add tags to snippets, and then later filter the snippets by tag for easier organization.
104
-
105
- = I need help with Code Snippets =
106
- You can get help with Code Snippets either on the [WordPress Support Forums](http://wordpress.org/support/plugin/code-snippets/), on [GithHub](https://github.com/bungeshea/code-snippets/issues), or on [WordPress Answers](http://wordpress.stackexchange.com).
107
-
108
- = I have an idea for a cool feature for Code Snippets! =
109
- That's great! Let me know by starting (or adding to) a topic in the [Support Forums](http://wordpress.org/support/plugin/code-snippets/) or open an issue on [GitHub](https://github.com/bungeshea/code-snippets/issues).
110
-
111
- = I want to contribute to and help develop the Code Snippets plugin! =
112
- That's fantastic! Join me on [GitHub](https://github.com/bungeshea/code-snippets), and also be sure to check out the [development page](http://code-snippets.bungeshea.com/development/) on the [project website](http://code-snippets.bungeshea.com).
113
-
114
- == Screenshots ==
115
-
116
- 1. Managing existing snippets
117
- 2. Adding a new snippet
118
- 3. Editing a snippet
119
- 4. Importing snippets from an XML file
120
-
121
- == Changelog ==
122
-
123
- = 1.9.1.1
124
- * Add capability check to site snippets importer
125
-
126
- = 1.9.1 =
127
- * Use an icon font for menu icon instead of embedded SVG
128
- * Use Sass (libsass) instead of Compass
129
- * Unminify CodeMirror scripts
130
- * Fixes for the WP 3.8 interface
131
- * Fix 'enable snippets menu for site admins' multisite setting
132
-
133
- = 1.9 =
134
- * Add and remove network capabilities as super admins are added and removed
135
- * Updated MP6 icon implementation
136
- * Replaced buggy trim `<?php` and `?>` functionality with a much more reliable regex method ([#](http://wordpress.org/support/topic/character-gets-cut))
137
- * Added French translation thanks to translator [oWEB](http://office-web.net)
138
- * Fixed snippet failing to save when code contains `%` character, props to [nikan06](http://wordpress.org/support/profile/nikan06) ([#](http://wordpress.org/support/topic/percent-sign-bug))
139
- * Added 'Save & Deactivate' button to the edit snippet page ([#](http://wordpress.org/support/topic/deactivate-button-in-edit-snippet-page))
140
- * Removed edit and install capabilities (now only uses the manage capability)
141
- * Fixed HTML breaking in export files ([#](http://wordpress.org/support/topic/import-problem-7))
142
- * Make the title of each snippet on the manage page a clickable link to edit the snippet ([#](http://wordpress.org/support/topic/deactivate-button-in-edit-snippet-page?replies=9#post-4682757))
143
- * Added nonce to edit snippet page
144
- * Hide row actions on manage snippet page by default
145
- * Removed screenshots from plugin
146
- * Improved CodeMirror implementation
147
- * Added a fallback MP6 icon
148
- * Use the proper WordPress database APIs all of the time
149
- * Rewritten export functionality
150
- * Fixed incorrect export filename
151
- * Updated CodeMirror to version 3.19
152
- * Removed CodeMirror bundled with plugin
153
- * Updated WordPress.org plugin banner
154
- * Fixed CodeMirror incompatibility with the WP Editor plugin
155
- * Fixed CodeMirror incompatibility with the Debug Bar Console plugin
156
-
157
- = 1.8.1 =
158
- * Compiled all CodeMirror scripts into a single file
159
- * Use Sass + Compass for CSS
160
- * Use Grunt for build automation
161
- * Minify CSS
162
- * Fixed code typo that was breaking export files
163
- * Updated CodeMirror to 3.15
164
-
165
- = 1.8 =
166
- * Allow no snippet name or code to be set
167
- * Prevented an error on fresh multisite installations
168
- * Refactored code to use best practices
169
- * Improved database table creation method: on a single-site install, the snippets table will always be created. On a multisite install, the network snippets table will always be created; the site-specific table will always be created for the main site; for sub-sites the snippets table will only be created on a visit to a snippets admin page.
170
- * Updated to CodeMirror 3.14
171
- * Changes to action and filter hook API
172
- * Added error message handling for import snippets page
173
- * Don't encode HTML entities in database
174
-
175
- = 1.7.1.2 =
176
- * Correct path to admin menu icon ([#](http://wordpress.org/support/topic/icon-disappears-with-mp6?replies=6#post-4148319))
177
-
178
- = 1.7.1.1 =
179
- * Fix a minor bug with custom capabilities and admin menus
180
-
181
- = 1.7.1 =
182
- * Fix a bug with snippet being set as deactivated when saved
183
- * Updated PHP Documentation completely. [View online](http://bungeshea.github.io/code-snippets/api)
184
- * Only load admin functions when viewing dashboard
185
- * Added German translation thanks to [David Decker](http://deckerweb.de)
186
- * Allow or deny site administrators access to snippet admin menus. Set your preference in the **Enable Administration Menus** setting under the *Settings > Network Settings* network admin menu.
187
- * Improve database table creation and upgrade process
188
- * Optimized to use less database queries
189
-
190
- = 1.7 =
191
- * Improved plugin API
192
- * Fixed a bug with saving snippets per page option ([#](http://wordpress.org/support/topic/plugin-code-snippets-snippets-per-page-does-not-work#post-3710991))
193
- * Updated CodeMirror to version 3.11
194
- * Allow plugin to be activated on individual sites on multisite ([#](http://wordpress.org/support/topic/dont-work-at-multisite))
195
- * Slimmed down the description visual editor
196
- * Added icon for the new MP6 admin UI ([#](http://wordpress.org/support/topic/icon-disappears-with-mp6))
197
- * Strip PHP tags from the beginning and end of a snippet in case someone forgets
198
- * Changed to [MIT license](http://opensource.org/licenses/mit-license.php)
199
- * Removed HTML, CSS and JavaScript CodeMirror modes that were messing things up
200
- * Made everything leaner, faster, and better
201
-
202
- = 1.6.1 =
203
- * Fixed a bug with permissions not being applied on install ([#](http://wordpress.org/support/topic/permissions-problem-after-install))
204
- * Fixed a bug in the uninstall method ([#](http://wordpress.org/support/topic/bug-in-delete-script))
205
-
206
- = 1.6 =
207
- * Updated code editor to use CodeMirror 3
208
- * Improved compatibility with Clean Options plugin
209
- * Code improvements and optimization
210
- * Changed namespace from `cs` to `code_snippets`
211
- * Move css and js under assets
212
- * Organized CodeMirror scripts
213
- * Improved updating process
214
- * Current line of code editor is now highlighted
215
- * Highlight matches of selected text in code editor
216
- * Only create snippet tables when needed
217
- * Store multisite only options in site options table
218
- * Fixed compatibility bugs with WordPress 3.5
219
-
220
- = 1.5 =
221
- * Updated CodeMirror to version 2.33
222
- * Updated the 'Manage Snippets' page to use the WP_List_Table class
223
- * Added 'Screen Options' tab to 'Manage Snippets' page
224
- * Added search capability to 'Manage Snippets' page
225
- * Added views to easily filter activated, deactivated and recently activated snippets
226
- * Added ID column to 'Manage Snippets' page
227
- * Added sortable name and ID column on 'Manage Snippets' page ([#](http://wordpress.org/support/topic/plugin-code-snippets-suggestion-sort-by-snippet-name))
228
- * Added custom capabilities
229
- * Improved API
230
- * Added 'Export to PHP' feature ([#](http://wordpress.org/support/topic/plugin-code-snippets-suggestion-bulk-export-to-php))
231
- * Lengthened snippet name field to 64 characters ([#](http://wordpress.org/support/topic/plugin-code-snippets-snippet-title-limited-to-36-characters))
232
- * Added i18n
233
-
234
- = 1.4 =
235
- * Added interface to Network Dashboard
236
- * Updated uninstall to support multisite
237
- * Replaced EditArea with [CodeMirror](http://codemirror.net)
238
- * Small improvements
239
-
240
- = 1.3.2 =
241
- * Fixed a bug with version 1.3.1
242
-
243
- = 1.3.1 =
244
- * Changed plugin website URI
245
- * Cleaned up some code
246
-
247
- = 1.3 =
248
- * Added export option to 'Manage Snippets' page
249
- * Added 'Import Snippets' page
250
-
251
- = 1.2 =
252
- * Minor improvements
253
- * Added code highlighting
254
- * Removed 'Uninstall Plugin' page
255
- * Data will now be cleaned up when plugin is deleted through WordPress admin
256
-
257
- = 1.1 =
258
- * Fixed a permissions bug with `DISALLOW_FILE_EDIT` being set to true ([#](http://wordpress.org/support/topic/plugin-code-snippets-cant-add-new))
259
- * Fixed a bug with the page title reading 'Add New Snippet' on the 'Edit Snippets' page
260
- * Fixed a bug not allowing the plugin to be Network Activated ([#](http://wordpress.org/support/topic/plugin-code-snippets-network-activate-does-not-create-snippets-tables))
261
-
262
- = 1.0 =
263
- * Stable version released.
264
-
265
- == Other Notes ==
266
-
267
- Plugin updates will be posted on the [plugin's homepage](http://code-snippets.bungeshea.com/) ([RSS](http://code-snippets.bungeshea.com/feed/)).
268
-
269
- * Snippets are stored in the `wp_snippets` table in the WordPress database (the table name may differ depending on what your table prefix is set to).
270
- * Code Snippets will automatically clean up its data when deleted through the WordPress dashboard.
271
-
272
- == Upgrade Notice ==
273
-
274
- = 1.9.1.1 =
275
- Add capability check to snippets importer
276
-
277
- = 1.9.1 =
278
- UI improvements for WordPress 3.8
279
-
280
- = 1.8.1 =
281
- Minimize CSS and JS; updated CodeMirror; fixed export files
282
-
283
- = 1.8 =
284
- Setting a snippet name and code are now optional; better table creation method; changes to API; bug fixes
285
-
286
- = 1.7.1.2 =
287
- Fixes the admin menu icon not loading
288
-
289
- = 1.7.1.1 =
290
- Fixes a minor bug with custom capabilities and admin menus
291
-
292
- = 1.7.1 =
293
- Added German translation thanks to David Decker; bug fixes and improvements
294
-
295
- = 1.7 =
296
- Many improvements and optimization. Download "Code Snippets Tags" plugin to add tags to snippets
297
-
298
- = 1.6 =
299
- Improvements and optimization with WordPress 3.5
300
-
301
- = 1.5 =
302
- Improvements on the 'Manage Snippets' page and localization
303
-
304
- = 1.4 =
305
- Better code highlighting and improved multisite support
306
-
307
- = 1.3.2 =
308
- Code Snippets has a new website: http://code-snippets.bungeshea.com/
309
-
310
- = 1.3 =
311
- Added import/export feature
312
-
313
- = 1.2 =
314
- Minor improvements |
315
- Added code highlighting |
316
- Plugin data will now be cleaned up when you delete the plugin.
317
-
318
- = 1.1 =
319
- Minor bug fixes and improvements on the the 'Edit Snippet' page
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Code Snippets ===
2
+ Contributors: bungeshea
3
+ Donate link: http://code-snippets.bungeshea.com/donate/
4
+ Tags: code-snippets, snippets, code, php, network, multisite
5
+ Requires at least: 3.3
6
+ Tested up to: 4.1.1
7
+ Stable tag: 2.0
8
+ License: MIT
9
+ License URI: license.txt
10
+
11
+ An easy, clean and simple way to add code snippets to your site.
12
+
13
+ == Description ==
14
+
15
+ **Code Snippets** is an easy, clean and simple way to add code snippets to your site. No need to edit to your theme's `functions.php` file again!
16
+
17
+ A snippet is a small chunk of PHP code that you can use to extend the functionality of a WordPress-powered website; essentially a mini-plugin with a *lot* less load on your site.
18
+ Most snippet-hosting sites tell you to add snippet code to your active theme's `functions.php` file, which can get rather long and messy after a while.
19
+ Code Snippets changes that by providing a GUI interface for adding snippets and **actually running them on your site** as if they were in your theme's `functions.php` file.
20
+
21
+ You can use a graphical interface, similar to the Plugins menu, to manage, activate, deactivate, edit and delete your snippets. Easily organize your snippets by adding a name and description using the visual editor. Code Snippets includes built-in syntax highlighting and other features to help you write your code. Snippets can be exported for transfer to another side, either in XML for later importing by the Code Snippets plugin, or in PHP for creating your own plugin or theme.
22
+
23
+ Although Code Snippets is designed to be easy-to-use and its interface looks, feels and acts as if it was a native part of WordPress, each screen includes a help tab, just in case you get stuck.
24
+
25
+ Further information, documentation and updates are available on the [plugin homepage](http://code-snippets.bungeshea.com). You can also contribute to the code at [GitHub](https://github.com/bungeshea/code-snippets).
26
+
27
+ If you have any feedback, issues, or suggestions for improvements please leave a topic in the [Support Forum](http://wordpress.org/support/plugin/code-snippets). If you like the plugin, or it is useful to you in any way, please review it on [WordPress.org](http://wordpress.org/support/view/plugin-reviews/code-snippets).
28
+
29
+ === Translations ===
30
+
31
+ Code Snippets can be used in these different languages thanks to the following translators:
32
+
33
+ * German - [David Decker](http://deckerweb.de)
34
+ * French - [oWEB](http://office-web.net)
35
+ * Japanese - [mt8](http://mt8.biz/)
36
+ * Serbo-Croatian - [Borisa Djuraskovic from Web Hosting Hub](http://www.webhostinghub.com/)
37
+ * Chinese - [Jincheng Shan](http://shanjincheng.com)
38
+ * Russian - [Alexander Samsonov](http://www.wordpressplugins.ru/administration/code-snippets.html)
39
+ * Slovak - [Ján Fajčák](http://wp.sk)
40
+
41
+ == Installation ==
42
+
43
+ = Automatic installation =
44
+
45
+ 1. Log into your WordPress admin
46
+ 2. Click __Plugins__
47
+ 3. Click __Add New__
48
+ 4. Search for __Code Snippets__
49
+ 5. Click __Install Now__ under "Code Snippets"
50
+ 6. Activate the plugin
51
+
52
+ = Manual installation =
53
+
54
+ 1. Download the plugin
55
+ 2. Extract the contents of the zip file
56
+ 3. Upload the contents of the zip file to the `wp-content/plugins/` folder of your WordPress installation
57
+ 4. Activate the Code Snippets plugin from 'Plugins' page.
58
+
59
+ **Network Activating** Code Snippets through the Network Dashboard will enable a special interface for running snippets across the entire network.
60
+
61
+ == Frequently Asked Questions ==
62
+
63
+ Further documentation is available on the [plugin website](http://code-snippets.bungeshea.com/).
64
+
65
+ = How can I insert my snippet into the post text editor? =
66
+ Snippets that you add to this plugin are not meant to be inserted into the text editor. Instead, they are run on your site just as if they were added to your functions.php file.
67
+
68
+ = Do I need to include the `<?php`, `<?` or `?>` tags in my snippet? =
69
+ No, just copy all the content inside those tags. If you accidentally forget (or just like being lazy), the tags will be stripped from the beginning and end of the snippet when you save it. You can, however, use those tags *inside* your snippets to start and end HTML sections
70
+
71
+ = Help! I just activated a snippet, and my whole site broke! =
72
+ You can try activating 'safe mode'. All snippets will not execute while safe mode is active, allowing you to access your site and deactivate the snippet that is causing the error. To activate safe mode, add the following line to your wp-config.php file, just before the line that reads `/* That's all, stop editing! Happy blogging. */`:
73
+
74
+ define('CODE_SNIPPETS_SAFE_MODE', true);
75
+
76
+ To turn safe mode off, either [comment out](http://php.net/manual/language.basic-syntax.comments.php) this line or delete it.
77
+
78
+ = Is there a way to add a snippet but not run it right away? =
79
+ Yes. Just add it but do not activate it yet.
80
+
81
+ = What do I use to write my snippets? =
82
+ The [CodeMirror](http://codemirror.net) source-code editor will add line numbers, syntax highlighting, bracket matching, search, tabulate and other cool features to the code editor.
83
+
84
+ = Can I preform search and replace commands in the code editor? =
85
+
86
+ * __Ctrl-F / Cmd-F__ : Start searching
87
+ * __Ctrl-G / Cmd-G__ : Find next
88
+ * __Shift-Ctrl-G / Shift-Cmd-G__ : Find previous
89
+ * __Shift-Ctrl-F / Cmd-Option-F__ : Replace
90
+ * __Shift-Ctrl-R / Shift-Cmd-Option-F__ : Replace all
91
+
92
+ = Will I lose my snippets if I change the theme or upgrade WordPress? =
93
+ No, the snippets are stored in the WordPress database and are independent of the theme and unaffected by WordPress upgrades.
94
+
95
+ = Can the plugin be completely uninstalled? =
96
+ Yes, when you delete Code Snippets using the 'Plugins' menu in WordPress it will clean up the database table and a few other bits of data. Be careful not to remove Code Snippets by deleting it from the Plugins menu unless you want this to happen.
97
+
98
+ = Can I copy any snippets I've created to another WordPress site? =
99
+ Yes! You can individually export a single snippet using the link below the snippet name on the 'Manage Snippets' page or bulk export multiple snippets using the 'Bulk Actions' feature. Snippets can later be imported using the 'Import Snippets' page by uploading the export file.
100
+
101
+ = Can I export my snippets to PHP for a site where I'm not using the Code Snippets plugin? =
102
+ Yes. Click the checkboxes next to the snippets you want to export, and then choose **Export to PHP** from the Bulk Actions menu and click Apply. The generated PHP file will contain the exported snippets' code, as well as their name and description in comments.
103
+
104
+ = Can I run network-wide snippets on a multisite installation? =
105
+ You can run snippets across an entire multisite network by **Network Activating** Code Snippets through the Network Dashboard. You can also activate Code Snippets just on the main site, and then individually on other sites of your choice.
106
+
107
+ ## Where are the snippets stored in my WordPress database?
108
+ Snippets are stored in the `wp_snippets` table in the WordPress database. The table name may differ depending on what your table prefix is set to.
109
+
110
+ = I need help with Code Snippets =
111
+ You can get help with Code Snippets either on the [WordPress Support Forums][support], on [GithHub][issues], or on [WordPress Answers](http://wordpress.stackexchange.com).
112
+
113
+ = I have an idea for a cool feature for Code Snippets! =
114
+ That's great! Let me know by starting (or adding to) a topic in the [Support Forums][support] or open an issue on [GitHub][issues].
115
+
116
+ = I want to contribute to and help develop the Code Snippets plugin! =
117
+ That's fantastic! Join me on [GitHub](http://github.com/bungeshea/code-snippets), and also be sure to check out the [development page](http://code-snippets.bungeshea.com/development/) on the [project website](http://code-snippets.bungeshea.com).
118
+
119
+ == Screenshots ==
120
+
121
+ 1. Managing existing snippets
122
+ 2. Adding a new snippet
123
+ 3. Editing a snippet
124
+ 4. Importing snippets from an XML file
125
+
126
+ == Changelog ==
127
+
128
+ = 2.0 =
129
+
130
+ **Highlights:**
131
+
132
+ * Better import/export functionality
133
+ * New settings page with code editor settings
134
+ * Code rewritten for cleaner and more efficient code
135
+ * Lots of new translations
136
+
137
+
138
+ * Removed old admin style support
139
+ * Removed backwards-compatible support
140
+ * Added braces to single-line conditionals in line with [new coding standards](https://make.wordpress.org/core/2013/11/13/proposed-coding-standards-change-always-require-braces/)
141
+ * Split up large classes into separate functions
142
+ * Improved plugin file structure
143
+ * Replaced uninstall hook with single file method
144
+ * Added link to Code Snippets importer under Snippets admin menu
145
+ * Added settings component and admin page
146
+ * Added support for different CodeMirror themes
147
+ * Integrated tags component into main plugin. Current users of the Code Snippets Tags plugin can safely uninstall it.
148
+ * Added Auto Close Brackets CodeMirror addon (props to TronicLabs)
149
+ * Fixed incompatibility errors with PHP 5.2
150
+ * Added Serbo-Croatian translation by Borisa Djuraskovic from [Web Hosting Hub](http://www.webhostinghub.com)
151
+ * Fixed empty MO translation files
152
+ * Added Highlight Selection Matches CodeMirror addon (props to TronicLabs)
153
+ * Added Chinese translation thanks to Jincheng Shan
154
+ * Updated CodeMirror library to version 4.6
155
+ * Added Russian translation by Alexander Samsonov
156
+ * Added Slovak translation by [Ján Fajčák] from [WordPress Slovakia](http://wp.sk)
157
+ * Added setting to always save and activate snippets by default
158
+ * Updated CodeMirror library to version 5.0
159
+ * Rewritten import/export functionality to use DOMDocument
160
+ * Merged Code_Snippets_Export_PHP class into Code_Snippets_Export class
161
+ * Removed duplicate MySQL primary key indexing
162
+
163
+ = 1.9.1.1
164
+ * Add capability check to site snippets importer
165
+
166
+ = 1.9.1 =
167
+ * Use an icon font for menu icon instead of embedded SVG
168
+ * Use Sass (libsass) instead of Compass
169
+ * Unminify CodeMirror scripts
170
+ * Fixes for the WP 3.8 interface
171
+ * Fix 'enable snippets menu for site admins' multisite setting
172
+
173
+ = 1.9 =
174
+ * Add and remove network capabilities as super admins are added and removed
175
+ * Updated MP6 icon implementation
176
+ * Replaced buggy trim `<?php` and `?>` functionality with a much more reliable regex method ([#](http://wordpress.org/support/topic/character-gets-cut))
177
+ * Added French translation thanks to translator [oWEB](http://office-web.net)
178
+ * Fixed snippet failing to save when code contains `%` character, props to [nikan06](http://wordpress.org/support/profile/nikan06) ([#](http://wordpress.org/support/topic/percent-sign-bug))
179
+ * Added 'Save & Deactivate' button to the edit snippet page ([#](http://wordpress.org/support/topic/deactivate-button-in-edit-snippet-page))
180
+ * Removed edit and install capabilities (now only uses the manage capability)
181
+ * Fixed HTML breaking in export files ([#](http://wordpress.org/support/topic/import-problem-7))
182
+ * Make the title of each snippet on the manage page a clickable link to edit the snippet ([#](http://wordpress.org/support/topic/deactivate-button-in-edit-snippet-page?replies=9#post-4682757))
183
+ * Added nonce to edit snippet page
184
+ * Hide row actions on manage snippet page by default
185
+ * Removed screenshots from plugin
186
+ * Improved CodeMirror implementation
187
+ * Added a fallback MP6 icon
188
+ * Use the proper WordPress database APIs all of the time
189
+ * Rewritten export functionality
190
+ * Fixed incorrect export filename
191
+ * Updated CodeMirror to version 3.19
192
+ * Removed CodeMirror bundled with plugin
193
+ * Updated WordPress.org plugin banner
194
+ * Fixed CodeMirror incompatibility with the WP Editor plugin
195
+ * Fixed CodeMirror incompatibility with the Debug Bar Console plugin
196
+
197
+ = 1.8.1 =
198
+ * Compiled all CodeMirror scripts into a single file
199
+ * Use Sass + Compass for CSS
200
+ * Use Grunt for build automation
201
+ * Minify CSS
202
+ * Fixed code typo that was breaking export files
203
+ * Updated CodeMirror to 3.15
204
+
205
+ = 1.8 =
206
+ * Allow no snippet name or code to be set
207
+ * Prevented an error on fresh multisite installations
208
+ * Refactored code to use best practices
209
+ * Improved database table creation method: on a single-site install, the snippets table will always be created. On a multisite install, the network snippets table will always be created; the site-specific table will always be created for the main site; for sub-sites the snippets table will only be created on a visit to a snippets admin page.
210
+ * Updated to CodeMirror 3.14
211
+ * Changes to action and filter hook API
212
+ * Added error message handling for import snippets page
213
+ * Don't encode HTML entities in database
214
+
215
+ = 1.7.1.2 =
216
+ * Correct path to admin menu icon ([#](http://wordpress.org/support/topic/icon-disappears-with-mp6?replies=6#post-4148319))
217
+
218
+ = 1.7.1.1 =
219
+ * Fix a minor bug with custom capabilities and admin menus
220
+
221
+ = 1.7.1 =
222
+ * Fix a bug with snippet being set as deactivated when saved
223
+ * Updated PHP Documentation completely. [View online](http://bungeshea.github.io/code-snippets/api)
224
+ * Only load admin functions when viewing dashboard
225
+ * Added German translation thanks to [David Decker](http://deckerweb.de)
226
+ * Allow or deny site administrators access to snippet admin menus. Set your preference in the **Enable Administration Menus** setting under the *Settings > Network Settings* network admin menu.
227
+ * Improve database table creation and upgrade process
228
+ * Optimized to use less database queries
229
+
230
+ = 1.7 =
231
+ * Improved plugin API
232
+ * Fixed a bug with saving snippets per page option ([#](http://wordpress.org/support/topic/plugin-code-snippets-snippets-per-page-does-not-work#post-3710991))
233
+ * Updated CodeMirror to version 3.11
234
+ * Allow plugin to be activated on individual sites on multisite ([#](http://wordpress.org/support/topic/dont-work-at-multisite))
235
+ * Slimmed down the description visual editor
236
+ * Added icon for the new MP6 admin UI ([#](http://wordpress.org/support/topic/icon-disappears-with-mp6))
237
+ * Strip PHP tags from the beginning and end of a snippet in case someone forgets
238
+ * Changed to [MIT license](http://opensource.org/licenses/mit-license.php)
239
+ * Removed HTML, CSS and JavaScript CodeMirror modes that were messing things up
240
+ * Made everything leaner, faster, and better
241
+
242
+ = 1.6.1 =
243
+ * Fixed a bug with permissions not being applied on install ([#](http://wordpress.org/support/topic/permissions-problem-after-install))
244
+ * Fixed a bug in the uninstall method ([#](http://wordpress.org/support/topic/bug-in-delete-script))
245
+
246
+ = 1.6 =
247
+ * Updated code editor to use CodeMirror 3
248
+ * Improved compatibility with Clean Options plugin
249
+ * Code improvements and optimization
250
+ * Changed namespace from `cs` to `code_snippets`
251
+ * Move css and js under assets
252
+ * Organized CodeMirror scripts
253
+ * Improved updating process
254
+ * Current line of code editor is now highlighted
255
+ * Highlight matches of selected text in code editor
256
+ * Only create snippet tables when needed
257
+ * Store multisite only options in site options table
258
+ * Fixed compatibility bugs with WordPress 3.5
259
+
260
+ = 1.5 =
261
+ * Updated CodeMirror to version 2.33
262
+ * Updated the 'Manage Snippets' page to use the WP_List_Table class
263
+ * Added 'Screen Options' tab to 'Manage Snippets' page
264
+ * Added search capability to 'Manage Snippets' page
265
+ * Added views to easily filter activated, deactivated and recently activated snippets
266
+ * Added ID column to 'Manage Snippets' page
267
+ * Added sortable name and ID column on 'Manage Snippets' page ([#](http://wordpress.org/support/topic/plugin-code-snippets-suggestion-sort-by-snippet-name))
268
+ * Added custom capabilities
269
+ * Improved API
270
+ * Added 'Export to PHP' feature ([#](http://wordpress.org/support/topic/plugin-code-snippets-suggestion-bulk-export-to-php))
271
+ * Lengthened snippet name field to 64 characters ([#](http://wordpress.org/support/topic/plugin-code-snippets-snippet-title-limited-to-36-characters))
272
+ * Added i18n
273
+
274
+ = 1.4 =
275
+ * Added interface to Network Dashboard
276
+ * Updated uninstall to support multisite
277
+ * Replaced EditArea with [CodeMirror](http://codemirror.net)
278
+ * Small improvements
279
+
280
+ = 1.3.2 =
281
+ * Fixed a bug with version 1.3.1
282
+
283
+ = 1.3.1 =
284
+ * Changed plugin website URI
285
+ * Cleaned up some code
286
+
287
+ = 1.3 =
288
+ * Added export option to 'Manage Snippets' page
289
+ * Added 'Import Snippets' page
290
+
291
+ = 1.2 =
292
+ * Minor improvements
293
+ * Added code highlighting
294
+ * Removed 'Uninstall Plugin' page
295
+ * Data will now be cleaned up when plugin is deleted through WordPress admin
296
+
297
+ = 1.1 =
298
+ * Fixed a permissions bug with `DISALLOW_FILE_EDIT` being set to true ([#](http://wordpress.org/support/topic/plugin-code-snippets-cant-add-new))
299
+ * Fixed a bug with the page title reading 'Add New Snippet' on the 'Edit Snippets' page
300
+ * Fixed a bug not allowing the plugin to be Network Activated ([#](http://wordpress.org/support/topic/plugin-code-snippets-network-activate-does-not-create-snippets-tables))
301
+
302
+ = 1.0 =
303
+ * Stable version released.
304
+
305
+ == Upgrade Notice ==
306
+
307
+ = 2.0 =
308
+ Improved import/export; new settings page; improved core code; more translations
309
+
310
+ = 1.9.1.1 =
311
+ Add capability check to snippets importer
312
+
313
+ = 1.9.1 =
314
+ UI improvements for WordPress 3.8
315
+
316
+ = 1.8.1 =
317
+ Minimize CSS and JS; updated CodeMirror; fixed export files
318
+
319
+ = 1.8 =
320
+ Setting a snippet name and code are now optional; better table creation method; changes to API; bug fixes
321
+
322
+ = 1.7.1.2 =
323
+ Fixes the admin menu icon not loading
324
+
325
+ = 1.7.1.1 =
326
+ Fixes a minor bug with custom capabilities and admin menus
327
+
328
+ = 1.7.1 =
329
+ Added German translation thanks to David Decker; bug fixes and improvements
330
+
331
+ = 1.7 =
332
+ Many improvements and optimization. Download "Code Snippets Tags" plugin to add tags to snippets
333
+
334
+ = 1.6 =
335
+ Improvements and optimization with WordPress 3.5
336
+
337
+ = 1.5 =
338
+ Improvements on the 'Manage Snippets' page and localization
339
+
340
+ = 1.4 =
341
+ Better code highlighting and improved multisite support
342
+
343
+ = 1.3.2 =
344
+ Code Snippets has a new website: http://code-snippets.bungeshea.com/
345
+
346
+ = 1.3 =
347
+ Added import/export feature
348
+
349
+ = 1.2 =
350
+ Minor improvements |
351
+ Added code highlighting |
352
+ Plugin data will now be cleaned up when you delete the plugin.
353
+
354
+ = 1.1 =
355
+ Minor bug fixes and improvements on the the 'Edit Snippet' page
uninstall.php ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Cleans up data created by this plugin
5
+ * @package Code_Snippets
6
+ * @since 2.0
7
+ */
8
+
9
+ /* Ensure this plugin is actually being uninstalled */
10
+ if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) {
11
+ exit();
12
+ }
13
+
14
+ /**
15
+ * Clean up data created by this plugin for a single site
16
+ * @since 2.0
17
+ */
18
+ function code_snippets_uninstall_site() {
19
+ global $wpdb;
20
+
21
+ /* Remove snippets database table */
22
+ $wpdb->query( "DROP TABLE IF EXISTS $wpdb->snippets" );
23
+
24
+ /* Remove saved options */
25
+ delete_option( 'code_snippets_version' );
26
+ delete_option( 'recently_activated_snippets' );
27
+
28
+ /* Deregister capabilities */
29
+ $role = get_role( apply_filters( 'code_snippets_role', 'administrator' ) );
30
+ $role->remove_cap( apply_filters( 'code_snippets_cap', 'manage_snippets' ) );
31
+ }
32
+
33
+
34
+ global $wpdb;
35
+
36
+ $wpdb->snippets = $wpdb->prefix . 'snippets';
37
+ $wpdb->ms_snippets = $wpdb->prefix . 'ms_snippets';
38
+
39
+ /* Multisite uninstall */
40
+
41
+ if ( is_multisite() ) {
42
+
43
+ /* Loop through sites */
44
+ $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
45
+
46
+ if ( $blog_ids ) {
47
+
48
+ foreach ( $blog_ids as $blog_id ) {
49
+ switch_to_blog( $blog_id );
50
+ code_snippets_uninstall_site();
51
+ }
52
+
53
+ restore_current_blog();
54
+ }
55
+
56
+ /* Remove multisite snippets database table */
57
+ $wpdb->query( "DROP TABLE IF EXISTS $wpdb->ms_snippets" );
58
+
59
+ /* Remove saved options */
60
+ delete_site_option( 'code_snippets_version' );
61
+ delete_site_option( 'recently_activated_snippets' );
62
+
63
+ /* Remove multisite capabilities */
64
+ $network_cap = apply_filters( 'code_snippets_network_cap', 'manage_network_snippets' );
65
+ $supers = get_super_admins();
66
+
67
+ foreach ( $supers as $admin ) {
68
+ $user = new WP_User( 0, $admin );
69
+ $user->remove_cap( $network_cap );
70
+ }
71
+
72
+ } else {
73
+ code_snippets_uninstall_site();
74
+ }
vendor/codemirror/addon/edit/matchbrackets.js CHANGED
@@ -1,87 +1,120 @@
1
- (function() {
2
- var ie_lt8 = /MSIE \d/.test(navigator.userAgent) &&
3
- (document.documentMode == null || document.documentMode < 8);
4
-
5
- var Pos = CodeMirror.Pos;
6
-
7
- var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"};
8
- function findMatchingBracket(cm, where, strict) {
9
- var state = cm.state.matchBrackets;
10
- var maxScanLen = (state && state.maxScanLineLength) || 10000;
11
- var maxScanLines = (state && state.maxScanLines) || 100;
12
-
13
- var cur = where || cm.getCursor(), line = cm.getLineHandle(cur.line), pos = cur.ch - 1;
14
- var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)];
15
- if (!match) return null;
16
- var forward = match.charAt(1) == ">", d = forward ? 1 : -1;
17
- if (strict && forward != (pos == cur.ch)) return null;
18
- var style = cm.getTokenTypeAt(Pos(cur.line, pos + 1));
19
-
20
- var stack = [line.text.charAt(pos)], re = /[(){}[\]]/;
21
- function scan(line, lineNo, start) {
22
- if (!line.text) return;
23
- var pos = forward ? 0 : line.text.length - 1, end = forward ? line.text.length : -1;
24
- if (line.text.length > maxScanLen) return null;
25
- if (start != null) pos = start + d;
26
- for (; pos != end; pos += d) {
27
- var ch = line.text.charAt(pos);
28
- if (re.test(ch) && cm.getTokenTypeAt(Pos(lineNo, pos + 1)) == style) {
29
- var match = matching[ch];
30
- if (match.charAt(1) == ">" == forward) stack.push(ch);
31
- else if (stack.pop() != match.charAt(0)) return {pos: pos, match: false};
32
- else if (!stack.length) return {pos: pos, match: true};
33
- }
34
- }
35
- }
36
- for (var i = cur.line, found, e = forward ? Math.min(i + maxScanLines, cm.lineCount()) : Math.max(-1, i - maxScanLines); i != e; i+=d) {
37
- if (i == cur.line) found = scan(line, i, pos);
38
- else found = scan(cm.getLineHandle(i), i);
39
- if (found) break;
40
- }
41
- return {from: Pos(cur.line, pos), to: found && Pos(i, found.pos),
42
- match: found && found.match, forward: forward};
43
- }
44
-
45
- function matchBrackets(cm, autoclear) {
46
- // Disable brace matching in long lines, since it'll cause hugely slow updates
47
- var maxHighlightLen = cm.state.matchBrackets.maxHighlightLineLength || 1000;
48
- var found = findMatchingBracket(cm);
49
- if (!found || cm.getLine(found.from.line).length > maxHighlightLen ||
50
- found.to && cm.getLine(found.to.line).length > maxHighlightLen)
51
- return;
52
-
53
- var style = found.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
54
- var one = cm.markText(found.from, Pos(found.from.line, found.from.ch + 1), {className: style});
55
- var two = found.to && cm.markText(found.to, Pos(found.to.line, found.to.ch + 1), {className: style});
56
- // Kludge to work around the IE bug from issue #1193, where text
57
- // input stops going to the textare whever this fires.
58
- if (ie_lt8 && cm.state.focused) cm.display.input.focus();
59
- var clear = function() {
60
- cm.operation(function() { one.clear(); two && two.clear(); });
61
- };
62
- if (autoclear) setTimeout(clear, 800);
63
- else return clear;
64
- }
65
-
66
- var currentlyHighlighted = null;
67
- function doMatchBrackets(cm) {
68
- cm.operation(function() {
69
- if (currentlyHighlighted) {currentlyHighlighted(); currentlyHighlighted = null;}
70
- if (!cm.somethingSelected()) currentlyHighlighted = matchBrackets(cm, false);
71
- });
72
- }
73
-
74
- CodeMirror.defineOption("matchBrackets", false, function(cm, val, old) {
75
- if (old && old != CodeMirror.Init)
76
- cm.off("cursorActivity", doMatchBrackets);
77
- if (val) {
78
- cm.state.matchBrackets = typeof val == "object" ? val : {};
79
- cm.on("cursorActivity", doMatchBrackets);
80
- }
81
- });
82
-
83
- CodeMirror.defineExtension("matchBrackets", function() {matchBrackets(this, true);});
84
- CodeMirror.defineExtension("findMatchingBracket", function(pos, strict){
85
- return findMatchingBracket(this, pos, strict);
86
- });
87
- })();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
4
+ (function(mod) {
5
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
6
+ mod(require("../../lib/codemirror"));
7
+ else if (typeof define == "function" && define.amd) // AMD
8
+ define(["../../lib/codemirror"], mod);
9
+ else // Plain browser env
10
+ mod(CodeMirror);
11
+ })(function(CodeMirror) {
12
+ var ie_lt8 = /MSIE \d/.test(navigator.userAgent) &&
13
+ (document.documentMode == null || document.documentMode < 8);
14
+
15
+ var Pos = CodeMirror.Pos;
16
+
17
+ var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"};
18
+
19
+ function findMatchingBracket(cm, where, strict, config) {
20
+ var line = cm.getLineHandle(where.line), pos = where.ch - 1;
21
+ var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)];
22
+ if (!match) return null;
23
+ var dir = match.charAt(1) == ">" ? 1 : -1;
24
+ if (strict && (dir > 0) != (pos == where.ch)) return null;
25
+ var style = cm.getTokenTypeAt(Pos(where.line, pos + 1));
26
+
27
+ var found = scanForBracket(cm, Pos(where.line, pos + (dir > 0 ? 1 : 0)), dir, style || null, config);
28
+ if (found == null) return null;
29
+ return {from: Pos(where.line, pos), to: found && found.pos,
30
+ match: found && found.ch == match.charAt(0), forward: dir > 0};
31
+ }
32
+
33
+ // bracketRegex is used to specify which type of bracket to scan
34
+ // should be a regexp, e.g. /[[\]]/
35
+ //
36
+ // Note: If "where" is on an open bracket, then this bracket is ignored.
37
+ //
38
+ // Returns false when no bracket was found, null when it reached
39
+ // maxScanLines and gave up
40
+ function scanForBracket(cm, where, dir, style, config) {
41
+ var maxScanLen = (config && config.maxScanLineLength) || 10000;
42
+ var maxScanLines = (config && config.maxScanLines) || 1000;
43
+
44
+ var stack = [];
45
+ var re = config && config.bracketRegex ? config.bracketRegex : /[(){}[\]]/;
46
+ var lineEnd = dir > 0 ? Math.min(where.line + maxScanLines, cm.lastLine() + 1)
47
+ : Math.max(cm.firstLine() - 1, where.line - maxScanLines);
48
+ for (var lineNo = where.line; lineNo != lineEnd; lineNo += dir) {
49
+ var line = cm.getLine(lineNo);
50
+ if (!line) continue;
51
+ var pos = dir > 0 ? 0 : line.length - 1, end = dir > 0 ? line.length : -1;
52
+ if (line.length > maxScanLen) continue;
53
+ if (lineNo == where.line) pos = where.ch - (dir < 0 ? 1 : 0);
54
+ for (; pos != end; pos += dir) {
55
+ var ch = line.charAt(pos);
56
+ if (re.test(ch) && (style === undefined || cm.getTokenTypeAt(Pos(lineNo, pos + 1)) == style)) {
57
+ var match = matching[ch];
58
+ if ((match.charAt(1) == ">") == (dir > 0)) stack.push(ch);
59
+ else if (!stack.length) return {pos: Pos(lineNo, pos), ch: ch};
60
+ else stack.pop();
61
+ }
62
+ }
63
+ }
64
+ return lineNo - dir == (dir > 0 ? cm.lastLine() : cm.firstLine()) ? false : null;
65
+ }
66
+
67
+ function matchBrackets(cm, autoclear, config) {
68
+ // Disable brace matching in long lines, since it'll cause hugely slow updates
69
+ var maxHighlightLen = cm.state.matchBrackets.maxHighlightLineLength || 1000;
70
+ var marks = [], ranges = cm.listSelections();
71
+ for (var i = 0; i < ranges.length; i++) {
72
+ var match = ranges[i].empty() && findMatchingBracket(cm, ranges[i].head, false, config);
73
+ if (match && cm.getLine(match.from.line).length <= maxHighlightLen) {
74
+ var style = match.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
75
+ marks.push(cm.markText(match.from, Pos(match.from.line, match.from.ch + 1), {className: style}));
76
+ if (match.to && cm.getLine(match.to.line).length <= maxHighlightLen)
77
+ marks.push(cm.markText(match.to, Pos(match.to.line, match.to.ch + 1), {className: style}));
78
+ }
79
+ }
80
+
81
+ if (marks.length) {
82
+ // Kludge to work around the IE bug from issue #1193, where text
83
+ // input stops going to the textare whever this fires.
84
+ if (ie_lt8 && cm.state.focused) cm.display.input.focus();
85
+
86
+ var clear = function() {
87
+ cm.operation(function() {
88
+ for (var i = 0; i < marks.length; i++) marks[i].clear();
89
+ });
90
+ };
91
+ if (autoclear) setTimeout(clear, 800);
92
+ else return clear;
93
+ }
94
+ }
95
+
96
+ var currentlyHighlighted = null;
97
+ function doMatchBrackets(cm) {
98
+ cm.operation(function() {
99
+ if (currentlyHighlighted) {currentlyHighlighted(); currentlyHighlighted = null;}
100
+ currentlyHighlighted = matchBrackets(cm, false, cm.state.matchBrackets);
101
+ });
102
+ }
103
+
104
+ CodeMirror.defineOption("matchBrackets", false, function(cm, val, old) {
105
+ if (old && old != CodeMirror.Init)
106
+ cm.off("cursorActivity", doMatchBrackets);
107
+ if (val) {
108
+ cm.state.matchBrackets = typeof val == "object" ? val : {};
109
+ cm.on("cursorActivity", doMatchBrackets);
110
+ }
111
+ });
112
+
113
+ CodeMirror.defineExtension("matchBrackets", function() {matchBrackets(this, true);});
114
+ CodeMirror.defineExtension("findMatchingBracket", function(pos, strict, config){
115
+ return findMatchingBracket(this, pos, strict, config);
116
+ });
117
+ CodeMirror.defineExtension("scanForBracket", function(pos, dir, style, config){
118
+ return scanForBracket(this, pos, dir, style, config);
119
+ });
120
+ });
vendor/codemirror/addon/search/search.js CHANGED
@@ -1,133 +1,164 @@
1
- // Define search commands. Depends on dialog.js or another
2
- // implementation of the openDialog method.
3
-
4
- // Replace works a little oddly -- it will do the replace on the next
5
- // Ctrl-G (or whatever is bound to findNext) press. You prevent a
6
- // replace by making sure the match is no longer selected when hitting
7
- // Ctrl-G.
8
-
9
- (function() {
10
- function searchOverlay(query) {
11
- if (typeof query == "string") return {token: function(stream) {
12
- if (stream.match(query)) return "searching";
13
- stream.next();
14
- stream.skipTo(query.charAt(0)) || stream.skipToEnd();
15
- }};
16
- return {token: function(stream) {
17
- if (stream.match(query)) return "searching";
18
- while (!stream.eol()) {
19
- stream.next();
20
- if (stream.match(query, false)) break;
21
- }
22
- }};
23
- }
24
-
25
- function SearchState() {
26
- this.posFrom = this.posTo = this.query = null;
27
- this.overlay = null;
28
- }
29
- function getSearchState(cm) {
30
- return cm.state.search || (cm.state.search = new SearchState());
31
- }
32
- function getSearchCursor(cm, query, pos) {
33
- // Heuristic: if the query string is all lowercase, do a case insensitive search.
34
- return cm.getSearchCursor(query, pos, typeof query == "string" && query == query.toLowerCase());
35
- }
36
- function dialog(cm, text, shortText, f) {
37
- if (cm.openDialog) cm.openDialog(text, f);
38
- else f(prompt(shortText, ""));
39
- }
40
- function confirmDialog(cm, text, shortText, fs) {
41
- if (cm.openConfirm) cm.openConfirm(text, fs);
42
- else if (confirm(shortText)) fs[0]();
43
- }
44
- function parseQuery(query) {
45
- var isRE = query.match(/^\/(.*)\/([a-z]*)$/);
46
- return isRE ? new RegExp(isRE[1], isRE[2].indexOf("i") == -1 ? "" : "i") : query;
47
- }
48
- var queryDialog =
49
- 'Search: <input type="text" style="width: 10em"/> <span style="color: #888">(Use /re/ syntax for regexp search)</span>';
50
- function doSearch(cm, rev) {
51
- var state = getSearchState(cm);
52
- if (state.query) return findNext(cm, rev);
53
- dialog(cm, queryDialog, "Search for:", function(query) {
54
- cm.operation(function() {
55
- if (!query || state.query) return;
56
- state.query = parseQuery(query);
57
- cm.removeOverlay(state.overlay);
58
- state.overlay = searchOverlay(state.query);
59
- cm.addOverlay(state.overlay);
60
- state.posFrom = state.posTo = cm.getCursor();
61
- findNext(cm, rev);
62
- });
63
- });
64
- }
65
- function findNext(cm, rev) {cm.operation(function() {
66
- var state = getSearchState(cm);
67
- var cursor = getSearchCursor(cm, state.query, rev ? state.posFrom : state.posTo);
68
- if (!cursor.find(rev)) {
69
- cursor = getSearchCursor(cm, state.query, rev ? CodeMirror.Pos(cm.lastLine()) : CodeMirror.Pos(cm.firstLine(), 0));
70
- if (!cursor.find(rev)) return;
71
- }
72
- cm.setSelection(cursor.from(), cursor.to());
73
- cm.scrollIntoView({from: cursor.from(), to: cursor.to()});
74
- state.posFrom = cursor.from(); state.posTo = cursor.to();
75
- });}
76
- function clearSearch(cm) {cm.operation(function() {
77
- var state = getSearchState(cm);
78
- if (!state.query) return;
79
- state.query = null;
80
- cm.removeOverlay(state.overlay);
81
- });}
82
-
83
- var replaceQueryDialog =
84
- 'Replace: <input type="text" style="width: 10em"/> <span style="color: #888">(Use /re/ syntax for regexp search)</span>';
85
- var replacementQueryDialog = 'With: <input type="text" style="width: 10em"/>';
86
- var doReplaceConfirm = "Replace? <button>Yes</button> <button>No</button> <button>Stop</button>";
87
- function replace(cm, all) {
88
- dialog(cm, replaceQueryDialog, "Replace:", function(query) {
89
- if (!query) return;
90
- query = parseQuery(query);
91
- dialog(cm, replacementQueryDialog, "Replace with:", function(text) {
92
- if (all) {
93
- cm.operation(function() {
94
- for (var cursor = getSearchCursor(cm, query); cursor.findNext();) {
95
- if (typeof query != "string") {
96
- var match = cm.getRange(cursor.from(), cursor.to()).match(query);
97
- cursor.replace(text.replace(/\$(\d)/, function(_, i) {return match[i];}));
98
- } else cursor.replace(text);
99
- }
100
- });
101
- } else {
102
- clearSearch(cm);
103
- var cursor = getSearchCursor(cm, query, cm.getCursor());
104
- var advance = function() {
105
- var start = cursor.from(), match;
106
- if (!(match = cursor.findNext())) {
107
- cursor = getSearchCursor(cm, query);
108
- if (!(match = cursor.findNext()) ||
109
- (start && cursor.from().line == start.line && cursor.from().ch == start.ch)) return;
110
- }
111
- cm.setSelection(cursor.from(), cursor.to());
112
- cm.scrollIntoView({from: cursor.from(), to: cursor.to()});
113
- confirmDialog(cm, doReplaceConfirm, "Replace?",
114
- [function() {doReplace(match);}, advance]);
115
- };
116
- var doReplace = function(match) {
117
- cursor.replace(typeof query == "string" ? text :
118
- text.replace(/\$(\d)/, function(_, i) {return match[i];}));
119
- advance();
120
- };
121
- advance();
122
- }
123
- });
124
- });
125
- }
126
-
127
- CodeMirror.commands.find = function(cm) {clearSearch(cm); doSearch(cm);};
128
- CodeMirror.commands.findNext = doSearch;
129
- CodeMirror.commands.findPrev = function(cm) {doSearch(cm, true);};
130
- CodeMirror.commands.clearSearch = clearSearch;
131
- CodeMirror.commands.replace = replace;
132
- CodeMirror.commands.replaceAll = function(cm) {replace(cm, true);};
133
- })();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
4
+ // Define search commands. Depends on dialog.js or another
5
+ // implementation of the openDialog method.
6
+
7
+ // Replace works a little oddly -- it will do the replace on the next
8
+ // Ctrl-G (or whatever is bound to findNext) press. You prevent a
9
+ // replace by making sure the match is no longer selected when hitting
10
+ // Ctrl-G.
11
+
12
+ (function(mod) {
13
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
14
+ mod(require("../../lib/codemirror"), require("./searchcursor"), require("../dialog/dialog"));
15
+ else if (typeof define == "function" && define.amd) // AMD
16
+ define(["../../lib/codemirror", "./searchcursor", "../dialog/dialog"], mod);
17
+ else // Plain browser env
18
+ mod(CodeMirror);
19
+ })(function(CodeMirror) {
20
+ "use strict";
21
+ function searchOverlay(query, caseInsensitive) {
22
+ if (typeof query == "string")
23
+ query = new RegExp(query.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"), caseInsensitive ? "gi" : "g");
24
+ else if (!query.global)
25
+ query = new RegExp(query.source, query.ignoreCase ? "gi" : "g");
26
+
27
+ return {token: function(stream) {
28
+ query.lastIndex = stream.pos;
29
+ var match = query.exec(stream.string);
30
+ if (match && match.index == stream.pos) {
31
+ stream.pos += match[0].length;
32
+ return "searching";
33
+ } else if (match) {
34
+ stream.pos = match.index;
35
+ } else {
36
+ stream.skipToEnd();
37
+ }
38
+ }};
39
+ }
40
+
41
+ function SearchState() {
42
+ this.posFrom = this.posTo = this.query = null;
43
+ this.overlay = null;
44
+ }
45
+ function getSearchState(cm) {
46
+ return cm.state.search || (cm.state.search = new SearchState());
47
+ }
48
+ function queryCaseInsensitive(query) {
49
+ return typeof query == "string" && query == query.toLowerCase();
50
+ }
51
+ function getSearchCursor(cm, query, pos) {
52
+ // Heuristic: if the query string is all lowercase, do a case insensitive search.
53
+ return cm.getSearchCursor(query, pos, queryCaseInsensitive(query));
54
+ }
55
+ function dialog(cm, text, shortText, deflt, f) {
56
+ if (cm.openDialog) cm.openDialog(text, f, {value: deflt});
57
+ else f(prompt(shortText, deflt));
58
+ }
59
+ function confirmDialog(cm, text, shortText, fs) {
60
+ if (cm.openConfirm) cm.openConfirm(text, fs);
61
+ else if (confirm(shortText)) fs[0]();
62
+ }
63
+ function parseQuery(query) {
64
+ var isRE = query.match(/^\/(.*)\/([a-z]*)$/);
65
+ if (isRE) {
66
+ try { query = new RegExp(isRE[1], isRE[2].indexOf("i") == -1 ? "" : "i"); }
67
+ catch(e) {} // Not a regular expression after all, do a string search
68
+ }
69
+ if (typeof query == "string" ? query == "" : query.test(""))
70
+ query = /x^/;
71
+ return query;
72
+ }
73
+ var queryDialog =
74
+ 'Search: <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">(Use /re/ syntax for regexp search)</span>';
75
+ function doSearch(cm, rev) {
76
+ var state = getSearchState(cm);
77
+ if (state.query) return findNext(cm, rev);
78
+ dialog(cm, queryDialog, "Search for:", cm.getSelection(), function(query) {
79
+ cm.operation(function() {
80
+ if (!query || state.query) return;
81
+ state.query = parseQuery(query);
82
+ cm.removeOverlay(state.overlay, queryCaseInsensitive(state.query));
83
+ state.overlay = searchOverlay(state.query, queryCaseInsensitive(state.query));
84
+ cm.addOverlay(state.overlay);
85
+ if (cm.showMatchesOnScrollbar) {
86
+ if (state.annotate) { state.annotate.clear(); state.annotate = null; }
87
+ state.annotate = cm.showMatchesOnScrollbar(state.query, queryCaseInsensitive(state.query));
88
+ }
89
+ state.posFrom = state.posTo = cm.getCursor();
90
+ findNext(cm, rev);
91
+ });
92
+ });
93
+ }
94
+ function findNext(cm, rev) {cm.operation(function() {
95
+ var state = getSearchState(cm);
96
+ var cursor = getSearchCursor(cm, state.query, rev ? state.posFrom : state.posTo);
97
+ if (!cursor.find(rev)) {
98
+ cursor = getSearchCursor(cm, state.query, rev ? CodeMirror.Pos(cm.lastLine()) : CodeMirror.Pos(cm.firstLine(), 0));
99
+ if (!cursor.find(rev)) return;
100
+ }
101
+ cm.setSelection(cursor.from(), cursor.to());
102
+ cm.scrollIntoView({from: cursor.from(), to: cursor.to()});
103
+ state.posFrom = cursor.from(); state.posTo = cursor.to();
104
+ });}
105
+ function clearSearch(cm) {cm.operation(function() {
106
+ var state = getSearchState(cm);
107
+ if (!state.query) return;
108
+ state.query = null;
109
+ cm.removeOverlay(state.overlay);
110
+ if (state.annotate) { state.annotate.clear(); state.annotate = null; }
111
+ });}
112
+
113
+ var replaceQueryDialog =
114
+ 'Replace: <input type="text" style="width: 10em" class="CodeMirror-search-field"/> <span style="color: #888" class="CodeMirror-search-hint">(Use /re/ syntax for regexp search)</span>';
115
+ var replacementQueryDialog = 'With: <input type="text" style="width: 10em" class="CodeMirror-search-field"/>';
116
+ var doReplaceConfirm = "Replace? <button>Yes</button> <button>No</button> <button>Stop</button>";
117
+ function replace(cm, all) {
118
+ if (cm.getOption("readOnly")) return;
119
+ dialog(cm, replaceQueryDialog, "Replace:", cm.getSelection(), function(query) {
120
+ if (!query) return;
121
+ query = parseQuery(query);
122
+ dialog(cm, replacementQueryDialog, "Replace with:", "", function(text) {
123
+ if (all) {
124
+ cm.operation(function() {
125
+ for (var cursor = getSearchCursor(cm, query); cursor.findNext();) {
126
+ if (typeof query != "string") {
127
+ var match = cm.getRange(cursor.from(), cursor.to()).match(query);
128
+ cursor.replace(text.replace(/\$(\d)/g, function(_, i) {return match[i];}));
129
+ } else cursor.replace(text);
130
+ }
131
+ });
132
+ } else {
133
+ clearSearch(cm);
134
+ var cursor = getSearchCursor(cm, query, cm.getCursor());
135
+ var advance = function() {
136
+ var start = cursor.from(), match;
137
+ if (!(match = cursor.findNext())) {
138
+ cursor = getSearchCursor(cm, query);
139
+ if (!(match = cursor.findNext()) ||
140
+ (start && cursor.from().line == start.line && cursor.from().ch == start.ch)) return;
141
+ }
142
+ cm.setSelection(cursor.from(), cursor.to());
143
+ cm.scrollIntoView({from: cursor.from(), to: cursor.to()});
144
+ confirmDialog(cm, doReplaceConfirm, "Replace?",
145
+ [function() {doReplace(match);}, advance]);
146
+ };
147
+ var doReplace = function(match) {
148
+ cursor.replace(typeof query == "string" ? text :
149
+ text.replace(/\$(\d)/g, function(_, i) {return match[i];}));
150
+ advance();
151
+ };
152
+ advance();
153
+ }
154
+ });
155
+ });
156
+ }
157
+
158
+ CodeMirror.commands.find = function(cm) {clearSearch(cm); doSearch(cm);};
159
+ CodeMirror.commands.findNext = doSearch;
160
+ CodeMirror.commands.findPrev = function(cm) {doSearch(cm, true);};
161
+ CodeMirror.commands.clearSearch = clearSearch;
162
+ CodeMirror.commands.replace = replace;
163
+ CodeMirror.commands.replaceAll = function(cm) {replace(cm, true);};
164
+ });
vendor/codemirror/addon/search/searchcursor.js CHANGED
@@ -1,143 +1,189 @@
1
- (function(){
2
- var Pos = CodeMirror.Pos;
3
-
4
- function SearchCursor(doc, query, pos, caseFold) {
5
- this.atOccurrence = false; this.doc = doc;
6
- if (caseFold == null && typeof query == "string") caseFold = false;
7
-
8
- pos = pos ? doc.clipPos(pos) : Pos(0, 0);
9
- this.pos = {from: pos, to: pos};
10
-
11
- // The matches method is filled in based on the type of query.
12
- // It takes a position and a direction, and returns an object
13
- // describing the next occurrence of the query, or null if no
14
- // more matches were found.
15
- if (typeof query != "string") { // Regexp match
16
- if (!query.global) query = new RegExp(query.source, query.ignoreCase ? "ig" : "g");
17
- this.matches = function(reverse, pos) {
18
- if (reverse) {
19
- query.lastIndex = 0;
20
- var line = doc.getLine(pos.line).slice(0, pos.ch), cutOff = 0, match, start;
21
- for (;;) {
22
- query.lastIndex = cutOff;
23
- var newMatch = query.exec(line);
24
- if (!newMatch) break;
25
- match = newMatch;
26
- start = match.index;
27
- cutOff = match.index + (match[0].length || 1);
28
- if (cutOff == line.length) break;
29
- }
30
- var matchLen = (match && match[0].length) || 0;
31
- if (!matchLen) {
32
- if (start == 0 && line.length == 0) {match = undefined;}
33
- else if (start != doc.getLine(pos.line).length) {
34
- matchLen++;
35
- }
36
- }
37
- } else {
38
- query.lastIndex = pos.ch;
39
- var line = doc.getLine(pos.line), match = query.exec(line);
40
- var matchLen = (match && match[0].length) || 0;
41
- var start = match && match.index;
42
- if (start + matchLen != line.length && !matchLen) matchLen = 1;
43
- }
44
- if (match && matchLen)
45
- return {from: Pos(pos.line, start),
46
- to: Pos(pos.line, start + matchLen),
47
- match: match};
48
- };
49
- } else { // String query
50
- if (caseFold) query = query.toLowerCase();
51
- var fold = caseFold ? function(str){return str.toLowerCase();} : function(str){return str;};
52
- var target = query.split("\n");
53
- // Different methods for single-line and multi-line queries
54
- if (target.length == 1) {
55
- if (!query.length) {
56
- // Empty string would match anything and never progress, so
57
- // we define it to match nothing instead.
58
- this.matches = function() {};
59
- } else {
60
- this.matches = function(reverse, pos) {
61
- var line = fold(doc.getLine(pos.line)), len = query.length, match;
62
- if (reverse ? (pos.ch >= len && (match = line.lastIndexOf(query, pos.ch - len)) != -1)
63
- : (match = line.indexOf(query, pos.ch)) != -1)
64
- return {from: Pos(pos.line, match),
65
- to: Pos(pos.line, match + len)};
66
- };
67
- }
68
- } else {
69
- this.matches = function(reverse, pos) {
70
- var ln = pos.line, idx = (reverse ? target.length - 1 : 0), match = target[idx], line = fold(doc.getLine(ln));
71
- var offsetA = (reverse ? line.indexOf(match) + match.length : line.lastIndexOf(match));
72
- if (reverse ? offsetA > pos.ch || offsetA != match.length
73
- : offsetA < pos.ch || offsetA != line.length - match.length)
74
- return;
75
- for (;;) {
76
- if (reverse ? !ln : ln == doc.lineCount() - 1) return;
77
- line = fold(doc.getLine(ln += reverse ? -1 : 1));
78
- match = target[reverse ? --idx : ++idx];
79
- if (idx > 0 && idx < target.length - 1) {
80
- if (line != match) return;
81
- else continue;
82
- }
83
- var offsetB = (reverse ? line.lastIndexOf(match) : line.indexOf(match) + match.length);
84
- if (reverse ? offsetB != line.length - match.length : offsetB != match.length)
85
- return;
86
- var start = Pos(pos.line, offsetA), end = Pos(ln, offsetB);
87
- return {from: reverse ? end : start, to: reverse ? start : end};
88
- }
89
- };
90
- }
91
- }
92
- }
93
-
94
- SearchCursor.prototype = {
95
- findNext: function() {return this.find(false);},
96
- findPrevious: function() {return this.find(true);},
97
-
98
- find: function(reverse) {
99
- var self = this, pos = this.doc.clipPos(reverse ? this.pos.from : this.pos.to);
100
- function savePosAndFail(line) {
101
- var pos = Pos(line, 0);
102
- self.pos = {from: pos, to: pos};
103
- self.atOccurrence = false;
104
- return false;
105
- }
106
-
107
- for (;;) {
108
- if (this.pos = this.matches(reverse, pos)) {
109
- if (!this.pos.from || !this.pos.to) { console.log(this.matches, this.pos); }
110
- this.atOccurrence = true;
111
- return this.pos.match || true;
112
- }
113
- if (reverse) {
114
- if (!pos.line) return savePosAndFail(0);
115
- pos = Pos(pos.line-1, this.doc.getLine(pos.line-1).length);
116
- }
117
- else {
118
- var maxLine = this.doc.lineCount();
119
- if (pos.line == maxLine - 1) return savePosAndFail(maxLine);
120
- pos = Pos(pos.line + 1, 0);
121
- }
122
- }
123
- },
124
-
125
- from: function() {if (this.atOccurrence) return this.pos.from;},
126
- to: function() {if (this.atOccurrence) return this.pos.to;},
127
-
128
- replace: function(newText) {
129
- if (!this.atOccurrence) return;
130
- var lines = CodeMirror.splitLines(newText);
131
- this.doc.replaceRange(lines, this.pos.from, this.pos.to);
132
- this.pos.to = Pos(this.pos.from.line + lines.length - 1,
133
- lines[lines.length - 1].length + (lines.length == 1 ? this.pos.from.ch : 0));
134
- }
135
- };
136
-
137
- CodeMirror.defineExtension("getSearchCursor", function(query, pos, caseFold) {
138
- return new SearchCursor(this.doc, query, pos, caseFold);
139
- });
140
- CodeMirror.defineDocExtension("getSearchCursor", function(query, pos, caseFold) {
141
- return new SearchCursor(this, query, pos, caseFold);
142
- });
143
- })();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
4
+ (function(mod) {
5
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
6
+ mod(require("../../lib/codemirror"));
7
+ else if (typeof define == "function" && define.amd) // AMD
8
+ define(["../../lib/codemirror"], mod);
9
+ else // Plain browser env
10
+ mod(CodeMirror);
11
+ })(function(CodeMirror) {
12
+ "use strict";
13
+ var Pos = CodeMirror.Pos;
14
+
15
+ function SearchCursor(doc, query, pos, caseFold) {
16
+ this.atOccurrence = false; this.doc = doc;
17
+ if (caseFold == null && typeof query == "string") caseFold = false;
18
+
19
+ pos = pos ? doc.clipPos(pos) : Pos(0, 0);
20
+ this.pos = {from: pos, to: pos};
21
+
22
+ // The matches method is filled in based on the type of query.
23
+ // It takes a position and a direction, and returns an object
24
+ // describing the next occurrence of the query, or null if no
25
+ // more matches were found.
26
+ if (typeof query != "string") { // Regexp match
27
+ if (!query.global) query = new RegExp(query.source, query.ignoreCase ? "ig" : "g");
28
+ this.matches = function(reverse, pos) {
29
+ if (reverse) {
30
+ query.lastIndex = 0;
31
+ var line = doc.getLine(pos.line).slice(0, pos.ch), cutOff = 0, match, start;
32
+ for (;;) {
33
+ query.lastIndex = cutOff;
34
+ var newMatch = query.exec(line);
35
+ if (!newMatch) break;
36
+ match = newMatch;
37
+ start = match.index;
38
+ cutOff = match.index + (match[0].length || 1);
39
+ if (cutOff == line.length) break;
40
+ }
41
+ var matchLen = (match && match[0].length) || 0;
42
+ if (!matchLen) {
43
+ if (start == 0 && line.length == 0) {match = undefined;}
44
+ else if (start != doc.getLine(pos.line).length) {
45
+ matchLen++;
46
+ }
47
+ }
48
+ } else {
49
+ query.lastIndex = pos.ch;
50
+ var line = doc.getLine(pos.line), match = query.exec(line);
51
+ var matchLen = (match && match[0].length) || 0;
52
+ var start = match && match.index;
53
+ if (start + matchLen != line.length && !matchLen) matchLen = 1;
54
+ }
55
+ if (match && matchLen)
56
+ return {from: Pos(pos.line, start),
57
+ to: Pos(pos.line, start + matchLen),
58
+ match: match};
59
+ };
60
+ } else { // String query
61
+ var origQuery = query;
62
+ if (caseFold) query = query.toLowerCase();
63
+ var fold = caseFold ? function(str){return str.toLowerCase();} : function(str){return str;};
64
+ var target = query.split("\n");
65
+ // Different methods for single-line and multi-line queries
66
+ if (target.length == 1) {
67
+ if (!query.length) {
68
+ // Empty string would match anything and never progress, so
69
+ // we define it to match nothing instead.
70
+ this.matches = function() {};
71
+ } else {
72
+ this.matches = function(reverse, pos) {
73
+ if (reverse) {
74
+ var orig = doc.getLine(pos.line).slice(0, pos.ch), line = fold(orig);
75
+ var match = line.lastIndexOf(query);
76
+ if (match > -1) {
77
+ match = adjustPos(orig, line, match);
78
+ return {from: Pos(pos.line, match), to: Pos(pos.line, match + origQuery.length)};
79
+ }
80
+ } else {
81
+ var orig = doc.getLine(pos.line).slice(pos.ch), line = fold(orig);
82
+ var match = line.indexOf(query);
83
+ if (match > -1) {
84
+ match = adjustPos(orig, line, match) + pos.ch;
85
+ return {from: Pos(pos.line, match), to: Pos(pos.line, match + origQuery.length)};
86
+ }
87
+ }
88
+ };
89
+ }
90
+ } else {
91
+ var origTarget = origQuery.split("\n");
92
+ this.matches = function(reverse, pos) {
93
+ var last = target.length - 1;
94
+ if (reverse) {
95
+ if (pos.line - (target.length - 1) < doc.firstLine()) return;
96
+ if (fold(doc.getLine(pos.line).slice(0, origTarget[last].length)) != target[target.length - 1]) return;
97
+ var to = Pos(pos.line, origTarget[last].length);
98
+ for (var ln = pos.line - 1, i = last - 1; i >= 1; --i, --ln)
99
+ if (target[i] != fold(doc.getLine(ln))) return;
100
+ var line = doc.getLine(ln), cut = line.length - origTarget[0].length;
101
+ if (fold(line.slice(cut)) != target[0]) return;
102
+ return {from: Pos(ln, cut), to: to};
103
+ } else {
104
+ if (pos.line + (target.length - 1) > doc.lastLine()) return;
105
+ var line = doc.getLine(pos.line), cut = line.length - origTarget[0].length;
106
+ if (fold(line.slice(cut)) != target[0]) return;
107
+ var from = Pos(pos.line, cut);
108
+ for (var ln = pos.line + 1, i = 1; i < last; ++i, ++ln)
109
+ if (target[i] != fold(doc.getLine(ln))) return;
110
+ if (fold(doc.getLine(ln).slice(0, origTarget[last].length)) != target[last]) return;
111
+ return {from: from, to: Pos(ln, origTarget[last].length)};
112
+ }
113
+ };
114
+ }
115
+ }
116
+ }
117
+
118
+ SearchCursor.prototype = {
119
+ findNext: function() {return this.find(false);},
120
+ findPrevious: function() {return this.find(true);},
121
+
122
+ find: function(reverse) {
123
+ var self = this, pos = this.doc.clipPos(reverse ? this.pos.from : this.pos.to);
124
+ function savePosAndFail(line) {
125
+ var pos = Pos(line, 0);
126
+ self.pos = {from: pos, to: pos};
127
+ self.atOccurrence = false;
128
+ return false;
129
+ }
130
+
131
+ for (;;) {
132
+ if (this.pos = this.matches(reverse, pos)) {
133
+ this.atOccurrence = true;
134
+ return this.pos.match || true;
135
+ }
136
+ if (reverse) {
137
+ if (!pos.line) return savePosAndFail(0);
138
+ pos = Pos(pos.line-1, this.doc.getLine(pos.line-1).length);
139
+ }
140
+ else {
141
+ var maxLine = this.doc.lineCount();
142
+ if (pos.line == maxLine - 1) return savePosAndFail(maxLine);
143
+ pos = Pos(pos.line + 1, 0);
144
+ }
145
+ }
146
+ },
147
+
148
+ from: function() {if (this.atOccurrence) return this.pos.from;},
149
+ to: function() {if (this.atOccurrence) return this.pos.to;},
150
+
151
+ replace: function(newText) {
152
+ if (!this.atOccurrence) return;
153
+ var lines = CodeMirror.splitLines(newText);
154
+ this.doc.replaceRange(lines, this.pos.from, this.pos.to);
155
+ this.pos.to = Pos(this.pos.from.line + lines.length - 1,
156
+ lines[lines.length - 1].length + (lines.length == 1 ? this.pos.from.ch : 0));
157
+ }
158
+ };
159
+
160
+ // Maps a position in a case-folded line back to a position in the original line
161
+ // (compensating for codepoints increasing in number during folding)
162
+ function adjustPos(orig, folded, pos) {
163
+ if (orig.length == folded.length) return pos;
164
+ for (var pos1 = Math.min(pos, orig.length);;) {
165
+ var len1 = orig.slice(0, pos1).toLowerCase().length;
166
+ if (len1 < pos) ++pos1;
167
+ else if (len1 > pos) --pos1;
168
+ else return pos1;
169
+ }
170
+ }
171
+
172
+ CodeMirror.defineExtension("getSearchCursor", function(query, pos, caseFold) {
173
+ return new SearchCursor(this.doc, query, pos, caseFold);
174
+ });
175
+ CodeMirror.defineDocExtension("getSearchCursor", function(query, pos, caseFold) {
176
+ return new SearchCursor(this, query, pos, caseFold);
177
+ });
178
+
179
+ CodeMirror.defineExtension("selectMatches", function(query, caseFold) {
180
+ var ranges = [], next;
181
+ var cur = this.getSearchCursor(query, this.getCursor("from"), caseFold);
182
+ while (next = cur.findNext()) {
183
+ if (CodeMirror.cmpPos(cur.to(), this.getCursor("to")) > 0) break;
184
+ ranges.push({anchor: cur.from(), head: cur.to()});
185
+ }
186
+ if (ranges.length)
187
+ this.setSelections(ranges, 0);
188
+ });
189
+ });
vendor/codemirror/lib/codemirror.css CHANGED
@@ -1,263 +1,309 @@
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
- }
40
-
41
- /* CURSOR */
42
-
43
- .CodeMirror div.CodeMirror-cursor {
44
- border-left: 1px solid black;
45
- z-index: 3;
46
- }
47
- /* Shown when moving in bi-directional text */
48
- .CodeMirror div.CodeMirror-secondarycursor {
49
- border-left: 1px solid silver;
50
- }
51
- .CodeMirror.cm-keymap-fat-cursor div.CodeMirror-cursor {
52
- width: auto;
53
- border: 0;
54
- background: #7e7;
55
- z-index: 1;
56
- }
57
- /* Can style cursor different in overwrite (non-insert) mode */
58
- .CodeMirror div.CodeMirror-cursor.CodeMirror-overwrite {}
59
-
60
- .cm-tab { display: inline-block; }
61
-
62
- /* DEFAULT THEME */
63
-
64
- .cm-s-default .cm-keyword {color: #708;}
65
- .cm-s-default .cm-atom {color: #219;}
66
- .cm-s-default .cm-number {color: #164;}
67
- .cm-s-default .cm-def {color: #00f;}
68
- .cm-s-default .cm-variable {color: black;}
69
- .cm-s-default .cm-variable-2 {color: #05a;}
70
- .cm-s-default .cm-variable-3 {color: #085;}
71
- .cm-s-default .cm-property {color: black;}
72
- .cm-s-default .cm-operator {color: black;}
73
- .cm-s-default .cm-comment {color: #a50;}
74
- .cm-s-default .cm-string {color: #a11;}
75
- .cm-s-default .cm-string-2 {color: #f50;}
76
- .cm-s-default .cm-meta {color: #555;}
77
- .cm-s-default .cm-qualifier {color: #555;}
78
- .cm-s-default .cm-builtin {color: #30a;}
79
- .cm-s-default .cm-bracket {color: #997;}
80
- .cm-s-default .cm-tag {color: #170;}
81
- .cm-s-default .cm-attribute {color: #00c;}
82
- .cm-s-default .cm-header {color: blue;}
83
- .cm-s-default .cm-quote {color: #090;}
84
- .cm-s-default .cm-hr {color: #999;}
85
- .cm-s-default .cm-link {color: #00c;}
86
-
87
- .cm-negative {color: #d44;}
88
- .cm-positive {color: #292;}
89
- .cm-header, .cm-strong {font-weight: bold;}
90
- .cm-em {font-style: italic;}
91
- .cm-link {text-decoration: underline;}
92
-
93
- .cm-s-default .cm-error {color: #f00;}
94
- .cm-invalidchar {color: #f00;}
95
-
96
- div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
97
- div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
98
- .CodeMirror-activeline-background {background: #e8f2ff;}
99
-
100
- /* STOP */
101
-
102
- /* The rest of this file contains styles related to the mechanics of
103
- the editor. You probably shouldn't touch them. */
104
-
105
- .CodeMirror {
106
- line-height: 1;
107
- position: relative;
108
- overflow: hidden;
109
- background: white;
110
- color: black;
111
- }
112
-
113
- .CodeMirror-scroll {
114
- /* 30px is the magic margin used to hide the element's real scrollbars */
115
- /* See overflow: hidden in .CodeMirror */
116
- margin-bottom: -30px; margin-right: -30px;
117
- padding-bottom: 30px; padding-right: 30px;
118
- height: 100%;
119
- outline: none; /* Prevent dragging from highlighting the element */
120
- position: relative;
121
- -moz-box-sizing: content-box;
122
- box-sizing: content-box;
123
- }
124
- .CodeMirror-sizer {
125
- position: relative;
126
- }
127
-
128
- /* The fake, visible scrollbars. Used to force redraw during scrolling
129
- before actuall scrolling happens, thus preventing shaking and
130
- flickering artifacts. */
131
- .CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
132
- position: absolute;
133
- z-index: 6;
134
- display: none;
135
- }
136
- .CodeMirror-vscrollbar {
137
- right: 0; top: 0;
138
- overflow-x: hidden;
139
- overflow-y: scroll;
140
- }
141
- .CodeMirror-hscrollbar {
142
- bottom: 0; left: 0;
143
- overflow-y: hidden;
144
- overflow-x: scroll;
145
- }
146
- .CodeMirror-scrollbar-filler {
147
- right: 0; bottom: 0;
148
- }
149
- .CodeMirror-gutter-filler {
150
- left: 0; bottom: 0;
151
- }
152
-
153
- .CodeMirror-gutters {
154
- position: absolute; left: 0; top: 0;
155
- padding-bottom: 30px;
156
- z-index: 3;
157
- }
158
- .CodeMirror-gutter {
159
- white-space: normal;
160
- height: 100%;
161
- -moz-box-sizing: content-box;
162
- box-sizing: content-box;
163
- padding-bottom: 30px;
164
- margin-bottom: -32px;
165
- display: inline-block;
166
- /* Hack to make IE7 behave */
167
- *zoom:1;
168
- *display:inline;
169
- }
170
- .CodeMirror-gutter-elt {
171
- position: absolute;
172
- cursor: default;
173
- z-index: 4;
174
- }
175
-
176
- .CodeMirror-lines {
177
- cursor: text;
178
- }
179
- .CodeMirror pre {
180
- /* Reset some styles that the rest of the page might have set */
181
- -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
182
- border-width: 0;
183
- background: transparent;
184
- font-family: inherit;
185
- font-size: inherit;
186
- margin: 0;
187
- white-space: pre;
188
- word-wrap: normal;
189
- line-height: inherit;
190
- color: inherit;
191
- z-index: 2;
192
- position: relative;
193
- overflow: visible;
194
- }
195
- .CodeMirror-wrap pre {
196
- word-wrap: break-word;
197
- white-space: pre-wrap;
198
- word-break: normal;
199
- }
200
- .CodeMirror-code pre {
201
- border-right: 30px solid transparent;
202
- width: -webkit-fit-content;
203
- width: -moz-fit-content;
204
- width: fit-content;
205
- }
206
- .CodeMirror-wrap .CodeMirror-code pre {
207
- border-right: none;
208
- width: auto;
209
- }
210
- .CodeMirror-linebackground {
211
- position: absolute;
212
- left: 0; right: 0; top: 0; bottom: 0;
213
- z-index: 0;
214
- }
215
-
216
- .CodeMirror-linewidget {
217
- position: relative;
218
- z-index: 2;
219
- overflow: auto;
220
- }
221
-
222
- .CodeMirror-widget {}
223
-
224
- .CodeMirror-wrap .CodeMirror-scroll {
225
- overflow-x: hidden;
226
- }
227
-
228
- .CodeMirror-measure {
229
- position: absolute;
230
- width: 100%;
231
- height: 0;
232
- overflow: hidden;
233
- visibility: hidden;
234
- }
235
- .CodeMirror-measure pre { position: static; }
236
-
237
- .CodeMirror div.CodeMirror-cursor {
238
- position: absolute;
239
- visibility: hidden;
240
- border-right: none;
241
- width: 0;
242
- }
243
- .CodeMirror-focused div.CodeMirror-cursor {
244
- visibility: visible;
245
- }
246
-
247
- .CodeMirror-selected { background: #d9d9d9; }
248
- .CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
249
-
250
- .cm-searching {
251
- background: #ffa;
252
- background: rgba(255, 255, 0, .4);
253
- }
254
-
255
- /* IE7 hack to prevent it from returning funny offsetTops on the spans */
256
- .CodeMirror span { *vertical-align: text-bottom; }
257
-
258
- @media print {
259
- /* Hide the cursor when printing */
260
- .CodeMirror div.CodeMirror-cursor {
261
- visibility: hidden;
262
- }
263
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* BASICS */
2
+
3
+ .CodeMirror {
4
+ /* Set height, width, borders, and global font properties here */
5
+ font-family: monospace;
6
+ height: 300px;
7
+ }
8
+
9
+ /* PADDING */
10
+
11
+ .CodeMirror-lines {
12
+ padding: 4px 0; /* Vertical padding around content */
13
+ }
14
+ .CodeMirror pre {
15
+ padding: 0 4px; /* Horizontal padding of content */
16
+ }
17
+
18
+ .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
19
+ background-color: white; /* The little square between H and V scrollbars */
20
+ }
21
+
22
+ /* GUTTER */
23
+
24
+ .CodeMirror-gutters {
25
+ border-right: 1px solid #ddd;
26
+ background-color: #f7f7f7;
27
+ white-space: nowrap;
28
+ }
29
+ .CodeMirror-linenumbers {}
30
+ .CodeMirror-linenumber {
31
+ padding: 0 3px 0 5px;
32
+ min-width: 20px;
33
+ text-align: right;
34
+ color: #999;
35
+ -moz-box-sizing: content-box;
36
+ box-sizing: content-box;
37
+ }
38
+
39
+ .CodeMirror-guttermarker { color: black; }
40
+ .CodeMirror-guttermarker-subtle { color: #999; }
41
+
42
+ /* CURSOR */
43
+
44
+ .CodeMirror div.CodeMirror-cursor {
45
+ border-left: 1px solid black;
46
+ }
47
+ /* Shown when moving in bi-directional text */
48
+ .CodeMirror div.CodeMirror-secondarycursor {
49
+ border-left: 1px solid silver;
50
+ }
51
+ .CodeMirror.cm-fat-cursor div.CodeMirror-cursor {
52
+ width: auto;
53
+ border: 0;
54
+ background: #7e7;
55
+ }
56
+ .CodeMirror.cm-fat-cursor div.CodeMirror-cursors {
57
+ z-index: 1;
58
+ }
59
+
60
+ .cm-animate-fat-cursor {
61
+ width: auto;
62
+ border: 0;
63
+ -webkit-animation: blink 1.06s steps(1) infinite;
64
+ -moz-animation: blink 1.06s steps(1) infinite;
65
+ animation: blink 1.06s steps(1) infinite;
66
+ }
67
+ @-moz-keyframes blink {
68
+ 0% { background: #7e7; }
69
+ 50% { background: none; }
70
+ 100% { background: #7e7; }
71
+ }
72
+ @-webkit-keyframes blink {
73
+ 0% { background: #7e7; }
74
+ 50% { background: none; }
75
+ 100% { background: #7e7; }
76
+ }
77
+ @keyframes blink {
78
+ 0% { background: #7e7; }
79
+ 50% { background: none; }
80
+ 100% { background: #7e7; }
81
+ }
82
+
83
+ /* Can style cursor different in overwrite (non-insert) mode */
84
+ div.CodeMirror-overwrite div.CodeMirror-cursor {}
85
+
86
+ .cm-tab { display: inline-block; text-decoration: inherit; }
87
+
88
+ .CodeMirror-ruler {
89
+ border-left: 1px solid #ccc;
90
+ position: absolute;
91
+ }
92
+
93
+ /* DEFAULT THEME */
94
+
95
+ .cm-s-default .cm-keyword {color: #708;}
96
+ .cm-s-default .cm-atom {color: #219;}
97
+ .cm-s-default .cm-number {color: #164;}
98
+ .cm-s-default .cm-def {color: #00f;}
99
+ .cm-s-default .cm-variable,
100
+ .cm-s-default .cm-punctuation,
101
+ .cm-s-default .cm-property,
102
+ .cm-s-default .cm-operator {}
103
+ .cm-s-default .cm-variable-2 {color: #05a;}
104
+ .cm-s-default .cm-variable-3 {color: #085;}
105
+ .cm-s-default .cm-comment {color: #a50;}
106
+ .cm-s-default .cm-string {color: #a11;}
107
+ .cm-s-default .cm-string-2 {color: #f50;}
108
+ .cm-s-default .cm-meta {color: #555;}
109
+ .cm-s-default .cm-qualifier {color: #555;}
110
+ .cm-s-default .cm-builtin {color: #30a;}
111
+ .cm-s-default .cm-bracket {color: #997;}
112
+ .cm-s-default .cm-tag {color: #170;}
113
+ .cm-s-default .cm-attribute {color: #00c;}
114
+ .cm-s-default .cm-header {color: blue;}
115
+ .cm-s-default .cm-quote {color: #090;}
116
+ .cm-s-default .cm-hr {color: #999;}
117
+ .cm-s-default .cm-link {color: #00c;}
118
+
119
+ .cm-negative {color: #d44;}
120
+ .cm-positive {color: #292;}
121
+ .cm-header, .cm-strong {font-weight: bold;}
122
+ .cm-em {font-style: italic;}
123
+ .cm-link {text-decoration: underline;}
124
+ .cm-strikethrough {text-decoration: line-through;}
125
+
126
+ .cm-s-default .cm-error {color: #f00;}
127
+ .cm-invalidchar {color: #f00;}
128
+
129
+ /* Default styles for common addons */
130
+
131
+ div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
132
+ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
133
+ .CodeMirror-matchingtag { background: rgba(255, 150, 0, .3); }
134
+ .CodeMirror-activeline-background {background: #e8f2ff;}
135
+
136
+ /* STOP */
137
+
138
+ /* The rest of this file contains styles related to the mechanics of
139
+ the editor. You probably shouldn't touch them. */
140
+
141
+ .CodeMirror {
142
+ line-height: 1;
143
+ position: relative;
144
+ overflow: hidden;
145
+ background: white;
146
+ color: black;
147
+ }
148
+
149
+ .CodeMirror-scroll {
150
+ overflow: scroll !important; /* Things will break if this is overridden */
151
+ /* 30px is the magic margin used to hide the element's real scrollbars */
152
+ /* See overflow: hidden in .CodeMirror */
153
+ margin-bottom: -30px; margin-right: -30px;
154
+ padding-bottom: 30px;
155
+ height: 100%;
156
+ outline: none; /* Prevent dragging from highlighting the element */
157
+ position: relative;
158
+ -moz-box-sizing: content-box;
159
+ box-sizing: content-box;
160
+ }
161
+ .CodeMirror-sizer {
162
+ position: relative;
163
+ border-right: 30px solid transparent;
164
+ -moz-box-sizing: content-box;
165
+ box-sizing: content-box;
166
+ }
167
+
168
+ /* The fake, visible scrollbars. Used to force redraw during scrolling
169
+ before actuall scrolling happens, thus preventing shaking and
170
+ flickering artifacts. */
171
+ .CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
172
+ position: absolute;
173
+ z-index: 6;
174
+ display: none;
175
+ }
176
+ .CodeMirror-vscrollbar {
177
+ right: 0; top: 0;
178
+ overflow-x: hidden;
179
+ overflow-y: scroll;
180
+ }
181
+ .CodeMirror-hscrollbar {
182
+ bottom: 0; left: 0;
183
+ overflow-y: hidden;
184
+ overflow-x: scroll;
185
+ }
186
+ .CodeMirror-scrollbar-filler {
187
+ right: 0; bottom: 0;
188
+ }
189
+ .CodeMirror-gutter-filler {
190
+ left: 0; bottom: 0;
191
+ }
192
+
193
+ .CodeMirror-gutters {
194
+ position: absolute; left: 0; top: 0;
195
+ z-index: 3;
196
+ }
197
+ .CodeMirror-gutter {
198
+ white-space: normal;
199
+ height: 100%;
200
+ -moz-box-sizing: content-box;
201
+ box-sizing: content-box;
202
+ display: inline-block;
203
+ margin-bottom: -30px;
204
+ /* Hack to make IE7 behave */
205
+ *zoom:1;
206
+ *display:inline;
207
+ }
208
+ .CodeMirror-gutter-wrapper {
209
+ position: absolute;
210
+ z-index: 4;
211
+ height: 100%;
212
+ }
213
+ .CodeMirror-gutter-elt {
214
+ position: absolute;
215
+ cursor: default;
216
+ z-index: 4;
217
+ }
218
+
219
+ .CodeMirror-lines {
220
+ cursor: text;
221
+ min-height: 1px; /* prevents collapsing before first draw */
222
+ }
223
+ .CodeMirror pre {
224
+ /* Reset some styles that the rest of the page might have set */
225
+ -moz-border-radius: 0; -webkit-border-radius: 0; border-radius: 0;
226
+ border-width: 0;
227
+ background: transparent;
228
+ font-family: inherit;
229
+ font-size: inherit;
230
+ margin: 0;
231
+ white-space: pre;
232
+ word-wrap: normal;
233
+ line-height: inherit;
234
+ color: inherit;
235
+ z-index: 2;
236
+ position: relative;
237
+ overflow: visible;
238
+ }
239
+ .CodeMirror-wrap pre {
240
+ word-wrap: break-word;
241
+ white-space: pre-wrap;
242
+ word-break: normal;
243
+ }
244
+
245
+ .CodeMirror-linebackground {
246
+ position: absolute;
247
+ left: 0; right: 0; top: 0; bottom: 0;
248
+ z-index: 0;
249
+ }
250
+
251
+ .CodeMirror-linewidget {
252
+ position: relative;
253
+ z-index: 2;
254
+ overflow: auto;
255
+ }
256
+
257
+ .CodeMirror-widget {}
258
+
259
+ .CodeMirror-measure {
260
+ position: absolute;
261
+ width: 100%;
262
+ height: 0;
263
+ overflow: hidden;
264
+ visibility: hidden;
265
+ }
266
+ .CodeMirror-measure pre { position: static; }
267
+
268
+ .CodeMirror div.CodeMirror-cursor {
269
+ position: absolute;
270
+ border-right: none;
271
+ width: 0;
272
+ }
273
+
274
+ div.CodeMirror-cursors {
275
+ visibility: hidden;
276
+ position: relative;
277
+ z-index: 3;
278
+ }
279
+ .CodeMirror-focused div.CodeMirror-cursors {
280
+ visibility: visible;
281
+ }
282
+
283
+ .CodeMirror-selected { background: #d9d9d9; }
284
+ .CodeMirror-focused .CodeMirror-selected { background: #d7d4f0; }
285
+ .CodeMirror-crosshair { cursor: crosshair; }
286
+
287
+ .cm-searching {
288
+ background: #ffa;
289
+ background: rgba(255, 255, 0, .4);
290
+ }
291
+
292
+ /* IE7 hack to prevent it from returning funny offsetTops on the spans */
293
+ .CodeMirror span { *vertical-align: text-bottom; }
294
+
295
+ /* Used to force a border model for a node */
296
+ .cm-force-border { padding-right: .1px; }
297
+
298
+ @media print {
299
+ /* Hide the cursor when printing */
300
+ .CodeMirror div.CodeMirror-cursors {
301
+ visibility: hidden;
302
+ }
303
+ }
304
+
305
+ /* See issue #2901 */
306
+ .cm-tab-wrap-hack:after { content: ''; }
307
+
308
+ /* Help users use markselection to safely style text background */
309
+ span.CodeMirror-selectedtext { background: none; }
vendor/codemirror/lib/codemirror.js CHANGED
@@ -1,5942 +1,8045 @@
1
- // CodeMirror is the only global var we claim
2
- window.CodeMirror = (function() {
3
- "use strict";
4
-
5
- // BROWSER SNIFFING
6
-
7
- // Crude, but necessary to handle a number of hard-to-feature-detect
8
- // bugs and behavior differences.
9
- var gecko = /gecko\/\d/i.test(navigator.userAgent);
10
- // IE11 currently doesn't count as 'ie', since it has almost none of
11
- // the same bugs as earlier versions. Use ie_gt10 to handle
12
- // incompatibilities in that version.
13
- var ie = /MSIE \d/.test(navigator.userAgent);
14
- var ie_lt8 = ie && (document.documentMode == null || document.documentMode < 8);
15
- var ie_lt9 = ie && (document.documentMode == null || document.documentMode < 9);
16
- var ie_gt10 = /Trident\/([7-9]|\d{2,})\./.test(navigator.userAgent);
17
- var webkit = /WebKit\//.test(navigator.userAgent);
18
- var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(navigator.userAgent);
19
- var chrome = /Chrome\//.test(navigator.userAgent);
20
- var opera = /Opera\//.test(navigator.userAgent);
21
- var safari = /Apple Computer/.test(navigator.vendor);
22
- var khtml = /KHTML\//.test(navigator.userAgent);
23
- var mac_geLion = /Mac OS X 1\d\D([7-9]|\d\d)\D/.test(navigator.userAgent);
24
- var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent);
25
- var phantom = /PhantomJS/.test(navigator.userAgent);
26
-
27
- var ios = /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent);
28
- // This is woefully incomplete. Suggestions for alternative methods welcome.
29
- var mobile = ios || /Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent);
30
- var mac = ios || /Mac/.test(navigator.platform);
31
- var windows = /win/i.test(navigator.platform);
32
-
33
- var opera_version = opera && navigator.userAgent.match(/Version\/(\d*\.\d*)/);
34
- if (opera_version) opera_version = Number(opera_version[1]);
35
- if (opera_version && opera_version >= 15) { opera = false; webkit = true; }
36
- // Some browsers use the wrong event properties to signal cmd/ctrl on OS X
37
- var flipCtrlCmd = mac && (qtwebkit || opera && (opera_version == null || opera_version < 12.11));
38
- var captureMiddleClick = gecko || (ie && !ie_lt9);
39
-
40
- // Optimize some code when these features are not used
41
- var sawReadOnlySpans = false, sawCollapsedSpans = false;
42
-
43
- // CONSTRUCTOR
44
-
45
- function CodeMirror(place, options) {
46
- if (!(this instanceof CodeMirror)) return new CodeMirror(place, options);
47
-
48
- this.options = options = options || {};
49
- // Determine effective options based on given values and defaults.
50
- for (var opt in defaults) if (!options.hasOwnProperty(opt) && defaults.hasOwnProperty(opt))
51
- options[opt] = defaults[opt];
52
- setGuttersForLineNumbers(options);
53
-
54
- var docStart = typeof options.value == "string" ? 0 : options.value.first;
55
- var display = this.display = makeDisplay(place, docStart);
56
- display.wrapper.CodeMirror = this;
57
- updateGutters(this);
58
- if (options.autofocus && !mobile) focusInput(this);
59
-
60
- this.state = {keyMaps: [],
61
- overlays: [],
62
- modeGen: 0,
63
- overwrite: false, focused: false,
64
- suppressEdits: false, pasteIncoming: false,
65
- draggingText: false,
66
- highlight: new Delayed()};
67
-
68
- themeChanged(this);
69
- if (options.lineWrapping)
70
- this.display.wrapper.className += " CodeMirror-wrap";
71
-
72
- var doc = options.value;
73
- if (typeof doc == "string") doc = new Doc(options.value, options.mode);
74
- operation(this, attachDoc)(this, doc);
75
-
76
- // Override magic textarea content restore that IE sometimes does
77
- // on our hidden textarea on reload
78
- if (ie) setTimeout(bind(resetInput, this, true), 20);
79
-
80
- registerEventHandlers(this);
81
- // IE throws unspecified error in certain cases, when
82
- // trying to access activeElement before onload
83
- var hasFocus; try { hasFocus = (document.activeElement == display.input); } catch(e) { }
84
- if (hasFocus || (options.autofocus && !mobile)) setTimeout(bind(onFocus, this), 20);
85
- else onBlur(this);
86
-
87
- operation(this, function() {
88
- for (var opt in optionHandlers)
89
- if (optionHandlers.propertyIsEnumerable(opt))
90
- optionHandlers[opt](this, options[opt], Init);
91
- for (var i = 0; i < initHooks.length; ++i) initHooks[i](this);
92
- })();
93
- }
94
-
95
- // DISPLAY CONSTRUCTOR
96
-
97
- function makeDisplay(place, docStart) {
98
- var d = {};
99
-
100
- var input = d.input = elt("textarea", null, null, "position: absolute; padding: 0; width: 1px; height: 1em; outline: none; font-size: 4px;");
101
- if (webkit) input.style.width = "1000px";
102
- else input.setAttribute("wrap", "off");
103
- // if border: 0; -- iOS fails to open keyboard (issue #1287)
104
- if (ios) input.style.border = "1px solid black";
105
- input.setAttribute("autocorrect", "off"); input.setAttribute("autocapitalize", "off"); input.setAttribute("spellcheck", "false");
106
-
107
- // Wraps and hides input textarea
108
- d.inputDiv = elt("div", [input], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
109
- // The actual fake scrollbars.
110
- d.scrollbarH = elt("div", [elt("div", null, null, "height: 1px")], "CodeMirror-hscrollbar");
111
- d.scrollbarV = elt("div", [elt("div", null, null, "width: 1px")], "CodeMirror-vscrollbar");
112
- d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
113
- d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler");
114
- // DIVs containing the selection and the actual code
115
- d.lineDiv = elt("div", null, "CodeMirror-code");
116
- d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
117
- // Blinky cursor, and element used to ensure cursor fits at the end of a line
118
- d.cursor = elt("div", "\u00a0", "CodeMirror-cursor");
119
- // Secondary cursor, shown when on a 'jump' in bi-directional text
120
- d.otherCursor = elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor");
121
- // Used to measure text size
122
- d.measure = elt("div", null, "CodeMirror-measure");
123
- // Wraps everything that needs to exist inside the vertically-padded coordinate system
124
- d.lineSpace = elt("div", [d.measure, d.selectionDiv, d.lineDiv, d.cursor, d.otherCursor],
125
- null, "position: relative; outline: none");
126
- // Moved around its parent to cover visible view
127
- d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative");
128
- // Set to the height of the text, causes scrolling
129
- d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
130
- // D is needed because behavior of elts with overflow: auto and padding is inconsistent across browsers
131
- d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerCutOff + "px; width: 1px;");
132
- // Will contain the gutters, if any
133
- d.gutters = elt("div", null, "CodeMirror-gutters");
134
- d.lineGutter = null;
135
- // Provides scrolling
136
- d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll");
137
- d.scroller.setAttribute("tabIndex", "-1");
138
- // The element in which the editor lives.
139
- d.wrapper = elt("div", [d.inputDiv, d.scrollbarH, d.scrollbarV,
140
- d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
141
- // Work around IE7 z-index bug
142
- if (ie_lt8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; }
143
- if (place.appendChild) place.appendChild(d.wrapper); else place(d.wrapper);
144
-
145
- // Needed to hide big blue blinking cursor on Mobile Safari
146
- if (ios) input.style.width = "0px";
147
- if (!webkit) d.scroller.draggable = true;
148
- // Needed to handle Tab key in KHTML
149
- if (khtml) { d.inputDiv.style.height = "1px"; d.inputDiv.style.position = "absolute"; }
150
- // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
151
- else if (ie_lt8) d.scrollbarH.style.minWidth = d.scrollbarV.style.minWidth = "18px";
152
-
153
- // Current visible range (may be bigger than the view window).
154
- d.viewOffset = d.lastSizeC = 0;
155
- d.showingFrom = d.showingTo = docStart;
156
-
157
- // Used to only resize the line number gutter when necessary (when
158
- // the amount of lines crosses a boundary that makes its width change)
159
- d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
160
- // See readInput and resetInput
161
- d.prevInput = "";
162
- // Set to true when a non-horizontal-scrolling widget is added. As
163
- // an optimization, widget aligning is skipped when d is false.
164
- d.alignWidgets = false;
165
- // Flag that indicates whether we currently expect input to appear
166
- // (after some event like 'keypress' or 'input') and are polling
167
- // intensively.
168
- d.pollingFast = false;
169
- // Self-resetting timeout for the poller
170
- d.poll = new Delayed();
171
-
172
- d.cachedCharWidth = d.cachedTextHeight = null;
173
- d.measureLineCache = [];
174
- d.measureLineCachePos = 0;
175
-
176
- // Tracks when resetInput has punted to just putting a short
177
- // string instead of the (large) selection.
178
- d.inaccurateSelection = false;
179
-
180
- // Tracks the maximum line length so that the horizontal scrollbar
181
- // can be kept static when scrolling.
182
- d.maxLine = null;
183
- d.maxLineLength = 0;
184
- d.maxLineChanged = false;
185
-
186
- // Used for measuring wheel scrolling granularity
187
- d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null;
188
-
189
- return d;
190
- }
191
-
192
- // STATE UPDATES
193
-
194
- // Used to get the editor into a consistent state again when options change.
195
-
196
- function loadMode(cm) {
197
- cm.doc.mode = CodeMirror.getMode(cm.options, cm.doc.modeOption);
198
- cm.doc.iter(function(line) {
199
- if (line.stateAfter) line.stateAfter = null;
200
- if (line.styles) line.styles = null;
201
- });
202
- cm.doc.frontier = cm.doc.first;
203
- startWorker(cm, 100);
204
- cm.state.modeGen++;
205
- if (cm.curOp) regChange(cm);
206
- }
207
-
208
- function wrappingChanged(cm) {
209
- if (cm.options.lineWrapping) {
210
- cm.display.wrapper.className += " CodeMirror-wrap";
211
- cm.display.sizer.style.minWidth = "";
212
- } else {
213
- cm.display.wrapper.className = cm.display.wrapper.className.replace(" CodeMirror-wrap", "");
214
- computeMaxLength(cm);
215
- }
216
- estimateLineHeights(cm);
217
- regChange(cm);
218
- clearCaches(cm);
219
- setTimeout(function(){updateScrollbars(cm);}, 100);
220
- }
221
-
222
- function estimateHeight(cm) {
223
- var th = textHeight(cm.display), wrapping = cm.options.lineWrapping;
224
- var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);
225
- return function(line) {
226
- if (lineIsHidden(cm.doc, line))
227
- return 0;
228
- else if (wrapping)
229
- return (Math.ceil(line.text.length / perLine) || 1) * th;
230
- else
231
- return th;
232
- };
233
- }
234
-
235
- function estimateLineHeights(cm) {
236
- var doc = cm.doc, est = estimateHeight(cm);
237
- doc.iter(function(line) {
238
- var estHeight = est(line);
239
- if (estHeight != line.height) updateLineHeight(line, estHeight);
240
- });
241
- }
242
-
243
- function keyMapChanged(cm) {
244
- var map = keyMap[cm.options.keyMap], style = map.style;
245
- cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-keymap-\S+/g, "") +
246
- (style ? " cm-keymap-" + style : "");
247
- cm.state.disableInput = map.disableInput;
248
- }
249
-
250
- function themeChanged(cm) {
251
- cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
252
- cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
253
- clearCaches(cm);
254
- }
255
-
256
- function guttersChanged(cm) {
257
- updateGutters(cm);
258
- regChange(cm);
259
- setTimeout(function(){alignHorizontally(cm);}, 20);
260
- }
261
-
262
- function updateGutters(cm) {
263
- var gutters = cm.display.gutters, specs = cm.options.gutters;
264
- removeChildren(gutters);
265
- for (var i = 0; i < specs.length; ++i) {
266
- var gutterClass = specs[i];
267
- var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass));
268
- if (gutterClass == "CodeMirror-linenumbers") {
269
- cm.display.lineGutter = gElt;
270
- gElt.style.width = (cm.display.lineNumWidth || 1) + "px";
271
- }
272
- }
273
- gutters.style.display = i ? "" : "none";
274
- }
275
-
276
- function lineLength(doc, line) {
277
- if (line.height == 0) return 0;
278
- var len = line.text.length, merged, cur = line;
279
- while (merged = collapsedSpanAtStart(cur)) {
280
- var found = merged.find();
281
- cur = getLine(doc, found.from.line);
282
- len += found.from.ch - found.to.ch;
283
- }
284
- cur = line;
285
- while (merged = collapsedSpanAtEnd(cur)) {
286
- var found = merged.find();
287
- len -= cur.text.length - found.from.ch;
288
- cur = getLine(doc, found.to.line);
289
- len += cur.text.length - found.to.ch;
290
- }
291
- return len;
292
- }
293
-
294
- function computeMaxLength(cm) {
295
- var d = cm.display, doc = cm.doc;
296
- d.maxLine = getLine(doc, doc.first);
297
- d.maxLineLength = lineLength(doc, d.maxLine);
298
- d.maxLineChanged = true;
299
- doc.iter(function(line) {
300
- var len = lineLength(doc, line);
301
- if (len > d.maxLineLength) {
302
- d.maxLineLength = len;
303
- d.maxLine = line;
304
- }
305
- });
306
- }
307
-
308
- // Make sure the gutters options contains the element
309
- // "CodeMirror-linenumbers" when the lineNumbers option is true.
310
- function setGuttersForLineNumbers(options) {
311
- var found = indexOf(options.gutters, "CodeMirror-linenumbers");
312
- if (found == -1 && options.lineNumbers) {
313
- options.gutters = options.gutters.concat(["CodeMirror-linenumbers"]);
314
- } else if (found > -1 && !options.lineNumbers) {
315
- options.gutters = options.gutters.slice(0);
316
- options.gutters.splice(found, 1);
317
- }
318
- }
319
-
320
- // SCROLLBARS
321
-
322
- // Re-synchronize the fake scrollbars with the actual size of the
323
- // content. Optionally force a scrollTop.
324
- function updateScrollbars(cm) {
325
- var d = cm.display, docHeight = cm.doc.height;
326
- var totalHeight = docHeight + paddingVert(d);
327
- d.sizer.style.minHeight = d.heightForcer.style.top = totalHeight + "px";
328
- d.gutters.style.height = Math.max(totalHeight, d.scroller.clientHeight - scrollerCutOff) + "px";
329
- var scrollHeight = Math.max(totalHeight, d.scroller.scrollHeight);
330
- var needsH = d.scroller.scrollWidth > (d.scroller.clientWidth + 1);
331
- var needsV = scrollHeight > (d.scroller.clientHeight + 1);
332
- if (needsV) {
333
- d.scrollbarV.style.display = "block";
334
- d.scrollbarV.style.bottom = needsH ? scrollbarWidth(d.measure) + "px" : "0";
335
- d.scrollbarV.firstChild.style.height =
336
- (scrollHeight - d.scroller.clientHeight + d.scrollbarV.clientHeight) + "px";
337
- } else {
338
- d.scrollbarV.style.display = "";
339
- d.scrollbarV.firstChild.style.height = "0";
340
- }
341
- if (needsH) {
342
- d.scrollbarH.style.display = "block";
343
- d.scrollbarH.style.right = needsV ? scrollbarWidth(d.measure) + "px" : "0";
344
- d.scrollbarH.firstChild.style.width =
345
- (d.scroller.scrollWidth - d.scroller.clientWidth + d.scrollbarH.clientWidth) + "px";
346
- } else {
347
- d.scrollbarH.style.display = "";
348
- d.scrollbarH.firstChild.style.width = "0";
349
- }
350
- if (needsH && needsV) {
351
- d.scrollbarFiller.style.display = "block";
352
- d.scrollbarFiller.style.height = d.scrollbarFiller.style.width = scrollbarWidth(d.measure) + "px";
353
- } else d.scrollbarFiller.style.display = "";
354
- if (needsH && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
355
- d.gutterFiller.style.display = "block";
356
- d.gutterFiller.style.height = scrollbarWidth(d.measure) + "px";
357
- d.gutterFiller.style.width = d.gutters.offsetWidth + "px";
358
- } else d.gutterFiller.style.display = "";
359
-
360
- if (mac_geLion && scrollbarWidth(d.measure) === 0) {
361
- d.scrollbarV.style.minWidth = d.scrollbarH.style.minHeight = mac_geMountainLion ? "18px" : "12px";
362
- d.scrollbarV.style.pointerEvents = d.scrollbarH.style.pointerEvents = "none";
363
- }
364
- }
365
-
366
- function visibleLines(display, doc, viewPort) {
367
- var top = display.scroller.scrollTop, height = display.wrapper.clientHeight;
368
- if (typeof viewPort == "number") top = viewPort;
369
- else if (viewPort) {top = viewPort.top; height = viewPort.bottom - viewPort.top;}
370
- top = Math.floor(top - paddingTop(display));
371
- var bottom = Math.ceil(top + height);
372
- return {from: lineAtHeight(doc, top), to: lineAtHeight(doc, bottom)};
373
- }
374
-
375
- // LINE NUMBERS
376
-
377
- function alignHorizontally(cm) {
378
- var display = cm.display;
379
- if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) return;
380
- var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft;
381
- var gutterW = display.gutters.offsetWidth, l = comp + "px";
382
- for (var n = display.lineDiv.firstChild; n; n = n.nextSibling) if (n.alignable) {
383
- for (var i = 0, a = n.alignable; i < a.length; ++i) a[i].style.left = l;
384
- }
385
- if (cm.options.fixedGutter)
386
- display.gutters.style.left = (comp + gutterW) + "px";
387
- }
388
-
389
- function maybeUpdateLineNumberWidth(cm) {
390
- if (!cm.options.lineNumbers) return false;
391
- var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display;
392
- if (last.length != display.lineNumChars) {
393
- var test = display.measure.appendChild(elt("div", [elt("div", last)],
394
- "CodeMirror-linenumber CodeMirror-gutter-elt"));
395
- var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
396
- display.lineGutter.style.width = "";
397
- display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding);
398
- display.lineNumWidth = display.lineNumInnerWidth + padding;
399
- display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
400
- display.lineGutter.style.width = display.lineNumWidth + "px";
401
- return true;
402
- }
403
- return false;
404
- }
405
-
406
- function lineNumberFor(options, i) {
407
- return String(options.lineNumberFormatter(i + options.firstLineNumber));
408
- }
409
- function compensateForHScroll(display) {
410
- return getRect(display.scroller).left - getRect(display.sizer).left;
411
- }
412
-
413
- // DISPLAY DRAWING
414
-
415
- function updateDisplay(cm, changes, viewPort, forced) {
416
- var oldFrom = cm.display.showingFrom, oldTo = cm.display.showingTo, updated;
417
- var visible = visibleLines(cm.display, cm.doc, viewPort);
418
- for (var first = true;; first = false) {
419
- var oldWidth = cm.display.scroller.clientWidth;
420
- if (!updateDisplayInner(cm, changes, visible, forced)) break;
421
- updated = true;
422
- changes = [];
423
- updateSelection(cm);
424
- updateScrollbars(cm);
425
- if (first && cm.options.lineWrapping && oldWidth != cm.display.scroller.clientWidth) {
426
- forced = true;
427
- continue;
428
- }
429
- forced = false;
430
-
431
- // Clip forced viewport to actual scrollable area
432
- if (viewPort)
433
- viewPort = Math.min(cm.display.scroller.scrollHeight - cm.display.scroller.clientHeight,
434
- typeof viewPort == "number" ? viewPort : viewPort.top);
435
- visible = visibleLines(cm.display, cm.doc, viewPort);
436
- if (visible.from >= cm.display.showingFrom && visible.to <= cm.display.showingTo)
437
- break;
438
- }
439
-
440
- if (updated) {
441
- signalLater(cm, "update", cm);
442
- if (cm.display.showingFrom != oldFrom || cm.display.showingTo != oldTo)
443
- signalLater(cm, "viewportChange", cm, cm.display.showingFrom, cm.display.showingTo);
444
- }
445
- return updated;
446
- }
447
-
448
- // Uses a set of changes plus the current scroll position to
449
- // determine which DOM updates have to be made, and makes the
450
- // updates.
451
- function updateDisplayInner(cm, changes, visible, forced) {
452
- var display = cm.display, doc = cm.doc;
453
- if (!display.wrapper.clientWidth) {
454
- display.showingFrom = display.showingTo = doc.first;
455
- display.viewOffset = 0;
456
- return;
457
- }
458
-
459
- // Bail out if the visible area is already rendered and nothing changed.
460
- if (!forced && changes.length == 0 &&
461
- visible.from > display.showingFrom && visible.to < display.showingTo)
462
- return;
463
-
464
- if (maybeUpdateLineNumberWidth(cm))
465
- changes = [{from: doc.first, to: doc.first + doc.size}];
466
- var gutterW = display.sizer.style.marginLeft = display.gutters.offsetWidth + "px";
467
- display.scrollbarH.style.left = cm.options.fixedGutter ? gutterW : "0";
468
-
469
- // Used to determine which lines need their line numbers updated
470
- var positionsChangedFrom = Infinity;
471
- if (cm.options.lineNumbers)
472
- for (var i = 0; i < changes.length; ++i)
473
- if (changes[i].diff && changes[i].from < positionsChangedFrom) { positionsChangedFrom = changes[i].from; }
474
-
475
- var end = doc.first + doc.size;
476
- var from = Math.max(visible.from - cm.options.viewportMargin, doc.first);
477
- var to = Math.min(end, visible.to + cm.options.viewportMargin);
478
- if (display.showingFrom < from && from - display.showingFrom < 20) from = Math.max(doc.first, display.showingFrom);
479
- if (display.showingTo > to && display.showingTo - to < 20) to = Math.min(end, display.showingTo);
480
- if (sawCollapsedSpans) {
481
- from = lineNo(visualLine(doc, getLine(doc, from)));
482
- while (to < end && lineIsHidden(doc, getLine(doc, to))) ++to;
483
- }
484
-
485
- // Create a range of theoretically intact lines, and punch holes
486
- // in that using the change info.
487
- var intact = [{from: Math.max(display.showingFrom, doc.first),
488
- to: Math.min(display.showingTo, end)}];
489
- if (intact[0].from >= intact[0].to) intact = [];
490
- else intact = computeIntact(intact, changes);
491
- // When merged lines are present, we might have to reduce the
492
- // intact ranges because changes in continued fragments of the
493
- // intact lines do require the lines to be redrawn.
494
- if (sawCollapsedSpans)
495
- for (var i = 0; i < intact.length; ++i) {
496
- var range = intact[i], merged;
497
- while (merged = collapsedSpanAtEnd(getLine(doc, range.to - 1))) {
498
- var newTo = merged.find().from.line;
499
- if (newTo > range.from) range.to = newTo;
500
- else { intact.splice(i--, 1); break; }
501
- }
502
- }
503
-
504
- // Clip off the parts that won't be visible
505
- var intactLines = 0;
506
- for (var i = 0; i < intact.length; ++i) {
507
- var range = intact[i];
508
- if (range.from < from) range.from = from;
509
- if (range.to > to) range.to = to;
510
- if (range.from >= range.to) intact.splice(i--, 1);
511
- else intactLines += range.to - range.from;
512
- }
513
- if (!forced && intactLines == to - from && from == display.showingFrom && to == display.showingTo) {
514
- updateViewOffset(cm);
515
- return;
516
- }
517
- intact.sort(function(a, b) {return a.from - b.from;});
518
-
519
- // Avoid crashing on IE's "unspecified error" when in iframes
520
- try {
521
- var focused = document.activeElement;
522
- } catch(e) {}
523
- if (intactLines < (to - from) * .7) display.lineDiv.style.display = "none";
524
- patchDisplay(cm, from, to, intact, positionsChangedFrom);
525
- display.lineDiv.style.display = "";
526
- if (focused && document.activeElement != focused && focused.offsetHeight) focused.focus();
527
-
528
- var different = from != display.showingFrom || to != display.showingTo ||
529
- display.lastSizeC != display.wrapper.clientHeight;
530
- // This is just a bogus formula that detects when the editor is
531
- // resized or the font size changes.
532
- if (different) {
533
- display.lastSizeC = display.wrapper.clientHeight;
534
- startWorker(cm, 400);
535
- }
536
- display.showingFrom = from; display.showingTo = to;
537
-
538
- updateHeightsInViewport(cm);
539
- updateViewOffset(cm);
540
-
541
- return true;
542
- }
543
-
544
- function updateHeightsInViewport(cm) {
545
- var display = cm.display;
546
- var prevBottom = display.lineDiv.offsetTop;
547
- for (var node = display.lineDiv.firstChild, height; node; node = node.nextSibling) if (node.lineObj) {
548
- if (ie_lt8) {
549
- var bot = node.offsetTop + node.offsetHeight;
550
- height = bot - prevBottom;
551
- prevBottom = bot;
552
- } else {
553
- var box = getRect(node);
554
- height = box.bottom - box.top;
555
- }
556
- var diff = node.lineObj.height - height;
557
- if (height < 2) height = textHeight(display);
558
- if (diff > .001 || diff < -.001) {
559
- updateLineHeight(node.lineObj, height);
560
- var widgets = node.lineObj.widgets;
561
- if (widgets) for (var i = 0; i < widgets.length; ++i)
562
- widgets[i].height = widgets[i].node.offsetHeight;
563
- }
564
- }
565
- }
566
-
567
- function updateViewOffset(cm) {
568
- var off = cm.display.viewOffset = heightAtLine(cm, getLine(cm.doc, cm.display.showingFrom));
569
- // Position the mover div to align with the current virtual scroll position
570
- cm.display.mover.style.top = off + "px";
571
- }
572
-
573
- function computeIntact(intact, changes) {
574
- for (var i = 0, l = changes.length || 0; i < l; ++i) {
575
- var change = changes[i], intact2 = [], diff = change.diff || 0;
576
- for (var j = 0, l2 = intact.length; j < l2; ++j) {
577
- var range = intact[j];
578
- if (change.to <= range.from && change.diff) {
579
- intact2.push({from: range.from + diff, to: range.to + diff});
580
- } else if (change.to <= range.from || change.from >= range.to) {
581
- intact2.push(range);
582
- } else {
583
- if (change.from > range.from)
584
- intact2.push({from: range.from, to: change.from});
585
- if (change.to < range.to)
586
- intact2.push({from: change.to + diff, to: range.to + diff});
587
- }
588
- }
589
- intact = intact2;
590
- }
591
- return intact;
592
- }
593
-
594
- function getDimensions(cm) {
595
- var d = cm.display, left = {}, width = {};
596
- for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
597
- left[cm.options.gutters[i]] = n.offsetLeft;
598
- width[cm.options.gutters[i]] = n.offsetWidth;
599
- }
600
- return {fixedPos: compensateForHScroll(d),
601
- gutterTotalWidth: d.gutters.offsetWidth,
602
- gutterLeft: left,
603
- gutterWidth: width,
604
- wrapperWidth: d.wrapper.clientWidth};
605
- }
606
-
607
- function patchDisplay(cm, from, to, intact, updateNumbersFrom) {
608
- var dims = getDimensions(cm);
609
- var display = cm.display, lineNumbers = cm.options.lineNumbers;
610
- if (!intact.length && (!webkit || !cm.display.currentWheelTarget))
611
- removeChildren(display.lineDiv);
612
- var container = display.lineDiv, cur = container.firstChild;
613
-
614
- function rm(node) {
615
- var next = node.nextSibling;
616
- if (webkit && mac && cm.display.currentWheelTarget == node) {
617
- node.style.display = "none";
618
- node.lineObj = null;
619
- } else {
620
- node.parentNode.removeChild(node);
621
- }
622
- return next;
623
- }
624
-
625
- var nextIntact = intact.shift(), lineN = from;
626
- cm.doc.iter(from, to, function(line) {
627
- if (nextIntact && nextIntact.to == lineN) nextIntact = intact.shift();
628
- if (lineIsHidden(cm.doc, line)) {
629
- if (line.height != 0) updateLineHeight(line, 0);
630
- if (line.widgets && cur && cur.previousSibling) for (var i = 0; i < line.widgets.length; ++i) {
631
- var w = line.widgets[i];
632
- if (w.showIfHidden) {
633
- var prev = cur.previousSibling;
634
- if (/pre/i.test(prev.nodeName)) {
635
- var wrap = elt("div", null, null, "position: relative");
636
- prev.parentNode.replaceChild(wrap, prev);
637
- wrap.appendChild(prev);
638
- prev = wrap;
639
- }
640
- var wnode = prev.appendChild(elt("div", [w.node], "CodeMirror-linewidget"));
641
- if (!w.handleMouseEvents) wnode.ignoreEvents = true;
642
- positionLineWidget(w, wnode, prev, dims);
643
- }
644
- }
645
- } else if (nextIntact && nextIntact.from <= lineN && nextIntact.to > lineN) {
646
- // This line is intact. Skip to the actual node. Update its
647
- // line number if needed.
648
- while (cur.lineObj != line) cur = rm(cur);
649
- if (lineNumbers && updateNumbersFrom <= lineN && cur.lineNumber)
650
- setTextContent(cur.lineNumber, lineNumberFor(cm.options, lineN));
651
- cur = cur.nextSibling;
652
- } else {
653
- // For lines with widgets, make an attempt to find and reuse
654
- // the existing element, so that widgets aren't needlessly
655
- // removed and re-inserted into the dom
656
- if (line.widgets) for (var j = 0, search = cur, reuse; search && j < 20; ++j, search = search.nextSibling)
657
- if (search.lineObj == line && /div/i.test(search.nodeName)) { reuse = search; break; }
658
- // This line needs to be generated.
659
- var lineNode = buildLineElement(cm, line, lineN, dims, reuse);
660
- if (lineNode != reuse) {
661
- container.insertBefore(lineNode, cur);
662
- } else {
663
- while (cur != reuse) cur = rm(cur);
664
- cur = cur.nextSibling;
665
- }
666
-
667
- lineNode.lineObj = line;
668
- }
669
- ++lineN;
670
- });
671
- while (cur) cur = rm(cur);
672
- }
673
-
674
- function buildLineElement(cm, line, lineNo, dims, reuse) {
675
- var built = buildLineContent(cm, line), lineElement = built.pre;
676
- var markers = line.gutterMarkers, display = cm.display, wrap;
677
-
678
- var bgClass = built.bgClass ? built.bgClass + " " + (line.bgClass || "") : line.bgClass;
679
- if (!cm.options.lineNumbers && !markers && !bgClass && !line.wrapClass && !line.widgets)
680
- return lineElement;
681
-
682
- // Lines with gutter elements, widgets or a background class need
683
- // to be wrapped again, and have the extra elements added to the
684
- // wrapper div
685
-
686
- if (reuse) {
687
- reuse.alignable = null;
688
- var isOk = true, widgetsSeen = 0, insertBefore = null;
689
- for (var n = reuse.firstChild, next; n; n = next) {
690
- next = n.nextSibling;
691
- if (!/\bCodeMirror-linewidget\b/.test(n.className)) {
692
- reuse.removeChild(n);
693
- } else {
694
- for (var i = 0; i < line.widgets.length; ++i) {
695
- var widget = line.widgets[i];
696
- if (widget.node == n.firstChild) {
697
- if (!widget.above && !insertBefore) insertBefore = n;
698
- positionLineWidget(widget, n, reuse, dims);
699
- ++widgetsSeen;
700
- break;
701
- }
702
- }
703
- if (i == line.widgets.length) { isOk = false; break; }
704
- }
705
- }
706
- reuse.insertBefore(lineElement, insertBefore);
707
- if (isOk && widgetsSeen == line.widgets.length) {
708
- wrap = reuse;
709
- reuse.className = line.wrapClass || "";
710
- }
711
- }
712
- if (!wrap) {
713
- wrap = elt("div", null, line.wrapClass, "position: relative");
714
- wrap.appendChild(lineElement);
715
- }
716
- // Kludge to make sure the styled element lies behind the selection (by z-index)
717
- if (bgClass)
718
- wrap.insertBefore(elt("div", null, bgClass + " CodeMirror-linebackground"), wrap.firstChild);
719
- if (cm.options.lineNumbers || markers) {
720
- var gutterWrap = wrap.insertBefore(elt("div", null, null, "position: absolute; left: " +
721
- (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px"),
722
- wrap.firstChild);
723
- if (cm.options.fixedGutter) (wrap.alignable || (wrap.alignable = [])).push(gutterWrap);
724
- if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
725
- wrap.lineNumber = gutterWrap.appendChild(
726
- elt("div", lineNumberFor(cm.options, lineNo),
727
- "CodeMirror-linenumber CodeMirror-gutter-elt",
728
- "left: " + dims.gutterLeft["CodeMirror-linenumbers"] + "px; width: "
729
- + display.lineNumInnerWidth + "px"));
730
- if (markers)
731
- for (var k = 0; k < cm.options.gutters.length; ++k) {
732
- var id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id];
733
- if (found)
734
- gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt", "left: " +
735
- dims.gutterLeft[id] + "px; width: " + dims.gutterWidth[id] + "px"));
736
- }
737
- }
738
- if (ie_lt8) wrap.style.zIndex = 2;
739
- if (line.widgets && wrap != reuse) for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
740
- var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget");
741
- if (!widget.handleMouseEvents) node.ignoreEvents = true;
742
- positionLineWidget(widget, node, wrap, dims);
743
- if (widget.above)
744
- wrap.insertBefore(node, cm.options.lineNumbers && line.height != 0 ? gutterWrap : lineElement);
745
- else
746
- wrap.appendChild(node);
747
- signalLater(widget, "redraw");
748
- }
749
- return wrap;
750
- }
751
-
752
- function positionLineWidget(widget, node, wrap, dims) {
753
- if (widget.noHScroll) {
754
- (wrap.alignable || (wrap.alignable = [])).push(node);
755
- var width = dims.wrapperWidth;
756
- node.style.left = dims.fixedPos + "px";
757
- if (!widget.coverGutter) {
758
- width -= dims.gutterTotalWidth;
759
- node.style.paddingLeft = dims.gutterTotalWidth + "px";
760
- }
761
- node.style.width = width + "px";
762
- }
763
- if (widget.coverGutter) {
764
- node.style.zIndex = 5;
765
- node.style.position = "relative";
766
- if (!widget.noHScroll) node.style.marginLeft = -dims.gutterTotalWidth + "px";
767
- }
768
- }
769
-
770
- // SELECTION / CURSOR
771
-
772
- function updateSelection(cm) {
773
- var display = cm.display;
774
- var collapsed = posEq(cm.doc.sel.from, cm.doc.sel.to);
775
- if (collapsed || cm.options.showCursorWhenSelecting)
776
- updateSelectionCursor(cm);
777
- else
778
- display.cursor.style.display = display.otherCursor.style.display = "none";
779
- if (!collapsed)
780
- updateSelectionRange(cm);
781
- else
782
- display.selectionDiv.style.display = "none";
783
-
784
- // Move the hidden textarea near the cursor to prevent scrolling artifacts
785
- if (cm.options.moveInputWithCursor) {
786
- var headPos = cursorCoords(cm, cm.doc.sel.head, "div");
787
- var wrapOff = getRect(display.wrapper), lineOff = getRect(display.lineDiv);
788
- display.inputDiv.style.top = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
789
- headPos.top + lineOff.top - wrapOff.top)) + "px";
790
- display.inputDiv.style.left = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
791
- headPos.left + lineOff.left - wrapOff.left)) + "px";
792
- }
793
- }
794
-
795
- // No selection, plain cursor
796
- function updateSelectionCursor(cm) {
797
- var display = cm.display, pos = cursorCoords(cm, cm.doc.sel.head, "div");
798
- display.cursor.style.left = pos.left + "px";
799
- display.cursor.style.top = pos.top + "px";
800
- display.cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
801
- display.cursor.style.display = "";
802
-
803
- if (pos.other) {
804
- display.otherCursor.style.display = "";
805
- display.otherCursor.style.left = pos.other.left + "px";
806
- display.otherCursor.style.top = pos.other.top + "px";
807
- display.otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px";
808
- } else { display.otherCursor.style.display = "none"; }
809
- }
810
-
811
- // Highlight selection
812
- function updateSelectionRange(cm) {
813
- var display = cm.display, doc = cm.doc, sel = cm.doc.sel;
814
- var fragment = document.createDocumentFragment();
815
- var clientWidth = display.lineSpace.offsetWidth, pl = paddingLeft(cm.display);
816
-
817
- function add(left, top, width, bottom) {
818
- if (top < 0) top = 0;
819
- fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left +
820
- "px; top: " + top + "px; width: " + (width == null ? clientWidth - left : width) +
821
- "px; height: " + (bottom - top) + "px"));
822
- }
823
-
824
- function drawForLine(line, fromArg, toArg) {
825
- var lineObj = getLine(doc, line);
826
- var lineLen = lineObj.text.length;
827
- var start, end;
828
- function coords(ch, bias) {
829
- return charCoords(cm, Pos(line, ch), "div", lineObj, bias);
830
- }
831
-
832
- iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) {
833
- var leftPos = coords(from, "left"), rightPos, left, right;
834
- if (from == to) {
835
- rightPos = leftPos;
836
- left = right = leftPos.left;
837
- } else {
838
- rightPos = coords(to - 1, "right");
839
- if (dir == "rtl") { var tmp = leftPos; leftPos = rightPos; rightPos = tmp; }
840
- left = leftPos.left;
841
- right = rightPos.right;
842
- }
843
- if (fromArg == null && from == 0) left = pl;
844
- if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
845
- add(left, leftPos.top, null, leftPos.bottom);
846
- left = pl;
847
- if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top);
848
- }
849
- if (toArg == null && to == lineLen) right = clientWidth;
850
- if (!start || leftPos.top < start.top || leftPos.top == start.top && leftPos.left < start.left)
851
- start = leftPos;
852
- if (!end || rightPos.bottom > end.bottom || rightPos.bottom == end.bottom && rightPos.right > end.right)
853
- end = rightPos;
854
- if (left < pl + 1) left = pl;
855
- add(left, rightPos.top, right - left, rightPos.bottom);
856
- });
857
- return {start: start, end: end};
858
- }
859
-
860
- if (sel.from.line == sel.to.line) {
861
- drawForLine(sel.from.line, sel.from.ch, sel.to.ch);
862
- } else {
863
- var fromLine = getLine(doc, sel.from.line), toLine = getLine(doc, sel.to.line);
864
- var singleVLine = visualLine(doc, fromLine) == visualLine(doc, toLine);
865
- var leftEnd = drawForLine(sel.from.line, sel.from.ch, singleVLine ? fromLine.text.length : null).end;
866
- var rightStart = drawForLine(sel.to.line, singleVLine ? 0 : null, sel.to.ch).start;
867
- if (singleVLine) {
868
- if (leftEnd.top < rightStart.top - 2) {
869
- add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
870
- add(pl, rightStart.top, rightStart.left, rightStart.bottom);
871
- } else {
872
- add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
873
- }
874
- }
875
- if (leftEnd.bottom < rightStart.top)
876
- add(pl, leftEnd.bottom, null, rightStart.top);
877
- }
878
-
879
- removeChildrenAndAdd(display.selectionDiv, fragment);
880
- display.selectionDiv.style.display = "";
881
- }
882
-
883
- // Cursor-blinking
884
- function restartBlink(cm) {
885
- if (!cm.state.focused) return;
886
- var display = cm.display;
887
- clearInterval(display.blinker);
888
- var on = true;
889
- display.cursor.style.visibility = display.otherCursor.style.visibility = "";
890
- if (cm.options.cursorBlinkRate > 0)
891
- display.blinker = setInterval(function() {
892
- display.cursor.style.visibility = display.otherCursor.style.visibility = (on = !on) ? "" : "hidden";
893
- }, cm.options.cursorBlinkRate);
894
- }
895
-
896
- // HIGHLIGHT WORKER
897
-
898
- function startWorker(cm, time) {
899
- if (cm.doc.mode.startState && cm.doc.frontier < cm.display.showingTo)
900
- cm.state.highlight.set(time, bind(highlightWorker, cm));
901
- }
902
-
903
- function highlightWorker(cm) {
904
- var doc = cm.doc;
905
- if (doc.frontier < doc.first) doc.frontier = doc.first;
906
- if (doc.frontier >= cm.display.showingTo) return;
907
- var end = +new Date + cm.options.workTime;
908
- var state = copyState(doc.mode, getStateBefore(cm, doc.frontier));
909
- var changed = [], prevChange;
910
- doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.showingTo + 500), function(line) {
911
- if (doc.frontier >= cm.display.showingFrom) { // Visible
912
- var oldStyles = line.styles;
913
- line.styles = highlightLine(cm, line, state, true);
914
- var ischange = !oldStyles || oldStyles.length != line.styles.length;
915
- for (var i = 0; !ischange && i < oldStyles.length; ++i) ischange = oldStyles[i] != line.styles[i];
916
- if (ischange) {
917
- if (prevChange && prevChange.end == doc.frontier) prevChange.end++;
918
- else changed.push(prevChange = {start: doc.frontier, end: doc.frontier + 1});
919
- }
920
- line.stateAfter = copyState(doc.mode, state);
921
- } else {
922
- processLine(cm, line.text, state);
923
- line.stateAfter = doc.frontier % 5 == 0 ? copyState(doc.mode, state) : null;
924
- }
925
- ++doc.frontier;
926
- if (+new Date > end) {
927
- startWorker(cm, cm.options.workDelay);
928
- return true;
929
- }
930
- });
931
- if (changed.length)
932
- operation(cm, function() {
933
- for (var i = 0; i < changed.length; ++i)
934
- regChange(this, changed[i].start, changed[i].end);
935
- })();
936
- }
937
-
938
- // Finds the line to start with when starting a parse. Tries to
939
- // find a line with a stateAfter, so that it can start with a
940
- // valid state. If that fails, it returns the line with the
941
- // smallest indentation, which tends to need the least context to
942
- // parse correctly.
943
- function findStartLine(cm, n, precise) {
944
- var minindent, minline, doc = cm.doc;
945
- var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100);
946
- for (var search = n; search > lim; --search) {
947
- if (search <= doc.first) return doc.first;
948
- var line = getLine(doc, search - 1);
949
- if (line.stateAfter && (!precise || search <= doc.frontier)) return search;
950
- var indented = countColumn(line.text, null, cm.options.tabSize);
951
- if (minline == null || minindent > indented) {
952
- minline = search - 1;
953
- minindent = indented;
954
- }
955
- }
956
- return minline;
957
- }
958
-
959
- function getStateBefore(cm, n, precise) {
960
- var doc = cm.doc, display = cm.display;
961
- if (!doc.mode.startState) return true;
962
- var pos = findStartLine(cm, n, precise), state = pos > doc.first && getLine(doc, pos-1).stateAfter;
963
- if (!state) state = startState(doc.mode);
964
- else state = copyState(doc.mode, state);
965
- doc.iter(pos, n, function(line) {
966
- processLine(cm, line.text, state);
967
- var save = pos == n - 1 || pos % 5 == 0 || pos >= display.showingFrom && pos < display.showingTo;
968
- line.stateAfter = save ? copyState(doc.mode, state) : null;
969
- ++pos;
970
- });
971
- if (precise) doc.frontier = pos;
972
- return state;
973
- }
974
-
975
- // POSITION MEASUREMENT
976
-
977
- function paddingTop(display) {return display.lineSpace.offsetTop;}
978
- function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight;}
979
- function paddingLeft(display) {
980
- var e = removeChildrenAndAdd(display.measure, elt("pre", null, null, "text-align: left")).appendChild(elt("span", "x"));
981
- return e.offsetLeft;
982
- }
983
-
984
- function measureChar(cm, line, ch, data, bias) {
985
- var dir = -1;
986
- data = data || measureLine(cm, line);
987
- if (data.crude) {
988
- var left = data.left + ch * data.width;
989
- return {left: left, right: left + data.width, top: data.top, bottom: data.bottom};
990
- }
991
-
992
- for (var pos = ch;; pos += dir) {
993
- var r = data[pos];
994
- if (r) break;
995
- if (dir < 0 && pos == 0) dir = 1;
996
- }
997
- bias = pos > ch ? "left" : pos < ch ? "right" : bias;
998
- if (bias == "left" && r.leftSide) r = r.leftSide;
999
- else if (bias == "right" && r.rightSide) r = r.rightSide;
1000
- return {left: pos < ch ? r.right : r.left,
1001
- right: pos > ch ? r.left : r.right,
1002
- top: r.top,
1003
- bottom: r.bottom};
1004
- }
1005
-
1006
- function findCachedMeasurement(cm, line) {
1007
- var cache = cm.display.measureLineCache;
1008
- for (var i = 0; i < cache.length; ++i) {
1009
- var memo = cache[i];
1010
- if (memo.text == line.text && memo.markedSpans == line.markedSpans &&
1011
- cm.display.scroller.clientWidth == memo.width &&
1012
- memo.classes == line.textClass + "|" + line.wrapClass)
1013
- return memo;
1014
- }
1015
- }
1016
-
1017
- function clearCachedMeasurement(cm, line) {
1018
- var exists = findCachedMeasurement(cm, line);
1019
- if (exists) exists.text = exists.measure = exists.markedSpans = null;
1020
- }
1021
-
1022
- function measureLine(cm, line) {
1023
- // First look in the cache
1024
- var cached = findCachedMeasurement(cm, line);
1025
- if (cached) return cached.measure;
1026
-
1027
- // Failing that, recompute and store result in cache
1028
- var measure = measureLineInner(cm, line);
1029
- var cache = cm.display.measureLineCache;
1030
- var memo = {text: line.text, width: cm.display.scroller.clientWidth,
1031
- markedSpans: line.markedSpans, measure: measure,
1032
- classes: line.textClass + "|" + line.wrapClass};
1033
- if (cache.length == 16) cache[++cm.display.measureLineCachePos % 16] = memo;
1034
- else cache.push(memo);
1035
- return measure;
1036
- }
1037
-
1038
- function measureLineInner(cm, line) {
1039
- if (!cm.options.lineWrapping && line.text.length >= cm.options.crudeMeasuringFrom)
1040
- return crudelyMeasureLine(cm, line);
1041
-
1042
- var display = cm.display, measure = emptyArray(line.text.length);
1043
- var pre = buildLineContent(cm, line, measure, true).pre;
1044
-
1045
- // IE does not cache element positions of inline elements between
1046
- // calls to getBoundingClientRect. This makes the loop below,
1047
- // which gathers the positions of all the characters on the line,
1048
- // do an amount of layout work quadratic to the number of
1049
- // characters. When line wrapping is off, we try to improve things
1050
- // by first subdividing the line into a bunch of inline blocks, so
1051
- // that IE can reuse most of the layout information from caches
1052
- // for those blocks. This does interfere with line wrapping, so it
1053
- // doesn't work when wrapping is on, but in that case the
1054
- // situation is slightly better, since IE does cache line-wrapping
1055
- // information and only recomputes per-line.
1056
- if (ie && !ie_lt8 && !cm.options.lineWrapping && pre.childNodes.length > 100) {
1057
- var fragment = document.createDocumentFragment();
1058
- var chunk = 10, n = pre.childNodes.length;
1059
- for (var i = 0, chunks = Math.ceil(n / chunk); i < chunks; ++i) {
1060
- var wrap = elt("div", null, null, "display: inline-block");
1061
- for (var j = 0; j < chunk && n; ++j) {
1062
- wrap.appendChild(pre.firstChild);
1063
- --n;
1064
- }
1065
- fragment.appendChild(wrap);
1066
- }
1067
- pre.appendChild(fragment);
1068
- }
1069
-
1070
- removeChildrenAndAdd(display.measure, pre);
1071
-
1072
- var outer = getRect(display.lineDiv);
1073
- var vranges = [], data = emptyArray(line.text.length), maxBot = pre.offsetHeight;
1074
- // Work around an IE7/8 bug where it will sometimes have randomly
1075
- // replaced our pre with a clone at this point.
1076
- if (ie_lt9 && display.measure.first != pre)
1077
- removeChildrenAndAdd(display.measure, pre);
1078
-
1079
- function measureRect(rect) {
1080
- var top = rect.top - outer.top, bot = rect.bottom - outer.top;
1081
- if (bot > maxBot) bot = maxBot;
1082
- if (top < 0) top = 0;
1083
- for (var i = vranges.length - 2; i >= 0; i -= 2) {
1084
- var rtop = vranges[i], rbot = vranges[i+1];
1085
- if (rtop > bot || rbot < top) continue;
1086
- if (rtop <= top && rbot >= bot ||
1087
- top <= rtop && bot >= rbot ||
1088
- Math.min(bot, rbot) - Math.max(top, rtop) >= (bot - top) >> 1) {
1089
- vranges[i] = Math.min(top, rtop);
1090
- vranges[i+1] = Math.max(bot, rbot);
1091
- break;
1092
- }
1093
- }
1094
- if (i < 0) { i = vranges.length; vranges.push(top, bot); }
1095
- return {left: rect.left - outer.left,
1096
- right: rect.right - outer.left,
1097
- top: i, bottom: null};
1098
- }
1099
- function finishRect(rect) {
1100
- rect.bottom = vranges[rect.top+1];
1101
- rect.top = vranges[rect.top];
1102
- }
1103
-
1104
- for (var i = 0, cur; i < measure.length; ++i) if (cur = measure[i]) {
1105
- var node = cur, rect = null;
1106
- // A widget might wrap, needs special care
1107
- if (/\bCodeMirror-widget\b/.test(cur.className) && cur.getClientRects) {
1108
- if (cur.firstChild.nodeType == 1) node = cur.firstChild;
1109
- var rects = node.getClientRects();
1110
- if (rects.length > 1) {
1111
- rect = data[i] = measureRect(rects[0]);
1112
- rect.rightSide = measureRect(rects[rects.length - 1]);
1113
- }
1114
- }
1115
- if (!rect) rect = data[i] = measureRect(getRect(node));
1116
- if (cur.measureRight) rect.right = getRect(cur.measureRight).left;
1117
- if (cur.leftSide) rect.leftSide = measureRect(getRect(cur.leftSide));
1118
- }
1119
- removeChildren(cm.display.measure);
1120
- for (var i = 0, cur; i < data.length; ++i) if (cur = data[i]) {
1121
- finishRect(cur);
1122
- if (cur.leftSide) finishRect(cur.leftSide);
1123
- if (cur.rightSide) finishRect(cur.rightSide);
1124
- }
1125
- return data;
1126
- }
1127
-
1128
- function crudelyMeasureLine(cm, line) {
1129
- var copy = new Line(line.text.slice(0, 100), null);
1130
- if (line.textClass) copy.textClass = line.textClass;
1131
- var measure = measureLineInner(cm, copy);
1132
- var left = measureChar(cm, copy, 0, measure, "left");
1133
- var right = measureChar(cm, copy, 99, measure, "right");
1134
- return {crude: true, top: left.top, left: left.left, bottom: left.bottom, width: (right.right - left.left) / 100};
1135
- }
1136
-
1137
- function measureLineWidth(cm, line) {
1138
- var hasBadSpan = false;
1139
- if (line.markedSpans) for (var i = 0; i < line.markedSpans; ++i) {
1140
- var sp = line.markedSpans[i];
1141
- if (sp.collapsed && (sp.to == null || sp.to == line.text.length)) hasBadSpan = true;
1142
- }
1143
- var cached = !hasBadSpan && findCachedMeasurement(cm, line);
1144
- if (cached || line.text.length >= cm.options.crudeMeasuringFrom)
1145
- return measureChar(cm, line, line.text.length, cached && cached.measure, "right").right;
1146
-
1147
- var pre = buildLineContent(cm, line, null, true).pre;
1148
- var end = pre.appendChild(zeroWidthElement(cm.display.measure));
1149
- removeChildrenAndAdd(cm.display.measure, pre);
1150
- return getRect(end).right - getRect(cm.display.lineDiv).left;
1151
- }
1152
-
1153
- function clearCaches(cm) {
1154
- cm.display.measureLineCache.length = cm.display.measureLineCachePos = 0;
1155
- cm.display.cachedCharWidth = cm.display.cachedTextHeight = null;
1156
- if (!cm.options.lineWrapping) cm.display.maxLineChanged = true;
1157
- cm.display.lineNumChars = null;
1158
- }
1159
-
1160
- function pageScrollX() { return window.pageXOffset || (document.documentElement || document.body).scrollLeft; }
1161
- function pageScrollY() { return window.pageYOffset || (document.documentElement || document.body).scrollTop; }
1162
-
1163
- // Context is one of "line", "div" (display.lineDiv), "local"/null (editor), or "page"
1164
- function intoCoordSystem(cm, lineObj, rect, context) {
1165
- if (lineObj.widgets) for (var i = 0; i < lineObj.widgets.length; ++i) if (lineObj.widgets[i].above) {
1166
- var size = widgetHeight(lineObj.widgets[i]);
1167
- rect.top += size; rect.bottom += size;
1168
- }
1169
- if (context == "line") return rect;
1170
- if (!context) context = "local";
1171
- var yOff = heightAtLine(cm, lineObj);
1172
- if (context == "local") yOff += paddingTop(cm.display);
1173
- else yOff -= cm.display.viewOffset;
1174
- if (context == "page" || context == "window") {
1175
- var lOff = getRect(cm.display.lineSpace);
1176
- yOff += lOff.top + (context == "window" ? 0 : pageScrollY());
1177
- var xOff = lOff.left + (context == "window" ? 0 : pageScrollX());
1178
- rect.left += xOff; rect.right += xOff;
1179
- }
1180
- rect.top += yOff; rect.bottom += yOff;
1181
- return rect;
1182
- }
1183
-
1184
- // Context may be "window", "page", "div", or "local"/null
1185
- // Result is in "div" coords
1186
- function fromCoordSystem(cm, coords, context) {
1187
- if (context == "div") return coords;
1188
- var left = coords.left, top = coords.top;
1189
- // First move into "page" coordinate system
1190
- if (context == "page") {
1191
- left -= pageScrollX();
1192
- top -= pageScrollY();
1193
- } else if (context == "local" || !context) {
1194
- var localBox = getRect(cm.display.sizer);
1195
- left += localBox.left;
1196
- top += localBox.top;
1197
- }
1198
-
1199
- var lineSpaceBox = getRect(cm.display.lineSpace);
1200
- return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top};
1201
- }
1202
-
1203
- function charCoords(cm, pos, context, lineObj, bias) {
1204
- if (!lineObj) lineObj = getLine(cm.doc, pos.line);
1205
- return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, null, bias), context);
1206
- }
1207
-
1208
- function cursorCoords(cm, pos, context, lineObj, measurement) {
1209
- lineObj = lineObj || getLine(cm.doc, pos.line);
1210
- if (!measurement) measurement = measureLine(cm, lineObj);
1211
- function get(ch, right) {
1212
- var m = measureChar(cm, lineObj, ch, measurement, right ? "right" : "left");
1213
- if (right) m.left = m.right; else m.right = m.left;
1214
- return intoCoordSystem(cm, lineObj, m, context);
1215
- }
1216
- function getBidi(ch, partPos) {
1217
- var part = order[partPos], right = part.level % 2;
1218
- if (ch == bidiLeft(part) && partPos && part.level < order[partPos - 1].level) {
1219
- part = order[--partPos];
1220
- ch = bidiRight(part) - (part.level % 2 ? 0 : 1);
1221
- right = true;
1222
- } else if (ch == bidiRight(part) && partPos < order.length - 1 && part.level < order[partPos + 1].level) {
1223
- part = order[++partPos];
1224
- ch = bidiLeft(part) - part.level % 2;
1225
- right = false;
1226
- }
1227
- if (right && ch == part.to && ch > part.from) return get(ch - 1);
1228
- return get(ch, right);
1229
- }
1230
- var order = getOrder(lineObj), ch = pos.ch;
1231
- if (!order) return get(ch);
1232
- var partPos = getBidiPartAt(order, ch);
1233
- var val = getBidi(ch, partPos);
1234
- if (bidiOther != null) val.other = getBidi(ch, bidiOther);
1235
- return val;
1236
- }
1237
-
1238
- function PosWithInfo(line, ch, outside, xRel) {
1239
- var pos = new Pos(line, ch);
1240
- pos.xRel = xRel;
1241
- if (outside) pos.outside = true;
1242
- return pos;
1243
- }
1244
-
1245
- // Coords must be lineSpace-local
1246
- function coordsChar(cm, x, y) {
1247
- var doc = cm.doc;
1248
- y += cm.display.viewOffset;
1249
- if (y < 0) return PosWithInfo(doc.first, 0, true, -1);
1250
- var lineNo = lineAtHeight(doc, y), last = doc.first + doc.size - 1;
1251
- if (lineNo > last)
1252
- return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, true, 1);
1253
- if (x < 0) x = 0;
1254
-
1255
- for (;;) {
1256
- var lineObj = getLine(doc, lineNo);
1257
- var found = coordsCharInner(cm, lineObj, lineNo, x, y);
1258
- var merged = collapsedSpanAtEnd(lineObj);
1259
- var mergedPos = merged && merged.find();
1260
- if (merged && (found.ch > mergedPos.from.ch || found.ch == mergedPos.from.ch && found.xRel > 0))
1261
- lineNo = mergedPos.to.line;
1262
- else
1263
- return found;
1264
- }
1265
- }
1266
-
1267
- function coordsCharInner(cm, lineObj, lineNo, x, y) {
1268
- var innerOff = y - heightAtLine(cm, lineObj);
1269
- var wrongLine = false, adjust = 2 * cm.display.wrapper.clientWidth;
1270
- var measurement = measureLine(cm, lineObj);
1271
-
1272
- function getX(ch) {
1273
- var sp = cursorCoords(cm, Pos(lineNo, ch), "line",
1274
- lineObj, measurement);
1275
- wrongLine = true;
1276
- if (innerOff > sp.bottom) return sp.left - adjust;
1277
- else if (innerOff < sp.top) return sp.left + adjust;
1278
- else wrongLine = false;
1279
- return sp.left;
1280
- }
1281
-
1282
- var bidi = getOrder(lineObj), dist = lineObj.text.length;
1283
- var from = lineLeft(lineObj), to = lineRight(lineObj);
1284
- var fromX = getX(from), fromOutside = wrongLine, toX = getX(to), toOutside = wrongLine;
1285
-
1286
- if (x > toX) return PosWithInfo(lineNo, to, toOutside, 1);
1287
- // Do a binary search between these bounds.
1288
- for (;;) {
1289
- if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) {
1290
- var ch = x < fromX || x - fromX <= toX - x ? from : to;
1291
- var xDiff = x - (ch == from ? fromX : toX);
1292
- while (isExtendingChar.test(lineObj.text.charAt(ch))) ++ch;
1293
- var pos = PosWithInfo(lineNo, ch, ch == from ? fromOutside : toOutside,
1294
- xDiff < 0 ? -1 : xDiff ? 1 : 0);
1295
- return pos;
1296
- }
1297
- var step = Math.ceil(dist / 2), middle = from + step;
1298
- if (bidi) {
1299
- middle = from;
1300
- for (var i = 0; i < step; ++i) middle = moveVisually(lineObj, middle, 1);
1301
- }
1302
- var middleX = getX(middle);
1303
- if (middleX > x) {to = middle; toX = middleX; if (toOutside = wrongLine) toX += 1000; dist = step;}
1304
- else {from = middle; fromX = middleX; fromOutside = wrongLine; dist -= step;}
1305
- }
1306
- }
1307
-
1308
- var measureText;
1309
- function textHeight(display) {
1310
- if (display.cachedTextHeight != null) return display.cachedTextHeight;
1311
- if (measureText == null) {
1312
- measureText = elt("pre");
1313
- // Measure a bunch of lines, for browsers that compute
1314
- // fractional heights.
1315
- for (var i = 0; i < 49; ++i) {
1316
- measureText.appendChild(document.createTextNode("x"));
1317
- measureText.appendChild(elt("br"));
1318
- }
1319
- measureText.appendChild(document.createTextNode("x"));
1320
- }
1321
- removeChildrenAndAdd(display.measure, measureText);
1322
- var height = measureText.offsetHeight / 50;
1323
- if (height > 3) display.cachedTextHeight = height;
1324
- removeChildren(display.measure);
1325
- return height || 1;
1326
- }
1327
-
1328
- function charWidth(display) {
1329
- if (display.cachedCharWidth != null) return display.cachedCharWidth;
1330
- var anchor = elt("span", "x");
1331
- var pre = elt("pre", [anchor]);
1332
- removeChildrenAndAdd(display.measure, pre);
1333
- var width = anchor.offsetWidth;
1334
- if (width > 2) display.cachedCharWidth = width;
1335
- return width || 10;
1336
- }
1337
-
1338
- // OPERATIONS
1339
-
1340
- // Operations are used to wrap changes in such a way that each
1341
- // change won't have to update the cursor and display (which would
1342
- // be awkward, slow, and error-prone), but instead updates are
1343
- // batched and then all combined and executed at once.
1344
-
1345
- var nextOpId = 0;
1346
- function startOperation(cm) {
1347
- cm.curOp = {
1348
- // An array of ranges of lines that have to be updated. See
1349
- // updateDisplay.
1350
- changes: [],
1351
- forceUpdate: false,
1352
- updateInput: null,
1353
- userSelChange: null,
1354
- textChanged: null,
1355
- selectionChanged: false,
1356
- cursorActivity: false,
1357
- updateMaxLine: false,
1358
- updateScrollPos: false,
1359
- id: ++nextOpId
1360
- };
1361
- if (!delayedCallbackDepth++) delayedCallbacks = [];
1362
- }
1363
-
1364
- function endOperation(cm) {
1365
- var op = cm.curOp, doc = cm.doc, display = cm.display;
1366
- cm.curOp = null;
1367
-
1368
- if (op.updateMaxLine) computeMaxLength(cm);
1369
- if (display.maxLineChanged && !cm.options.lineWrapping && display.maxLine) {
1370
- var width = measureLineWidth(cm, display.maxLine);
1371
- display.sizer.style.minWidth = Math.max(0, width + 3 + scrollerCutOff) + "px";
1372
- display.maxLineChanged = false;
1373
- var maxScrollLeft = Math.max(0, display.sizer.offsetLeft + display.sizer.offsetWidth - display.scroller.clientWidth);
1374
- if (maxScrollLeft < doc.scrollLeft && !op.updateScrollPos)
1375
- setScrollLeft(cm, Math.min(display.scroller.scrollLeft, maxScrollLeft), true);
1376
- }
1377
- var newScrollPos, updated;
1378
- if (op.updateScrollPos) {
1379
- newScrollPos = op.updateScrollPos;
1380
- } else if (op.selectionChanged && display.scroller.clientHeight) { // don't rescroll if not visible
1381
- var coords = cursorCoords(cm, doc.sel.head);
1382
- newScrollPos = calculateScrollPos(cm, coords.left, coords.top, coords.left, coords.bottom);
1383
- }
1384
- if (op.changes.length || op.forceUpdate || newScrollPos && newScrollPos.scrollTop != null) {
1385
- updated = updateDisplay(cm, op.changes, newScrollPos && newScrollPos.scrollTop, op.forceUpdate);
1386
- if (cm.display.scroller.offsetHeight) cm.doc.scrollTop = cm.display.scroller.scrollTop;
1387
- }
1388
- if (!updated && op.selectionChanged) updateSelection(cm);
1389
- if (op.updateScrollPos) {
1390
- var top = Math.max(0, Math.min(display.scroller.scrollHeight - display.scroller.clientHeight, newScrollPos.scrollTop));
1391
- var left = Math.max(0, Math.min(display.scroller.scrollWidth - display.scroller.clientWidth, newScrollPos.scrollLeft));
1392
- display.scroller.scrollTop = display.scrollbarV.scrollTop = doc.scrollTop = top;
1393
- display.scroller.scrollLeft = display.scrollbarH.scrollLeft = doc.scrollLeft = left;
1394
- alignHorizontally(cm);
1395
- if (op.scrollToPos)
1396
- scrollPosIntoView(cm, clipPos(cm.doc, op.scrollToPos.from),
1397
- clipPos(cm.doc, op.scrollToPos.to), op.scrollToPos.margin);
1398
- } else if (newScrollPos) {
1399
- scrollCursorIntoView(cm);
1400
- }
1401
- if (op.selectionChanged) restartBlink(cm);
1402
-
1403
- if (cm.state.focused && op.updateInput)
1404
- resetInput(cm, op.userSelChange);
1405
-
1406
- var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers;
1407
- if (hidden) for (var i = 0; i < hidden.length; ++i)
1408
- if (!hidden[i].lines.length) signal(hidden[i], "hide");
1409
- if (unhidden) for (var i = 0; i < unhidden.length; ++i)
1410
- if (unhidden[i].lines.length) signal(unhidden[i], "unhide");
1411
-
1412
- var delayed;
1413
- if (!--delayedCallbackDepth) {
1414
- delayed = delayedCallbacks;
1415
- delayedCallbacks = null;
1416
- }
1417
- if (op.textChanged)
1418
- signal(cm, "change", cm, op.textChanged);
1419
- if (op.cursorActivity) signal(cm, "cursorActivity", cm);
1420
- if (delayed) for (var i = 0; i < delayed.length; ++i) delayed[i]();
1421
- }
1422
-
1423
- // Wraps a function in an operation. Returns the wrapped function.
1424
- function operation(cm1, f) {
1425
- return function() {
1426
- var cm = cm1 || this, withOp = !cm.curOp;
1427
- if (withOp) startOperation(cm);
1428
- try { var result = f.apply(cm, arguments); }
1429
- finally { if (withOp) endOperation(cm); }
1430
- return result;
1431
- };
1432
- }
1433
- function docOperation(f) {
1434
- return function() {
1435
- var withOp = this.cm && !this.cm.curOp, result;
1436
- if (withOp) startOperation(this.cm);
1437
- try { result = f.apply(this, arguments); }
1438
- finally { if (withOp) endOperation(this.cm); }
1439
- return result;
1440
- };
1441
- }
1442
- function runInOp(cm, f) {
1443
- var withOp = !cm.curOp, result;
1444
- if (withOp) startOperation(cm);
1445
- try { result = f(); }
1446
- finally { if (withOp) endOperation(cm); }
1447
- return result;
1448
- }
1449
-
1450
- function regChange(cm, from, to, lendiff) {
1451
- if (from == null) from = cm.doc.first;
1452
- if (to == null) to = cm.doc.first + cm.doc.size;
1453
- cm.curOp.changes.push({from: from, to: to, diff: lendiff});
1454
- }
1455
-
1456
- // INPUT HANDLING
1457
-
1458
- function slowPoll(cm) {
1459
- if (cm.display.pollingFast) return;
1460
- cm.display.poll.set(cm.options.pollInterval, function() {
1461
- readInput(cm);
1462
- if (cm.state.focused) slowPoll(cm);
1463
- });
1464
- }
1465
-
1466
- function fastPoll(cm) {
1467
- var missed = false;
1468
- cm.display.pollingFast = true;
1469
- function p() {
1470
- var changed = readInput(cm);
1471
- if (!changed && !missed) {missed = true; cm.display.poll.set(60, p);}
1472
- else {cm.display.pollingFast = false; slowPoll(cm);}
1473
- }
1474
- cm.display.poll.set(20, p);
1475
- }
1476
-
1477
- // prevInput is a hack to work with IME. If we reset the textarea
1478
- // on every change, that breaks IME. So we look for changes
1479
- // compared to the previous content instead. (Modern browsers have
1480
- // events that indicate IME taking place, but these are not widely
1481
- // supported or compatible enough yet to rely on.)
1482
- function readInput(cm) {
1483
- var input = cm.display.input, prevInput = cm.display.prevInput, doc = cm.doc, sel = doc.sel;
1484
- if (!cm.state.focused || hasSelection(input) || isReadOnly(cm) || cm.state.disableInput) return false;
1485
- if (cm.state.pasteIncoming && cm.state.fakedLastChar) {
1486
- input.value = input.value.substring(0, input.value.length - 1);
1487
- cm.state.fakedLastChar = false;
1488
- }
1489
- var text = input.value;
1490
- if (text == prevInput && posEq(sel.from, sel.to)) return false;
1491
- if (ie && !ie_lt9 && cm.display.inputHasSelection === text) {
1492
- resetInput(cm, true);
1493
- return false;
1494
- }
1495
-
1496
- var withOp = !cm.curOp;
1497
- if (withOp) startOperation(cm);
1498
- sel.shift = false;
1499
- var same = 0, l = Math.min(prevInput.length, text.length);
1500
- while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) ++same;
1501
- var from = sel.from, to = sel.to;
1502
- if (same < prevInput.length)
1503
- from = Pos(from.line, from.ch - (prevInput.length - same));
1504
- else if (cm.state.overwrite && posEq(from, to) && !cm.state.pasteIncoming)
1505
- to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + (text.length - same)));
1506
-
1507
- var updateInput = cm.curOp.updateInput;
1508
- var changeEvent = {from: from, to: to, text: splitLines(text.slice(same)),
1509
- origin: cm.state.pasteIncoming ? "paste" : "+input"};
1510
- makeChange(cm.doc, changeEvent, "end");
1511
- cm.curOp.updateInput = updateInput;
1512
- signalLater(cm, "inputRead", cm, changeEvent);
1513
-
1514
- if (text.length > 1000 || text.indexOf("\n") > -1) input.value = cm.display.prevInput = "";
1515
- else cm.display.prevInput = text;
1516
- if (withOp) endOperation(cm);
1517
- cm.state.pasteIncoming = false;
1518
- return true;
1519
- }
1520
-
1521
- function resetInput(cm, user) {
1522
- var minimal, selected, doc = cm.doc;
1523
- if (!posEq(doc.sel.from, doc.sel.to)) {
1524
- cm.display.prevInput = "";
1525
- minimal = hasCopyEvent &&
1526
- (doc.sel.to.line - doc.sel.from.line > 100 || (selected = cm.getSelection()).length > 1000);
1527
- var content = minimal ? "-" : selected || cm.getSelection();
1528
- cm.display.input.value = content;
1529
- if (cm.state.focused) selectInput(cm.display.input);
1530
- if (ie && !ie_lt9) cm.display.inputHasSelection = content;
1531
- } else if (user) {
1532
- cm.display.prevInput = cm.display.input.value = "";
1533
- if (ie && !ie_lt9) cm.display.inputHasSelection = null;
1534
- }
1535
- cm.display.inaccurateSelection = minimal;
1536
- }
1537
-
1538
- function focusInput(cm) {
1539
- if (cm.options.readOnly != "nocursor" && (!mobile || document.activeElement != cm.display.input))
1540
- cm.display.input.focus();
1541
- }
1542
-
1543
- function isReadOnly(cm) {
1544
- return cm.options.readOnly || cm.doc.cantEdit;
1545
- }
1546
-
1547
- // EVENT HANDLERS
1548
-
1549
- function registerEventHandlers(cm) {
1550
- var d = cm.display;
1551
- on(d.scroller, "mousedown", operation(cm, onMouseDown));
1552
- if (ie)
1553
- on(d.scroller, "dblclick", operation(cm, function(e) {
1554
- if (signalDOMEvent(cm, e)) return;
1555
- var pos = posFromMouse(cm, e);
1556
- if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) return;
1557
- e_preventDefault(e);
1558
- var word = findWordAt(getLine(cm.doc, pos.line).text, pos);
1559
- extendSelection(cm.doc, word.from, word.to);
1560
- }));
1561
- else
1562
- on(d.scroller, "dblclick", function(e) { signalDOMEvent(cm, e) || e_preventDefault(e); });
1563
- on(d.lineSpace, "selectstart", function(e) {
1564
- if (!eventInWidget(d, e)) e_preventDefault(e);
1565
- });
1566
- // Gecko browsers fire contextmenu *after* opening the menu, at
1567
- // which point we can't mess with it anymore. Context menu is
1568
- // handled in onMouseDown for Gecko.
1569
- if (!captureMiddleClick) on(d.scroller, "contextmenu", function(e) {onContextMenu(cm, e);});
1570
-
1571
- on(d.scroller, "scroll", function() {
1572
- if (d.scroller.clientHeight) {
1573
- setScrollTop(cm, d.scroller.scrollTop);
1574
- setScrollLeft(cm, d.scroller.scrollLeft, true);
1575
- signal(cm, "scroll", cm);
1576
- }
1577
- });
1578
- on(d.scrollbarV, "scroll", function() {
1579
- if (d.scroller.clientHeight) setScrollTop(cm, d.scrollbarV.scrollTop);
1580
- });
1581
- on(d.scrollbarH, "scroll", function() {
1582
- if (d.scroller.clientHeight) setScrollLeft(cm, d.scrollbarH.scrollLeft);
1583
- });
1584
-
1585
- on(d.scroller, "mousewheel", function(e){onScrollWheel(cm, e);});
1586
- on(d.scroller, "DOMMouseScroll", function(e){onScrollWheel(cm, e);});
1587
-
1588
- function reFocus() { if (cm.state.focused) setTimeout(bind(focusInput, cm), 0); }
1589
- on(d.scrollbarH, "mousedown", reFocus);
1590
- on(d.scrollbarV, "mousedown", reFocus);
1591
- // Prevent wrapper from ever scrolling
1592
- on(d.wrapper, "scroll", function() { d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; });
1593
-
1594
- var resizeTimer;
1595
- function onResize() {
1596
- if (resizeTimer == null) resizeTimer = setTimeout(function() {
1597
- resizeTimer = null;
1598
- // Might be a text scaling operation, clear size caches.
1599
- d.cachedCharWidth = d.cachedTextHeight = knownScrollbarWidth = null;
1600
- clearCaches(cm);
1601
- runInOp(cm, bind(regChange, cm));
1602
- }, 100);
1603
- }
1604
- on(window, "resize", onResize);
1605
- // Above handler holds on to the editor and its data structures.
1606
- // Here we poll to unregister it when the editor is no longer in
1607
- // the document, so that it can be garbage-collected.
1608
- function unregister() {
1609
- for (var p = d.wrapper.parentNode; p && p != document.body; p = p.parentNode) {}
1610
- if (p) setTimeout(unregister, 5000);
1611
- else off(window, "resize", onResize);
1612
- }
1613
- setTimeout(unregister, 5000);
1614
-
1615
- on(d.input, "keyup", operation(cm, function(e) {
1616
- if (signalDOMEvent(cm, e) || cm.options.onKeyEvent && cm.options.onKeyEvent(cm, addStop(e))) return;
1617
- if (e.keyCode == 16) cm.doc.sel.shift = false;
1618
- }));
1619
- on(d.input, "input", function() {
1620
- if (ie && !ie_lt9 && cm.display.inputHasSelection) cm.display.inputHasSelection = null;
1621
- fastPoll(cm);
1622
- });
1623
- on(d.input, "keydown", operation(cm, onKeyDown));
1624
- on(d.input, "keypress", operation(cm, onKeyPress));
1625
- on(d.input, "focus", bind(onFocus, cm));
1626
- on(d.input, "blur", bind(onBlur, cm));
1627
-
1628
- function drag_(e) {
1629
- if (signalDOMEvent(cm, e) || cm.options.onDragEvent && cm.options.onDragEvent(cm, addStop(e))) return;
1630
- e_stop(e);
1631
- }
1632
- if (cm.options.dragDrop) {
1633
- on(d.scroller, "dragstart", function(e){onDragStart(cm, e);});
1634
- on(d.scroller, "dragenter", drag_);
1635
- on(d.scroller, "dragover", drag_);
1636
- on(d.scroller, "drop", operation(cm, onDrop));
1637
- }
1638
- on(d.scroller, "paste", function(e) {
1639
- if (eventInWidget(d, e)) return;
1640
- focusInput(cm);
1641
- fastPoll(cm);
1642
- });
1643
- on(d.input, "paste", function() {
1644
- // Workaround for webkit bug https://bugs.webkit.org/show_bug.cgi?id=90206
1645
- // Add a char to the end of textarea before paste occur so that
1646
- // selection doesn't span to the end of textarea.
1647
- if (webkit && !cm.state.fakedLastChar && !(new Date - cm.state.lastMiddleDown < 200)) {
1648
- var start = d.input.selectionStart, end = d.input.selectionEnd;
1649
- d.input.value += "$";
1650
- d.input.selectionStart = start;
1651
- d.input.selectionEnd = end;
1652
- cm.state.fakedLastChar = true;
1653
- }
1654
- cm.state.pasteIncoming = true;
1655
- fastPoll(cm);
1656
- });
1657
-
1658
- function prepareCopy() {
1659
- if (d.inaccurateSelection) {
1660
- d.prevInput = "";
1661
- d.inaccurateSelection = false;
1662
- d.input.value = cm.getSelection();
1663
- selectInput(d.input);
1664
- }
1665
- }
1666
- on(d.input, "cut", prepareCopy);
1667
- on(d.input, "copy", prepareCopy);
1668
-
1669
- // Needed to handle Tab key in KHTML
1670
- if (khtml) on(d.sizer, "mouseup", function() {
1671
- if (document.activeElement == d.input) d.input.blur();
1672
- focusInput(cm);
1673
- });
1674
- }
1675
-
1676
- function eventInWidget(display, e) {
1677
- for (var n = e_target(e); n != display.wrapper; n = n.parentNode) {
1678
- if (!n || n.ignoreEvents || n.parentNode == display.sizer && n != display.mover) return true;
1679
- }
1680
- }
1681
-
1682
- function posFromMouse(cm, e, liberal) {
1683
- var display = cm.display;
1684
- if (!liberal) {
1685
- var target = e_target(e);
1686
- if (target == display.scrollbarH || target == display.scrollbarH.firstChild ||
1687
- target == display.scrollbarV || target == display.scrollbarV.firstChild ||
1688
- target == display.scrollbarFiller || target == display.gutterFiller) return null;
1689
- }
1690
- var x, y, space = getRect(display.lineSpace);
1691
- // Fails unpredictably on IE[67] when mouse is dragged around quickly.
1692
- try { x = e.clientX; y = e.clientY; } catch (e) { return null; }
1693
- return coordsChar(cm, x - space.left, y - space.top);
1694
- }
1695
-
1696
- var lastClick, lastDoubleClick;
1697
- function onMouseDown(e) {
1698
- if (signalDOMEvent(this, e)) return;
1699
- var cm = this, display = cm.display, doc = cm.doc, sel = doc.sel;
1700
- sel.shift = e.shiftKey;
1701
-
1702
- if (eventInWidget(display, e)) {
1703
- if (!webkit) {
1704
- display.scroller.draggable = false;
1705
- setTimeout(function(){display.scroller.draggable = true;}, 100);
1706
- }
1707
- return;
1708
- }
1709
- if (clickInGutter(cm, e)) return;
1710
- var start = posFromMouse(cm, e);
1711
-
1712
- switch (e_button(e)) {
1713
- case 3:
1714
- if (captureMiddleClick) onContextMenu.call(cm, cm, e);
1715
- return;
1716
- case 2:
1717
- if (webkit) cm.state.lastMiddleDown = +new Date;
1718
- if (start) extendSelection(cm.doc, start);
1719
- setTimeout(bind(focusInput, cm), 20);
1720
- e_preventDefault(e);
1721
- return;
1722
- }
1723
- // For button 1, if it was clicked inside the editor
1724
- // (posFromMouse returning non-null), we have to adjust the
1725
- // selection.
1726
- if (!start) {if (e_target(e) == display.scroller) e_preventDefault(e); return;}
1727
-
1728
- if (!cm.state.focused) onFocus(cm);
1729
-
1730
- var now = +new Date, type = "single";
1731
- if (lastDoubleClick && lastDoubleClick.time > now - 400 && posEq(lastDoubleClick.pos, start)) {
1732
- type = "triple";
1733
- e_preventDefault(e);
1734
- setTimeout(bind(focusInput, cm), 20);
1735
- selectLine(cm, start.line);
1736
- } else if (lastClick && lastClick.time > now - 400 && posEq(lastClick.pos, start)) {
1737
- type = "double";
1738
- lastDoubleClick = {time: now, pos: start};
1739
- e_preventDefault(e);
1740
- var word = findWordAt(getLine(doc, start.line).text, start);
1741
- extendSelection(cm.doc, word.from, word.to);
1742
- } else { lastClick = {time: now, pos: start}; }
1743
-
1744
- var last = start;
1745
- if (cm.options.dragDrop && dragAndDrop && !isReadOnly(cm) && !posEq(sel.from, sel.to) &&
1746
- !posLess(start, sel.from) && !posLess(sel.to, start) && type == "single") {
1747
- var dragEnd = operation(cm, function(e2) {
1748
- if (webkit) display.scroller.draggable = false;
1749
- cm.state.draggingText = false;
1750
- off(document, "mouseup", dragEnd);
1751
- off(display.scroller, "drop", dragEnd);
1752
- if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) {
1753
- e_preventDefault(e2);
1754
- extendSelection(cm.doc, start);
1755
- focusInput(cm);
1756
- }
1757
- });
1758
- // Let the drag handler handle this.
1759
- if (webkit) display.scroller.draggable = true;
1760
- cm.state.draggingText = dragEnd;
1761
- // IE's approach to draggable
1762
- if (display.scroller.dragDrop) display.scroller.dragDrop();
1763
- on(document, "mouseup", dragEnd);
1764
- on(display.scroller, "drop", dragEnd);
1765
- return;
1766
- }
1767
- e_preventDefault(e);
1768
- if (type == "single") extendSelection(cm.doc, clipPos(doc, start));
1769
-
1770
- var startstart = sel.from, startend = sel.to, lastPos = start;
1771
-
1772
- function doSelect(cur) {
1773
- if (posEq(lastPos, cur)) return;
1774
- lastPos = cur;
1775
-
1776
- if (type == "single") {
1777
- extendSelection(cm.doc, clipPos(doc, start), cur);
1778
- return;
1779
- }
1780
-
1781
- startstart = clipPos(doc, startstart);
1782
- startend = clipPos(doc, startend);
1783
- if (type == "double") {
1784
- var word = findWordAt(getLine(doc, cur.line).text, cur);
1785
- if (posLess(cur, startstart)) extendSelection(cm.doc, word.from, startend);
1786
- else extendSelection(cm.doc, startstart, word.to);
1787
- } else if (type == "triple") {
1788
- if (posLess(cur, startstart)) extendSelection(cm.doc, startend, clipPos(doc, Pos(cur.line, 0)));
1789
- else extendSelection(cm.doc, startstart, clipPos(doc, Pos(cur.line + 1, 0)));
1790
- }
1791
- }
1792
-
1793
- var editorSize = getRect(display.wrapper);
1794
- // Used to ensure timeout re-tries don't fire when another extend
1795
- // happened in the meantime (clearTimeout isn't reliable -- at
1796
- // least on Chrome, the timeouts still happen even when cleared,
1797
- // if the clear happens after their scheduled firing time).
1798
- var counter = 0;
1799
-
1800
- function extend(e) {
1801
- var curCount = ++counter;
1802
- var cur = posFromMouse(cm, e, true);
1803
- if (!cur) return;
1804
- if (!posEq(cur, last)) {
1805
- if (!cm.state.focused) onFocus(cm);
1806
- last = cur;
1807
- doSelect(cur);
1808
- var visible = visibleLines(display, doc);
1809
- if (cur.line >= visible.to || cur.line < visible.from)
1810
- setTimeout(operation(cm, function(){if (counter == curCount) extend(e);}), 150);
1811
- } else {
1812
- var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;
1813
- if (outside) setTimeout(operation(cm, function() {
1814
- if (counter != curCount) return;
1815
- display.scroller.scrollTop += outside;
1816
- extend(e);
1817
- }), 50);
1818
- }
1819
- }
1820
-
1821
- function done(e) {
1822
- counter = Infinity;
1823
- e_preventDefault(e);
1824
- focusInput(cm);
1825
- off(document, "mousemove", move);
1826
- off(document, "mouseup", up);
1827
- }
1828
-
1829
- var move = operation(cm, function(e) {
1830
- if (!ie && !e_button(e)) done(e);
1831
- else extend(e);
1832
- });
1833
- var up = operation(cm, done);
1834
- on(document, "mousemove", move);
1835
- on(document, "mouseup", up);
1836
- }
1837
-
1838
- function gutterEvent(cm, e, type, prevent, signalfn) {
1839
- try { var mX = e.clientX, mY = e.clientY; }
1840
- catch(e) { return false; }
1841
- if (mX >= Math.floor(getRect(cm.display.gutters).right)) return false;
1842
- if (prevent) e_preventDefault(e);
1843
-
1844
- var display = cm.display;
1845
- var lineBox = getRect(display.lineDiv);
1846
-
1847
- if (mY > lineBox.bottom || !hasHandler(cm, type)) return e_defaultPrevented(e);
1848
- mY -= lineBox.top - display.viewOffset;
1849
-
1850
- for (var i = 0; i < cm.options.gutters.length; ++i) {
1851
- var g = display.gutters.childNodes[i];
1852
- if (g && getRect(g).right >= mX) {
1853
- var line = lineAtHeight(cm.doc, mY);
1854
- var gutter = cm.options.gutters[i];
1855
- signalfn(cm, type, cm, line, gutter, e);
1856
- return e_defaultPrevented(e);
1857
- }
1858
- }
1859
- }
1860
-
1861
- function contextMenuInGutter(cm, e) {
1862
- if (!hasHandler(cm, "gutterContextMenu")) return false;
1863
- return gutterEvent(cm, e, "gutterContextMenu", false, signal);
1864
- }
1865
-
1866
- function clickInGutter(cm, e) {
1867
- return gutterEvent(cm, e, "gutterClick", true, signalLater);
1868
- }
1869
-
1870
- // Kludge to work around strange IE behavior where it'll sometimes
1871
- // re-fire a series of drag-related events right after the drop (#1551)
1872
- var lastDrop = 0;
1873
-
1874
- function onDrop(e) {
1875
- var cm = this;
1876
- if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e) || (cm.options.onDragEvent && cm.options.onDragEvent(cm, addStop(e))))
1877
- return;
1878
- e_preventDefault(e);
1879
- if (ie) lastDrop = +new Date;
1880
- var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
1881
- if (!pos || isReadOnly(cm)) return;
1882
- if (files && files.length && window.FileReader && window.File) {
1883
- var n = files.length, text = Array(n), read = 0;
1884
- var loadFile = function(file, i) {
1885
- var reader = new FileReader;
1886
- reader.onload = function() {
1887
- text[i] = reader.result;
1888
- if (++read == n) {
1889
- pos = clipPos(cm.doc, pos);
1890
- makeChange(cm.doc, {from: pos, to: pos, text: splitLines(text.join("\n")), origin: "paste"}, "around");
1891
- }
1892
- };
1893
- reader.readAsText(file);
1894
- };
1895
- for (var i = 0; i < n; ++i) loadFile(files[i], i);
1896
- } else {
1897
- // Don't do a replace if the drop happened inside of the selected text.
1898
- if (cm.state.draggingText && !(posLess(pos, cm.doc.sel.from) || posLess(cm.doc.sel.to, pos))) {
1899
- cm.state.draggingText(e);
1900
- // Ensure the editor is re-focused
1901
- setTimeout(bind(focusInput, cm), 20);
1902
- return;
1903
- }
1904
- try {
1905
- var text = e.dataTransfer.getData("Text");
1906
- if (text) {
1907
- var curFrom = cm.doc.sel.from, curTo = cm.doc.sel.to;
1908
- setSelection(cm.doc, pos, pos);
1909
- if (cm.state.draggingText) replaceRange(cm.doc, "", curFrom, curTo, "paste");
1910
- cm.replaceSelection(text, null, "paste");
1911
- focusInput(cm);
1912
- }
1913
- }
1914
- catch(e){}
1915
- }
1916
- }
1917
-
1918
- function onDragStart(cm, e) {
1919
- if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return; }
1920
- if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) return;
1921
-
1922
- var txt = cm.getSelection();
1923
- e.dataTransfer.setData("Text", txt);
1924
-
1925
- // Use dummy image instead of default browsers image.
1926
- // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
1927
- if (e.dataTransfer.setDragImage && !safari) {
1928
- var img = elt("img", null, null, "position: fixed; left: 0; top: 0;");
1929
- img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
1930
- if (opera) {
1931
- img.width = img.height = 1;
1932
- cm.display.wrapper.appendChild(img);
1933
- // Force a relayout, or Opera won't use our image for some obscure reason
1934
- img._top = img.offsetTop;
1935
- }
1936
- e.dataTransfer.setDragImage(img, 0, 0);
1937
- if (opera) img.parentNode.removeChild(img);
1938
- }
1939
- }
1940
-
1941
- function setScrollTop(cm, val) {
1942
- if (Math.abs(cm.doc.scrollTop - val) < 2) return;
1943
- cm.doc.scrollTop = val;
1944
- if (!gecko) updateDisplay(cm, [], val);
1945
- if (cm.display.scroller.scrollTop != val) cm.display.scroller.scrollTop = val;
1946
- if (cm.display.scrollbarV.scrollTop != val) cm.display.scrollbarV.scrollTop = val;
1947
- if (gecko) updateDisplay(cm, []);
1948
- startWorker(cm, 100);
1949
- }
1950
- function setScrollLeft(cm, val, isScroller) {
1951
- if (isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) return;
1952
- val = Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth);
1953
- cm.doc.scrollLeft = val;
1954
- alignHorizontally(cm);
1955
- if (cm.display.scroller.scrollLeft != val) cm.display.scroller.scrollLeft = val;
1956
- if (cm.display.scrollbarH.scrollLeft != val) cm.display.scrollbarH.scrollLeft = val;
1957
- }
1958
-
1959
- // Since the delta values reported on mouse wheel events are
1960
- // unstandardized between browsers and even browser versions, and
1961
- // generally horribly unpredictable, this code starts by measuring
1962
- // the scroll effect that the first few mouse wheel events have,
1963
- // and, from that, detects the way it can convert deltas to pixel
1964
- // offsets afterwards.
1965
- //
1966
- // The reason we want to know the amount a wheel event will scroll
1967
- // is that it gives us a chance to update the display before the
1968
- // actual scrolling happens, reducing flickering.
1969
-
1970
- var wheelSamples = 0, wheelPixelsPerUnit = null;
1971
- // Fill in a browser-detected starting value on browsers where we
1972
- // know one. These don't have to be accurate -- the result of them
1973
- // being wrong would just be a slight flicker on the first wheel
1974
- // scroll (if it is large enough).
1975
- if (ie) wheelPixelsPerUnit = -.53;
1976
- else if (gecko) wheelPixelsPerUnit = 15;
1977
- else if (chrome) wheelPixelsPerUnit = -.7;
1978
- else if (safari) wheelPixelsPerUnit = -1/3;
1979
-
1980
- function onScrollWheel(cm, e) {
1981
- var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
1982
- if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) dx = e.detail;
1983
- if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) dy = e.detail;
1984
- else if (dy == null) dy = e.wheelDelta;
1985
-
1986
- var display = cm.display, scroll = display.scroller;
1987
- // Quit if there's nothing to scroll here
1988
- if (!(dx && scroll.scrollWidth > scroll.clientWidth ||
1989
- dy && scroll.scrollHeight > scroll.clientHeight)) return;
1990
-
1991
- // Webkit browsers on OS X abort momentum scrolls when the target
1992
- // of the scroll event is removed from the scrollable element.
1993
- // This hack (see related code in patchDisplay) makes sure the
1994
- // element is kept around.
1995
- if (dy && mac && webkit) {
1996
- for (var cur = e.target; cur != scroll; cur = cur.parentNode) {
1997
- if (cur.lineObj) {
1998
- cm.display.currentWheelTarget = cur;
1999
- break;
2000
- }
2001
- }
2002
- }
2003
-
2004
- // On some browsers, horizontal scrolling will cause redraws to
2005
- // happen before the gutter has been realigned, causing it to
2006
- // wriggle around in a most unseemly way. When we have an
2007
- // estimated pixels/delta value, we just handle horizontal
2008
- // scrolling entirely here. It'll be slightly off from native, but
2009
- // better than glitching out.
2010
- if (dx && !gecko && !opera && wheelPixelsPerUnit != null) {
2011
- if (dy)
2012
- setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight)));
2013
- setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth)));
2014
- e_preventDefault(e);
2015
- display.wheelStartX = null; // Abort measurement, if in progress
2016
- return;
2017
- }
2018
-
2019
- if (dy && wheelPixelsPerUnit != null) {
2020
- var pixels = dy * wheelPixelsPerUnit;
2021
- var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight;
2022
- if (pixels < 0) top = Math.max(0, top + pixels - 50);
2023
- else bot = Math.min(cm.doc.height, bot + pixels + 50);
2024
- updateDisplay(cm, [], {top: top, bottom: bot});
2025
- }
2026
-
2027
- if (wheelSamples < 20) {
2028
- if (display.wheelStartX == null) {
2029
- display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop;
2030
- display.wheelDX = dx; display.wheelDY = dy;
2031
- setTimeout(function() {
2032
- if (display.wheelStartX == null) return;
2033
- var movedX = scroll.scrollLeft - display.wheelStartX;
2034
- var movedY = scroll.scrollTop - display.wheelStartY;
2035
- var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
2036
- (movedX && display.wheelDX && movedX / display.wheelDX);
2037
- display.wheelStartX = display.wheelStartY = null;
2038
- if (!sample) return;
2039
- wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
2040
- ++wheelSamples;
2041
- }, 200);
2042
- } else {
2043
- display.wheelDX += dx; display.wheelDY += dy;
2044
- }
2045
- }
2046
- }
2047
-
2048
- function doHandleBinding(cm, bound, dropShift) {
2049
- if (typeof bound == "string") {
2050
- bound = commands[bound];
2051
- if (!bound) return false;
2052
- }
2053
- // Ensure previous input has been read, so that the handler sees a
2054
- // consistent view of the document
2055
- if (cm.display.pollingFast && readInput(cm)) cm.display.pollingFast = false;
2056
- var doc = cm.doc, prevShift = doc.sel.shift, done = false;
2057
- try {
2058
- if (isReadOnly(cm)) cm.state.suppressEdits = true;
2059
- if (dropShift) doc.sel.shift = false;
2060
- done = bound(cm) != Pass;
2061
- } finally {
2062
- doc.sel.shift = prevShift;
2063
- cm.state.suppressEdits = false;
2064
- }
2065
- return done;
2066
- }
2067
-
2068
- function allKeyMaps(cm) {
2069
- var maps = cm.state.keyMaps.slice(0);
2070
- if (cm.options.extraKeys) maps.push(cm.options.extraKeys);
2071
- maps.push(cm.options.keyMap);
2072
- return maps;
2073
- }
2074
-
2075
- var maybeTransition;
2076
- function handleKeyBinding(cm, e) {
2077
- // Handle auto keymap transitions
2078
- var startMap = getKeyMap(cm.options.keyMap), next = startMap.auto;
2079
- clearTimeout(maybeTransition);
2080
- if (next && !isModifierKey(e)) maybeTransition = setTimeout(function() {
2081
- if (getKeyMap(cm.options.keyMap) == startMap) {
2082
- cm.options.keyMap = (next.call ? next.call(null, cm) : next);
2083
- keyMapChanged(cm);
2084
- }
2085
- }, 50);
2086
-
2087
- var name = keyName(e, true), handled = false;
2088
- if (!name) return false;
2089
- var keymaps = allKeyMaps(cm);
2090
-
2091
- if (e.shiftKey) {
2092
- // First try to resolve full name (including 'Shift-'). Failing
2093
- // that, see if there is a cursor-motion command (starting with
2094
- // 'go') bound to the keyname without 'Shift-'.
2095
- handled = lookupKey("Shift-" + name, keymaps, function(b) {return doHandleBinding(cm, b, true);})
2096
- || lookupKey(name, keymaps, function(b) {
2097
- if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
2098
- return doHandleBinding(cm, b);
2099
- });
2100
- } else {
2101
- handled = lookupKey(name, keymaps, function(b) { return doHandleBinding(cm, b); });
2102
- }
2103
-
2104
- if (handled) {
2105
- e_preventDefault(e);
2106
- restartBlink(cm);
2107
- if (ie_lt9) { e.oldKeyCode = e.keyCode; e.keyCode = 0; }
2108
- signalLater(cm, "keyHandled", cm, name, e);
2109
- }
2110
- return handled;
2111
- }
2112
-
2113
- function handleCharBinding(cm, e, ch) {
2114
- var handled = lookupKey("'" + ch + "'", allKeyMaps(cm),
2115
- function(b) { return doHandleBinding(cm, b, true); });
2116
- if (handled) {
2117
- e_preventDefault(e);
2118
- restartBlink(cm);
2119
- signalLater(cm, "keyHandled", cm, "'" + ch + "'", e);
2120
- }
2121
- return handled;
2122
- }
2123
-
2124
- var lastStoppedKey = null;
2125
- function onKeyDown(e) {
2126
- var cm = this;
2127
- if (!cm.state.focused) onFocus(cm);
2128
- if (signalDOMEvent(cm, e) || cm.options.onKeyEvent && cm.options.onKeyEvent(cm, addStop(e))) return;
2129
- if (ie && e.keyCode == 27) e.returnValue = false;
2130
- var code = e.keyCode;
2131
- // IE does strange things with escape.
2132
- cm.doc.sel.shift = code == 16 || e.shiftKey;
2133
- // First give onKeyEvent option a chance to handle this.
2134
- var handled = handleKeyBinding(cm, e);
2135
- if (opera) {
2136
- lastStoppedKey = handled ? code : null;
2137
- // Opera has no cut event... we try to at least catch the key combo
2138
- if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
2139
- cm.replaceSelection("");
2140
- }
2141
- }
2142
-
2143
- function onKeyPress(e) {
2144
- var cm = this;
2145
- if (signalDOMEvent(cm, e) || cm.options.onKeyEvent && cm.options.onKeyEvent(cm, addStop(e))) return;
2146
- var keyCode = e.keyCode, charCode = e.charCode;
2147
- if (opera && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return;}
2148
- if (((opera && (!e.which || e.which < 10)) || khtml) && handleKeyBinding(cm, e)) return;
2149
- var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
2150
- if (this.options.electricChars && this.doc.mode.electricChars &&
2151
- this.options.smartIndent && !isReadOnly(this) &&
2152
- this.doc.mode.electricChars.indexOf(ch) > -1)
2153
- setTimeout(operation(cm, function() {indentLine(cm, cm.doc.sel.to.line, "smart");}), 75);
2154
- if (handleCharBinding(cm, e, ch)) return;
2155
- if (ie && !ie_lt9) cm.display.inputHasSelection = null;
2156
- fastPoll(cm);
2157
- }
2158
-
2159
- function onFocus(cm) {
2160
- if (cm.options.readOnly == "nocursor") return;
2161
- if (!cm.state.focused) {
2162
- signal(cm, "focus", cm);
2163
- cm.state.focused = true;
2164
- if (cm.display.wrapper.className.search(/\bCodeMirror-focused\b/) == -1)
2165
- cm.display.wrapper.className += " CodeMirror-focused";
2166
- if (!cm.curOp) {
2167
- resetInput(cm, true);
2168
- if (webkit) setTimeout(bind(resetInput, cm, true), 0); // Issue #1730
2169
- }
2170
- }
2171
- slowPoll(cm);
2172
- restartBlink(cm);
2173
- }
2174
- function onBlur(cm) {
2175
- if (cm.state.focused) {
2176
- signal(cm, "blur", cm);
2177
- cm.state.focused = false;
2178
- cm.display.wrapper.className = cm.display.wrapper.className.replace(" CodeMirror-focused", "");
2179
- }
2180
- clearInterval(cm.display.blinker);
2181
- setTimeout(function() {if (!cm.state.focused) cm.doc.sel.shift = false;}, 150);
2182
- }
2183
-
2184
- var detectingSelectAll;
2185
- function onContextMenu(cm, e) {
2186
- if (signalDOMEvent(cm, e, "contextmenu")) return;
2187
- var display = cm.display, sel = cm.doc.sel;
2188
- if (eventInWidget(display, e) || contextMenuInGutter(cm, e)) return;
2189
-
2190
- var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
2191
- if (!pos || opera) return; // Opera is difficult.
2192
-
2193
- // Reset the current text selection only if the click is done outside of the selection
2194
- // and 'resetSelectionOnContextMenu' option is true.
2195
- var reset = cm.options.resetSelectionOnContextMenu;
2196
- if (reset && (posEq(sel.from, sel.to) || posLess(pos, sel.from) || !posLess(pos, sel.to)))
2197
- operation(cm, setSelection)(cm.doc, pos, pos);
2198
-
2199
- var oldCSS = display.input.style.cssText;
2200
- display.inputDiv.style.position = "absolute";
2201
- display.input.style.cssText = "position: fixed; width: 30px; height: 30px; top: " + (e.clientY - 5) +
2202
- "px; left: " + (e.clientX - 5) + "px; z-index: 1000; background: white; outline: none;" +
2203
- "border-width: 0; outline: none; overflow: hidden; opacity: .05; -ms-opacity: .05; filter: alpha(opacity=5);";
2204
- focusInput(cm);
2205
- resetInput(cm, true);
2206
- // Adds "Select all" to context menu in FF
2207
- if (posEq(sel.from, sel.to)) display.input.value = display.prevInput = " ";
2208
-
2209
- function prepareSelectAllHack() {
2210
- if (display.input.selectionStart != null) {
2211
- var extval = display.input.value = "\u200b" + (posEq(sel.from, sel.to) ? "" : display.input.value);
2212
- display.prevInput = "\u200b";
2213
- display.input.selectionStart = 1; display.input.selectionEnd = extval.length;
2214
- }
2215
- }
2216
- function rehide() {
2217
- display.inputDiv.style.position = "relative";
2218
- display.input.style.cssText = oldCSS;
2219
- if (ie_lt9) display.scrollbarV.scrollTop = display.scroller.scrollTop = scrollPos;
2220
- slowPoll(cm);
2221
-
2222
- // Try to detect the user choosing select-all
2223
- if (display.input.selectionStart != null) {
2224
- if (!ie || ie_lt9) prepareSelectAllHack();
2225
- clearTimeout(detectingSelectAll);
2226
- var i = 0, poll = function(){
2227
- if (display.prevInput == " " && display.input.selectionStart == 0)
2228
- operation(cm, commands.selectAll)(cm);
2229
- else if (i++ < 10) detectingSelectAll = setTimeout(poll, 500);
2230
- else resetInput(cm);
2231
- };
2232
- detectingSelectAll = setTimeout(poll, 200);
2233
- }
2234
- }
2235
-
2236
- if (ie && !ie_lt9) prepareSelectAllHack();
2237
- if (captureMiddleClick) {
2238
- e_stop(e);
2239
- var mouseup = function() {
2240
- off(window, "mouseup", mouseup);
2241
- setTimeout(rehide, 20);
2242
- };
2243
- on(window, "mouseup", mouseup);
2244
- } else {
2245
- setTimeout(rehide, 50);
2246
- }
2247
- }
2248
-
2249
- // UPDATING
2250
-
2251
- var changeEnd = CodeMirror.changeEnd = function(change) {
2252
- if (!change.text) return change.to;
2253
- return Pos(change.from.line + change.text.length - 1,
2254
- lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0));
2255
- };
2256
-
2257
- // Make sure a position will be valid after the given change.
2258
- function clipPostChange(doc, change, pos) {
2259
- if (!posLess(change.from, pos)) return clipPos(doc, pos);
2260
- var diff = (change.text.length - 1) - (change.to.line - change.from.line);
2261
- if (pos.line > change.to.line + diff) {
2262
- var preLine = pos.line - diff, lastLine = doc.first + doc.size - 1;
2263
- if (preLine > lastLine) return Pos(lastLine, getLine(doc, lastLine).text.length);
2264
- return clipToLen(pos, getLine(doc, preLine).text.length);
2265
- }
2266
- if (pos.line == change.to.line + diff)
2267
- return clipToLen(pos, lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0) +
2268
- getLine(doc, change.to.line).text.length - change.to.ch);
2269
- var inside = pos.line - change.from.line;
2270
- return clipToLen(pos, change.text[inside].length + (inside ? 0 : change.from.ch));
2271
- }
2272
-
2273
- // Hint can be null|"end"|"start"|"around"|{anchor,head}
2274
- function computeSelAfterChange(doc, change, hint) {
2275
- if (hint && typeof hint == "object") // Assumed to be {anchor, head} object
2276
- return {anchor: clipPostChange(doc, change, hint.anchor),
2277
- head: clipPostChange(doc, change, hint.head)};
2278
-
2279
- if (hint == "start") return {anchor: change.from, head: change.from};
2280
-
2281
- var end = changeEnd(change);
2282
- if (hint == "around") return {anchor: change.from, head: end};
2283
- if (hint == "end") return {anchor: end, head: end};
2284
-
2285
- // hint is null, leave the selection alone as much as possible
2286
- var adjustPos = function(pos) {
2287
- if (posLess(pos, change.from)) return pos;
2288
- if (!posLess(change.to, pos)) return end;
2289
-
2290
- var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch;
2291
- if (pos.line == change.to.line) ch += end.ch - change.to.ch;
2292
- return Pos(line, ch);
2293
- };
2294
- return {anchor: adjustPos(doc.sel.anchor), head: adjustPos(doc.sel.head)};
2295
- }
2296
-
2297
- function filterChange(doc, change, update) {
2298
- var obj = {
2299
- canceled: false,
2300
- from: change.from,
2301
- to: change.to,
2302
- text: change.text,
2303
- origin: change.origin,
2304
- cancel: function() { this.canceled = true; }
2305
- };
2306
- if (update) obj.update = function(from, to, text, origin) {
2307
- if (from) this.from = clipPos(doc, from);
2308
- if (to) this.to = clipPos(doc, to);
2309
- if (text) this.text = text;
2310
- if (origin !== undefined) this.origin = origin;
2311
- };
2312
- signal(doc, "beforeChange", doc, obj);
2313
- if (doc.cm) signal(doc.cm, "beforeChange", doc.cm, obj);
2314
-
2315
- if (obj.canceled) return null;
2316
- return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin};
2317
- }
2318
-
2319
- // Replace the range from from to to by the strings in replacement.
2320
- // change is a {from, to, text [, origin]} object
2321
- function makeChange(doc, change, selUpdate, ignoreReadOnly) {
2322
- if (doc.cm) {
2323
- if (!doc.cm.curOp) return operation(doc.cm, makeChange)(doc, change, selUpdate, ignoreReadOnly);
2324
- if (doc.cm.state.suppressEdits) return;
2325
- }
2326
-
2327
- if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
2328
- change = filterChange(doc, change, true);
2329
- if (!change) return;
2330
- }
2331
-
2332
- // Possibly split or suppress the update based on the presence
2333
- // of read-only spans in its range.
2334
- var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to);
2335
- if (split) {
2336
- for (var i = split.length - 1; i >= 1; --i)
2337
- makeChangeNoReadonly(doc, {from: split[i].from, to: split[i].to, text: [""]});
2338
- if (split.length)
2339
- makeChangeNoReadonly(doc, {from: split[0].from, to: split[0].to, text: change.text}, selUpdate);
2340
- } else {
2341
- makeChangeNoReadonly(doc, change, selUpdate);
2342
- }
2343
- }
2344
-
2345
- function makeChangeNoReadonly(doc, change, selUpdate) {
2346
- if (change.text.length == 1 && change.text[0] == "" && posEq(change.from, change.to)) return;
2347
- var selAfter = computeSelAfterChange(doc, change, selUpdate);
2348
- addToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN);
2349
-
2350
- makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change));
2351
- var rebased = [];
2352
-
2353
- linkedDocs(doc, function(doc, sharedHist) {
2354
- if (!sharedHist && indexOf(rebased, doc.history) == -1) {
2355
- rebaseHist(doc.history, change);
2356
- rebased.push(doc.history);
2357
- }
2358
- makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change));
2359
- });
2360
- }
2361
-
2362
- function makeChangeFromHistory(doc, type) {
2363
- if (doc.cm && doc.cm.state.suppressEdits) return;
2364
-
2365
- var hist = doc.history;
2366
- var event = (type == "undo" ? hist.done : hist.undone).pop();
2367
- if (!event) return;
2368
-
2369
- var anti = {changes: [], anchorBefore: event.anchorAfter, headBefore: event.headAfter,
2370
- anchorAfter: event.anchorBefore, headAfter: event.headBefore,
2371
- generation: hist.generation};
2372
- (type == "undo" ? hist.undone : hist.done).push(anti);
2373
- hist.generation = event.generation || ++hist.maxGeneration;
2374
-
2375
- var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange");
2376
-
2377
- for (var i = event.changes.length - 1; i >= 0; --i) {
2378
- var change = event.changes[i];
2379
- change.origin = type;
2380
- if (filter && !filterChange(doc, change, false)) {
2381
- (type == "undo" ? hist.done : hist.undone).length = 0;
2382
- return;
2383
- }
2384
-
2385
- anti.changes.push(historyChangeFromChange(doc, change));
2386
-
2387
- var after = i ? computeSelAfterChange(doc, change, null)
2388
- : {anchor: event.anchorBefore, head: event.headBefore};
2389
- makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change));
2390
- var rebased = [];
2391
-
2392
- linkedDocs(doc, function(doc, sharedHist) {
2393
- if (!sharedHist && indexOf(rebased, doc.history) == -1) {
2394
- rebaseHist(doc.history, change);
2395
- rebased.push(doc.history);
2396
- }
2397
- makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change));
2398
- });
2399
- }
2400
- }
2401
-
2402
- function shiftDoc(doc, distance) {
2403
- function shiftPos(pos) {return Pos(pos.line + distance, pos.ch);}
2404
- doc.first += distance;
2405
- if (doc.cm) regChange(doc.cm, doc.first, doc.first, distance);
2406
- doc.sel.head = shiftPos(doc.sel.head); doc.sel.anchor = shiftPos(doc.sel.anchor);
2407
- doc.sel.from = shiftPos(doc.sel.from); doc.sel.to = shiftPos(doc.sel.to);
2408
- }
2409
-
2410
- function makeChangeSingleDoc(doc, change, selAfter, spans) {
2411
- if (doc.cm && !doc.cm.curOp)
2412
- return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans);
2413
-
2414
- if (change.to.line < doc.first) {
2415
- shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line));
2416
- return;
2417
- }
2418
- if (change.from.line > doc.lastLine()) return;
2419
-
2420
- // Clip the change to the size of this doc
2421
- if (change.from.line < doc.first) {
2422
- var shift = change.text.length - 1 - (doc.first - change.from.line);
2423
- shiftDoc(doc, shift);
2424
- change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
2425
- text: [lst(change.text)], origin: change.origin};
2426
- }
2427
- var last = doc.lastLine();
2428
- if (change.to.line > last) {
2429
- change = {from: change.from, to: Pos(last, getLine(doc, last).text.length),
2430
- text: [change.text[0]], origin: change.origin};
2431
- }
2432
-
2433
- change.removed = getBetween(doc, change.from, change.to);
2434
-
2435
- if (!selAfter) selAfter = computeSelAfterChange(doc, change, null);
2436
- if (doc.cm) makeChangeSingleDocInEditor(doc.cm, change, spans, selAfter);
2437
- else updateDoc(doc, change, spans, selAfter);
2438
- }
2439
-
2440
- function makeChangeSingleDocInEditor(cm, change, spans, selAfter) {
2441
- var doc = cm.doc, display = cm.display, from = change.from, to = change.to;
2442
-
2443
- var recomputeMaxLength = false, checkWidthStart = from.line;
2444
- if (!cm.options.lineWrapping) {
2445
- checkWidthStart = lineNo(visualLine(doc, getLine(doc, from.line)));
2446
- doc.iter(checkWidthStart, to.line + 1, function(line) {
2447
- if (line == display.maxLine) {
2448
- recomputeMaxLength = true;
2449
- return true;
2450
- }
2451
- });
2452
- }
2453
-
2454
- if (!posLess(doc.sel.head, change.from) && !posLess(change.to, doc.sel.head))
2455
- cm.curOp.cursorActivity = true;
2456
-
2457
- updateDoc(doc, change, spans, selAfter, estimateHeight(cm));
2458
-
2459
- if (!cm.options.lineWrapping) {
2460
- doc.iter(checkWidthStart, from.line + change.text.length, function(line) {
2461
- var len = lineLength(doc, line);
2462
- if (len > display.maxLineLength) {
2463
- display.maxLine = line;
2464
- display.maxLineLength = len;
2465
- display.maxLineChanged = true;
2466
- recomputeMaxLength = false;
2467
- }
2468
- });
2469
- if (recomputeMaxLength) cm.curOp.updateMaxLine = true;
2470
- }
2471
-
2472
- // Adjust frontier, schedule worker
2473
- doc.frontier = Math.min(doc.frontier, from.line);
2474
- startWorker(cm, 400);
2475
-
2476
- var lendiff = change.text.length - (to.line - from.line) - 1;
2477
- // Remember that these lines changed, for updating the display
2478
- regChange(cm, from.line, to.line + 1, lendiff);
2479
-
2480
- if (hasHandler(cm, "change")) {
2481
- var changeObj = {from: from, to: to,
2482
- text: change.text,
2483
- removed: change.removed,
2484
- origin: change.origin};
2485
- if (cm.curOp.textChanged) {
2486
- for (var cur = cm.curOp.textChanged; cur.next; cur = cur.next) {}
2487
- cur.next = changeObj;
2488
- } else cm.curOp.textChanged = changeObj;
2489
- }
2490
- }
2491
-
2492
- function replaceRange(doc, code, from, to, origin) {
2493
- if (!to) to = from;
2494
- if (posLess(to, from)) { var tmp = to; to = from; from = tmp; }
2495
- if (typeof code == "string") code = splitLines(code);
2496
- makeChange(doc, {from: from, to: to, text: code, origin: origin}, null);
2497
- }
2498
-
2499
- // POSITION OBJECT
2500
-
2501
- function Pos(line, ch) {
2502
- if (!(this instanceof Pos)) return new Pos(line, ch);
2503
- this.line = line; this.ch = ch;
2504
- }
2505
- CodeMirror.Pos = Pos;
2506
-
2507
- function posEq(a, b) {return a.line == b.line && a.ch == b.ch;}
2508
- function posLess(a, b) {return a.line < b.line || (a.line == b.line && a.ch < b.ch);}
2509
- function copyPos(x) {return Pos(x.line, x.ch);}
2510
-
2511
- // SELECTION
2512
-
2513
- function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1));}
2514
- function clipPos(doc, pos) {
2515
- if (pos.line < doc.first) return Pos(doc.first, 0);
2516
- var last = doc.first + doc.size - 1;
2517
- if (pos.line > last) return Pos(last, getLine(doc, last).text.length);
2518
- return clipToLen(pos, getLine(doc, pos.line).text.length);
2519
- }
2520
- function clipToLen(pos, linelen) {
2521
- var ch = pos.ch;
2522
- if (ch == null || ch > linelen) return Pos(pos.line, linelen);
2523
- else if (ch < 0) return Pos(pos.line, 0);
2524
- else return pos;
2525
- }
2526
- function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size;}
2527
-
2528
- // If shift is held, this will move the selection anchor. Otherwise,
2529
- // it'll set the whole selection.
2530
- function extendSelection(doc, pos, other, bias) {
2531
- if (doc.sel.shift || doc.sel.extend) {
2532
- var anchor = doc.sel.anchor;
2533
- if (other) {
2534
- var posBefore = posLess(pos, anchor);
2535
- if (posBefore != posLess(other, anchor)) {
2536
- anchor = pos;
2537
- pos = other;
2538
- } else if (posBefore != posLess(pos, other)) {
2539
- pos = other;
2540
- }
2541
- }
2542
- setSelection(doc, anchor, pos, bias);
2543
- } else {
2544
- setSelection(doc, pos, other || pos, bias);
2545
- }
2546
- if (doc.cm) doc.cm.curOp.userSelChange = true;
2547
- }
2548
-
2549
- function filterSelectionChange(doc, anchor, head) {
2550
- var obj = {anchor: anchor, head: head};
2551
- signal(doc, "beforeSelectionChange", doc, obj);
2552
- if (doc.cm) signal(doc.cm, "beforeSelectionChange", doc.cm, obj);
2553
- obj.anchor = clipPos(doc, obj.anchor); obj.head = clipPos(doc, obj.head);
2554
- return obj;
2555
- }
2556
-
2557
- // Update the selection. Last two args are only used by
2558
- // updateDoc, since they have to be expressed in the line
2559
- // numbers before the update.
2560
- function setSelection(doc, anchor, head, bias, checkAtomic) {
2561
- if (!checkAtomic && hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange")) {
2562
- var filtered = filterSelectionChange(doc, anchor, head);
2563
- head = filtered.head;
2564
- anchor = filtered.anchor;
2565
- }
2566
-
2567
- var sel = doc.sel;
2568
- sel.goalColumn = null;
2569
- if (bias == null) bias = posLess(head, sel.head) ? -1 : 1;
2570
- // Skip over atomic spans.
2571
- if (checkAtomic || !posEq(anchor, sel.anchor))
2572
- anchor = skipAtomic(doc, anchor, bias, checkAtomic != "push");
2573
- if (checkAtomic || !posEq(head, sel.head))
2574
- head = skipAtomic(doc, head, bias, checkAtomic != "push");
2575
-
2576
- if (posEq(sel.anchor, anchor) && posEq(sel.head, head)) return;
2577
-
2578
- sel.anchor = anchor; sel.head = head;
2579
- var inv = posLess(head, anchor);
2580
- sel.from = inv ? head : anchor;
2581
- sel.to = inv ? anchor : head;
2582
-
2583
- if (doc.cm)
2584
- doc.cm.curOp.updateInput = doc.cm.curOp.selectionChanged =
2585
- doc.cm.curOp.cursorActivity = true;
2586
-
2587
- signalLater(doc, "cursorActivity", doc);
2588
- }
2589
-
2590
- function reCheckSelection(cm) {
2591
- setSelection(cm.doc, cm.doc.sel.from, cm.doc.sel.to, null, "push");
2592
- }
2593
-
2594
- function skipAtomic(doc, pos, bias, mayClear) {
2595
- var flipped = false, curPos = pos;
2596
- var dir = bias || 1;
2597
- doc.cantEdit = false;
2598
- search: for (;;) {
2599
- var line = getLine(doc, curPos.line);
2600
- if (line.markedSpans) {
2601
- for (var i = 0; i < line.markedSpans.length; ++i) {
2602
- var sp = line.markedSpans[i], m = sp.marker;
2603
- if ((sp.from == null || (m.inclusiveLeft ? sp.from <= curPos.ch : sp.from < curPos.ch)) &&
2604
- (sp.to == null || (m.inclusiveRight ? sp.to >= curPos.ch : sp.to > curPos.ch))) {
2605
- if (mayClear) {
2606
- signal(m, "beforeCursorEnter");
2607
- if (m.explicitlyCleared) {
2608
- if (!line.markedSpans) break;
2609
- else {--i; continue;}
2610
- }
2611
- }
2612
- if (!m.atomic) continue;
2613
- var newPos = m.find()[dir < 0 ? "from" : "to"];
2614
- if (posEq(newPos, curPos)) {
2615
- newPos.ch += dir;
2616
- if (newPos.ch < 0) {
2617
- if (newPos.line > doc.first) newPos = clipPos(doc, Pos(newPos.line - 1));
2618
- else newPos = null;
2619
- } else if (newPos.ch > line.text.length) {
2620
- if (newPos.line < doc.first + doc.size - 1) newPos = Pos(newPos.line + 1, 0);
2621
- else newPos = null;
2622
- }
2623
- if (!newPos) {
2624
- if (flipped) {
2625
- // Driven in a corner -- no valid cursor position found at all
2626
- // -- try again *with* clearing, if we didn't already
2627
- if (!mayClear) return skipAtomic(doc, pos, bias, true);
2628
- // Otherwise, turn off editing until further notice, and return the start of the doc
2629
- doc.cantEdit = true;
2630
- return Pos(doc.first, 0);
2631
- }
2632
- flipped = true; newPos = pos; dir = -dir;
2633
- }
2634
- }
2635
- curPos = newPos;
2636
- continue search;
2637
- }
2638
- }
2639
- }
2640
- return curPos;
2641
- }
2642
- }
2643
-
2644
- // SCROLLING
2645
-
2646
- function scrollCursorIntoView(cm) {
2647
- var coords = scrollPosIntoView(cm, cm.doc.sel.head, null, cm.options.cursorScrollMargin);
2648
- if (!cm.state.focused) return;
2649
- var display = cm.display, box = getRect(display.sizer), doScroll = null;
2650
- if (coords.top + box.top < 0) doScroll = true;
2651
- else if (coords.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) doScroll = false;
2652
- if (doScroll != null && !phantom) {
2653
- var hidden = display.cursor.style.display == "none";
2654
- if (hidden) {
2655
- display.cursor.style.display = "";
2656
- display.cursor.style.left = coords.left + "px";
2657
- display.cursor.style.top = (coords.top - display.viewOffset) + "px";
2658
- }
2659
- display.cursor.scrollIntoView(doScroll);
2660
- if (hidden) display.cursor.style.display = "none";
2661
- }
2662
- }
2663
-
2664
- function scrollPosIntoView(cm, pos, end, margin) {
2665
- if (margin == null) margin = 0;
2666
- for (;;) {
2667
- var changed = false, coords = cursorCoords(cm, pos);
2668
- var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
2669
- var scrollPos = calculateScrollPos(cm, Math.min(coords.left, endCoords.left),
2670
- Math.min(coords.top, endCoords.top) - margin,
2671
- Math.max(coords.left, endCoords.left),
2672
- Math.max(coords.bottom, endCoords.bottom) + margin);
2673
- var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft;
2674
- if (scrollPos.scrollTop != null) {
2675
- setScrollTop(cm, scrollPos.scrollTop);
2676
- if (Math.abs(cm.doc.scrollTop - startTop) > 1) changed = true;
2677
- }
2678
- if (scrollPos.scrollLeft != null) {
2679
- setScrollLeft(cm, scrollPos.scrollLeft);
2680
- if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) changed = true;
2681
- }
2682
- if (!changed) return coords;
2683
- }
2684
- }
2685
-
2686
- function scrollIntoView(cm, x1, y1, x2, y2) {
2687
- var scrollPos = calculateScrollPos(cm, x1, y1, x2, y2);
2688
- if (scrollPos.scrollTop != null) setScrollTop(cm, scrollPos.scrollTop);
2689
- if (scrollPos.scrollLeft != null) setScrollLeft(cm, scrollPos.scrollLeft);
2690
- }
2691
-
2692
- function calculateScrollPos(cm, x1, y1, x2, y2) {
2693
- var display = cm.display, snapMargin = textHeight(cm.display);
2694
- if (y1 < 0) y1 = 0;
2695
- var screen = display.scroller.clientHeight - scrollerCutOff, screentop = display.scroller.scrollTop, result = {};
2696
- var docBottom = cm.doc.height + paddingVert(display);
2697
- var atTop = y1 < snapMargin, atBottom = y2 > docBottom - snapMargin;
2698
- if (y1 < screentop) {
2699
- result.scrollTop = atTop ? 0 : y1;
2700
- } else if (y2 > screentop + screen) {
2701
- var newTop = Math.min(y1, (atBottom ? docBottom : y2) - screen);
2702
- if (newTop != screentop) result.scrollTop = newTop;
2703
- }
2704
-
2705
- var screenw = display.scroller.clientWidth - scrollerCutOff, screenleft = display.scroller.scrollLeft;
2706
- x1 += display.gutters.offsetWidth; x2 += display.gutters.offsetWidth;
2707
- var gutterw = display.gutters.offsetWidth;
2708
- var atLeft = x1 < gutterw + 10;
2709
- if (x1 < screenleft + gutterw || atLeft) {
2710
- if (atLeft) x1 = 0;
2711
- result.scrollLeft = Math.max(0, x1 - 10 - gutterw);
2712
- } else if (x2 > screenw + screenleft - 3) {
2713
- result.scrollLeft = x2 + 10 - screenw;
2714
- }
2715
- return result;
2716
- }
2717
-
2718
- function updateScrollPos(cm, left, top) {
2719
- cm.curOp.updateScrollPos = {scrollLeft: left == null ? cm.doc.scrollLeft : left,
2720
- scrollTop: top == null ? cm.doc.scrollTop : top};
2721
- }
2722
-
2723
- function addToScrollPos(cm, left, top) {
2724
- var pos = cm.curOp.updateScrollPos || (cm.curOp.updateScrollPos = {scrollLeft: cm.doc.scrollLeft, scrollTop: cm.doc.scrollTop});
2725
- var scroll = cm.display.scroller;
2726
- pos.scrollTop = Math.max(0, Math.min(scroll.scrollHeight - scroll.clientHeight, pos.scrollTop + top));
2727
- pos.scrollLeft = Math.max(0, Math.min(scroll.scrollWidth - scroll.clientWidth, pos.scrollLeft + left));
2728
- }
2729
-
2730
- // API UTILITIES
2731
-
2732
- function indentLine(cm, n, how, aggressive) {
2733
- var doc = cm.doc;
2734
- if (how == null) how = "add";
2735
- if (how == "smart") {
2736
- if (!cm.doc.mode.indent) how = "prev";
2737
- else var state = getStateBefore(cm, n);
2738
- }
2739
-
2740
- var tabSize = cm.options.tabSize;
2741
- var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
2742
- var curSpaceString = line.text.match(/^\s*/)[0], indentation;
2743
- if (how == "smart") {
2744
- indentation = cm.doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
2745
- if (indentation == Pass) {
2746
- if (!aggressive) return;
2747
- how = "prev";
2748
- }
2749
- }
2750
- if (how == "prev") {
2751
- if (n > doc.first) indentation = countColumn(getLine(doc, n-1).text, null, tabSize);
2752
- else indentation = 0;
2753
- } else if (how == "add") {
2754
- indentation = curSpace + cm.options.indentUnit;
2755
- } else if (how == "subtract") {
2756
- indentation = curSpace - cm.options.indentUnit;
2757
- } else if (typeof how == "number") {
2758
- indentation = curSpace + how;
2759
- }
2760
- indentation = Math.max(0, indentation);
2761
-
2762
- var indentString = "", pos = 0;
2763
- if (cm.options.indentWithTabs)
2764
- for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";}
2765
- if (pos < indentation) indentString += spaceStr(indentation - pos);
2766
-
2767
- if (indentString != curSpaceString)
2768
- replaceRange(cm.doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input");
2769
- else if (doc.sel.head.line == n && doc.sel.head.ch < curSpaceString.length)
2770
- setSelection(doc, Pos(n, curSpaceString.length), Pos(n, curSpaceString.length), 1);
2771
- line.stateAfter = null;
2772
- }
2773
-
2774
- function changeLine(cm, handle, op) {
2775
- var no = handle, line = handle, doc = cm.doc;
2776
- if (typeof handle == "number") line = getLine(doc, clipLine(doc, handle));
2777
- else no = lineNo(handle);
2778
- if (no == null) return null;
2779
- if (op(line, no)) regChange(cm, no, no + 1);
2780
- else return null;
2781
- return line;
2782
- }
2783
-
2784
- function findPosH(doc, pos, dir, unit, visually) {
2785
- var line = pos.line, ch = pos.ch, origDir = dir;
2786
- var lineObj = getLine(doc, line);
2787
- var possible = true;
2788
- function findNextLine() {
2789
- var l = line + dir;
2790
- if (l < doc.first || l >= doc.first + doc.size) return (possible = false);
2791
- line = l;
2792
- return lineObj = getLine(doc, l);
2793
- }
2794
- function moveOnce(boundToLine) {
2795
- var next = (visually ? moveVisually : moveLogically)(lineObj, ch, dir, true);
2796
- if (next == null) {
2797
- if (!boundToLine && findNextLine()) {
2798
- if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj);
2799
- else ch = dir < 0 ? lineObj.text.length : 0;
2800
- } else return (possible = false);
2801
- } else ch = next;
2802
- return true;
2803
- }
2804
-
2805
- if (unit == "char") moveOnce();
2806
- else if (unit == "column") moveOnce(true);
2807
- else if (unit == "word" || unit == "group") {
2808
- var sawType = null, group = unit == "group";
2809
- for (var first = true;; first = false) {
2810
- if (dir < 0 && !moveOnce(!first)) break;
2811
- var cur = lineObj.text.charAt(ch) || "\n";
2812
- var type = isWordChar(cur) ? "w"
2813
- : !group ? null
2814
- : /\s/.test(cur) ? null
2815
- : "p";
2816
- if (sawType && sawType != type) {
2817
- if (dir < 0) {dir = 1; moveOnce();}
2818
- break;
2819
- }
2820
- if (type) sawType = type;
2821
- if (dir > 0 && !moveOnce(!first)) break;
2822
- }
2823
- }
2824
- var result = skipAtomic(doc, Pos(line, ch), origDir, true);
2825
- if (!possible) result.hitSide = true;
2826
- return result;
2827
- }
2828
-
2829
- function findPosV(cm, pos, dir, unit) {
2830
- var doc = cm.doc, x = pos.left, y;
2831
- if (unit == "page") {
2832
- var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
2833
- y = pos.top + dir * (pageSize - (dir < 0 ? 1.5 : .5) * textHeight(cm.display));
2834
- } else if (unit == "line") {
2835
- y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
2836
- }
2837
- for (;;) {
2838
- var target = coordsChar(cm, x, y);
2839
- if (!target.outside) break;
2840
- if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break; }
2841
- y += dir * 5;
2842
- }
2843
- return target;
2844
- }
2845
-
2846
- function findWordAt(line, pos) {
2847
- var start = pos.ch, end = pos.ch;
2848
- if (line) {
2849
- if ((pos.xRel < 0 || end == line.length) && start) --start; else ++end;
2850
- var startChar = line.charAt(start);
2851
- var check = isWordChar(startChar) ? isWordChar
2852
- : /\s/.test(startChar) ? function(ch) {return /\s/.test(ch);}
2853
- : function(ch) {return !/\s/.test(ch) && !isWordChar(ch);};
2854
- while (start > 0 && check(line.charAt(start - 1))) --start;
2855
- while (end < line.length && check(line.charAt(end))) ++end;
2856
- }
2857
- return {from: Pos(pos.line, start), to: Pos(pos.line, end)};
2858
- }
2859
-
2860
- function selectLine(cm, line) {
2861
- extendSelection(cm.doc, Pos(line, 0), clipPos(cm.doc, Pos(line + 1, 0)));
2862
- }
2863
-
2864
- // PROTOTYPE
2865
-
2866
- // The publicly visible API. Note that operation(null, f) means
2867
- // 'wrap f in an operation, performed on its `this` parameter'
2868
-
2869
- CodeMirror.prototype = {
2870
- constructor: CodeMirror,
2871
- focus: function(){window.focus(); focusInput(this); fastPoll(this);},
2872
-
2873
- setOption: function(option, value) {
2874
- var options = this.options, old = options[option];
2875
- if (options[option] == value && option != "mode") return;
2876
- options[option] = value;
2877
- if (optionHandlers.hasOwnProperty(option))
2878
- operation(this, optionHandlers[option])(this, value, old);
2879
- },
2880
-
2881
- getOption: function(option) {return this.options[option];},
2882
- getDoc: function() {return this.doc;},
2883
-
2884
- addKeyMap: function(map, bottom) {
2885
- this.state.keyMaps[bottom ? "push" : "unshift"](map);
2886
- },
2887
- removeKeyMap: function(map) {
2888
- var maps = this.state.keyMaps;
2889
- for (var i = 0; i < maps.length; ++i)
2890
- if (maps[i] == map || (typeof maps[i] != "string" && maps[i].name == map)) {
2891
- maps.splice(i, 1);
2892
- return true;
2893
- }
2894
- },
2895
-
2896
- addOverlay: operation(null, function(spec, options) {
2897
- var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec);
2898
- if (mode.startState) throw new Error("Overlays may not be stateful.");
2899
- this.state.overlays.push({mode: mode, modeSpec: spec, opaque: options && options.opaque});
2900
- this.state.modeGen++;
2901
- regChange(this);
2902
- }),
2903
- removeOverlay: operation(null, function(spec) {
2904
- var overlays = this.state.overlays;
2905
- for (var i = 0; i < overlays.length; ++i) {
2906
- var cur = overlays[i].modeSpec;
2907
- if (cur == spec || typeof spec == "string" && cur.name == spec) {
2908
- overlays.splice(i, 1);
2909
- this.state.modeGen++;
2910
- regChange(this);
2911
- return;
2912
- }
2913
- }
2914
- }),
2915
-
2916
- indentLine: operation(null, function(n, dir, aggressive) {
2917
- if (typeof dir != "string" && typeof dir != "number") {
2918
- if (dir == null) dir = this.options.smartIndent ? "smart" : "prev";
2919
- else dir = dir ? "add" : "subtract";
2920
- }
2921
- if (isLine(this.doc, n)) indentLine(this, n, dir, aggressive);
2922
- }),
2923
- indentSelection: operation(null, function(how) {
2924
- var sel = this.doc.sel;
2925
- if (posEq(sel.from, sel.to)) return indentLine(this, sel.from.line, how);
2926
- var e = sel.to.line - (sel.to.ch ? 0 : 1);
2927
- for (var i = sel.from.line; i <= e; ++i) indentLine(this, i, how);
2928
- }),
2929
-
2930
- // Fetch the parser token for a given character. Useful for hacks
2931
- // that want to inspect the mode state (say, for completion).
2932
- getTokenAt: function(pos, precise) {
2933
- var doc = this.doc;
2934
- pos = clipPos(doc, pos);
2935
- var state = getStateBefore(this, pos.line, precise), mode = this.doc.mode;
2936
- var line = getLine(doc, pos.line);
2937
- var stream = new StringStream(line.text, this.options.tabSize);
2938
- while (stream.pos < pos.ch && !stream.eol()) {
2939
- stream.start = stream.pos;
2940
- var style = mode.token(stream, state);
2941
- }
2942
- return {start: stream.start,
2943
- end: stream.pos,
2944
- string: stream.current(),
2945
- className: style || null, // Deprecated, use 'type' instead
2946
- type: style || null,
2947
- state: state};
2948
- },
2949
-
2950
- getTokenTypeAt: function(pos) {
2951
- pos = clipPos(this.doc, pos);
2952
- var styles = getLineStyles(this, getLine(this.doc, pos.line));
2953
- var before = 0, after = (styles.length - 1) / 2, ch = pos.ch;
2954
- if (ch == 0) return styles[2];
2955
- for (;;) {
2956
- var mid = (before + after) >> 1;
2957
- if ((mid ? styles[mid * 2 - 1] : 0) >= ch) after = mid;
2958
- else if (styles[mid * 2 + 1] < ch) before = mid + 1;
2959
- else return styles[mid * 2 + 2];
2960
- }
2961
- },
2962
-
2963
- getModeAt: function(pos) {
2964
- var mode = this.doc.mode;
2965
- if (!mode.innerMode) return mode;
2966
- return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode;
2967
- },
2968
-
2969
- getHelper: function(pos, type) {
2970
- if (!helpers.hasOwnProperty(type)) return;
2971
- var help = helpers[type], mode = this.getModeAt(pos);
2972
- return mode[type] && help[mode[type]] ||
2973
- mode.helperType && help[mode.helperType] ||
2974
- help[mode.name];
2975
- },
2976
-
2977
- getStateAfter: function(line, precise) {
2978
- var doc = this.doc;
2979
- line = clipLine(doc, line == null ? doc.first + doc.size - 1: line);
2980
- return getStateBefore(this, line + 1, precise);
2981
- },
2982
-
2983
- cursorCoords: function(start, mode) {
2984
- var pos, sel = this.doc.sel;
2985
- if (start == null) pos = sel.head;
2986
- else if (typeof start == "object") pos = clipPos(this.doc, start);
2987
- else pos = start ? sel.from : sel.to;
2988
- return cursorCoords(this, pos, mode || "page");
2989
- },
2990
-
2991
- charCoords: function(pos, mode) {
2992
- return charCoords(this, clipPos(this.doc, pos), mode || "page");
2993
- },
2994
-
2995
- coordsChar: function(coords, mode) {
2996
- coords = fromCoordSystem(this, coords, mode || "page");
2997
- return coordsChar(this, coords.left, coords.top);
2998
- },
2999
-
3000
- lineAtHeight: function(height, mode) {
3001
- height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top;
3002
- return lineAtHeight(this.doc, height + this.display.viewOffset);
3003
- },
3004
- heightAtLine: function(line, mode) {
3005
- var end = false, last = this.doc.first + this.doc.size - 1;
3006
- if (line < this.doc.first) line = this.doc.first;
3007
- else if (line > last) { line = last; end = true; }
3008
- var lineObj = getLine(this.doc, line);
3009
- return intoCoordSystem(this, getLine(this.doc, line), {top: 0, left: 0}, mode || "page").top +
3010
- (end ? lineObj.height : 0);
3011
- },
3012
-
3013
- defaultTextHeight: function() { return textHeight(this.display); },
3014
- defaultCharWidth: function() { return charWidth(this.display); },
3015
-
3016
- setGutterMarker: operation(null, function(line, gutterID, value) {
3017
- return changeLine(this, line, function(line) {
3018
- var markers = line.gutterMarkers || (line.gutterMarkers = {});
3019
- markers[gutterID] = value;
3020
- if (!value && isEmpty(markers)) line.gutterMarkers = null;
3021
- return true;
3022
- });
3023
- }),
3024
-
3025
- clearGutter: operation(null, function(gutterID) {
3026
- var cm = this, doc = cm.doc, i = doc.first;
3027
- doc.iter(function(line) {
3028
- if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
3029
- line.gutterMarkers[gutterID] = null;
3030
- regChange(cm, i, i + 1);
3031
- if (isEmpty(line.gutterMarkers)) line.gutterMarkers = null;
3032
- }
3033
- ++i;
3034
- });
3035
- }),
3036
-
3037
- addLineClass: operation(null, function(handle, where, cls) {
3038
- return changeLine(this, handle, function(line) {
3039
- var prop = where == "text" ? "textClass" : where == "background" ? "bgClass" : "wrapClass";
3040
- if (!line[prop]) line[prop] = cls;
3041
- else if (new RegExp("(?:^|\\s)" + cls + "(?:$|\\s)").test(line[prop])) return false;
3042
- else line[prop] += " " + cls;
3043
- return true;
3044
- });
3045
- }),
3046
-
3047
- removeLineClass: operation(null, function(handle, where, cls) {
3048
- return changeLine(this, handle, function(line) {
3049
- var prop = where == "text" ? "textClass" : where == "background" ? "bgClass" : "wrapClass";
3050
- var cur = line[prop];
3051
- if (!cur) return false;
3052
- else if (cls == null) line[prop] = null;
3053
- else {
3054
- var found = cur.match(new RegExp("(?:^|\\s+)" + cls + "(?:$|\\s+)"));
3055
- if (!found) return false;
3056
- var end = found.index + found[0].length;
3057
- line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null;
3058
- }
3059
- return true;
3060
- });
3061
- }),
3062
-
3063
- addLineWidget: operation(null, function(handle, node, options) {
3064
- return addLineWidget(this, handle, node, options);
3065
- }),
3066
-
3067
- removeLineWidget: function(widget) { widget.clear(); },
3068
-
3069
- lineInfo: function(line) {
3070
- if (typeof line == "number") {
3071
- if (!isLine(this.doc, line)) return null;
3072
- var n = line;
3073
- line = getLine(this.doc, line);
3074
- if (!line) return null;
3075
- } else {
3076
- var n = lineNo(line);
3077
- if (n == null) return null;
3078
- }
3079
- return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
3080
- textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
3081
- widgets: line.widgets};
3082
- },
3083
-
3084
- getViewport: function() { return {from: this.display.showingFrom, to: this.display.showingTo};},
3085
-
3086
- addWidget: function(pos, node, scroll, vert, horiz) {
3087
- var display = this.display;
3088
- pos = cursorCoords(this, clipPos(this.doc, pos));
3089
- var top = pos.bottom, left = pos.left;
3090
- node.style.position = "absolute";
3091
- display.sizer.appendChild(node);
3092
- if (vert == "over") {
3093
- top = pos.top;
3094
- } else if (vert == "above" || vert == "near") {
3095
- var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),
3096
- hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth);
3097
- // Default to positioning above (if specified and possible); otherwise default to positioning below
3098
- if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight)
3099
- top = pos.top - node.offsetHeight;
3100
- else if (pos.bottom + node.offsetHeight <= vspace)
3101
- top = pos.bottom;
3102
- if (left + node.offsetWidth > hspace)
3103
- left = hspace - node.offsetWidth;
3104
- }
3105
- node.style.top = top + "px";
3106
- node.style.left = node.style.right = "";
3107
- if (horiz == "right") {
3108
- left = display.sizer.clientWidth - node.offsetWidth;
3109
- node.style.right = "0px";
3110
- } else {
3111
- if (horiz == "left") left = 0;
3112
- else if (horiz == "middle") left = (display.sizer.clientWidth - node.offsetWidth) / 2;
3113
- node.style.left = left + "px";
3114
- }
3115
- if (scroll)
3116
- scrollIntoView(this, left, top, left + node.offsetWidth, top + node.offsetHeight);
3117
- },
3118
-
3119
- triggerOnKeyDown: operation(null, onKeyDown),
3120
-
3121
- execCommand: function(cmd) {return commands[cmd](this);},
3122
-
3123
- findPosH: function(from, amount, unit, visually) {
3124
- var dir = 1;
3125
- if (amount < 0) { dir = -1; amount = -amount; }
3126
- for (var i = 0, cur = clipPos(this.doc, from); i < amount; ++i) {
3127
- cur = findPosH(this.doc, cur, dir, unit, visually);
3128
- if (cur.hitSide) break;
3129
- }
3130
- return cur;
3131
- },
3132
-
3133
- moveH: operation(null, function(dir, unit) {
3134
- var sel = this.doc.sel, pos;
3135
- if (sel.shift || sel.extend || posEq(sel.from, sel.to))
3136
- pos = findPosH(this.doc, sel.head, dir, unit, this.options.rtlMoveVisually);
3137
- else
3138
- pos = dir < 0 ? sel.from : sel.to;
3139
- extendSelection(this.doc, pos, pos, dir);
3140
- }),
3141
-
3142
- deleteH: operation(null, function(dir, unit) {
3143
- var sel = this.doc.sel;
3144
- if (!posEq(sel.from, sel.to)) replaceRange(this.doc, "", sel.from, sel.to, "+delete");
3145
- else replaceRange(this.doc, "", sel.from, findPosH(this.doc, sel.head, dir, unit, false), "+delete");
3146
- this.curOp.userSelChange = true;
3147
- }),
3148
-
3149
- findPosV: function(from, amount, unit, goalColumn) {
3150
- var dir = 1, x = goalColumn;
3151
- if (amount < 0) { dir = -1; amount = -amount; }
3152
- for (var i = 0, cur = clipPos(this.doc, from); i < amount; ++i) {
3153
- var coords = cursorCoords(this, cur, "div");
3154
- if (x == null) x = coords.left;
3155
- else coords.left = x;
3156
- cur = findPosV(this, coords, dir, unit);
3157
- if (cur.hitSide) break;
3158
- }
3159
- return cur;
3160
- },
3161
-
3162
- moveV: operation(null, function(dir, unit) {
3163
- var sel = this.doc.sel;
3164
- var pos = cursorCoords(this, sel.head, "div");
3165
- if (sel.goalColumn != null) pos.left = sel.goalColumn;
3166
- var target = findPosV(this, pos, dir, unit);
3167
-
3168
- if (unit == "page") addToScrollPos(this, 0, charCoords(this, target, "div").top - pos.top);
3169
- extendSelection(this.doc, target, target, dir);
3170
- sel.goalColumn = pos.left;
3171
- }),
3172
-
3173
- toggleOverwrite: function(value) {
3174
- if (value != null && value == this.state.overwrite) return;
3175
- if (this.state.overwrite = !this.state.overwrite)
3176
- this.display.cursor.className += " CodeMirror-overwrite";
3177
- else
3178
- this.display.cursor.className = this.display.cursor.className.replace(" CodeMirror-overwrite", "");
3179
- },
3180
- hasFocus: function() { return this.state.focused; },
3181
-
3182
- scrollTo: operation(null, function(x, y) {
3183
- updateScrollPos(this, x, y);
3184
- }),
3185
- getScrollInfo: function() {
3186
- var scroller = this.display.scroller, co = scrollerCutOff;
3187
- return {left: scroller.scrollLeft, top: scroller.scrollTop,
3188
- height: scroller.scrollHeight - co, width: scroller.scrollWidth - co,
3189
- clientHeight: scroller.clientHeight - co, clientWidth: scroller.clientWidth - co};
3190
- },
3191
-
3192
- scrollIntoView: operation(null, function(range, margin) {
3193
- if (range == null) range = {from: this.doc.sel.head, to: null};
3194
- else if (typeof range == "number") range = {from: Pos(range, 0), to: null};
3195
- else if (range.from == null) range = {from: range, to: null};
3196
- if (!range.to) range.to = range.from;
3197
- if (!margin) margin = 0;
3198
-
3199
- var coords = range;
3200
- if (range.from.line != null) {
3201
- this.curOp.scrollToPos = {from: range.from, to: range.to, margin: margin};
3202
- coords = {from: cursorCoords(this, range.from),
3203
- to: cursorCoords(this, range.to)};
3204
- }
3205
- var sPos = calculateScrollPos(this, Math.min(coords.from.left, coords.to.left),
3206
- Math.min(coords.from.top, coords.to.top) - margin,
3207
- Math.max(coords.from.right, coords.to.right),
3208
- Math.max(coords.from.bottom, coords.to.bottom) + margin);
3209
- updateScrollPos(this, sPos.scrollLeft, sPos.scrollTop);
3210
- }),
3211
-
3212
- setSize: operation(null, function(width, height) {
3213
- function interpret(val) {
3214
- return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val;
3215
- }
3216
- if (width != null) this.display.wrapper.style.width = interpret(width);
3217
- if (height != null) this.display.wrapper.style.height = interpret(height);
3218
- if (this.options.lineWrapping)
3219
- this.display.measureLineCache.length = this.display.measureLineCachePos = 0;
3220
- this.curOp.forceUpdate = true;
3221
- }),
3222
-
3223
- operation: function(f){return runInOp(this, f);},
3224
-
3225
- refresh: operation(null, function() {
3226
- var badHeight = this.display.cachedTextHeight == null;
3227
- clearCaches(this);
3228
- updateScrollPos(this, this.doc.scrollLeft, this.doc.scrollTop);
3229
- regChange(this);
3230
- if (badHeight) estimateLineHeights(this);
3231
- }),
3232
-
3233
- swapDoc: operation(null, function(doc) {
3234
- var old = this.doc;
3235
- old.cm = null;
3236
- attachDoc(this, doc);
3237
- clearCaches(this);
3238
- resetInput(this, true);
3239
- updateScrollPos(this, doc.scrollLeft, doc.scrollTop);
3240
- signalLater(this, "swapDoc", this, old);
3241
- return old;
3242
- }),
3243
-
3244
- getInputField: function(){return this.display.input;},
3245
- getWrapperElement: function(){return this.display.wrapper;},
3246
- getScrollerElement: function(){return this.display.scroller;},
3247
- getGutterElement: function(){return this.display.gutters;}
3248
- };
3249
- eventMixin(CodeMirror);
3250
-
3251
- // OPTION DEFAULTS
3252
-
3253
- var optionHandlers = CodeMirror.optionHandlers = {};
3254
-
3255
- // The default configuration options.
3256
- var defaults = CodeMirror.defaults = {};
3257
-
3258
- function option(name, deflt, handle, notOnInit) {
3259
- CodeMirror.defaults[name] = deflt;
3260
- if (handle) optionHandlers[name] =
3261
- notOnInit ? function(cm, val, old) {if (old != Init) handle(cm, val, old);} : handle;
3262
- }
3263
-
3264
- var Init = CodeMirror.Init = {toString: function(){return "CodeMirror.Init";}};
3265
-
3266
- // These two are, on init, called from the constructor because they
3267
- // have to be initialized before the editor can start at all.
3268
- option("value", "", function(cm, val) {
3269
- cm.setValue(val);
3270
- }, true);
3271
- option("mode", null, function(cm, val) {
3272
- cm.doc.modeOption = val;
3273
- loadMode(cm);
3274
- }, true);
3275
-
3276
- option("indentUnit", 2, loadMode, true);
3277
- option("indentWithTabs", false);
3278
- option("smartIndent", true);
3279
- option("tabSize", 4, function(cm) {
3280
- loadMode(cm);
3281
- clearCaches(cm);
3282
- regChange(cm);
3283
- }, true);
3284
- option("specialChars", /[\t\u0000-\u0019\u00ad\u200b\u2028\u2029\ufeff]/g, function(cm, val) {
3285
- cm.options.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g");
3286
- cm.refresh();
3287
- }, true);
3288
- option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function(cm) {cm.refresh();}, true);
3289
- option("electricChars", true);
3290
- option("rtlMoveVisually", !windows);
3291
- option("wholeLineUpdateBefore", true);
3292
-
3293
- option("theme", "default", function(cm) {
3294
- themeChanged(cm);
3295
- guttersChanged(cm);
3296
- }, true);
3297
- option("keyMap", "default", keyMapChanged);
3298
- option("extraKeys", null);
3299
-
3300
- option("onKeyEvent", null);
3301
- option("onDragEvent", null);
3302
-
3303
- option("lineWrapping", false, wrappingChanged, true);
3304
- option("gutters", [], function(cm) {
3305
- setGuttersForLineNumbers(cm.options);
3306
- guttersChanged(cm);
3307
- }, true);
3308
- option("fixedGutter", true, function(cm, val) {
3309
- cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0";
3310
- cm.refresh();
3311
- }, true);
3312
- option("coverGutterNextToScrollbar", false, updateScrollbars, true);
3313
- option("lineNumbers", false, function(cm) {
3314
- setGuttersForLineNumbers(cm.options);
3315
- guttersChanged(cm);
3316
- }, true);
3317
- option("firstLineNumber", 1, guttersChanged, true);
3318
- option("lineNumberFormatter", function(integer) {return integer;}, guttersChanged, true);
3319
- option("showCursorWhenSelecting", false, updateSelection, true);
3320
-
3321
- option("resetSelectionOnContextMenu", true);
3322
-
3323
- option("readOnly", false, function(cm, val) {
3324
- if (val == "nocursor") {
3325
- onBlur(cm);
3326
- cm.display.input.blur();
3327
- cm.display.disabled = true;
3328
- } else {
3329
- cm.display.disabled = false;
3330
- if (!val) resetInput(cm, true);
3331
- }
3332
- });
3333
- option("dragDrop", true);
3334
-
3335
- option("cursorBlinkRate", 530);
3336
- option("cursorScrollMargin", 0);
3337
- option("cursorHeight", 1);
3338
- option("workTime", 100);
3339
- option("workDelay", 100);
3340
- option("flattenSpans", true);
3341
- option("pollInterval", 100);
3342
- option("undoDepth", 40, function(cm, val){cm.doc.history.undoDepth = val;});
3343
- option("historyEventDelay", 500);
3344
- option("viewportMargin", 10, function(cm){cm.refresh();}, true);
3345
- option("maxHighlightLength", 10000, function(cm){loadMode(cm); cm.refresh();}, true);
3346
- option("crudeMeasuringFrom", 10000);
3347
- option("moveInputWithCursor", true, function(cm, val) {
3348
- if (!val) cm.display.inputDiv.style.top = cm.display.inputDiv.style.left = 0;
3349
- });
3350
-
3351
- option("tabindex", null, function(cm, val) {
3352
- cm.display.input.tabIndex = val || "";
3353
- });
3354
- option("autofocus", null);
3355
-
3356
- // MODE DEFINITION AND QUERYING
3357
-
3358
- // Known modes, by name and by MIME
3359
- var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {};
3360
-
3361
- CodeMirror.defineMode = function(name, mode) {
3362
- if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name;
3363
- if (arguments.length > 2) {
3364
- mode.dependencies = [];
3365
- for (var i = 2; i < arguments.length; ++i) mode.dependencies.push(arguments[i]);
3366
- }
3367
- modes[name] = mode;
3368
- };
3369
-
3370
- CodeMirror.defineMIME = function(mime, spec) {
3371
- mimeModes[mime] = spec;
3372
- };
3373
-
3374
- CodeMirror.resolveMode = function(spec) {
3375
- if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
3376
- spec = mimeModes[spec];
3377
- } else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
3378
- var found = mimeModes[spec.name];
3379
- spec = createObj(found, spec);
3380
- spec.name = found.name;
3381
- } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
3382
- return CodeMirror.resolveMode("application/xml");
3383
- }
3384
- if (typeof spec == "string") return {name: spec};
3385
- else return spec || {name: "null"};
3386
- };
3387
-
3388
- CodeMirror.getMode = function(options, spec) {
3389
- var spec = CodeMirror.resolveMode(spec);
3390
- var mfactory = modes[spec.name];
3391
- if (!mfactory) return CodeMirror.getMode(options, "text/plain");
3392
- var modeObj = mfactory(options, spec);
3393
- if (modeExtensions.hasOwnProperty(spec.name)) {
3394
- var exts = modeExtensions[spec.name];
3395
- for (var prop in exts) {
3396
- if (!exts.hasOwnProperty(prop)) continue;
3397
- if (modeObj.hasOwnProperty(prop)) modeObj["_" + prop] = modeObj[prop];
3398
- modeObj[prop] = exts[prop];
3399
- }
3400
- }
3401
- modeObj.name = spec.name;
3402
-
3403
- return modeObj;
3404
- };
3405
-
3406
- CodeMirror.defineMode("null", function() {
3407
- return {token: function(stream) {stream.skipToEnd();}};
3408
- });
3409
- CodeMirror.defineMIME("text/plain", "null");
3410
-
3411
- var modeExtensions = CodeMirror.modeExtensions = {};
3412
- CodeMirror.extendMode = function(mode, properties) {
3413
- var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
3414
- copyObj(properties, exts);
3415
- };
3416
-
3417
- // EXTENSIONS
3418
-
3419
- CodeMirror.defineExtension = function(name, func) {
3420
- CodeMirror.prototype[name] = func;
3421
- };
3422
- CodeMirror.defineDocExtension = function(name, func) {
3423
- Doc.prototype[name] = func;
3424
- };
3425
- CodeMirror.defineOption = option;
3426
-
3427
- var initHooks = [];
3428
- CodeMirror.defineInitHook = function(f) {initHooks.push(f);};
3429
-
3430
- var helpers = CodeMirror.helpers = {};
3431
- CodeMirror.registerHelper = function(type, name, value) {
3432
- if (!helpers.hasOwnProperty(type)) helpers[type] = CodeMirror[type] = {};
3433
- helpers[type][name] = value;
3434
- };
3435
-
3436
- // UTILITIES
3437
-
3438
- CodeMirror.isWordChar = isWordChar;
3439
-
3440
- // MODE STATE HANDLING
3441
-
3442
- // Utility functions for working with state. Exported because modes
3443
- // sometimes need to do this.
3444
- function copyState(mode, state) {
3445
- if (state === true) return state;
3446
- if (mode.copyState) return mode.copyState(state);
3447
- var nstate = {};
3448
- for (var n in state) {
3449
- var val = state[n];
3450
- if (val instanceof Array) val = val.concat([]);
3451
- nstate[n] = val;
3452
- }
3453
- return nstate;
3454
- }
3455
- CodeMirror.copyState = copyState;
3456
-
3457
- function startState(mode, a1, a2) {
3458
- return mode.startState ? mode.startState(a1, a2) : true;
3459
- }
3460
- CodeMirror.startState = startState;
3461
-
3462
- CodeMirror.innerMode = function(mode, state) {
3463
- while (mode.innerMode) {
3464
- var info = mode.innerMode(state);
3465
- if (!info || info.mode == mode) break;
3466
- state = info.state;
3467
- mode = info.mode;
3468
- }
3469
- return info || {mode: mode, state: state};
3470
- };
3471
-
3472
- // STANDARD COMMANDS
3473
-
3474
- var commands = CodeMirror.commands = {
3475
- selectAll: function(cm) {cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()));},
3476
- killLine: function(cm) {
3477
- var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to);
3478
- if (!sel && cm.getLine(from.line).length == from.ch)
3479
- cm.replaceRange("", from, Pos(from.line + 1, 0), "+delete");
3480
- else cm.replaceRange("", from, sel ? to : Pos(from.line), "+delete");
3481
- },
3482
- deleteLine: function(cm) {
3483
- var l = cm.getCursor().line;
3484
- cm.replaceRange("", Pos(l, 0), Pos(l), "+delete");
3485
- },
3486
- delLineLeft: function(cm) {
3487
- var cur = cm.getCursor();
3488
- cm.replaceRange("", Pos(cur.line, 0), cur, "+delete");
3489
- },
3490
- undo: function(cm) {cm.undo();},
3491
- redo: function(cm) {cm.redo();},
3492
- goDocStart: function(cm) {cm.extendSelection(Pos(cm.firstLine(), 0));},
3493
- goDocEnd: function(cm) {cm.extendSelection(Pos(cm.lastLine()));},
3494
- goLineStart: function(cm) {
3495
- cm.extendSelection(lineStart(cm, cm.getCursor().line));
3496
- },
3497
- goLineStartSmart: function(cm) {
3498
- var cur = cm.getCursor(), start = lineStart(cm, cur.line);
3499
- var line = cm.getLineHandle(start.line);
3500
- var order = getOrder(line);
3501
- if (!order || order[0].level == 0) {
3502
- var firstNonWS = Math.max(0, line.text.search(/\S/));
3503
- var inWS = cur.line == start.line && cur.ch <= firstNonWS && cur.ch;
3504
- cm.extendSelection(Pos(start.line, inWS ? 0 : firstNonWS));
3505
- } else cm.extendSelection(start);
3506
- },
3507
- goLineEnd: function(cm) {
3508
- cm.extendSelection(lineEnd(cm, cm.getCursor().line));
3509
- },
3510
- goLineRight: function(cm) {
3511
- var top = cm.charCoords(cm.getCursor(), "div").top + 5;
3512
- cm.extendSelection(cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div"));
3513
- },
3514
- goLineLeft: function(cm) {
3515
- var top = cm.charCoords(cm.getCursor(), "div").top + 5;
3516
- cm.extendSelection(cm.coordsChar({left: 0, top: top}, "div"));
3517
- },
3518
- goLineUp: function(cm) {cm.moveV(-1, "line");},
3519
- goLineDown: function(cm) {cm.moveV(1, "line");},
3520
- goPageUp: function(cm) {cm.moveV(-1, "page");},
3521
- goPageDown: function(cm) {cm.moveV(1, "page");},
3522
- goCharLeft: function(cm) {cm.moveH(-1, "char");},
3523
- goCharRight: function(cm) {cm.moveH(1, "char");},
3524
- goColumnLeft: function(cm) {cm.moveH(-1, "column");},
3525
- goColumnRight: function(cm) {cm.moveH(1, "column");},
3526
- goWordLeft: function(cm) {cm.moveH(-1, "word");},
3527
- goGroupRight: function(cm) {cm.moveH(1, "group");},
3528
- goGroupLeft: function(cm) {cm.moveH(-1, "group");},
3529
- goWordRight: function(cm) {cm.moveH(1, "word");},
3530
- delCharBefore: function(cm) {cm.deleteH(-1, "char");},
3531
- delCharAfter: function(cm) {cm.deleteH(1, "char");},
3532
- delWordBefore: function(cm) {cm.deleteH(-1, "word");},
3533
- delWordAfter: function(cm) {cm.deleteH(1, "word");},
3534
- delGroupBefore: function(cm) {cm.deleteH(-1, "group");},
3535
- delGroupAfter: function(cm) {cm.deleteH(1, "group");},
3536
- indentAuto: function(cm) {cm.indentSelection("smart");},
3537
- indentMore: function(cm) {cm.indentSelection("add");},
3538
- indentLess: function(cm) {cm.indentSelection("subtract");},
3539
- insertTab: function(cm) {cm.replaceSelection("\t", "end", "+input");},
3540
- defaultTab: function(cm) {
3541
- if (cm.somethingSelected()) cm.indentSelection("add");
3542
- else cm.replaceSelection("\t", "end", "+input");
3543
- },
3544
- transposeChars: function(cm) {
3545
- var cur = cm.getCursor(), line = cm.getLine(cur.line);
3546
- if (cur.ch > 0 && cur.ch < line.length - 1)
3547
- cm.replaceRange(line.charAt(cur.ch) + line.charAt(cur.ch - 1),
3548
- Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1));
3549
- },
3550
- newlineAndIndent: function(cm) {
3551
- operation(cm, function() {
3552
- cm.replaceSelection("\n", "end", "+input");
3553
- cm.indentLine(cm.getCursor().line, null, true);
3554
- })();
3555
- },
3556
- toggleOverwrite: function(cm) {cm.toggleOverwrite();}
3557
- };
3558
-
3559
- // STANDARD KEYMAPS
3560
-
3561
- var keyMap = CodeMirror.keyMap = {};
3562
- keyMap.basic = {
3563
- "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
3564
- "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
3565
- "Delete": "delCharAfter", "Backspace": "delCharBefore", "Shift-Backspace": "delCharBefore",
3566
- "Tab": "defaultTab", "Shift-Tab": "indentAuto",
3567
- "Enter": "newlineAndIndent", "Insert": "toggleOverwrite"
3568
- };
3569
- // Note that the save and find-related commands aren't defined by
3570
- // default. Unknown commands are simply ignored.
3571
- keyMap.pcDefault = {
3572
- "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
3573
- "Ctrl-Home": "goDocStart", "Alt-Up": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Down": "goDocEnd",
3574
- "Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
3575
- "Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find",
3576
- "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
3577
- "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
3578
- fallthrough: "basic"
3579
- };
3580
- keyMap.macDefault = {
3581
- "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
3582
- "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
3583
- "Alt-Right": "goGroupRight", "Cmd-Left": "goLineStart", "Cmd-Right": "goLineEnd", "Alt-Backspace": "delGroupBefore",
3584
- "Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find",
3585
- "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
3586
- "Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delLineLeft",
3587
- fallthrough: ["basic", "emacsy"]
3588
- };
3589
- keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
3590
- keyMap.emacsy = {
3591
- "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
3592
- "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
3593
- "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
3594
- "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars"
3595
- };
3596
-
3597
- // KEYMAP DISPATCH
3598
-
3599
- function getKeyMap(val) {
3600
- if (typeof val == "string") return keyMap[val];
3601
- else return val;
3602
- }
3603
-
3604
- function lookupKey(name, maps, handle) {
3605
- function lookup(map) {
3606
- map = getKeyMap(map);
3607
- var found = map[name];
3608
- if (found === false) return "stop";
3609
- if (found != null && handle(found)) return true;
3610
- if (map.nofallthrough) return "stop";
3611
-
3612
- var fallthrough = map.fallthrough;
3613
- if (fallthrough == null) return false;
3614
- if (Object.prototype.toString.call(fallthrough) != "[object Array]")
3615
- return lookup(fallthrough);
3616
- for (var i = 0, e = fallthrough.length; i < e; ++i) {
3617
- var done = lookup(fallthrough[i]);
3618
- if (done) return done;
3619
- }
3620
- return false;
3621
- }
3622
-
3623
- for (var i = 0; i < maps.length; ++i) {
3624
- var done = lookup(maps[i]);
3625
- if (done) return done != "stop";
3626
- }
3627
- }
3628
- function isModifierKey(event) {
3629
- var name = keyNames[event.keyCode];
3630
- return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod";
3631
- }
3632
- function keyName(event, noShift) {
3633
- if (opera && event.keyCode == 34 && event["char"]) return false;
3634
- var name = keyNames[event.keyCode];
3635
- if (name == null || event.altGraphKey) return false;
3636
- if (event.altKey) name = "Alt-" + name;
3637
- if (flipCtrlCmd ? event.metaKey : event.ctrlKey) name = "Ctrl-" + name;
3638
- if (flipCtrlCmd ? event.ctrlKey : event.metaKey) name = "Cmd-" + name;
3639
- if (!noShift && event.shiftKey) name = "Shift-" + name;
3640
- return name;
3641
- }
3642
- CodeMirror.lookupKey = lookupKey;
3643
- CodeMirror.isModifierKey = isModifierKey;
3644
- CodeMirror.keyName = keyName;
3645
-
3646
- // FROMTEXTAREA
3647
-
3648
- CodeMirror.fromTextArea = function(textarea, options) {
3649
- if (!options) options = {};
3650
- options.value = textarea.value;
3651
- if (!options.tabindex && textarea.tabindex)
3652
- options.tabindex = textarea.tabindex;
3653
- if (!options.placeholder && textarea.placeholder)
3654
- options.placeholder = textarea.placeholder;
3655
- // Set autofocus to true if this textarea is focused, or if it has
3656
- // autofocus and no other element is focused.
3657
- if (options.autofocus == null) {
3658
- var hasFocus = document.body;
3659
- // doc.activeElement occasionally throws on IE
3660
- try { hasFocus = document.activeElement; } catch(e) {}
3661
- options.autofocus = hasFocus == textarea ||
3662
- textarea.getAttribute("autofocus") != null && hasFocus == document.body;
3663
- }
3664
-
3665
- function save() {textarea.value = cm.getValue();}
3666
- if (textarea.form) {
3667
- on(textarea.form, "submit", save);
3668
- // Deplorable hack to make the submit method do the right thing.
3669
- if (!options.leaveSubmitMethodAlone) {
3670
- var form = textarea.form, realSubmit = form.submit;
3671
- try {
3672
- var wrappedSubmit = form.submit = function() {
3673
- save();
3674
- form.submit = realSubmit;
3675
- form.submit();
3676
- form.submit = wrappedSubmit;
3677
- };
3678
- } catch(e) {}
3679
- }
3680
- }
3681
-
3682
- textarea.style.display = "none";
3683
- var cm = CodeMirror(function(node) {
3684
- textarea.parentNode.insertBefore(node, textarea.nextSibling);
3685
- }, options);
3686
- cm.save = save;
3687
- cm.getTextArea = function() { return textarea; };
3688
- cm.toTextArea = function() {
3689
- save();
3690
- textarea.parentNode.removeChild(cm.getWrapperElement());
3691
- textarea.style.display = "";
3692
- if (textarea.form) {
3693
- off(textarea.form, "submit", save);
3694
- if (typeof textarea.form.submit == "function")
3695
- textarea.form.submit = realSubmit;
3696
- }
3697
- };
3698
- return cm;
3699
- };
3700
-
3701
- // STRING STREAM
3702
-
3703
- // Fed to the mode parsers, provides helper functions to make
3704
- // parsers more succinct.
3705
-
3706
- // The character stream used by a mode's parser.
3707
- function StringStream(string, tabSize) {
3708
- this.pos = this.start = 0;
3709
- this.string = string;
3710
- this.tabSize = tabSize || 8;
3711
- this.lastColumnPos = this.lastColumnValue = 0;
3712
- }
3713
-
3714
- StringStream.prototype = {
3715
- eol: function() {return this.pos >= this.string.length;},
3716
- sol: function() {return this.pos == 0;},
3717
- peek: function() {return this.string.charAt(this.pos) || undefined;},
3718
- next: function() {
3719
- if (this.pos < this.string.length)
3720
- return this.string.charAt(this.pos++);
3721
- },
3722
- eat: function(match) {
3723
- var ch = this.string.charAt(this.pos);
3724
- if (typeof match == "string") var ok = ch == match;
3725
- else var ok = ch && (match.test ? match.test(ch) : match(ch));
3726
- if (ok) {++this.pos; return ch;}
3727
- },
3728
- eatWhile: function(match) {
3729
- var start = this.pos;
3730
- while (this.eat(match)){}
3731
- return this.pos > start;
3732
- },
3733
- eatSpace: function() {
3734
- var start = this.pos;
3735
- while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
3736
- return this.pos > start;
3737
- },
3738
- skipToEnd: function() {this.pos = this.string.length;},
3739
- skipTo: function(ch) {
3740
- var found = this.string.indexOf(ch, this.pos);
3741
- if (found > -1) {this.pos = found; return true;}
3742
- },
3743
- backUp: function(n) {this.pos -= n;},
3744
- column: function() {
3745
- if (this.lastColumnPos < this.start) {
3746
- this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);
3747
- this.lastColumnPos = this.start;
3748
- }
3749
- return this.lastColumnValue;
3750
- },
3751
- indentation: function() {return countColumn(this.string, null, this.tabSize);},
3752
- match: function(pattern, consume, caseInsensitive) {
3753
- if (typeof pattern == "string") {
3754
- var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
3755
- var substr = this.string.substr(this.pos, pattern.length);
3756
- if (cased(substr) == cased(pattern)) {
3757
- if (consume !== false) this.pos += pattern.length;
3758
- return true;
3759
- }
3760
- } else {
3761
- var match = this.string.slice(this.pos).match(pattern);
3762
- if (match && match.index > 0) return null;
3763
- if (match && consume !== false) this.pos += match[0].length;
3764
- return match;
3765
- }
3766
- },
3767
- current: function(){return this.string.slice(this.start, this.pos);}
3768
- };
3769
- CodeMirror.StringStream = StringStream;
3770
-
3771
- // TEXTMARKERS
3772
-
3773
- function TextMarker(doc, type) {
3774
- this.lines = [];
3775
- this.type = type;
3776
- this.doc = doc;
3777
- }
3778
- CodeMirror.TextMarker = TextMarker;
3779
- eventMixin(TextMarker);
3780
-
3781
- TextMarker.prototype.clear = function() {
3782
- if (this.explicitlyCleared) return;
3783
- var cm = this.doc.cm, withOp = cm && !cm.curOp;
3784
- if (withOp) startOperation(cm);
3785
- if (hasHandler(this, "clear")) {
3786
- var found = this.find();
3787
- if (found) signalLater(this, "clear", found.from, found.to);
3788
- }
3789
- var min = null, max = null;
3790
- for (var i = 0; i < this.lines.length; ++i) {
3791
- var line = this.lines[i];
3792
- var span = getMarkedSpanFor(line.markedSpans, this);
3793
- if (span.to != null) max = lineNo(line);
3794
- line.markedSpans = removeMarkedSpan(line.markedSpans, span);
3795
- if (span.from != null)
3796
- min = lineNo(line);
3797
- else if (this.collapsed && !lineIsHidden(this.doc, line) && cm)
3798
- updateLineHeight(line, textHeight(cm.display));
3799
- }
3800
- if (cm && this.collapsed && !cm.options.lineWrapping) for (var i = 0; i < this.lines.length; ++i) {
3801
- var visual = visualLine(cm.doc, this.lines[i]), len = lineLength(cm.doc, visual);
3802
- if (len > cm.display.maxLineLength) {
3803
- cm.display.maxLine = visual;
3804
- cm.display.maxLineLength = len;
3805
- cm.display.maxLineChanged = true;
3806
- }
3807
- }
3808
-
3809
- if (min != null && cm) regChange(cm, min, max + 1);
3810
- this.lines.length = 0;
3811
- this.explicitlyCleared = true;
3812
- if (this.atomic && this.doc.cantEdit) {
3813
- this.doc.cantEdit = false;
3814
- if (cm) reCheckSelection(cm);
3815
- }
3816
- if (withOp) endOperation(cm);
3817
- };
3818
-
3819
- TextMarker.prototype.find = function() {
3820
- var from, to;
3821
- for (var i = 0; i < this.lines.length; ++i) {
3822
- var line = this.lines[i];
3823
- var span = getMarkedSpanFor(line.markedSpans, this);
3824
- if (span.from != null || span.to != null) {
3825
- var found = lineNo(line);
3826
- if (span.from != null) from = Pos(found, span.from);
3827
- if (span.to != null) to = Pos(found, span.to);
3828
- }
3829
- }
3830
- if (this.type == "bookmark") return from;
3831
- return from && {from: from, to: to};
3832
- };
3833
-
3834
- TextMarker.prototype.changed = function() {
3835
- var pos = this.find(), cm = this.doc.cm;
3836
- if (!pos || !cm) return;
3837
- if (this.type != "bookmark") pos = pos.from;
3838
- var line = getLine(this.doc, pos.line);
3839
- clearCachedMeasurement(cm, line);
3840
- if (pos.line >= cm.display.showingFrom && pos.line < cm.display.showingTo) {
3841
- for (var node = cm.display.lineDiv.firstChild; node; node = node.nextSibling) if (node.lineObj == line) {
3842
- if (node.offsetHeight != line.height) updateLineHeight(line, node.offsetHeight);
3843
- break;
3844
- }
3845
- runInOp(cm, function() {
3846
- cm.curOp.selectionChanged = cm.curOp.forceUpdate = cm.curOp.updateMaxLine = true;
3847
- });
3848
- }
3849
- };
3850
-
3851
- TextMarker.prototype.attachLine = function(line) {
3852
- if (!this.lines.length && this.doc.cm) {
3853
- var op = this.doc.cm.curOp;
3854
- if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1)
3855
- (op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this);
3856
- }
3857
- this.lines.push(line);
3858
- };
3859
- TextMarker.prototype.detachLine = function(line) {
3860
- this.lines.splice(indexOf(this.lines, line), 1);
3861
- if (!this.lines.length && this.doc.cm) {
3862
- var op = this.doc.cm.curOp;
3863
- (op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this);
3864
- }
3865
- };
3866
-
3867
- function markText(doc, from, to, options, type) {
3868
- if (options && options.shared) return markTextShared(doc, from, to, options, type);
3869
- if (doc.cm && !doc.cm.curOp) return operation(doc.cm, markText)(doc, from, to, options, type);
3870
-
3871
- var marker = new TextMarker(doc, type);
3872
- if (posLess(to, from) || posEq(from, to) && type == "range" &&
3873
- !(options.inclusiveLeft && options.inclusiveRight))
3874
- return marker;
3875
- if (options) copyObj(options, marker);
3876
- if (marker.replacedWith) {
3877
- marker.collapsed = true;
3878
- marker.replacedWith = elt("span", [marker.replacedWith], "CodeMirror-widget");
3879
- if (!options.handleMouseEvents) marker.replacedWith.ignoreEvents = true;
3880
- }
3881
- if (marker.collapsed) sawCollapsedSpans = true;
3882
-
3883
- if (marker.addToHistory)
3884
- addToHistory(doc, {from: from, to: to, origin: "markText"},
3885
- {head: doc.sel.head, anchor: doc.sel.anchor}, NaN);
3886
-
3887
- var curLine = from.line, size = 0, collapsedAtStart, collapsedAtEnd, cm = doc.cm, updateMaxLine;
3888
- doc.iter(curLine, to.line + 1, function(line) {
3889
- if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(doc, line) == cm.display.maxLine)
3890
- updateMaxLine = true;
3891
- var span = {from: null, to: null, marker: marker};
3892
- size += line.text.length;
3893
- if (curLine == from.line) {span.from = from.ch; size -= from.ch;}
3894
- if (curLine == to.line) {span.to = to.ch; size -= line.text.length - to.ch;}
3895
- if (marker.collapsed) {
3896
- if (curLine == to.line) collapsedAtEnd = collapsedSpanAt(line, to.ch);
3897
- if (curLine == from.line) collapsedAtStart = collapsedSpanAt(line, from.ch);
3898
- else updateLineHeight(line, 0);
3899
- }
3900
- addMarkedSpan(line, span);
3901
- ++curLine;
3902
- });
3903
- if (marker.collapsed) doc.iter(from.line, to.line + 1, function(line) {
3904
- if (lineIsHidden(doc, line)) updateLineHeight(line, 0);
3905
- });
3906
-
3907
- if (marker.clearOnEnter) on(marker, "beforeCursorEnter", function() { marker.clear(); });
3908
-
3909
- if (marker.readOnly) {
3910
- sawReadOnlySpans = true;
3911
- if (doc.history.done.length || doc.history.undone.length)
3912
- doc.clearHistory();
3913
- }
3914
- if (marker.collapsed) {
3915
- if (collapsedAtStart != collapsedAtEnd)
3916
- throw new Error("Inserting collapsed marker overlapping an existing one");
3917
- marker.size = size;
3918
- marker.atomic = true;
3919
- }
3920
- if (cm) {
3921
- if (updateMaxLine) cm.curOp.updateMaxLine = true;
3922
- if (marker.className || marker.title || marker.startStyle || marker.endStyle || marker.collapsed)
3923
- regChange(cm, from.line, to.line + 1);
3924
- if (marker.atomic) reCheckSelection(cm);
3925
- }
3926
- return marker;
3927
- }
3928
-
3929
- // SHARED TEXTMARKERS
3930
-
3931
- function SharedTextMarker(markers, primary) {
3932
- this.markers = markers;
3933
- this.primary = primary;
3934
- for (var i = 0, me = this; i < markers.length; ++i) {
3935
- markers[i].parent = this;
3936
- on(markers[i], "clear", function(){me.clear();});
3937
- }
3938
- }
3939
- CodeMirror.SharedTextMarker = SharedTextMarker;
3940
- eventMixin(SharedTextMarker);
3941
-
3942
- SharedTextMarker.prototype.clear = function() {
3943
- if (this.explicitlyCleared) return;
3944
- this.explicitlyCleared = true;
3945
- for (var i = 0; i < this.markers.length; ++i)
3946
- this.markers[i].clear();
3947
- signalLater(this, "clear");
3948
- };
3949
- SharedTextMarker.prototype.find = function() {
3950
- return this.primary.find();
3951
- };
3952
-
3953
- function markTextShared(doc, from, to, options, type) {
3954
- options = copyObj(options);
3955
- options.shared = false;
3956
- var markers = [markText(doc, from, to, options, type)], primary = markers[0];
3957
- var widget = options.replacedWith;
3958
- linkedDocs(doc, function(doc) {
3959
- if (widget) options.replacedWith = widget.cloneNode(true);
3960
- markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type));
3961
- for (var i = 0; i < doc.linked.length; ++i)
3962
- if (doc.linked[i].isParent) return;
3963
- primary = lst(markers);
3964
- });
3965
- return new SharedTextMarker(markers, primary);
3966
- }
3967
-
3968
- // TEXTMARKER SPANS
3969
-
3970
- function getMarkedSpanFor(spans, marker) {
3971
- if (spans) for (var i = 0; i < spans.length; ++i) {
3972
- var span = spans[i];
3973
- if (span.marker == marker) return span;
3974
- }
3975
- }
3976
- function removeMarkedSpan(spans, span) {
3977
- for (var r, i = 0; i < spans.length; ++i)
3978
- if (spans[i] != span) (r || (r = [])).push(spans[i]);
3979
- return r;
3980
- }
3981
- function addMarkedSpan(line, span) {
3982
- line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];
3983
- span.marker.attachLine(line);
3984
- }
3985
-
3986
- function markedSpansBefore(old, startCh, isInsert) {
3987
- if (old) for (var i = 0, nw; i < old.length; ++i) {
3988
- var span = old[i], marker = span.marker;
3989
- var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
3990
- if (startsBefore ||
3991
- (marker.inclusiveLeft && marker.inclusiveRight || marker.type == "bookmark") &&
3992
- span.from == startCh && (!isInsert || !span.marker.insertLeft)) {
3993
- var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh);
3994
- (nw || (nw = [])).push({from: span.from,
3995
- to: endsAfter ? null : span.to,
3996
- marker: marker});
3997
- }
3998
- }
3999
- return nw;
4000
- }
4001
-
4002
- function markedSpansAfter(old, endCh, isInsert) {
4003
- if (old) for (var i = 0, nw; i < old.length; ++i) {
4004
- var span = old[i], marker = span.marker;
4005
- var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
4006
- if (endsAfter || marker.type == "bookmark" && span.from == endCh && (!isInsert || span.marker.insertLeft)) {
4007
- var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh);
4008
- (nw || (nw = [])).push({from: startsBefore ? null : span.from - endCh,
4009
- to: span.to == null ? null : span.to - endCh,
4010
- marker: marker});
4011
- }
4012
- }
4013
- return nw;
4014
- }
4015
-
4016
- function stretchSpansOverChange(doc, change) {
4017
- var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;
4018
- var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;
4019
- if (!oldFirst && !oldLast) return null;
4020
-
4021
- var startCh = change.from.ch, endCh = change.to.ch, isInsert = posEq(change.from, change.to);
4022
- // Get the spans that 'stick out' on both sides
4023
- var first = markedSpansBefore(oldFirst, startCh, isInsert);
4024
- var last = markedSpansAfter(oldLast, endCh, isInsert);
4025
-
4026
- // Next, merge those two ends
4027
- var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0);
4028
- if (first) {
4029
- // Fix up .to properties of first
4030
- for (var i = 0; i < first.length; ++i) {
4031
- var span = first[i];
4032
- if (span.to == null) {
4033
- var found = getMarkedSpanFor(last, span.marker);
4034
- if (!found) span.to = startCh;
4035
- else if (sameLine) span.to = found.to == null ? null : found.to + offset;
4036
- }
4037
- }
4038
- }
4039
- if (last) {
4040
- // Fix up .from in last (or move them into first in case of sameLine)
4041
- for (var i = 0; i < last.length; ++i) {
4042
- var span = last[i];
4043
- if (span.to != null) span.to += offset;
4044
- if (span.from == null) {
4045
- var found = getMarkedSpanFor(first, span.marker);
4046
- if (!found) {
4047
- span.from = offset;
4048
- if (sameLine) (first || (first = [])).push(span);
4049
- }
4050
- } else {
4051
- span.from += offset;
4052
- if (sameLine) (first || (first = [])).push(span);
4053
- }
4054
- }
4055
- }
4056
- if (sameLine && first) {
4057
- // Make sure we didn't create any zero-length spans
4058
- for (var i = 0; i < first.length; ++i)
4059
- if (first[i].from != null && first[i].from == first[i].to && first[i].marker.type != "bookmark")
4060
- first.splice(i--, 1);
4061
- if (!first.length) first = null;
4062
- }
4063
-
4064
- var newMarkers = [first];
4065
- if (!sameLine) {
4066
- // Fill gap with whole-line-spans
4067
- var gap = change.text.length - 2, gapMarkers;
4068
- if (gap > 0 && first)
4069
- for (var i = 0; i < first.length; ++i)
4070
- if (first[i].to == null)
4071
- (gapMarkers || (gapMarkers = [])).push({from: null, to: null, marker: first[i].marker});
4072
- for (var i = 0; i < gap; ++i)
4073
- newMarkers.push(gapMarkers);
4074
- newMarkers.push(last);
4075
- }
4076
- return newMarkers;
4077
- }
4078
-
4079
- function mergeOldSpans(doc, change) {
4080
- var old = getOldSpans(doc, change);
4081
- var stretched = stretchSpansOverChange(doc, change);
4082
- if (!old) return stretched;
4083
- if (!stretched) return old;
4084
-
4085
- for (var i = 0; i < old.length; ++i) {
4086
- var oldCur = old[i], stretchCur = stretched[i];
4087
- if (oldCur && stretchCur) {
4088
- spans: for (var j = 0; j < stretchCur.length; ++j) {
4089
- var span = stretchCur[j];
4090
- for (var k = 0; k < oldCur.length; ++k)
4091
- if (oldCur[k].marker == span.marker) continue spans;
4092
- oldCur.push(span);
4093
- }
4094
- } else if (stretchCur) {
4095
- old[i] = stretchCur;
4096
- }
4097
- }
4098
- return old;
4099
- }
4100
-
4101
- function removeReadOnlyRanges(doc, from, to) {
4102
- var markers = null;
4103
- doc.iter(from.line, to.line + 1, function(line) {
4104
- if (line.markedSpans) for (var i = 0; i < line.markedSpans.length; ++i) {
4105
- var mark = line.markedSpans[i].marker;
4106
- if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
4107
- (markers || (markers = [])).push(mark);
4108
- }
4109
- });
4110
- if (!markers) return null;
4111
- var parts = [{from: from, to: to}];
4112
- for (var i = 0; i < markers.length; ++i) {
4113
- var mk = markers[i], m = mk.find();
4114
- for (var j = 0; j < parts.length; ++j) {
4115
- var p = parts[j];
4116
- if (posLess(p.to, m.from) || posLess(m.to, p.from)) continue;
4117
- var newParts = [j, 1];
4118
- if (posLess(p.from, m.from) || !mk.inclusiveLeft && posEq(p.from, m.from))
4119
- newParts.push({from: p.from, to: m.from});
4120
- if (posLess(m.to, p.to) || !mk.inclusiveRight && posEq(p.to, m.to))
4121
- newParts.push({from: m.to, to: p.to});
4122
- parts.splice.apply(parts, newParts);
4123
- j += newParts.length - 1;
4124
- }
4125
- }
4126
- return parts;
4127
- }
4128
-
4129
- function collapsedSpanAt(line, ch) {
4130
- var sps = sawCollapsedSpans && line.markedSpans, found;
4131
- if (sps) for (var sp, i = 0; i < sps.length; ++i) {
4132
- sp = sps[i];
4133
- if (!sp.marker.collapsed) continue;
4134
- if ((sp.from == null || sp.from < ch) &&
4135
- (sp.to == null || sp.to > ch) &&
4136
- (!found || found.width < sp.marker.width))
4137
- found = sp.marker;
4138
- }
4139
- return found;
4140
- }
4141
- function collapsedSpanAtStart(line) { return collapsedSpanAt(line, -1); }
4142
- function collapsedSpanAtEnd(line) { return collapsedSpanAt(line, line.text.length + 1); }
4143
-
4144
- function visualLine(doc, line) {
4145
- var merged;
4146
- while (merged = collapsedSpanAtStart(line))
4147
- line = getLine(doc, merged.find().from.line);
4148
- return line;
4149
- }
4150
-
4151
- function lineIsHidden(doc, line) {
4152
- var sps = sawCollapsedSpans && line.markedSpans;
4153
- if (sps) for (var sp, i = 0; i < sps.length; ++i) {
4154
- sp = sps[i];
4155
- if (!sp.marker.collapsed) continue;
4156
- if (sp.from == null) return true;
4157
- if (sp.marker.replacedWith) continue;
4158
- if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp))
4159
- return true;
4160
- }
4161
- }
4162
- function lineIsHiddenInner(doc, line, span) {
4163
- if (span.to == null) {
4164
- var end = span.marker.find().to, endLine = getLine(doc, end.line);
4165
- return lineIsHiddenInner(doc, endLine, getMarkedSpanFor(endLine.markedSpans, span.marker));
4166
- }
4167
- if (span.marker.inclusiveRight && span.to == line.text.length)
4168
- return true;
4169
- for (var sp, i = 0; i < line.markedSpans.length; ++i) {
4170
- sp = line.markedSpans[i];
4171
- if (sp.marker.collapsed && !sp.marker.replacedWith && sp.from == span.to &&
4172
- (sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
4173
- lineIsHiddenInner(doc, line, sp)) return true;
4174
- }
4175
- }
4176
-
4177
- function detachMarkedSpans(line) {
4178
- var spans = line.markedSpans;
4179
- if (!spans) return;
4180
- for (var i = 0; i < spans.length; ++i)
4181
- spans[i].marker.detachLine(line);
4182
- line.markedSpans = null;
4183
- }
4184
-
4185
- function attachMarkedSpans(line, spans) {
4186
- if (!spans) return;
4187
- for (var i = 0; i < spans.length; ++i)
4188
- spans[i].marker.attachLine(line);
4189
- line.markedSpans = spans;
4190
- }
4191
-
4192
- // LINE WIDGETS
4193
-
4194
- var LineWidget = CodeMirror.LineWidget = function(cm, node, options) {
4195
- if (options) for (var opt in options) if (options.hasOwnProperty(opt))
4196
- this[opt] = options[opt];
4197
- this.cm = cm;
4198
- this.node = node;
4199
- };
4200
- eventMixin(LineWidget);
4201
- function widgetOperation(f) {
4202
- return function() {
4203
- var withOp = !this.cm.curOp;
4204
- if (withOp) startOperation(this.cm);
4205
- try {var result = f.apply(this, arguments);}
4206
- finally {if (withOp) endOperation(this.cm);}
4207
- return result;
4208
- };
4209
- }
4210
- LineWidget.prototype.clear = widgetOperation(function() {
4211
- var ws = this.line.widgets, no = lineNo(this.line);
4212
- if (no == null || !ws) return;
4213
- for (var i = 0; i < ws.length; ++i) if (ws[i] == this) ws.splice(i--, 1);
4214
- if (!ws.length) this.line.widgets = null;
4215
- var aboveVisible = heightAtLine(this.cm, this.line) < this.cm.doc.scrollTop;
4216
- updateLineHeight(this.line, Math.max(0, this.line.height - widgetHeight(this)));
4217
- if (aboveVisible) addToScrollPos(this.cm, 0, -this.height);
4218
- regChange(this.cm, no, no + 1);
4219
- });
4220
- LineWidget.prototype.changed = widgetOperation(function() {
4221
- var oldH = this.height;
4222
- this.height = null;
4223
- var diff = widgetHeight(this) - oldH;
4224
- if (!diff) return;
4225
- updateLineHeight(this.line, this.line.height + diff);
4226
- var no = lineNo(this.line);
4227
- regChange(this.cm, no, no + 1);
4228
- });
4229
-
4230
- function widgetHeight(widget) {
4231
- if (widget.height != null) return widget.height;
4232
- if (!widget.node.parentNode || widget.node.parentNode.nodeType != 1)
4233
- removeChildrenAndAdd(widget.cm.display.measure, elt("div", [widget.node], null, "position: relative"));
4234
- return widget.height = widget.node.offsetHeight;
4235
- }
4236
-
4237
- function addLineWidget(cm, handle, node, options) {
4238
- var widget = new LineWidget(cm, node, options);
4239
- if (widget.noHScroll) cm.display.alignWidgets = true;
4240
- changeLine(cm, handle, function(line) {
4241
- var widgets = line.widgets || (line.widgets = []);
4242
- if (widget.insertAt == null) widgets.push(widget);
4243
- else widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget);
4244
- widget.line = line;
4245
- if (!lineIsHidden(cm.doc, line) || widget.showIfHidden) {
4246
- var aboveVisible = heightAtLine(cm, line) < cm.doc.scrollTop;
4247
- updateLineHeight(line, line.height + widgetHeight(widget));
4248
- if (aboveVisible) addToScrollPos(cm, 0, widget.height);
4249
- }
4250
- return true;
4251
- });
4252
- return widget;
4253
- }
4254
-
4255
- // LINE DATA STRUCTURE
4256
-
4257
- // Line objects. These hold state related to a line, including
4258
- // highlighting info (the styles array).
4259
- var Line = CodeMirror.Line = function(text, markedSpans, estimateHeight) {
4260
- this.text = text;
4261
- attachMarkedSpans(this, markedSpans);
4262
- this.height = estimateHeight ? estimateHeight(this) : 1;
4263
- };
4264
- eventMixin(Line);
4265
- Line.prototype.lineNo = function() { return lineNo(this); };
4266
-
4267
- function updateLine(line, text, markedSpans, estimateHeight) {
4268
- line.text = text;
4269
- if (line.stateAfter) line.stateAfter = null;
4270
- if (line.styles) line.styles = null;
4271
- if (line.order != null) line.order = null;
4272
- detachMarkedSpans(line);
4273
- attachMarkedSpans(line, markedSpans);
4274
- var estHeight = estimateHeight ? estimateHeight(line) : 1;
4275
- if (estHeight != line.height) updateLineHeight(line, estHeight);
4276
- }
4277
-
4278
- function cleanUpLine(line) {
4279
- line.parent = null;
4280
- detachMarkedSpans(line);
4281
- }
4282
-
4283
- // Run the given mode's parser over a line, update the styles
4284
- // array, which contains alternating fragments of text and CSS
4285
- // classes.
4286
- function runMode(cm, text, mode, state, f, forceToEnd) {
4287
- var flattenSpans = mode.flattenSpans;
4288
- if (flattenSpans == null) flattenSpans = cm.options.flattenSpans;
4289
- var curStart = 0, curStyle = null;
4290
- var stream = new StringStream(text, cm.options.tabSize), style;
4291
- if (text == "" && mode.blankLine) mode.blankLine(state);
4292
- while (!stream.eol()) {
4293
- if (stream.pos > cm.options.maxHighlightLength) {
4294
- flattenSpans = false;
4295
- if (forceToEnd) processLine(cm, text, state, stream.pos);
4296
- stream.pos = text.length;
4297
- style = null;
4298
- } else {
4299
- style = mode.token(stream, state);
4300
- }
4301
- if (!flattenSpans || curStyle != style) {
4302
- if (curStart < stream.start) f(stream.start, curStyle);
4303
- curStart = stream.start; curStyle = style;
4304
- }
4305
- stream.start = stream.pos;
4306
- }
4307
- while (curStart < stream.pos) {
4308
- // Webkit seems to refuse to render text nodes longer than 57444 characters
4309
- var pos = Math.min(stream.pos, curStart + 50000);
4310
- f(pos, curStyle);
4311
- curStart = pos;
4312
- }
4313
- }
4314
-
4315
- function highlightLine(cm, line, state, forceToEnd) {
4316
- // A styles array always starts with a number identifying the
4317
- // mode/overlays that it is based on (for easy invalidation).
4318
- var st = [cm.state.modeGen];
4319
- // Compute the base array of styles
4320
- runMode(cm, line.text, cm.doc.mode, state, function(end, style) {
4321
- st.push(end, style);
4322
- }, forceToEnd);
4323
-
4324
- // Run overlays, adjust style array.
4325
- for (var o = 0; o < cm.state.overlays.length; ++o) {
4326
- var overlay = cm.state.overlays[o], i = 1, at = 0;
4327
- runMode(cm, line.text, overlay.mode, true, function(end, style) {
4328
- var start = i;
4329
- // Ensure there's a token end at the current position, and that i points at it
4330
- while (at < end) {
4331
- var i_end = st[i];
4332
- if (i_end > end)
4333
- st.splice(i, 1, end, st[i+1], i_end);
4334
- i += 2;
4335
- at = Math.min(end, i_end);
4336
- }
4337
- if (!style) return;
4338
- if (overlay.opaque) {
4339
- st.splice(start, i - start, end, style);
4340
- i = start + 2;
4341
- } else {
4342
- for (; start < i; start += 2) {
4343
- var cur = st[start+1];
4344
- st[start+1] = cur ? cur + " " + style : style;
4345
- }
4346
- }
4347
- });
4348
- }
4349
-
4350
- return st;
4351
- }
4352
-
4353
- function getLineStyles(cm, line) {
4354
- if (!line.styles || line.styles[0] != cm.state.modeGen)
4355
- line.styles = highlightLine(cm, line, line.stateAfter = getStateBefore(cm, lineNo(line)));
4356
- return line.styles;
4357
- }
4358
-
4359
- // Lightweight form of highlight -- proceed over this line and
4360
- // update state, but don't save a style array.
4361
- function processLine(cm, text, state, startAt) {
4362
- var mode = cm.doc.mode;
4363
- var stream = new StringStream(text, cm.options.tabSize);
4364
- stream.start = stream.pos = startAt || 0;
4365
- if (text == "" && mode.blankLine) mode.blankLine(state);
4366
- while (!stream.eol() && stream.pos <= cm.options.maxHighlightLength) {
4367
- mode.token(stream, state);
4368
- stream.start = stream.pos;
4369
- }
4370
- }
4371
-
4372
- var styleToClassCache = {};
4373
- function interpretTokenStyle(style, builder) {
4374
- if (!style) return null;
4375
- for (;;) {
4376
- var lineClass = style.match(/(?:^|\s)line-(background-)?(\S+)/);
4377
- if (!lineClass) break;
4378
- style = style.slice(0, lineClass.index) + style.slice(lineClass.index + lineClass[0].length);
4379
- var prop = lineClass[1] ? "bgClass" : "textClass";
4380
- if (builder[prop] == null)
4381
- builder[prop] = lineClass[2];
4382
- else if (!(new RegExp("(?:^|\s)" + lineClass[2] + "(?:$|\s)")).test(builder[prop]))
4383
- builder[prop] += " " + lineClass[2];
4384
- }
4385
- return styleToClassCache[style] ||
4386
- (styleToClassCache[style] = "cm-" + style.replace(/ +/g, " cm-"));
4387
- }
4388
-
4389
- function buildLineContent(cm, realLine, measure, copyWidgets) {
4390
- var merged, line = realLine, empty = true;
4391
- while (merged = collapsedSpanAtStart(line))
4392
- line = getLine(cm.doc, merged.find().from.line);
4393
-
4394
- var builder = {pre: elt("pre"), col: 0, pos: 0,
4395
- measure: null, measuredSomething: false, cm: cm,
4396
- copyWidgets: copyWidgets};
4397
-
4398
- do {
4399
- if (line.text) empty = false;
4400
- builder.measure = line == realLine && measure;
4401
- builder.pos = 0;
4402
- builder.addToken = builder.measure ? buildTokenMeasure : buildToken;
4403
- if ((ie || webkit) && cm.getOption("lineWrapping"))
4404
- builder.addToken = buildTokenSplitSpaces(builder.addToken);
4405
- var next = insertLineContent(line, builder, getLineStyles(cm, line));
4406
- if (measure && line == realLine && !builder.measuredSomething) {
4407
- measure[0] = builder.pre.appendChild(zeroWidthElement(cm.display.measure));
4408
- builder.measuredSomething = true;
4409
- }
4410
- if (next) line = getLine(cm.doc, next.to.line);
4411
- } while (next);
4412
-
4413
- if (measure && !builder.measuredSomething && !measure[0])
4414
- measure[0] = builder.pre.appendChild(empty ? elt("span", "\u00a0") : zeroWidthElement(cm.display.measure));
4415
- if (!builder.pre.firstChild && !lineIsHidden(cm.doc, realLine))
4416
- builder.pre.appendChild(document.createTextNode("\u00a0"));
4417
-
4418
- var order;
4419
- // Work around problem with the reported dimensions of single-char
4420
- // direction spans on IE (issue #1129). See also the comment in
4421
- // cursorCoords.
4422
- if (measure && (ie || ie_gt10) && (order = getOrder(line))) {
4423
- var l = order.length - 1;
4424
- if (order[l].from == order[l].to) --l;
4425
- var last = order[l], prev = order[l - 1];
4426
- if (last.from + 1 == last.to && prev && last.level < prev.level) {
4427
- var span = measure[builder.pos - 1];
4428
- if (span) span.parentNode.insertBefore(span.measureRight = zeroWidthElement(cm.display.measure),
4429
- span.nextSibling);
4430
- }
4431
- }
4432
-
4433
- var textClass = builder.textClass ? builder.textClass + " " + (realLine.textClass || "") : realLine.textClass;
4434
- if (textClass) builder.pre.className = textClass;
4435
-
4436
- signal(cm, "renderLine", cm, realLine, builder.pre);
4437
- return builder;
4438
- }
4439
-
4440
- function defaultSpecialCharPlaceholder(ch) {
4441
- var token = elt("span", "\u2022", "cm-invalidchar");
4442
- token.title = "\\u" + ch.charCodeAt(0).toString(16);
4443
- return token;
4444
- }
4445
-
4446
- function buildToken(builder, text, style, startStyle, endStyle, title) {
4447
- if (!text) return;
4448
- var special = builder.cm.options.specialChars;
4449
- if (!special.test(text)) {
4450
- builder.col += text.length;
4451
- var content = document.createTextNode(text);
4452
- } else {
4453
- var content = document.createDocumentFragment(), pos = 0;
4454
- while (true) {
4455
- special.lastIndex = pos;
4456
- var m = special.exec(text);
4457
- var skipped = m ? m.index - pos : text.length - pos;
4458
- if (skipped) {
4459
- content.appendChild(document.createTextNode(text.slice(pos, pos + skipped)));
4460
- builder.col += skipped;
4461
- }
4462
- if (!m) break;
4463
- pos += skipped + 1;
4464
- if (m[0] == "\t") {
4465
- var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
4466
- content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
4467
- builder.col += tabWidth;
4468
- } else {
4469
- var token = builder.cm.options.specialCharPlaceholder(m[0]);
4470
- content.appendChild(token);
4471
- builder.col += 1;
4472
- }
4473
- }
4474
- }
4475
- if (style || startStyle || endStyle || builder.measure) {
4476
- var fullStyle = style || "";
4477
- if (startStyle) fullStyle += startStyle;
4478
- if (endStyle) fullStyle += endStyle;
4479
- var token = elt("span", [content], fullStyle);
4480
- if (title) token.title = title;
4481
- return builder.pre.appendChild(token);
4482
- }
4483
- builder.pre.appendChild(content);
4484
- }
4485
-
4486
- function buildTokenMeasure(builder, text, style, startStyle, endStyle) {
4487
- var wrapping = builder.cm.options.lineWrapping;
4488
- for (var i = 0; i < text.length; ++i) {
4489
- var ch = text.charAt(i), start = i == 0;
4490
- if (ch >= "\ud800" && ch < "\udbff" && i < text.length - 1) {
4491
- ch = text.slice(i, i + 2);
4492
- ++i;
4493
- } else if (i && wrapping && spanAffectsWrapping(text, i)) {
4494
- builder.pre.appendChild(elt("wbr"));
4495
- }
4496
- var old = builder.measure[builder.pos];
4497
- var span = builder.measure[builder.pos] =
4498
- buildToken(builder, ch, style,
4499
- start && startStyle, i == text.length - 1 && endStyle);
4500
- if (old) span.leftSide = old.leftSide || old;
4501
- // In IE single-space nodes wrap differently than spaces
4502
- // embedded in larger text nodes, except when set to
4503
- // white-space: normal (issue #1268).
4504
- if (ie && wrapping && ch == " " && i && !/\s/.test(text.charAt(i - 1)) &&
4505
- i < text.length - 1 && !/\s/.test(text.charAt(i + 1)))
4506
- span.style.whiteSpace = "normal";
4507
- builder.pos += ch.length;
4508
- }
4509
- if (text.length) builder.measuredSomething = true;
4510
- }
4511
-
4512
- function buildTokenSplitSpaces(inner) {
4513
- function split(old) {
4514
- var out = " ";
4515
- for (var i = 0; i < old.length - 2; ++i) out += i % 2 ? " " : "\u00a0";
4516
- out += " ";
4517
- return out;
4518
- }
4519
- return function(builder, text, style, startStyle, endStyle, title) {
4520
- return inner(builder, text.replace(/ {3,}/g, split), style, startStyle, endStyle, title);
4521
- };
4522
- }
4523
-
4524
- function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
4525
- var widget = !ignoreWidget && marker.replacedWith;
4526
- if (widget) {
4527
- if (builder.copyWidgets) widget = widget.cloneNode(true);
4528
- builder.pre.appendChild(widget);
4529
- if (builder.measure) {
4530
- if (size) {
4531
- builder.measure[builder.pos] = widget;
4532
- } else {
4533
- var elt = zeroWidthElement(builder.cm.display.measure);
4534
- if (marker.type == "bookmark" && !marker.insertLeft)
4535
- builder.measure[builder.pos] = builder.pre.appendChild(elt);
4536
- else if (builder.measure[builder.pos])
4537
- return;
4538
- else
4539
- builder.measure[builder.pos] = builder.pre.insertBefore(elt, widget);
4540
- }
4541
- builder.measuredSomething = true;
4542
- }
4543
- }
4544
- builder.pos += size;
4545
- }
4546
-
4547
- // Outputs a number of spans to make up a line, taking highlighting
4548
- // and marked text into account.
4549
- function insertLineContent(line, builder, styles) {
4550
- var spans = line.markedSpans, allText = line.text, at = 0;
4551
- if (!spans) {
4552
- for (var i = 1; i < styles.length; i+=2)
4553
- builder.addToken(builder, allText.slice(at, at = styles[i]), interpretTokenStyle(styles[i+1], builder));
4554
- return;
4555
- }
4556
-
4557
- var len = allText.length, pos = 0, i = 1, text = "", style;
4558
- var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, title, collapsed;
4559
- for (;;) {
4560
- if (nextChange == pos) { // Update current marker set
4561
- spanStyle = spanEndStyle = spanStartStyle = title = "";
4562
- collapsed = null; nextChange = Infinity;
4563
- var foundBookmarks = [];
4564
- for (var j = 0; j < spans.length; ++j) {
4565
- var sp = spans[j], m = sp.marker;
4566
- if (sp.from <= pos && (sp.to == null || sp.to > pos)) {
4567
- if (sp.to != null && nextChange > sp.to) { nextChange = sp.to; spanEndStyle = ""; }
4568
- if (m.className) spanStyle += " " + m.className;
4569
- if (m.startStyle && sp.from == pos) spanStartStyle += " " + m.startStyle;
4570
- if (m.endStyle && sp.to == nextChange) spanEndStyle += " " + m.endStyle;
4571
- if (m.title && !title) title = m.title;
4572
- if (m.collapsed && (!collapsed || collapsed.marker.size < m.size))
4573
- collapsed = sp;
4574
- } else if (sp.from > pos && nextChange > sp.from) {
4575
- nextChange = sp.from;
4576
- }
4577
- if (m.type == "bookmark" && sp.from == pos && m.replacedWith) foundBookmarks.push(m);
4578
- }
4579
- if (collapsed && (collapsed.from || 0) == pos) {
4580
- buildCollapsedSpan(builder, (collapsed.to == null ? len : collapsed.to) - pos,
4581
- collapsed.marker, collapsed.from == null);
4582
- if (collapsed.to == null) return collapsed.marker.find();
4583
- }
4584
- if (!collapsed && foundBookmarks.length) for (var j = 0; j < foundBookmarks.length; ++j)
4585
- buildCollapsedSpan(builder, 0, foundBookmarks[j]);
4586
- }
4587
- if (pos >= len) break;
4588
-
4589
- var upto = Math.min(len, nextChange);
4590
- while (true) {
4591
- if (text) {
4592
- var end = pos + text.length;
4593
- if (!collapsed) {
4594
- var tokenText = end > upto ? text.slice(0, upto - pos) : text;
4595
- builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
4596
- spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title);
4597
- }
4598
- if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;}
4599
- pos = end;
4600
- spanStartStyle = "";
4601
- }
4602
- text = allText.slice(at, at = styles[i++]);
4603
- style = interpretTokenStyle(styles[i++], builder);
4604
- }
4605
- }
4606
- }
4607
-
4608
- // DOCUMENT DATA STRUCTURE
4609
-
4610
- function updateDoc(doc, change, markedSpans, selAfter, estimateHeight) {
4611
- function spansFor(n) {return markedSpans ? markedSpans[n] : null;}
4612
- function update(line, text, spans) {
4613
- updateLine(line, text, spans, estimateHeight);
4614
- signalLater(line, "change", line, change);
4615
- }
4616
-
4617
- var from = change.from, to = change.to, text = change.text;
4618
- var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line);
4619
- var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line;
4620
-
4621
- // First adjust the line structure
4622
- if (from.ch == 0 && to.ch == 0 && lastText == "" &&
4623
- (!doc.cm || doc.cm.options.wholeLineUpdateBefore)) {
4624
- // This is a whole-line replace. Treated specially to make
4625
- // sure line objects move the way they are supposed to.
4626
- for (var i = 0, e = text.length - 1, added = []; i < e; ++i)
4627
- added.push(new Line(text[i], spansFor(i), estimateHeight));
4628
- update(lastLine, lastLine.text, lastSpans);
4629
- if (nlines) doc.remove(from.line, nlines);
4630
- if (added.length) doc.insert(from.line, added);
4631
- } else if (firstLine == lastLine) {
4632
- if (text.length == 1) {
4633
- update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans);
4634
- } else {
4635
- for (var added = [], i = 1, e = text.length - 1; i < e; ++i)
4636
- added.push(new Line(text[i], spansFor(i), estimateHeight));
4637
- added.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight));
4638
- update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
4639
- doc.insert(from.line + 1, added);
4640
- }
4641
- } else if (text.length == 1) {
4642
- update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0));
4643
- doc.remove(from.line + 1, nlines);
4644
- } else {
4645
- update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
4646
- update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans);
4647
- for (var i = 1, e = text.length - 1, added = []; i < e; ++i)
4648
- added.push(new Line(text[i], spansFor(i), estimateHeight));
4649
- if (nlines > 1) doc.remove(from.line + 1, nlines - 1);
4650
- doc.insert(from.line + 1, added);
4651
- }
4652
-
4653
- signalLater(doc, "change", doc, change);
4654
- setSelection(doc, selAfter.anchor, selAfter.head, null, true);
4655
- }
4656
-
4657
- function LeafChunk(lines) {
4658
- this.lines = lines;
4659
- this.parent = null;
4660
- for (var i = 0, e = lines.length, height = 0; i < e; ++i) {
4661
- lines[i].parent = this;
4662
- height += lines[i].height;
4663
- }
4664
- this.height = height;
4665
- }
4666
-
4667
- LeafChunk.prototype = {
4668
- chunkSize: function() { return this.lines.length; },
4669
- removeInner: function(at, n) {
4670
- for (var i = at, e = at + n; i < e; ++i) {
4671
- var line = this.lines[i];
4672
- this.height -= line.height;
4673
- cleanUpLine(line);
4674
- signalLater(line, "delete");
4675
- }
4676
- this.lines.splice(at, n);
4677
- },
4678
- collapse: function(lines) {
4679
- lines.splice.apply(lines, [lines.length, 0].concat(this.lines));
4680
- },
4681
- insertInner: function(at, lines, height) {
4682
- this.height += height;
4683
- this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
4684
- for (var i = 0, e = lines.length; i < e; ++i) lines[i].parent = this;
4685
- },
4686
- iterN: function(at, n, op) {
4687
- for (var e = at + n; at < e; ++at)
4688
- if (op(this.lines[at])) return true;
4689
- }
4690
- };
4691
-
4692
- function BranchChunk(children) {
4693
- this.children = children;
4694
- var size = 0, height = 0;
4695
- for (var i = 0, e = children.length; i < e; ++i) {
4696
- var ch = children[i];
4697
- size += ch.chunkSize(); height += ch.height;
4698
- ch.parent = this;
4699
- }
4700
- this.size = size;
4701
- this.height = height;
4702
- this.parent = null;
4703
- }
4704
-
4705
- BranchChunk.prototype = {
4706
- chunkSize: function() { return this.size; },
4707
- removeInner: function(at, n) {
4708
- this.size -= n;
4709
- for (var i = 0; i < this.children.length; ++i) {
4710
- var child = this.children[i], sz = child.chunkSize();
4711
- if (at < sz) {
4712
- var rm = Math.min(n, sz - at), oldHeight = child.height;
4713
- child.removeInner(at, rm);
4714
- this.height -= oldHeight - child.height;
4715
- if (sz == rm) { this.children.splice(i--, 1); child.parent = null; }
4716
- if ((n -= rm) == 0) break;
4717
- at = 0;
4718
- } else at -= sz;
4719
- }
4720
- if (this.size - n < 25) {
4721
- var lines = [];
4722
- this.collapse(lines);
4723
- this.children = [new LeafChunk(lines)];
4724
- this.children[0].parent = this;
4725
- }
4726
- },
4727
- collapse: function(lines) {
4728
- for (var i = 0, e = this.children.length; i < e; ++i) this.children[i].collapse(lines);
4729
- },
4730
- insertInner: function(at, lines, height) {
4731
- this.size += lines.length;
4732
- this.height += height;
4733
- for (var i = 0, e = this.children.length; i < e; ++i) {
4734
- var child = this.children[i], sz = child.chunkSize();
4735
- if (at <= sz) {
4736
- child.insertInner(at, lines, height);
4737
- if (child.lines && child.lines.length > 50) {
4738
- while (child.lines.length > 50) {
4739
- var spilled = child.lines.splice(child.lines.length - 25, 25);
4740
- var newleaf = new LeafChunk(spilled);
4741
- child.height -= newleaf.height;
4742
- this.children.splice(i + 1, 0, newleaf);
4743
- newleaf.parent = this;
4744
- }
4745
- this.maybeSpill();
4746
- }
4747
- break;
4748
- }
4749
- at -= sz;
4750
- }
4751
- },
4752
- maybeSpill: function() {
4753
- if (this.children.length <= 10) return;
4754
- var me = this;
4755
- do {
4756
- var spilled = me.children.splice(me.children.length - 5, 5);
4757
- var sibling = new BranchChunk(spilled);
4758
- if (!me.parent) { // Become the parent node
4759
- var copy = new BranchChunk(me.children);
4760
- copy.parent = me;
4761
- me.children = [copy, sibling];
4762
- me = copy;
4763
- } else {
4764
- me.size -= sibling.size;
4765
- me.height -= sibling.height;
4766
- var myIndex = indexOf(me.parent.children, me);
4767
- me.parent.children.splice(myIndex + 1, 0, sibling);
4768
- }
4769
- sibling.parent = me.parent;
4770
- } while (me.children.length > 10);
4771
- me.parent.maybeSpill();
4772
- },
4773
- iterN: function(at, n, op) {
4774
- for (var i = 0, e = this.children.length; i < e; ++i) {
4775
- var child = this.children[i], sz = child.chunkSize();
4776
- if (at < sz) {
4777
- var used = Math.min(n, sz - at);
4778
- if (child.iterN(at, used, op)) return true;
4779
- if ((n -= used) == 0) break;
4780
- at = 0;
4781
- } else at -= sz;
4782
- }
4783
- }
4784
- };
4785
-
4786
- var nextDocId = 0;
4787
- var Doc = CodeMirror.Doc = function(text, mode, firstLine) {
4788
- if (!(this instanceof Doc)) return new Doc(text, mode, firstLine);
4789
- if (firstLine == null) firstLine = 0;
4790
-
4791
- BranchChunk.call(this, [new LeafChunk([new Line("", null)])]);
4792
- this.first = firstLine;
4793
- this.scrollTop = this.scrollLeft = 0;
4794
- this.cantEdit = false;
4795
- this.history = makeHistory();
4796
- this.cleanGeneration = 1;
4797
- this.frontier = firstLine;
4798
- var start = Pos(firstLine, 0);
4799
- this.sel = {from: start, to: start, head: start, anchor: start, shift: false, extend: false, goalColumn: null};
4800
- this.id = ++nextDocId;
4801
- this.modeOption = mode;
4802
-
4803
- if (typeof text == "string") text = splitLines(text);
4804
- updateDoc(this, {from: start, to: start, text: text}, null, {head: start, anchor: start});
4805
- };
4806
-
4807
- Doc.prototype = createObj(BranchChunk.prototype, {
4808
- constructor: Doc,
4809
- iter: function(from, to, op) {
4810
- if (op) this.iterN(from - this.first, to - from, op);
4811
- else this.iterN(this.first, this.first + this.size, from);
4812
- },
4813
-
4814
- insert: function(at, lines) {
4815
- var height = 0;
4816
- for (var i = 0, e = lines.length; i < e; ++i) height += lines[i].height;
4817
- this.insertInner(at - this.first, lines, height);
4818
- },
4819
- remove: function(at, n) { this.removeInner(at - this.first, n); },
4820
-
4821
- getValue: function(lineSep) {
4822
- var lines = getLines(this, this.first, this.first + this.size);
4823
- if (lineSep === false) return lines;
4824
- return lines.join(lineSep || "\n");
4825
- },
4826
- setValue: function(code) {
4827
- var top = Pos(this.first, 0), last = this.first + this.size - 1;
4828
- makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length),
4829
- text: splitLines(code), origin: "setValue"},
4830
- {head: top, anchor: top}, true);
4831
- },
4832
- replaceRange: function(code, from, to, origin) {
4833
- from = clipPos(this, from);
4834
- to = to ? clipPos(this, to) : from;
4835
- replaceRange(this, code, from, to, origin);
4836
- },
4837
- getRange: function(from, to, lineSep) {
4838
- var lines = getBetween(this, clipPos(this, from), clipPos(this, to));
4839
- if (lineSep === false) return lines;
4840
- return lines.join(lineSep || "\n");
4841
- },
4842
-
4843
- getLine: function(line) {var l = this.getLineHandle(line); return l && l.text;},
4844
- setLine: function(line, text) {
4845
- if (isLine(this, line))
4846
- replaceRange(this, text, Pos(line, 0), clipPos(this, Pos(line)));
4847
- },
4848
- removeLine: function(line) {
4849
- if (line) replaceRange(this, "", clipPos(this, Pos(line - 1)), clipPos(this, Pos(line)));
4850
- else replaceRange(this, "", Pos(0, 0), clipPos(this, Pos(1, 0)));
4851
- },
4852
-
4853
- getLineHandle: function(line) {if (isLine(this, line)) return getLine(this, line);},
4854
- getLineNumber: function(line) {return lineNo(line);},
4855
-
4856
- getLineHandleVisualStart: function(line) {
4857
- if (typeof line == "number") line = getLine(this, line);
4858
- return visualLine(this, line);
4859
- },
4860
-
4861
- lineCount: function() {return this.size;},
4862
- firstLine: function() {return this.first;},
4863
- lastLine: function() {return this.first + this.size - 1;},
4864
-
4865
- clipPos: function(pos) {return clipPos(this, pos);},
4866
-
4867
- getCursor: function(start) {
4868
- var sel = this.sel, pos;
4869
- if (start == null || start == "head") pos = sel.head;
4870
- else if (start == "anchor") pos = sel.anchor;
4871
- else if (start == "end" || start === false) pos = sel.to;
4872
- else pos = sel.from;
4873
- return copyPos(pos);
4874
- },
4875
- somethingSelected: function() {return !posEq(this.sel.head, this.sel.anchor);},
4876
-
4877
- setCursor: docOperation(function(line, ch, extend) {
4878
- var pos = clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line);
4879
- if (extend) extendSelection(this, pos);
4880
- else setSelection(this, pos, pos);
4881
- }),
4882
- setSelection: docOperation(function(anchor, head, bias) {
4883
- setSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), bias);
4884
- }),
4885
- extendSelection: docOperation(function(from, to, bias) {
4886
- extendSelection(this, clipPos(this, from), to && clipPos(this, to), bias);
4887
- }),
4888
-
4889
- getSelection: function(lineSep) {return this.getRange(this.sel.from, this.sel.to, lineSep);},
4890
- replaceSelection: function(code, collapse, origin) {
4891
- makeChange(this, {from: this.sel.from, to: this.sel.to, text: splitLines(code), origin: origin}, collapse || "around");
4892
- },
4893
- undo: docOperation(function() {makeChangeFromHistory(this, "undo");}),
4894
- redo: docOperation(function() {makeChangeFromHistory(this, "redo");}),
4895
-
4896
- setExtending: function(val) {this.sel.extend = val;},
4897
-
4898
- historySize: function() {
4899
- var hist = this.history;
4900
- return {undo: hist.done.length, redo: hist.undone.length};
4901
- },
4902
- clearHistory: function() {this.history = makeHistory(this.history.maxGeneration);},
4903
-
4904
- markClean: function() {
4905
- this.cleanGeneration = this.changeGeneration();
4906
- },
4907
- changeGeneration: function() {
4908
- this.history.lastOp = this.history.lastOrigin = null;
4909
- return this.history.generation;
4910
- },
4911
- isClean: function (gen) {
4912
- return this.history.generation == (gen || this.cleanGeneration);
4913
- },
4914
-
4915
- getHistory: function() {
4916
- return {done: copyHistoryArray(this.history.done),
4917
- undone: copyHistoryArray(this.history.undone)};
4918
- },
4919
- setHistory: function(histData) {
4920
- var hist = this.history = makeHistory(this.history.maxGeneration);
4921
- hist.done = histData.done.slice(0);
4922
- hist.undone = histData.undone.slice(0);
4923
- },
4924
-
4925
- markText: function(from, to, options) {
4926
- return markText(this, clipPos(this, from), clipPos(this, to), options, "range");
4927
- },
4928
- setBookmark: function(pos, options) {
4929
- var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options),
4930
- insertLeft: options && options.insertLeft};
4931
- pos = clipPos(this, pos);
4932
- return markText(this, pos, pos, realOpts, "bookmark");
4933
- },
4934
- findMarksAt: function(pos) {
4935
- pos = clipPos(this, pos);
4936
- var markers = [], spans = getLine(this, pos.line).markedSpans;
4937
- if (spans) for (var i = 0; i < spans.length; ++i) {
4938
- var span = spans[i];
4939
- if ((span.from == null || span.from <= pos.ch) &&
4940
- (span.to == null || span.to >= pos.ch))
4941
- markers.push(span.marker.parent || span.marker);
4942
- }
4943
- return markers;
4944
- },
4945
- getAllMarks: function() {
4946
- var markers = [];
4947
- this.iter(function(line) {
4948
- var sps = line.markedSpans;
4949
- if (sps) for (var i = 0; i < sps.length; ++i)
4950
- if (sps[i].from != null) markers.push(sps[i].marker);
4951
- });
4952
- return markers;
4953
- },
4954
-
4955
- posFromIndex: function(off) {
4956
- var ch, lineNo = this.first;
4957
- this.iter(function(line) {
4958
- var sz = line.text.length + 1;
4959
- if (sz > off) { ch = off; return true; }
4960
- off -= sz;
4961
- ++lineNo;
4962
- });
4963
- return clipPos(this, Pos(lineNo, ch));
4964
- },
4965
- indexFromPos: function (coords) {
4966
- coords = clipPos(this, coords);
4967
- var index = coords.ch;
4968
- if (coords.line < this.first || coords.ch < 0) return 0;
4969
- this.iter(this.first, coords.line, function (line) {
4970
- index += line.text.length + 1;
4971
- });
4972
- return index;
4973
- },
4974
-
4975
- copy: function(copyHistory) {
4976
- var doc = new Doc(getLines(this, this.first, this.first + this.size), this.modeOption, this.first);
4977
- doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft;
4978
- doc.sel = {from: this.sel.from, to: this.sel.to, head: this.sel.head, anchor: this.sel.anchor,
4979
- shift: this.sel.shift, extend: false, goalColumn: this.sel.goalColumn};
4980
- if (copyHistory) {
4981
- doc.history.undoDepth = this.history.undoDepth;
4982
- doc.setHistory(this.getHistory());
4983
- }
4984
- return doc;
4985
- },
4986
-
4987
- linkedDoc: function(options) {
4988
- if (!options) options = {};
4989
- var from = this.first, to = this.first + this.size;
4990
- if (options.from != null && options.from > from) from = options.from;
4991
- if (options.to != null && options.to < to) to = options.to;
4992
- var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from);
4993
- if (options.sharedHist) copy.history = this.history;
4994
- (this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist});
4995
- copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}];
4996
- return copy;
4997
- },
4998
- unlinkDoc: function(other) {
4999
- if (other instanceof CodeMirror) other = other.doc;
5000
- if (this.linked) for (var i = 0; i < this.linked.length; ++i) {
5001
- var link = this.linked[i];
5002
- if (link.doc != other) continue;
5003
- this.linked.splice(i, 1);
5004
- other.unlinkDoc(this);
5005
- break;
5006
- }
5007
- // If the histories were shared, split them again
5008
- if (other.history == this.history) {
5009
- var splitIds = [other.id];
5010
- linkedDocs(other, function(doc) {splitIds.push(doc.id);}, true);
5011
- other.history = makeHistory();
5012
- other.history.done = copyHistoryArray(this.history.done, splitIds);
5013
- other.history.undone = copyHistoryArray(this.history.undone, splitIds);
5014
- }
5015
- },
5016
- iterLinkedDocs: function(f) {linkedDocs(this, f);},
5017
-
5018
- getMode: function() {return this.mode;},
5019
- getEditor: function() {return this.cm;}
5020
- });
5021
-
5022
- Doc.prototype.eachLine = Doc.prototype.iter;
5023
-
5024
- // The Doc methods that should be available on CodeMirror instances
5025
- var dontDelegate = "iter insert remove copy getEditor".split(" ");
5026
- for (var prop in Doc.prototype) if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0)
5027
- CodeMirror.prototype[prop] = (function(method) {
5028
- return function() {return method.apply(this.doc, arguments);};
5029
- })(Doc.prototype[prop]);
5030
-
5031
- eventMixin(Doc);
5032
-
5033
- function linkedDocs(doc, f, sharedHistOnly) {
5034
- function propagate(doc, skip, sharedHist) {
5035
- if (doc.linked) for (var i = 0; i < doc.linked.length; ++i) {
5036
- var rel = doc.linked[i];
5037
- if (rel.doc == skip) continue;
5038
- var shared = sharedHist && rel.sharedHist;
5039
- if (sharedHistOnly && !shared) continue;
5040
- f(rel.doc, shared);
5041
- propagate(rel.doc, doc, shared);
5042
- }
5043
- }
5044
- propagate(doc, null, true);
5045
- }
5046
-
5047
- function attachDoc(cm, doc) {
5048
- if (doc.cm) throw new Error("This document is already in use.");
5049
- cm.doc = doc;
5050
- doc.cm = cm;
5051
- estimateLineHeights(cm);
5052
- loadMode(cm);
5053
- if (!cm.options.lineWrapping) computeMaxLength(cm);
5054
- cm.options.mode = doc.modeOption;
5055
- regChange(cm);
5056
- }
5057
-
5058
- // LINE UTILITIES
5059
-
5060
- function getLine(chunk, n) {
5061
- n -= chunk.first;
5062
- while (!chunk.lines) {
5063
- for (var i = 0;; ++i) {
5064
- var child = chunk.children[i], sz = child.chunkSize();
5065
- if (n < sz) { chunk = child; break; }
5066
- n -= sz;
5067
- }
5068
- }
5069
- return chunk.lines[n];
5070
- }
5071
-
5072
- function getBetween(doc, start, end) {
5073
- var out = [], n = start.line;
5074
- doc.iter(start.line, end.line + 1, function(line) {
5075
- var text = line.text;
5076
- if (n == end.line) text = text.slice(0, end.ch);
5077
- if (n == start.line) text = text.slice(start.ch);
5078
- out.push(text);
5079
- ++n;
5080
- });
5081
- return out;
5082
- }
5083
- function getLines(doc, from, to) {
5084
- var out = [];
5085
- doc.iter(from, to, function(line) { out.push(line.text); });
5086
- return out;
5087
- }
5088
-
5089
- function updateLineHeight(line, height) {
5090
- var diff = height - line.height;
5091
- for (var n = line; n; n = n.parent) n.height += diff;
5092
- }
5093
-
5094
- function lineNo(line) {
5095
- if (line.parent == null) return null;
5096
- var cur = line.parent, no = indexOf(cur.lines, line);
5097
- for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
5098
- for (var i = 0;; ++i) {
5099
- if (chunk.children[i] == cur) break;
5100
- no += chunk.children[i].chunkSize();
5101
- }
5102
- }
5103
- return no + cur.first;
5104
- }
5105
-
5106
- function lineAtHeight(chunk, h) {
5107
- var n = chunk.first;
5108
- outer: do {
5109
- for (var i = 0, e = chunk.children.length; i < e; ++i) {
5110
- var child = chunk.children[i], ch = child.height;
5111
- if (h < ch) { chunk = child; continue outer; }
5112
- h -= ch;
5113
- n += child.chunkSize();
5114
- }
5115
- return n;
5116
- } while (!chunk.lines);
5117
- for (var i = 0, e = chunk.lines.length; i < e; ++i) {
5118
- var line = chunk.lines[i], lh = line.height;
5119
- if (h < lh) break;
5120
- h -= lh;
5121
- }
5122
- return n + i;
5123
- }
5124
-
5125
- function heightAtLine(cm, lineObj) {
5126
- lineObj = visualLine(cm.doc, lineObj);
5127
-
5128
- var h = 0, chunk = lineObj.parent;
5129
- for (var i = 0; i < chunk.lines.length; ++i) {
5130
- var line = chunk.lines[i];
5131
- if (line == lineObj) break;
5132
- else h += line.height;
5133
- }
5134
- for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
5135
- for (var i = 0; i < p.children.length; ++i) {
5136
- var cur = p.children[i];
5137
- if (cur == chunk) break;
5138
- else h += cur.height;
5139
- }
5140
- }
5141
- return h;
5142
- }
5143
-
5144
- function getOrder(line) {
5145
- var order = line.order;
5146
- if (order == null) order = line.order = bidiOrdering(line.text);
5147
- return order;
5148
- }
5149
-
5150
- // HISTORY
5151
-
5152
- function makeHistory(startGen) {
5153
- return {
5154
- // Arrays of history events. Doing something adds an event to
5155
- // done and clears undo. Undoing moves events from done to
5156
- // undone, redoing moves them in the other direction.
5157
- done: [], undone: [], undoDepth: Infinity,
5158
- // Used to track when changes can be merged into a single undo
5159
- // event
5160
- lastTime: 0, lastOp: null, lastOrigin: null,
5161
- // Used by the isClean() method
5162
- generation: startGen || 1, maxGeneration: startGen || 1
5163
- };
5164
- }
5165
-
5166
- function attachLocalSpans(doc, change, from, to) {
5167
- var existing = change["spans_" + doc.id], n = 0;
5168
- doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function(line) {
5169
- if (line.markedSpans)
5170
- (existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans;
5171
- ++n;
5172
- });
5173
- }
5174
-
5175
- function historyChangeFromChange(doc, change) {
5176
- var from = { line: change.from.line, ch: change.from.ch };
5177
- var histChange = {from: from, to: changeEnd(change), text: getBetween(doc, change.from, change.to)};
5178
- attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);
5179
- linkedDocs(doc, function(doc) {attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);}, true);
5180
- return histChange;
5181
- }
5182
-
5183
- function addToHistory(doc, change, selAfter, opId) {
5184
- var hist = doc.history;
5185
- hist.undone.length = 0;
5186
- var time = +new Date, cur = lst(hist.done);
5187
-
5188
- if (cur &&
5189
- (hist.lastOp == opId ||
5190
- hist.lastOrigin == change.origin && change.origin &&
5191
- ((change.origin.charAt(0) == "+" && doc.cm && hist.lastTime > time - doc.cm.options.historyEventDelay) ||
5192
- change.origin.charAt(0) == "*"))) {
5193
- // Merge this change into the last event
5194
- var last = lst(cur.changes);
5195
- if (posEq(change.from, change.to) && posEq(change.from, last.to)) {
5196
- // Optimized case for simple insertion -- don't want to add
5197
- // new changesets for every character typed
5198
- last.to = changeEnd(change);
5199
- } else {
5200
- // Add new sub-event
5201
- cur.changes.push(historyChangeFromChange(doc, change));
5202
- }
5203
- cur.anchorAfter = selAfter.anchor; cur.headAfter = selAfter.head;
5204
- } else {
5205
- // Can not be merged, start a new event.
5206
- cur = {changes: [historyChangeFromChange(doc, change)],
5207
- generation: hist.generation,
5208
- anchorBefore: doc.sel.anchor, headBefore: doc.sel.head,
5209
- anchorAfter: selAfter.anchor, headAfter: selAfter.head};
5210
- hist.done.push(cur);
5211
- hist.generation = ++hist.maxGeneration;
5212
- while (hist.done.length > hist.undoDepth)
5213
- hist.done.shift();
5214
- }
5215
- hist.lastTime = time;
5216
- hist.lastOp = opId;
5217
- hist.lastOrigin = change.origin;
5218
- }
5219
-
5220
- function removeClearedSpans(spans) {
5221
- if (!spans) return null;
5222
- for (var i = 0, out; i < spans.length; ++i) {
5223
- if (spans[i].marker.explicitlyCleared) { if (!out) out = spans.slice(0, i); }
5224
- else if (out) out.push(spans[i]);
5225
- }
5226
- return !out ? spans : out.length ? out : null;
5227
- }
5228
-
5229
- function getOldSpans(doc, change) {
5230
- var found = change["spans_" + doc.id];
5231
- if (!found) return null;
5232
- for (var i = 0, nw = []; i < change.text.length; ++i)
5233
- nw.push(removeClearedSpans(found[i]));
5234
- return nw;
5235
- }
5236
-
5237
- // Used both to provide a JSON-safe object in .getHistory, and, when
5238
- // detaching a document, to split the history in two
5239
- function copyHistoryArray(events, newGroup) {
5240
- for (var i = 0, copy = []; i < events.length; ++i) {
5241
- var event = events[i], changes = event.changes, newChanges = [];
5242
- copy.push({changes: newChanges, anchorBefore: event.anchorBefore, headBefore: event.headBefore,
5243
- anchorAfter: event.anchorAfter, headAfter: event.headAfter});
5244
- for (var j = 0; j < changes.length; ++j) {
5245
- var change = changes[j], m;
5246
- newChanges.push({from: change.from, to: change.to, text: change.text});
5247
- if (newGroup) for (var prop in change) if (m = prop.match(/^spans_(\d+)$/)) {
5248
- if (indexOf(newGroup, Number(m[1])) > -1) {
5249
- lst(newChanges)[prop] = change[prop];
5250
- delete change[prop];
5251
- }
5252
- }
5253
- }
5254
- }
5255
- return copy;
5256
- }
5257
-
5258
- // Rebasing/resetting history to deal with externally-sourced changes
5259
-
5260
- function rebaseHistSel(pos, from, to, diff) {
5261
- if (to < pos.line) {
5262
- pos.line += diff;
5263
- } else if (from < pos.line) {
5264
- pos.line = from;
5265
- pos.ch = 0;
5266
- }
5267
- }
5268
-
5269
- // Tries to rebase an array of history events given a change in the
5270
- // document. If the change touches the same lines as the event, the
5271
- // event, and everything 'behind' it, is discarded. If the change is
5272
- // before the event, the event's positions are updated. Uses a
5273
- // copy-on-write scheme for the positions, to avoid having to
5274
- // reallocate them all on every rebase, but also avoid problems with
5275
- // shared position objects being unsafely updated.
5276
- function rebaseHistArray(array, from, to, diff) {
5277
- for (var i = 0; i < array.length; ++i) {
5278
- var sub = array[i], ok = true;
5279
- for (var j = 0; j < sub.changes.length; ++j) {
5280
- var cur = sub.changes[j];
5281
- if (!sub.copied) { cur.from = copyPos(cur.from); cur.to = copyPos(cur.to); }
5282
- if (to < cur.from.line) {
5283
- cur.from.line += diff;
5284
- cur.to.line += diff;
5285
- } else if (from <= cur.to.line) {
5286
- ok = false;
5287
- break;
5288
- }
5289
- }
5290
- if (!sub.copied) {
5291
- sub.anchorBefore = copyPos(sub.anchorBefore); sub.headBefore = copyPos(sub.headBefore);
5292
- sub.anchorAfter = copyPos(sub.anchorAfter); sub.readAfter = copyPos(sub.headAfter);
5293
- sub.copied = true;
5294
- }
5295
- if (!ok) {
5296
- array.splice(0, i + 1);
5297
- i = 0;
5298
- } else {
5299
- rebaseHistSel(sub.anchorBefore); rebaseHistSel(sub.headBefore);
5300
- rebaseHistSel(sub.anchorAfter); rebaseHistSel(sub.headAfter);
5301
- }
5302
- }
5303
- }
5304
-
5305
- function rebaseHist(hist, change) {
5306
- var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1;
5307
- rebaseHistArray(hist.done, from, to, diff);
5308
- rebaseHistArray(hist.undone, from, to, diff);
5309
- }
5310
-
5311
- // EVENT OPERATORS
5312
-
5313
- function stopMethod() {e_stop(this);}
5314
- // Ensure an event has a stop method.
5315
- function addStop(event) {
5316
- if (!event.stop) event.stop = stopMethod;
5317
- return event;
5318
- }
5319
-
5320
- function e_preventDefault(e) {
5321
- if (e.preventDefault) e.preventDefault();
5322
- else e.returnValue = false;
5323
- }
5324
- function e_stopPropagation(e) {
5325
- if (e.stopPropagation) e.stopPropagation();
5326
- else e.cancelBubble = true;
5327
- }
5328
- function e_defaultPrevented(e) {
5329
- return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false;
5330
- }
5331
- function e_stop(e) {e_preventDefault(e); e_stopPropagation(e);}
5332
- CodeMirror.e_stop = e_stop;
5333
- CodeMirror.e_preventDefault = e_preventDefault;
5334
- CodeMirror.e_stopPropagation = e_stopPropagation;
5335
-
5336
- function e_target(e) {return e.target || e.srcElement;}
5337
- function e_button(e) {
5338
- var b = e.which;
5339
- if (b == null) {
5340
- if (e.button & 1) b = 1;
5341
- else if (e.button & 2) b = 3;
5342
- else if (e.button & 4) b = 2;
5343
- }
5344
- if (mac && e.ctrlKey && b == 1) b = 3;
5345
- return b;
5346
- }
5347
-
5348
- // EVENT HANDLING
5349
-
5350
- function on(emitter, type, f) {
5351
- if (emitter.addEventListener)
5352
- emitter.addEventListener(type, f, false);
5353
- else if (emitter.attachEvent)
5354
- emitter.attachEvent("on" + type, f);
5355
- else {
5356
- var map = emitter._handlers || (emitter._handlers = {});
5357
- var arr = map[type] || (map[type] = []);
5358
- arr.push(f);
5359
- }
5360
- }
5361
-
5362
- function off(emitter, type, f) {
5363
- if (emitter.removeEventListener)
5364
- emitter.removeEventListener(type, f, false);
5365
- else if (emitter.detachEvent)
5366
- emitter.detachEvent("on" + type, f);
5367
- else {
5368
- var arr = emitter._handlers && emitter._handlers[type];
5369
- if (!arr) return;
5370
- for (var i = 0; i < arr.length; ++i)
5371
- if (arr[i] == f) { arr.splice(i, 1); break; }
5372
- }
5373
- }
5374
-
5375
- function signal(emitter, type /*, values...*/) {
5376
- var arr = emitter._handlers && emitter._handlers[type];
5377
- if (!arr) return;
5378
- var args = Array.prototype.slice.call(arguments, 2);
5379
- for (var i = 0; i < arr.length; ++i) arr[i].apply(null, args);
5380
- }
5381
-
5382
- var delayedCallbacks, delayedCallbackDepth = 0;
5383
- function signalLater(emitter, type /*, values...*/) {
5384
- var arr = emitter._handlers && emitter._handlers[type];
5385
- if (!arr) return;
5386
- var args = Array.prototype.slice.call(arguments, 2);
5387
- if (!delayedCallbacks) {
5388
- ++delayedCallbackDepth;
5389
- delayedCallbacks = [];
5390
- setTimeout(fireDelayed, 0);
5391
- }
5392
- function bnd(f) {return function(){f.apply(null, args);};};
5393
- for (var i = 0; i < arr.length; ++i)
5394
- delayedCallbacks.push(bnd(arr[i]));
5395
- }
5396
-
5397
- function signalDOMEvent(cm, e, override) {
5398
- signal(cm, override || e.type, cm, e);
5399
- return e_defaultPrevented(e) || e.codemirrorIgnore;
5400
- }
5401
-
5402
- function fireDelayed() {
5403
- --delayedCallbackDepth;
5404
- var delayed = delayedCallbacks;
5405
- delayedCallbacks = null;
5406
- for (var i = 0; i < delayed.length; ++i) delayed[i]();
5407
- }
5408
-
5409
- function hasHandler(emitter, type) {
5410
- var arr = emitter._handlers && emitter._handlers[type];
5411
- return arr && arr.length > 0;
5412
- }
5413
-
5414
- CodeMirror.on = on; CodeMirror.off = off; CodeMirror.signal = signal;
5415
-
5416
- function eventMixin(ctor) {
5417
- ctor.prototype.on = function(type, f) {on(this, type, f);};
5418
- ctor.prototype.off = function(type, f) {off(this, type, f);};
5419
- }
5420
-
5421
- // MISC UTILITIES
5422
-
5423
- // Number of pixels added to scroller and sizer to hide scrollbar
5424
- var scrollerCutOff = 30;
5425
-
5426
- // Returned or thrown by various protocols to signal 'I'm not
5427
- // handling this'.
5428
- var Pass = CodeMirror.Pass = {toString: function(){return "CodeMirror.Pass";}};
5429
-
5430
- function Delayed() {this.id = null;}
5431
- Delayed.prototype = {set: function(ms, f) {clearTimeout(this.id); this.id = setTimeout(f, ms);}};
5432
-
5433
- // Counts the column offset in a string, taking tabs into account.
5434
- // Used mostly to find indentation.
5435
- function countColumn(string, end, tabSize, startIndex, startValue) {
5436
- if (end == null) {
5437
- end = string.search(/[^\s\u00a0]/);
5438
- if (end == -1) end = string.length;
5439
- }
5440
- for (var i = startIndex || 0, n = startValue || 0; i < end; ++i) {
5441
- if (string.charAt(i) == "\t") n += tabSize - (n % tabSize);
5442
- else ++n;
5443
- }
5444
- return n;
5445
- }
5446
- CodeMirror.countColumn = countColumn;
5447
-
5448
- var spaceStrs = [""];
5449
- function spaceStr(n) {
5450
- while (spaceStrs.length <= n)
5451
- spaceStrs.push(lst(spaceStrs) + " ");
5452
- return spaceStrs[n];
5453
- }
5454
-
5455
- function lst(arr) { return arr[arr.length-1]; }
5456
-
5457
- function selectInput(node) {
5458
- if (ios) { // Mobile Safari apparently has a bug where select() is broken.
5459
- node.selectionStart = 0;
5460
- node.selectionEnd = node.value.length;
5461
- } else {
5462
- // Suppress mysterious IE10 errors
5463
- try { node.select(); }
5464
- catch(_e) {}
5465
- }
5466
- }
5467
-
5468
- function indexOf(collection, elt) {
5469
- if (collection.indexOf) return collection.indexOf(elt);
5470
- for (var i = 0, e = collection.length; i < e; ++i)
5471
- if (collection[i] == elt) return i;
5472
- return -1;
5473
- }
5474
-
5475
- function createObj(base, props) {
5476
- function Obj() {}
5477
- Obj.prototype = base;
5478
- var inst = new Obj();
5479
- if (props) copyObj(props, inst);
5480
- return inst;
5481
- }
5482
-
5483
- function copyObj(obj, target) {
5484
- if (!target) target = {};
5485
- for (var prop in obj) if (obj.hasOwnProperty(prop)) target[prop] = obj[prop];
5486
- return target;
5487
- }
5488
-
5489
- function emptyArray(size) {
5490
- for (var a = [], i = 0; i < size; ++i) a.push(undefined);
5491
- return a;
5492
- }
5493
-
5494
- function bind(f) {
5495
- var args = Array.prototype.slice.call(arguments, 1);
5496
- return function(){return f.apply(null, args);};
5497
- }
5498
-
5499
- var nonASCIISingleCaseWordChar = /[\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
5500
- function isWordChar(ch) {
5501
- return /\w/.test(ch) || ch > "\x80" &&
5502
- (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch));
5503
- }
5504
-
5505
- function isEmpty(obj) {
5506
- for (var n in obj) if (obj.hasOwnProperty(n) && obj[n]) return false;
5507
- return true;
5508
- }
5509
-
5510
- var isExtendingChar = /[\u0300-\u036F\u0483-\u0487\u0488-\u0489\u0591-\u05BD\u05BF\u05C1-\u05C2\u05C4-\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7-\u06E8\u06EA-\u06ED\uA66F\u1DC0–\u1DFF\u20D0–\u20FF\uA670-\uA672\uA674-\uA67D\uA69F\udc00-\udfff\uFE20–\uFE2F]/;
5511
-
5512
- // DOM UTILITIES
5513
-
5514
- function elt(tag, content, className, style) {
5515
- var e = document.createElement(tag);
5516
- if (className) e.className = className;
5517
- if (style) e.style.cssText = style;
5518
- if (typeof content == "string") setTextContent(e, content);
5519
- else if (content) for (var i = 0; i < content.length; ++i) e.appendChild(content[i]);
5520
- return e;
5521
- }
5522
-
5523
- function removeChildren(e) {
5524
- for (var count = e.childNodes.length; count > 0; --count)
5525
- e.removeChild(e.firstChild);
5526
- return e;
5527
- }
5528
-
5529
- function removeChildrenAndAdd(parent, e) {
5530
- return removeChildren(parent).appendChild(e);
5531
- }
5532
-
5533
- function setTextContent(e, str) {
5534
- if (ie_lt9) {
5535
- e.innerHTML = "";
5536
- e.appendChild(document.createTextNode(str));
5537
- } else e.textContent = str;
5538
- }
5539
-
5540
- function getRect(node) {
5541
- return node.getBoundingClientRect();
5542
- }
5543
- CodeMirror.replaceGetRect = function(f) { getRect = f; };
5544
-
5545
- // FEATURE DETECTION
5546
-
5547
- // Detect drag-and-drop
5548
- var dragAndDrop = function() {
5549
- // There is *some* kind of drag-and-drop support in IE6-8, but I
5550
- // couldn't get it to work yet.
5551
- if (ie_lt9) return false;
5552
- var div = elt('div');
5553
- return "draggable" in div || "dragDrop" in div;
5554
- }();
5555
-
5556
- // For a reason I have yet to figure out, some browsers disallow
5557
- // word wrapping between certain characters *only* if a new inline
5558
- // element is started between them. This makes it hard to reliably
5559
- // measure the position of things, since that requires inserting an
5560
- // extra span. This terribly fragile set of tests matches the
5561
- // character combinations that suffer from this phenomenon on the
5562
- // various browsers.
5563
- function spanAffectsWrapping() { return false; }
5564
- if (gecko) // Only for "$'"
5565
- spanAffectsWrapping = function(str, i) {
5566
- return str.charCodeAt(i - 1) == 36 && str.charCodeAt(i) == 39;
5567
- };
5568
- else if (safari && !/Version\/([6-9]|\d\d)\b/.test(navigator.userAgent))
5569
- spanAffectsWrapping = function(str, i) {
5570
- return /\-[^ \-?]|\?[^ !\'\"\),.\-\/:;\?\]\}]/.test(str.slice(i - 1, i + 1));
5571
- };
5572
- else if (webkit && /Chrome\/(?:29|[3-9]\d|\d\d\d)\./.test(navigator.userAgent))
5573
- spanAffectsWrapping = function(str, i) {
5574
- var code = str.charCodeAt(i - 1);
5575
- return code >= 8208 && code <= 8212;
5576
- };
5577
- else if (webkit)
5578
- spanAffectsWrapping = function(str, i) {
5579
- if (i > 1 && str.charCodeAt(i - 1) == 45) {
5580
- if (/\w/.test(str.charAt(i - 2)) && /[^\-?\.]/.test(str.charAt(i))) return true;
5581
- if (i > 2 && /[\d\.,]/.test(str.charAt(i - 2)) && /[\d\.,]/.test(str.charAt(i))) return false;
5582
- }
5583
- return /[~!#%&*)=+}\]\\|\"\.>,:;][({[<]|-[^\-?\.\u2010-\u201f\u2026]|\?[\w~`@#$%\^&*(_=+{[|><]|…[\w~`@#$%\^&*(_=+{[><]/.test(str.slice(i - 1, i + 1));
5584
- };
5585
-
5586
- var knownScrollbarWidth;
5587
- function scrollbarWidth(measure) {
5588
- if (knownScrollbarWidth != null) return knownScrollbarWidth;
5589
- var test = elt("div", null, null, "width: 50px; height: 50px; overflow-x: scroll");
5590
- removeChildrenAndAdd(measure, test);
5591
- if (test.offsetWidth)
5592
- knownScrollbarWidth = test.offsetHeight - test.clientHeight;
5593
- return knownScrollbarWidth || 0;
5594
- }
5595
-
5596
- var zwspSupported;
5597
- function zeroWidthElement(measure) {
5598
- if (zwspSupported == null) {
5599
- var test = elt("span", "\u200b");
5600
- removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]));
5601
- if (measure.firstChild.offsetHeight != 0)
5602
- zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !ie_lt8;
5603
- }
5604
- if (zwspSupported) return elt("span", "\u200b");
5605
- else return elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px");
5606
- }
5607
-
5608
- // See if "".split is the broken IE version, if so, provide an
5609
- // alternative way to split lines.
5610
- var splitLines = "\n\nb".split(/\n/).length != 3 ? function(string) {
5611
- var pos = 0, result = [], l = string.length;
5612
- while (pos <= l) {
5613
- var nl = string.indexOf("\n", pos);
5614
- if (nl == -1) nl = string.length;
5615
- var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
5616
- var rt = line.indexOf("\r");
5617
- if (rt != -1) {
5618
- result.push(line.slice(0, rt));
5619
- pos += rt + 1;
5620
- } else {
5621
- result.push(line);
5622
- pos = nl + 1;
5623
- }
5624
- }
5625
- return result;
5626
- } : function(string){return string.split(/\r\n?|\n/);};
5627
- CodeMirror.splitLines = splitLines;
5628
-
5629
- var hasSelection = window.getSelection ? function(te) {
5630
- try { return te.selectionStart != te.selectionEnd; }
5631
- catch(e) { return false; }
5632
- } : function(te) {
5633
- try {var range = te.ownerDocument.selection.createRange();}
5634
- catch(e) {}
5635
- if (!range || range.parentElement() != te) return false;
5636
- return range.compareEndPoints("StartToEnd", range) != 0;
5637
- };
5638
-
5639
- var hasCopyEvent = (function() {
5640
- var e = elt("div");
5641
- if ("oncopy" in e) return true;
5642
- e.setAttribute("oncopy", "return;");
5643
- return typeof e.oncopy == 'function';
5644
- })();
5645
-
5646
- // KEY NAMING
5647
-
5648
- var keyNames = {3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
5649
- 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
5650
- 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
5651
- 46: "Delete", 59: ";", 91: "Mod", 92: "Mod", 93: "Mod", 109: "-", 107: "=", 127: "Delete",
5652
- 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
5653
- 221: "]", 222: "'", 63276: "PageUp", 63277: "PageDown", 63275: "End", 63273: "Home",
5654
- 63234: "Left", 63232: "Up", 63235: "Right", 63233: "Down", 63302: "Insert", 63272: "Delete"};
5655
- CodeMirror.keyNames = keyNames;
5656
- (function() {
5657
- // Number keys
5658
- for (var i = 0; i < 10; i++) keyNames[i + 48] = String(i);
5659
- // Alphabetic keys
5660
- for (var i = 65; i <= 90; i++) keyNames[i] = String.fromCharCode(i);
5661
- // Function keys
5662
- for (var i = 1; i <= 12; i++) keyNames[i + 111] = keyNames[i + 63235] = "F" + i;
5663
- })();
5664
-
5665
- // BIDI HELPERS
5666
-
5667
- function iterateBidiSections(order, from, to, f) {
5668
- if (!order) return f(from, to, "ltr");
5669
- var found = false;
5670
- for (var i = 0; i < order.length; ++i) {
5671
- var part = order[i];
5672
- if (part.from < to && part.to > from || from == to && part.to == from) {
5673
- f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr");
5674
- found = true;
5675
- }
5676
- }
5677
- if (!found) f(from, to, "ltr");
5678
- }
5679
-
5680
- function bidiLeft(part) { return part.level % 2 ? part.to : part.from; }
5681
- function bidiRight(part) { return part.level % 2 ? part.from : part.to; }
5682
-
5683
- function lineLeft(line) { var order = getOrder(line); return order ? bidiLeft(order[0]) : 0; }
5684
- function lineRight(line) {
5685
- var order = getOrder(line);
5686
- if (!order) return line.text.length;
5687
- return bidiRight(lst(order));
5688
- }
5689
-
5690
- function lineStart(cm, lineN) {
5691
- var line = getLine(cm.doc, lineN);
5692
- var visual = visualLine(cm.doc, line);
5693
- if (visual != line) lineN = lineNo(visual);
5694
- var order = getOrder(visual);
5695
- var ch = !order ? 0 : order[0].level % 2 ? lineRight(visual) : lineLeft(visual);
5696
- return Pos(lineN, ch);
5697
- }
5698
- function lineEnd(cm, lineN) {
5699
- var merged, line;
5700
- while (merged = collapsedSpanAtEnd(line = getLine(cm.doc, lineN)))
5701
- lineN = merged.find().to.line;
5702
- var order = getOrder(line);
5703
- var ch = !order ? line.text.length : order[0].level % 2 ? lineLeft(line) : lineRight(line);
5704
- return Pos(lineN, ch);
5705
- }
5706
-
5707
- function compareBidiLevel(order, a, b) {
5708
- var linedir = order[0].level;
5709
- if (a == linedir) return true;
5710
- if (b == linedir) return false;
5711
- return a < b;
5712
- }
5713
- var bidiOther;
5714
- function getBidiPartAt(order, pos) {
5715
- for (var i = 0, found; i < order.length; ++i) {
5716
- var cur = order[i];
5717
- if (cur.from < pos && cur.to > pos) { bidiOther = null; return i; }
5718
- if (cur.from == pos || cur.to == pos) {
5719
- if (found == null) {
5720
- found = i;
5721
- } else if (compareBidiLevel(order, cur.level, order[found].level)) {
5722
- bidiOther = found;
5723
- return i;
5724
- } else {
5725
- bidiOther = i;
5726
- return found;
5727
- }
5728
- }
5729
- }
5730
- bidiOther = null;
5731
- return found;
5732
- }
5733
-
5734
- function moveInLine(line, pos, dir, byUnit) {
5735
- if (!byUnit) return pos + dir;
5736
- do pos += dir;
5737
- while (pos > 0 && isExtendingChar.test(line.text.charAt(pos)));
5738
- return pos;
5739
- }
5740
-
5741
- // This is somewhat involved. It is needed in order to move
5742
- // 'visually' through bi-directional text -- i.e., pressing left
5743
- // should make the cursor go left, even when in RTL text. The
5744
- // tricky part is the 'jumps', where RTL and LTR text touch each
5745
- // other. This often requires the cursor offset to move more than
5746
- // one unit, in order to visually move one unit.
5747
- function moveVisually(line, start, dir, byUnit) {
5748
- var bidi = getOrder(line);
5749
- if (!bidi) return moveLogically(line, start, dir, byUnit);
5750
- var pos = getBidiPartAt(bidi, start), part = bidi[pos];
5751
- var target = moveInLine(line, start, part.level % 2 ? -dir : dir, byUnit);
5752
-
5753
- for (;;) {
5754
- if (target > part.from && target < part.to) return target;
5755
- if (target == part.from || target == part.to) {
5756
- if (getBidiPartAt(bidi, target) == pos) return target;
5757
- part = bidi[pos += dir];
5758
- return (dir > 0) == part.level % 2 ? part.to : part.from;
5759
- } else {
5760
- part = bidi[pos += dir];
5761
- if (!part) return null;
5762
- if ((dir > 0) == part.level % 2)
5763
- target = moveInLine(line, part.to, -1, byUnit);
5764
- else
5765
- target = moveInLine(line, part.from, 1, byUnit);
5766
- }
5767
- }
5768
- }
5769
-
5770
- function moveLogically(line, start, dir, byUnit) {
5771
- var target = start + dir;
5772
- if (byUnit) while (target > 0 && isExtendingChar.test(line.text.charAt(target))) target += dir;
5773
- return target < 0 || target > line.text.length ? null : target;
5774
- }
5775
-
5776
- // Bidirectional ordering algorithm
5777
- // See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
5778
- // that this (partially) implements.
5779
-
5780
- // One-char codes used for character types:
5781
- // L (L): Left-to-Right
5782
- // R (R): Right-to-Left
5783
- // r (AL): Right-to-Left Arabic
5784
- // 1 (EN): European Number
5785
- // + (ES): European Number Separator
5786
- // % (ET): European Number Terminator
5787
- // n (AN): Arabic Number
5788
- // , (CS): Common Number Separator
5789
- // m (NSM): Non-Spacing Mark
5790
- // b (BN): Boundary Neutral
5791
- // s (B): Paragraph Separator
5792
- // t (S): Segment Separator
5793
- // w (WS): Whitespace
5794
- // N (ON): Other Neutrals
5795
-
5796
- // Returns null if characters are ordered as they appear
5797
- // (left-to-right), or an array of sections ({from, to, level}
5798
- // objects) in the order in which they occur visually.
5799
- var bidiOrdering = (function() {
5800
- // Character types for codepoints 0 to 0xff
5801
- var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLL";
5802
- // Character types for codepoints 0x600 to 0x6ff
5803
- var arabicTypes = "rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmmrrrrrrrrrrrrrrrrrr";
5804
- function charType(code) {
5805
- if (code <= 0xff) return lowTypes.charAt(code);
5806
- else if (0x590 <= code && code <= 0x5f4) return "R";
5807
- else if (0x600 <= code && code <= 0x6ff) return arabicTypes.charAt(code - 0x600);
5808
- else if (0x700 <= code && code <= 0x8ac) return "r";
5809
- else return "L";
5810
- }
5811
-
5812
- var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
5813
- var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/;
5814
- // Browsers seem to always treat the boundaries of block elements as being L.
5815
- var outerType = "L";
5816
-
5817
- return function(str) {
5818
- if (!bidiRE.test(str)) return false;
5819
- var len = str.length, types = [];
5820
- for (var i = 0, type; i < len; ++i)
5821
- types.push(type = charType(str.charCodeAt(i)));
5822
-
5823
- // W1. Examine each non-spacing mark (NSM) in the level run, and
5824
- // change the type of the NSM to the type of the previous
5825
- // character. If the NSM is at the start of the level run, it will
5826
- // get the type of sor.
5827
- for (var i = 0, prev = outerType; i < len; ++i) {
5828
- var type = types[i];
5829
- if (type == "m") types[i] = prev;
5830
- else prev = type;
5831
- }
5832
-
5833
- // W2. Search backwards from each instance of a European number
5834
- // until the first strong type (R, L, AL, or sor) is found. If an
5835
- // AL is found, change the type of the European number to Arabic
5836
- // number.
5837
- // W3. Change all ALs to R.
5838
- for (var i = 0, cur = outerType; i < len; ++i) {
5839
- var type = types[i];
5840
- if (type == "1" && cur == "r") types[i] = "n";
5841
- else if (isStrong.test(type)) { cur = type; if (type == "r") types[i] = "R"; }
5842
- }
5843
-
5844
- // W4. A single European separator between two European numbers
5845
- // changes to a European number. A single common separator between
5846
- // two numbers of the same type changes to that type.
5847
- for (var i = 1, prev = types[0]; i < len - 1; ++i) {
5848
- var type = types[i];
5849
- if (type == "+" && prev == "1" && types[i+1] == "1") types[i] = "1";
5850
- else if (type == "," && prev == types[i+1] &&
5851
- (prev == "1" || prev == "n")) types[i] = prev;
5852
- prev = type;
5853
- }
5854
-
5855
- // W5. A sequence of European terminators adjacent to European
5856
- // numbers changes to all European numbers.
5857
- // W6. Otherwise, separators and terminators change to Other
5858
- // Neutral.
5859
- for (var i = 0; i < len; ++i) {
5860
- var type = types[i];
5861
- if (type == ",") types[i] = "N";
5862
- else if (type == "%") {
5863
- for (var end = i + 1; end < len && types[end] == "%"; ++end) {}
5864
- var replace = (i && types[i-1] == "!") || (end < len - 1 && types[end] == "1") ? "1" : "N";
5865
- for (var j = i; j < end; ++j) types[j] = replace;
5866
- i = end - 1;
5867
- }
5868
- }
5869
-
5870
- // W7. Search backwards from each instance of a European number
5871
- // until the first strong type (R, L, or sor) is found. If an L is
5872
- // found, then change the type of the European number to L.
5873
- for (var i = 0, cur = outerType; i < len; ++i) {
5874
- var type = types[i];
5875
- if (cur == "L" && type == "1") types[i] = "L";
5876
- else if (isStrong.test(type)) cur = type;
5877
- }
5878
-
5879
- // N1. A sequence of neutrals takes the direction of the
5880
- // surrounding strong text if the text on both sides has the same
5881
- // direction. European and Arabic numbers act as if they were R in
5882
- // terms of their influence on neutrals. Start-of-level-run (sor)
5883
- // and end-of-level-run (eor) are used at level run boundaries.
5884
- // N2. Any remaining neutrals take the embedding direction.
5885
- for (var i = 0; i < len; ++i) {
5886
- if (isNeutral.test(types[i])) {
5887
- for (var end = i + 1; end < len && isNeutral.test(types[end]); ++end) {}
5888
- var before = (i ? types[i-1] : outerType) == "L";
5889
- var after = (end < len - 1 ? types[end] : outerType) == "L";
5890
- var replace = before || after ? "L" : "R";
5891
- for (var j = i; j < end; ++j) types[j] = replace;
5892
- i = end - 1;
5893
- }
5894
- }
5895
-
5896
- // Here we depart from the documented algorithm, in order to avoid
5897
- // building up an actual levels array. Since there are only three
5898
- // levels (0, 1, 2) in an implementation that doesn't take
5899
- // explicit embedding into account, we can build up the order on
5900
- // the fly, without following the level-based algorithm.
5901
- var order = [], m;
5902
- for (var i = 0; i < len;) {
5903
- if (countsAsLeft.test(types[i])) {
5904
- var start = i;
5905
- for (++i; i < len && countsAsLeft.test(types[i]); ++i) {}
5906
- order.push({from: start, to: i, level: 0});
5907
- } else {
5908
- var pos = i, at = order.length;
5909
- for (++i; i < len && types[i] != "L"; ++i) {}
5910
- for (var j = pos; j < i;) {
5911
- if (countsAsNum.test(types[j])) {
5912
- if (pos < j) order.splice(at, 0, {from: pos, to: j, level: 1});
5913
- var nstart = j;
5914
- for (++j; j < i && countsAsNum.test(types[j]); ++j) {}
5915
- order.splice(at, 0, {from: nstart, to: j, level: 2});
5916
- pos = j;
5917
- } else ++j;
5918
- }
5919
- if (pos < i) order.splice(at, 0, {from: pos, to: i, level: 1});
5920
- }
5921
- }
5922
- if (order[0].level == 1 && (m = str.match(/^\s+/))) {
5923
- order[0].from = m[0].length;
5924
- order.unshift({from: 0, to: m[0].length, level: 0});
5925
- }
5926
- if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
5927
- lst(order).to -= m[0].length;
5928
- order.push({from: len - m[0].length, to: len, level: 0});
5929
- }
5930
- if (order[0].level != lst(order).level)
5931
- order.push({from: len, to: len, level: order[0].level});
5932
-
5933
- return order;
5934
- };
5935
- })();
5936
-
5937
- // THE END
5938
-
5939
- CodeMirror.version = "3.20.0";
5940
-
5941
- return CodeMirror;
5942
- })();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ initScrollbars(this);
81
+
82
+ this.state = {
83
+ keyMaps: [], // stores maps added by addKeyMap
84
+ overlays: [], // highlighting overlays, as added by addOverlay
85
+ modeGen: 0, // bumped when mode/overlay changes, used to invalidate highlighting info
86
+ overwrite: false, focused: false,
87
+ suppressEdits: false, // used to disable editing during key handlers when in readOnly mode
88
+ pasteIncoming: false, cutIncoming: false, // help recognize paste/cut edits in readInput
89
+ draggingText: false,
90
+ highlight: new Delayed(), // stores highlight worker timeout
91
+ keySeq: null // Unfinished key sequence
92
+ };
93
+
94
+ // Override magic textarea content restore that IE sometimes does
95
+ // on our hidden textarea on reload
96
+ if (ie && ie_version < 11) setTimeout(bind(resetInput, this, true), 20);
97
+
98
+ registerEventHandlers(this);
99
+ ensureGlobalHandlers();
100
+
101
+ startOperation(this);
102
+ this.curOp.forceUpdate = true;
103
+ attachDoc(this, doc);
104
+
105
+ if ((options.autofocus && !mobile) || activeElt() == display.input)
106
+ setTimeout(bind(onFocus, this), 20);
107
+ else
108
+ onBlur(this);
109
+
110
+ for (var opt in optionHandlers) if (optionHandlers.hasOwnProperty(opt))
111
+ optionHandlers[opt](this, options[opt], Init);
112
+ maybeUpdateLineNumberWidth(this);
113
+ for (var i = 0; i < initHooks.length; ++i) initHooks[i](this);
114
+ endOperation(this);
115
+ // Suppress optimizelegibility in Webkit, since it breaks text
116
+ // measuring on line wrapping boundaries.
117
+ if (webkit && options.lineWrapping &&
118
+ getComputedStyle(display.lineDiv).textRendering == "optimizelegibility")
119
+ display.lineDiv.style.textRendering = "auto";
120
+ }
121
+
122
+ // DISPLAY CONSTRUCTOR
123
+
124
+ // The display handles the DOM integration, both for input reading
125
+ // and content drawing. It holds references to DOM nodes and
126
+ // display-related state.
127
+
128
+ function Display(place, doc) {
129
+ var d = this;
130
+
131
+ // The semihidden textarea that is focused when the editor is
132
+ // focused, and receives input.
133
+ var input = d.input = elt("textarea", null, null, "position: absolute; padding: 0; width: 1px; height: 1em; outline: none");
134
+ // The textarea is kept positioned near the cursor to prevent the
135
+ // fact that it'll be scrolled into view on input from scrolling
136
+ // our fake cursor out of view. On webkit, when wrap=off, paste is
137
+ // very slow. So make the area wide instead.
138
+ if (webkit) input.style.width = "1000px";
139
+ else input.setAttribute("wrap", "off");
140
+ // If border: 0; -- iOS fails to open keyboard (issue #1287)
141
+ if (ios) input.style.border = "1px solid black";
142
+ input.setAttribute("autocorrect", "off"); input.setAttribute("autocapitalize", "off"); input.setAttribute("spellcheck", "false");
143
+
144
+ // Wraps and hides input textarea
145
+ d.inputDiv = elt("div", [input], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
146
+ // Covers bottom-right square when both scrollbars are present.
147
+ d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
148
+ d.scrollbarFiller.setAttribute("not-content", "true");
149
+ // Covers bottom of gutter when coverGutterNextToScrollbar is on
150
+ // and h scrollbar is present.
151
+ d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler");
152
+ d.gutterFiller.setAttribute("not-content", "true");
153
+ // Will contain the actual code, positioned to cover the viewport.
154
+ d.lineDiv = elt("div", null, "CodeMirror-code");
155
+ // Elements are added to these to represent selection and cursors.
156
+ d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
157
+ d.cursorDiv = elt("div", null, "CodeMirror-cursors");
158
+ // A visibility: hidden element used to find the size of things.
159
+ d.measure = elt("div", null, "CodeMirror-measure");
160
+ // When lines outside of the viewport are measured, they are drawn in this.
161
+ d.lineMeasure = elt("div", null, "CodeMirror-measure");
162
+ // Wraps everything that needs to exist inside the vertically-padded coordinate system
163
+ d.lineSpace = elt("div", [d.measure, d.lineMeasure, d.selectionDiv, d.cursorDiv, d.lineDiv],
164
+ null, "position: relative; outline: none");
165
+ // Moved around its parent to cover visible view.
166
+ d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative");
167
+ // Set to the height of the document, allowing scrolling.
168
+ d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
169
+ d.sizerWidth = null;
170
+ // Behavior of elts with overflow: auto and padding is
171
+ // inconsistent across browsers. This is used to ensure the
172
+ // scrollable area is big enough.
173
+ d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerGap + "px; width: 1px;");
174
+ // Will contain the gutters, if any.
175
+ d.gutters = elt("div", null, "CodeMirror-gutters");
176
+ d.lineGutter = null;
177
+ // Actual scrollable element.
178
+ d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll");
179
+ d.scroller.setAttribute("tabIndex", "-1");
180
+ // The element in which the editor lives.
181
+ d.wrapper = elt("div", [d.inputDiv, d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
182
+
183
+ // Work around IE7 z-index bug (not perfect, hence IE7 not really being supported)
184
+ if (ie && ie_version < 8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; }
185
+ // Needed to hide big blue blinking cursor on Mobile Safari
186
+ if (ios) input.style.width = "0px";
187
+ if (!webkit) d.scroller.draggable = true;
188
+ // Needed to handle Tab key in KHTML
189
+ if (khtml) { d.inputDiv.style.height = "1px"; d.inputDiv.style.position = "absolute"; }
190
+
191
+ if (place) {
192
+ if (place.appendChild) place.appendChild(d.wrapper);
193
+ else place(d.wrapper);
194
+ }
195
+
196
+ // Current rendered range (may be bigger than the view window).
197
+ d.viewFrom = d.viewTo = doc.first;
198
+ d.reportedViewFrom = d.reportedViewTo = doc.first;
199
+ // Information about the rendered lines.
200
+ d.view = [];
201
+ d.renderedView = null;
202
+ // Holds info about a single rendered line when it was rendered
203
+ // for measurement, while not in view.
204
+ d.externalMeasured = null;
205
+ // Empty space (in pixels) above the view
206
+ d.viewOffset = 0;
207
+ d.lastWrapHeight = d.lastWrapWidth = 0;
208
+ d.updateLineNumbers = null;
209
+
210
+ d.nativeBarWidth = d.barHeight = d.barWidth = 0;
211
+ d.scrollbarsClipped = false;
212
+
213
+ // Used to only resize the line number gutter when necessary (when
214
+ // the amount of lines crosses a boundary that makes its width change)
215
+ d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
216
+ // See readInput and resetInput
217
+ d.prevInput = "";
218
+ // Set to true when a non-horizontal-scrolling line widget is
219
+ // added. As an optimization, line widget aligning is skipped when
220
+ // this is false.
221
+ d.alignWidgets = false;
222
+ // Flag that indicates whether we expect input to appear real soon
223
+ // now (after some event like 'keypress' or 'input') and are
224
+ // polling intensively.
225
+ d.pollingFast = false;
226
+ // Self-resetting timeout for the poller
227
+ d.poll = new Delayed();
228
+
229
+ d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
230
+
231
+ // Tracks when resetInput has punted to just putting a short
232
+ // string into the textarea instead of the full selection.
233
+ d.inaccurateSelection = false;
234
+
235
+ // Tracks the maximum line length so that the horizontal scrollbar
236
+ // can be kept static when scrolling.
237
+ d.maxLine = null;
238
+ d.maxLineLength = 0;
239
+ d.maxLineChanged = false;
240
+
241
+ // Used for measuring wheel scrolling granularity
242
+ d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null;
243
+
244
+ // True when shift is held down.
245
+ d.shift = false;
246
+
247
+ // Used to track whether anything happened since the context menu
248
+ // was opened.
249
+ d.selForContextMenu = null;
250
+ }
251
+
252
+ // STATE UPDATES
253
+
254
+ // Used to get the editor into a consistent state again when options change.
255
+
256
+ function loadMode(cm) {
257
+ cm.doc.mode = CodeMirror.getMode(cm.options, cm.doc.modeOption);
258
+ resetModeState(cm);
259
+ }
260
+
261
+ function resetModeState(cm) {
262
+ cm.doc.iter(function(line) {
263
+ if (line.stateAfter) line.stateAfter = null;
264
+ if (line.styles) line.styles = null;
265
+ });
266
+ cm.doc.frontier = cm.doc.first;
267
+ startWorker(cm, 100);
268
+ cm.state.modeGen++;
269
+ if (cm.curOp) regChange(cm);
270
+ }
271
+
272
+ function wrappingChanged(cm) {
273
+ if (cm.options.lineWrapping) {
274
+ addClass(cm.display.wrapper, "CodeMirror-wrap");
275
+ cm.display.sizer.style.minWidth = "";
276
+ cm.display.sizerWidth = null;
277
+ } else {
278
+ rmClass(cm.display.wrapper, "CodeMirror-wrap");
279
+ findMaxLine(cm);
280
+ }
281
+ estimateLineHeights(cm);
282
+ regChange(cm);
283
+ clearCaches(cm);
284
+ setTimeout(function(){updateScrollbars(cm);}, 100);
285
+ }
286
+
287
+ // Returns a function that estimates the height of a line, to use as
288
+ // first approximation until the line becomes visible (and is thus
289
+ // properly measurable).
290
+ function estimateHeight(cm) {
291
+ var th = textHeight(cm.display), wrapping = cm.options.lineWrapping;
292
+ var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);
293
+ return function(line) {
294
+ if (lineIsHidden(cm.doc, line)) return 0;
295
+
296
+ var widgetsHeight = 0;
297
+ if (line.widgets) for (var i = 0; i < line.widgets.length; i++) {
298
+ if (line.widgets[i].height) widgetsHeight += line.widgets[i].height;
299
+ }
300
+
301
+ if (wrapping)
302
+ return widgetsHeight + (Math.ceil(line.text.length / perLine) || 1) * th;
303
+ else
304
+ return widgetsHeight + th;
305
+ };
306
+ }
307
+
308
+ function estimateLineHeights(cm) {
309
+ var doc = cm.doc, est = estimateHeight(cm);
310
+ doc.iter(function(line) {
311
+ var estHeight = est(line);
312
+ if (estHeight != line.height) updateLineHeight(line, estHeight);
313
+ });
314
+ }
315
+
316
+ function themeChanged(cm) {
317
+ cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
318
+ cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
319
+ clearCaches(cm);
320
+ }
321
+
322
+ function guttersChanged(cm) {
323
+ updateGutters(cm);
324
+ regChange(cm);
325
+ setTimeout(function(){alignHorizontally(cm);}, 20);
326
+ }
327
+
328
+ // Rebuild the gutter elements, ensure the margin to the left of the
329
+ // code matches their width.
330
+ function updateGutters(cm) {
331
+ var gutters = cm.display.gutters, specs = cm.options.gutters;
332
+ removeChildren(gutters);
333
+ for (var i = 0; i < specs.length; ++i) {
334
+ var gutterClass = specs[i];
335
+ var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass));
336
+ if (gutterClass == "CodeMirror-linenumbers") {
337
+ cm.display.lineGutter = gElt;
338
+ gElt.style.width = (cm.display.lineNumWidth || 1) + "px";
339
+ }
340
+ }
341
+ gutters.style.display = i ? "" : "none";
342
+ updateGutterSpace(cm);
343
+ }
344
+
345
+ function updateGutterSpace(cm) {
346
+ var width = cm.display.gutters.offsetWidth;
347
+ cm.display.sizer.style.marginLeft = width + "px";
348
+ }
349
+
350
+ // Compute the character length of a line, taking into account
351
+ // collapsed ranges (see markText) that might hide parts, and join
352
+ // other lines onto it.
353
+ function lineLength(line) {
354
+ if (line.height == 0) return 0;
355
+ var len = line.text.length, merged, cur = line;
356
+ while (merged = collapsedSpanAtStart(cur)) {
357
+ var found = merged.find(0, true);
358
+ cur = found.from.line;
359
+ len += found.from.ch - found.to.ch;
360
+ }
361
+ cur = line;
362
+ while (merged = collapsedSpanAtEnd(cur)) {
363
+ var found = merged.find(0, true);
364
+ len -= cur.text.length - found.from.ch;
365
+ cur = found.to.line;
366
+ len += cur.text.length - found.to.ch;
367
+ }
368
+ return len;
369
+ }
370
+
371
+ // Find the longest line in the document.
372
+ function findMaxLine(cm) {
373
+ var d = cm.display, doc = cm.doc;
374
+ d.maxLine = getLine(doc, doc.first);
375
+ d.maxLineLength = lineLength(d.maxLine);
376
+ d.maxLineChanged = true;
377
+ doc.iter(function(line) {
378
+ var len = lineLength(line);
379
+ if (len > d.maxLineLength) {
380
+ d.maxLineLength = len;
381
+ d.maxLine = line;
382
+ }
383
+ });
384
+ }
385
+
386
+ // Make sure the gutters options contains the element
387
+ // "CodeMirror-linenumbers" when the lineNumbers option is true.
388
+ function setGuttersForLineNumbers(options) {
389
+ var found = indexOf(options.gutters, "CodeMirror-linenumbers");
390
+ if (found == -1 && options.lineNumbers) {
391
+ options.gutters = options.gutters.concat(["CodeMirror-linenumbers"]);
392
+ } else if (found > -1 && !options.lineNumbers) {
393
+ options.gutters = options.gutters.slice(0);
394
+ options.gutters.splice(found, 1);
395
+ }
396
+ }
397
+
398
+ // SCROLLBARS
399
+
400
+ // Prepare DOM reads needed to update the scrollbars. Done in one
401
+ // shot to minimize update/measure roundtrips.
402
+ function measureForScrollbars(cm) {
403
+ var d = cm.display, gutterW = d.gutters.offsetWidth;
404
+ var docH = Math.round(cm.doc.height + paddingVert(cm.display));
405
+ return {
406
+ clientHeight: d.scroller.clientHeight,
407
+ viewHeight: d.wrapper.clientHeight,
408
+ scrollWidth: d.scroller.scrollWidth, clientWidth: d.scroller.clientWidth,
409
+ viewWidth: d.wrapper.clientWidth,
410
+ barLeft: cm.options.fixedGutter ? gutterW : 0,
411
+ docHeight: docH,
412
+ scrollHeight: docH + scrollGap(cm) + d.barHeight,
413
+ nativeBarWidth: d.nativeBarWidth,
414
+ gutterWidth: gutterW
415
+ };
416
+ }
417
+
418
+ function NativeScrollbars(place, scroll, cm) {
419
+ this.cm = cm;
420
+ var vert = this.vert = elt("div", [elt("div", null, null, "min-width: 1px")], "CodeMirror-vscrollbar");
421
+ var horiz = this.horiz = elt("div", [elt("div", null, null, "height: 100%; min-height: 1px")], "CodeMirror-hscrollbar");
422
+ place(vert); place(horiz);
423
+
424
+ on(vert, "scroll", function() {
425
+ if (vert.clientHeight) scroll(vert.scrollTop, "vertical");
426
+ });
427
+ on(horiz, "scroll", function() {
428
+ if (horiz.clientWidth) scroll(horiz.scrollLeft, "horizontal");
429
+ });
430
+
431
+ this.checkedOverlay = false;
432
+ // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
433
+ if (ie && ie_version < 8) this.horiz.style.minHeight = this.vert.style.minWidth = "18px";
434
+ }
435
+
436
+ NativeScrollbars.prototype = copyObj({
437
+ update: function(measure) {
438
+ var needsH = measure.scrollWidth > measure.clientWidth + 1;
439
+ var needsV = measure.scrollHeight > measure.clientHeight + 1;
440
+ var sWidth = measure.nativeBarWidth;
441
+
442
+ if (needsV) {
443
+ this.vert.style.display = "block";
444
+ this.vert.style.bottom = needsH ? sWidth + "px" : "0";
445
+ var totalHeight = measure.viewHeight - (needsH ? sWidth : 0);
446
+ // A bug in IE8 can cause this value to be negative, so guard it.
447
+ this.vert.firstChild.style.height =
448
+ Math.max(0, measure.scrollHeight - measure.clientHeight + totalHeight) + "px";
449
+ } else {
450
+ this.vert.style.display = "";
451
+ this.vert.firstChild.style.height = "0";
452
+ }
453
+
454
+ if (needsH) {
455
+ this.horiz.style.display = "block";
456
+ this.horiz.style.right = needsV ? sWidth + "px" : "0";
457
+ this.horiz.style.left = measure.barLeft + "px";
458
+ var totalWidth = measure.viewWidth - measure.barLeft - (needsV ? sWidth : 0);
459
+ this.horiz.firstChild.style.width =
460
+ (measure.scrollWidth - measure.clientWidth + totalWidth) + "px";
461
+ } else {
462
+ this.horiz.style.display = "";
463
+ this.horiz.firstChild.style.width = "0";
464
+ }
465
+
466
+ if (!this.checkedOverlay && measure.clientHeight > 0) {
467
+ if (sWidth == 0) this.overlayHack();
468
+ this.checkedOverlay = true;
469
+ }
470
+
471
+ return {right: needsV ? sWidth : 0, bottom: needsH ? sWidth : 0};
472
+ },
473
+ setScrollLeft: function(pos) {
474
+ if (this.horiz.scrollLeft != pos) this.horiz.scrollLeft = pos;
475
+ },
476
+ setScrollTop: function(pos) {
477
+ if (this.vert.scrollTop != pos) this.vert.scrollTop = pos;
478
+ },
479
+ overlayHack: function() {
480
+ var w = mac && !mac_geMountainLion ? "12px" : "18px";
481
+ this.horiz.style.minHeight = this.vert.style.minWidth = w;
482
+ var self = this;
483
+ var barMouseDown = function(e) {
484
+ if (e_target(e) != self.vert && e_target(e) != self.horiz)
485
+ operation(self.cm, onMouseDown)(e);
486
+ };
487
+ on(this.vert, "mousedown", barMouseDown);
488
+ on(this.horiz, "mousedown", barMouseDown);
489
+ },
490
+ clear: function() {
491
+ var parent = this.horiz.parentNode;
492
+ parent.removeChild(this.horiz);
493
+ parent.removeChild(this.vert);
494
+ }
495
+ }, NativeScrollbars.prototype);
496
+
497
+ function NullScrollbars() {}
498
+
499
+ NullScrollbars.prototype = copyObj({
500
+ update: function() { return {bottom: 0, right: 0}; },
501
+ setScrollLeft: function() {},
502
+ setScrollTop: function() {},
503
+ clear: function() {}
504
+ }, NullScrollbars.prototype);
505
+
506
+ CodeMirror.scrollbarModel = {"native": NativeScrollbars, "null": NullScrollbars};
507
+
508
+ function initScrollbars(cm) {
509
+ if (cm.display.scrollbars) {
510
+ cm.display.scrollbars.clear();
511
+ if (cm.display.scrollbars.addClass)
512
+ rmClass(cm.display.wrapper, cm.display.scrollbars.addClass);
513
+ }
514
+
515
+ cm.display.scrollbars = new CodeMirror.scrollbarModel[cm.options.scrollbarStyle](function(node) {
516
+ cm.display.wrapper.insertBefore(node, cm.display.scrollbarFiller);
517
+ on(node, "mousedown", function() {
518
+ if (cm.state.focused) setTimeout(bind(focusInput, cm), 0);
519
+ });
520
+ node.setAttribute("not-content", "true");
521
+ }, function(pos, axis) {
522
+ if (axis == "horizontal") setScrollLeft(cm, pos);
523
+ else setScrollTop(cm, pos);
524
+ }, cm);
525
+ if (cm.display.scrollbars.addClass)
526
+ addClass(cm.display.wrapper, cm.display.scrollbars.addClass);
527
+ }
528
+
529
+ function updateScrollbars(cm, measure) {
530
+ if (!measure) measure = measureForScrollbars(cm);
531
+ var startWidth = cm.display.barWidth, startHeight = cm.display.barHeight;
532
+ updateScrollbarsInner(cm, measure);
533
+ for (var i = 0; i < 4 && startWidth != cm.display.barWidth || startHeight != cm.display.barHeight; i++) {
534
+ if (startWidth != cm.display.barWidth && cm.options.lineWrapping)
535
+ updateHeightsInViewport(cm);
536
+ updateScrollbarsInner(cm, measureForScrollbars(cm));
537
+ startWidth = cm.display.barWidth; startHeight = cm.display.barHeight;
538
+ }
539
+ }
540
+
541
+ // Re-synchronize the fake scrollbars with the actual size of the
542
+ // content.
543
+ function updateScrollbarsInner(cm, measure) {
544
+ var d = cm.display;
545
+ var sizes = d.scrollbars.update(measure);
546
+
547
+ d.sizer.style.paddingRight = (d.barWidth = sizes.right) + "px";
548
+ d.sizer.style.paddingBottom = (d.barHeight = sizes.bottom) + "px";
549
+
550
+ if (sizes.right && sizes.bottom) {
551
+ d.scrollbarFiller.style.display = "block";
552
+ d.scrollbarFiller.style.height = sizes.bottom + "px";
553
+ d.scrollbarFiller.style.width = sizes.right + "px";
554
+ } else d.scrollbarFiller.style.display = "";
555
+ if (sizes.bottom && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
556
+ d.gutterFiller.style.display = "block";
557
+ d.gutterFiller.style.height = sizes.bottom + "px";
558
+ d.gutterFiller.style.width = measure.gutterWidth + "px";
559
+ } else d.gutterFiller.style.display = "";
560
+ }
561
+
562
+ // Compute the lines that are visible in a given viewport (defaults
563
+ // the the current scroll position). viewport may contain top,
564
+ // height, and ensure (see op.scrollToPos) properties.
565
+ function visibleLines(display, doc, viewport) {
566
+ var top = viewport && viewport.top != null ? Math.max(0, viewport.top) : display.scroller.scrollTop;
567
+ top = Math.floor(top - paddingTop(display));
568
+ var bottom = viewport && viewport.bottom != null ? viewport.bottom : top + display.wrapper.clientHeight;
569
+
570
+ var from = lineAtHeight(doc, top), to = lineAtHeight(doc, bottom);
571
+ // Ensure is a {from: {line, ch}, to: {line, ch}} object, and
572
+ // forces those lines into the viewport (if possible).
573
+ if (viewport && viewport.ensure) {
574
+ var ensureFrom = viewport.ensure.from.line, ensureTo = viewport.ensure.to.line;
575
+ if (ensureFrom < from) {
576
+ from = ensureFrom;
577
+ to = lineAtHeight(doc, heightAtLine(getLine(doc, ensureFrom)) + display.wrapper.clientHeight);
578
+ } else if (Math.min(ensureTo, doc.lastLine()) >= to) {
579
+ from = lineAtHeight(doc, heightAtLine(getLine(doc, ensureTo)) - display.wrapper.clientHeight);
580
+ to = ensureTo;
581
+ }
582
+ }
583
+ return {from: from, to: Math.max(to, from + 1)};
584
+ }
585
+
586
+ // LINE NUMBERS
587
+
588
+ // Re-align line numbers and gutter marks to compensate for
589
+ // horizontal scrolling.
590
+ function alignHorizontally(cm) {
591
+ var display = cm.display, view = display.view;
592
+ if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) return;
593
+ var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft;
594
+ var gutterW = display.gutters.offsetWidth, left = comp + "px";
595
+ for (var i = 0; i < view.length; i++) if (!view[i].hidden) {
596
+ if (cm.options.fixedGutter && view[i].gutter)
597
+ view[i].gutter.style.left = left;
598
+ var align = view[i].alignable;
599
+ if (align) for (var j = 0; j < align.length; j++)
600
+ align[j].style.left = left;
601
+ }
602
+ if (cm.options.fixedGutter)
603
+ display.gutters.style.left = (comp + gutterW) + "px";
604
+ }
605
+
606
+ // Used to ensure that the line number gutter is still the right
607
+ // size for the current document size. Returns true when an update
608
+ // is needed.
609
+ function maybeUpdateLineNumberWidth(cm) {
610
+ if (!cm.options.lineNumbers) return false;
611
+ var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display;
612
+ if (last.length != display.lineNumChars) {
613
+ var test = display.measure.appendChild(elt("div", [elt("div", last)],
614
+ "CodeMirror-linenumber CodeMirror-gutter-elt"));
615
+ var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
616
+ display.lineGutter.style.width = "";
617
+ display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding);
618
+ display.lineNumWidth = display.lineNumInnerWidth + padding;
619
+ display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
620
+ display.lineGutter.style.width = display.lineNumWidth + "px";
621
+ updateGutterSpace(cm);
622
+ return true;
623
+ }
624
+ return false;
625
+ }
626
+
627
+ function lineNumberFor(options, i) {
628
+ return String(options.lineNumberFormatter(i + options.firstLineNumber));
629
+ }
630
+
631
+ // Computes display.scroller.scrollLeft + display.gutters.offsetWidth,
632
+ // but using getBoundingClientRect to get a sub-pixel-accurate
633
+ // result.
634
+ function compensateForHScroll(display) {
635
+ return display.scroller.getBoundingClientRect().left - display.sizer.getBoundingClientRect().left;
636
+ }
637
+
638
+ // DISPLAY DRAWING
639
+
640
+ function DisplayUpdate(cm, viewport, force) {
641
+ var display = cm.display;
642
+
643
+ this.viewport = viewport;
644
+ // Store some values that we'll need later (but don't want to force a relayout for)
645
+ this.visible = visibleLines(display, cm.doc, viewport);
646
+ this.editorIsHidden = !display.wrapper.offsetWidth;
647
+ this.wrapperHeight = display.wrapper.clientHeight;
648
+ this.wrapperWidth = display.wrapper.clientWidth;
649
+ this.oldDisplayWidth = displayWidth(cm);
650
+ this.force = force;
651
+ this.dims = getDimensions(cm);
652
+ }
653
+
654
+ function maybeClipScrollbars(cm) {
655
+ var display = cm.display;
656
+ if (!display.scrollbarsClipped && display.scroller.offsetWidth) {
657
+ display.nativeBarWidth = display.scroller.offsetWidth - display.scroller.clientWidth;
658
+ display.heightForcer.style.height = scrollGap(cm) + "px";
659
+ display.sizer.style.marginBottom = -display.nativeBarWidth + "px";
660
+ display.sizer.style.borderRightWidth = scrollGap(cm) + "px";
661
+ display.scrollbarsClipped = true;
662
+ }
663
+ }
664
+
665
+ // Does the actual updating of the line display. Bails out
666
+ // (returning false) when there is nothing to be done and forced is
667
+ // false.
668
+ function updateDisplayIfNeeded(cm, update) {
669
+ var display = cm.display, doc = cm.doc;
670
+
671
+ if (update.editorIsHidden) {
672
+ resetView(cm);
673
+ return false;
674
+ }
675
+
676
+ // Bail out if the visible area is already rendered and nothing changed.
677
+ if (!update.force &&
678
+ update.visible.from >= display.viewFrom && update.visible.to <= display.viewTo &&
679
+ (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo) &&
680
+ display.renderedView == display.view && countDirtyView(cm) == 0)
681
+ return false;
682
+
683
+ if (maybeUpdateLineNumberWidth(cm)) {
684
+ resetView(cm);
685
+ update.dims = getDimensions(cm);
686
+ }
687
+
688
+ // Compute a suitable new viewport (from & to)
689
+ var end = doc.first + doc.size;
690
+ var from = Math.max(update.visible.from - cm.options.viewportMargin, doc.first);
691
+ var to = Math.min(end, update.visible.to + cm.options.viewportMargin);
692
+ if (display.viewFrom < from && from - display.viewFrom < 20) from = Math.max(doc.first, display.viewFrom);
693
+ if (display.viewTo > to && display.viewTo - to < 20) to = Math.min(end, display.viewTo);
694
+ if (sawCollapsedSpans) {
695
+ from = visualLineNo(cm.doc, from);
696
+ to = visualLineEndNo(cm.doc, to);
697
+ }
698
+
699
+ var different = from != display.viewFrom || to != display.viewTo ||
700
+ display.lastWrapHeight != update.wrapperHeight || display.lastWrapWidth != update.wrapperWidth;
701
+ adjustView(cm, from, to);
702
+
703
+ display.viewOffset = heightAtLine(getLine(cm.doc, display.viewFrom));
704
+ // Position the mover div to align with the current scroll position
705
+ cm.display.mover.style.top = display.viewOffset + "px";
706
+
707
+ var toUpdate = countDirtyView(cm);
708
+ if (!different && toUpdate == 0 && !update.force && display.renderedView == display.view &&
709
+ (display.updateLineNumbers == null || display.updateLineNumbers >= display.viewTo))
710
+ return false;
711
+
712
+ // For big changes, we hide the enclosing element during the
713
+ // update, since that speeds up the operations on most browsers.
714
+ var focused = activeElt();
715
+ if (toUpdate > 4) display.lineDiv.style.display = "none";
716
+ patchDisplay(cm, display.updateLineNumbers, update.dims);
717
+ if (toUpdate > 4) display.lineDiv.style.display = "";
718
+ display.renderedView = display.view;
719
+ // There might have been a widget with a focused element that got
720
+ // hidden or updated, if so re-focus it.
721
+ if (focused && activeElt() != focused && focused.offsetHeight) focused.focus();
722
+
723
+ // Prevent selection and cursors from interfering with the scroll
724
+ // width and height.
725
+ removeChildren(display.cursorDiv);
726
+ removeChildren(display.selectionDiv);
727
+ display.gutters.style.height = 0;
728
+
729
+ if (different) {
730
+ display.lastWrapHeight = update.wrapperHeight;
731
+ display.lastWrapWidth = update.wrapperWidth;
732
+ startWorker(cm, 400);
733
+ }
734
+
735
+ display.updateLineNumbers = null;
736
+
737
+ return true;
738
+ }
739
+
740
+ function postUpdateDisplay(cm, update) {
741
+ var force = update.force, viewport = update.viewport;
742
+ for (var first = true;; first = false) {
743
+ if (first && cm.options.lineWrapping && update.oldDisplayWidth != displayWidth(cm)) {
744
+ force = true;
745
+ } else {
746
+ force = false;
747
+ // Clip forced viewport to actual scrollable area.
748
+ if (viewport && viewport.top != null)
749
+ viewport = {top: Math.min(cm.doc.height + paddingVert(cm.display) - displayHeight(cm), viewport.top)};
750
+ // Updated line heights might result in the drawn area not
751
+ // actually covering the viewport. Keep looping until it does.
752
+ update.visible = visibleLines(cm.display, cm.doc, viewport);
753
+ if (update.visible.from >= cm.display.viewFrom && update.visible.to <= cm.display.viewTo)
754
+ break;
755
+ }
756
+ if (!updateDisplayIfNeeded(cm, update)) break;
757
+ updateHeightsInViewport(cm);
758
+ var barMeasure = measureForScrollbars(cm);
759
+ updateSelection(cm);
760
+ setDocumentHeight(cm, barMeasure);
761
+ updateScrollbars(cm, barMeasure);
762
+ }
763
+
764
+ signalLater(cm, "update", cm);
765
+ if (cm.display.viewFrom != cm.display.reportedViewFrom || cm.display.viewTo != cm.display.reportedViewTo) {
766
+ signalLater(cm, "viewportChange", cm, cm.display.viewFrom, cm.display.viewTo);
767
+ cm.display.reportedViewFrom = cm.display.viewFrom; cm.display.reportedViewTo = cm.display.viewTo;
768
+ }
769
+ }
770
+
771
+ function updateDisplaySimple(cm, viewport) {
772
+ var update = new DisplayUpdate(cm, viewport);
773
+ if (updateDisplayIfNeeded(cm, update)) {
774
+ updateHeightsInViewport(cm);
775
+ postUpdateDisplay(cm, update);
776
+ var barMeasure = measureForScrollbars(cm);
777
+ updateSelection(cm);
778
+ setDocumentHeight(cm, barMeasure);
779
+ updateScrollbars(cm, barMeasure);
780
+ }
781
+ }
782
+
783
+ function setDocumentHeight(cm, measure) {
784
+ cm.display.sizer.style.minHeight = measure.docHeight + "px";
785
+ var total = measure.docHeight + cm.display.barHeight;
786
+ cm.display.heightForcer.style.top = total + "px";
787
+ cm.display.gutters.style.height = Math.max(total + scrollGap(cm), measure.clientHeight) + "px";
788
+ }
789
+
790
+ // Read the actual heights of the rendered lines, and update their
791
+ // stored heights to match.
792
+ function updateHeightsInViewport(cm) {
793
+ var display = cm.display;
794
+ var prevBottom = display.lineDiv.offsetTop;
795
+ for (var i = 0; i < display.view.length; i++) {
796
+ var cur = display.view[i], height;
797
+ if (cur.hidden) continue;
798
+ if (ie && ie_version < 8) {
799
+ var bot = cur.node.offsetTop + cur.node.offsetHeight;
800
+ height = bot - prevBottom;
801
+ prevBottom = bot;
802
+ } else {
803
+ var box = cur.node.getBoundingClientRect();
804
+ height = box.bottom - box.top;
805
+ }
806
+ var diff = cur.line.height - height;
807
+ if (height < 2) height = textHeight(display);
808
+ if (diff > .001 || diff < -.001) {
809
+ updateLineHeight(cur.line, height);
810
+ updateWidgetHeight(cur.line);
811
+ if (cur.rest) for (var j = 0; j < cur.rest.length; j++)
812
+ updateWidgetHeight(cur.rest[j]);
813
+ }
814
+ }
815
+ }
816
+
817
+ // Read and store the height of line widgets associated with the
818
+ // given line.
819
+ function updateWidgetHeight(line) {
820
+ if (line.widgets) for (var i = 0; i < line.widgets.length; ++i)
821
+ line.widgets[i].height = line.widgets[i].node.offsetHeight;
822
+ }
823
+
824
+ // Do a bulk-read of the DOM positions and sizes needed to draw the
825
+ // view, so that we don't interleave reading and writing to the DOM.
826
+ function getDimensions(cm) {
827
+ var d = cm.display, left = {}, width = {};
828
+ var gutterLeft = d.gutters.clientLeft;
829
+ for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
830
+ left[cm.options.gutters[i]] = n.offsetLeft + n.clientLeft + gutterLeft;
831
+ width[cm.options.gutters[i]] = n.clientWidth;
832
+ }
833
+ return {fixedPos: compensateForHScroll(d),
834
+ gutterTotalWidth: d.gutters.offsetWidth,
835
+ gutterLeft: left,
836
+ gutterWidth: width,
837
+ wrapperWidth: d.wrapper.clientWidth};
838
+ }
839
+
840
+ // Sync the actual display DOM structure with display.view, removing
841
+ // nodes for lines that are no longer in view, and creating the ones
842
+ // that are not there yet, and updating the ones that are out of
843
+ // date.
844
+ function patchDisplay(cm, updateNumbersFrom, dims) {
845
+ var display = cm.display, lineNumbers = cm.options.lineNumbers;
846
+ var container = display.lineDiv, cur = container.firstChild;
847
+
848
+ function rm(node) {
849
+ var next = node.nextSibling;
850
+ // Works around a throw-scroll bug in OS X Webkit
851
+ if (webkit && mac && cm.display.currentWheelTarget == node)
852
+ node.style.display = "none";
853
+ else
854
+ node.parentNode.removeChild(node);
855
+ return next;
856
+ }
857
+
858
+ var view = display.view, lineN = display.viewFrom;
859
+ // Loop over the elements in the view, syncing cur (the DOM nodes
860
+ // in display.lineDiv) with the view as we go.
861
+ for (var i = 0; i < view.length; i++) {
862
+ var lineView = view[i];
863
+ if (lineView.hidden) {
864
+ } else if (!lineView.node) { // Not drawn yet
865
+ var node = buildLineElement(cm, lineView, lineN, dims);
866
+ container.insertBefore(node, cur);
867
+ } else { // Already drawn
868
+ while (cur != lineView.node) cur = rm(cur);
869
+ var updateNumber = lineNumbers && updateNumbersFrom != null &&
870
+ updateNumbersFrom <= lineN && lineView.lineNumber;
871
+ if (lineView.changes) {
872
+ if (indexOf(lineView.changes, "gutter") > -1) updateNumber = false;
873
+ updateLineForChanges(cm, lineView, lineN, dims);
874
+ }
875
+ if (updateNumber) {
876
+ removeChildren(lineView.lineNumber);
877
+ lineView.lineNumber.appendChild(document.createTextNode(lineNumberFor(cm.options, lineN)));
878
+ }
879
+ cur = lineView.node.nextSibling;
880
+ }
881
+ lineN += lineView.size;
882
+ }
883
+ while (cur) cur = rm(cur);
884
+ }
885
+
886
+ // When an aspect of a line changes, a string is added to
887
+ // lineView.changes. This updates the relevant part of the line's
888
+ // DOM structure.
889
+ function updateLineForChanges(cm, lineView, lineN, dims) {
890
+ for (var j = 0; j < lineView.changes.length; j++) {
891
+ var type = lineView.changes[j];
892
+ if (type == "text") updateLineText(cm, lineView);
893
+ else if (type == "gutter") updateLineGutter(cm, lineView, lineN, dims);
894
+ else if (type == "class") updateLineClasses(lineView);
895
+ else if (type == "widget") updateLineWidgets(lineView, dims);
896
+ }
897
+ lineView.changes = null;
898
+ }
899
+
900
+ // Lines with gutter elements, widgets or a background class need to
901
+ // be wrapped, and have the extra elements added to the wrapper div
902
+ function ensureLineWrapped(lineView) {
903
+ if (lineView.node == lineView.text) {
904
+ lineView.node = elt("div", null, null, "position: relative");
905
+ if (lineView.text.parentNode)
906
+ lineView.text.parentNode.replaceChild(lineView.node, lineView.text);
907
+ lineView.node.appendChild(lineView.text);
908
+ if (ie && ie_version < 8) lineView.node.style.zIndex = 2;
909
+ }
910
+ return lineView.node;
911
+ }
912
+
913
+ function updateLineBackground(lineView) {
914
+ var cls = lineView.bgClass ? lineView.bgClass + " " + (lineView.line.bgClass || "") : lineView.line.bgClass;
915
+ if (cls) cls += " CodeMirror-linebackground";
916
+ if (lineView.background) {
917
+ if (cls) lineView.background.className = cls;
918
+ else { lineView.background.parentNode.removeChild(lineView.background); lineView.background = null; }
919
+ } else if (cls) {
920
+ var wrap = ensureLineWrapped(lineView);
921
+ lineView.background = wrap.insertBefore(elt("div", null, cls), wrap.firstChild);
922
+ }
923
+ }
924
+
925
+ // Wrapper around buildLineContent which will reuse the structure
926
+ // in display.externalMeasured when possible.
927
+ function getLineContent(cm, lineView) {
928
+ var ext = cm.display.externalMeasured;
929
+ if (ext && ext.line == lineView.line) {
930
+ cm.display.externalMeasured = null;
931
+ lineView.measure = ext.measure;
932
+ return ext.built;
933
+ }
934
+ return buildLineContent(cm, lineView);
935
+ }
936
+
937
+ // Redraw the line's text. Interacts with the background and text
938
+ // classes because the mode may output tokens that influence these
939
+ // classes.
940
+ function updateLineText(cm, lineView) {
941
+ var cls = lineView.text.className;
942
+ var built = getLineContent(cm, lineView);
943
+ if (lineView.text == lineView.node) lineView.node = built.pre;
944
+ lineView.text.parentNode.replaceChild(built.pre, lineView.text);
945
+ lineView.text = built.pre;
946
+ if (built.bgClass != lineView.bgClass || built.textClass != lineView.textClass) {
947
+ lineView.bgClass = built.bgClass;
948
+ lineView.textClass = built.textClass;
949
+ updateLineClasses(lineView);
950
+ } else if (cls) {
951
+ lineView.text.className = cls;
952
+ }
953
+ }
954
+
955
+ function updateLineClasses(lineView) {
956
+ updateLineBackground(lineView);
957
+ if (lineView.line.wrapClass)
958
+ ensureLineWrapped(lineView).className = lineView.line.wrapClass;
959
+ else if (lineView.node != lineView.text)
960
+ lineView.node.className = "";
961
+ var textClass = lineView.textClass ? lineView.textClass + " " + (lineView.line.textClass || "") : lineView.line.textClass;
962
+ lineView.text.className = textClass || "";
963
+ }
964
+
965
+ function updateLineGutter(cm, lineView, lineN, dims) {
966
+ if (lineView.gutter) {
967
+ lineView.node.removeChild(lineView.gutter);
968
+ lineView.gutter = null;
969
+ }
970
+ var markers = lineView.line.gutterMarkers;
971
+ if (cm.options.lineNumbers || markers) {
972
+ var wrap = ensureLineWrapped(lineView);
973
+ var gutterWrap = lineView.gutter =
974
+ wrap.insertBefore(elt("div", null, "CodeMirror-gutter-wrapper", "left: " +
975
+ (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) +
976
+ "px; width: " + dims.gutterTotalWidth + "px"),
977
+ lineView.text);
978
+ if (lineView.line.gutterClass)
979
+ gutterWrap.className += " " + lineView.line.gutterClass;
980
+ if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
981
+ lineView.lineNumber = gutterWrap.appendChild(
982
+ elt("div", lineNumberFor(cm.options, lineN),
983
+ "CodeMirror-linenumber CodeMirror-gutter-elt",
984
+ "left: " + dims.gutterLeft["CodeMirror-linenumbers"] + "px; width: "
985
+ + cm.display.lineNumInnerWidth + "px"));
986
+ if (markers) for (var k = 0; k < cm.options.gutters.length; ++k) {
987
+ var id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id];
988
+ if (found)
989
+ gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt", "left: " +
990
+ dims.gutterLeft[id] + "px; width: " + dims.gutterWidth[id] + "px"));
991
+ }
992
+ }
993
+ }
994
+
995
+ function updateLineWidgets(lineView, dims) {
996
+ if (lineView.alignable) lineView.alignable = null;
997
+ for (var node = lineView.node.firstChild, next; node; node = next) {
998
+ var next = node.nextSibling;
999
+ if (node.className == "CodeMirror-linewidget")
1000
+ lineView.node.removeChild(node);
1001
+ }
1002
+ insertLineWidgets(lineView, dims);
1003
+ }
1004
+
1005
+ // Build a line's DOM representation from scratch
1006
+ function buildLineElement(cm, lineView, lineN, dims) {
1007
+ var built = getLineContent(cm, lineView);
1008
+ lineView.text = lineView.node = built.pre;
1009
+ if (built.bgClass) lineView.bgClass = built.bgClass;
1010
+ if (built.textClass) lineView.textClass = built.textClass;
1011
+
1012
+ updateLineClasses(lineView);
1013
+ updateLineGutter(cm, lineView, lineN, dims);
1014
+ insertLineWidgets(lineView, dims);
1015
+ return lineView.node;
1016
+ }
1017
+
1018
+ // A lineView may contain multiple logical lines (when merged by
1019
+ // collapsed spans). The widgets for all of them need to be drawn.
1020
+ function insertLineWidgets(lineView, dims) {
1021
+ insertLineWidgetsFor(lineView.line, lineView, dims, true);
1022
+ if (lineView.rest) for (var i = 0; i < lineView.rest.length; i++)
1023
+ insertLineWidgetsFor(lineView.rest[i], lineView, dims, false);
1024
+ }
1025
+
1026
+ function insertLineWidgetsFor(line, lineView, dims, allowAbove) {
1027
+ if (!line.widgets) return;
1028
+ var wrap = ensureLineWrapped(lineView);
1029
+ for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
1030
+ var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget");
1031
+ if (!widget.handleMouseEvents) node.setAttribute("cm-ignore-events", "true");
1032
+ positionLineWidget(widget, node, lineView, dims);
1033
+ if (allowAbove && widget.above)
1034
+ wrap.insertBefore(node, lineView.gutter || lineView.text);
1035
+ else
1036
+ wrap.appendChild(node);
1037
+ signalLater(widget, "redraw");
1038
+ }
1039
+ }
1040
+
1041
+ function positionLineWidget(widget, node, lineView, dims) {
1042
+ if (widget.noHScroll) {
1043
+ (lineView.alignable || (lineView.alignable = [])).push(node);
1044
+ var width = dims.wrapperWidth;
1045
+ node.style.left = dims.fixedPos + "px";
1046
+ if (!widget.coverGutter) {
1047
+ width -= dims.gutterTotalWidth;
1048
+ node.style.paddingLeft = dims.gutterTotalWidth + "px";
1049
+ }
1050
+ node.style.width = width + "px";
1051
+ }
1052
+ if (widget.coverGutter) {
1053
+ node.style.zIndex = 5;
1054
+ node.style.position = "relative";
1055
+ if (!widget.noHScroll) node.style.marginLeft = -dims.gutterTotalWidth + "px";
1056
+ }
1057
+ }
1058
+
1059
+ // POSITION OBJECT
1060
+
1061
+ // A Pos instance represents a position within the text.
1062
+ var Pos = CodeMirror.Pos = function(line, ch) {
1063
+ if (!(this instanceof Pos)) return new Pos(line, ch);
1064
+ this.line = line; this.ch = ch;
1065
+ };
1066
+
1067
+ // Compare two positions, return 0 if they are the same, a negative
1068
+ // number when a is less, and a positive number otherwise.
1069
+ var cmp = CodeMirror.cmpPos = function(a, b) { return a.line - b.line || a.ch - b.ch; };
1070
+
1071
+ function copyPos(x) {return Pos(x.line, x.ch);}
1072
+ function maxPos(a, b) { return cmp(a, b) < 0 ? b : a; }
1073
+ function minPos(a, b) { return cmp(a, b) < 0 ? a : b; }
1074
+
1075
+ // SELECTION / CURSOR
1076
+
1077
+ // Selection objects are immutable. A new one is created every time
1078
+ // the selection changes. A selection is one or more non-overlapping
1079
+ // (and non-touching) ranges, sorted, and an integer that indicates
1080
+ // which one is the primary selection (the one that's scrolled into
1081
+ // view, that getCursor returns, etc).
1082
+ function Selection(ranges, primIndex) {
1083
+ this.ranges = ranges;
1084
+ this.primIndex = primIndex;
1085
+ }
1086
+
1087
+ Selection.prototype = {
1088
+ primary: function() { return this.ranges[this.primIndex]; },
1089
+ equals: function(other) {
1090
+ if (other == this) return true;
1091
+ if (other.primIndex != this.primIndex || other.ranges.length != this.ranges.length) return false;
1092
+ for (var i = 0; i < this.ranges.length; i++) {
1093
+ var here = this.ranges[i], there = other.ranges[i];
1094
+ if (cmp(here.anchor, there.anchor) != 0 || cmp(here.head, there.head) != 0) return false;
1095
+ }
1096
+ return true;
1097
+ },
1098
+ deepCopy: function() {
1099
+ for (var out = [], i = 0; i < this.ranges.length; i++)
1100
+ out[i] = new Range(copyPos(this.ranges[i].anchor), copyPos(this.ranges[i].head));
1101
+ return new Selection(out, this.primIndex);
1102
+ },
1103
+ somethingSelected: function() {
1104
+ for (var i = 0; i < this.ranges.length; i++)
1105
+ if (!this.ranges[i].empty()) return true;
1106
+ return false;
1107
+ },
1108
+ contains: function(pos, end) {
1109
+ if (!end) end = pos;
1110
+ for (var i = 0; i < this.ranges.length; i++) {
1111
+ var range = this.ranges[i];
1112
+ if (cmp(end, range.from()) >= 0 && cmp(pos, range.to()) <= 0)
1113
+ return i;
1114
+ }
1115
+ return -1;
1116
+ }
1117
+ };
1118
+
1119
+ function Range(anchor, head) {
1120
+ this.anchor = anchor; this.head = head;
1121
+ }
1122
+
1123
+ Range.prototype = {
1124
+ from: function() { return minPos(this.anchor, this.head); },
1125
+ to: function() { return maxPos(this.anchor, this.head); },
1126
+ empty: function() {
1127
+ return this.head.line == this.anchor.line && this.head.ch == this.anchor.ch;
1128
+ }
1129
+ };
1130
+
1131
+ // Take an unsorted, potentially overlapping set of ranges, and
1132
+ // build a selection out of it. 'Consumes' ranges array (modifying
1133
+ // it).
1134
+ function normalizeSelection(ranges, primIndex) {
1135
+ var prim = ranges[primIndex];
1136
+ ranges.sort(function(a, b) { return cmp(a.from(), b.from()); });
1137
+ primIndex = indexOf(ranges, prim);
1138
+ for (var i = 1; i < ranges.length; i++) {
1139
+ var cur = ranges[i], prev = ranges[i - 1];
1140
+ if (cmp(prev.to(), cur.from()) >= 0) {
1141
+ var from = minPos(prev.from(), cur.from()), to = maxPos(prev.to(), cur.to());
1142
+ var inv = prev.empty() ? cur.from() == cur.head : prev.from() == prev.head;
1143
+ if (i <= primIndex) --primIndex;
1144
+ ranges.splice(--i, 2, new Range(inv ? to : from, inv ? from : to));
1145
+ }
1146
+ }
1147
+ return new Selection(ranges, primIndex);
1148
+ }
1149
+
1150
+ function simpleSelection(anchor, head) {
1151
+ return new Selection([new Range(anchor, head || anchor)], 0);
1152
+ }
1153
+
1154
+ // Most of the external API clips given positions to make sure they
1155
+ // actually exist within the document.
1156
+ function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1));}
1157
+ function clipPos(doc, pos) {
1158
+ if (pos.line < doc.first) return Pos(doc.first, 0);
1159
+ var last = doc.first + doc.size - 1;
1160
+ if (pos.line > last) return Pos(last, getLine(doc, last).text.length);
1161
+ return clipToLen(pos, getLine(doc, pos.line).text.length);
1162
+ }
1163
+ function clipToLen(pos, linelen) {
1164
+ var ch = pos.ch;
1165
+ if (ch == null || ch > linelen) return Pos(pos.line, linelen);
1166
+ else if (ch < 0) return Pos(pos.line, 0);
1167
+ else return pos;
1168
+ }
1169
+ function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size;}
1170
+ function clipPosArray(doc, array) {
1171
+ for (var out = [], i = 0; i < array.length; i++) out[i] = clipPos(doc, array[i]);
1172
+ return out;
1173
+ }
1174
+
1175
+ // SELECTION UPDATES
1176
+
1177
+ // The 'scroll' parameter given to many of these indicated whether
1178
+ // the new cursor position should be scrolled into view after
1179
+ // modifying the selection.
1180
+
1181
+ // If shift is held or the extend flag is set, extends a range to
1182
+ // include a given position (and optionally a second position).
1183
+ // Otherwise, simply returns the range between the given positions.
1184
+ // Used for cursor motion and such.
1185
+ function extendRange(doc, range, head, other) {
1186
+ if (doc.cm && doc.cm.display.shift || doc.extend) {
1187
+ var anchor = range.anchor;
1188
+ if (other) {
1189
+ var posBefore = cmp(head, anchor) < 0;
1190
+ if (posBefore != (cmp(other, anchor) < 0)) {
1191
+ anchor = head;
1192
+ head = other;
1193
+ } else if (posBefore != (cmp(head, other) < 0)) {
1194
+ head = other;
1195
+ }
1196
+ }
1197
+ return new Range(anchor, head);
1198
+ } else {
1199
+ return new Range(other || head, head);
1200
+ }
1201
+ }
1202
+
1203
+ // Extend the primary selection range, discard the rest.
1204
+ function extendSelection(doc, head, other, options) {
1205
+ setSelection(doc, new Selection([extendRange(doc, doc.sel.primary(), head, other)], 0), options);
1206
+ }
1207
+
1208
+ // Extend all selections (pos is an array of selections with length
1209
+ // equal the number of selections)
1210
+ function extendSelections(doc, heads, options) {
1211
+ for (var out = [], i = 0; i < doc.sel.ranges.length; i++)
1212
+ out[i] = extendRange(doc, doc.sel.ranges[i], heads[i], null);
1213
+ var newSel = normalizeSelection(out, doc.sel.primIndex);
1214
+ setSelection(doc, newSel, options);
1215
+ }
1216
+
1217
+ // Updates a single range in the selection.
1218
+ function replaceOneSelection(doc, i, range, options) {
1219
+ var ranges = doc.sel.ranges.slice(0);
1220
+ ranges[i] = range;
1221
+ setSelection(doc, normalizeSelection(ranges, doc.sel.primIndex), options);
1222
+ }
1223
+
1224
+ // Reset the selection to a single range.
1225
+ function setSimpleSelection(doc, anchor, head, options) {
1226
+ setSelection(doc, simpleSelection(anchor, head), options);
1227
+ }
1228
+
1229
+ // Give beforeSelectionChange handlers a change to influence a
1230
+ // selection update.
1231
+ function filterSelectionChange(doc, sel) {
1232
+ var obj = {
1233
+ ranges: sel.ranges,
1234
+ update: function(ranges) {
1235
+ this.ranges = [];
1236
+ for (var i = 0; i < ranges.length; i++)
1237
+ this.ranges[i] = new Range(clipPos(doc, ranges[i].anchor),
1238
+ clipPos(doc, ranges[i].head));
1239
+ }
1240
+ };
1241
+ signal(doc, "beforeSelectionChange", doc, obj);
1242
+ if (doc.cm) signal(doc.cm, "beforeSelectionChange", doc.cm, obj);
1243
+ if (obj.ranges != sel.ranges) return normalizeSelection(obj.ranges, obj.ranges.length - 1);
1244
+ else return sel;
1245
+ }
1246
+
1247
+ function setSelectionReplaceHistory(doc, sel, options) {
1248
+ var done = doc.history.done, last = lst(done);
1249
+ if (last && last.ranges) {
1250
+ done[done.length - 1] = sel;
1251
+ setSelectionNoUndo(doc, sel, options);
1252
+ } else {
1253
+ setSelection(doc, sel, options);
1254
+ }
1255
+ }
1256
+
1257
+ // Set a new selection.
1258
+ function setSelection(doc, sel, options) {
1259
+ setSelectionNoUndo(doc, sel, options);
1260
+ addSelectionToHistory(doc, doc.sel, doc.cm ? doc.cm.curOp.id : NaN, options);
1261
+ }
1262
+
1263
+ function setSelectionNoUndo(doc, sel, options) {
1264
+ if (hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange"))
1265
+ sel = filterSelectionChange(doc, sel);
1266
+
1267
+ var bias = options && options.bias ||
1268
+ (cmp(sel.primary().head, doc.sel.primary().head) < 0 ? -1 : 1);
1269
+ setSelectionInner(doc, skipAtomicInSelection(doc, sel, bias, true));
1270
+
1271
+ if (!(options && options.scroll === false) && doc.cm)
1272
+ ensureCursorVisible(doc.cm);
1273
+ }
1274
+
1275
+ function setSelectionInner(doc, sel) {
1276
+ if (sel.equals(doc.sel)) return;
1277
+
1278
+ doc.sel = sel;
1279
+
1280
+ if (doc.cm) {
1281
+ doc.cm.curOp.updateInput = doc.cm.curOp.selectionChanged = true;
1282
+ signalCursorActivity(doc.cm);
1283
+ }
1284
+ signalLater(doc, "cursorActivity", doc);
1285
+ }
1286
+
1287
+ // Verify that the selection does not partially select any atomic
1288
+ // marked ranges.
1289
+ function reCheckSelection(doc) {
1290
+ setSelectionInner(doc, skipAtomicInSelection(doc, doc.sel, null, false), sel_dontScroll);
1291
+ }
1292
+
1293
+ // Return a selection that does not partially select any atomic
1294
+ // ranges.
1295
+ function skipAtomicInSelection(doc, sel, bias, mayClear) {
1296
+ var out;
1297
+ for (var i = 0; i < sel.ranges.length; i++) {
1298
+ var range = sel.ranges[i];
1299
+ var newAnchor = skipAtomic(doc, range.anchor, bias, mayClear);
1300
+ var newHead = skipAtomic(doc, range.head, bias, mayClear);
1301
+ if (out || newAnchor != range.anchor || newHead != range.head) {
1302
+ if (!out) out = sel.ranges.slice(0, i);
1303
+ out[i] = new Range(newAnchor, newHead);
1304
+ }
1305
+ }
1306
+ return out ? normalizeSelection(out, sel.primIndex) : sel;
1307
+ }
1308
+
1309
+ // Ensure a given position is not inside an atomic range.
1310
+ function skipAtomic(doc, pos, bias, mayClear) {
1311
+ var flipped = false, curPos = pos;
1312
+ var dir = bias || 1;
1313
+ doc.cantEdit = false;
1314
+ search: for (;;) {
1315
+ var line = getLine(doc, curPos.line);
1316
+ if (line.markedSpans) {
1317
+ for (var i = 0; i < line.markedSpans.length; ++i) {
1318
+ var sp = line.markedSpans[i], m = sp.marker;
1319
+ if ((sp.from == null || (m.inclusiveLeft ? sp.from <= curPos.ch : sp.from < curPos.ch)) &&
1320
+ (sp.to == null || (m.inclusiveRight ? sp.to >= curPos.ch : sp.to > curPos.ch))) {
1321
+ if (mayClear) {
1322
+ signal(m, "beforeCursorEnter");
1323
+ if (m.explicitlyCleared) {
1324
+ if (!line.markedSpans) break;
1325
+ else {--i; continue;}
1326
+ }
1327
+ }
1328
+ if (!m.atomic) continue;
1329
+ var newPos = m.find(dir < 0 ? -1 : 1);
1330
+ if (cmp(newPos, curPos) == 0) {
1331
+ newPos.ch += dir;
1332
+ if (newPos.ch < 0) {
1333
+ if (newPos.line > doc.first) newPos = clipPos(doc, Pos(newPos.line - 1));
1334
+ else newPos = null;
1335
+ } else if (newPos.ch > line.text.length) {
1336
+ if (newPos.line < doc.first + doc.size - 1) newPos = Pos(newPos.line + 1, 0);
1337
+ else newPos = null;
1338
+ }
1339
+ if (!newPos) {
1340
+ if (flipped) {
1341
+ // Driven in a corner -- no valid cursor position found at all
1342
+ // -- try again *with* clearing, if we didn't already
1343
+ if (!mayClear) return skipAtomic(doc, pos, bias, true);
1344
+ // Otherwise, turn off editing until further notice, and return the start of the doc
1345
+ doc.cantEdit = true;
1346
+ return Pos(doc.first, 0);
1347
+ }
1348
+ flipped = true; newPos = pos; dir = -dir;
1349
+ }
1350
+ }
1351
+ curPos = newPos;
1352
+ continue search;
1353
+ }
1354
+ }
1355
+ }
1356
+ return curPos;
1357
+ }
1358
+ }
1359
+
1360
+ // SELECTION DRAWING
1361
+
1362
+ // Redraw the selection and/or cursor
1363
+ function drawSelection(cm) {
1364
+ var display = cm.display, doc = cm.doc, result = {};
1365
+ var curFragment = result.cursors = document.createDocumentFragment();
1366
+ var selFragment = result.selection = document.createDocumentFragment();
1367
+
1368
+ for (var i = 0; i < doc.sel.ranges.length; i++) {
1369
+ var range = doc.sel.ranges[i];
1370
+ var collapsed = range.empty();
1371
+ if (collapsed || cm.options.showCursorWhenSelecting)
1372
+ drawSelectionCursor(cm, range, curFragment);
1373
+ if (!collapsed)
1374
+ drawSelectionRange(cm, range, selFragment);
1375
+ }
1376
+
1377
+ // Move the hidden textarea near the cursor to prevent scrolling artifacts
1378
+ if (cm.options.moveInputWithCursor) {
1379
+ var headPos = cursorCoords(cm, doc.sel.primary().head, "div");
1380
+ var wrapOff = display.wrapper.getBoundingClientRect(), lineOff = display.lineDiv.getBoundingClientRect();
1381
+ result.teTop = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
1382
+ headPos.top + lineOff.top - wrapOff.top));
1383
+ result.teLeft = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
1384
+ headPos.left + lineOff.left - wrapOff.left));
1385
+ }
1386
+
1387
+ return result;
1388
+ }
1389
+
1390
+ function showSelection(cm, drawn) {
1391
+ removeChildrenAndAdd(cm.display.cursorDiv, drawn.cursors);
1392
+ removeChildrenAndAdd(cm.display.selectionDiv, drawn.selection);
1393
+ if (drawn.teTop != null) {
1394
+ cm.display.inputDiv.style.top = drawn.teTop + "px";
1395
+ cm.display.inputDiv.style.left = drawn.teLeft + "px";
1396
+ }
1397
+ }
1398
+
1399
+ function updateSelection(cm) {
1400
+ showSelection(cm, drawSelection(cm));
1401
+ }
1402
+
1403
+ // Draws a cursor for the given range
1404
+ function drawSelectionCursor(cm, range, output) {
1405
+ var pos = cursorCoords(cm, range.head, "div", null, null, !cm.options.singleCursorHeightPerLine);
1406
+
1407
+ var cursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor"));
1408
+ cursor.style.left = pos.left + "px";
1409
+ cursor.style.top = pos.top + "px";
1410
+ cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
1411
+
1412
+ if (pos.other) {
1413
+ // Secondary cursor, shown when on a 'jump' in bi-directional text
1414
+ var otherCursor = output.appendChild(elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor"));
1415
+ otherCursor.style.display = "";
1416
+ otherCursor.style.left = pos.other.left + "px";
1417
+ otherCursor.style.top = pos.other.top + "px";
1418
+ otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px";
1419
+ }
1420
+ }
1421
+
1422
+ // Draws the given range as a highlighted selection
1423
+ function drawSelectionRange(cm, range, output) {
1424
+ var display = cm.display, doc = cm.doc;
1425
+ var fragment = document.createDocumentFragment();
1426
+ var padding = paddingH(cm.display), leftSide = padding.left;
1427
+ var rightSide = Math.max(display.sizerWidth, displayWidth(cm) - display.sizer.offsetLeft) - padding.right;
1428
+
1429
+ function add(left, top, width, bottom) {
1430
+ if (top < 0) top = 0;
1431
+ top = Math.round(top);
1432
+ bottom = Math.round(bottom);
1433
+ fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left +
1434
+ "px; top: " + top + "px; width: " + (width == null ? rightSide - left : width) +
1435
+ "px; height: " + (bottom - top) + "px"));
1436
+ }
1437
+
1438
+ function drawForLine(line, fromArg, toArg) {
1439
+ var lineObj = getLine(doc, line);
1440
+ var lineLen = lineObj.text.length;
1441
+ var start, end;
1442
+ function coords(ch, bias) {
1443
+ return charCoords(cm, Pos(line, ch), "div", lineObj, bias);
1444
+ }
1445
+
1446
+ iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) {
1447
+ var leftPos = coords(from, "left"), rightPos, left, right;
1448
+ if (from == to) {
1449
+ rightPos = leftPos;
1450
+ left = right = leftPos.left;
1451
+ } else {
1452
+ rightPos = coords(to - 1, "right");
1453
+ if (dir == "rtl") { var tmp = leftPos; leftPos = rightPos; rightPos = tmp; }
1454
+ left = leftPos.left;
1455
+ right = rightPos.right;
1456
+ }
1457
+ if (fromArg == null && from == 0) left = leftSide;
1458
+ if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
1459
+ add(left, leftPos.top, null, leftPos.bottom);
1460
+ left = leftSide;
1461
+ if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top);
1462
+ }
1463
+ if (toArg == null && to == lineLen) right = rightSide;
1464
+ if (!start || leftPos.top < start.top || leftPos.top == start.top && leftPos.left < start.left)
1465
+ start = leftPos;
1466
+ if (!end || rightPos.bottom > end.bottom || rightPos.bottom == end.bottom && rightPos.right > end.right)
1467
+ end = rightPos;
1468
+ if (left < leftSide + 1) left = leftSide;
1469
+ add(left, rightPos.top, right - left, rightPos.bottom);
1470
+ });
1471
+ return {start: start, end: end};
1472
+ }
1473
+
1474
+ var sFrom = range.from(), sTo = range.to();
1475
+ if (sFrom.line == sTo.line) {
1476
+ drawForLine(sFrom.line, sFrom.ch, sTo.ch);
1477
+ } else {
1478
+ var fromLine = getLine(doc, sFrom.line), toLine = getLine(doc, sTo.line);
1479
+ var singleVLine = visualLine(fromLine) == visualLine(toLine);
1480
+ var leftEnd = drawForLine(sFrom.line, sFrom.ch, singleVLine ? fromLine.text.length + 1 : null).end;
1481
+ var rightStart = drawForLine(sTo.line, singleVLine ? 0 : null, sTo.ch).start;
1482
+ if (singleVLine) {
1483
+ if (leftEnd.top < rightStart.top - 2) {
1484
+ add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
1485
+ add(leftSide, rightStart.top, rightStart.left, rightStart.bottom);
1486
+ } else {
1487
+ add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
1488
+ }
1489
+ }
1490
+ if (leftEnd.bottom < rightStart.top)
1491
+ add(leftSide, leftEnd.bottom, null, rightStart.top);
1492
+ }
1493
+
1494
+ output.appendChild(fragment);
1495
+ }
1496
+
1497
+ // Cursor-blinking
1498
+ function restartBlink(cm) {
1499
+ if (!cm.state.focused) return;
1500
+ var display = cm.display;
1501
+ clearInterval(display.blinker);
1502
+ var on = true;
1503
+ display.cursorDiv.style.visibility = "";
1504
+ if (cm.options.cursorBlinkRate > 0)
1505
+ display.blinker = setInterval(function() {
1506
+ display.cursorDiv.style.visibility = (on = !on) ? "" : "hidden";
1507
+ }, cm.options.cursorBlinkRate);
1508
+ else if (cm.options.cursorBlinkRate < 0)
1509
+ display.cursorDiv.style.visibility = "hidden";
1510
+ }
1511
+
1512
+ // HIGHLIGHT WORKER
1513
+
1514
+ function startWorker(cm, time) {
1515
+ if (cm.doc.mode.startState && cm.doc.frontier < cm.display.viewTo)
1516
+ cm.state.highlight.set(time, bind(highlightWorker, cm));
1517
+ }
1518
+
1519
+ function highlightWorker(cm) {
1520
+ var doc = cm.doc;
1521
+ if (doc.frontier < doc.first) doc.frontier = doc.first;
1522
+ if (doc.frontier >= cm.display.viewTo) return;
1523
+ var end = +new Date + cm.options.workTime;
1524
+ var state = copyState(doc.mode, getStateBefore(cm, doc.frontier));
1525
+ var changedLines = [];
1526
+
1527
+ doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.viewTo + 500), function(line) {
1528
+ if (doc.frontier >= cm.display.viewFrom) { // Visible
1529
+ var oldStyles = line.styles;
1530
+ var highlighted = highlightLine(cm, line, state, true);
1531
+ line.styles = highlighted.styles;
1532
+ var oldCls = line.styleClasses, newCls = highlighted.classes;
1533
+ if (newCls) line.styleClasses = newCls;
1534
+ else if (oldCls) line.styleClasses = null;
1535
+ var ischange = !oldStyles || oldStyles.length != line.styles.length ||
1536
+ oldCls != newCls && (!oldCls || !newCls || oldCls.bgClass != newCls.bgClass || oldCls.textClass != newCls.textClass);
1537
+ for (var i = 0; !ischange && i < oldStyles.length; ++i) ischange = oldStyles[i] != line.styles[i];
1538
+ if (ischange) changedLines.push(doc.frontier);
1539
+ line.stateAfter = copyState(doc.mode, state);
1540
+ } else {
1541
+ processLine(cm, line.text, state);
1542
+ line.stateAfter = doc.frontier % 5 == 0 ? copyState(doc.mode, state) : null;
1543
+ }
1544
+ ++doc.frontier;
1545
+ if (+new Date > end) {
1546
+ startWorker(cm, cm.options.workDelay);
1547
+ return true;
1548
+ }
1549
+ });
1550
+ if (changedLines.length) runInOp(cm, function() {
1551
+ for (var i = 0; i < changedLines.length; i++)
1552
+ regLineChange(cm, changedLines[i], "text");
1553
+ });
1554
+ }
1555
+
1556
+ // Finds the line to start with when starting a parse. Tries to
1557
+ // find a line with a stateAfter, so that it can start with a
1558
+ // valid state. If that fails, it returns the line with the
1559
+ // smallest indentation, which tends to need the least context to
1560
+ // parse correctly.
1561
+ function findStartLine(cm, n, precise) {
1562
+ var minindent, minline, doc = cm.doc;
1563
+ var lim = precise ? -1 : n - (cm.doc.mode.innerMode ? 1000 : 100);
1564
+ for (var search = n; search > lim; --search) {
1565
+ if (search <= doc.first) return doc.first;
1566
+ var line = getLine(doc, search - 1);
1567
+ if (line.stateAfter && (!precise || search <= doc.frontier)) return search;
1568
+ var indented = countColumn(line.text, null, cm.options.tabSize);
1569
+ if (minline == null || minindent > indented) {
1570
+ minline = search - 1;
1571
+ minindent = indented;
1572
+ }
1573
+ }
1574
+ return minline;
1575
+ }
1576
+
1577
+ function getStateBefore(cm, n, precise) {
1578
+ var doc = cm.doc, display = cm.display;
1579
+ if (!doc.mode.startState) return true;
1580
+ var pos = findStartLine(cm, n, precise), state = pos > doc.first && getLine(doc, pos-1).stateAfter;
1581
+ if (!state) state = startState(doc.mode);
1582
+ else state = copyState(doc.mode, state);
1583
+ doc.iter(pos, n, function(line) {
1584
+ processLine(cm, line.text, state);
1585
+ var save = pos == n - 1 || pos % 5 == 0 || pos >= display.viewFrom && pos < display.viewTo;
1586
+ line.stateAfter = save ? copyState(doc.mode, state) : null;
1587
+ ++pos;
1588
+ });
1589
+ if (precise) doc.frontier = pos;
1590
+ return state;
1591
+ }
1592
+
1593
+ // POSITION MEASUREMENT
1594
+
1595
+ function paddingTop(display) {return display.lineSpace.offsetTop;}
1596
+ function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight;}
1597
+ function paddingH(display) {
1598
+ if (display.cachedPaddingH) return display.cachedPaddingH;
1599
+ var e = removeChildrenAndAdd(display.measure, elt("pre", "x"));
1600
+ var style = window.getComputedStyle ? window.getComputedStyle(e) : e.currentStyle;
1601
+ var data = {left: parseInt(style.paddingLeft), right: parseInt(style.paddingRight)};
1602
+ if (!isNaN(data.left) && !isNaN(data.right)) display.cachedPaddingH = data;
1603
+ return data;
1604
+ }
1605
+
1606
+ function scrollGap(cm) { return scrollerGap - cm.display.nativeBarWidth; }
1607
+ function displayWidth(cm) {
1608
+ return cm.display.scroller.clientWidth - scrollGap(cm) - cm.display.barWidth;
1609
+ }
1610
+ function displayHeight(cm) {
1611
+ return cm.display.scroller.clientHeight - scrollGap(cm) - cm.display.barHeight;
1612
+ }
1613
+
1614
+ // Ensure the lineView.wrapping.heights array is populated. This is
1615
+ // an array of bottom offsets for the lines that make up a drawn
1616
+ // line. When lineWrapping is on, there might be more than one
1617
+ // height.
1618
+ function ensureLineHeights(cm, lineView, rect) {
1619
+ var wrapping = cm.options.lineWrapping;
1620
+ var curWidth = wrapping && displayWidth(cm);
1621
+ if (!lineView.measure.heights || wrapping && lineView.measure.width != curWidth) {
1622
+ var heights = lineView.measure.heights = [];
1623
+ if (wrapping) {
1624
+ lineView.measure.width = curWidth;
1625
+ var rects = lineView.text.firstChild.getClientRects();
1626
+ for (var i = 0; i < rects.length - 1; i++) {
1627
+ var cur = rects[i], next = rects[i + 1];
1628
+ if (Math.abs(cur.bottom - next.bottom) > 2)
1629
+ heights.push((cur.bottom + next.top) / 2 - rect.top);
1630
+ }
1631
+ }
1632
+ heights.push(rect.bottom - rect.top);
1633
+ }
1634
+ }
1635
+
1636
+ // Find a line map (mapping character offsets to text nodes) and a
1637
+ // measurement cache for the given line number. (A line view might
1638
+ // contain multiple lines when collapsed ranges are present.)
1639
+ function mapFromLineView(lineView, line, lineN) {
1640
+ if (lineView.line == line)
1641
+ return {map: lineView.measure.map, cache: lineView.measure.cache};
1642
+ for (var i = 0; i < lineView.rest.length; i++)
1643
+ if (lineView.rest[i] == line)
1644
+ return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i]};
1645
+ for (var i = 0; i < lineView.rest.length; i++)
1646
+ if (lineNo(lineView.rest[i]) > lineN)
1647
+ return {map: lineView.measure.maps[i], cache: lineView.measure.caches[i], before: true};
1648
+ }
1649
+
1650
+ // Render a line into the hidden node display.externalMeasured. Used
1651
+ // when measurement is needed for a line that's not in the viewport.
1652
+ function updateExternalMeasurement(cm, line) {
1653
+ line = visualLine(line);
1654
+ var lineN = lineNo(line);
1655
+ var view = cm.display.externalMeasured = new LineView(cm.doc, line, lineN);
1656
+ view.lineN = lineN;
1657
+ var built = view.built = buildLineContent(cm, view);
1658
+ view.text = built.pre;
1659
+ removeChildrenAndAdd(cm.display.lineMeasure, built.pre);
1660
+ return view;
1661
+ }
1662
+
1663
+ // Get a {top, bottom, left, right} box (in line-local coordinates)
1664
+ // for a given character.
1665
+ function measureChar(cm, line, ch, bias) {
1666
+ return measureCharPrepared(cm, prepareMeasureForLine(cm, line), ch, bias);
1667
+ }
1668
+
1669
+ // Find a line view that corresponds to the given line number.
1670
+ function findViewForLine(cm, lineN) {
1671
+ if (lineN >= cm.display.viewFrom && lineN < cm.display.viewTo)
1672
+ return cm.display.view[findViewIndex(cm, lineN)];
1673
+ var ext = cm.display.externalMeasured;
1674
+ if (ext && lineN >= ext.lineN && lineN < ext.lineN + ext.size)
1675
+ return ext;
1676
+ }
1677
+
1678
+ // Measurement can be split in two steps, the set-up work that
1679
+ // applies to the whole line, and the measurement of the actual
1680
+ // character. Functions like coordsChar, that need to do a lot of
1681
+ // measurements in a row, can thus ensure that the set-up work is
1682
+ // only done once.
1683
+ function prepareMeasureForLine(cm, line) {
1684
+ var lineN = lineNo(line);
1685
+ var view = findViewForLine(cm, lineN);
1686
+ if (view && !view.text)
1687
+ view = null;
1688
+ else if (view && view.changes)
1689
+ updateLineForChanges(cm, view, lineN, getDimensions(cm));
1690
+ if (!view)
1691
+ view = updateExternalMeasurement(cm, line);
1692
+
1693
+ var info = mapFromLineView(view, line, lineN);
1694
+ return {
1695
+ line: line, view: view, rect: null,
1696
+ map: info.map, cache: info.cache, before: info.before,
1697
+ hasHeights: false
1698
+ };
1699
+ }
1700
+
1701
+ // Given a prepared measurement object, measures the position of an
1702
+ // actual character (or fetches it from the cache).
1703
+ function measureCharPrepared(cm, prepared, ch, bias, varHeight) {
1704
+ if (prepared.before) ch = -1;
1705
+ var key = ch + (bias || ""), found;
1706
+ if (prepared.cache.hasOwnProperty(key)) {
1707
+ found = prepared.cache[key];
1708
+ } else {
1709
+ if (!prepared.rect)
1710
+ prepared.rect = prepared.view.text.getBoundingClientRect();
1711
+ if (!prepared.hasHeights) {
1712
+ ensureLineHeights(cm, prepared.view, prepared.rect);
1713
+ prepared.hasHeights = true;
1714
+ }
1715
+ found = measureCharInner(cm, prepared, ch, bias);
1716
+ if (!found.bogus) prepared.cache[key] = found;
1717
+ }
1718
+ return {left: found.left, right: found.right,
1719
+ top: varHeight ? found.rtop : found.top,
1720
+ bottom: varHeight ? found.rbottom : found.bottom};
1721
+ }
1722
+
1723
+ var nullRect = {left: 0, right: 0, top: 0, bottom: 0};
1724
+
1725
+ function measureCharInner(cm, prepared, ch, bias) {
1726
+ var map = prepared.map;
1727
+
1728
+ var node, start, end, collapse;
1729
+ // First, search the line map for the text node corresponding to,
1730
+ // or closest to, the target character.
1731
+ for (var i = 0; i < map.length; i += 3) {
1732
+ var mStart = map[i], mEnd = map[i + 1];
1733
+ if (ch < mStart) {
1734
+ start = 0; end = 1;
1735
+ collapse = "left";
1736
+ } else if (ch < mEnd) {
1737
+ start = ch - mStart;
1738
+ end = start + 1;
1739
+ } else if (i == map.length - 3 || ch == mEnd && map[i + 3] > ch) {
1740
+ end = mEnd - mStart;
1741
+ start = end - 1;
1742
+ if (ch >= mEnd) collapse = "right";
1743
+ }
1744
+ if (start != null) {
1745
+ node = map[i + 2];
1746
+ if (mStart == mEnd && bias == (node.insertLeft ? "left" : "right"))
1747
+ collapse = bias;
1748
+ if (bias == "left" && start == 0)
1749
+ while (i && map[i - 2] == map[i - 3] && map[i - 1].insertLeft) {
1750
+ node = map[(i -= 3) + 2];
1751
+ collapse = "left";
1752
+ }
1753
+ if (bias == "right" && start == mEnd - mStart)
1754
+ while (i < map.length - 3 && map[i + 3] == map[i + 4] && !map[i + 5].insertLeft) {
1755
+ node = map[(i += 3) + 2];
1756
+ collapse = "right";
1757
+ }
1758
+ break;
1759
+ }
1760
+ }
1761
+
1762
+ var rect;
1763
+ if (node.nodeType == 3) { // If it is a text node, use a range to retrieve the coordinates.
1764
+ for (var i = 0; i < 4; i++) { // Retry a maximum of 4 times when nonsense rectangles are returned
1765
+ while (start && isExtendingChar(prepared.line.text.charAt(mStart + start))) --start;
1766
+ while (mStart + end < mEnd && isExtendingChar(prepared.line.text.charAt(mStart + end))) ++end;
1767
+ if (ie && ie_version < 9 && start == 0 && end == mEnd - mStart) {
1768
+ rect = node.parentNode.getBoundingClientRect();
1769
+ } else if (ie && cm.options.lineWrapping) {
1770
+ var rects = range(node, start, end).getClientRects();
1771
+ if (rects.length)
1772
+ rect = rects[bias == "right" ? rects.length - 1 : 0];
1773
+ else
1774
+ rect = nullRect;
1775
+ } else {
1776
+ rect = range(node, start, end).getBoundingClientRect() || nullRect;
1777
+ }
1778
+ if (rect.left || rect.right || start == 0) break;
1779
+ end = start;
1780
+ start = start - 1;
1781
+ collapse = "right";
1782
+ }
1783
+ if (ie && ie_version < 11) rect = maybeUpdateRectForZooming(cm.display.measure, rect);
1784
+ } else { // If it is a widget, simply get the box for the whole widget.
1785
+ if (start > 0) collapse = bias = "right";
1786
+ var rects;
1787
+ if (cm.options.lineWrapping && (rects = node.getClientRects()).length > 1)
1788
+ rect = rects[bias == "right" ? rects.length - 1 : 0];
1789
+ else
1790
+ rect = node.getBoundingClientRect();
1791
+ }
1792
+ if (ie && ie_version < 9 && !start && (!rect || !rect.left && !rect.right)) {
1793
+ var rSpan = node.parentNode.getClientRects()[0];
1794
+ if (rSpan)
1795
+ rect = {left: rSpan.left, right: rSpan.left + charWidth(cm.display), top: rSpan.top, bottom: rSpan.bottom};
1796
+ else
1797
+ rect = nullRect;
1798
+ }
1799
+
1800
+ var rtop = rect.top - prepared.rect.top, rbot = rect.bottom - prepared.rect.top;
1801
+ var mid = (rtop + rbot) / 2;
1802
+ var heights = prepared.view.measure.heights;
1803
+ for (var i = 0; i < heights.length - 1; i++)
1804
+ if (mid < heights[i]) break;
1805
+ var top = i ? heights[i - 1] : 0, bot = heights[i];
1806
+ var result = {left: (collapse == "right" ? rect.right : rect.left) - prepared.rect.left,
1807
+ right: (collapse == "left" ? rect.left : rect.right) - prepared.rect.left,
1808
+ top: top, bottom: bot};
1809
+ if (!rect.left && !rect.right) result.bogus = true;
1810
+ if (!cm.options.singleCursorHeightPerLine) { result.rtop = rtop; result.rbottom = rbot; }
1811
+
1812
+ return result;
1813
+ }
1814
+
1815
+ // Work around problem with bounding client rects on ranges being
1816
+ // returned incorrectly when zoomed on IE10 and below.
1817
+ function maybeUpdateRectForZooming(measure, rect) {
1818
+ if (!window.screen || screen.logicalXDPI == null ||
1819
+ screen.logicalXDPI == screen.deviceXDPI || !hasBadZoomedRects(measure))
1820
+ return rect;
1821
+ var scaleX = screen.logicalXDPI / screen.deviceXDPI;
1822
+ var scaleY = screen.logicalYDPI / screen.deviceYDPI;
1823
+ return {left: rect.left * scaleX, right: rect.right * scaleX,
1824
+ top: rect.top * scaleY, bottom: rect.bottom * scaleY};
1825
+ }
1826
+
1827
+ function clearLineMeasurementCacheFor(lineView) {
1828
+ if (lineView.measure) {
1829
+ lineView.measure.cache = {};
1830
+ lineView.measure.heights = null;
1831
+ if (lineView.rest) for (var i = 0; i < lineView.rest.length; i++)
1832
+ lineView.measure.caches[i] = {};
1833
+ }
1834
+ }
1835
+
1836
+ function clearLineMeasurementCache(cm) {
1837
+ cm.display.externalMeasure = null;
1838
+ removeChildren(cm.display.lineMeasure);
1839
+ for (var i = 0; i < cm.display.view.length; i++)
1840
+ clearLineMeasurementCacheFor(cm.display.view[i]);
1841
+ }
1842
+
1843
+ function clearCaches(cm) {
1844
+ clearLineMeasurementCache(cm);
1845
+ cm.display.cachedCharWidth = cm.display.cachedTextHeight = cm.display.cachedPaddingH = null;
1846
+ if (!cm.options.lineWrapping) cm.display.maxLineChanged = true;
1847
+ cm.display.lineNumChars = null;
1848
+ }
1849
+
1850
+ function pageScrollX() { return window.pageXOffset || (document.documentElement || document.body).scrollLeft; }
1851
+ function pageScrollY() { return window.pageYOffset || (document.documentElement || document.body).scrollTop; }
1852
+
1853
+ // Converts a {top, bottom, left, right} box from line-local
1854
+ // coordinates into another coordinate system. Context may be one of
1855
+ // "line", "div" (display.lineDiv), "local"/null (editor), "window",
1856
+ // or "page".
1857
+ function intoCoordSystem(cm, lineObj, rect, context) {
1858
+ if (lineObj.widgets) for (var i = 0; i < lineObj.widgets.length; ++i) if (lineObj.widgets[i].above) {
1859
+ var size = widgetHeight(lineObj.widgets[i]);
1860
+ rect.top += size; rect.bottom += size;
1861
+ }
1862
+ if (context == "line") return rect;
1863
+ if (!context) context = "local";
1864
+ var yOff = heightAtLine(lineObj);
1865
+ if (context == "local") yOff += paddingTop(cm.display);
1866
+ else yOff -= cm.display.viewOffset;
1867
+ if (context == "page" || context == "window") {
1868
+ var lOff = cm.display.lineSpace.getBoundingClientRect();
1869
+ yOff += lOff.top + (context == "window" ? 0 : pageScrollY());
1870
+ var xOff = lOff.left + (context == "window" ? 0 : pageScrollX());
1871
+ rect.left += xOff; rect.right += xOff;
1872
+ }
1873
+ rect.top += yOff; rect.bottom += yOff;
1874
+ return rect;
1875
+ }
1876
+
1877
+ // Coverts a box from "div" coords to another coordinate system.
1878
+ // Context may be "window", "page", "div", or "local"/null.
1879
+ function fromCoordSystem(cm, coords, context) {
1880
+ if (context == "div") return coords;
1881
+ var left = coords.left, top = coords.top;
1882
+ // First move into "page" coordinate system
1883
+ if (context == "page") {
1884
+ left -= pageScrollX();
1885
+ top -= pageScrollY();
1886
+ } else if (context == "local" || !context) {
1887
+ var localBox = cm.display.sizer.getBoundingClientRect();
1888
+ left += localBox.left;
1889
+ top += localBox.top;
1890
+ }
1891
+
1892
+ var lineSpaceBox = cm.display.lineSpace.getBoundingClientRect();
1893
+ return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top};
1894
+ }
1895
+
1896
+ function charCoords(cm, pos, context, lineObj, bias) {
1897
+ if (!lineObj) lineObj = getLine(cm.doc, pos.line);
1898
+ return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, bias), context);
1899
+ }
1900
+
1901
+ // Returns a box for a given cursor position, which may have an
1902
+ // 'other' property containing the position of the secondary cursor
1903
+ // on a bidi boundary.
1904
+ function cursorCoords(cm, pos, context, lineObj, preparedMeasure, varHeight) {
1905
+ lineObj = lineObj || getLine(cm.doc, pos.line);
1906
+ if (!preparedMeasure) preparedMeasure = prepareMeasureForLine(cm, lineObj);
1907
+ function get(ch, right) {
1908
+ var m = measureCharPrepared(cm, preparedMeasure, ch, right ? "right" : "left", varHeight);
1909
+ if (right) m.left = m.right; else m.right = m.left;
1910
+ return intoCoordSystem(cm, lineObj, m, context);
1911
+ }
1912
+ function getBidi(ch, partPos) {
1913
+ var part = order[partPos], right = part.level % 2;
1914
+ if (ch == bidiLeft(part) && partPos && part.level < order[partPos - 1].level) {
1915
+ part = order[--partPos];
1916
+ ch = bidiRight(part) - (part.level % 2 ? 0 : 1);
1917
+ right = true;
1918
+ } else if (ch == bidiRight(part) && partPos < order.length - 1 && part.level < order[partPos + 1].level) {
1919
+ part = order[++partPos];
1920
+ ch = bidiLeft(part) - part.level % 2;
1921
+ right = false;
1922
+ }
1923
+ if (right && ch == part.to && ch > part.from) return get(ch - 1);
1924
+ return get(ch, right);
1925
+ }
1926
+ var order = getOrder(lineObj), ch = pos.ch;
1927
+ if (!order) return get(ch);
1928
+ var partPos = getBidiPartAt(order, ch);
1929
+ var val = getBidi(ch, partPos);
1930
+ if (bidiOther != null) val.other = getBidi(ch, bidiOther);
1931
+ return val;
1932
+ }
1933
+
1934
+ // Used to cheaply estimate the coordinates for a position. Used for
1935
+ // intermediate scroll updates.
1936
+ function estimateCoords(cm, pos) {
1937
+ var left = 0, pos = clipPos(cm.doc, pos);
1938
+ if (!cm.options.lineWrapping) left = charWidth(cm.display) * pos.ch;
1939
+ var lineObj = getLine(cm.doc, pos.line);
1940
+ var top = heightAtLine(lineObj) + paddingTop(cm.display);
1941
+ return {left: left, right: left, top: top, bottom: top + lineObj.height};
1942
+ }
1943
+
1944
+ // Positions returned by coordsChar contain some extra information.
1945
+ // xRel is the relative x position of the input coordinates compared
1946
+ // to the found position (so xRel > 0 means the coordinates are to
1947
+ // the right of the character position, for example). When outside
1948
+ // is true, that means the coordinates lie outside the line's
1949
+ // vertical range.
1950
+ function PosWithInfo(line, ch, outside, xRel) {
1951
+ var pos = Pos(line, ch);
1952
+ pos.xRel = xRel;
1953
+ if (outside) pos.outside = true;
1954
+ return pos;
1955
+ }
1956
+
1957
+ // Compute the character position closest to the given coordinates.
1958
+ // Input must be lineSpace-local ("div" coordinate system).
1959
+ function coordsChar(cm, x, y) {
1960
+ var doc = cm.doc;
1961
+ y += cm.display.viewOffset;
1962
+ if (y < 0) return PosWithInfo(doc.first, 0, true, -1);
1963
+ var lineN = lineAtHeight(doc, y), last = doc.first + doc.size - 1;
1964
+ if (lineN > last)
1965
+ return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, true, 1);
1966
+ if (x < 0) x = 0;
1967
+
1968
+ var lineObj = getLine(doc, lineN);
1969
+ for (;;) {
1970
+ var found = coordsCharInner(cm, lineObj, lineN, x, y);
1971
+ var merged = collapsedSpanAtEnd(lineObj);
1972
+ var mergedPos = merged && merged.find(0, true);
1973
+ if (merged && (found.ch > mergedPos.from.ch || found.ch == mergedPos.from.ch && found.xRel > 0))
1974
+ lineN = lineNo(lineObj = mergedPos.to.line);
1975
+ else
1976
+ return found;
1977
+ }
1978
+ }
1979
+
1980
+ function coordsCharInner(cm, lineObj, lineNo, x, y) {
1981
+ var innerOff = y - heightAtLine(lineObj);
1982
+ var wrongLine = false, adjust = 2 * cm.display.wrapper.clientWidth;
1983
+ var preparedMeasure = prepareMeasureForLine(cm, lineObj);
1984
+
1985
+ function getX(ch) {
1986
+ var sp = cursorCoords(cm, Pos(lineNo, ch), "line", lineObj, preparedMeasure);
1987
+ wrongLine = true;
1988
+ if (innerOff > sp.bottom) return sp.left - adjust;
1989
+ else if (innerOff < sp.top) return sp.left + adjust;
1990
+ else wrongLine = false;
1991
+ return sp.left;
1992
+ }
1993
+
1994
+ var bidi = getOrder(lineObj), dist = lineObj.text.length;
1995
+ var from = lineLeft(lineObj), to = lineRight(lineObj);
1996
+ var fromX = getX(from), fromOutside = wrongLine, toX = getX(to), toOutside = wrongLine;
1997
+
1998
+ if (x > toX) return PosWithInfo(lineNo, to, toOutside, 1);
1999
+ // Do a binary search between these bounds.
2000
+ for (;;) {
2001
+ if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) {
2002
+ var ch = x < fromX || x - fromX <= toX - x ? from : to;
2003
+ var xDiff = x - (ch == from ? fromX : toX);
2004
+ while (isExtendingChar(lineObj.text.charAt(ch))) ++ch;
2005
+ var pos = PosWithInfo(lineNo, ch, ch == from ? fromOutside : toOutside,
2006
+ xDiff < -1 ? -1 : xDiff > 1 ? 1 : 0);
2007
+ return pos;
2008
+ }
2009
+ var step = Math.ceil(dist / 2), middle = from + step;
2010
+ if (bidi) {
2011
+ middle = from;
2012
+ for (var i = 0; i < step; ++i) middle = moveVisually(lineObj, middle, 1);
2013
+ }
2014
+ var middleX = getX(middle);
2015
+ if (middleX > x) {to = middle; toX = middleX; if (toOutside = wrongLine) toX += 1000; dist = step;}
2016
+ else {from = middle; fromX = middleX; fromOutside = wrongLine; dist -= step;}
2017
+ }
2018
+ }
2019
+
2020
+ var measureText;
2021
+ // Compute the default text height.
2022
+ function textHeight(display) {
2023
+ if (display.cachedTextHeight != null) return display.cachedTextHeight;
2024
+ if (measureText == null) {
2025
+ measureText = elt("pre");
2026
+ // Measure a bunch of lines, for browsers that compute
2027
+ // fractional heights.
2028
+ for (var i = 0; i < 49; ++i) {
2029
+ measureText.appendChild(document.createTextNode("x"));
2030
+ measureText.appendChild(elt("br"));
2031
+ }
2032
+ measureText.appendChild(document.createTextNode("x"));
2033
+ }
2034
+ removeChildrenAndAdd(display.measure, measureText);
2035
+ var height = measureText.offsetHeight / 50;
2036
+ if (height > 3) display.cachedTextHeight = height;
2037
+ removeChildren(display.measure);
2038
+ return height || 1;
2039
+ }
2040
+
2041
+ // Compute the default character width.
2042
+ function charWidth(display) {
2043
+ if (display.cachedCharWidth != null) return display.cachedCharWidth;
2044
+ var anchor = elt("span", "xxxxxxxxxx");
2045
+ var pre = elt("pre", [anchor]);
2046
+ removeChildrenAndAdd(display.measure, pre);
2047
+ var rect = anchor.getBoundingClientRect(), width = (rect.right - rect.left) / 10;
2048
+ if (width > 2) display.cachedCharWidth = width;
2049
+ return width || 10;
2050
+ }
2051
+
2052
+ // OPERATIONS
2053
+
2054
+ // Operations are used to wrap a series of changes to the editor
2055
+ // state in such a way that each change won't have to update the
2056
+ // cursor and display (which would be awkward, slow, and
2057
+ // error-prone). Instead, display updates are batched and then all
2058
+ // combined and executed at once.
2059
+
2060
+ var operationGroup = null;
2061
+
2062
+ var nextOpId = 0;
2063
+ // Start a new operation.
2064
+ function startOperation(cm) {
2065
+ cm.curOp = {
2066
+ cm: cm,
2067
+ viewChanged: false, // Flag that indicates that lines might need to be redrawn
2068
+ startHeight: cm.doc.height, // Used to detect need to update scrollbar
2069
+ forceUpdate: false, // Used to force a redraw
2070
+ updateInput: null, // Whether to reset the input textarea
2071
+ typing: false, // Whether this reset should be careful to leave existing text (for compositing)
2072
+ changeObjs: null, // Accumulated changes, for firing change events
2073
+ cursorActivityHandlers: null, // Set of handlers to fire cursorActivity on
2074
+ cursorActivityCalled: 0, // Tracks which cursorActivity handlers have been called already
2075
+ selectionChanged: false, // Whether the selection needs to be redrawn
2076
+ updateMaxLine: false, // Set when the widest line needs to be determined anew
2077
+ scrollLeft: null, scrollTop: null, // Intermediate scroll position, not pushed to DOM yet
2078
+ scrollToPos: null, // Used to scroll to a specific position
2079
+ id: ++nextOpId // Unique ID
2080
+ };
2081
+ if (operationGroup) {
2082
+ operationGroup.ops.push(cm.curOp);
2083
+ } else {
2084
+ cm.curOp.ownsGroup = operationGroup = {
2085
+ ops: [cm.curOp],
2086
+ delayedCallbacks: []
2087
+ };
2088
+ }
2089
+ }
2090
+
2091
+ function fireCallbacksForOps(group) {
2092
+ // Calls delayed callbacks and cursorActivity handlers until no
2093
+ // new ones appear
2094
+ var callbacks = group.delayedCallbacks, i = 0;
2095
+ do {
2096
+ for (; i < callbacks.length; i++)
2097
+ callbacks[i]();
2098
+ for (var j = 0; j < group.ops.length; j++) {
2099
+ var op = group.ops[j];
2100
+ if (op.cursorActivityHandlers)
2101
+ while (op.cursorActivityCalled < op.cursorActivityHandlers.length)
2102
+ op.cursorActivityHandlers[op.cursorActivityCalled++](op.cm);
2103
+ }
2104
+ } while (i < callbacks.length);
2105
+ }
2106
+
2107
+ // Finish an operation, updating the display and signalling delayed events
2108
+ function endOperation(cm) {
2109
+ var op = cm.curOp, group = op.ownsGroup;
2110
+ if (!group) return;
2111
+
2112
+ try { fireCallbacksForOps(group); }
2113
+ finally {
2114
+ operationGroup = null;
2115
+ for (var i = 0; i < group.ops.length; i++)
2116
+ group.ops[i].cm.curOp = null;
2117
+ endOperations(group);
2118
+ }
2119
+ }
2120
+
2121
+ // The DOM updates done when an operation finishes are batched so
2122
+ // that the minimum number of relayouts are required.
2123
+ function endOperations(group) {
2124
+ var ops = group.ops;
2125
+ for (var i = 0; i < ops.length; i++) // Read DOM
2126
+ endOperation_R1(ops[i]);
2127
+ for (var i = 0; i < ops.length; i++) // Write DOM (maybe)
2128
+ endOperation_W1(ops[i]);
2129
+ for (var i = 0; i < ops.length; i++) // Read DOM
2130
+ endOperation_R2(ops[i]);
2131
+ for (var i = 0; i < ops.length; i++) // Write DOM (maybe)
2132
+ endOperation_W2(ops[i]);
2133
+ for (var i = 0; i < ops.length; i++) // Read DOM
2134
+ endOperation_finish(ops[i]);
2135
+ }
2136
+
2137
+ function endOperation_R1(op) {
2138
+ var cm = op.cm, display = cm.display;
2139
+ maybeClipScrollbars(cm);
2140
+ if (op.updateMaxLine) findMaxLine(cm);
2141
+
2142
+ op.mustUpdate = op.viewChanged || op.forceUpdate || op.scrollTop != null ||
2143
+ op.scrollToPos && (op.scrollToPos.from.line < display.viewFrom ||
2144
+ op.scrollToPos.to.line >= display.viewTo) ||
2145
+ display.maxLineChanged && cm.options.lineWrapping;
2146
+ op.update = op.mustUpdate &&
2147
+ new DisplayUpdate(cm, op.mustUpdate && {top: op.scrollTop, ensure: op.scrollToPos}, op.forceUpdate);
2148
+ }
2149
+
2150
+ function endOperation_W1(op) {
2151
+ op.updatedDisplay = op.mustUpdate && updateDisplayIfNeeded(op.cm, op.update);
2152
+ }
2153
+
2154
+ function endOperation_R2(op) {
2155
+ var cm = op.cm, display = cm.display;
2156
+ if (op.updatedDisplay) updateHeightsInViewport(cm);
2157
+
2158
+ op.barMeasure = measureForScrollbars(cm);
2159
+
2160
+ // If the max line changed since it was last measured, measure it,
2161
+ // and ensure the document's width matches it.
2162
+ // updateDisplay_W2 will use these properties to do the actual resizing
2163
+ if (display.maxLineChanged && !cm.options.lineWrapping) {
2164
+ op.adjustWidthTo = measureChar(cm, display.maxLine, display.maxLine.text.length).left + 3;
2165
+ cm.display.sizerWidth = op.adjustWidthTo;
2166
+ op.barMeasure.scrollWidth =
2167
+ Math.max(display.scroller.clientWidth, display.sizer.offsetLeft + op.adjustWidthTo + scrollGap(cm) + cm.display.barWidth);
2168
+ op.maxScrollLeft = Math.max(0, display.sizer.offsetLeft + op.adjustWidthTo - displayWidth(cm));
2169
+ }
2170
+
2171
+ if (op.updatedDisplay || op.selectionChanged)
2172
+ op.newSelectionNodes = drawSelection(cm);
2173
+ }
2174
+
2175
+ function endOperation_W2(op) {
2176
+ var cm = op.cm;
2177
+
2178
+ if (op.adjustWidthTo != null) {
2179
+ cm.display.sizer.style.minWidth = op.adjustWidthTo + "px";
2180
+ if (op.maxScrollLeft < cm.doc.scrollLeft)
2181
+ setScrollLeft(cm, Math.min(cm.display.scroller.scrollLeft, op.maxScrollLeft), true);
2182
+ cm.display.maxLineChanged = false;
2183
+ }
2184
+
2185
+ if (op.newSelectionNodes)
2186
+ showSelection(cm, op.newSelectionNodes);
2187
+ if (op.updatedDisplay)
2188
+ setDocumentHeight(cm, op.barMeasure);
2189
+ if (op.updatedDisplay || op.startHeight != cm.doc.height)
2190
+ updateScrollbars(cm, op.barMeasure);
2191
+
2192
+ if (op.selectionChanged) restartBlink(cm);
2193
+
2194
+ if (cm.state.focused && op.updateInput)
2195
+ resetInput(cm, op.typing);
2196
+ }
2197
+
2198
+ function endOperation_finish(op) {
2199
+ var cm = op.cm, display = cm.display, doc = cm.doc;
2200
+
2201
+ if (op.updatedDisplay) postUpdateDisplay(cm, op.update);
2202
+
2203
+ // Abort mouse wheel delta measurement, when scrolling explicitly
2204
+ if (display.wheelStartX != null && (op.scrollTop != null || op.scrollLeft != null || op.scrollToPos))
2205
+ display.wheelStartX = display.wheelStartY = null;
2206
+
2207
+ // Propagate the scroll position to the actual DOM scroller
2208
+ if (op.scrollTop != null && (display.scroller.scrollTop != op.scrollTop || op.forceScroll)) {
2209
+ doc.scrollTop = Math.max(0, Math.min(display.scroller.scrollHeight - display.scroller.clientHeight, op.scrollTop));
2210
+ display.scrollbars.setScrollTop(doc.scrollTop);
2211
+ display.scroller.scrollTop = doc.scrollTop;
2212
+ }
2213
+ if (op.scrollLeft != null && (display.scroller.scrollLeft != op.scrollLeft || op.forceScroll)) {
2214
+ doc.scrollLeft = Math.max(0, Math.min(display.scroller.scrollWidth - displayWidth(cm), op.scrollLeft));
2215
+ display.scrollbars.setScrollLeft(doc.scrollLeft);
2216
+ display.scroller.scrollLeft = doc.scrollLeft;
2217
+ alignHorizontally(cm);
2218
+ }
2219
+ // If we need to scroll a specific position into view, do so.
2220
+ if (op.scrollToPos) {
2221
+ var coords = scrollPosIntoView(cm, clipPos(doc, op.scrollToPos.from),
2222
+ clipPos(doc, op.scrollToPos.to), op.scrollToPos.margin);
2223
+ if (op.scrollToPos.isCursor && cm.state.focused) maybeScrollWindow(cm, coords);
2224
+ }
2225
+
2226
+ // Fire events for markers that are hidden/unidden by editing or
2227
+ // undoing
2228
+ var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers;
2229
+ if (hidden) for (var i = 0; i < hidden.length; ++i)
2230
+ if (!hidden[i].lines.length) signal(hidden[i], "hide");
2231
+ if (unhidden) for (var i = 0; i < unhidden.length; ++i)
2232
+ if (unhidden[i].lines.length) signal(unhidden[i], "unhide");
2233
+
2234
+ if (display.wrapper.offsetHeight)
2235
+ doc.scrollTop = cm.display.scroller.scrollTop;
2236
+
2237
+ // Fire change events, and delayed event handlers
2238
+ if (op.changeObjs)
2239
+ signal(cm, "changes", cm, op.changeObjs);
2240
+ }
2241
+
2242
+ // Run the given function in an operation
2243
+ function runInOp(cm, f) {
2244
+ if (cm.curOp) return f();
2245
+ startOperation(cm);
2246
+ try { return f(); }
2247
+ finally { endOperation(cm); }
2248
+ }
2249
+ // Wraps a function in an operation. Returns the wrapped function.
2250
+ function operation(cm, f) {
2251
+ return function() {
2252
+ if (cm.curOp) return f.apply(cm, arguments);
2253
+ startOperation(cm);
2254
+ try { return f.apply(cm, arguments); }
2255
+ finally { endOperation(cm); }
2256
+ };
2257
+ }
2258
+ // Used to add methods to editor and doc instances, wrapping them in
2259
+ // operations.
2260
+ function methodOp(f) {
2261
+ return function() {
2262
+ if (this.curOp) return f.apply(this, arguments);
2263
+ startOperation(this);
2264
+ try { return f.apply(this, arguments); }
2265
+ finally { endOperation(this); }
2266
+ };
2267
+ }
2268
+ function docMethodOp(f) {
2269
+ return function() {
2270
+ var cm = this.cm;
2271
+ if (!cm || cm.curOp) return f.apply(this, arguments);
2272
+ startOperation(cm);
2273
+ try { return f.apply(this, arguments); }
2274
+ finally { endOperation(cm); }
2275
+ };
2276
+ }
2277
+
2278
+ // VIEW TRACKING
2279
+
2280
+ // These objects are used to represent the visible (currently drawn)
2281
+ // part of the document. A LineView may correspond to multiple
2282
+ // logical lines, if those are connected by collapsed ranges.
2283
+ function LineView(doc, line, lineN) {
2284
+ // The starting line
2285
+ this.line = line;
2286
+ // Continuing lines, if any
2287
+ this.rest = visualLineContinued(line);
2288
+ // Number of logical lines in this visual line
2289
+ this.size = this.rest ? lineNo(lst(this.rest)) - lineN + 1 : 1;
2290
+ this.node = this.text = null;
2291
+ this.hidden = lineIsHidden(doc, line);
2292
+ }
2293
+
2294
+ // Create a range of LineView objects for the given lines.
2295
+ function buildViewArray(cm, from, to) {
2296
+ var array = [], nextPos;
2297
+ for (var pos = from; pos < to; pos = nextPos) {
2298
+ var view = new LineView(cm.doc, getLine(cm.doc, pos), pos);
2299
+ nextPos = pos + view.size;
2300
+ array.push(view);
2301
+ }
2302
+ return array;
2303
+ }
2304
+
2305
+ // Updates the display.view data structure for a given change to the
2306
+ // document. From and to are in pre-change coordinates. Lendiff is
2307
+ // the amount of lines added or subtracted by the change. This is
2308
+ // used for changes that span multiple lines, or change the way
2309
+ // lines are divided into visual lines. regLineChange (below)
2310
+ // registers single-line changes.
2311
+ function regChange(cm, from, to, lendiff) {
2312
+ if (from == null) from = cm.doc.first;
2313
+ if (to == null) to = cm.doc.first + cm.doc.size;
2314
+ if (!lendiff) lendiff = 0;
2315
+
2316
+ var display = cm.display;
2317
+ if (lendiff && to < display.viewTo &&
2318
+ (display.updateLineNumbers == null || display.updateLineNumbers > from))
2319
+ display.updateLineNumbers = from;
2320
+
2321
+ cm.curOp.viewChanged = true;
2322
+
2323
+ if (from >= display.viewTo) { // Change after
2324
+ if (sawCollapsedSpans && visualLineNo(cm.doc, from) < display.viewTo)
2325
+ resetView(cm);
2326
+ } else if (to <= display.viewFrom) { // Change before
2327
+ if (sawCollapsedSpans && visualLineEndNo(cm.doc, to + lendiff) > display.viewFrom) {
2328
+ resetView(cm);
2329
+ } else {
2330
+ display.viewFrom += lendiff;
2331
+ display.viewTo += lendiff;
2332
+ }
2333
+ } else if (from <= display.viewFrom && to >= display.viewTo) { // Full overlap
2334
+ resetView(cm);
2335
+ } else if (from <= display.viewFrom) { // Top overlap
2336
+ var cut = viewCuttingPoint(cm, to, to + lendiff, 1);
2337
+ if (cut) {
2338
+ display.view = display.view.slice(cut.index);
2339
+ display.viewFrom = cut.lineN;
2340
+ display.viewTo += lendiff;
2341
+ } else {
2342
+ resetView(cm);
2343
+ }
2344
+ } else if (to >= display.viewTo) { // Bottom overlap
2345
+ var cut = viewCuttingPoint(cm, from, from, -1);
2346
+ if (cut) {
2347
+ display.view = display.view.slice(0, cut.index);
2348
+ display.viewTo = cut.lineN;
2349
+ } else {
2350
+ resetView(cm);
2351
+ }
2352
+ } else { // Gap in the middle
2353
+ var cutTop = viewCuttingPoint(cm, from, from, -1);
2354
+ var cutBot = viewCuttingPoint(cm, to, to + lendiff, 1);
2355
+ if (cutTop && cutBot) {
2356
+ display.view = display.view.slice(0, cutTop.index)
2357
+ .concat(buildViewArray(cm, cutTop.lineN, cutBot.lineN))
2358
+ .concat(display.view.slice(cutBot.index));
2359
+ display.viewTo += lendiff;
2360
+ } else {
2361
+ resetView(cm);
2362
+ }
2363
+ }
2364
+
2365
+ var ext = display.externalMeasured;
2366
+ if (ext) {
2367
+ if (to < ext.lineN)
2368
+ ext.lineN += lendiff;
2369
+ else if (from < ext.lineN + ext.size)
2370
+ display.externalMeasured = null;
2371
+ }
2372
+ }
2373
+
2374
+ // Register a change to a single line. Type must be one of "text",
2375
+ // "gutter", "class", "widget"
2376
+ function regLineChange(cm, line, type) {
2377
+ cm.curOp.viewChanged = true;
2378
+ var display = cm.display, ext = cm.display.externalMeasured;
2379
+ if (ext && line >= ext.lineN && line < ext.lineN + ext.size)
2380
+ display.externalMeasured = null;
2381
+
2382
+ if (line < display.viewFrom || line >= display.viewTo) return;
2383
+ var lineView = display.view[findViewIndex(cm, line)];
2384
+ if (lineView.node == null) return;
2385
+ var arr = lineView.changes || (lineView.changes = []);
2386
+ if (indexOf(arr, type) == -1) arr.push(type);
2387
+ }
2388
+
2389
+ // Clear the view.
2390
+ function resetView(cm) {
2391
+ cm.display.viewFrom = cm.display.viewTo = cm.doc.first;
2392
+ cm.display.view = [];
2393
+ cm.display.viewOffset = 0;
2394
+ }
2395
+
2396
+ // Find the view element corresponding to a given line. Return null
2397
+ // when the line isn't visible.
2398
+ function findViewIndex(cm, n) {
2399
+ if (n >= cm.display.viewTo) return null;
2400
+ n -= cm.display.viewFrom;
2401
+ if (n < 0) return null;
2402
+ var view = cm.display.view;
2403
+ for (var i = 0; i < view.length; i++) {
2404
+ n -= view[i].size;
2405
+ if (n < 0) return i;
2406
+ }
2407
+ }
2408
+
2409
+ function viewCuttingPoint(cm, oldN, newN, dir) {
2410
+ var index = findViewIndex(cm, oldN), diff, view = cm.display.view;
2411
+ if (!sawCollapsedSpans || newN == cm.doc.first + cm.doc.size)
2412
+ return {index: index, lineN: newN};
2413
+ for (var i = 0, n = cm.display.viewFrom; i < index; i++)
2414
+ n += view[i].size;
2415
+ if (n != oldN) {
2416
+ if (dir > 0) {
2417
+ if (index == view.length - 1) return null;
2418
+ diff = (n + view[index].size) - oldN;
2419
+ index++;
2420
+ } else {
2421
+ diff = n - oldN;
2422
+ }
2423
+ oldN += diff; newN += diff;
2424
+ }
2425
+ while (visualLineNo(cm.doc, newN) != newN) {
2426
+ if (index == (dir < 0 ? 0 : view.length - 1)) return null;
2427
+ newN += dir * view[index - (dir < 0 ? 1 : 0)].size;
2428
+ index += dir;
2429
+ }
2430
+ return {index: index, lineN: newN};
2431
+ }
2432
+
2433
+ // Force the view to cover a given range, adding empty view element
2434
+ // or clipping off existing ones as needed.
2435
+ function adjustView(cm, from, to) {
2436
+ var display = cm.display, view = display.view;
2437
+ if (view.length == 0 || from >= display.viewTo || to <= display.viewFrom) {
2438
+ display.view = buildViewArray(cm, from, to);
2439
+ display.viewFrom = from;
2440
+ } else {
2441
+ if (display.viewFrom > from)
2442
+ display.view = buildViewArray(cm, from, display.viewFrom).concat(display.view);
2443
+ else if (display.viewFrom < from)
2444
+ display.view = display.view.slice(findViewIndex(cm, from));
2445
+ display.viewFrom = from;
2446
+ if (display.viewTo < to)
2447
+ display.view = display.view.concat(buildViewArray(cm, display.viewTo, to));
2448
+ else if (display.viewTo > to)
2449
+ display.view = display.view.slice(0, findViewIndex(cm, to));
2450
+ }
2451
+ display.viewTo = to;
2452
+ }
2453
+
2454
+ // Count the number of lines in the view whose DOM representation is
2455
+ // out of date (or nonexistent).
2456
+ function countDirtyView(cm) {
2457
+ var view = cm.display.view, dirty = 0;
2458
+ for (var i = 0; i < view.length; i++) {
2459
+ var lineView = view[i];
2460
+ if (!lineView.hidden && (!lineView.node || lineView.changes)) ++dirty;
2461
+ }
2462
+ return dirty;
2463
+ }
2464
+
2465
+ // INPUT HANDLING
2466
+
2467
+ // Poll for input changes, using the normal rate of polling. This
2468
+ // runs as long as the editor is focused.
2469
+ function slowPoll(cm) {
2470
+ if (cm.display.pollingFast) return;
2471
+ cm.display.poll.set(cm.options.pollInterval, function() {
2472
+ readInput(cm);
2473
+ if (cm.state.focused) slowPoll(cm);
2474
+ });
2475
+ }
2476
+
2477
+ // When an event has just come in that is likely to add or change
2478
+ // something in the input textarea, we poll faster, to ensure that
2479
+ // the change appears on the screen quickly.
2480
+ function fastPoll(cm) {
2481
+ var missed = false;
2482
+ cm.display.pollingFast = true;
2483
+ function p() {
2484
+ var changed = readInput(cm);
2485
+ if (!changed && !missed) {missed = true; cm.display.poll.set(60, p);}
2486
+ else {cm.display.pollingFast = false; slowPoll(cm);}
2487
+ }
2488
+ cm.display.poll.set(20, p);
2489
+ }
2490
+
2491
+ // This will be set to an array of strings when copying, so that,
2492
+ // when pasting, we know what kind of selections the copied text
2493
+ // was made out of.
2494
+ var lastCopied = null;
2495
+
2496
+ // Read input from the textarea, and update the document to match.
2497
+ // When something is selected, it is present in the textarea, and
2498
+ // selected (unless it is huge, in which case a placeholder is
2499
+ // used). When nothing is selected, the cursor sits after previously
2500
+ // seen text (can be empty), which is stored in prevInput (we must
2501
+ // not reset the textarea when typing, because that breaks IME).
2502
+ function readInput(cm) {
2503
+ var input = cm.display.input, prevInput = cm.display.prevInput, doc = cm.doc;
2504
+ // Since this is called a *lot*, try to bail out as cheaply as
2505
+ // possible when it is clear that nothing happened. hasSelection
2506
+ // will be the case when there is a lot of text in the textarea,
2507
+ // in which case reading its value would be expensive.
2508
+ if (!cm.state.focused || (hasSelection(input) && !prevInput) || isReadOnly(cm) || cm.options.disableInput || cm.state.keySeq)
2509
+ return false;
2510
+ // See paste handler for more on the fakedLastChar kludge
2511
+ if (cm.state.pasteIncoming && cm.state.fakedLastChar) {
2512
+ input.value = input.value.substring(0, input.value.length - 1);
2513
+ cm.state.fakedLastChar = false;
2514
+ }
2515
+ var text = input.value;
2516
+ // If nothing changed, bail.
2517
+ if (text == prevInput && !cm.somethingSelected()) return false;
2518
+ // Work around nonsensical selection resetting in IE9/10, and
2519
+ // inexplicable appearance of private area unicode characters on
2520
+ // some key combos in Mac (#2689).
2521
+ if (ie && ie_version >= 9 && cm.display.inputHasSelection === text ||
2522
+ mac && /[\uf700-\uf7ff]/.test(text)) {
2523
+ resetInput(cm);
2524
+ return false;
2525
+ }
2526
+
2527
+ var withOp = !cm.curOp;
2528
+ if (withOp) startOperation(cm);
2529
+ cm.display.shift = false;
2530
+
2531
+ if (text.charCodeAt(0) == 0x200b && doc.sel == cm.display.selForContextMenu && !prevInput)
2532
+ prevInput = "\u200b";
2533
+ // Find the part of the input that is actually new
2534
+ var same = 0, l = Math.min(prevInput.length, text.length);
2535
+ while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) ++same;
2536
+ var inserted = text.slice(same), textLines = splitLines(inserted);
2537
+
2538
+ // When pasing N lines into N selections, insert one line per selection
2539
+ var multiPaste = null;
2540
+ if (cm.state.pasteIncoming && doc.sel.ranges.length > 1) {
2541
+ if (lastCopied && lastCopied.join("\n") == inserted)
2542
+ multiPaste = doc.sel.ranges.length % lastCopied.length == 0 && map(lastCopied, splitLines);
2543
+ else if (textLines.length == doc.sel.ranges.length)
2544
+ multiPaste = map(textLines, function(l) { return [l]; });
2545
+ }
2546
+
2547
+ // Normal behavior is to insert the new text into every selection
2548
+ for (var i = doc.sel.ranges.length - 1; i >= 0; i--) {
2549
+ var range = doc.sel.ranges[i];
2550
+ var from = range.from(), to = range.to();
2551
+ // Handle deletion
2552
+ if (same < prevInput.length)
2553
+ from = Pos(from.line, from.ch - (prevInput.length - same));
2554
+ // Handle overwrite
2555
+ else if (cm.state.overwrite && range.empty() && !cm.state.pasteIncoming)
2556
+ to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + lst(textLines).length));
2557
+ var updateInput = cm.curOp.updateInput;
2558
+ var changeEvent = {from: from, to: to, text: multiPaste ? multiPaste[i % multiPaste.length] : textLines,
2559
+ origin: cm.state.pasteIncoming ? "paste" : cm.state.cutIncoming ? "cut" : "+input"};
2560
+ makeChange(cm.doc, changeEvent);
2561
+ signalLater(cm, "inputRead", cm, changeEvent);
2562
+ // When an 'electric' character is inserted, immediately trigger a reindent
2563
+ if (inserted && !cm.state.pasteIncoming && cm.options.electricChars &&
2564
+ cm.options.smartIndent && range.head.ch < 100 &&
2565
+ (!i || doc.sel.ranges[i - 1].head.line != range.head.line)) {
2566
+ var mode = cm.getModeAt(range.head);
2567
+ var end = changeEnd(changeEvent);
2568
+ if (mode.electricChars) {
2569
+ for (var j = 0; j < mode.electricChars.length; j++)
2570
+ if (inserted.indexOf(mode.electricChars.charAt(j)) > -1) {
2571
+ indentLine(cm, end.line, "smart");
2572
+ break;
2573
+ }
2574
+ } else if (mode.electricInput) {
2575
+ if (mode.electricInput.test(getLine(doc, end.line).text.slice(0, end.ch)))
2576
+ indentLine(cm, end.line, "smart");
2577
+ }
2578
+ }
2579
+ }
2580
+ ensureCursorVisible(cm);
2581
+ cm.curOp.updateInput = updateInput;
2582
+ cm.curOp.typing = true;
2583
+
2584
+ // Don't leave long text in the textarea, since it makes further polling slow
2585
+ if (text.length > 1000 || text.indexOf("\n") > -1) input.value = cm.display.prevInput = "";
2586
+ else cm.display.prevInput = text;
2587
+ if (withOp) endOperation(cm);
2588
+ cm.state.pasteIncoming = cm.state.cutIncoming = false;
2589
+ return true;
2590
+ }
2591
+
2592
+ // Reset the input to correspond to the selection (or to be empty,
2593
+ // when not typing and nothing is selected)
2594
+ function resetInput(cm, typing) {
2595
+ if (cm.display.contextMenuPending) return;
2596
+ var minimal, selected, doc = cm.doc;
2597
+ if (cm.somethingSelected()) {
2598
+ cm.display.prevInput = "";
2599
+ var range = doc.sel.primary();
2600
+ minimal = hasCopyEvent &&
2601
+ (range.to().line - range.from().line > 100 || (selected = cm.getSelection()).length > 1000);
2602
+ var content = minimal ? "-" : selected || cm.getSelection();
2603
+ cm.display.input.value = content;
2604
+ if (cm.state.focused) selectInput(cm.display.input);
2605
+ if (ie && ie_version >= 9) cm.display.inputHasSelection = content;
2606
+ } else if (!typing) {
2607
+ cm.display.prevInput = cm.display.input.value = "";
2608
+ if (ie && ie_version >= 9) cm.display.inputHasSelection = null;
2609
+ }
2610
+ cm.display.inaccurateSelection = minimal;
2611
+ }
2612
+
2613
+ function focusInput(cm) {
2614
+ if (cm.options.readOnly != "nocursor" && (!mobile || activeElt() != cm.display.input))
2615
+ cm.display.input.focus();
2616
+ }
2617
+
2618
+ function ensureFocus(cm) {
2619
+ if (!cm.state.focused) { focusInput(cm); onFocus(cm); }
2620
+ }
2621
+
2622
+ function isReadOnly(cm) {
2623
+ return cm.options.readOnly || cm.doc.cantEdit;
2624
+ }
2625
+
2626
+ // EVENT HANDLERS
2627
+
2628
+ // Attach the necessary event handlers when initializing the editor
2629
+ function registerEventHandlers(cm) {
2630
+ var d = cm.display;
2631
+ on(d.scroller, "mousedown", operation(cm, onMouseDown));
2632
+ // Older IE's will not fire a second mousedown for a double click
2633
+ if (ie && ie_version < 11)
2634
+ on(d.scroller, "dblclick", operation(cm, function(e) {
2635
+ if (signalDOMEvent(cm, e)) return;
2636
+ var pos = posFromMouse(cm, e);
2637
+ if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) return;
2638
+ e_preventDefault(e);
2639
+ var word = cm.findWordAt(pos);
2640
+ extendSelection(cm.doc, word.anchor, word.head);
2641
+ }));
2642
+ else
2643
+ on(d.scroller, "dblclick", function(e) { signalDOMEvent(cm, e) || e_preventDefault(e); });
2644
+ // Prevent normal selection in the editor (we handle our own)
2645
+ on(d.lineSpace, "selectstart", function(e) {
2646
+ if (!eventInWidget(d, e)) e_preventDefault(e);
2647
+ });
2648
+ // Some browsers fire contextmenu *after* opening the menu, at
2649
+ // which point we can't mess with it anymore. Context menu is
2650
+ // handled in onMouseDown for these browsers.
2651
+ if (!captureRightClick) on(d.scroller, "contextmenu", function(e) {onContextMenu(cm, e);});
2652
+
2653
+ // Sync scrolling between fake scrollbars and real scrollable
2654
+ // area, ensure viewport is updated when scrolling.
2655
+ on(d.scroller, "scroll", function() {
2656
+ if (d.scroller.clientHeight) {
2657
+ setScrollTop(cm, d.scroller.scrollTop);
2658
+ setScrollLeft(cm, d.scroller.scrollLeft, true);
2659
+ signal(cm, "scroll", cm);
2660
+ }
2661
+ });
2662
+
2663
+ // Listen to wheel events in order to try and update the viewport on time.
2664
+ on(d.scroller, "mousewheel", function(e){onScrollWheel(cm, e);});
2665
+ on(d.scroller, "DOMMouseScroll", function(e){onScrollWheel(cm, e);});
2666
+
2667
+ // Prevent wrapper from ever scrolling
2668
+ on(d.wrapper, "scroll", function() { d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; });
2669
+
2670
+ on(d.input, "keyup", function(e) { onKeyUp.call(cm, e); });
2671
+ on(d.input, "input", function() {
2672
+ if (ie && ie_version >= 9 && cm.display.inputHasSelection) cm.display.inputHasSelection = null;
2673
+ readInput(cm);
2674
+ });
2675
+ on(d.input, "keydown", operation(cm, onKeyDown));
2676
+ on(d.input, "keypress", operation(cm, onKeyPress));
2677
+ on(d.input, "focus", bind(onFocus, cm));
2678
+ on(d.input, "blur", bind(onBlur, cm));
2679
+
2680
+ function drag_(e) {
2681
+ if (!signalDOMEvent(cm, e)) e_stop(e);
2682
+ }
2683
+ if (cm.options.dragDrop) {
2684
+ on(d.scroller, "dragstart", function(e){onDragStart(cm, e);});
2685
+ on(d.scroller, "dragenter", drag_);
2686
+ on(d.scroller, "dragover", drag_);
2687
+ on(d.scroller, "drop", operation(cm, onDrop));
2688
+ }
2689
+ on(d.scroller, "paste", function(e) {
2690
+ if (eventInWidget(d, e)) return;
2691
+ cm.state.pasteIncoming = true;
2692
+ focusInput(cm);
2693
+ fastPoll(cm);
2694
+ });
2695
+ on(d.input, "paste", function() {
2696
+ // Workaround for webkit bug https://bugs.webkit.org/show_bug.cgi?id=90206
2697
+ // Add a char to the end of textarea before paste occur so that
2698
+ // selection doesn't span to the end of textarea.
2699
+ if (webkit && !cm.state.fakedLastChar && !(new Date - cm.state.lastMiddleDown < 200)) {
2700
+ var start = d.input.selectionStart, end = d.input.selectionEnd;
2701
+ d.input.value += "$";
2702
+ // The selection end needs to be set before the start, otherwise there
2703
+ // can be an intermediate non-empty selection between the two, which
2704
+ // can override the middle-click paste buffer on linux and cause the
2705
+ // wrong thing to get pasted.
2706
+ d.input.selectionEnd = end;
2707
+ d.input.selectionStart = start;
2708
+ cm.state.fakedLastChar = true;
2709
+ }
2710
+ cm.state.pasteIncoming = true;
2711
+ fastPoll(cm);
2712
+ });
2713
+
2714
+ function prepareCopyCut(e) {
2715
+ if (cm.somethingSelected()) {
2716
+ lastCopied = cm.getSelections();
2717
+ if (d.inaccurateSelection) {
2718
+ d.prevInput = "";
2719
+ d.inaccurateSelection = false;
2720
+ d.input.value = lastCopied.join("\n");
2721
+ selectInput(d.input);
2722
+ }
2723
+ } else {
2724
+ var text = [], ranges = [];
2725
+ for (var i = 0; i < cm.doc.sel.ranges.length; i++) {
2726
+ var line = cm.doc.sel.ranges[i].head.line;
2727
+ var lineRange = {anchor: Pos(line, 0), head: Pos(line + 1, 0)};
2728
+ ranges.push(lineRange);
2729
+ text.push(cm.getRange(lineRange.anchor, lineRange.head));
2730
+ }
2731
+ if (e.type == "cut") {
2732
+ cm.setSelections(ranges, null, sel_dontScroll);
2733
+ } else {
2734
+ d.prevInput = "";
2735
+ d.input.value = text.join("\n");
2736
+ selectInput(d.input);
2737
+ }
2738
+ lastCopied = text;
2739
+ }
2740
+ if (e.type == "cut") cm.state.cutIncoming = true;
2741
+ }
2742
+ on(d.input, "cut", prepareCopyCut);
2743
+ on(d.input, "copy", prepareCopyCut);
2744
+
2745
+ // Needed to handle Tab key in KHTML
2746
+ if (khtml) on(d.sizer, "mouseup", function() {
2747
+ if (activeElt() == d.input) d.input.blur();
2748
+ focusInput(cm);
2749
+ });
2750
+ }
2751
+
2752
+ // Called when the window resizes
2753
+ function onResize(cm) {
2754
+ var d = cm.display;
2755
+ if (d.lastWrapHeight == d.wrapper.clientHeight && d.lastWrapWidth == d.wrapper.clientWidth)
2756
+ return;
2757
+ // Might be a text scaling operation, clear size caches.
2758
+ d.cachedCharWidth = d.cachedTextHeight = d.cachedPaddingH = null;
2759
+ d.scrollbarsClipped = false;
2760
+ cm.setSize();
2761
+ }
2762
+
2763
+ // MOUSE EVENTS
2764
+
2765
+ // Return true when the given mouse event happened in a widget
2766
+ function eventInWidget(display, e) {
2767
+ for (var n = e_target(e); n != display.wrapper; n = n.parentNode) {
2768
+ if (!n || (n.nodeType == 1 && n.getAttribute("cm-ignore-events") == "true") ||
2769
+ (n.parentNode == display.sizer && n != display.mover))
2770
+ return true;
2771
+ }
2772
+ }
2773
+
2774
+ // Given a mouse event, find the corresponding position. If liberal
2775
+ // is false, it checks whether a gutter or scrollbar was clicked,
2776
+ // and returns null if it was. forRect is used by rectangular
2777
+ // selections, and tries to estimate a character position even for
2778
+ // coordinates beyond the right of the text.
2779
+ function posFromMouse(cm, e, liberal, forRect) {
2780
+ var display = cm.display;
2781
+ if (!liberal && e_target(e).getAttribute("not-content") == "true") return null;
2782
+
2783
+ var x, y, space = display.lineSpace.getBoundingClientRect();
2784
+ // Fails unpredictably on IE[67] when mouse is dragged around quickly.
2785
+ try { x = e.clientX - space.left; y = e.clientY - space.top; }
2786
+ catch (e) { return null; }
2787
+ var coords = coordsChar(cm, x, y), line;
2788
+ if (forRect && coords.xRel == 1 && (line = getLine(cm.doc, coords.line).text).length == coords.ch) {
2789
+ var colDiff = countColumn(line, line.length, cm.options.tabSize) - line.length;
2790
+ coords = Pos(coords.line, Math.max(0, Math.round((x - paddingH(cm.display).left) / charWidth(cm.display)) - colDiff));
2791
+ }
2792
+ return coords;
2793
+ }
2794
+
2795
+ // A mouse down can be a single click, double click, triple click,
2796
+ // start of selection drag, start of text drag, new cursor
2797
+ // (ctrl-click), rectangle drag (alt-drag), or xwin
2798
+ // middle-click-paste. Or it might be a click on something we should
2799
+ // not interfere with, such as a scrollbar or widget.
2800
+ function onMouseDown(e) {
2801
+ if (signalDOMEvent(this, e)) return;
2802
+ var cm = this, display = cm.display;
2803
+ display.shift = e.shiftKey;
2804
+
2805
+ if (eventInWidget(display, e)) {
2806
+ if (!webkit) {
2807
+ // Briefly turn off draggability, to allow widgets to do
2808
+ // normal dragging things.
2809
+ display.scroller.draggable = false;
2810
+ setTimeout(function(){display.scroller.draggable = true;}, 100);
2811
+ }
2812
+ return;
2813
+ }
2814
+ if (clickInGutter(cm, e)) return;
2815
+ var start = posFromMouse(cm, e);
2816
+ window.focus();
2817
+
2818
+ switch (e_button(e)) {
2819
+ case 1:
2820
+ if (start)
2821
+ leftButtonDown(cm, e, start);
2822
+ else if (e_target(e) == display.scroller)
2823
+ e_preventDefault(e);
2824
+ break;
2825
+ case 2:
2826
+ if (webkit) cm.state.lastMiddleDown = +new Date;
2827
+ if (start) extendSelection(cm.doc, start);
2828
+ setTimeout(bind(focusInput, cm), 20);
2829
+ e_preventDefault(e);
2830
+ break;
2831
+ case 3:
2832
+ if (captureRightClick) onContextMenu(cm, e);
2833
+ break;
2834
+ }
2835
+ }
2836
+
2837
+ var lastClick, lastDoubleClick;
2838
+ function leftButtonDown(cm, e, start) {
2839
+ setTimeout(bind(ensureFocus, cm), 0);
2840
+
2841
+ var now = +new Date, type;
2842
+ if (lastDoubleClick && lastDoubleClick.time > now - 400 && cmp(lastDoubleClick.pos, start) == 0) {
2843
+ type = "triple";
2844
+ } else if (lastClick && lastClick.time > now - 400 && cmp(lastClick.pos, start) == 0) {
2845
+ type = "double";
2846
+ lastDoubleClick = {time: now, pos: start};
2847
+ } else {
2848
+ type = "single";
2849
+ lastClick = {time: now, pos: start};
2850
+ }
2851
+
2852
+ var sel = cm.doc.sel, modifier = mac ? e.metaKey : e.ctrlKey, contained;
2853
+ if (cm.options.dragDrop && dragAndDrop && !isReadOnly(cm) &&
2854
+ type == "single" && (contained = sel.contains(start)) > -1 &&
2855
+ !sel.ranges[contained].empty())
2856
+ leftButtonStartDrag(cm, e, start, modifier);
2857
+ else
2858
+ leftButtonSelect(cm, e, start, type, modifier);
2859
+ }
2860
+
2861
+ // Start a text drag. When it ends, see if any dragging actually
2862
+ // happen, and treat as a click if it didn't.
2863
+ function leftButtonStartDrag(cm, e, start, modifier) {
2864
+ var display = cm.display;
2865
+ var dragEnd = operation(cm, function(e2) {
2866
+ if (webkit) display.scroller.draggable = false;
2867
+ cm.state.draggingText = false;
2868
+ off(document, "mouseup", dragEnd);
2869
+ off(display.scroller, "drop", dragEnd);
2870
+ if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) {
2871
+ e_preventDefault(e2);
2872
+ if (!modifier)
2873
+ extendSelection(cm.doc, start);
2874
+ focusInput(cm);
2875
+ // Work around unexplainable focus problem in IE9 (#2127)
2876
+ if (ie && ie_version == 9)
2877
+ setTimeout(function() {document.body.focus(); focusInput(cm);}, 20);
2878
+ }
2879
+ });
2880
+ // Let the drag handler handle this.
2881
+ if (webkit) display.scroller.draggable = true;
2882
+ cm.state.draggingText = dragEnd;
2883
+ // IE's approach to draggable
2884
+ if (display.scroller.dragDrop) display.scroller.dragDrop();
2885
+ on(document, "mouseup", dragEnd);
2886
+ on(display.scroller, "drop", dragEnd);
2887
+ }
2888
+
2889
+ // Normal selection, as opposed to text dragging.
2890
+ function leftButtonSelect(cm, e, start, type, addNew) {
2891
+ var display = cm.display, doc = cm.doc;
2892
+ e_preventDefault(e);
2893
+
2894
+ var ourRange, ourIndex, startSel = doc.sel, ranges = startSel.ranges;
2895
+ if (addNew && !e.shiftKey) {
2896
+ ourIndex = doc.sel.contains(start);
2897
+ if (ourIndex > -1)
2898
+ ourRange = ranges[ourIndex];
2899
+ else
2900
+ ourRange = new Range(start, start);
2901
+ } else {
2902
+ ourRange = doc.sel.primary();
2903
+ }
2904
+
2905
+ if (e.altKey) {
2906
+ type = "rect";
2907
+ if (!addNew) ourRange = new Range(start, start);
2908
+ start = posFromMouse(cm, e, true, true);
2909
+ ourIndex = -1;
2910
+ } else if (type == "double") {
2911
+ var word = cm.findWordAt(start);
2912
+ if (cm.display.shift || doc.extend)
2913
+ ourRange = extendRange(doc, ourRange, word.anchor, word.head);
2914
+ else
2915
+ ourRange = word;
2916
+ } else if (type == "triple") {
2917
+ var line = new Range(Pos(start.line, 0), clipPos(doc, Pos(start.line + 1, 0)));
2918
+ if (cm.display.shift || doc.extend)
2919
+ ourRange = extendRange(doc, ourRange, line.anchor, line.head);
2920
+ else
2921
+ ourRange = line;
2922
+ } else {
2923
+ ourRange = extendRange(doc, ourRange, start);
2924
+ }
2925
+
2926
+ if (!addNew) {
2927
+ ourIndex = 0;
2928
+ setSelection(doc, new Selection([ourRange], 0), sel_mouse);
2929
+ startSel = doc.sel;
2930
+ } else if (ourIndex == -1) {
2931
+ ourIndex = ranges.length;
2932
+ setSelection(doc, normalizeSelection(ranges.concat([ourRange]), ourIndex),
2933
+ {scroll: false, origin: "*mouse"});
2934
+ } else if (ranges.length > 1 && ranges[ourIndex].empty() && type == "single") {
2935
+ setSelection(doc, normalizeSelection(ranges.slice(0, ourIndex).concat(ranges.slice(ourIndex + 1)), 0));
2936
+ startSel = doc.sel;
2937
+ } else {
2938
+ replaceOneSelection(doc, ourIndex, ourRange, sel_mouse);
2939
+ }
2940
+
2941
+ var lastPos = start;
2942
+ function extendTo(pos) {
2943
+ if (cmp(lastPos, pos) == 0) return;
2944
+ lastPos = pos;
2945
+
2946
+ if (type == "rect") {
2947
+ var ranges = [], tabSize = cm.options.tabSize;
2948
+ var startCol = countColumn(getLine(doc, start.line).text, start.ch, tabSize);
2949
+ var posCol = countColumn(getLine(doc, pos.line).text, pos.ch, tabSize);
2950
+ var left = Math.min(startCol, posCol), right = Math.max(startCol, posCol);
2951
+ for (var line = Math.min(start.line, pos.line), end = Math.min(cm.lastLine(), Math.max(start.line, pos.line));
2952
+ line <= end; line++) {
2953
+ var text = getLine(doc, line).text, leftPos = findColumn(text, left, tabSize);
2954
+ if (left == right)
2955
+ ranges.push(new Range(Pos(line, leftPos), Pos(line, leftPos)));
2956
+ else if (text.length > leftPos)
2957
+ ranges.push(new Range(Pos(line, leftPos), Pos(line, findColumn(text, right, tabSize))));
2958
+ }
2959
+ if (!ranges.length) ranges.push(new Range(start, start));
2960
+ setSelection(doc, normalizeSelection(startSel.ranges.slice(0, ourIndex).concat(ranges), ourIndex),
2961
+ {origin: "*mouse", scroll: false});
2962
+ cm.scrollIntoView(pos);
2963
+ } else {
2964
+ var oldRange = ourRange;
2965
+ var anchor = oldRange.anchor, head = pos;
2966
+ if (type != "single") {
2967
+ if (type == "double")
2968
+ var range = cm.findWordAt(pos);
2969
+ else
2970
+ var range = new Range(Pos(pos.line, 0), clipPos(doc, Pos(pos.line + 1, 0)));
2971
+ if (cmp(range.anchor, anchor) > 0) {
2972
+ head = range.head;
2973
+ anchor = minPos(oldRange.from(), range.anchor);
2974
+ } else {
2975
+ head = range.anchor;
2976
+ anchor = maxPos(oldRange.to(), range.head);
2977
+ }
2978
+ }
2979
+ var ranges = startSel.ranges.slice(0);
2980
+ ranges[ourIndex] = new Range(clipPos(doc, anchor), head);
2981
+ setSelection(doc, normalizeSelection(ranges, ourIndex), sel_mouse);
2982
+ }
2983
+ }
2984
+
2985
+ var editorSize = display.wrapper.getBoundingClientRect();
2986
+ // Used to ensure timeout re-tries don't fire when another extend
2987
+ // happened in the meantime (clearTimeout isn't reliable -- at
2988
+ // least on Chrome, the timeouts still happen even when cleared,
2989
+ // if the clear happens after their scheduled firing time).
2990
+ var counter = 0;
2991
+
2992
+ function extend(e) {
2993
+ var curCount = ++counter;
2994
+ var cur = posFromMouse(cm, e, true, type == "rect");
2995
+ if (!cur) return;
2996
+ if (cmp(cur, lastPos) != 0) {
2997
+ ensureFocus(cm);
2998
+ extendTo(cur);
2999
+ var visible = visibleLines(display, doc);
3000
+ if (cur.line >= visible.to || cur.line < visible.from)
3001
+ setTimeout(operation(cm, function(){if (counter == curCount) extend(e);}), 150);
3002
+ } else {
3003
+ var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;
3004
+ if (outside) setTimeout(operation(cm, function() {
3005
+ if (counter != curCount) return;
3006
+ display.scroller.scrollTop += outside;
3007
+ extend(e);
3008
+ }), 50);
3009
+ }
3010
+ }
3011
+
3012
+ function done(e) {
3013
+ counter = Infinity;
3014
+ e_preventDefault(e);
3015
+ focusInput(cm);
3016
+ off(document, "mousemove", move);
3017
+ off(document, "mouseup", up);
3018
+ doc.history.lastSelOrigin = null;
3019
+ }
3020
+
3021
+ var move = operation(cm, function(e) {
3022
+ if (!e_button(e)) done(e);
3023
+ else extend(e);
3024
+ });
3025
+ var up = operation(cm, done);
3026
+ on(document, "mousemove", move);
3027
+ on(document, "mouseup", up);
3028
+ }
3029
+
3030
+ // Determines whether an event happened in the gutter, and fires the
3031
+ // handlers for the corresponding event.
3032
+ function gutterEvent(cm, e, type, prevent, signalfn) {
3033
+ try { var mX = e.clientX, mY = e.clientY; }
3034
+ catch(e) { return false; }
3035
+ if (mX >= Math.floor(cm.display.gutters.getBoundingClientRect().right)) return false;
3036
+ if (prevent) e_preventDefault(e);
3037
+
3038
+ var display = cm.display;
3039
+ var lineBox = display.lineDiv.getBoundingClientRect();
3040
+
3041
+ if (mY > lineBox.bottom || !hasHandler(cm, type)) return e_defaultPrevented(e);
3042
+ mY -= lineBox.top - display.viewOffset;
3043
+
3044
+ for (var i = 0; i < cm.options.gutters.length; ++i) {
3045
+ var g = display.gutters.childNodes[i];
3046
+ if (g && g.getBoundingClientRect().right >= mX) {
3047
+ var line = lineAtHeight(cm.doc, mY);
3048
+ var gutter = cm.options.gutters[i];
3049
+ signalfn(cm, type, cm, line, gutter, e);
3050
+ return e_defaultPrevented(e);
3051
+ }
3052
+ }
3053
+ }
3054
+
3055
+ function clickInGutter(cm, e) {
3056
+ return gutterEvent(cm, e, "gutterClick", true, signalLater);
3057
+ }
3058
+
3059
+ // Kludge to work around strange IE behavior where it'll sometimes
3060
+ // re-fire a series of drag-related events right after the drop (#1551)
3061
+ var lastDrop = 0;
3062
+
3063
+ function onDrop(e) {
3064
+ var cm = this;
3065
+ if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e))
3066
+ return;
3067
+ e_preventDefault(e);
3068
+ if (ie) lastDrop = +new Date;
3069
+ var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
3070
+ if (!pos || isReadOnly(cm)) return;
3071
+ // Might be a file drop, in which case we simply extract the text
3072
+ // and insert it.
3073
+ if (files && files.length && window.FileReader && window.File) {
3074
+ var n = files.length, text = Array(n), read = 0;
3075
+ var loadFile = function(file, i) {
3076
+ var reader = new FileReader;
3077
+ reader.onload = operation(cm, function() {
3078
+ text[i] = reader.result;
3079
+ if (++read == n) {
3080
+ pos = clipPos(cm.doc, pos);
3081
+ var change = {from: pos, to: pos, text: splitLines(text.join("\n")), origin: "paste"};
3082
+ makeChange(cm.doc, change);
3083
+ setSelectionReplaceHistory(cm.doc, simpleSelection(pos, changeEnd(change)));
3084
+ }
3085
+ });
3086
+ reader.readAsText(file);
3087
+ };
3088
+ for (var i = 0; i < n; ++i) loadFile(files[i], i);
3089
+ } else { // Normal drop
3090
+ // Don't do a replace if the drop happened inside of the selected text.
3091
+ if (cm.state.draggingText && cm.doc.sel.contains(pos) > -1) {
3092
+ cm.state.draggingText(e);
3093
+ // Ensure the editor is re-focused
3094
+ setTimeout(bind(focusInput, cm), 20);
3095
+ return;
3096
+ }
3097
+ try {
3098
+ var text = e.dataTransfer.getData("Text");
3099
+ if (text) {
3100
+ if (cm.state.draggingText && !(mac ? e.metaKey : e.ctrlKey))
3101
+ var selected = cm.listSelections();
3102
+ setSelectionNoUndo(cm.doc, simpleSelection(pos, pos));
3103
+ if (selected) for (var i = 0; i < selected.length; ++i)
3104
+ replaceRange(cm.doc, "", selected[i].anchor, selected[i].head, "drag");
3105
+ cm.replaceSelection(text, "around", "paste");
3106
+ focusInput(cm);
3107
+ }
3108
+ }
3109
+ catch(e){}
3110
+ }
3111
+ }
3112
+
3113
+ function onDragStart(cm, e) {
3114
+ if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return; }
3115
+ if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) return;
3116
+
3117
+ e.dataTransfer.setData("Text", cm.getSelection());
3118
+
3119
+ // Use dummy image instead of default browsers image.
3120
+ // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
3121
+ if (e.dataTransfer.setDragImage && !safari) {
3122
+ var img = elt("img", null, null, "position: fixed; left: 0; top: 0;");
3123
+ img.src = "data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==";
3124
+ if (presto) {
3125
+ img.width = img.height = 1;
3126
+ cm.display.wrapper.appendChild(img);
3127
+ // Force a relayout, or Opera won't use our image for some obscure reason
3128
+ img._top = img.offsetTop;
3129
+ }
3130
+ e.dataTransfer.setDragImage(img, 0, 0);
3131
+ if (presto) img.parentNode.removeChild(img);
3132
+ }
3133
+ }
3134
+
3135
+ // SCROLL EVENTS
3136
+
3137
+ // Sync the scrollable area and scrollbars, ensure the viewport
3138
+ // covers the visible area.
3139
+ function setScrollTop(cm, val) {
3140
+ if (Math.abs(cm.doc.scrollTop - val) < 2) return;
3141
+ cm.doc.scrollTop = val;
3142
+ if (!gecko) updateDisplaySimple(cm, {top: val});
3143
+ if (cm.display.scroller.scrollTop != val) cm.display.scroller.scrollTop = val;
3144
+ cm.display.scrollbars.setScrollTop(val);
3145
+ if (gecko) updateDisplaySimple(cm);
3146
+ startWorker(cm, 100);
3147
+ }
3148
+ // Sync scroller and scrollbar, ensure the gutter elements are
3149
+ // aligned.
3150
+ function setScrollLeft(cm, val, isScroller) {
3151
+ if (isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) return;
3152
+ val = Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth);
3153
+ cm.doc.scrollLeft = val;
3154
+ alignHorizontally(cm);
3155
+ if (cm.display.scroller.scrollLeft != val) cm.display.scroller.scrollLeft = val;
3156
+ cm.display.scrollbars.setScrollLeft(val);
3157
+ }
3158
+
3159
+ // Since the delta values reported on mouse wheel events are
3160
+ // unstandardized between browsers and even browser versions, and
3161
+ // generally horribly unpredictable, this code starts by measuring
3162
+ // the scroll effect that the first few mouse wheel events have,
3163
+ // and, from that, detects the way it can convert deltas to pixel
3164
+ // offsets afterwards.
3165
+ //
3166
+ // The reason we want to know the amount a wheel event will scroll
3167
+ // is that it gives us a chance to update the display before the
3168
+ // actual scrolling happens, reducing flickering.
3169
+
3170
+ var wheelSamples = 0, wheelPixelsPerUnit = null;
3171
+ // Fill in a browser-detected starting value on browsers where we
3172
+ // know one. These don't have to be accurate -- the result of them
3173
+ // being wrong would just be a slight flicker on the first wheel
3174
+ // scroll (if it is large enough).
3175
+ if (ie) wheelPixelsPerUnit = -.53;
3176
+ else if (gecko) wheelPixelsPerUnit = 15;
3177
+ else if (chrome) wheelPixelsPerUnit = -.7;
3178
+ else if (safari) wheelPixelsPerUnit = -1/3;
3179
+
3180
+ var wheelEventDelta = function(e) {
3181
+ var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
3182
+ if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) dx = e.detail;
3183
+ if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) dy = e.detail;
3184
+ else if (dy == null) dy = e.wheelDelta;
3185
+ return {x: dx, y: dy};
3186
+ };
3187
+ CodeMirror.wheelEventPixels = function(e) {
3188
+ var delta = wheelEventDelta(e);
3189
+ delta.x *= wheelPixelsPerUnit;
3190
+ delta.y *= wheelPixelsPerUnit;
3191
+ return delta;
3192
+ };
3193
+
3194
+ function onScrollWheel(cm, e) {
3195
+ var delta = wheelEventDelta(e), dx = delta.x, dy = delta.y;
3196
+
3197
+ var display = cm.display, scroll = display.scroller;
3198
+ // Quit if there's nothing to scroll here
3199
+ if (!(dx && scroll.scrollWidth > scroll.clientWidth ||
3200
+ dy && scroll.scrollHeight > scroll.clientHeight)) return;
3201
+
3202
+ // Webkit browsers on OS X abort momentum scrolls when the target
3203
+ // of the scroll event is removed from the scrollable element.
3204
+ // This hack (see related code in patchDisplay) makes sure the
3205
+ // element is kept around.
3206
+ if (dy && mac && webkit) {
3207
+ outer: for (var cur = e.target, view = display.view; cur != scroll; cur = cur.parentNode) {
3208
+ for (var i = 0; i < view.length; i++) {
3209
+ if (view[i].node == cur) {
3210
+ cm.display.currentWheelTarget = cur;
3211
+ break outer;
3212
+ }
3213
+ }
3214
+ }
3215
+ }
3216
+
3217
+ // On some browsers, horizontal scrolling will cause redraws to
3218
+ // happen before the gutter has been realigned, causing it to
3219
+ // wriggle around in a most unseemly way. When we have an
3220
+ // estimated pixels/delta value, we just handle horizontal
3221
+ // scrolling entirely here. It'll be slightly off from native, but
3222
+ // better than glitching out.
3223
+ if (dx && !gecko && !presto && wheelPixelsPerUnit != null) {
3224
+ if (dy)
3225
+ setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight)));
3226
+ setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth)));
3227
+ e_preventDefault(e);
3228
+ display.wheelStartX = null; // Abort measurement, if in progress
3229
+ return;
3230
+ }
3231
+
3232
+ // 'Project' the visible viewport to cover the area that is being
3233
+ // scrolled into view (if we know enough to estimate it).
3234
+ if (dy && wheelPixelsPerUnit != null) {
3235
+ var pixels = dy * wheelPixelsPerUnit;
3236
+ var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight;
3237
+ if (pixels < 0) top = Math.max(0, top + pixels - 50);
3238
+ else bot = Math.min(cm.doc.height, bot + pixels + 50);
3239
+ updateDisplaySimple(cm, {top: top, bottom: bot});
3240
+ }
3241
+
3242
+ if (wheelSamples < 20) {
3243
+ if (display.wheelStartX == null) {
3244
+ display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop;
3245
+ display.wheelDX = dx; display.wheelDY = dy;
3246
+ setTimeout(function() {
3247
+ if (display.wheelStartX == null) return;
3248
+ var movedX = scroll.scrollLeft - display.wheelStartX;
3249
+ var movedY = scroll.scrollTop - display.wheelStartY;
3250
+ var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
3251
+ (movedX && display.wheelDX && movedX / display.wheelDX);
3252
+ display.wheelStartX = display.wheelStartY = null;
3253
+ if (!sample) return;
3254
+ wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
3255
+ ++wheelSamples;
3256
+ }, 200);
3257
+ } else {
3258
+ display.wheelDX += dx; display.wheelDY += dy;
3259
+ }
3260
+ }
3261
+ }
3262
+
3263
+ // KEY EVENTS
3264
+
3265
+ // Run a handler that was bound to a key.
3266
+ function doHandleBinding(cm, bound, dropShift) {
3267
+ if (typeof bound == "string") {
3268
+ bound = commands[bound];
3269
+ if (!bound) return false;
3270
+ }
3271
+ // Ensure previous input has been read, so that the handler sees a
3272
+ // consistent view of the document
3273
+ if (cm.display.pollingFast && readInput(cm)) cm.display.pollingFast = false;
3274
+ var prevShift = cm.display.shift, done = false;
3275
+ try {
3276
+ if (isReadOnly(cm)) cm.state.suppressEdits = true;
3277
+ if (dropShift) cm.display.shift = false;
3278
+ done = bound(cm) != Pass;
3279
+ } finally {
3280
+ cm.display.shift = prevShift;
3281
+ cm.state.suppressEdits = false;
3282
+ }
3283
+ return done;
3284
+ }
3285
+
3286
+ function lookupKeyForEditor(cm, name, handle) {
3287
+ for (var i = 0; i < cm.state.keyMaps.length; i++) {
3288
+ var result = lookupKey(name, cm.state.keyMaps[i], handle, cm);
3289
+ if (result) return result;
3290
+ }
3291
+ return (cm.options.extraKeys && lookupKey(name, cm.options.extraKeys, handle, cm))
3292
+ || lookupKey(name, cm.options.keyMap, handle, cm);
3293
+ }
3294
+
3295
+ var stopSeq = new Delayed;
3296
+ function dispatchKey(cm, name, e, handle) {
3297
+ var seq = cm.state.keySeq;
3298
+ if (seq) {
3299
+ if (isModifierKey(name)) return "handled";
3300
+ stopSeq.set(50, function() {
3301
+ if (cm.state.keySeq == seq) {
3302
+ cm.state.keySeq = null;
3303
+ resetInput(cm);
3304
+ }
3305
+ });
3306
+ name = seq + " " + name;
3307
+ }
3308
+ var result = lookupKeyForEditor(cm, name, handle);
3309
+
3310
+ if (result == "multi")
3311
+ cm.state.keySeq = name;
3312
+ if (result == "handled")
3313
+ signalLater(cm, "keyHandled", cm, name, e);
3314
+
3315
+ if (result == "handled" || result == "multi") {
3316
+ e_preventDefault(e);
3317
+ restartBlink(cm);
3318
+ }
3319
+
3320
+ if (seq && !result && /\'$/.test(name)) {
3321
+ e_preventDefault(e);
3322
+ return true;
3323
+ }
3324
+ return !!result;
3325
+ }
3326
+
3327
+ // Handle a key from the keydown event.
3328
+ function handleKeyBinding(cm, e) {
3329
+ var name = keyName(e, true);
3330
+ if (!name) return false;
3331
+
3332
+ if (e.shiftKey && !cm.state.keySeq) {
3333
+ // First try to resolve full name (including 'Shift-'). Failing
3334
+ // that, see if there is a cursor-motion command (starting with
3335
+ // 'go') bound to the keyname without 'Shift-'.
3336
+ return dispatchKey(cm, "Shift-" + name, e, function(b) {return doHandleBinding(cm, b, true);})
3337
+ || dispatchKey(cm, name, e, function(b) {
3338
+ if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
3339
+ return doHandleBinding(cm, b);
3340
+ });
3341
+ } else {
3342
+ return dispatchKey(cm, name, e, function(b) { return doHandleBinding(cm, b); });
3343
+ }
3344
+ }
3345
+
3346
+ // Handle a key from the keypress event
3347
+ function handleCharBinding(cm, e, ch) {
3348
+ return dispatchKey(cm, "'" + ch + "'", e,
3349
+ function(b) { return doHandleBinding(cm, b, true); });
3350
+ }
3351
+
3352
+ var lastStoppedKey = null;
3353
+ function onKeyDown(e) {
3354
+ var cm = this;
3355
+ ensureFocus(cm);
3356
+ if (signalDOMEvent(cm, e)) return;
3357
+ // IE does strange things with escape.
3358
+ if (ie && ie_version < 11 && e.keyCode == 27) e.returnValue = false;
3359
+ var code = e.keyCode;
3360
+ cm.display.shift = code == 16 || e.shiftKey;
3361
+ var handled = handleKeyBinding(cm, e);
3362
+ if (presto) {
3363
+ lastStoppedKey = handled ? code : null;
3364
+ // Opera has no cut event... we try to at least catch the key combo
3365
+ if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
3366
+ cm.replaceSelection("", null, "cut");
3367
+ }
3368
+
3369
+ // Turn mouse into crosshair when Alt is held on Mac.
3370
+ if (code == 18 && !/\bCodeMirror-crosshair\b/.test(cm.display.lineDiv.className))
3371
+ showCrossHair(cm);
3372
+ }
3373
+
3374
+ function showCrossHair(cm) {
3375
+ var lineDiv = cm.display.lineDiv;
3376
+ addClass(lineDiv, "CodeMirror-crosshair");
3377
+
3378
+ function up(e) {
3379
+ if (e.keyCode == 18 || !e.altKey) {
3380
+ rmClass(lineDiv, "CodeMirror-crosshair");
3381
+ off(document, "keyup", up);
3382
+ off(document, "mouseover", up);
3383
+ }
3384
+ }
3385
+ on(document, "keyup", up);
3386
+ on(document, "mouseover", up);
3387
+ }
3388
+
3389
+ function onKeyUp(e) {
3390
+ if (e.keyCode == 16) this.doc.sel.shift = false;
3391
+ signalDOMEvent(this, e);
3392
+ }
3393
+
3394
+ function onKeyPress(e) {
3395
+ var cm = this;
3396
+ if (signalDOMEvent(cm, e) || e.ctrlKey && !e.altKey || mac && e.metaKey) return;
3397
+ var keyCode = e.keyCode, charCode = e.charCode;
3398
+ if (presto && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return;}
3399
+ if (((presto && (!e.which || e.which < 10)) || khtml) && handleKeyBinding(cm, e)) return;
3400
+ var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
3401
+ if (handleCharBinding(cm, e, ch)) return;
3402
+ if (ie && ie_version >= 9) cm.display.inputHasSelection = null;
3403
+ fastPoll(cm);
3404
+ }
3405
+
3406
+ // FOCUS/BLUR EVENTS
3407
+
3408
+ function onFocus(cm) {
3409
+ if (cm.options.readOnly == "nocursor") return;
3410
+ if (!cm.state.focused) {
3411
+ signal(cm, "focus", cm);
3412
+ cm.state.focused = true;
3413
+ addClass(cm.display.wrapper, "CodeMirror-focused");
3414
+ // The prevInput test prevents this from firing when a context
3415
+ // menu is closed (since the resetInput would kill the
3416
+ // select-all detection hack)
3417
+ if (!cm.curOp && cm.display.selForContextMenu != cm.doc.sel) {
3418
+ resetInput(cm);
3419
+ if (webkit) setTimeout(bind(resetInput, cm, true), 0); // Issue #1730
3420
+ }
3421
+ }
3422
+ slowPoll(cm);
3423
+ restartBlink(cm);
3424
+ }
3425
+ function onBlur(cm) {
3426
+ if (cm.state.focused) {
3427
+ signal(cm, "blur", cm);
3428
+ cm.state.focused = false;
3429
+ rmClass(cm.display.wrapper, "CodeMirror-focused");
3430
+ }
3431
+ clearInterval(cm.display.blinker);
3432
+ setTimeout(function() {if (!cm.state.focused) cm.display.shift = false;}, 150);
3433
+ }
3434
+
3435
+ // CONTEXT MENU HANDLING
3436
+
3437
+ // To make the context menu work, we need to briefly unhide the
3438
+ // textarea (making it as unobtrusive as possible) to let the
3439
+ // right-click take effect on it.
3440
+ function onContextMenu(cm, e) {
3441
+ if (signalDOMEvent(cm, e, "contextmenu")) return;
3442
+ var display = cm.display;
3443
+ if (eventInWidget(display, e) || contextMenuInGutter(cm, e)) return;
3444
+
3445
+ var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
3446
+ if (!pos || presto) return; // Opera is difficult.
3447
+
3448
+ // Reset the current text selection only if the click is done outside of the selection
3449
+ // and 'resetSelectionOnContextMenu' option is true.
3450
+ var reset = cm.options.resetSelectionOnContextMenu;
3451
+ if (reset && cm.doc.sel.contains(pos) == -1)
3452
+ operation(cm, setSelection)(cm.doc, simpleSelection(pos), sel_dontScroll);
3453
+
3454
+ var oldCSS = display.input.style.cssText;
3455
+ display.inputDiv.style.position = "absolute";
3456
+ display.input.style.cssText = "position: fixed; width: 30px; height: 30px; top: " + (e.clientY - 5) +
3457
+ "px; left: " + (e.clientX - 5) + "px; z-index: 1000; background: " +
3458
+ (ie ? "rgba(255, 255, 255, .05)" : "transparent") +
3459
+ "; outline: none; border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";
3460
+ if (webkit) var oldScrollY = window.scrollY; // Work around Chrome issue (#2712)
3461
+ focusInput(cm);
3462
+ if (webkit) window.scrollTo(null, oldScrollY);
3463
+ resetInput(cm);
3464
+ // Adds "Select all" to context menu in FF
3465
+ if (!cm.somethingSelected()) display.input.value = display.prevInput = " ";
3466
+ display.contextMenuPending = true;
3467
+ display.selForContextMenu = cm.doc.sel;
3468
+ clearTimeout(display.detectingSelectAll);
3469
+
3470
+ // Select-all will be greyed out if there's nothing to select, so
3471
+ // this adds a zero-width space so that we can later check whether
3472
+ // it got selected.
3473
+ function prepareSelectAllHack() {
3474
+ if (display.input.selectionStart != null) {
3475
+ var selected = cm.somethingSelected();
3476
+ var extval = display.input.value = "\u200b" + (selected ? display.input.value : "");
3477
+ display.prevInput = selected ? "" : "\u200b";
3478
+ display.input.selectionStart = 1; display.input.selectionEnd = extval.length;
3479
+ // Re-set this, in case some other handler touched the
3480
+ // selection in the meantime.
3481
+ display.selForContextMenu = cm.doc.sel;
3482
+ }
3483
+ }
3484
+ function rehide() {
3485
+ display.contextMenuPending = false;
3486
+ display.inputDiv.style.position = "relative";
3487
+ display.input.style.cssText = oldCSS;
3488
+ if (ie && ie_version < 9) display.scrollbars.setScrollTop(display.scroller.scrollTop = scrollPos);
3489
+ slowPoll(cm);
3490
+
3491
+ // Try to detect the user choosing select-all
3492
+ if (display.input.selectionStart != null) {
3493
+ if (!ie || (ie && ie_version < 9)) prepareSelectAllHack();
3494
+ var i = 0, poll = function() {
3495
+ if (display.selForContextMenu == cm.doc.sel && display.input.selectionStart == 0)
3496
+ operation(cm, commands.selectAll)(cm);
3497
+ else if (i++ < 10) display.detectingSelectAll = setTimeout(poll, 500);
3498
+ else resetInput(cm);
3499
+ };
3500
+ display.detectingSelectAll = setTimeout(poll, 200);
3501
+ }
3502
+ }
3503
+
3504
+ if (ie && ie_version >= 9) prepareSelectAllHack();
3505
+ if (captureRightClick) {
3506
+ e_stop(e);
3507
+ var mouseup = function() {
3508
+ off(window, "mouseup", mouseup);
3509
+ setTimeout(rehide, 20);
3510
+ };
3511
+ on(window, "mouseup", mouseup);
3512
+ } else {
3513
+ setTimeout(rehide, 50);
3514
+ }
3515
+ }
3516
+
3517
+ function contextMenuInGutter(cm, e) {
3518
+ if (!hasHandler(cm, "gutterContextMenu")) return false;
3519
+ return gutterEvent(cm, e, "gutterContextMenu", false, signal);
3520
+ }
3521
+
3522
+ // UPDATING
3523
+
3524
+ // Compute the position of the end of a change (its 'to' property
3525
+ // refers to the pre-change end).
3526
+ var changeEnd = CodeMirror.changeEnd = function(change) {
3527
+ if (!change.text) return change.to;
3528
+ return Pos(change.from.line + change.text.length - 1,
3529
+ lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0));
3530
+ };
3531
+
3532
+ // Adjust a position to refer to the post-change position of the
3533
+ // same text, or the end of the change if the change covers it.
3534
+ function adjustForChange(pos, change) {
3535
+ if (cmp(pos, change.from) < 0) return pos;
3536
+ if (cmp(pos, change.to) <= 0) return changeEnd(change);
3537
+
3538
+ var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch;
3539
+ if (pos.line == change.to.line) ch += changeEnd(change).ch - change.to.ch;
3540
+ return Pos(line, ch);
3541
+ }
3542
+
3543
+ function computeSelAfterChange(doc, change) {
3544
+ var out = [];
3545
+ for (var i = 0; i < doc.sel.ranges.length; i++) {
3546
+ var range = doc.sel.ranges[i];
3547
+ out.push(new Range(adjustForChange(range.anchor, change),
3548
+ adjustForChange(range.head, change)));
3549
+ }
3550
+ return normalizeSelection(out, doc.sel.primIndex);
3551
+ }
3552
+
3553
+ function offsetPos(pos, old, nw) {
3554
+ if (pos.line == old.line)
3555
+ return Pos(nw.line, pos.ch - old.ch + nw.ch);
3556
+ else
3557
+ return Pos(nw.line + (pos.line - old.line), pos.ch);
3558
+ }
3559
+
3560
+ // Used by replaceSelections to allow moving the selection to the
3561
+ // start or around the replaced test. Hint may be "start" or "around".
3562
+ function computeReplacedSel(doc, changes, hint) {
3563
+ var out = [];
3564
+ var oldPrev = Pos(doc.first, 0), newPrev = oldPrev;
3565
+ for (var i = 0; i < changes.length; i++) {
3566
+ var change = changes[i];
3567
+ var from = offsetPos(change.from, oldPrev, newPrev);
3568
+ var to = offsetPos(changeEnd(change), oldPrev, newPrev);
3569
+ oldPrev = change.to;
3570
+ newPrev = to;
3571
+ if (hint == "around") {
3572
+ var range = doc.sel.ranges[i], inv = cmp(range.head, range.anchor) < 0;
3573
+ out[i] = new Range(inv ? to : from, inv ? from : to);
3574
+ } else {
3575
+ out[i] = new Range(from, from);
3576
+ }
3577
+ }
3578
+ return new Selection(out, doc.sel.primIndex);
3579
+ }
3580
+
3581
+ // Allow "beforeChange" event handlers to influence a change
3582
+ function filterChange(doc, change, update) {
3583
+ var obj = {
3584
+ canceled: false,
3585
+ from: change.from,
3586
+ to: change.to,
3587
+ text: change.text,
3588
+ origin: change.origin,
3589
+ cancel: function() { this.canceled = true; }
3590
+ };
3591
+ if (update) obj.update = function(from, to, text, origin) {
3592
+ if (from) this.from = clipPos(doc, from);
3593
+ if (to) this.to = clipPos(doc, to);
3594
+ if (text) this.text = text;
3595
+ if (origin !== undefined) this.origin = origin;
3596
+ };
3597
+ signal(doc, "beforeChange", doc, obj);
3598
+ if (doc.cm) signal(doc.cm, "beforeChange", doc.cm, obj);
3599
+
3600
+ if (obj.canceled) return null;
3601
+ return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin};
3602
+ }
3603
+
3604
+ // Apply a change to a document, and add it to the document's
3605
+ // history, and propagating it to all linked documents.
3606
+ function makeChange(doc, change, ignoreReadOnly) {
3607
+ if (doc.cm) {
3608
+ if (!doc.cm.curOp) return operation(doc.cm, makeChange)(doc, change, ignoreReadOnly);
3609
+ if (doc.cm.state.suppressEdits) return;
3610
+ }
3611
+
3612
+ if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
3613
+ change = filterChange(doc, change, true);
3614
+ if (!change) return;
3615
+ }
3616
+
3617
+ // Possibly split or suppress the update based on the presence
3618
+ // of read-only spans in its range.
3619
+ var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to);
3620
+ if (split) {
3621
+ for (var i = split.length - 1; i >= 0; --i)
3622
+ makeChangeInner(doc, {from: split[i].from, to: split[i].to, text: i ? [""] : change.text});
3623
+ } else {
3624
+ makeChangeInner(doc, change);
3625
+ }
3626
+ }
3627
+
3628
+ function makeChangeInner(doc, change) {
3629
+ if (change.text.length == 1 && change.text[0] == "" && cmp(change.from, change.to) == 0) return;
3630
+ var selAfter = computeSelAfterChange(doc, change);
3631
+ addChangeToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN);
3632
+
3633
+ makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change));
3634
+ var rebased = [];
3635
+
3636
+ linkedDocs(doc, function(doc, sharedHist) {
3637
+ if (!sharedHist && indexOf(rebased, doc.history) == -1) {
3638
+ rebaseHist(doc.history, change);
3639
+ rebased.push(doc.history);
3640
+ }
3641
+ makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change));
3642
+ });
3643
+ }
3644
+
3645
+ // Revert a change stored in a document's history.
3646
+ function makeChangeFromHistory(doc, type, allowSelectionOnly) {
3647
+ if (doc.cm && doc.cm.state.suppressEdits) return;
3648
+
3649
+ var hist = doc.history, event, selAfter = doc.sel;
3650
+ var source = type == "undo" ? hist.done : hist.undone, dest = type == "undo" ? hist.undone : hist.done;
3651
+
3652
+ // Verify that there is a useable event (so that ctrl-z won't
3653
+ // needlessly clear selection events)
3654
+ for (var i = 0; i < source.length; i++) {
3655
+ event = source[i];
3656
+ if (allowSelectionOnly ? event.ranges && !event.equals(doc.sel) : !event.ranges)
3657
+ break;
3658
+ }
3659
+ if (i == source.length) return;
3660
+ hist.lastOrigin = hist.lastSelOrigin = null;
3661
+
3662
+ for (;;) {
3663
+ event = source.pop();
3664
+ if (event.ranges) {
3665
+ pushSelectionToHistory(event, dest);
3666
+ if (allowSelectionOnly && !event.equals(doc.sel)) {
3667
+ setSelection(doc, event, {clearRedo: false});
3668
+ return;
3669
+ }
3670
+ selAfter = event;
3671
+ }
3672
+ else break;
3673
+ }
3674
+
3675
+ // Build up a reverse change object to add to the opposite history
3676
+ // stack (redo when undoing, and vice versa).
3677
+ var antiChanges = [];
3678
+ pushSelectionToHistory(selAfter, dest);
3679
+ dest.push({changes: antiChanges, generation: hist.generation});
3680
+ hist.generation = event.generation || ++hist.maxGeneration;
3681
+
3682
+ var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange");
3683
+
3684
+ for (var i = event.changes.length - 1; i >= 0; --i) {
3685
+ var change = event.changes[i];
3686
+ change.origin = type;
3687
+ if (filter && !filterChange(doc, change, false)) {
3688
+ source.length = 0;
3689
+ return;
3690
+ }
3691
+
3692
+ antiChanges.push(historyChangeFromChange(doc, change));
3693
+
3694
+ var after = i ? computeSelAfterChange(doc, change) : lst(source);
3695
+ makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change));
3696
+ if (!i && doc.cm) doc.cm.scrollIntoView({from: change.from, to: changeEnd(change)});
3697
+ var rebased = [];
3698
+
3699
+ // Propagate to the linked documents
3700
+ linkedDocs(doc, function(doc, sharedHist) {
3701
+ if (!sharedHist && indexOf(rebased, doc.history) == -1) {
3702
+ rebaseHist(doc.history, change);
3703
+ rebased.push(doc.history);
3704
+ }
3705
+ makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change));
3706
+ });
3707
+ }
3708
+ }
3709
+
3710
+ // Sub-views need their line numbers shifted when text is added
3711
+ // above or below them in the parent document.
3712
+ function shiftDoc(doc, distance) {
3713
+ if (distance == 0) return;
3714
+ doc.first += distance;
3715
+ doc.sel = new Selection(map(doc.sel.ranges, function(range) {
3716
+ return new Range(Pos(range.anchor.line + distance, range.anchor.ch),
3717
+ Pos(range.head.line + distance, range.head.ch));
3718
+ }), doc.sel.primIndex);
3719
+ if (doc.cm) {
3720
+ regChange(doc.cm, doc.first, doc.first - distance, distance);
3721
+ for (var d = doc.cm.display, l = d.viewFrom; l < d.viewTo; l++)
3722
+ regLineChange(doc.cm, l, "gutter");
3723
+ }
3724
+ }
3725
+
3726
+ // More lower-level change function, handling only a single document
3727
+ // (not linked ones).
3728
+ function makeChangeSingleDoc(doc, change, selAfter, spans) {
3729
+ if (doc.cm && !doc.cm.curOp)
3730
+ return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans);
3731
+
3732
+ if (change.to.line < doc.first) {
3733
+ shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line));
3734
+ return;
3735
+ }
3736
+ if (change.from.line > doc.lastLine()) return;
3737
+
3738
+ // Clip the change to the size of this doc
3739
+ if (change.from.line < doc.first) {
3740
+ var shift = change.text.length - 1 - (doc.first - change.from.line);
3741
+ shiftDoc(doc, shift);
3742
+ change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
3743
+ text: [lst(change.text)], origin: change.origin};
3744
+ }
3745
+ var last = doc.lastLine();
3746
+ if (change.to.line > last) {
3747
+ change = {from: change.from, to: Pos(last, getLine(doc, last).text.length),
3748
+ text: [change.text[0]], origin: change.origin};
3749
+ }
3750
+
3751
+ change.removed = getBetween(doc, change.from, change.to);
3752
+
3753
+ if (!selAfter) selAfter = computeSelAfterChange(doc, change);
3754
+ if (doc.cm) makeChangeSingleDocInEditor(doc.cm, change, spans);
3755
+ else updateDoc(doc, change, spans);
3756
+ setSelectionNoUndo(doc, selAfter, sel_dontScroll);
3757
+ }
3758
+
3759
+ // Handle the interaction of a change to a document with the editor
3760
+ // that this document is part of.
3761
+ function makeChangeSingleDocInEditor(cm, change, spans) {
3762
+ var doc = cm.doc, display = cm.display, from = change.from, to = change.to;
3763
+
3764
+ var recomputeMaxLength = false, checkWidthStart = from.line;
3765
+ if (!cm.options.lineWrapping) {
3766
+ checkWidthStart = lineNo(visualLine(getLine(doc, from.line)));
3767
+ doc.iter(checkWidthStart, to.line + 1, function(line) {
3768
+ if (line == display.maxLine) {
3769
+ recomputeMaxLength = true;
3770
+ return true;
3771
+ }
3772
+ });
3773
+ }
3774
+
3775
+ if (doc.sel.contains(change.from, change.to) > -1)
3776
+ signalCursorActivity(cm);
3777
+
3778
+ updateDoc(doc, change, spans, estimateHeight(cm));
3779
+
3780
+ if (!cm.options.lineWrapping) {
3781
+ doc.iter(checkWidthStart, from.line + change.text.length, function(line) {
3782
+ var len = lineLength(line);
3783
+ if (len > display.maxLineLength) {
3784
+ display.maxLine = line;
3785
+ display.maxLineLength = len;
3786
+ display.maxLineChanged = true;
3787
+ recomputeMaxLength = false;
3788
+ }
3789
+ });
3790
+ if (recomputeMaxLength) cm.curOp.updateMaxLine = true;
3791
+ }
3792
+
3793
+ // Adjust frontier, schedule worker
3794
+ doc.frontier = Math.min(doc.frontier, from.line);
3795
+ startWorker(cm, 400);
3796
+
3797
+ var lendiff = change.text.length - (to.line - from.line) - 1;
3798
+ // Remember that these lines changed, for updating the display
3799
+ if (change.full)
3800
+ regChange(cm);
3801
+ else if (from.line == to.line && change.text.length == 1 && !isWholeLineUpdate(cm.doc, change))
3802
+ regLineChange(cm, from.line, "text");
3803
+ else
3804
+ regChange(cm, from.line, to.line + 1, lendiff);
3805
+
3806
+ var changesHandler = hasHandler(cm, "changes"), changeHandler = hasHandler(cm, "change");
3807
+ if (changeHandler || changesHandler) {
3808
+ var obj = {
3809
+ from: from, to: to,
3810
+ text: change.text,
3811
+ removed: change.removed,
3812
+ origin: change.origin
3813
+ };
3814
+ if (changeHandler) signalLater(cm, "change", cm, obj);
3815
+ if (changesHandler) (cm.curOp.changeObjs || (cm.curOp.changeObjs = [])).push(obj);
3816
+ }
3817
+ cm.display.selForContextMenu = null;
3818
+ }
3819
+
3820
+ function replaceRange(doc, code, from, to, origin) {
3821
+ if (!to) to = from;
3822
+ if (cmp(to, from) < 0) { var tmp = to; to = from; from = tmp; }
3823
+ if (typeof code == "string") code = splitLines(code);
3824
+ makeChange(doc, {from: from, to: to, text: code, origin: origin});
3825
+ }
3826
+
3827
+ // SCROLLING THINGS INTO VIEW
3828
+
3829
+ // If an editor sits on the top or bottom of the window, partially
3830
+ // scrolled out of view, this ensures that the cursor is visible.
3831
+ function maybeScrollWindow(cm, coords) {
3832
+ if (signalDOMEvent(cm, "scrollCursorIntoView")) return;
3833
+
3834
+ var display = cm.display, box = display.sizer.getBoundingClientRect(), doScroll = null;
3835
+ if (coords.top + box.top < 0) doScroll = true;
3836
+ else if (coords.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) doScroll = false;
3837
+ if (doScroll != null && !phantom) {
3838
+ var scrollNode = elt("div", "\u200b", null, "position: absolute; top: " +
3839
+ (coords.top - display.viewOffset - paddingTop(cm.display)) + "px; height: " +
3840
+ (coords.bottom - coords.top + scrollGap(cm) + display.barHeight) + "px; left: " +
3841
+ coords.left + "px; width: 2px;");
3842
+ cm.display.lineSpace.appendChild(scrollNode);
3843
+ scrollNode.scrollIntoView(doScroll);
3844
+ cm.display.lineSpace.removeChild(scrollNode);
3845
+ }
3846
+ }
3847
+
3848
+ // Scroll a given position into view (immediately), verifying that
3849
+ // it actually became visible (as line heights are accurately
3850
+ // measured, the position of something may 'drift' during drawing).
3851
+ function scrollPosIntoView(cm, pos, end, margin) {
3852
+ if (margin == null) margin = 0;
3853
+ for (var limit = 0; limit < 5; limit++) {
3854
+ var changed = false, coords = cursorCoords(cm, pos);
3855
+ var endCoords = !end || end == pos ? coords : cursorCoords(cm, end);
3856
+ var scrollPos = calculateScrollPos(cm, Math.min(coords.left, endCoords.left),
3857
+ Math.min(coords.top, endCoords.top) - margin,
3858
+ Math.max(coords.left, endCoords.left),
3859
+ Math.max(coords.bottom, endCoords.bottom) + margin);
3860
+ var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft;
3861
+ if (scrollPos.scrollTop != null) {
3862
+ setScrollTop(cm, scrollPos.scrollTop);
3863
+ if (Math.abs(cm.doc.scrollTop - startTop) > 1) changed = true;
3864
+ }
3865
+ if (scrollPos.scrollLeft != null) {
3866
+ setScrollLeft(cm, scrollPos.scrollLeft);
3867
+ if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) changed = true;
3868
+ }
3869
+ if (!changed) break;
3870
+ }
3871
+ return coords;
3872
+ }
3873
+
3874
+ // Scroll a given set of coordinates into view (immediately).
3875
+ function scrollIntoView(cm, x1, y1, x2, y2) {
3876
+ var scrollPos = calculateScrollPos(cm, x1, y1, x2, y2);
3877
+ if (scrollPos.scrollTop != null) setScrollTop(cm, scrollPos.scrollTop);
3878
+ if (scrollPos.scrollLeft != null) setScrollLeft(cm, scrollPos.scrollLeft);
3879
+ }
3880
+
3881
+ // Calculate a new scroll position needed to scroll the given
3882
+ // rectangle into view. Returns an object with scrollTop and
3883
+ // scrollLeft properties. When these are undefined, the
3884
+ // vertical/horizontal position does not need to be adjusted.
3885
+ function calculateScrollPos(cm, x1, y1, x2, y2) {
3886
+ var display = cm.display, snapMargin = textHeight(cm.display);
3887
+ if (y1 < 0) y1 = 0;
3888
+ var screentop = cm.curOp && cm.curOp.scrollTop != null ? cm.curOp.scrollTop : display.scroller.scrollTop;
3889
+ var screen = displayHeight(cm), result = {};
3890
+ if (y2 - y1 > screen) y2 = y1 + screen;
3891
+ var docBottom = cm.doc.height + paddingVert(display);
3892
+ var atTop = y1 < snapMargin, atBottom = y2 > docBottom - snapMargin;
3893
+ if (y1 < screentop) {
3894
+ result.scrollTop = atTop ? 0 : y1;
3895
+ } else if (y2 > screentop + screen) {
3896
+ var newTop = Math.min(y1, (atBottom ? docBottom : y2) - screen);
3897
+ if (newTop != screentop) result.scrollTop = newTop;
3898
+ }
3899
+
3900
+ var screenleft = cm.curOp && cm.curOp.scrollLeft != null ? cm.curOp.scrollLeft : display.scroller.scrollLeft;
3901
+ var screenw = displayWidth(cm) - (cm.options.fixedGutter ? display.gutters.offsetWidth : 0);
3902
+ var tooWide = x2 - x1 > screenw;
3903
+ if (tooWide) x2 = x1 + screenw;
3904
+ if (x1 < 10)
3905
+ result.scrollLeft = 0;
3906
+ else if (x1 < screenleft)
3907
+ result.scrollLeft = Math.max(0, x1 - (tooWide ? 0 : 10));
3908
+ else if (x2 > screenw + screenleft - 3)
3909
+ result.scrollLeft = x2 + (tooWide ? 0 : 10) - screenw;
3910
+ return result;
3911
+ }
3912
+
3913
+ // Store a relative adjustment to the scroll position in the current
3914
+ // operation (to be applied when the operation finishes).
3915
+ function addToScrollPos(cm, left, top) {
3916
+ if (left != null || top != null) resolveScrollToPos(cm);
3917
+ if (left != null)
3918
+ cm.curOp.scrollLeft = (cm.curOp.scrollLeft == null ? cm.doc.scrollLeft : cm.curOp.scrollLeft) + left;
3919
+ if (top != null)
3920
+ cm.curOp.scrollTop = (cm.curOp.scrollTop == null ? cm.doc.scrollTop : cm.curOp.scrollTop) + top;
3921
+ }
3922
+
3923
+ // Make sure that at the end of the operation the current cursor is
3924
+ // shown.
3925
+ function ensureCursorVisible(cm) {
3926
+ resolveScrollToPos(cm);
3927
+ var cur = cm.getCursor(), from = cur, to = cur;
3928
+ if (!cm.options.lineWrapping) {
3929
+ from = cur.ch ? Pos(cur.line, cur.ch - 1) : cur;
3930
+ to = Pos(cur.line, cur.ch + 1);
3931
+ }
3932
+ cm.curOp.scrollToPos = {from: from, to: to, margin: cm.options.cursorScrollMargin, isCursor: true};
3933
+ }
3934
+
3935
+ // When an operation has its scrollToPos property set, and another
3936
+ // scroll action is applied before the end of the operation, this
3937
+ // 'simulates' scrolling that position into view in a cheap way, so
3938
+ // that the effect of intermediate scroll commands is not ignored.
3939
+ function resolveScrollToPos(cm) {
3940
+ var range = cm.curOp.scrollToPos;
3941
+ if (range) {
3942
+ cm.curOp.scrollToPos = null;
3943
+ var from = estimateCoords(cm, range.from), to = estimateCoords(cm, range.to);
3944
+ var sPos = calculateScrollPos(cm, Math.min(from.left, to.left),
3945
+ Math.min(from.top, to.top) - range.margin,
3946
+ Math.max(from.right, to.right),
3947
+ Math.max(from.bottom, to.bottom) + range.margin);
3948
+ cm.scrollTo(sPos.scrollLeft, sPos.scrollTop);
3949
+ }
3950
+ }
3951
+
3952
+ // API UTILITIES
3953
+
3954
+ // Indent the given line. The how parameter can be "smart",
3955
+ // "add"/null, "subtract", or "prev". When aggressive is false
3956
+ // (typically set to true for forced single-line indents), empty
3957
+ // lines are not indented, and places where the mode returns Pass
3958
+ // are left alone.
3959
+ function indentLine(cm, n, how, aggressive) {
3960
+ var doc = cm.doc, state;
3961
+ if (how == null) how = "add";
3962
+ if (how == "smart") {
3963
+ // Fall back to "prev" when the mode doesn't have an indentation
3964
+ // method.
3965
+ if (!doc.mode.indent) how = "prev";
3966
+ else state = getStateBefore(cm, n);
3967
+ }
3968
+
3969
+ var tabSize = cm.options.tabSize;
3970
+ var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
3971
+ if (line.stateAfter) line.stateAfter = null;
3972
+ var curSpaceString = line.text.match(/^\s*/)[0], indentation;
3973
+ if (!aggressive && !/\S/.test(line.text)) {
3974
+ indentation = 0;
3975
+ how = "not";
3976
+ } else if (how == "smart") {
3977
+ indentation = doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
3978
+ if (indentation == Pass || indentation > 150) {
3979
+ if (!aggressive) return;
3980
+ how = "prev";
3981
+ }
3982
+ }
3983
+ if (how == "prev") {
3984
+ if (n > doc.first) indentation = countColumn(getLine(doc, n-1).text, null, tabSize);
3985
+ else indentation = 0;
3986
+ } else if (how == "add") {
3987
+ indentation = curSpace + cm.options.indentUnit;
3988
+ } else if (how == "subtract") {
3989
+ indentation = curSpace - cm.options.indentUnit;
3990
+ } else if (typeof how == "number") {
3991
+ indentation = curSpace + how;
3992
+ }
3993
+ indentation = Math.max(0, indentation);
3994
+
3995
+ var indentString = "", pos = 0;
3996
+ if (cm.options.indentWithTabs)
3997
+ for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";}
3998
+ if (pos < indentation) indentString += spaceStr(indentation - pos);
3999
+
4000
+ if (indentString != curSpaceString) {
4001
+ replaceRange(doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input");
4002
+ } else {
4003
+ // Ensure that, if the cursor was in the whitespace at the start
4004
+ // of the line, it is moved to the end of that space.
4005
+ for (var i = 0; i < doc.sel.ranges.length; i++) {
4006
+ var range = doc.sel.ranges[i];
4007
+ if (range.head.line == n && range.head.ch < curSpaceString.length) {
4008
+ var pos = Pos(n, curSpaceString.length);
4009
+ replaceOneSelection(doc, i, new Range(pos, pos));
4010
+ break;
4011
+ }
4012
+ }
4013
+ }
4014
+ line.stateAfter = null;
4015
+ }
4016
+
4017
+ // Utility for applying a change to a line by handle or number,
4018
+ // returning the number and optionally registering the line as
4019
+ // changed.
4020
+ function changeLine(doc, handle, changeType, op) {
4021
+ var no = handle, line = handle;
4022
+ if (typeof handle == "number") line = getLine(doc, clipLine(doc, handle));
4023
+ else no = lineNo(handle);
4024
+ if (no == null) return null;
4025
+ if (op(line, no) && doc.cm) regLineChange(doc.cm, no, changeType);
4026
+ return line;
4027
+ }
4028
+
4029
+ // Helper for deleting text near the selection(s), used to implement
4030
+ // backspace, delete, and similar functionality.
4031
+ function deleteNearSelection(cm, compute) {
4032
+ var ranges = cm.doc.sel.ranges, kill = [];
4033
+ // Build up a set of ranges to kill first, merging overlapping
4034
+ // ranges.
4035
+ for (var i = 0; i < ranges.length; i++) {
4036
+ var toKill = compute(ranges[i]);
4037
+ while (kill.length && cmp(toKill.from, lst(kill).to) <= 0) {
4038
+ var replaced = kill.pop();
4039
+ if (cmp(replaced.from, toKill.from) < 0) {
4040
+ toKill.from = replaced.from;
4041
+ break;
4042
+ }
4043
+ }
4044
+ kill.push(toKill);
4045
+ }
4046
+ // Next, remove those actual ranges.
4047
+ runInOp(cm, function() {
4048
+ for (var i = kill.length - 1; i >= 0; i--)
4049
+ replaceRange(cm.doc, "", kill[i].from, kill[i].to, "+delete");
4050
+ ensureCursorVisible(cm);
4051
+ });
4052
+ }
4053
+
4054
+ // Used for horizontal relative motion. Dir is -1 or 1 (left or
4055
+ // right), unit can be "char", "column" (like char, but doesn't
4056
+ // cross line boundaries), "word" (across next word), or "group" (to
4057
+ // the start of next group of word or non-word-non-whitespace
4058
+ // chars). The visually param controls whether, in right-to-left
4059
+ // text, direction 1 means to move towards the next index in the
4060
+ // string, or towards the character to the right of the current
4061
+ // position. The resulting position will have a hitSide=true
4062
+ // property if it reached the end of the document.
4063
+ function findPosH(doc, pos, dir, unit, visually) {
4064
+ var line = pos.line, ch = pos.ch, origDir = dir;
4065
+ var lineObj = getLine(doc, line);
4066
+ var possible = true;
4067
+ function findNextLine() {
4068
+ var l = line + dir;
4069
+ if (l < doc.first || l >= doc.first + doc.size) return (possible = false);
4070
+ line = l;
4071
+ return lineObj = getLine(doc, l);
4072
+ }
4073
+ function moveOnce(boundToLine) {
4074
+ var next = (visually ? moveVisually : moveLogically)(lineObj, ch, dir, true);
4075
+ if (next == null) {
4076
+ if (!boundToLine && findNextLine()) {
4077
+ if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj);
4078
+ else ch = dir < 0 ? lineObj.text.length : 0;
4079
+ } else return (possible = false);
4080
+ } else ch = next;
4081
+ return true;
4082
+ }
4083
+
4084
+ if (unit == "char") moveOnce();
4085
+ else if (unit == "column") moveOnce(true);
4086
+ else if (unit == "word" || unit == "group") {
4087
+ var sawType = null, group = unit == "group";
4088
+ var helper = doc.cm && doc.cm.getHelper(pos, "wordChars");
4089
+ for (var first = true;; first = false) {
4090
+ if (dir < 0 && !moveOnce(!first)) break;
4091
+ var cur = lineObj.text.charAt(ch) || "\n";
4092
+ var type = isWordChar(cur, helper) ? "w"
4093
+ : group && cur == "\n" ? "n"
4094
+ : !group || /\s/.test(cur) ? null
4095
+ : "p";
4096
+ if (group && !first && !type) type = "s";
4097
+ if (sawType && sawType != type) {
4098
+ if (dir < 0) {dir = 1; moveOnce();}
4099
+ break;
4100
+ }
4101
+
4102
+ if (type) sawType = type;
4103
+ if (dir > 0 && !moveOnce(!first)) break;
4104
+ }
4105
+ }
4106
+ var result = skipAtomic(doc, Pos(line, ch), origDir, true);
4107
+ if (!possible) result.hitSide = true;
4108
+ return result;
4109
+ }
4110
+
4111
+ // For relative vertical movement. Dir may be -1 or 1. Unit can be
4112
+ // "page" or "line". The resulting position will have a hitSide=true
4113
+ // property if it reached the end of the document.
4114
+ function findPosV(cm, pos, dir, unit) {
4115
+ var doc = cm.doc, x = pos.left, y;
4116
+ if (unit == "page") {
4117
+ var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
4118
+ y = pos.top + dir * (pageSize - (dir < 0 ? 1.5 : .5) * textHeight(cm.display));
4119
+ } else if (unit == "line") {
4120
+ y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
4121
+ }
4122
+ for (;;) {
4123
+ var target = coordsChar(cm, x, y);
4124
+ if (!target.outside) break;
4125
+ if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break; }
4126
+ y += dir * 5;
4127
+ }
4128
+ return target;
4129
+ }
4130
+
4131
+ // EDITOR METHODS
4132
+
4133
+ // The publicly visible API. Note that methodOp(f) means
4134
+ // 'wrap f in an operation, performed on its `this` parameter'.
4135
+
4136
+ // This is not the complete set of editor methods. Most of the
4137
+ // methods defined on the Doc type are also injected into
4138
+ // CodeMirror.prototype, for backwards compatibility and
4139
+ // convenience.
4140
+
4141
+ CodeMirror.prototype = {
4142
+ constructor: CodeMirror,
4143
+ focus: function(){window.focus(); focusInput(this); fastPoll(this);},
4144
+
4145
+ setOption: function(option, value) {
4146
+ var options = this.options, old = options[option];
4147
+ if (options[option] == value && option != "mode") return;
4148
+ options[option] = value;
4149
+ if (optionHandlers.hasOwnProperty(option))
4150
+ operation(this, optionHandlers[option])(this, value, old);
4151
+ },
4152
+
4153
+ getOption: function(option) {return this.options[option];},
4154
+ getDoc: function() {return this.doc;},
4155
+
4156
+ addKeyMap: function(map, bottom) {
4157
+ this.state.keyMaps[bottom ? "push" : "unshift"](getKeyMap(map));
4158
+ },
4159
+ removeKeyMap: function(map) {
4160
+ var maps = this.state.keyMaps;
4161
+ for (var i = 0; i < maps.length; ++i)
4162
+ if (maps[i] == map || maps[i].name == map) {
4163
+ maps.splice(i, 1);
4164
+ return true;
4165
+ }
4166
+ },
4167
+
4168
+ addOverlay: methodOp(function(spec, options) {
4169
+ var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec);
4170
+ if (mode.startState) throw new Error("Overlays may not be stateful.");
4171
+ this.state.overlays.push({mode: mode, modeSpec: spec, opaque: options && options.opaque});
4172
+ this.state.modeGen++;
4173
+ regChange(this);
4174
+ }),
4175
+ removeOverlay: methodOp(function(spec) {
4176
+ var overlays = this.state.overlays;
4177
+ for (var i = 0; i < overlays.length; ++i) {
4178
+ var cur = overlays[i].modeSpec;
4179
+ if (cur == spec || typeof spec == "string" && cur.name == spec) {
4180
+ overlays.splice(i, 1);
4181
+ this.state.modeGen++;
4182
+ regChange(this);
4183
+ return;
4184
+ }
4185
+ }
4186
+ }),
4187
+
4188
+ indentLine: methodOp(function(n, dir, aggressive) {
4189
+ if (typeof dir != "string" && typeof dir != "number") {
4190
+ if (dir == null) dir = this.options.smartIndent ? "smart" : "prev";
4191
+ else dir = dir ? "add" : "subtract";
4192
+ }
4193
+ if (isLine(this.doc, n)) indentLine(this, n, dir, aggressive);
4194
+ }),
4195
+ indentSelection: methodOp(function(how) {
4196
+ var ranges = this.doc.sel.ranges, end = -1;
4197
+ for (var i = 0; i < ranges.length; i++) {
4198
+ var range = ranges[i];
4199
+ if (!range.empty()) {
4200
+ var from = range.from(), to = range.to();
4201
+ var start = Math.max(end, from.line);
4202
+ end = Math.min(this.lastLine(), to.line - (to.ch ? 0 : 1)) + 1;
4203
+ for (var j = start; j < end; ++j)
4204
+ indentLine(this, j, how);
4205
+ var newRanges = this.doc.sel.ranges;
4206
+ if (from.ch == 0 && ranges.length == newRanges.length && newRanges[i].from().ch > 0)
4207
+ replaceOneSelection(this.doc, i, new Range(from, newRanges[i].to()), sel_dontScroll);
4208
+ } else if (range.head.line > end) {
4209
+ indentLine(this, range.head.line, how, true);
4210
+ end = range.head.line;
4211
+ if (i == this.doc.sel.primIndex) ensureCursorVisible(this);
4212
+ }
4213
+ }
4214
+ }),
4215
+
4216
+ // Fetch the parser token for a given character. Useful for hacks
4217
+ // that want to inspect the mode state (say, for completion).
4218
+ getTokenAt: function(pos, precise) {
4219
+ return takeToken(this, pos, precise);
4220
+ },
4221
+
4222
+ getLineTokens: function(line, precise) {
4223
+ return takeToken(this, Pos(line), precise, true);
4224
+ },
4225
+
4226
+ getTokenTypeAt: function(pos) {
4227
+ pos = clipPos(this.doc, pos);
4228
+ var styles = getLineStyles(this, getLine(this.doc, pos.line));
4229
+ var before = 0, after = (styles.length - 1) / 2, ch = pos.ch;
4230
+ var type;
4231
+ if (ch == 0) type = styles[2];
4232
+ else for (;;) {
4233
+ var mid = (before + after) >> 1;
4234
+ if ((mid ? styles[mid * 2 - 1] : 0) >= ch) after = mid;
4235
+ else if (styles[mid * 2 + 1] < ch) before = mid + 1;
4236
+ else { type = styles[mid * 2 + 2]; break; }
4237
+ }
4238
+ var cut = type ? type.indexOf("cm-overlay ") : -1;
4239
+ return cut < 0 ? type : cut == 0 ? null : type.slice(0, cut - 1);
4240
+ },
4241
+
4242
+ getModeAt: function(pos) {
4243
+ var mode = this.doc.mode;
4244
+ if (!mode.innerMode) return mode;
4245
+ return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode;
4246
+ },
4247
+
4248
+ getHelper: function(pos, type) {
4249
+ return this.getHelpers(pos, type)[0];
4250
+ },
4251
+
4252
+ getHelpers: function(pos, type) {
4253
+ var found = [];
4254
+ if (!helpers.hasOwnProperty(type)) return helpers;
4255
+ var help = helpers[type], mode = this.getModeAt(pos);
4256
+ if (typeof mode[type] == "string") {
4257
+ if (help[mode[type]]) found.push(help[mode[type]]);
4258
+ } else if (mode[type]) {
4259
+ for (var i = 0; i < mode[type].length; i++) {
4260
+ var val = help[mode[type][i]];
4261
+ if (val) found.push(val);
4262
+ }
4263
+ } else if (mode.helperType && help[mode.helperType]) {
4264
+ found.push(help[mode.helperType]);
4265
+ } else if (help[mode.name]) {
4266
+ found.push(help[mode.name]);
4267
+ }
4268
+ for (var i = 0; i < help._global.length; i++) {
4269
+ var cur = help._global[i];
4270
+ if (cur.pred(mode, this) && indexOf(found, cur.val) == -1)
4271
+ found.push(cur.val);
4272
+ }
4273
+ return found;
4274
+ },
4275
+
4276
+ getStateAfter: function(line, precise) {
4277
+ var doc = this.doc;
4278
+ line = clipLine(doc, line == null ? doc.first + doc.size - 1: line);
4279
+ return getStateBefore(this, line + 1, precise);
4280
+ },
4281
+
4282
+ cursorCoords: function(start, mode) {
4283
+ var pos, range = this.doc.sel.primary();
4284
+ if (start == null) pos = range.head;
4285
+ else if (typeof start == "object") pos = clipPos(this.doc, start);
4286
+ else pos = start ? range.from() : range.to();
4287
+ return cursorCoords(this, pos, mode || "page");
4288
+ },
4289
+
4290
+ charCoords: function(pos, mode) {
4291
+ return charCoords(this, clipPos(this.doc, pos), mode || "page");
4292
+ },
4293
+
4294
+ coordsChar: function(coords, mode) {
4295
+ coords = fromCoordSystem(this, coords, mode || "page");
4296
+ return coordsChar(this, coords.left, coords.top);
4297
+ },
4298
+
4299
+ lineAtHeight: function(height, mode) {
4300
+ height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top;
4301
+ return lineAtHeight(this.doc, height + this.display.viewOffset);
4302
+ },
4303
+ heightAtLine: function(line, mode) {
4304
+ var end = false, last = this.doc.first + this.doc.size - 1;
4305
+ if (line < this.doc.first) line = this.doc.first;
4306
+ else if (line > last) { line = last; end = true; }
4307
+ var lineObj = getLine(this.doc, line);
4308
+ return intoCoordSystem(this, lineObj, {top: 0, left: 0}, mode || "page").top +
4309
+ (end ? this.doc.height - heightAtLine(lineObj) : 0);
4310
+ },
4311
+
4312
+ defaultTextHeight: function() { return textHeight(this.display); },
4313
+ defaultCharWidth: function() { return charWidth(this.display); },
4314
+
4315
+ setGutterMarker: methodOp(function(line, gutterID, value) {
4316
+ return changeLine(this.doc, line, "gutter", function(line) {
4317
+ var markers = line.gutterMarkers || (line.gutterMarkers = {});
4318
+ markers[gutterID] = value;
4319
+ if (!value && isEmpty(markers)) line.gutterMarkers = null;
4320
+ return true;
4321
+ });
4322
+ }),
4323
+
4324
+ clearGutter: methodOp(function(gutterID) {
4325
+ var cm = this, doc = cm.doc, i = doc.first;
4326
+ doc.iter(function(line) {
4327
+ if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
4328
+ line.gutterMarkers[gutterID] = null;
4329
+ regLineChange(cm, i, "gutter");
4330
+ if (isEmpty(line.gutterMarkers)) line.gutterMarkers = null;
4331
+ }
4332
+ ++i;
4333
+ });
4334
+ }),
4335
+
4336
+ addLineWidget: methodOp(function(handle, node, options) {
4337
+ return addLineWidget(this, handle, node, options);
4338
+ }),
4339
+
4340
+ removeLineWidget: function(widget) { widget.clear(); },
4341
+
4342
+ lineInfo: function(line) {
4343
+ if (typeof line == "number") {
4344
+ if (!isLine(this.doc, line)) return null;
4345
+ var n = line;
4346
+ line = getLine(this.doc, line);
4347
+ if (!line) return null;
4348
+ } else {
4349
+ var n = lineNo(line);
4350
+ if (n == null) return null;
4351
+ }
4352
+ return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
4353
+ textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
4354
+ widgets: line.widgets};
4355
+ },
4356
+
4357
+ getViewport: function() { return {from: this.display.viewFrom, to: this.display.viewTo};},
4358
+
4359
+ addWidget: function(pos, node, scroll, vert, horiz) {
4360
+ var display = this.display;
4361
+ pos = cursorCoords(this, clipPos(this.doc, pos));
4362
+ var top = pos.bottom, left = pos.left;
4363
+ node.style.position = "absolute";
4364
+ node.setAttribute("cm-ignore-events", "true");
4365
+ display.sizer.appendChild(node);
4366
+ if (vert == "over") {
4367
+ top = pos.top;
4368
+ } else if (vert == "above" || vert == "near") {
4369
+ var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),
4370
+ hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth);
4371
+ // Default to positioning above (if specified and possible); otherwise default to positioning below
4372
+ if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight)
4373
+ top = pos.top - node.offsetHeight;
4374
+ else if (pos.bottom + node.offsetHeight <= vspace)
4375
+ top = pos.bottom;
4376
+ if (left + node.offsetWidth > hspace)
4377
+ left = hspace - node.offsetWidth;
4378
+ }
4379
+ node.style.top = top + "px";
4380
+ node.style.left = node.style.right = "";
4381
+ if (horiz == "right") {
4382
+ left = display.sizer.clientWidth - node.offsetWidth;
4383
+ node.style.right = "0px";
4384
+ } else {
4385
+ if (horiz == "left") left = 0;
4386
+ else if (horiz == "middle") left = (display.sizer.clientWidth - node.offsetWidth) / 2;
4387
+ node.style.left = left + "px";
4388
+ }
4389
+ if (scroll)
4390
+ scrollIntoView(this, left, top, left + node.offsetWidth, top + node.offsetHeight);
4391
+ },
4392
+
4393
+ triggerOnKeyDown: methodOp(onKeyDown),
4394
+ triggerOnKeyPress: methodOp(onKeyPress),
4395
+ triggerOnKeyUp: onKeyUp,
4396
+
4397
+ execCommand: function(cmd) {
4398
+ if (commands.hasOwnProperty(cmd))
4399
+ return commands[cmd](this);
4400
+ },
4401
+
4402
+ findPosH: function(from, amount, unit, visually) {
4403
+ var dir = 1;
4404
+ if (amount < 0) { dir = -1; amount = -amount; }
4405
+ for (var i = 0, cur = clipPos(this.doc, from); i < amount; ++i) {
4406
+ cur = findPosH(this.doc, cur, dir, unit, visually);
4407
+ if (cur.hitSide) break;
4408
+ }
4409
+ return cur;
4410
+ },
4411
+
4412
+ moveH: methodOp(function(dir, unit) {
4413
+ var cm = this;
4414
+ cm.extendSelectionsBy(function(range) {
4415
+ if (cm.display.shift || cm.doc.extend || range.empty())
4416
+ return findPosH(cm.doc, range.head, dir, unit, cm.options.rtlMoveVisually);
4417
+ else
4418
+ return dir < 0 ? range.from() : range.to();
4419
+ }, sel_move);
4420
+ }),
4421
+
4422
+ deleteH: methodOp(function(dir, unit) {
4423
+ var sel = this.doc.sel, doc = this.doc;
4424
+ if (sel.somethingSelected())
4425
+ doc.replaceSelection("", null, "+delete");
4426
+ else
4427
+ deleteNearSelection(this, function(range) {
4428
+ var other = findPosH(doc, range.head, dir, unit, false);
4429
+ return dir < 0 ? {from: other, to: range.head} : {from: range.head, to: other};
4430
+ });
4431
+ }),
4432
+
4433
+ findPosV: function(from, amount, unit, goalColumn) {
4434
+ var dir = 1, x = goalColumn;
4435
+ if (amount < 0) { dir = -1; amount = -amount; }
4436
+ for (var i = 0, cur = clipPos(this.doc, from); i < amount; ++i) {
4437
+ var coords = cursorCoords(this, cur, "div");
4438
+ if (x == null) x = coords.left;
4439
+ else coords.left = x;
4440
+ cur = findPosV(this, coords, dir, unit);
4441
+ if (cur.hitSide) break;
4442
+ }
4443
+ return cur;
4444
+ },
4445
+
4446
+ moveV: methodOp(function(dir, unit) {
4447
+ var cm = this, doc = this.doc, goals = [];
4448
+ var collapse = !cm.display.shift && !doc.extend && doc.sel.somethingSelected();
4449
+ doc.extendSelectionsBy(function(range) {
4450
+ if (collapse)
4451
+ return dir < 0 ? range.from() : range.to();
4452
+ var headPos = cursorCoords(cm, range.head, "div");
4453
+ if (range.goalColumn != null) headPos.left = range.goalColumn;
4454
+ goals.push(headPos.left);
4455
+ var pos = findPosV(cm, headPos, dir, unit);
4456
+ if (unit == "page" && range == doc.sel.primary())
4457
+ addToScrollPos(cm, null, charCoords(cm, pos, "div").top - headPos.top);
4458
+ return pos;
4459
+ }, sel_move);
4460
+ if (goals.length) for (var i = 0; i < doc.sel.ranges.length; i++)
4461
+ doc.sel.ranges[i].goalColumn = goals[i];
4462
+ }),
4463
+
4464
+ // Find the word at the given position (as returned by coordsChar).
4465
+ findWordAt: function(pos) {
4466
+ var doc = this.doc, line = getLine(doc, pos.line).text;
4467
+ var start = pos.ch, end = pos.ch;
4468
+ if (line) {
4469
+ var helper = this.getHelper(pos, "wordChars");
4470
+ if ((pos.xRel < 0 || end == line.length) && start) --start; else ++end;
4471
+ var startChar = line.charAt(start);
4472
+ var check = isWordChar(startChar, helper)
4473
+ ? function(ch) { return isWordChar(ch, helper); }
4474
+ : /\s/.test(startChar) ? function(ch) {return /\s/.test(ch);}
4475
+ : function(ch) {return !/\s/.test(ch) && !isWordChar(ch);};
4476
+ while (start > 0 && check(line.charAt(start - 1))) --start;
4477
+ while (end < line.length && check(line.charAt(end))) ++end;
4478
+ }
4479
+ return new Range(Pos(pos.line, start), Pos(pos.line, end));
4480
+ },
4481
+
4482
+ toggleOverwrite: function(value) {
4483
+ if (value != null && value == this.state.overwrite) return;
4484
+ if (this.state.overwrite = !this.state.overwrite)
4485
+ addClass(this.display.cursorDiv, "CodeMirror-overwrite");
4486
+ else
4487
+ rmClass(this.display.cursorDiv, "CodeMirror-overwrite");
4488
+
4489
+ signal(this, "overwriteToggle", this, this.state.overwrite);
4490
+ },
4491
+ hasFocus: function() { return activeElt() == this.display.input; },
4492
+
4493
+ scrollTo: methodOp(function(x, y) {
4494
+ if (x != null || y != null) resolveScrollToPos(this);
4495
+ if (x != null) this.curOp.scrollLeft = x;
4496
+ if (y != null) this.curOp.scrollTop = y;
4497
+ }),
4498
+ getScrollInfo: function() {
4499
+ var scroller = this.display.scroller;
4500
+ return {left: scroller.scrollLeft, top: scroller.scrollTop,
4501
+ height: scroller.scrollHeight - scrollGap(this) - this.display.barHeight,
4502
+ width: scroller.scrollWidth - scrollGap(this) - this.display.barWidth,
4503
+ clientHeight: displayHeight(this), clientWidth: displayWidth(this)};
4504
+ },
4505
+
4506
+ scrollIntoView: methodOp(function(range, margin) {
4507
+ if (range == null) {
4508
+ range = {from: this.doc.sel.primary().head, to: null};
4509
+ if (margin == null) margin = this.options.cursorScrollMargin;
4510
+ } else if (typeof range == "number") {
4511
+ range = {from: Pos(range, 0), to: null};
4512
+ } else if (range.from == null) {
4513
+ range = {from: range, to: null};
4514
+ }
4515
+ if (!range.to) range.to = range.from;
4516
+ range.margin = margin || 0;
4517
+
4518
+ if (range.from.line != null) {
4519
+ resolveScrollToPos(this);
4520
+ this.curOp.scrollToPos = range;
4521
+ } else {
4522
+ var sPos = calculateScrollPos(this, Math.min(range.from.left, range.to.left),
4523
+ Math.min(range.from.top, range.to.top) - range.margin,
4524
+ Math.max(range.from.right, range.to.right),
4525
+ Math.max(range.from.bottom, range.to.bottom) + range.margin);
4526
+ this.scrollTo(sPos.scrollLeft, sPos.scrollTop);
4527
+ }
4528
+ }),
4529
+
4530
+ setSize: methodOp(function(width, height) {
4531
+ var cm = this;
4532
+ function interpret(val) {
4533
+ return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val;
4534
+ }
4535
+ if (width != null) cm.display.wrapper.style.width = interpret(width);
4536
+ if (height != null) cm.display.wrapper.style.height = interpret(height);
4537
+ if (cm.options.lineWrapping) clearLineMeasurementCache(this);
4538
+ var lineNo = cm.display.viewFrom;
4539
+ cm.doc.iter(lineNo, cm.display.viewTo, function(line) {
4540
+ if (line.widgets) for (var i = 0; i < line.widgets.length; i++)
4541
+ if (line.widgets[i].noHScroll) { regLineChange(cm, lineNo, "widget"); break; }
4542
+ ++lineNo;
4543
+ });
4544
+ cm.curOp.forceUpdate = true;
4545
+ signal(cm, "refresh", this);
4546
+ }),
4547
+
4548
+ operation: function(f){return runInOp(this, f);},
4549
+
4550
+ refresh: methodOp(function() {
4551
+ var oldHeight = this.display.cachedTextHeight;
4552
+ regChange(this);
4553
+ this.curOp.forceUpdate = true;
4554
+ clearCaches(this);
4555
+ this.scrollTo(this.doc.scrollLeft, this.doc.scrollTop);
4556
+ updateGutterSpace(this);
4557
+ if (oldHeight == null || Math.abs(oldHeight - textHeight(this.display)) > .5)
4558
+ estimateLineHeights(this);
4559
+ signal(this, "refresh", this);
4560
+ }),
4561
+
4562
+ swapDoc: methodOp(function(doc) {
4563
+ var old = this.doc;
4564
+ old.cm = null;
4565
+ attachDoc(this, doc);
4566
+ clearCaches(this);
4567
+ resetInput(this);
4568
+ this.scrollTo(doc.scrollLeft, doc.scrollTop);
4569
+ this.curOp.forceScroll = true;
4570
+ signalLater(this, "swapDoc", this, old);
4571
+ return old;
4572
+ }),
4573
+
4574
+ getInputField: function(){return this.display.input;},
4575
+ getWrapperElement: function(){return this.display.wrapper;},
4576
+ getScrollerElement: function(){return this.display.scroller;},
4577
+ getGutterElement: function(){return this.display.gutters;}
4578
+ };
4579
+ eventMixin(CodeMirror);
4580
+
4581
+ // OPTION DEFAULTS
4582
+
4583
+ // The default configuration options.
4584
+ var defaults = CodeMirror.defaults = {};
4585
+ // Functions to run when options are changed.
4586
+ var optionHandlers = CodeMirror.optionHandlers = {};
4587
+
4588
+ function option(name, deflt, handle, notOnInit) {
4589
+ CodeMirror.defaults[name] = deflt;
4590
+ if (handle) optionHandlers[name] =
4591
+ notOnInit ? function(cm, val, old) {if (old != Init) handle(cm, val, old);} : handle;
4592
+ }
4593
+
4594
+ // Passed to option handlers when there is no old value.
4595
+ var Init = CodeMirror.Init = {toString: function(){return "CodeMirror.Init";}};
4596
+
4597
+ // These two are, on init, called from the constructor because they
4598
+ // have to be initialized before the editor can start at all.
4599
+ option("value", "", function(cm, val) {
4600
+ cm.setValue(val);
4601
+ }, true);
4602
+ option("mode", null, function(cm, val) {
4603
+ cm.doc.modeOption = val;
4604
+ loadMode(cm);
4605
+ }, true);
4606
+
4607
+ option("indentUnit", 2, loadMode, true);
4608
+ option("indentWithTabs", false);
4609
+ option("smartIndent", true);
4610
+ option("tabSize", 4, function(cm) {
4611
+ resetModeState(cm);
4612
+ clearCaches(cm);
4613
+ regChange(cm);
4614
+ }, true);
4615
+ option("specialChars", /[\t\u0000-\u0019\u00ad\u200b-\u200f\u2028\u2029\ufeff]/g, function(cm, val) {
4616
+ cm.options.specialChars = new RegExp(val.source + (val.test("\t") ? "" : "|\t"), "g");
4617
+ cm.refresh();
4618
+ }, true);
4619
+ option("specialCharPlaceholder", defaultSpecialCharPlaceholder, function(cm) {cm.refresh();}, true);
4620
+ option("electricChars", true);
4621
+ option("rtlMoveVisually", !windows);
4622
+ option("wholeLineUpdateBefore", true);
4623
+
4624
+ option("theme", "default", function(cm) {
4625
+ themeChanged(cm);
4626
+ guttersChanged(cm);
4627
+ }, true);
4628
+ option("keyMap", "default", function(cm, val, old) {
4629
+ var next = getKeyMap(val);
4630
+ var prev = old != CodeMirror.Init && getKeyMap(old);
4631
+ if (prev && prev.detach) prev.detach(cm, next);
4632
+ if (next.attach) next.attach(cm, prev || null);
4633
+ });
4634
+ option("extraKeys", null);
4635
+
4636
+ option("lineWrapping", false, wrappingChanged, true);
4637
+ option("gutters", [], function(cm) {
4638
+ setGuttersForLineNumbers(cm.options);
4639
+ guttersChanged(cm);
4640
+ }, true);
4641
+ option("fixedGutter", true, function(cm, val) {
4642
+ cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0";
4643
+ cm.refresh();
4644
+ }, true);
4645
+ option("coverGutterNextToScrollbar", false, function(cm) {updateScrollbars(cm);}, true);
4646
+ option("scrollbarStyle", "native", function(cm) {
4647
+ initScrollbars(cm);
4648
+ updateScrollbars(cm);
4649
+ cm.display.scrollbars.setScrollTop(cm.doc.scrollTop);
4650
+ cm.display.scrollbars.setScrollLeft(cm.doc.scrollLeft);
4651
+ }, true);
4652
+ option("lineNumbers", false, function(cm) {
4653
+ setGuttersForLineNumbers(cm.options);
4654
+ guttersChanged(cm);
4655
+ }, true);
4656
+ option("firstLineNumber", 1, guttersChanged, true);
4657
+ option("lineNumberFormatter", function(integer) {return integer;}, guttersChanged, true);
4658
+ option("showCursorWhenSelecting", false, updateSelection, true);
4659
+
4660
+ option("resetSelectionOnContextMenu", true);
4661
+
4662
+ option("readOnly", false, function(cm, val) {
4663
+ if (val == "nocursor") {
4664
+ onBlur(cm);
4665
+ cm.display.input.blur();
4666
+ cm.display.disabled = true;
4667
+ } else {
4668
+ cm.display.disabled = false;
4669
+ if (!val) resetInput(cm);
4670
+ }
4671
+ });
4672
+ option("disableInput", false, function(cm, val) {if (!val) resetInput(cm);}, true);
4673
+ option("dragDrop", true);
4674
+
4675
+ option("cursorBlinkRate", 530);
4676
+ option("cursorScrollMargin", 0);
4677
+ option("cursorHeight", 1, updateSelection, true);
4678
+ option("singleCursorHeightPerLine", true, updateSelection, true);
4679
+ option("workTime", 100);
4680
+ option("workDelay", 100);
4681
+ option("flattenSpans", true, resetModeState, true);
4682
+ option("addModeClass", false, resetModeState, true);
4683
+ option("pollInterval", 100);
4684
+ option("undoDepth", 200, function(cm, val){cm.doc.history.undoDepth = val;});
4685
+ option("historyEventDelay", 1250);
4686
+ option("viewportMargin", 10, function(cm){cm.refresh();}, true);
4687
+ option("maxHighlightLength", 10000, resetModeState, true);
4688
+ option("moveInputWithCursor", true, function(cm, val) {
4689
+ if (!val) cm.display.inputDiv.style.top = cm.display.inputDiv.style.left = 0;
4690
+ });
4691
+
4692
+ option("tabindex", null, function(cm, val) {
4693
+ cm.display.input.tabIndex = val || "";
4694
+ });
4695
+ option("autofocus", null);
4696
+
4697
+ // MODE DEFINITION AND QUERYING
4698
+
4699
+ // Known modes, by name and by MIME
4700
+ var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {};
4701
+
4702
+ // Extra arguments are stored as the mode's dependencies, which is
4703
+ // used by (legacy) mechanisms like loadmode.js to automatically
4704
+ // load a mode. (Preferred mechanism is the require/define calls.)
4705
+ CodeMirror.defineMode = function(name, mode) {
4706
+ if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name;
4707
+ if (arguments.length > 2)
4708
+ mode.dependencies = Array.prototype.slice.call(arguments, 2);
4709
+ modes[name] = mode;
4710
+ };
4711
+
4712
+ CodeMirror.defineMIME = function(mime, spec) {
4713
+ mimeModes[mime] = spec;
4714
+ };
4715
+
4716
+ // Given a MIME type, a {name, ...options} config object, or a name
4717
+ // string, return a mode config object.
4718
+ CodeMirror.resolveMode = function(spec) {
4719
+ if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
4720
+ spec = mimeModes[spec];
4721
+ } else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
4722
+ var found = mimeModes[spec.name];
4723
+ if (typeof found == "string") found = {name: found};
4724
+ spec = createObj(found, spec);
4725
+ spec.name = found.name;
4726
+ } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
4727
+ return CodeMirror.resolveMode("application/xml");
4728
+ }
4729
+ if (typeof spec == "string") return {name: spec};
4730
+ else return spec || {name: "null"};
4731
+ };
4732
+
4733
+ // Given a mode spec (anything that resolveMode accepts), find and
4734
+ // initialize an actual mode object.
4735
+ CodeMirror.getMode = function(options, spec) {
4736
+ var spec = CodeMirror.resolveMode(spec);
4737
+ var mfactory = modes[spec.name];
4738
+ if (!mfactory) return CodeMirror.getMode(options, "text/plain");
4739
+ var modeObj = mfactory(options, spec);
4740
+ if (modeExtensions.hasOwnProperty(spec.name)) {
4741
+ var exts = modeExtensions[spec.name];
4742
+ for (var prop in exts) {
4743
+ if (!exts.hasOwnProperty(prop)) continue;
4744
+ if (modeObj.hasOwnProperty(prop)) modeObj["_" + prop] = modeObj[prop];
4745
+ modeObj[prop] = exts[prop];
4746
+ }
4747
+ }
4748
+ modeObj.name = spec.name;
4749
+ if (spec.helperType) modeObj.helperType = spec.helperType;
4750
+ if (spec.modeProps) for (var prop in spec.modeProps)
4751
+ modeObj[prop] = spec.modeProps[prop];
4752
+
4753
+ return modeObj;
4754
+ };
4755
+
4756
+ // Minimal default mode.
4757
+ CodeMirror.defineMode("null", function() {
4758
+ return {token: function(stream) {stream.skipToEnd();}};
4759
+ });
4760
+ CodeMirror.defineMIME("text/plain", "null");
4761
+
4762
+ // This can be used to attach properties to mode objects from
4763
+ // outside the actual mode definition.
4764
+ var modeExtensions = CodeMirror.modeExtensions = {};
4765
+ CodeMirror.extendMode = function(mode, properties) {
4766
+ var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
4767
+ copyObj(properties, exts);
4768
+ };
4769
+
4770
+ // EXTENSIONS
4771
+
4772
+ CodeMirror.defineExtension = function(name, func) {
4773
+ CodeMirror.prototype[name] = func;
4774
+ };
4775
+ CodeMirror.defineDocExtension = function(name, func) {
4776
+ Doc.prototype[name] = func;
4777
+ };
4778
+ CodeMirror.defineOption = option;
4779
+
4780
+ var initHooks = [];
4781
+ CodeMirror.defineInitHook = function(f) {initHooks.push(f);};
4782
+
4783
+ var helpers = CodeMirror.helpers = {};
4784
+ CodeMirror.registerHelper = function(type, name, value) {
4785
+ if (!helpers.hasOwnProperty(type)) helpers[type] = CodeMirror[type] = {_global: []};
4786
+ helpers[type][name] = value;
4787
+ };
4788
+ CodeMirror.registerGlobalHelper = function(type, name, predicate, value) {
4789
+ CodeMirror.registerHelper(type, name, value);
4790
+ helpers[type]._global.push({pred: predicate, val: value});
4791
+ };
4792
+
4793
+ // MODE STATE HANDLING
4794
+
4795
+ // Utility functions for working with state. Exported because nested
4796
+ // modes need to do this for their inner modes.
4797
+
4798
+ var copyState = CodeMirror.copyState = function(mode, state) {
4799
+ if (state === true) return state;
4800
+ if (mode.copyState) return mode.copyState(state);
4801
+ var nstate = {};
4802
+ for (var n in state) {
4803
+ var val = state[n];
4804
+ if (val instanceof Array) val = val.concat([]);
4805
+ nstate[n] = val;
4806
+ }
4807
+ return nstate;
4808
+ };
4809
+
4810
+ var startState = CodeMirror.startState = function(mode, a1, a2) {
4811
+ return mode.startState ? mode.startState(a1, a2) : true;
4812
+ };
4813
+
4814
+ // Given a mode and a state (for that mode), find the inner mode and
4815
+ // state at the position that the state refers to.
4816
+ CodeMirror.innerMode = function(mode, state) {
4817
+ while (mode.innerMode) {
4818
+ var info = mode.innerMode(state);
4819
+ if (!info || info.mode == mode) break;
4820
+ state = info.state;
4821
+ mode = info.mode;
4822
+ }
4823
+ return info || {mode: mode, state: state};
4824
+ };
4825
+
4826
+ // STANDARD COMMANDS
4827
+
4828
+ // Commands are parameter-less actions that can be performed on an
4829
+ // editor, mostly used for keybindings.
4830
+ var commands = CodeMirror.commands = {
4831
+ selectAll: function(cm) {cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()), sel_dontScroll);},
4832
+ singleSelection: function(cm) {
4833
+ cm.setSelection(cm.getCursor("anchor"), cm.getCursor("head"), sel_dontScroll);
4834
+ },
4835
+ killLine: function(cm) {
4836
+ deleteNearSelection(cm, function(range) {
4837
+ if (range.empty()) {
4838
+ var len = getLine(cm.doc, range.head.line).text.length;
4839
+ if (range.head.ch == len && range.head.line < cm.lastLine())
4840
+ return {from: range.head, to: Pos(range.head.line + 1, 0)};
4841
+ else
4842
+ return {from: range.head, to: Pos(range.head.line, len)};
4843
+ } else {
4844
+ return {from: range.from(), to: range.to()};
4845
+ }
4846
+ });
4847
+ },
4848
+ deleteLine: function(cm) {
4849
+ deleteNearSelection(cm, function(range) {
4850
+ return {from: Pos(range.from().line, 0),
4851
+ to: clipPos(cm.doc, Pos(range.to().line + 1, 0))};
4852
+ });
4853
+ },
4854
+ delLineLeft: function(cm) {
4855
+ deleteNearSelection(cm, function(range) {
4856
+ return {from: Pos(range.from().line, 0), to: range.from()};
4857
+ });
4858
+ },
4859
+ delWrappedLineLeft: function(cm) {
4860
+ deleteNearSelection(cm, function(range) {
4861
+ var top = cm.charCoords(range.head, "div").top + 5;
4862
+ var leftPos = cm.coordsChar({left: 0, top: top}, "div");
4863
+ return {from: leftPos, to: range.from()};
4864
+ });
4865
+ },
4866
+ delWrappedLineRight: function(cm) {
4867
+ deleteNearSelection(cm, function(range) {
4868
+ var top = cm.charCoords(range.head, "div").top + 5;
4869
+ var rightPos = cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div");
4870
+ return {from: range.from(), to: rightPos };
4871
+ });
4872
+ },
4873
+ undo: function(cm) {cm.undo();},
4874
+ redo: function(cm) {cm.redo();},
4875
+ undoSelection: function(cm) {cm.undoSelection();},
4876
+ redoSelection: function(cm) {cm.redoSelection();},
4877
+ goDocStart: function(cm) {cm.extendSelection(Pos(cm.firstLine(), 0));},
4878
+ goDocEnd: function(cm) {cm.extendSelection(Pos(cm.lastLine()));},
4879
+ goLineStart: function(cm) {
4880
+ cm.extendSelectionsBy(function(range) { return lineStart(cm, range.head.line); },
4881
+ {origin: "+move", bias: 1});
4882
+ },
4883
+ goLineStartSmart: function(cm) {
4884
+ cm.extendSelectionsBy(function(range) {
4885
+ return lineStartSmart(cm, range.head);
4886
+ }, {origin: "+move", bias: 1});
4887
+ },
4888
+ goLineEnd: function(cm) {
4889
+ cm.extendSelectionsBy(function(range) { return lineEnd(cm, range.head.line); },
4890
+ {origin: "+move", bias: -1});
4891
+ },
4892
+ goLineRight: function(cm) {
4893
+ cm.extendSelectionsBy(function(range) {
4894
+ var top = cm.charCoords(range.head, "div").top + 5;
4895
+ return cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div");
4896
+ }, sel_move);
4897
+ },
4898
+ goLineLeft: function(cm) {
4899
+ cm.extendSelectionsBy(function(range) {
4900
+ var top = cm.charCoords(range.head, "div").top + 5;
4901
+ return cm.coordsChar({left: 0, top: top}, "div");
4902
+ }, sel_move);
4903
+ },
4904
+ goLineLeftSmart: function(cm) {
4905
+ cm.extendSelectionsBy(function(range) {
4906
+ var top = cm.charCoords(range.head, "div").top + 5;
4907
+ var pos = cm.coordsChar({left: 0, top: top}, "div");
4908
+ if (pos.ch < cm.getLine(pos.line).search(/\S/)) return lineStartSmart(cm, range.head);
4909
+ return pos;
4910
+ }, sel_move);
4911
+ },
4912
+ goLineUp: function(cm) {cm.moveV(-1, "line");},
4913
+ goLineDown: function(cm) {cm.moveV(1, "line");},
4914
+ goPageUp: function(cm) {cm.moveV(-1, "page");},
4915
+ goPageDown: function(cm) {cm.moveV(1, "page");},
4916
+ goCharLeft: function(cm) {cm.moveH(-1, "char");},
4917
+ goCharRight: function(cm) {cm.moveH(1, "char");},
4918
+ goColumnLeft: function(cm) {cm.moveH(-1, "column");},
4919
+ goColumnRight: function(cm) {cm.moveH(1, "column");},
4920
+ goWordLeft: function(cm) {cm.moveH(-1, "word");},
4921
+ goGroupRight: function(cm) {cm.moveH(1, "group");},
4922
+ goGroupLeft: function(cm) {cm.moveH(-1, "group");},
4923
+ goWordRight: function(cm) {cm.moveH(1, "word");},
4924
+ delCharBefore: function(cm) {cm.deleteH(-1, "char");},
4925
+ delCharAfter: function(cm) {cm.deleteH(1, "char");},
4926
+ delWordBefore: function(cm) {cm.deleteH(-1, "word");},
4927
+ delWordAfter: function(cm) {cm.deleteH(1, "word");},
4928
+ delGroupBefore: function(cm) {cm.deleteH(-1, "group");},
4929
+ delGroupAfter: function(cm) {cm.deleteH(1, "group");},
4930
+ indentAuto: function(cm) {cm.indentSelection("smart");},
4931
+ indentMore: function(cm) {cm.indentSelection("add");},
4932
+ indentLess: function(cm) {cm.indentSelection("subtract");},
4933
+ insertTab: function(cm) {cm.replaceSelection("\t");},
4934
+ insertSoftTab: function(cm) {
4935
+ var spaces = [], ranges = cm.listSelections(), tabSize = cm.options.tabSize;
4936
+ for (var i = 0; i < ranges.length; i++) {
4937
+ var pos = ranges[i].from();
4938
+ var col = countColumn(cm.getLine(pos.line), pos.ch, tabSize);
4939
+ spaces.push(new Array(tabSize - col % tabSize + 1).join(" "));
4940
+ }
4941
+ cm.replaceSelections(spaces);
4942
+ },
4943
+ defaultTab: function(cm) {
4944
+ if (cm.somethingSelected()) cm.indentSelection("add");
4945
+ else cm.execCommand("insertTab");
4946
+ },
4947
+ transposeChars: function(cm) {
4948
+ runInOp(cm, function() {
4949
+ var ranges = cm.listSelections(), newSel = [];
4950
+ for (var i = 0; i < ranges.length; i++) {
4951
+ var cur = ranges[i].head, line = getLine(cm.doc, cur.line).text;
4952
+ if (line) {
4953
+ if (cur.ch == line.length) cur = new Pos(cur.line, cur.ch - 1);
4954
+ if (cur.ch > 0) {
4955
+ cur = new Pos(cur.line, cur.ch + 1);
4956
+ cm.replaceRange(line.charAt(cur.ch - 1) + line.charAt(cur.ch - 2),
4957
+ Pos(cur.line, cur.ch - 2), cur, "+transpose");
4958
+ } else if (cur.line > cm.doc.first) {
4959
+ var prev = getLine(cm.doc, cur.line - 1).text;
4960
+ if (prev)
4961
+ cm.replaceRange(line.charAt(0) + "\n" + prev.charAt(prev.length - 1),
4962
+ Pos(cur.line - 1, prev.length - 1), Pos(cur.line, 1), "+transpose");
4963
+ }
4964
+ }
4965
+ newSel.push(new Range(cur, cur));
4966
+ }
4967
+ cm.setSelections(newSel);
4968
+ });
4969
+ },
4970
+ newlineAndIndent: function(cm) {
4971
+ runInOp(cm, function() {
4972
+ var len = cm.listSelections().length;
4973
+ for (var i = 0; i < len; i++) {
4974
+ var range = cm.listSelections()[i];
4975
+ cm.replaceRange("\n", range.anchor, range.head, "+input");
4976
+ cm.indentLine(range.from().line + 1, null, true);
4977
+ ensureCursorVisible(cm);
4978
+ }
4979
+ });
4980
+ },
4981
+ toggleOverwrite: function(cm) {cm.toggleOverwrite();}
4982
+ };
4983
+
4984
+
4985
+ // STANDARD KEYMAPS
4986
+
4987
+ var keyMap = CodeMirror.keyMap = {};
4988
+
4989
+ keyMap.basic = {
4990
+ "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
4991
+ "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
4992
+ "Delete": "delCharAfter", "Backspace": "delCharBefore", "Shift-Backspace": "delCharBefore",
4993
+ "Tab": "defaultTab", "Shift-Tab": "indentAuto",
4994
+ "Enter": "newlineAndIndent", "Insert": "toggleOverwrite",
4995
+ "Esc": "singleSelection"
4996
+ };
4997
+ // Note that the save and find-related commands aren't defined by
4998
+ // default. User code or addons can define them. Unknown commands
4999
+ // are simply ignored.
5000
+ keyMap.pcDefault = {
5001
+ "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
5002
+ "Ctrl-Home": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Up": "goLineUp", "Ctrl-Down": "goLineDown",
5003
+ "Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
5004
+ "Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find",
5005
+ "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
5006
+ "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
5007
+ "Ctrl-U": "undoSelection", "Shift-Ctrl-U": "redoSelection", "Alt-U": "redoSelection",
5008
+ fallthrough: "basic"
5009
+ };
5010
+ // Very basic readline/emacs-style bindings, which are standard on Mac.
5011
+ keyMap.emacsy = {
5012
+ "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
5013
+ "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
5014
+ "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
5015
+ "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars"
5016
+ };
5017
+ keyMap.macDefault = {
5018
+ "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
5019
+ "Cmd-Home": "goDocStart", "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
5020
+ "Alt-Right": "goGroupRight", "Cmd-Left": "goLineLeft", "Cmd-Right": "goLineRight", "Alt-Backspace": "delGroupBefore",
5021
+ "Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find",
5022
+ "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
5023
+ "Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delWrappedLineLeft", "Cmd-Delete": "delWrappedLineRight",
5024
+ "Cmd-U": "undoSelection", "Shift-Cmd-U": "redoSelection", "Ctrl-Up": "goDocStart", "Ctrl-Down": "goDocEnd",
5025
+ fallthrough: ["basic", "emacsy"]
5026
+ };
5027
+ keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
5028
+
5029
+ // KEYMAP DISPATCH
5030
+
5031
+ function normalizeKeyName(name) {
5032
+ var parts = name.split(/-(?!$)/), name = parts[parts.length - 1];
5033
+ var alt, ctrl, shift, cmd;
5034
+ for (var i = 0; i < parts.length - 1; i++) {
5035
+ var mod = parts[i];
5036
+ if (/^(cmd|meta|m)$/i.test(mod)) cmd = true;
5037
+ else if (/^a(lt)?$/i.test(mod)) alt = true;
5038
+ else if (/^(c|ctrl|control)$/i.test(mod)) ctrl = true;
5039
+ else if (/^s(hift)$/i.test(mod)) shift = true;
5040
+ else throw new Error("Unrecognized modifier name: " + mod);
5041
+ }
5042
+ if (alt) name = "Alt-" + name;
5043
+ if (ctrl) name = "Ctrl-" + name;
5044
+ if (cmd) name = "Cmd-" + name;
5045
+ if (shift) name = "Shift-" + name;
5046
+ return name;
5047
+ }
5048
+
5049
+ // This is a kludge to keep keymaps mostly working as raw objects
5050
+ // (backwards compatibility) while at the same time support features
5051
+ // like normalization and multi-stroke key bindings. It compiles a
5052
+ // new normalized keymap, and then updates the old object to reflect
5053
+ // this.
5054
+ CodeMirror.normalizeKeyMap = function(keymap) {
5055
+ var copy = {};
5056
+ for (var keyname in keymap) if (keymap.hasOwnProperty(keyname)) {
5057
+ var value = keymap[keyname];
5058
+ if (/^(name|fallthrough|(de|at)tach)$/.test(keyname)) continue;
5059
+ if (value == "...") { delete keymap[keyname]; continue; }
5060
+
5061
+ var keys = map(keyname.split(" "), normalizeKeyName);
5062
+ for (var i = 0; i < keys.length; i++) {
5063
+ var val, name;
5064
+ if (i == keys.length - 1) {
5065
+ name = keyname;
5066
+ val = value;
5067
+ } else {
5068
+ name = keys.slice(0, i + 1).join(" ");
5069
+ val = "...";
5070
+ }
5071
+ var prev = copy[name];
5072
+ if (!prev) copy[name] = val;
5073
+ else if (prev != val) throw new Error("Inconsistent bindings for " + name);
5074
+ }
5075
+ delete keymap[keyname];
5076
+ }
5077
+ for (var prop in copy) keymap[prop] = copy[prop];
5078
+ return keymap;
5079
+ };
5080
+
5081
+ var lookupKey = CodeMirror.lookupKey = function(key, map, handle, context) {
5082
+ map = getKeyMap(map);
5083
+ var found = map.call ? map.call(key, context) : map[key];
5084
+ if (found === false) return "nothing";
5085
+ if (found === "...") return "multi";
5086
+ if (found != null && handle(found)) return "handled";
5087
+
5088
+ if (map.fallthrough) {
5089
+ if (Object.prototype.toString.call(map.fallthrough) != "[object Array]")
5090
+ return lookupKey(key, map.fallthrough, handle, context);
5091
+ for (var i = 0; i < map.fallthrough.length; i++) {
5092
+ var result = lookupKey(key, map.fallthrough[i], handle, context);
5093
+ if (result) return result;
5094
+ }
5095
+ }
5096
+ };
5097
+
5098
+ // Modifier key presses don't count as 'real' key presses for the
5099
+ // purpose of keymap fallthrough.
5100
+ var isModifierKey = CodeMirror.isModifierKey = function(value) {
5101
+ var name = typeof value == "string" ? value : keyNames[value.keyCode];
5102
+ return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod";
5103
+ };
5104
+
5105
+ // Look up the name of a key as indicated by an event object.
5106
+ var keyName = CodeMirror.keyName = function(event, noShift) {
5107
+ if (presto && event.keyCode == 34 && event["char"]) return false;
5108
+ var base = keyNames[event.keyCode], name = base;
5109
+ if (name == null || event.altGraphKey) return false;
5110
+ if (event.altKey && base != "Alt") name = "Alt-" + name;
5111
+ if ((flipCtrlCmd ? event.metaKey : event.ctrlKey) && base != "Ctrl") name = "Ctrl-" + name;
5112
+ if ((flipCtrlCmd ? event.ctrlKey : event.metaKey) && base != "Cmd") name = "Cmd-" + name;
5113
+ if (!noShift && event.shiftKey && base != "Shift") name = "Shift-" + name;
5114
+ return name;
5115
+ };
5116
+
5117
+ function getKeyMap(val) {
5118
+ return typeof val == "string" ? keyMap[val] : val;
5119
+ }
5120
+
5121
+ // FROMTEXTAREA
5122
+
5123
+ CodeMirror.fromTextArea = function(textarea, options) {
5124
+ if (!options) options = {};
5125
+ options.value = textarea.value;
5126
+ if (!options.tabindex && textarea.tabindex)
5127
+ options.tabindex = textarea.tabindex;
5128
+ if (!options.placeholder && textarea.placeholder)
5129
+ options.placeholder = textarea.placeholder;
5130
+ // Set autofocus to true if this textarea is focused, or if it has
5131
+ // autofocus and no other element is focused.
5132
+ if (options.autofocus == null) {
5133
+ var hasFocus = activeElt();
5134
+ options.autofocus = hasFocus == textarea ||
5135
+ textarea.getAttribute("autofocus") != null && hasFocus == document.body;
5136
+ }
5137
+
5138
+ function save() {textarea.value = cm.getValue();}
5139
+ if (textarea.form) {
5140
+ on(textarea.form, "submit", save);
5141
+ // Deplorable hack to make the submit method do the right thing.
5142
+ if (!options.leaveSubmitMethodAlone) {
5143
+ var form = textarea.form, realSubmit = form.submit;
5144
+ try {
5145
+ var wrappedSubmit = form.submit = function() {
5146
+ save();
5147
+ form.submit = realSubmit;
5148
+ form.submit();
5149
+ form.submit = wrappedSubmit;
5150
+ };
5151
+ } catch(e) {}
5152
+ }
5153
+ }
5154
+
5155
+ textarea.style.display = "none";
5156
+ var cm = CodeMirror(function(node) {
5157
+ textarea.parentNode.insertBefore(node, textarea.nextSibling);
5158
+ }, options);
5159
+ cm.save = save;
5160
+ cm.getTextArea = function() { return textarea; };
5161
+ cm.toTextArea = function() {
5162
+ cm.toTextArea = isNaN; // Prevent this from being ran twice
5163
+ save();
5164
+ textarea.parentNode.removeChild(cm.getWrapperElement());
5165
+ textarea.style.display = "";
5166
+ if (textarea.form) {
5167
+ off(textarea.form, "submit", save);
5168
+ if (typeof textarea.form.submit == "function")
5169
+ textarea.form.submit = realSubmit;
5170
+ }
5171
+ };
5172
+ return cm;
5173
+ };
5174
+
5175
+ // STRING STREAM
5176
+
5177
+ // Fed to the mode parsers, provides helper functions to make
5178
+ // parsers more succinct.
5179
+
5180
+ var StringStream = CodeMirror.StringStream = function(string, tabSize) {
5181
+ this.pos = this.start = 0;
5182
+ this.string = string;
5183
+ this.tabSize = tabSize || 8;
5184
+ this.lastColumnPos = this.lastColumnValue = 0;
5185
+ this.lineStart = 0;
5186
+ };
5187
+
5188
+ StringStream.prototype = {
5189
+ eol: function() {return this.pos >= this.string.length;},
5190
+ sol: function() {return this.pos == this.lineStart;},
5191
+ peek: function() {return this.string.charAt(this.pos) || undefined;},
5192
+ next: function() {
5193
+ if (this.pos < this.string.length)
5194
+ return this.string.charAt(this.pos++);
5195
+ },
5196
+ eat: function(match) {
5197
+ var ch = this.string.charAt(this.pos);
5198
+ if (typeof match == "string") var ok = ch == match;
5199
+ else var ok = ch && (match.test ? match.test(ch) : match(ch));
5200
+ if (ok) {++this.pos; return ch;}
5201
+ },
5202
+ eatWhile: function(match) {
5203
+ var start = this.pos;
5204
+ while (this.eat(match)){}
5205
+ return this.pos > start;
5206
+ },
5207
+ eatSpace: function() {
5208
+ var start = this.pos;
5209
+ while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
5210
+ return this.pos > start;
5211
+ },
5212
+ skipToEnd: function() {this.pos = this.string.length;},
5213
+ skipTo: function(ch) {
5214
+ var found = this.string.indexOf(ch, this.pos);
5215
+ if (found > -1) {this.pos = found; return true;}
5216
+ },
5217
+ backUp: function(n) {this.pos -= n;},
5218
+ column: function() {
5219
+ if (this.lastColumnPos < this.start) {
5220
+ this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);
5221
+ this.lastColumnPos = this.start;
5222
+ }
5223
+ return this.lastColumnValue - (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0);
5224
+ },
5225
+ indentation: function() {
5226
+ return countColumn(this.string, null, this.tabSize) -
5227
+ (this.lineStart ? countColumn(this.string, this.lineStart, this.tabSize) : 0);
5228
+ },
5229
+ match: function(pattern, consume, caseInsensitive) {
5230
+ if (typeof pattern == "string") {
5231
+ var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
5232
+ var substr = this.string.substr(this.pos, pattern.length);
5233
+ if (cased(substr) == cased(pattern)) {
5234
+ if (consume !== false) this.pos += pattern.length;
5235
+ return true;
5236
+ }
5237
+ } else {
5238
+ var match = this.string.slice(this.pos).match(pattern);
5239
+ if (match && match.index > 0) return null;
5240
+ if (match && consume !== false) this.pos += match[0].length;
5241
+ return match;
5242
+ }
5243
+ },
5244
+ current: function(){return this.string.slice(this.start, this.pos);},
5245
+ hideFirstChars: function(n, inner) {
5246
+ this.lineStart += n;
5247
+ try { return inner(); }
5248
+ finally { this.lineStart -= n; }
5249
+ }
5250
+ };
5251
+
5252
+ // TEXTMARKERS
5253
+
5254
+ // Created with markText and setBookmark methods. A TextMarker is a
5255
+ // handle that can be used to clear or find a marked position in the
5256
+ // document. Line objects hold arrays (markedSpans) containing
5257
+ // {from, to, marker} object pointing to such marker objects, and
5258
+ // indicating that such a marker is present on that line. Multiple
5259
+ // lines may point to the same marker when it spans across lines.
5260
+ // The spans will have null for their from/to properties when the
5261
+ // marker continues beyond the start/end of the line. Markers have
5262
+ // links back to the lines they currently touch.
5263
+
5264
+ var TextMarker = CodeMirror.TextMarker = function(doc, type) {
5265
+ this.lines = [];
5266
+ this.type = type;
5267
+ this.doc = doc;
5268
+ };
5269
+ eventMixin(TextMarker);
5270
+
5271
+ // Clear the marker.
5272
+ TextMarker.prototype.clear = function() {
5273
+ if (this.explicitlyCleared) return;
5274
+ var cm = this.doc.cm, withOp = cm && !cm.curOp;
5275
+ if (withOp) startOperation(cm);
5276
+ if (hasHandler(this, "clear")) {
5277
+ var found = this.find();
5278
+ if (found) signalLater(this, "clear", found.from, found.to);
5279
+ }
5280
+ var min = null, max = null;
5281
+ for (var i = 0; i < this.lines.length; ++i) {
5282
+ var line = this.lines[i];
5283
+ var span = getMarkedSpanFor(line.markedSpans, this);
5284
+ if (cm && !this.collapsed) regLineChange(cm, lineNo(line), "text");
5285
+ else if (cm) {
5286
+ if (span.to != null) max = lineNo(line);
5287
+ if (span.from != null) min = lineNo(line);
5288
+ }
5289
+ line.markedSpans = removeMarkedSpan(line.markedSpans, span);
5290
+ if (span.from == null && this.collapsed && !lineIsHidden(this.doc, line) && cm)
5291
+ updateLineHeight(line, textHeight(cm.display));
5292
+ }
5293
+ if (cm && this.collapsed && !cm.options.lineWrapping) for (var i = 0; i < this.lines.length; ++i) {
5294
+ var visual = visualLine(this.lines[i]), len = lineLength(visual);
5295
+ if (len > cm.display.maxLineLength) {
5296
+ cm.display.maxLine = visual;
5297
+ cm.display.maxLineLength = len;
5298
+ cm.display.maxLineChanged = true;
5299
+ }
5300
+ }
5301
+
5302
+ if (min != null && cm && this.collapsed) regChange(cm, min, max + 1);
5303
+ this.lines.length = 0;
5304
+ this.explicitlyCleared = true;
5305
+ if (this.atomic && this.doc.cantEdit) {
5306
+ this.doc.cantEdit = false;
5307
+ if (cm) reCheckSelection(cm.doc);
5308
+ }
5309
+ if (cm) signalLater(cm, "markerCleared", cm, this);
5310
+ if (withOp) endOperation(cm);
5311
+ if (this.parent) this.parent.clear();
5312
+ };
5313
+
5314
+ // Find the position of the marker in the document. Returns a {from,
5315
+ // to} object by default. Side can be passed to get a specific side
5316
+ // -- 0 (both), -1 (left), or 1 (right). When lineObj is true, the
5317
+ // Pos objects returned contain a line object, rather than a line
5318
+ // number (used to prevent looking up the same line twice).
5319
+ TextMarker.prototype.find = function(side, lineObj) {
5320
+ if (side == null && this.type == "bookmark") side = 1;
5321
+ var from, to;
5322
+ for (var i = 0; i < this.lines.length; ++i) {
5323
+ var line = this.lines[i];
5324
+ var span = getMarkedSpanFor(line.markedSpans, this);
5325
+ if (span.from != null) {
5326
+ from = Pos(lineObj ? line : lineNo(line), span.from);
5327
+ if (side == -1) return from;
5328
+ }
5329
+ if (span.to != null) {
5330
+ to = Pos(lineObj ? line : lineNo(line), span.to);
5331
+ if (side == 1) return to;
5332
+ }
5333
+ }
5334
+ return from && {from: from, to: to};
5335
+ };
5336
+
5337
+ // Signals that the marker's widget changed, and surrounding layout
5338
+ // should be recomputed.
5339
+ TextMarker.prototype.changed = function() {
5340
+ var pos = this.find(-1, true), widget = this, cm = this.doc.cm;
5341
+ if (!pos || !cm) return;
5342
+ runInOp(cm, function() {
5343
+ var line = pos.line, lineN = lineNo(pos.line);
5344
+ var view = findViewForLine(cm, lineN);
5345
+ if (view) {
5346
+ clearLineMeasurementCacheFor(view);
5347
+ cm.curOp.selectionChanged = cm.curOp.forceUpdate = true;
5348
+ }
5349
+ cm.curOp.updateMaxLine = true;
5350
+ if (!lineIsHidden(widget.doc, line) && widget.height != null) {
5351
+ var oldHeight = widget.height;
5352
+ widget.height = null;
5353
+ var dHeight = widgetHeight(widget) - oldHeight;
5354
+ if (dHeight)
5355
+ updateLineHeight(line, line.height + dHeight);
5356
+ }
5357
+ });
5358
+ };
5359
+
5360
+ TextMarker.prototype.attachLine = function(line) {
5361
+ if (!this.lines.length && this.doc.cm) {
5362
+ var op = this.doc.cm.curOp;
5363
+ if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1)
5364
+ (op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this);
5365
+ }
5366
+ this.lines.push(line);
5367
+ };
5368
+ TextMarker.prototype.detachLine = function(line) {
5369
+ this.lines.splice(indexOf(this.lines, line), 1);
5370
+ if (!this.lines.length && this.doc.cm) {
5371
+ var op = this.doc.cm.curOp;
5372
+ (op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this);
5373
+ }
5374
+ };
5375
+
5376
+ // Collapsed markers have unique ids, in order to be able to order
5377
+ // them, which is needed for uniquely determining an outer marker
5378
+ // when they overlap (they may nest, but not partially overlap).
5379
+ var nextMarkerId = 0;
5380
+
5381
+ // Create a marker, wire it up to the right lines, and
5382
+ function markText(doc, from, to, options, type) {
5383
+ // Shared markers (across linked documents) are handled separately
5384
+ // (markTextShared will call out to this again, once per
5385
+ // document).
5386
+ if (options && options.shared) return markTextShared(doc, from, to, options, type);
5387
+ // Ensure we are in an operation.
5388
+ if (doc.cm && !doc.cm.curOp) return operation(doc.cm, markText)(doc, from, to, options, type);
5389
+
5390
+ var marker = new TextMarker(doc, type), diff = cmp(from, to);
5391
+ if (options) copyObj(options, marker, false);
5392
+ // Don't connect empty markers unless clearWhenEmpty is false
5393
+ if (diff > 0 || diff == 0 && marker.clearWhenEmpty !== false)
5394
+ return marker;
5395
+ if (marker.replacedWith) {
5396
+ // Showing up as a widget implies collapsed (widget replaces text)
5397
+ marker.collapsed = true;
5398
+ marker.widgetNode = elt("span", [marker.replacedWith], "CodeMirror-widget");
5399
+ if (!options.handleMouseEvents) marker.widgetNode.setAttribute("cm-ignore-events", "true");
5400
+ if (options.insertLeft) marker.widgetNode.insertLeft = true;
5401
+ }
5402
+ if (marker.collapsed) {
5403
+ if (conflictingCollapsedRange(doc, from.line, from, to, marker) ||
5404
+ from.line != to.line && conflictingCollapsedRange(doc, to.line, from, to, marker))
5405
+ throw new Error("Inserting collapsed marker partially overlapping an existing one");
5406
+ sawCollapsedSpans = true;
5407
+ }
5408
+
5409
+ if (marker.addToHistory)
5410
+ addChangeToHistory(doc, {from: from, to: to, origin: "markText"}, doc.sel, NaN);
5411
+
5412
+ var curLine = from.line, cm = doc.cm, updateMaxLine;
5413
+ doc.iter(curLine, to.line + 1, function(line) {
5414
+ if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(line) == cm.display.maxLine)
5415
+ updateMaxLine = true;
5416
+ if (marker.collapsed && curLine != from.line) updateLineHeight(line, 0);
5417
+ addMarkedSpan(line, new MarkedSpan(marker,
5418
+ curLine == from.line ? from.ch : null,
5419
+ curLine == to.line ? to.ch : null));
5420
+ ++curLine;
5421
+ });
5422
+ // lineIsHidden depends on the presence of the spans, so needs a second pass
5423
+ if (marker.collapsed) doc.iter(from.line, to.line + 1, function(line) {
5424
+ if (lineIsHidden(doc, line)) updateLineHeight(line, 0);
5425
+ });
5426
+
5427
+ if (marker.clearOnEnter) on(marker, "beforeCursorEnter", function() { marker.clear(); });
5428
+
5429
+ if (marker.readOnly) {
5430
+ sawReadOnlySpans = true;
5431
+ if (doc.history.done.length || doc.history.undone.length)
5432
+ doc.clearHistory();
5433
+ }
5434
+ if (marker.collapsed) {
5435
+ marker.id = ++nextMarkerId;
5436
+ marker.atomic = true;
5437
+ }
5438
+ if (cm) {
5439
+ // Sync editor state
5440
+ if (updateMaxLine) cm.curOp.updateMaxLine = true;
5441
+ if (marker.collapsed)
5442
+ regChange(cm, from.line, to.line + 1);
5443
+ else if (marker.className || marker.title || marker.startStyle || marker.endStyle || marker.css)
5444
+ for (var i = from.line; i <= to.line; i++) regLineChange(cm, i, "text");
5445
+ if (marker.atomic) reCheckSelection(cm.doc);
5446
+ signalLater(cm, "markerAdded", cm, marker);
5447
+ }
5448
+ return marker;
5449
+ }
5450
+
5451
+ // SHARED TEXTMARKERS
5452
+
5453
+ // A shared marker spans multiple linked documents. It is
5454
+ // implemented as a meta-marker-object controlling multiple normal
5455
+ // markers.
5456
+ var SharedTextMarker = CodeMirror.SharedTextMarker = function(markers, primary) {
5457
+ this.markers = markers;
5458
+ this.primary = primary;
5459
+ for (var i = 0; i < markers.length; ++i)
5460
+ markers[i].parent = this;
5461
+ };
5462
+ eventMixin(SharedTextMarker);
5463
+
5464
+ SharedTextMarker.prototype.clear = function() {
5465
+ if (this.explicitlyCleared) return;
5466
+ this.explicitlyCleared = true;
5467
+ for (var i = 0; i < this.markers.length; ++i)
5468
+ this.markers[i].clear();
5469
+ signalLater(this, "clear");
5470
+ };
5471
+ SharedTextMarker.prototype.find = function(side, lineObj) {
5472
+ return this.primary.find(side, lineObj);
5473
+ };
5474
+
5475
+ function markTextShared(doc, from, to, options, type) {
5476
+ options = copyObj(options);
5477
+ options.shared = false;
5478
+ var markers = [markText(doc, from, to, options, type)], primary = markers[0];
5479
+ var widget = options.widgetNode;
5480
+ linkedDocs(doc, function(doc) {
5481
+ if (widget) options.widgetNode = widget.cloneNode(true);
5482
+ markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type));
5483
+ for (var i = 0; i < doc.linked.length; ++i)
5484
+ if (doc.linked[i].isParent) return;
5485
+ primary = lst(markers);
5486
+ });
5487
+ return new SharedTextMarker(markers, primary);
5488
+ }
5489
+
5490
+ function findSharedMarkers(doc) {
5491
+ return doc.findMarks(Pos(doc.first, 0), doc.clipPos(Pos(doc.lastLine())),
5492
+ function(m) { return m.parent; });
5493
+ }
5494
+
5495
+ function copySharedMarkers(doc, markers) {
5496
+ for (var i = 0; i < markers.length; i++) {
5497
+ var marker = markers[i], pos = marker.find();
5498
+ var mFrom = doc.clipPos(pos.from), mTo = doc.clipPos(pos.to);
5499
+ if (cmp(mFrom, mTo)) {
5500
+ var subMark = markText(doc, mFrom, mTo, marker.primary, marker.primary.type);
5501
+ marker.markers.push(subMark);
5502
+ subMark.parent = marker;
5503
+ }
5504
+ }
5505
+ }
5506
+
5507
+ function detachSharedMarkers(markers) {
5508
+ for (var i = 0; i < markers.length; i++) {
5509
+ var marker = markers[i], linked = [marker.primary.doc];;
5510
+ linkedDocs(marker.primary.doc, function(d) { linked.push(d); });
5511
+ for (var j = 0; j < marker.markers.length; j++) {
5512
+ var subMarker = marker.markers[j];
5513
+ if (indexOf(linked, subMarker.doc) == -1) {
5514
+ subMarker.parent = null;
5515
+ marker.markers.splice(j--, 1);
5516
+ }
5517
+ }
5518
+ }
5519
+ }
5520
+
5521
+ // TEXTMARKER SPANS
5522
+
5523
+ function MarkedSpan(marker, from, to) {
5524
+ this.marker = marker;
5525
+ this.from = from; this.to = to;
5526
+ }
5527
+
5528
+ // Search an array of spans for a span matching the given marker.
5529
+ function getMarkedSpanFor(spans, marker) {
5530
+ if (spans) for (var i = 0; i < spans.length; ++i) {
5531
+ var span = spans[i];
5532
+ if (span.marker == marker) return span;
5533
+ }
5534
+ }
5535
+ // Remove a span from an array, returning undefined if no spans are
5536
+ // left (we don't store arrays for lines without spans).
5537
+ function removeMarkedSpan(spans, span) {
5538
+ for (var r, i = 0; i < spans.length; ++i)
5539
+ if (spans[i] != span) (r || (r = [])).push(spans[i]);
5540
+ return r;
5541
+ }
5542
+ // Add a span to a line.
5543
+ function addMarkedSpan(line, span) {
5544
+ line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];
5545
+ span.marker.attachLine(line);
5546
+ }
5547
+
5548
+ // Used for the algorithm that adjusts markers for a change in the
5549
+ // document. These functions cut an array of spans at a given
5550
+ // character position, returning an array of remaining chunks (or
5551
+ // undefined if nothing remains).
5552
+ function markedSpansBefore(old, startCh, isInsert) {
5553
+ if (old) for (var i = 0, nw; i < old.length; ++i) {
5554
+ var span = old[i], marker = span.marker;
5555
+ var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
5556
+ if (startsBefore || span.from == startCh && marker.type == "bookmark" && (!isInsert || !span.marker.insertLeft)) {
5557
+ var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh);
5558
+ (nw || (nw = [])).push(new MarkedSpan(marker, span.from, endsAfter ? null : span.to));
5559
+ }
5560
+ }
5561
+ return nw;
5562
+ }
5563
+ function markedSpansAfter(old, endCh, isInsert) {
5564
+ if (old) for (var i = 0, nw; i < old.length; ++i) {
5565
+ var span = old[i], marker = span.marker;
5566
+ var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
5567
+ if (endsAfter || span.from == endCh && marker.type == "bookmark" && (!isInsert || span.marker.insertLeft)) {
5568
+ var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh);
5569
+ (nw || (nw = [])).push(new MarkedSpan(marker, startsBefore ? null : span.from - endCh,
5570
+ span.to == null ? null : span.to - endCh));
5571
+ }
5572
+ }
5573
+ return nw;
5574
+ }
5575
+
5576
+ // Given a change object, compute the new set of marker spans that
5577
+ // cover the line in which the change took place. Removes spans
5578
+ // entirely within the change, reconnects spans belonging to the
5579
+ // same marker that appear on both sides of the change, and cuts off
5580
+ // spans partially within the change. Returns an array of span
5581
+ // arrays with one element for each line in (after) the change.
5582
+ function stretchSpansOverChange(doc, change) {
5583
+ if (change.full) return null;
5584
+ var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;
5585
+ var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;
5586
+ if (!oldFirst && !oldLast) return null;
5587
+
5588
+ var startCh = change.from.ch, endCh = change.to.ch, isInsert = cmp(change.from, change.to) == 0;
5589
+ // Get the spans that 'stick out' on both sides
5590
+ var first = markedSpansBefore(oldFirst, startCh, isInsert);
5591
+ var last = markedSpansAfter(oldLast, endCh, isInsert);
5592
+
5593
+ // Next, merge those two ends
5594
+ var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0);
5595
+ if (first) {
5596
+ // Fix up .to properties of first
5597
+ for (var i = 0; i < first.length; ++i) {
5598
+ var span = first[i];
5599
+ if (span.to == null) {
5600
+ var found = getMarkedSpanFor(last, span.marker);
5601
+ if (!found) span.to = startCh;
5602
+ else if (sameLine) span.to = found.to == null ? null : found.to + offset;
5603
+ }
5604
+ }
5605
+ }
5606
+ if (last) {
5607
+ // Fix up .from in last (or move them into first in case of sameLine)
5608
+ for (var i = 0; i < last.length; ++i) {
5609
+ var span = last[i];
5610
+ if (span.to != null) span.to += offset;
5611
+ if (span.from == null) {
5612
+ var found = getMarkedSpanFor(first, span.marker);
5613
+ if (!found) {
5614
+ span.from = offset;
5615
+ if (sameLine) (first || (first = [])).push(span);
5616
+ }
5617
+ } else {
5618
+ span.from += offset;
5619
+ if (sameLine) (first || (first = [])).push(span);
5620
+ }
5621
+ }
5622
+ }
5623
+ // Make sure we didn't create any zero-length spans
5624
+ if (first) first = clearEmptySpans(first);
5625
+ if (last && last != first) last = clearEmptySpans(last);
5626
+
5627
+ var newMarkers = [first];
5628
+ if (!sameLine) {
5629
+ // Fill gap with whole-line-spans
5630
+ var gap = change.text.length - 2, gapMarkers;
5631
+ if (gap > 0 && first)
5632
+ for (var i = 0; i < first.length; ++i)
5633
+ if (first[i].to == null)
5634
+ (gapMarkers || (gapMarkers = [])).push(new MarkedSpan(first[i].marker, null, null));
5635
+ for (var i = 0; i < gap; ++i)
5636
+ newMarkers.push(gapMarkers);
5637
+ newMarkers.push(last);
5638
+ }
5639
+ return newMarkers;
5640
+ }
5641
+
5642
+ // Remove spans that are empty and don't have a clearWhenEmpty
5643
+ // option of false.
5644
+ function clearEmptySpans(spans) {
5645
+ for (var i = 0; i < spans.length; ++i) {
5646
+ var span = spans[i];
5647
+ if (span.from != null && span.from == span.to && span.marker.clearWhenEmpty !== false)
5648
+ spans.splice(i--, 1);
5649
+ }
5650
+ if (!spans.length) return null;
5651
+ return spans;
5652
+ }
5653
+
5654
+ // Used for un/re-doing changes from the history. Combines the
5655
+ // result of computing the existing spans with the set of spans that
5656
+ // existed in the history (so that deleting around a span and then
5657
+ // undoing brings back the span).
5658
+ function mergeOldSpans(doc, change) {
5659
+ var old = getOldSpans(doc, change);
5660
+ var stretched = stretchSpansOverChange(doc, change);
5661
+ if (!old) return stretched;
5662
+ if (!stretched) return old;
5663
+
5664
+ for (var i = 0; i < old.length; ++i) {
5665
+ var oldCur = old[i], stretchCur = stretched[i];
5666
+ if (oldCur && stretchCur) {
5667
+ spans: for (var j = 0; j < stretchCur.length; ++j) {
5668
+ var span = stretchCur[j];
5669
+ for (var k = 0; k < oldCur.length; ++k)
5670
+ if (oldCur[k].marker == span.marker) continue spans;
5671
+ oldCur.push(span);
5672
+ }
5673
+ } else if (stretchCur) {
5674
+ old[i] = stretchCur;
5675
+ }
5676
+ }
5677
+ return old;
5678
+ }
5679
+
5680
+ // Used to 'clip' out readOnly ranges when making a change.
5681
+ function removeReadOnlyRanges(doc, from, to) {
5682
+ var markers = null;
5683
+ doc.iter(from.line, to.line + 1, function(line) {
5684
+ if (line.markedSpans) for (var i = 0; i < line.markedSpans.length; ++i) {
5685
+ var mark = line.markedSpans[i].marker;
5686
+ if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
5687
+ (markers || (markers = [])).push(mark);
5688
+ }
5689
+ });
5690
+ if (!markers) return null;
5691
+ var parts = [{from: from, to: to}];
5692
+ for (var i = 0; i < markers.length; ++i) {
5693
+ var mk = markers[i], m = mk.find(0);
5694
+ for (var j = 0; j < parts.length; ++j) {
5695
+ var p = parts[j];
5696
+ if (cmp(p.to, m.from) < 0 || cmp(p.from, m.to) > 0) continue;
5697
+ var newParts = [j, 1], dfrom = cmp(p.from, m.from), dto = cmp(p.to, m.to);
5698
+ if (dfrom < 0 || !mk.inclusiveLeft && !dfrom)
5699
+ newParts.push({from: p.from, to: m.from});
5700
+ if (dto > 0 || !mk.inclusiveRight && !dto)
5701
+ newParts.push({from: m.to, to: p.to});
5702
+ parts.splice.apply(parts, newParts);
5703
+ j += newParts.length - 1;
5704
+ }
5705
+ }
5706
+ return parts;
5707
+ }
5708
+
5709
+ // Connect or disconnect spans from a line.
5710
+ function detachMarkedSpans(line) {
5711
+ var spans = line.markedSpans;
5712
+ if (!spans) return;
5713
+ for (var i = 0; i < spans.length; ++i)
5714
+ spans[i].marker.detachLine(line);
5715
+ line.markedSpans = null;
5716
+ }
5717
+ function attachMarkedSpans(line, spans) {
5718
+ if (!spans) return;
5719
+ for (var i = 0; i < spans.length; ++i)
5720
+ spans[i].marker.attachLine(line);
5721
+ line.markedSpans = spans;
5722
+ }
5723
+
5724
+ // Helpers used when computing which overlapping collapsed span
5725
+ // counts as the larger one.
5726
+ function extraLeft(marker) { return marker.inclusiveLeft ? -1 : 0; }
5727
+ function extraRight(marker) { return marker.inclusiveRight ? 1 : 0; }
5728
+
5729
+ // Returns a number indicating which of two overlapping collapsed
5730
+ // spans is larger (and thus includes the other). Falls back to
5731
+ // comparing ids when the spans cover exactly the same range.
5732
+ function compareCollapsedMarkers(a, b) {
5733
+ var lenDiff = a.lines.length - b.lines.length;
5734
+ if (lenDiff != 0) return lenDiff;
5735
+ var aPos = a.find(), bPos = b.find();
5736
+ var fromCmp = cmp(aPos.from, bPos.from) || extraLeft(a) - extraLeft(b);
5737
+ if (fromCmp) return -fromCmp;
5738
+ var toCmp = cmp(aPos.to, bPos.to) || extraRight(a) - extraRight(b);
5739
+ if (toCmp) return toCmp;
5740
+ return b.id - a.id;
5741
+ }
5742
+
5743
+ // Find out whether a line ends or starts in a collapsed span. If
5744
+ // so, return the marker for that span.
5745
+ function collapsedSpanAtSide(line, start) {
5746
+ var sps = sawCollapsedSpans && line.markedSpans, found;
5747
+ if (sps) for (var sp, i = 0; i < sps.length; ++i) {
5748
+ sp = sps[i];
5749
+ if (sp.marker.collapsed && (start ? sp.from : sp.to) == null &&
5750
+ (!found || compareCollapsedMarkers(found, sp.marker) < 0))
5751
+ found = sp.marker;
5752
+ }
5753
+ return found;
5754
+ }
5755
+ function collapsedSpanAtStart(line) { return collapsedSpanAtSide(line, true); }
5756
+ function collapsedSpanAtEnd(line) { return collapsedSpanAtSide(line, false); }
5757
+
5758
+ // Test whether there exists a collapsed span that partially
5759
+ // overlaps (covers the start or end, but not both) of a new span.
5760
+ // Such overlap is not allowed.
5761
+ function conflictingCollapsedRange(doc, lineNo, from, to, marker) {
5762
+ var line = getLine(doc, lineNo);
5763
+ var sps = sawCollapsedSpans && line.markedSpans;
5764
+ if (sps) for (var i = 0; i < sps.length; ++i) {
5765
+ var sp = sps[i];
5766
+ if (!sp.marker.collapsed) continue;
5767
+ var found = sp.marker.find(0);
5768
+ var fromCmp = cmp(found.from, from) || extraLeft(sp.marker) - extraLeft(marker);
5769
+ var toCmp = cmp(found.to, to) || extraRight(sp.marker) - extraRight(marker);
5770
+ if (fromCmp >= 0 && toCmp <= 0 || fromCmp <= 0 && toCmp >= 0) continue;
5771
+ if (fromCmp <= 0 && (cmp(found.to, from) > 0 || (sp.marker.inclusiveRight && marker.inclusiveLeft)) ||
5772
+ fromCmp >= 0 && (cmp(found.from, to) < 0 || (sp.marker.inclusiveLeft && marker.inclusiveRight)))
5773
+ return true;
5774
+ }
5775
+ }
5776
+
5777
+ // A visual line is a line as drawn on the screen. Folding, for
5778
+ // example, can cause multiple logical lines to appear on the same
5779
+ // visual line. This finds the start of the visual line that the
5780
+ // given line is part of (usually that is the line itself).
5781
+ function visualLine(line) {
5782
+ var merged;
5783
+ while (merged = collapsedSpanAtStart(line))
5784
+ line = merged.find(-1, true).line;
5785
+ return line;
5786
+ }
5787
+
5788
+ // Returns an array of logical lines that continue the visual line
5789
+ // started by the argument, or undefined if there are no such lines.
5790
+ function visualLineContinued(line) {
5791
+ var merged, lines;
5792
+ while (merged = collapsedSpanAtEnd(line)) {
5793
+ line = merged.find(1, true).line;
5794
+ (lines || (lines = [])).push(line);
5795
+ }
5796
+ return lines;
5797
+ }
5798
+
5799
+ // Get the line number of the start of the visual line that the
5800
+ // given line number is part of.
5801
+ function visualLineNo(doc, lineN) {
5802
+ var line = getLine(doc, lineN), vis = visualLine(line);
5803
+ if (line == vis) return lineN;
5804
+ return lineNo(vis);
5805
+ }
5806
+ // Get the line number of the start of the next visual line after
5807
+ // the given line.
5808
+ function visualLineEndNo(doc, lineN) {
5809
+ if (lineN > doc.lastLine()) return lineN;
5810
+ var line = getLine(doc, lineN), merged;
5811
+ if (!lineIsHidden(doc, line)) return lineN;
5812
+ while (merged = collapsedSpanAtEnd(line))
5813
+ line = merged.find(1, true).line;
5814
+ return lineNo(line) + 1;
5815
+ }
5816
+
5817
+ // Compute whether a line is hidden. Lines count as hidden when they
5818
+ // are part of a visual line that starts with another line, or when
5819
+ // they are entirely covered by collapsed, non-widget span.
5820
+ function lineIsHidden(doc, line) {
5821
+ var sps = sawCollapsedSpans && line.markedSpans;
5822
+ if (sps) for (var sp, i = 0; i < sps.length; ++i) {
5823
+ sp = sps[i];
5824
+ if (!sp.marker.collapsed) continue;
5825
+ if (sp.from == null) return true;
5826
+ if (sp.marker.widgetNode) continue;
5827
+ if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp))
5828
+ return true;
5829
+ }
5830
+ }
5831
+ function lineIsHiddenInner(doc, line, span) {
5832
+ if (span.to == null) {
5833
+ var end = span.marker.find(1, true);
5834
+ return lineIsHiddenInner(doc, end.line, getMarkedSpanFor(end.line.markedSpans, span.marker));
5835
+ }
5836
+ if (span.marker.inclusiveRight && span.to == line.text.length)
5837
+ return true;
5838
+ for (var sp, i = 0; i < line.markedSpans.length; ++i) {
5839
+ sp = line.markedSpans[i];
5840
+ if (sp.marker.collapsed && !sp.marker.widgetNode && sp.from == span.to &&
5841
+ (sp.to == null || sp.to != span.from) &&
5842
+ (sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
5843
+ lineIsHiddenInner(doc, line, sp)) return true;
5844
+ }
5845
+ }
5846
+
5847
+ // LINE WIDGETS
5848
+
5849
+ // Line widgets are block elements displayed above or below a line.
5850
+
5851
+ var LineWidget = CodeMirror.LineWidget = function(cm, node, options) {
5852
+ if (options) for (var opt in options) if (options.hasOwnProperty(opt))
5853
+ this[opt] = options[opt];
5854
+ this.cm = cm;
5855
+ this.node = node;
5856
+ };
5857
+ eventMixin(LineWidget);
5858
+
5859
+ function adjustScrollWhenAboveVisible(cm, line, diff) {
5860
+ if (heightAtLine(line) < ((cm.curOp && cm.curOp.scrollTop) || cm.doc.scrollTop))
5861
+ addToScrollPos(cm, null, diff);
5862
+ }
5863
+
5864
+ LineWidget.prototype.clear = function() {
5865
+ var cm = this.cm, ws = this.line.widgets, line = this.line, no = lineNo(line);
5866
+ if (no == null || !ws) return;
5867
+ for (var i = 0; i < ws.length; ++i) if (ws[i] == this) ws.splice(i--, 1);
5868
+ if (!ws.length) line.widgets = null;
5869
+ var height = widgetHeight(this);
5870
+ runInOp(cm, function() {
5871
+ adjustScrollWhenAboveVisible(cm, line, -height);
5872
+ regLineChange(cm, no, "widget");
5873
+ updateLineHeight(line, Math.max(0, line.height - height));
5874
+ });
5875
+ };
5876
+ LineWidget.prototype.changed = function() {
5877
+ var oldH = this.height, cm = this.cm, line = this.line;
5878
+ this.height = null;
5879
+ var diff = widgetHeight(this) - oldH;
5880
+ if (!diff) return;
5881
+ runInOp(cm, function() {
5882
+ cm.curOp.forceUpdate = true;
5883
+ adjustScrollWhenAboveVisible(cm, line, diff);
5884
+ updateLineHeight(line, line.height + diff);
5885
+ });
5886
+ };
5887
+
5888
+ function widgetHeight(widget) {
5889
+ if (widget.height != null) return widget.height;
5890
+ if (!contains(document.body, widget.node)) {
5891
+ var parentStyle = "position: relative;";
5892
+ if (widget.coverGutter)
5893
+ parentStyle += "margin-left: -" + widget.cm.display.gutters.offsetWidth + "px;";
5894
+ if (widget.noHScroll)
5895
+ parentStyle += "width: " + widget.cm.display.wrapper.clientWidth + "px;";
5896
+ removeChildrenAndAdd(widget.cm.display.measure, elt("div", [widget.node], null, parentStyle));
5897
+ }
5898
+ return widget.height = widget.node.offsetHeight;
5899
+ }
5900
+
5901
+ function addLineWidget(cm, handle, node, options) {
5902
+ var widget = new LineWidget(cm, node, options);
5903
+ if (widget.noHScroll) cm.display.alignWidgets = true;
5904
+ changeLine(cm.doc, handle, "widget", function(line) {
5905
+ var widgets = line.widgets || (line.widgets = []);
5906
+ if (widget.insertAt == null) widgets.push(widget);
5907
+ else widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget);
5908
+ widget.line = line;
5909
+ if (!lineIsHidden(cm.doc, line)) {
5910
+ var aboveVisible = heightAtLine(line) < cm.doc.scrollTop;
5911
+ updateLineHeight(line, line.height + widgetHeight(widget));
5912
+ if (aboveVisible) addToScrollPos(cm, null, widget.height);
5913
+ cm.curOp.forceUpdate = true;
5914
+ }
5915
+ return true;
5916
+ });
5917
+ return widget;
5918
+ }
5919
+
5920
+ // LINE DATA STRUCTURE
5921
+
5922
+ // Line objects. These hold state related to a line, including
5923
+ // highlighting info (the styles array).
5924
+ var Line = CodeMirror.Line = function(text, markedSpans, estimateHeight) {
5925
+ this.text = text;
5926
+ attachMarkedSpans(this, markedSpans);
5927
+ this.height = estimateHeight ? estimateHeight(this) : 1;
5928
+ };
5929
+ eventMixin(Line);
5930
+ Line.prototype.lineNo = function() { return lineNo(this); };
5931
+
5932
+ // Change the content (text, markers) of a line. Automatically
5933
+ // invalidates cached information and tries to re-estimate the
5934
+ // line's height.
5935
+ function updateLine(line, text, markedSpans, estimateHeight) {
5936
+ line.text = text;
5937
+ if (line.stateAfter) line.stateAfter = null;
5938
+ if (line.styles) line.styles = null;
5939
+ if (line.order != null) line.order = null;
5940
+ detachMarkedSpans(line);
5941
+ attachMarkedSpans(line, markedSpans);
5942
+ var estHeight = estimateHeight ? estimateHeight(line) : 1;
5943
+ if (estHeight != line.height) updateLineHeight(line, estHeight);
5944
+ }
5945
+
5946
+ // Detach a line from the document tree and its markers.
5947
+ function cleanUpLine(line) {
5948
+ line.parent = null;
5949
+ detachMarkedSpans(line);
5950
+ }
5951
+
5952
+ function extractLineClasses(type, output) {
5953
+ if (type) for (;;) {
5954
+ var lineClass = type.match(/(?:^|\s+)line-(background-)?(\S+)/);
5955
+ if (!lineClass) break;
5956
+ type = type.slice(0, lineClass.index) + type.slice(lineClass.index + lineClass[0].length);
5957
+ var prop = lineClass[1] ? "bgClass" : "textClass";
5958
+ if (output[prop] == null)
5959
+ output[prop] = lineClass[2];
5960
+ else if (!(new RegExp("(?:^|\s)" + lineClass[2] + "(?:$|\s)")).test(output[prop]))
5961
+ output[prop] += " " + lineClass[2];
5962
+ }
5963
+ return type;
5964
+ }
5965
+
5966
+ function callBlankLine(mode, state) {
5967
+ if (mode.blankLine) return mode.blankLine(state);
5968
+ if (!mode.innerMode) return;
5969
+ var inner = CodeMirror.innerMode(mode, state);
5970
+ if (inner.mode.blankLine) return inner.mode.blankLine(inner.state);
5971
+ }
5972
+
5973
+ function readToken(mode, stream, state, inner) {
5974
+ for (var i = 0; i < 10; i++) {
5975
+ if (inner) inner[0] = CodeMirror.innerMode(mode, state).mode;
5976
+ var style = mode.token(stream, state);
5977
+ if (stream.pos > stream.start) return style;
5978
+ }
5979
+ throw new Error("Mode " + mode.name + " failed to advance stream.");
5980
+ }
5981
+
5982
+ // Utility for getTokenAt and getLineTokens
5983
+ function takeToken(cm, pos, precise, asArray) {
5984
+ function getObj(copy) {
5985
+ return {start: stream.start, end: stream.pos,
5986
+ string: stream.current(),
5987
+ type: style || null,
5988
+ state: copy ? copyState(doc.mode, state) : state};
5989
+ }
5990
+
5991
+ var doc = cm.doc, mode = doc.mode, style;
5992
+ pos = clipPos(doc, pos);
5993
+ var line = getLine(doc, pos.line), state = getStateBefore(cm, pos.line, precise);
5994
+ var stream = new StringStream(line.text, cm.options.tabSize), tokens;
5995
+ if (asArray) tokens = [];
5996
+ while ((asArray || stream.pos < pos.ch) && !stream.eol()) {
5997
+ stream.start = stream.pos;
5998
+ style = readToken(mode, stream, state);
5999
+ if (asArray) tokens.push(getObj(true));
6000
+ }
6001
+ return asArray ? tokens : getObj();
6002
+ }
6003
+
6004
+ // Run the given mode's parser over a line, calling f for each token.
6005
+ function runMode(cm, text, mode, state, f, lineClasses, forceToEnd) {
6006
+ var flattenSpans = mode.flattenSpans;
6007
+ if (flattenSpans == null) flattenSpans = cm.options.flattenSpans;
6008
+ var curStart = 0, curStyle = null;
6009
+ var stream = new StringStream(text, cm.options.tabSize), style;
6010
+ var inner = cm.options.addModeClass && [null];
6011
+ if (text == "") extractLineClasses(callBlankLine(mode, state), lineClasses);
6012
+ while (!stream.eol()) {
6013
+ if (stream.pos > cm.options.maxHighlightLength) {
6014
+ flattenSpans = false;
6015
+ if (forceToEnd) processLine(cm, text, state, stream.pos);
6016
+ stream.pos = text.length;
6017
+ style = null;
6018
+ } else {
6019
+ style = extractLineClasses(readToken(mode, stream, state, inner), lineClasses);
6020
+ }
6021
+ if (inner) {
6022
+ var mName = inner[0].name;
6023
+ if (mName) style = "m-" + (style ? mName + " " + style : mName);
6024
+ }
6025
+ if (!flattenSpans || curStyle != style) {
6026
+ while (curStart < stream.start) {
6027
+ curStart = Math.min(stream.start, curStart + 50000);
6028
+ f(curStart, curStyle);
6029
+ }
6030
+ curStyle = style;
6031
+ }
6032
+ stream.start = stream.pos;
6033
+ }
6034
+ while (curStart < stream.pos) {
6035
+ // Webkit seems to refuse to render text nodes longer than 57444 characters
6036
+ var pos = Math.min(stream.pos, curStart + 50000);
6037
+ f(pos, curStyle);
6038
+ curStart = pos;
6039
+ }
6040
+ }
6041
+
6042
+ // Compute a style array (an array starting with a mode generation
6043
+ // -- for invalidation -- followed by pairs of end positions and
6044
+ // style strings), which is used to highlight the tokens on the
6045
+ // line.
6046
+ function highlightLine(cm, line, state, forceToEnd) {
6047
+ // A styles array always starts with a number identifying the
6048
+ // mode/overlays that it is based on (for easy invalidation).
6049
+ var st = [cm.state.modeGen], lineClasses = {};
6050
+ // Compute the base array of styles
6051
+ runMode(cm, line.text, cm.doc.mode, state, function(end, style) {
6052
+ st.push(end, style);
6053
+ }, lineClasses, forceToEnd);
6054
+
6055
+ // Run overlays, adjust style array.
6056
+ for (var o = 0; o < cm.state.overlays.length; ++o) {
6057
+ var overlay = cm.state.overlays[o], i = 1, at = 0;
6058
+ runMode(cm, line.text, overlay.mode, true, function(end, style) {
6059
+ var start = i;
6060
+ // Ensure there's a token end at the current position, and that i points at it
6061
+ while (at < end) {
6062
+ var i_end = st[i];
6063
+ if (i_end > end)
6064
+ st.splice(i, 1, end, st[i+1], i_end);
6065
+ i += 2;
6066
+ at = Math.min(end, i_end);
6067
+ }
6068
+ if (!style) return;
6069
+ if (overlay.opaque) {
6070
+ st.splice(start, i - start, end, "cm-overlay " + style);
6071
+ i = start + 2;
6072
+ } else {
6073
+ for (; start < i; start += 2) {
6074
+ var cur = st[start+1];
6075
+ st[start+1] = (cur ? cur + " " : "") + "cm-overlay " + style;
6076
+ }
6077
+ }
6078
+ }, lineClasses);
6079
+ }
6080
+
6081
+ return {styles: st, classes: lineClasses.bgClass || lineClasses.textClass ? lineClasses : null};
6082
+ }
6083
+
6084
+ function getLineStyles(cm, line, updateFrontier) {
6085
+ if (!line.styles || line.styles[0] != cm.state.modeGen) {
6086
+ var result = highlightLine(cm, line, line.stateAfter = getStateBefore(cm, lineNo(line)));
6087
+ line.styles = result.styles;
6088
+ if (result.classes) line.styleClasses = result.classes;
6089
+ else if (line.styleClasses) line.styleClasses = null;
6090
+ if (updateFrontier === cm.doc.frontier) cm.doc.frontier++;
6091
+ }
6092
+ return line.styles;
6093
+ }
6094
+
6095
+ // Lightweight form of highlight -- proceed over this line and
6096
+ // update state, but don't save a style array. Used for lines that
6097
+ // aren't currently visible.
6098
+ function processLine(cm, text, state, startAt) {
6099
+ var mode = cm.doc.mode;
6100
+ var stream = new StringStream(text, cm.options.tabSize);
6101
+ stream.start = stream.pos = startAt || 0;
6102
+ if (text == "") callBlankLine(mode, state);
6103
+ while (!stream.eol() && stream.pos <= cm.options.maxHighlightLength) {
6104
+ readToken(mode, stream, state);
6105
+ stream.start = stream.pos;
6106
+ }
6107
+ }
6108
+
6109
+ // Convert a style as returned by a mode (either null, or a string
6110
+ // containing one or more styles) to a CSS style. This is cached,
6111
+ // and also looks for line-wide styles.
6112
+ var styleToClassCache = {}, styleToClassCacheWithMode = {};
6113
+ function interpretTokenStyle(style, options) {
6114
+ if (!style || /^\s*$/.test(style)) return null;
6115
+ var cache = options.addModeClass ? styleToClassCacheWithMode : styleToClassCache;
6116
+ return cache[style] ||
6117
+ (cache[style] = style.replace(/\S+/g, "cm-$&"));
6118
+ }
6119
+
6120
+ // Render the DOM representation of the text of a line. Also builds
6121
+ // up a 'line map', which points at the DOM nodes that represent
6122
+ // specific stretches of text, and is used by the measuring code.
6123
+ // The returned object contains the DOM node, this map, and
6124
+ // information about line-wide styles that were set by the mode.
6125
+ function buildLineContent(cm, lineView) {
6126
+ // The padding-right forces the element to have a 'border', which
6127
+ // is needed on Webkit to be able to get line-level bounding
6128
+ // rectangles for it (in measureChar).
6129
+ var content = elt("span", null, null, webkit ? "padding-right: .1px" : null);
6130
+ var builder = {pre: elt("pre", [content]), content: content, col: 0, pos: 0, cm: cm};
6131
+ lineView.measure = {};
6132
+
6133
+ // Iterate over the logical lines that make up this visual line.
6134
+ for (var i = 0; i <= (lineView.rest ? lineView.rest.length : 0); i++) {
6135
+ var line = i ? lineView.rest[i - 1] : lineView.line, order;
6136
+ builder.pos = 0;
6137
+ builder.addToken = buildToken;
6138
+ // Optionally wire in some hacks into the token-rendering
6139
+ // algorithm, to deal with browser quirks.
6140
+ if ((ie || webkit) && cm.getOption("lineWrapping"))
6141
+ builder.addToken = buildTokenSplitSpaces(builder.addToken);
6142
+ if (hasBadBidiRects(cm.display.measure) && (order = getOrder(line)))
6143
+ builder.addToken = buildTokenBadBidi(builder.addToken, order);
6144
+ builder.map = [];
6145
+ var allowFrontierUpdate = lineView != cm.display.externalMeasured && lineNo(line);
6146
+ insertLineContent(line, builder, getLineStyles(cm, line, allowFrontierUpdate));
6147
+ if (line.styleClasses) {
6148
+ if (line.styleClasses.bgClass)
6149
+ builder.bgClass = joinClasses(line.styleClasses.bgClass, builder.bgClass || "");
6150
+ if (line.styleClasses.textClass)
6151
+ builder.textClass = joinClasses(line.styleClasses.textClass, builder.textClass || "");
6152
+ }
6153
+
6154
+ // Ensure at least a single node is present, for measuring.
6155
+ if (builder.map.length == 0)
6156
+ builder.map.push(0, 0, builder.content.appendChild(zeroWidthElement(cm.display.measure)));
6157
+
6158
+ // Store the map and a cache object for the current logical line
6159
+ if (i == 0) {
6160
+ lineView.measure.map = builder.map;
6161
+ lineView.measure.cache = {};
6162
+ } else {
6163
+ (lineView.measure.maps || (lineView.measure.maps = [])).push(builder.map);
6164
+ (lineView.measure.caches || (lineView.measure.caches = [])).push({});
6165
+ }
6166
+ }
6167
+
6168
+ // See issue #2901
6169
+ if (webkit && /\bcm-tab\b/.test(builder.content.lastChild.className))
6170
+ builder.content.className = "cm-tab-wrap-hack";
6171
+
6172
+ signal(cm, "renderLine", cm, lineView.line, builder.pre);
6173
+ if (builder.pre.className)
6174
+ builder.textClass = joinClasses(builder.pre.className, builder.textClass || "");
6175
+
6176
+ return builder;
6177
+ }
6178
+
6179
+ function defaultSpecialCharPlaceholder(ch) {
6180
+ var token = elt("span", "\u2022", "cm-invalidchar");
6181
+ token.title = "\\u" + ch.charCodeAt(0).toString(16);
6182
+ return token;
6183
+ }
6184
+
6185
+ // Build up the DOM representation for a single token, and add it to
6186
+ // the line map. Takes care to render special characters separately.
6187
+ function buildToken(builder, text, style, startStyle, endStyle, title, css) {
6188
+ if (!text) return;
6189
+ var special = builder.cm.options.specialChars, mustWrap = false;
6190
+ if (!special.test(text)) {
6191
+ builder.col += text.length;
6192
+ var content = document.createTextNode(text);
6193
+ builder.map.push(builder.pos, builder.pos + text.length, content);
6194
+ if (ie && ie_version < 9) mustWrap = true;
6195
+ builder.pos += text.length;
6196
+ } else {
6197
+ var content = document.createDocumentFragment(), pos = 0;
6198
+ while (true) {
6199
+ special.lastIndex = pos;
6200
+ var m = special.exec(text);
6201
+ var skipped = m ? m.index - pos : text.length - pos;
6202
+ if (skipped) {
6203
+ var txt = document.createTextNode(text.slice(pos, pos + skipped));
6204
+ if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
6205
+ else content.appendChild(txt);
6206
+ builder.map.push(builder.pos, builder.pos + skipped, txt);
6207
+ builder.col += skipped;
6208
+ builder.pos += skipped;
6209
+ }
6210
+ if (!m) break;
6211
+ pos += skipped + 1;
6212
+ if (m[0] == "\t") {
6213
+ var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
6214
+ var txt = content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
6215
+ builder.col += tabWidth;
6216
+ } else {
6217
+ var txt = builder.cm.options.specialCharPlaceholder(m[0]);
6218
+ if (ie && ie_version < 9) content.appendChild(elt("span", [txt]));
6219
+ else content.appendChild(txt);
6220
+ builder.col += 1;
6221
+ }
6222
+ builder.map.push(builder.pos, builder.pos + 1, txt);
6223
+ builder.pos++;
6224
+ }
6225
+ }
6226
+ if (style || startStyle || endStyle || mustWrap || css) {
6227
+ var fullStyle = style || "";
6228
+ if (startStyle) fullStyle += startStyle;
6229
+ if (endStyle) fullStyle += endStyle;
6230
+ var token = elt("span", [content], fullStyle, css);
6231
+ if (title) token.title = title;
6232
+ return builder.content.appendChild(token);
6233
+ }
6234
+ builder.content.appendChild(content);
6235
+ }
6236
+
6237
+ function buildTokenSplitSpaces(inner) {
6238
+ function split(old) {
6239
+ var out = " ";
6240
+ for (var i = 0; i < old.length - 2; ++i) out += i % 2 ? " " : "\u00a0";
6241
+ out += " ";
6242
+ return out;
6243
+ }
6244
+ return function(builder, text, style, startStyle, endStyle, title) {
6245
+ inner(builder, text.replace(/ {3,}/g, split), style, startStyle, endStyle, title);
6246
+ };
6247
+ }
6248
+
6249
+ // Work around nonsense dimensions being reported for stretches of
6250
+ // right-to-left text.
6251
+ function buildTokenBadBidi(inner, order) {
6252
+ return function(builder, text, style, startStyle, endStyle, title) {
6253
+ style = style ? style + " cm-force-border" : "cm-force-border";
6254
+ var start = builder.pos, end = start + text.length;
6255
+ for (;;) {
6256
+ // Find the part that overlaps with the start of this text
6257
+ for (var i = 0; i < order.length; i++) {
6258
+ var part = order[i];
6259
+ if (part.to > start && part.from <= start) break;
6260
+ }
6261
+ if (part.to >= end) return inner(builder, text, style, startStyle, endStyle, title);
6262
+ inner(builder, text.slice(0, part.to - start), style, startStyle, null, title);
6263
+ startStyle = null;
6264
+ text = text.slice(part.to - start);
6265
+ start = part.to;
6266
+ }
6267
+ };
6268
+ }
6269
+
6270
+ function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
6271
+ var widget = !ignoreWidget && marker.widgetNode;
6272
+ if (widget) {
6273
+ builder.map.push(builder.pos, builder.pos + size, widget);
6274
+ builder.content.appendChild(widget);
6275
+ }
6276
+ builder.pos += size;
6277
+ }
6278
+
6279
+ // Outputs a number of spans to make up a line, taking highlighting
6280
+ // and marked text into account.
6281
+ function insertLineContent(line, builder, styles) {
6282
+ var spans = line.markedSpans, allText = line.text, at = 0;
6283
+ if (!spans) {
6284
+ for (var i = 1; i < styles.length; i+=2)
6285
+ builder.addToken(builder, allText.slice(at, at = styles[i]), interpretTokenStyle(styles[i+1], builder.cm.options));
6286
+ return;
6287
+ }
6288
+
6289
+ var len = allText.length, pos = 0, i = 1, text = "", style, css;
6290
+ var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, title, collapsed;
6291
+ for (;;) {
6292
+ if (nextChange == pos) { // Update current marker set
6293
+ spanStyle = spanEndStyle = spanStartStyle = title = css = "";
6294
+ collapsed = null; nextChange = Infinity;
6295
+ var foundBookmarks = [];
6296
+ for (var j = 0; j < spans.length; ++j) {
6297
+ var sp = spans[j], m = sp.marker;
6298
+ if (sp.from <= pos && (sp.to == null || sp.to > pos)) {
6299
+ if (sp.to != null && nextChange > sp.to) { nextChange = sp.to; spanEndStyle = ""; }
6300
+ if (m.className) spanStyle += " " + m.className;
6301
+ if (m.css) css = m.css;
6302
+ if (m.startStyle && sp.from == pos) spanStartStyle += " " + m.startStyle;
6303
+ if (m.endStyle && sp.to == nextChange) spanEndStyle += " " + m.endStyle;
6304
+ if (m.title && !title) title = m.title;
6305
+ if (m.collapsed && (!collapsed || compareCollapsedMarkers(collapsed.marker, m) < 0))
6306
+ collapsed = sp;
6307
+ } else if (sp.from > pos && nextChange > sp.from) {
6308
+ nextChange = sp.from;
6309
+ }
6310
+ if (m.type == "bookmark" && sp.from == pos && m.widgetNode) foundBookmarks.push(m);
6311
+ }
6312
+ if (collapsed && (collapsed.from || 0) == pos) {
6313
+ buildCollapsedSpan(builder, (collapsed.to == null ? len + 1 : collapsed.to) - pos,
6314
+ collapsed.marker, collapsed.from == null);
6315
+ if (collapsed.to == null) return;
6316
+ }
6317
+ if (!collapsed && foundBookmarks.length) for (var j = 0; j < foundBookmarks.length; ++j)
6318
+ buildCollapsedSpan(builder, 0, foundBookmarks[j]);
6319
+ }
6320
+ if (pos >= len) break;
6321
+
6322
+ var upto = Math.min(len, nextChange);
6323
+ while (true) {
6324
+ if (text) {
6325
+ var end = pos + text.length;
6326
+ if (!collapsed) {
6327
+ var tokenText = end > upto ? text.slice(0, upto - pos) : text;
6328
+ builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
6329
+ spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title, css);
6330
+ }
6331
+ if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;}
6332
+ pos = end;
6333
+ spanStartStyle = "";
6334
+ }
6335
+ text = allText.slice(at, at = styles[i++]);
6336
+ style = interpretTokenStyle(styles[i++], builder.cm.options);
6337
+ }
6338
+ }
6339
+ }
6340
+
6341
+ // DOCUMENT DATA STRUCTURE
6342
+
6343
+ // By default, updates that start and end at the beginning of a line
6344
+ // are treated specially, in order to make the association of line
6345
+ // widgets and marker elements with the text behave more intuitive.
6346
+ function isWholeLineUpdate(doc, change) {
6347
+ return change.from.ch == 0 && change.to.ch == 0 && lst(change.text) == "" &&
6348
+ (!doc.cm || doc.cm.options.wholeLineUpdateBefore);
6349
+ }
6350
+
6351
+ // Perform a change on the document data structure.
6352
+ function updateDoc(doc, change, markedSpans, estimateHeight) {
6353
+ function spansFor(n) {return markedSpans ? markedSpans[n] : null;}
6354
+ function update(line, text, spans) {
6355
+ updateLine(line, text, spans, estimateHeight);
6356
+ signalLater(line, "change", line, change);
6357
+ }
6358
+ function linesFor(start, end) {
6359
+ for (var i = start, result = []; i < end; ++i)
6360
+ result.push(new Line(text[i], spansFor(i), estimateHeight));
6361
+ return result;
6362
+ }
6363
+
6364
+ var from = change.from, to = change.to, text = change.text;
6365
+ var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line);
6366
+ var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line;
6367
+
6368
+ // Adjust the line structure
6369
+ if (change.full) {
6370
+ doc.insert(0, linesFor(0, text.length));
6371
+ doc.remove(text.length, doc.size - text.length);
6372
+ } else if (isWholeLineUpdate(doc, change)) {
6373
+ // This is a whole-line replace. Treated specially to make
6374
+ // sure line objects move the way they are supposed to.
6375
+ var added = linesFor(0, text.length - 1);
6376
+ update(lastLine, lastLine.text, lastSpans);
6377
+ if (nlines) doc.remove(from.line, nlines);
6378
+ if (added.length) doc.insert(from.line, added);
6379
+ } else if (firstLine == lastLine) {
6380
+ if (text.length == 1) {
6381
+ update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans);
6382
+ } else {
6383
+ var added = linesFor(1, text.length - 1);
6384
+ added.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight));
6385
+ update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
6386
+ doc.insert(from.line + 1, added);
6387
+ }
6388
+ } else if (text.length == 1) {
6389
+ update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0));
6390
+ doc.remove(from.line + 1, nlines);
6391
+ } else {
6392
+ update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
6393
+ update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans);
6394
+ var added = linesFor(1, text.length - 1);
6395
+ if (nlines > 1) doc.remove(from.line + 1, nlines - 1);
6396
+ doc.insert(from.line + 1, added);
6397
+ }
6398
+
6399
+ signalLater(doc, "change", doc, change);
6400
+ }
6401
+
6402
+ // The document is represented as a BTree consisting of leaves, with
6403
+ // chunk of lines in them, and branches, with up to ten leaves or
6404
+ // other branch nodes below them. The top node is always a branch
6405
+ // node, and is the document object itself (meaning it has
6406
+ // additional methods and properties).
6407
+ //
6408
+ // All nodes have parent links. The tree is used both to go from
6409
+ // line numbers to line objects, and to go from objects to numbers.
6410
+ // It also indexes by height, and is used to convert between height
6411
+ // and line object, and to find the total height of the document.
6412
+ //
6413
+ // See also http://marijnhaverbeke.nl/blog/codemirror-line-tree.html
6414
+
6415
+ function LeafChunk(lines) {
6416
+ this.lines = lines;
6417
+ this.parent = null;
6418
+ for (var i = 0, height = 0; i < lines.length; ++i) {
6419
+ lines[i].parent = this;
6420
+ height += lines[i].height;
6421
+ }
6422
+ this.height = height;
6423
+ }
6424
+
6425
+ LeafChunk.prototype = {
6426
+ chunkSize: function() { return this.lines.length; },
6427
+ // Remove the n lines at offset 'at'.
6428
+ removeInner: function(at, n) {
6429
+ for (var i = at, e = at + n; i < e; ++i) {
6430
+ var line = this.lines[i];
6431
+ this.height -= line.height;
6432
+ cleanUpLine(line);
6433
+ signalLater(line, "delete");
6434
+ }
6435
+ this.lines.splice(at, n);
6436
+ },
6437
+ // Helper used to collapse a small branch into a single leaf.
6438
+ collapse: function(lines) {
6439
+ lines.push.apply(lines, this.lines);
6440
+ },
6441
+ // Insert the given array of lines at offset 'at', count them as
6442
+ // having the given height.
6443
+ insertInner: function(at, lines, height) {
6444
+ this.height += height;
6445
+ this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
6446
+ for (var i = 0; i < lines.length; ++i) lines[i].parent = this;
6447
+ },
6448
+ // Used to iterate over a part of the tree.
6449
+ iterN: function(at, n, op) {
6450
+ for (var e = at + n; at < e; ++at)
6451
+ if (op(this.lines[at])) return true;
6452
+ }
6453
+ };
6454
+
6455
+ function BranchChunk(children) {
6456
+ this.children = children;
6457
+ var size = 0, height = 0;
6458
+ for (var i = 0; i < children.length; ++i) {
6459
+ var ch = children[i];
6460
+ size += ch.chunkSize(); height += ch.height;
6461
+ ch.parent = this;
6462
+ }
6463
+ this.size = size;
6464
+ this.height = height;
6465
+ this.parent = null;
6466
+ }
6467
+
6468
+ BranchChunk.prototype = {
6469
+ chunkSize: function() { return this.size; },
6470
+ removeInner: function(at, n) {
6471
+ this.size -= n;
6472
+ for (var i = 0; i < this.children.length; ++i) {
6473
+ var child = this.children[i], sz = child.chunkSize();
6474
+ if (at < sz) {
6475
+ var rm = Math.min(n, sz - at), oldHeight = child.height;
6476
+ child.removeInner(at, rm);
6477
+ this.height -= oldHeight - child.height;
6478
+ if (sz == rm) { this.children.splice(i--, 1); child.parent = null; }
6479
+ if ((n -= rm) == 0) break;
6480
+ at = 0;
6481
+ } else at -= sz;
6482
+ }
6483
+ // If the result is smaller than 25 lines, ensure that it is a
6484
+ // single leaf node.
6485
+ if (this.size - n < 25 &&
6486
+ (this.children.length > 1 || !(this.children[0] instanceof LeafChunk))) {
6487
+ var lines = [];
6488
+ this.collapse(lines);
6489
+ this.children = [new LeafChunk(lines)];
6490
+ this.children[0].parent = this;
6491
+ }
6492
+ },
6493
+ collapse: function(lines) {
6494
+ for (var i = 0; i < this.children.length; ++i) this.children[i].collapse(lines);
6495
+ },
6496
+ insertInner: function(at, lines, height) {
6497
+ this.size += lines.length;
6498
+ this.height += height;
6499
+ for (var i = 0; i < this.children.length; ++i) {
6500
+ var child = this.children[i], sz = child.chunkSize();
6501
+ if (at <= sz) {
6502
+ child.insertInner(at, lines, height);
6503
+ if (child.lines && child.lines.length > 50) {
6504
+ while (child.lines.length > 50) {
6505
+ var spilled = child.lines.splice(child.lines.length - 25, 25);
6506
+ var newleaf = new LeafChunk(spilled);
6507
+ child.height -= newleaf.height;
6508
+ this.children.splice(i + 1, 0, newleaf);
6509
+ newleaf.parent = this;
6510
+ }
6511
+ this.maybeSpill();
6512
+ }
6513
+ break;
6514
+ }
6515
+ at -= sz;
6516
+ }
6517
+ },
6518
+ // When a node has grown, check whether it should be split.
6519
+ maybeSpill: function() {
6520
+ if (this.children.length <= 10) return;
6521
+ var me = this;
6522
+ do {
6523
+ var spilled = me.children.splice(me.children.length - 5, 5);
6524
+ var sibling = new BranchChunk(spilled);
6525
+ if (!me.parent) { // Become the parent node
6526
+ var copy = new BranchChunk(me.children);
6527
+ copy.parent = me;
6528
+ me.children = [copy, sibling];
6529
+ me = copy;
6530
+ } else {
6531
+ me.size -= sibling.size;
6532
+ me.height -= sibling.height;
6533
+ var myIndex = indexOf(me.parent.children, me);
6534
+ me.parent.children.splice(myIndex + 1, 0, sibling);
6535
+ }
6536
+ sibling.parent = me.parent;
6537
+ } while (me.children.length > 10);
6538
+ me.parent.maybeSpill();
6539
+ },
6540
+ iterN: function(at, n, op) {
6541
+ for (var i = 0; i < this.children.length; ++i) {
6542
+ var child = this.children[i], sz = child.chunkSize();
6543
+ if (at < sz) {
6544
+ var used = Math.min(n, sz - at);
6545
+ if (child.iterN(at, used, op)) return true;
6546
+ if ((n -= used) == 0) break;
6547
+ at = 0;
6548
+ } else at -= sz;
6549
+ }
6550
+ }
6551
+ };
6552
+
6553
+ var nextDocId = 0;
6554
+ var Doc = CodeMirror.Doc = function(text, mode, firstLine) {
6555
+ if (!(this instanceof Doc)) return new Doc(text, mode, firstLine);
6556
+ if (firstLine == null) firstLine = 0;
6557
+
6558
+ BranchChunk.call(this, [new LeafChunk([new Line("", null)])]);
6559
+ this.first = firstLine;
6560
+ this.scrollTop = this.scrollLeft = 0;
6561
+ this.cantEdit = false;
6562
+ this.cleanGeneration = 1;
6563
+ this.frontier = firstLine;
6564
+ var start = Pos(firstLine, 0);
6565
+ this.sel = simpleSelection(start);
6566
+ this.history = new History(null);
6567
+ this.id = ++nextDocId;
6568
+ this.modeOption = mode;
6569
+
6570
+ if (typeof text == "string") text = splitLines(text);
6571
+ updateDoc(this, {from: start, to: start, text: text});
6572
+ setSelection(this, simpleSelection(start), sel_dontScroll);
6573
+ };
6574
+
6575
+ Doc.prototype = createObj(BranchChunk.prototype, {
6576
+ constructor: Doc,
6577
+ // Iterate over the document. Supports two forms -- with only one
6578
+ // argument, it calls that for each line in the document. With
6579
+ // three, it iterates over the range given by the first two (with
6580
+ // the second being non-inclusive).
6581
+ iter: function(from, to, op) {
6582
+ if (op) this.iterN(from - this.first, to - from, op);
6583
+ else this.iterN(this.first, this.first + this.size, from);
6584
+ },
6585
+
6586
+ // Non-public interface for adding and removing lines.
6587
+ insert: function(at, lines) {
6588
+ var height = 0;
6589
+ for (var i = 0; i < lines.length; ++i) height += lines[i].height;
6590
+ this.insertInner(at - this.first, lines, height);
6591
+ },
6592
+ remove: function(at, n) { this.removeInner(at - this.first, n); },
6593
+
6594
+ // From here, the methods are part of the public interface. Most
6595
+ // are also available from CodeMirror (editor) instances.
6596
+
6597
+ getValue: function(lineSep) {
6598
+ var lines = getLines(this, this.first, this.first + this.size);
6599
+ if (lineSep === false) return lines;
6600
+ return lines.join(lineSep || "\n");
6601
+ },
6602
+ setValue: docMethodOp(function(code) {
6603
+ var top = Pos(this.first, 0), last = this.first + this.size - 1;
6604
+ makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length),
6605
+ text: splitLines(code), origin: "setValue", full: true}, true);
6606
+ setSelection(this, simpleSelection(top));
6607
+ }),
6608
+ replaceRange: function(code, from, to, origin) {
6609
+ from = clipPos(this, from);
6610
+ to = to ? clipPos(this, to) : from;
6611
+ replaceRange(this, code, from, to, origin);
6612
+ },
6613
+ getRange: function(from, to, lineSep) {
6614
+ var lines = getBetween(this, clipPos(this, from), clipPos(this, to));
6615
+ if (lineSep === false) return lines;
6616
+ return lines.join(lineSep || "\n");
6617
+ },
6618
+
6619
+ getLine: function(line) {var l = this.getLineHandle(line); return l && l.text;},
6620
+
6621
+ getLineHandle: function(line) {if (isLine(this, line)) return getLine(this, line);},
6622
+ getLineNumber: function(line) {return lineNo(line);},
6623
+
6624
+ getLineHandleVisualStart: function(line) {
6625
+ if (typeof line == "number") line = getLine(this, line);
6626
+ return visualLine(line);
6627
+ },
6628
+
6629
+ lineCount: function() {return this.size;},
6630
+ firstLine: function() {return this.first;},
6631
+ lastLine: function() {return this.first + this.size - 1;},
6632
+
6633
+ clipPos: function(pos) {return clipPos(this, pos);},
6634
+
6635
+ getCursor: function(start) {
6636
+ var range = this.sel.primary(), pos;
6637
+ if (start == null || start == "head") pos = range.head;
6638
+ else if (start == "anchor") pos = range.anchor;
6639
+ else if (start == "end" || start == "to" || start === false) pos = range.to();
6640
+ else pos = range.from();
6641
+ return pos;
6642
+ },
6643
+ listSelections: function() { return this.sel.ranges; },
6644
+ somethingSelected: function() {return this.sel.somethingSelected();},
6645
+
6646
+ setCursor: docMethodOp(function(line, ch, options) {
6647
+ setSimpleSelection(this, clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line), null, options);
6648
+ }),
6649
+ setSelection: docMethodOp(function(anchor, head, options) {
6650
+ setSimpleSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), options);
6651
+ }),
6652
+ extendSelection: docMethodOp(function(head, other, options) {
6653
+ extendSelection(this, clipPos(this, head), other && clipPos(this, other), options);
6654
+ }),
6655
+ extendSelections: docMethodOp(function(heads, options) {
6656
+ extendSelections(this, clipPosArray(this, heads, options));
6657
+ }),
6658
+ extendSelectionsBy: docMethodOp(function(f, options) {
6659
+ extendSelections(this, map(this.sel.ranges, f), options);
6660
+ }),
6661
+ setSelections: docMethodOp(function(ranges, primary, options) {
6662
+ if (!ranges.length) return;
6663
+ for (var i = 0, out = []; i < ranges.length; i++)
6664
+ out[i] = new Range(clipPos(this, ranges[i].anchor),
6665
+ clipPos(this, ranges[i].head));
6666
+ if (primary == null) primary = Math.min(ranges.length - 1, this.sel.primIndex);
6667
+ setSelection(this, normalizeSelection(out, primary), options);
6668
+ }),
6669
+ addSelection: docMethodOp(function(anchor, head, options) {
6670
+ var ranges = this.sel.ranges.slice(0);
6671
+ ranges.push(new Range(clipPos(this, anchor), clipPos(this, head || anchor)));
6672
+ setSelection(this, normalizeSelection(ranges, ranges.length - 1), options);
6673
+ }),
6674
+
6675
+ getSelection: function(lineSep) {
6676
+ var ranges = this.sel.ranges, lines;
6677
+ for (var i = 0; i < ranges.length; i++) {
6678
+ var sel = getBetween(this, ranges[i].from(), ranges[i].to());
6679
+ lines = lines ? lines.concat(sel) : sel;
6680
+ }
6681
+ if (lineSep === false) return lines;
6682
+ else return lines.join(lineSep || "\n");
6683
+ },
6684
+ getSelections: function(lineSep) {
6685
+ var parts = [], ranges = this.sel.ranges;
6686
+ for (var i = 0; i < ranges.length; i++) {
6687
+ var sel = getBetween(this, ranges[i].from(), ranges[i].to());
6688
+ if (lineSep !== false) sel = sel.join(lineSep || "\n");
6689
+ parts[i] = sel;
6690
+ }
6691
+ return parts;
6692
+ },
6693
+ replaceSelection: function(code, collapse, origin) {
6694
+ var dup = [];
6695
+ for (var i = 0; i < this.sel.ranges.length; i++)
6696
+ dup[i] = code;
6697
+ this.replaceSelections(dup, collapse, origin || "+input");
6698
+ },
6699
+ replaceSelections: docMethodOp(function(code, collapse, origin) {
6700
+ var changes = [], sel = this.sel;
6701
+ for (var i = 0; i < sel.ranges.length; i++) {
6702
+ var range = sel.ranges[i];
6703
+ changes[i] = {from: range.from(), to: range.to(), text: splitLines(code[i]), origin: origin};
6704
+ }
6705
+ var newSel = collapse && collapse != "end" && computeReplacedSel(this, changes, collapse);
6706
+ for (var i = changes.length - 1; i >= 0; i--)
6707
+ makeChange(this, changes[i]);
6708
+ if (newSel) setSelectionReplaceHistory(this, newSel);
6709
+ else if (this.cm) ensureCursorVisible(this.cm);
6710
+ }),
6711
+ undo: docMethodOp(function() {makeChangeFromHistory(this, "undo");}),
6712
+ redo: docMethodOp(function() {makeChangeFromHistory(this, "redo");}),
6713
+ undoSelection: docMethodOp(function() {makeChangeFromHistory(this, "undo", true);}),
6714
+ redoSelection: docMethodOp(function() {makeChangeFromHistory(this, "redo", true);}),
6715
+
6716
+ setExtending: function(val) {this.extend = val;},
6717
+ getExtending: function() {return this.extend;},
6718
+
6719
+ historySize: function() {
6720
+ var hist = this.history, done = 0, undone = 0;
6721
+ for (var i = 0; i < hist.done.length; i++) if (!hist.done[i].ranges) ++done;
6722
+ for (var i = 0; i < hist.undone.length; i++) if (!hist.undone[i].ranges) ++undone;
6723
+ return {undo: done, redo: undone};
6724
+ },
6725
+ clearHistory: function() {this.history = new History(this.history.maxGeneration);},
6726
+
6727
+ markClean: function() {
6728
+ this.cleanGeneration = this.changeGeneration(true);
6729
+ },
6730
+ changeGeneration: function(forceSplit) {
6731
+ if (forceSplit)
6732
+ this.history.lastOp = this.history.lastSelOp = this.history.lastOrigin = null;
6733
+ return this.history.generation;
6734
+ },
6735
+ isClean: function (gen) {
6736
+ return this.history.generation == (gen || this.cleanGeneration);
6737
+ },
6738
+
6739
+ getHistory: function() {
6740
+ return {done: copyHistoryArray(this.history.done),
6741
+ undone: copyHistoryArray(this.history.undone)};
6742
+ },
6743
+ setHistory: function(histData) {
6744
+ var hist = this.history = new History(this.history.maxGeneration);
6745
+ hist.done = copyHistoryArray(histData.done.slice(0), null, true);
6746
+ hist.undone = copyHistoryArray(histData.undone.slice(0), null, true);
6747
+ },
6748
+
6749
+ addLineClass: docMethodOp(function(handle, where, cls) {
6750
+ return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function(line) {
6751
+ var prop = where == "text" ? "textClass"
6752
+ : where == "background" ? "bgClass"
6753
+ : where == "gutter" ? "gutterClass" : "wrapClass";
6754
+ if (!line[prop]) line[prop] = cls;
6755
+ else if (classTest(cls).test(line[prop])) return false;
6756
+ else line[prop] += " " + cls;
6757
+ return true;
6758
+ });
6759
+ }),
6760
+ removeLineClass: docMethodOp(function(handle, where, cls) {
6761
+ return changeLine(this, handle, where == "gutter" ? "gutter" : "class", function(line) {
6762
+ var prop = where == "text" ? "textClass"
6763
+ : where == "background" ? "bgClass"
6764
+ : where == "gutter" ? "gutterClass" : "wrapClass";
6765
+ var cur = line[prop];
6766
+ if (!cur) return false;
6767
+ else if (cls == null) line[prop] = null;
6768
+ else {
6769
+ var found = cur.match(classTest(cls));
6770
+ if (!found) return false;
6771
+ var end = found.index + found[0].length;
6772
+ line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null;
6773
+ }
6774
+ return true;
6775
+ });
6776
+ }),
6777
+
6778
+ markText: function(from, to, options) {
6779
+ return markText(this, clipPos(this, from), clipPos(this, to), options, "range");
6780
+ },
6781
+ setBookmark: function(pos, options) {
6782
+ var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options),
6783
+ insertLeft: options && options.insertLeft,
6784
+ clearWhenEmpty: false, shared: options && options.shared};
6785
+ pos = clipPos(this, pos);
6786
+ return markText(this, pos, pos, realOpts, "bookmark");
6787
+ },
6788
+ findMarksAt: function(pos) {
6789
+ pos = clipPos(this, pos);
6790
+ var markers = [], spans = getLine(this, pos.line).markedSpans;
6791
+ if (spans) for (var i = 0; i < spans.length; ++i) {
6792
+ var span = spans[i];
6793
+ if ((span.from == null || span.from <= pos.ch) &&
6794
+ (span.to == null || span.to >= pos.ch))
6795
+ markers.push(span.marker.parent || span.marker);
6796
+ }
6797
+ return markers;
6798
+ },
6799
+ findMarks: function(from, to, filter) {
6800
+ from = clipPos(this, from); to = clipPos(this, to);
6801
+ var found = [], lineNo = from.line;
6802
+ this.iter(from.line, to.line + 1, function(line) {
6803
+ var spans = line.markedSpans;
6804
+ if (spans) for (var i = 0; i < spans.length; i++) {
6805
+ var span = spans[i];
6806
+ if (!(lineNo == from.line && from.ch > span.to ||
6807
+ span.from == null && lineNo != from.line||
6808
+ lineNo == to.line && span.from > to.ch) &&
6809
+ (!filter || filter(span.marker)))
6810
+ found.push(span.marker.parent || span.marker);
6811
+ }
6812
+ ++lineNo;
6813
+ });
6814
+ return found;
6815
+ },
6816
+ getAllMarks: function() {
6817
+ var markers = [];
6818
+ this.iter(function(line) {
6819
+ var sps = line.markedSpans;
6820
+ if (sps) for (var i = 0; i < sps.length; ++i)
6821
+ if (sps[i].from != null) markers.push(sps[i].marker);
6822
+ });
6823
+ return markers;
6824
+ },
6825
+
6826
+ posFromIndex: function(off) {
6827
+ var ch, lineNo = this.first;
6828
+ this.iter(function(line) {
6829
+ var sz = line.text.length + 1;
6830
+ if (sz > off) { ch = off; return true; }
6831
+ off -= sz;
6832
+ ++lineNo;
6833
+ });
6834
+ return clipPos(this, Pos(lineNo, ch));
6835
+ },
6836
+ indexFromPos: function (coords) {
6837
+ coords = clipPos(this, coords);
6838
+ var index = coords.ch;
6839
+ if (coords.line < this.first || coords.ch < 0) return 0;
6840
+ this.iter(this.first, coords.line, function (line) {
6841
+ index += line.text.length + 1;
6842
+ });
6843
+ return index;
6844
+ },
6845
+
6846
+ copy: function(copyHistory) {
6847
+ var doc = new Doc(getLines(this, this.first, this.first + this.size), this.modeOption, this.first);
6848
+ doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft;
6849
+ doc.sel = this.sel;
6850
+ doc.extend = false;
6851
+ if (copyHistory) {
6852
+ doc.history.undoDepth = this.history.undoDepth;
6853
+ doc.setHistory(this.getHistory());
6854
+ }
6855
+ return doc;
6856
+ },
6857
+
6858
+ linkedDoc: function(options) {
6859
+ if (!options) options = {};
6860
+ var from = this.first, to = this.first + this.size;
6861
+ if (options.from != null && options.from > from) from = options.from;
6862
+ if (options.to != null && options.to < to) to = options.to;
6863
+ var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from);
6864
+ if (options.sharedHist) copy.history = this.history;
6865
+ (this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist});
6866
+ copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}];
6867
+ copySharedMarkers(copy, findSharedMarkers(this));
6868
+ return copy;
6869
+ },
6870
+ unlinkDoc: function(other) {
6871
+ if (other instanceof CodeMirror) other = other.doc;
6872
+ if (this.linked) for (var i = 0; i < this.linked.length; ++i) {
6873
+ var link = this.linked[i];
6874
+ if (link.doc != other) continue;
6875
+ this.linked.splice(i, 1);
6876
+ other.unlinkDoc(this);
6877
+ detachSharedMarkers(findSharedMarkers(this));
6878
+ break;
6879
+ }
6880
+ // If the histories were shared, split them again
6881
+ if (other.history == this.history) {
6882
+ var splitIds = [other.id];
6883
+ linkedDocs(other, function(doc) {splitIds.push(doc.id);}, true);
6884
+ other.history = new History(null);
6885
+ other.history.done = copyHistoryArray(this.history.done, splitIds);
6886
+ other.history.undone = copyHistoryArray(this.history.undone, splitIds);
6887
+ }
6888
+ },
6889
+ iterLinkedDocs: function(f) {linkedDocs(this, f);},
6890
+
6891
+ getMode: function() {return this.mode;},
6892
+ getEditor: function() {return this.cm;}
6893
+ });
6894
+
6895
+ // Public alias.
6896
+ Doc.prototype.eachLine = Doc.prototype.iter;
6897
+
6898
+ // Set up methods on CodeMirror's prototype to redirect to the editor's document.
6899
+ var dontDelegate = "iter insert remove copy getEditor".split(" ");
6900
+ for (var prop in Doc.prototype) if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0)
6901
+ CodeMirror.prototype[prop] = (function(method) {
6902
+ return function() {return method.apply(this.doc, arguments);};
6903
+ })(Doc.prototype[prop]);
6904
+
6905
+ eventMixin(Doc);
6906
+
6907
+ // Call f for all linked documents.
6908
+ function linkedDocs(doc, f, sharedHistOnly) {
6909
+ function propagate(doc, skip, sharedHist) {
6910
+ if (doc.linked) for (var i = 0; i < doc.linked.length; ++i) {
6911
+ var rel = doc.linked[i];
6912
+ if (rel.doc == skip) continue;
6913
+ var shared = sharedHist && rel.sharedHist;
6914
+ if (sharedHistOnly && !shared) continue;
6915
+ f(rel.doc, shared);
6916
+ propagate(rel.doc, doc, shared);
6917
+ }
6918
+ }
6919
+ propagate(doc, null, true);
6920
+ }
6921
+
6922
+ // Attach a document to an editor.
6923
+ function attachDoc(cm, doc) {
6924
+ if (doc.cm) throw new Error("This document is already in use.");
6925
+ cm.doc = doc;
6926
+ doc.cm = cm;
6927
+ estimateLineHeights(cm);
6928
+ loadMode(cm);
6929
+ if (!cm.options.lineWrapping) findMaxLine(cm);
6930
+ cm.options.mode = doc.modeOption;
6931
+ regChange(cm);
6932
+ }
6933
+
6934
+ // LINE UTILITIES
6935
+
6936
+ // Find the line object corresponding to the given line number.
6937
+ function getLine(doc, n) {
6938
+ n -= doc.first;
6939
+ if (n < 0 || n >= doc.size) throw new Error("There is no line " + (n + doc.first) + " in the document.");
6940
+ for (var chunk = doc; !chunk.lines;) {
6941
+ for (var i = 0;; ++i) {
6942
+ var child = chunk.children[i], sz = child.chunkSize();
6943
+ if (n < sz) { chunk = child; break; }
6944
+ n -= sz;
6945
+ }
6946
+ }
6947
+ return chunk.lines[n];
6948
+ }
6949
+
6950
+ // Get the part of a document between two positions, as an array of
6951
+ // strings.
6952
+ function getBetween(doc, start, end) {
6953
+ var out = [], n = start.line;
6954
+ doc.iter(start.line, end.line + 1, function(line) {
6955
+ var text = line.text;
6956
+ if (n == end.line) text = text.slice(0, end.ch);
6957
+ if (n == start.line) text = text.slice(start.ch);
6958
+ out.push(text);
6959
+ ++n;
6960
+ });
6961
+ return out;
6962
+ }
6963
+ // Get the lines between from and to, as array of strings.
6964
+ function getLines(doc, from, to) {
6965
+ var out = [];
6966
+ doc.iter(from, to, function(line) { out.push(line.text); });
6967
+ return out;
6968
+ }
6969
+
6970
+ // Update the height of a line, propagating the height change
6971
+ // upwards to parent nodes.
6972
+ function updateLineHeight(line, height) {
6973
+ var diff = height - line.height;
6974
+ if (diff) for (var n = line; n; n = n.parent) n.height += diff;
6975
+ }
6976
+
6977
+ // Given a line object, find its line number by walking up through
6978
+ // its parent links.
6979
+ function lineNo(line) {
6980
+ if (line.parent == null) return null;
6981
+ var cur = line.parent, no = indexOf(cur.lines, line);
6982
+ for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
6983
+ for (var i = 0;; ++i) {
6984
+ if (chunk.children[i] == cur) break;
6985
+ no += chunk.children[i].chunkSize();
6986
+ }
6987
+ }
6988
+ return no + cur.first;
6989
+ }
6990
+
6991
+ // Find the line at the given vertical position, using the height
6992
+ // information in the document tree.
6993
+ function lineAtHeight(chunk, h) {
6994
+ var n = chunk.first;
6995
+ outer: do {
6996
+ for (var i = 0; i < chunk.children.length; ++i) {
6997
+ var child = chunk.children[i], ch = child.height;
6998
+ if (h < ch) { chunk = child; continue outer; }
6999
+ h -= ch;
7000
+ n += child.chunkSize();
7001
+ }
7002
+ return n;
7003
+ } while (!chunk.lines);
7004
+ for (var i = 0; i < chunk.lines.length; ++i) {
7005
+ var line = chunk.lines[i], lh = line.height;
7006
+ if (h < lh) break;
7007
+ h -= lh;
7008
+ }
7009
+ return n + i;
7010
+ }
7011
+
7012
+
7013
+ // Find the height above the given line.
7014
+ function heightAtLine(lineObj) {
7015
+ lineObj = visualLine(lineObj);
7016
+
7017
+ var h = 0, chunk = lineObj.parent;
7018
+ for (var i = 0; i < chunk.lines.length; ++i) {
7019
+ var line = chunk.lines[i];
7020
+ if (line == lineObj) break;
7021
+ else h += line.height;
7022
+ }
7023
+ for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
7024
+ for (var i = 0; i < p.children.length; ++i) {
7025
+ var cur = p.children[i];
7026
+ if (cur == chunk) break;
7027
+ else h += cur.height;
7028
+ }
7029
+ }
7030
+ return h;
7031
+ }
7032
+
7033
+ // Get the bidi ordering for the given line (and cache it). Returns
7034
+ // false for lines that are fully left-to-right, and an array of
7035
+ // BidiSpan objects otherwise.
7036
+ function getOrder(line) {
7037
+ var order = line.order;
7038
+ if (order == null) order = line.order = bidiOrdering(line.text);
7039
+ return order;
7040
+ }
7041
+
7042
+ // HISTORY
7043
+
7044
+ function History(startGen) {
7045
+ // Arrays of change events and selections. Doing something adds an
7046
+ // event to done and clears undo. Undoing moves events from done
7047
+ // to undone, redoing moves them in the other direction.
7048
+ this.done = []; this.undone = [];
7049
+ this.undoDepth = Infinity;
7050
+ // Used to track when changes can be merged into a single undo
7051
+ // event
7052
+ this.lastModTime = this.lastSelTime = 0;
7053
+ this.lastOp = this.lastSelOp = null;
7054
+ this.lastOrigin = this.lastSelOrigin = null;
7055
+ // Used by the isClean() method
7056
+ this.generation = this.maxGeneration = startGen || 1;
7057
+ }
7058
+
7059
+ // Create a history change event from an updateDoc-style change
7060
+ // object.
7061
+ function historyChangeFromChange(doc, change) {
7062
+ var histChange = {from: copyPos(change.from), to: changeEnd(change), text: getBetween(doc, change.from, change.to)};
7063
+ attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);
7064
+ linkedDocs(doc, function(doc) {attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);}, true);
7065
+ return histChange;
7066
+ }
7067
+
7068
+ // Pop all selection events off the end of a history array. Stop at
7069
+ // a change event.
7070
+ function clearSelectionEvents(array) {
7071
+ while (array.length) {
7072
+ var last = lst(array);
7073
+ if (last.ranges) array.pop();
7074
+ else break;
7075
+ }
7076
+ }
7077
+
7078
+ // Find the top change event in the history. Pop off selection
7079
+ // events that are in the way.
7080
+ function lastChangeEvent(hist, force) {
7081
+ if (force) {
7082
+ clearSelectionEvents(hist.done);
7083
+ return lst(hist.done);
7084
+ } else if (hist.done.length && !lst(hist.done).ranges) {
7085
+ return lst(hist.done);
7086
+ } else if (hist.done.length > 1 && !hist.done[hist.done.length - 2].ranges) {
7087
+ hist.done.pop();
7088
+ return lst(hist.done);
7089
+ }
7090
+ }
7091
+
7092
+ // Register a change in the history. Merges changes that are within
7093
+ // a single operation, ore are close together with an origin that
7094
+ // allows merging (starting with "+") into a single event.
7095
+ function addChangeToHistory(doc, change, selAfter, opId) {
7096
+ var hist = doc.history;
7097
+ hist.undone.length = 0;
7098
+ var time = +new Date, cur;
7099
+
7100
+ if ((hist.lastOp == opId ||
7101
+ hist.lastOrigin == change.origin && change.origin &&
7102
+ ((change.origin.charAt(0) == "+" && doc.cm && hist.lastModTime > time - doc.cm.options.historyEventDelay) ||
7103
+ change.origin.charAt(0) == "*")) &&
7104
+ (cur = lastChangeEvent(hist, hist.lastOp == opId))) {
7105
+ // Merge this change into the last event
7106
+ var last = lst(cur.changes);
7107
+ if (cmp(change.from, change.to) == 0 && cmp(change.from, last.to) == 0) {
7108
+ // Optimized case for simple insertion -- don't want to add
7109
+ // new changesets for every character typed
7110
+ last.to = changeEnd(change);
7111
+ } else {
7112
+ // Add new sub-event
7113
+ cur.changes.push(historyChangeFromChange(doc, change));
7114
+ }
7115
+ } else {
7116
+ // Can not be merged, start a new event.
7117
+ var before = lst(hist.done);
7118
+ if (!before || !before.ranges)
7119
+ pushSelectionToHistory(doc.sel, hist.done);
7120
+ cur = {changes: [historyChangeFromChange(doc, change)],
7121
+ generation: hist.generation};
7122
+ hist.done.push(cur);
7123
+ while (hist.done.length > hist.undoDepth) {
7124
+ hist.done.shift();
7125
+ if (!hist.done[0].ranges) hist.done.shift();
7126
+ }
7127
+ }
7128
+ hist.done.push(selAfter);
7129
+ hist.generation = ++hist.maxGeneration;
7130
+ hist.lastModTime = hist.lastSelTime = time;
7131
+ hist.lastOp = hist.lastSelOp = opId;
7132
+ hist.lastOrigin = hist.lastSelOrigin = change.origin;
7133
+
7134
+ if (!last) signal(doc, "historyAdded");
7135
+ }
7136
+
7137
+ function selectionEventCanBeMerged(doc, origin, prev, sel) {
7138
+ var ch = origin.charAt(0);
7139
+ return ch == "*" ||
7140
+ ch == "+" &&
7141
+ prev.ranges.length == sel.ranges.length &&
7142
+ prev.somethingSelected() == sel.somethingSelected() &&
7143
+ new Date - doc.history.lastSelTime <= (doc.cm ? doc.cm.options.historyEventDelay : 500);
7144
+ }
7145
+
7146
+ // Called whenever the selection changes, sets the new selection as
7147
+ // the pending selection in the history, and pushes the old pending
7148
+ // selection into the 'done' array when it was significantly
7149
+ // different (in number of selected ranges, emptiness, or time).
7150
+ function addSelectionToHistory(doc, sel, opId, options) {
7151
+ var hist = doc.history, origin = options && options.origin;
7152
+
7153
+ // A new event is started when the previous origin does not match
7154
+ // the current, or the origins don't allow matching. Origins
7155
+ // starting with * are always merged, those starting with + are
7156
+ // merged when similar and close together in time.
7157
+ if (opId == hist.lastSelOp ||
7158
+ (origin && hist.lastSelOrigin == origin &&
7159
+ (hist.lastModTime == hist.lastSelTime && hist.lastOrigin == origin ||
7160
+ selectionEventCanBeMerged(doc, origin, lst(hist.done), sel))))
7161
+ hist.done[hist.done.length - 1] = sel;
7162
+ else
7163
+ pushSelectionToHistory(sel, hist.done);
7164
+
7165
+ hist.lastSelTime = +new Date;
7166
+ hist.lastSelOrigin = origin;
7167
+ hist.lastSelOp = opId;
7168
+ if (options && options.clearRedo !== false)
7169
+ clearSelectionEvents(hist.undone);
7170
+ }
7171
+
7172
+ function pushSelectionToHistory(sel, dest) {
7173
+ var top = lst(dest);
7174
+ if (!(top && top.ranges && top.equals(sel)))
7175
+ dest.push(sel);
7176
+ }
7177
+
7178
+ // Used to store marked span information in the history.
7179
+ function attachLocalSpans(doc, change, from, to) {
7180
+ var existing = change["spans_" + doc.id], n = 0;
7181
+ doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function(line) {
7182
+ if (line.markedSpans)
7183
+ (existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans;
7184
+ ++n;
7185
+ });
7186
+ }
7187
+
7188
+ // When un/re-doing restores text containing marked spans, those
7189
+ // that have been explicitly cleared should not be restored.
7190
+ function removeClearedSpans(spans) {
7191
+ if (!spans) return null;
7192
+ for (var i = 0, out; i < spans.length; ++i) {
7193
+ if (spans[i].marker.explicitlyCleared) { if (!out) out = spans.slice(0, i); }
7194
+ else if (out) out.push(spans[i]);
7195
+ }
7196
+ return !out ? spans : out.length ? out : null;
7197
+ }
7198
+
7199
+ // Retrieve and filter the old marked spans stored in a change event.
7200
+ function getOldSpans(doc, change) {
7201
+ var found = change["spans_" + doc.id];
7202
+ if (!found) return null;
7203
+ for (var i = 0, nw = []; i < change.text.length; ++i)
7204
+ nw.push(removeClearedSpans(found[i]));
7205
+ return nw;
7206
+ }
7207
+
7208
+ // Used both to provide a JSON-safe object in .getHistory, and, when
7209
+ // detaching a document, to split the history in two
7210
+ function copyHistoryArray(events, newGroup, instantiateSel) {
7211
+ for (var i = 0, copy = []; i < events.length; ++i) {
7212
+ var event = events[i];
7213
+ if (event.ranges) {
7214
+ copy.push(instantiateSel ? Selection.prototype.deepCopy.call(event) : event);
7215
+ continue;
7216
+ }
7217
+ var changes = event.changes, newChanges = [];
7218
+ copy.push({changes: newChanges});
7219
+ for (var j = 0; j < changes.length; ++j) {
7220
+ var change = changes[j], m;
7221
+ newChanges.push({from: change.from, to: change.to, text: change.text});
7222
+ if (newGroup) for (var prop in change) if (m = prop.match(/^spans_(\d+)$/)) {
7223
+ if (indexOf(newGroup, Number(m[1])) > -1) {
7224
+ lst(newChanges)[prop] = change[prop];
7225
+ delete change[prop];
7226
+ }
7227
+ }
7228
+ }
7229
+ }
7230
+ return copy;
7231
+ }
7232
+
7233
+ // Rebasing/resetting history to deal with externally-sourced changes
7234
+
7235
+ function rebaseHistSelSingle(pos, from, to, diff) {
7236
+ if (to < pos.line) {
7237
+ pos.line += diff;
7238
+ } else if (from < pos.line) {
7239
+ pos.line = from;
7240
+ pos.ch = 0;
7241
+ }
7242
+ }
7243
+
7244
+ // Tries to rebase an array of history events given a change in the
7245
+ // document. If the change touches the same lines as the event, the
7246
+ // event, and everything 'behind' it, is discarded. If the change is
7247
+ // before the event, the event's positions are updated. Uses a
7248
+ // copy-on-write scheme for the positions, to avoid having to
7249
+ // reallocate them all on every rebase, but also avoid problems with
7250
+ // shared position objects being unsafely updated.
7251
+ function rebaseHistArray(array, from, to, diff) {
7252
+ for (var i = 0; i < array.length; ++i) {
7253
+ var sub = array[i], ok = true;
7254
+ if (sub.ranges) {
7255
+ if (!sub.copied) { sub = array[i] = sub.deepCopy(); sub.copied = true; }
7256
+ for (var j = 0; j < sub.ranges.length; j++) {
7257
+ rebaseHistSelSingle(sub.ranges[j].anchor, from, to, diff);
7258
+ rebaseHistSelSingle(sub.ranges[j].head, from, to, diff);
7259
+ }
7260
+ continue;
7261
+ }
7262
+ for (var j = 0; j < sub.changes.length; ++j) {
7263
+ var cur = sub.changes[j];
7264
+ if (to < cur.from.line) {
7265
+ cur.from = Pos(cur.from.line + diff, cur.from.ch);
7266
+ cur.to = Pos(cur.to.line + diff, cur.to.ch);
7267
+ } else if (from <= cur.to.line) {
7268
+ ok = false;
7269
+ break;
7270
+ }
7271
+ }
7272
+ if (!ok) {
7273
+ array.splice(0, i + 1);
7274
+ i = 0;
7275
+ }
7276
+ }
7277
+ }
7278
+
7279
+ function rebaseHist(hist, change) {
7280
+ var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1;
7281
+ rebaseHistArray(hist.done, from, to, diff);
7282
+ rebaseHistArray(hist.undone, from, to, diff);
7283
+ }
7284
+
7285
+ // EVENT UTILITIES
7286
+
7287
+ // Due to the fact that we still support jurassic IE versions, some
7288
+ // compatibility wrappers are needed.
7289
+
7290
+ var e_preventDefault = CodeMirror.e_preventDefault = function(e) {
7291
+ if (e.preventDefault) e.preventDefault();
7292
+ else e.returnValue = false;
7293
+ };
7294
+ var e_stopPropagation = CodeMirror.e_stopPropagation = function(e) {
7295
+ if (e.stopPropagation) e.stopPropagation();
7296
+ else e.cancelBubble = true;
7297
+ };
7298
+ function e_defaultPrevented(e) {
7299
+ return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false;
7300
+ }
7301
+ var e_stop = CodeMirror.e_stop = function(e) {e_preventDefault(e); e_stopPropagation(e);};
7302
+
7303
+ function e_target(e) {return e.target || e.srcElement;}
7304
+ function e_button(e) {
7305
+ var b = e.which;
7306
+ if (b == null) {
7307
+ if (e.button & 1) b = 1;
7308
+ else if (e.button & 2) b = 3;
7309
+ else if (e.button & 4) b = 2;
7310
+ }
7311
+ if (mac && e.ctrlKey && b == 1) b = 3;
7312
+ return b;
7313
+ }
7314
+
7315
+ // EVENT HANDLING
7316
+
7317
+ // Lightweight event framework. on/off also work on DOM nodes,
7318
+ // registering native DOM handlers.
7319
+
7320
+ var on = CodeMirror.on = function(emitter, type, f) {
7321
+ if (emitter.addEventListener)
7322
+ emitter.addEventListener(type, f, false);
7323
+ else if (emitter.attachEvent)
7324
+ emitter.attachEvent("on" + type, f);
7325
+ else {
7326
+ var map = emitter._handlers || (emitter._handlers = {});
7327
+ var arr = map[type] || (map[type] = []);
7328
+ arr.push(f);
7329
+ }
7330
+ };
7331
+
7332
+ var off = CodeMirror.off = function(emitter, type, f) {
7333
+ if (emitter.removeEventListener)
7334
+ emitter.removeEventListener(type, f, false);
7335
+ else if (emitter.detachEvent)
7336
+ emitter.detachEvent("on" + type, f);
7337
+ else {
7338
+ var arr = emitter._handlers && emitter._handlers[type];
7339
+ if (!arr) return;
7340
+ for (var i = 0; i < arr.length; ++i)
7341
+ if (arr[i] == f) { arr.splice(i, 1); break; }
7342
+ }
7343
+ };
7344
+
7345
+ var signal = CodeMirror.signal = function(emitter, type /*, values...*/) {
7346
+ var arr = emitter._handlers && emitter._handlers[type];
7347
+ if (!arr) return;
7348
+ var args = Array.prototype.slice.call(arguments, 2);
7349
+ for (var i = 0; i < arr.length; ++i) arr[i].apply(null, args);
7350
+ };
7351
+
7352
+ var orphanDelayedCallbacks = null;
7353
+
7354
+ // Often, we want to signal events at a point where we are in the
7355
+ // middle of some work, but don't want the handler to start calling
7356
+ // other methods on the editor, which might be in an inconsistent
7357
+ // state or simply not expect any other events to happen.
7358
+ // signalLater looks whether there are any handlers, and schedules
7359
+ // them to be executed when the last operation ends, or, if no
7360
+ // operation is active, when a timeout fires.
7361
+ function signalLater(emitter, type /*, values...*/) {
7362
+ var arr = emitter._handlers && emitter._handlers[type];
7363
+ if (!arr) return;
7364
+ var args = Array.prototype.slice.call(arguments, 2), list;
7365
+ if (operationGroup) {
7366
+ list = operationGroup.delayedCallbacks;
7367
+ } else if (orphanDelayedCallbacks) {
7368
+ list = orphanDelayedCallbacks;
7369
+ } else {
7370
+ list = orphanDelayedCallbacks = [];
7371
+ setTimeout(fireOrphanDelayed, 0);
7372
+ }
7373
+ function bnd(f) {return function(){f.apply(null, args);};};
7374
+ for (var i = 0; i < arr.length; ++i)
7375
+ list.push(bnd(arr[i]));
7376
+ }
7377
+
7378
+ function fireOrphanDelayed() {
7379
+ var delayed = orphanDelayedCallbacks;
7380
+ orphanDelayedCallbacks = null;
7381
+ for (var i = 0; i < delayed.length; ++i) delayed[i]();
7382
+ }
7383
+
7384
+ // The DOM events that CodeMirror handles can be overridden by
7385
+ // registering a (non-DOM) handler on the editor for the event name,
7386
+ // and preventDefault-ing the event in that handler.
7387
+ function signalDOMEvent(cm, e, override) {
7388
+ if (typeof e == "string")
7389
+ e = {type: e, preventDefault: function() { this.defaultPrevented = true; }};
7390
+ signal(cm, override || e.type, cm, e);
7391
+ return e_defaultPrevented(e) || e.codemirrorIgnore;
7392
+ }
7393
+
7394
+ function signalCursorActivity(cm) {
7395
+ var arr = cm._handlers && cm._handlers.cursorActivity;
7396
+ if (!arr) return;
7397
+ var set = cm.curOp.cursorActivityHandlers || (cm.curOp.cursorActivityHandlers = []);
7398
+ for (var i = 0; i < arr.length; ++i) if (indexOf(set, arr[i]) == -1)
7399
+ set.push(arr[i]);
7400
+ }
7401
+
7402
+ function hasHandler(emitter, type) {
7403
+ var arr = emitter._handlers && emitter._handlers[type];
7404
+ return arr && arr.length > 0;
7405
+ }
7406
+
7407
+ // Add on and off methods to a constructor's prototype, to make
7408
+ // registering events on such objects more convenient.
7409
+ function eventMixin(ctor) {
7410
+ ctor.prototype.on = function(type, f) {on(this, type, f);};
7411
+ ctor.prototype.off = function(type, f) {off(this, type, f);};
7412
+ }
7413
+
7414
+ // MISC UTILITIES
7415
+
7416
+ // Number of pixels added to scroller and sizer to hide scrollbar
7417
+ var scrollerGap = 30;
7418
+
7419
+ // Returned or thrown by various protocols to signal 'I'm not
7420
+ // handling this'.
7421
+ var Pass = CodeMirror.Pass = {toString: function(){return "CodeMirror.Pass";}};
7422
+
7423
+ // Reused option objects for setSelection & friends
7424
+ var sel_dontScroll = {scroll: false}, sel_mouse = {origin: "*mouse"}, sel_move = {origin: "+move"};
7425
+
7426
+ function Delayed() {this.id = null;}
7427
+ Delayed.prototype.set = function(ms, f) {
7428
+ clearTimeout(this.id);
7429
+ this.id = setTimeout(f, ms);
7430
+ };
7431
+
7432
+ // Counts the column offset in a string, taking tabs into account.
7433
+ // Used mostly to find indentation.
7434
+ var countColumn = CodeMirror.countColumn = function(string, end, tabSize, startIndex, startValue) {
7435
+ if (end == null) {
7436
+ end = string.search(/[^\s\u00a0]/);
7437
+ if (end == -1) end = string.length;
7438
+ }
7439
+ for (var i = startIndex || 0, n = startValue || 0;;) {
7440
+ var nextTab = string.indexOf("\t", i);
7441
+ if (nextTab < 0 || nextTab >= end)
7442
+ return n + (end - i);
7443
+ n += nextTab - i;
7444
+ n += tabSize - (n % tabSize);
7445
+ i = nextTab + 1;
7446
+ }
7447
+ };
7448
+
7449
+ // The inverse of countColumn -- find the offset that corresponds to
7450
+ // a particular column.
7451
+ function findColumn(string, goal, tabSize) {
7452
+ for (var pos = 0, col = 0;;) {
7453
+ var nextTab = string.indexOf("\t", pos);
7454
+ if (nextTab == -1) nextTab = string.length;
7455
+ var skipped = nextTab - pos;
7456
+ if (nextTab == string.length || col + skipped >= goal)
7457
+ return pos + Math.min(skipped, goal - col);
7458
+ col += nextTab - pos;
7459
+ col += tabSize - (col % tabSize);
7460
+ pos = nextTab + 1;
7461
+ if (col >= goal) return pos;
7462
+ }
7463
+ }
7464
+
7465
+ var spaceStrs = [""];
7466
+ function spaceStr(n) {
7467
+ while (spaceStrs.length <= n)
7468
+ spaceStrs.push(lst(spaceStrs) + " ");
7469
+ return spaceStrs[n];
7470
+ }
7471
+
7472
+ function lst(arr) { return arr[arr.length-1]; }
7473
+
7474
+ var selectInput = function(node) { node.select(); };
7475
+ if (ios) // Mobile Safari apparently has a bug where select() is broken.
7476
+ selectInput = function(node) { node.selectionStart = 0; node.selectionEnd = node.value.length; };
7477
+ else if (ie) // Suppress mysterious IE10 errors
7478
+ selectInput = function(node) { try { node.select(); } catch(_e) {} };
7479
+
7480
+ function indexOf(array, elt) {
7481
+ for (var i = 0; i < array.length; ++i)
7482
+ if (array[i] == elt) return i;
7483
+ return -1;
7484
+ }
7485
+ function map(array, f) {
7486
+ var out = [];
7487
+ for (var i = 0; i < array.length; i++) out[i] = f(array[i], i);
7488
+ return out;
7489
+ }
7490
+
7491
+ function createObj(base, props) {
7492
+ var inst;
7493
+ if (Object.create) {
7494
+ inst = Object.create(base);
7495
+ } else {
7496
+ var ctor = function() {};
7497
+ ctor.prototype = base;
7498
+ inst = new ctor();
7499
+ }
7500
+ if (props) copyObj(props, inst);
7501
+ return inst;
7502
+ };
7503
+
7504
+ function copyObj(obj, target, overwrite) {
7505
+ if (!target) target = {};
7506
+ for (var prop in obj)
7507
+ if (obj.hasOwnProperty(prop) && (overwrite !== false || !target.hasOwnProperty(prop)))
7508
+ target[prop] = obj[prop];
7509
+ return target;
7510
+ }
7511
+
7512
+ function bind(f) {
7513
+ var args = Array.prototype.slice.call(arguments, 1);
7514
+ return function(){return f.apply(null, args);};
7515
+ }
7516
+
7517
+ var nonASCIISingleCaseWordChar = /[\u00df\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
7518
+ var isWordCharBasic = CodeMirror.isWordChar = function(ch) {
7519
+ return /\w/.test(ch) || ch > "\x80" &&
7520
+ (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch));
7521
+ };
7522
+ function isWordChar(ch, helper) {
7523
+ if (!helper) return isWordCharBasic(ch);
7524
+ if (helper.source.indexOf("\\w") > -1 && isWordCharBasic(ch)) return true;
7525
+ return helper.test(ch);
7526
+ }
7527
+
7528
+ function isEmpty(obj) {
7529
+ for (var n in obj) if (obj.hasOwnProperty(n) && obj[n]) return false;
7530
+ return true;
7531
+ }
7532
+
7533
+ // Extending unicode characters. A series of a non-extending char +
7534
+ // any number of extending chars is treated as a single unit as far
7535
+ // as editing and measuring is concerned. This is not fully correct,
7536
+ // since some scripts/fonts/browsers also treat other configurations
7537
+ // of code points as a group.
7538
+ var extendingChars = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/;
7539
+ function isExtendingChar(ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch); }
7540
+
7541
+ // DOM UTILITIES
7542
+
7543
+ function elt(tag, content, className, style) {
7544
+ var e = document.createElement(tag);
7545
+ if (className) e.className = className;
7546
+ if (style) e.style.cssText = style;
7547
+ if (typeof content == "string") e.appendChild(document.createTextNode(content));
7548
+ else if (content) for (var i = 0; i < content.length; ++i) e.appendChild(content[i]);
7549
+ return e;
7550
+ }
7551
+
7552
+ var range;
7553
+ if (document.createRange) range = function(node, start, end) {
7554
+ var r = document.createRange();
7555
+ r.setEnd(node, end);
7556
+ r.setStart(node, start);
7557
+ return r;
7558
+ };
7559
+ else range = function(node, start, end) {
7560
+ var r = document.body.createTextRange();
7561
+ try { r.moveToElementText(node.parentNode); }
7562
+ catch(e) { return r; }
7563
+ r.collapse(true);
7564
+ r.moveEnd("character", end);
7565
+ r.moveStart("character", start);
7566
+ return r;
7567
+ };
7568
+
7569
+ function removeChildren(e) {
7570
+ for (var count = e.childNodes.length; count > 0; --count)
7571
+ e.removeChild(e.firstChild);
7572
+ return e;
7573
+ }
7574
+
7575
+ function removeChildrenAndAdd(parent, e) {
7576
+ return removeChildren(parent).appendChild(e);
7577
+ }
7578
+
7579
+ function contains(parent, child) {
7580
+ if (parent.contains)
7581
+ return parent.contains(child);
7582
+ while (child = child.parentNode)
7583
+ if (child == parent) return true;
7584
+ }
7585
+
7586
+ function activeElt() { return document.activeElement; }
7587
+ // Older versions of IE throws unspecified error when touching
7588
+ // document.activeElement in some cases (during loading, in iframe)
7589
+ if (ie && ie_version < 11) activeElt = function() {
7590
+ try { return document.activeElement; }
7591
+ catch(e) { return document.body; }
7592
+ };
7593
+
7594
+ function classTest(cls) { return new RegExp("(^|\\s)" + cls + "(?:$|\\s)\\s*"); }
7595
+ var rmClass = CodeMirror.rmClass = function(node, cls) {
7596
+ var current = node.className;
7597
+ var match = classTest(cls).exec(current);
7598
+ if (match) {
7599
+ var after = current.slice(match.index + match[0].length);
7600
+ node.className = current.slice(0, match.index) + (after ? match[1] + after : "");
7601
+ }
7602
+ };
7603
+ var addClass = CodeMirror.addClass = function(node, cls) {
7604
+ var current = node.className;
7605
+ if (!classTest(cls).test(current)) node.className += (current ? " " : "") + cls;
7606
+ };
7607
+ function joinClasses(a, b) {
7608
+ var as = a.split(" ");
7609
+ for (var i = 0; i < as.length; i++)
7610
+ if (as[i] && !classTest(as[i]).test(b)) b += " " + as[i];
7611
+ return b;
7612
+ }
7613
+
7614
+ // WINDOW-WIDE EVENTS
7615
+
7616
+ // These must be handled carefully, because naively registering a
7617
+ // handler for each editor will cause the editors to never be
7618
+ // garbage collected.
7619
+
7620
+ function forEachCodeMirror(f) {
7621
+ if (!document.body.getElementsByClassName) return;
7622
+ var byClass = document.body.getElementsByClassName("CodeMirror");
7623
+ for (var i = 0; i < byClass.length; i++) {
7624
+ var cm = byClass[i].CodeMirror;
7625
+ if (cm) f(cm);
7626
+ }
7627
+ }
7628
+
7629
+ var globalsRegistered = false;
7630
+ function ensureGlobalHandlers() {
7631
+ if (globalsRegistered) return;
7632
+ registerGlobalHandlers();
7633
+ globalsRegistered = true;
7634
+ }
7635
+ function registerGlobalHandlers() {
7636
+ // When the window resizes, we need to refresh active editors.
7637
+ var resizeTimer;
7638
+ on(window, "resize", function() {
7639
+ if (resizeTimer == null) resizeTimer = setTimeout(function() {
7640
+ resizeTimer = null;
7641
+ forEachCodeMirror(onResize);
7642
+ }, 100);
7643
+ });
7644
+ // When the window loses focus, we want to show the editor as blurred
7645
+ on(window, "blur", function() {
7646
+ forEachCodeMirror(onBlur);
7647
+ });
7648
+ }
7649
+
7650
+ // FEATURE DETECTION
7651
+
7652
+ // Detect drag-and-drop
7653
+ var dragAndDrop = function() {
7654
+ // There is *some* kind of drag-and-drop support in IE6-8, but I
7655
+ // couldn't get it to work yet.
7656
+ if (ie && ie_version < 9) return false;
7657
+ var div = elt('div');
7658
+ return "draggable" in div || "dragDrop" in div;
7659
+ }();
7660
+
7661
+ var zwspSupported;
7662
+ function zeroWidthElement(measure) {
7663
+ if (zwspSupported == null) {
7664
+ var test = elt("span", "\u200b");
7665
+ removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]));
7666
+ if (measure.firstChild.offsetHeight != 0)
7667
+ zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !(ie && ie_version < 8);
7668
+ }
7669
+ if (zwspSupported) return elt("span", "\u200b");
7670
+ else return elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px");
7671
+ }
7672
+
7673
+ // Feature-detect IE's crummy client rect reporting for bidi text
7674
+ var badBidiRects;
7675
+ function hasBadBidiRects(measure) {
7676
+ if (badBidiRects != null) return badBidiRects;
7677
+ var txt = removeChildrenAndAdd(measure, document.createTextNode("A\u062eA"));
7678
+ var r0 = range(txt, 0, 1).getBoundingClientRect();
7679
+ if (!r0 || r0.left == r0.right) return false; // Safari returns null in some cases (#2780)
7680
+ var r1 = range(txt, 1, 2).getBoundingClientRect();
7681
+ return badBidiRects = (r1.right - r0.right < 3);
7682
+ }
7683
+
7684
+ // See if "".split is the broken IE version, if so, provide an
7685
+ // alternative way to split lines.
7686
+ var splitLines = CodeMirror.splitLines = "\n\nb".split(/\n/).length != 3 ? function(string) {
7687
+ var pos = 0, result = [], l = string.length;
7688
+ while (pos <= l) {
7689
+ var nl = string.indexOf("\n", pos);
7690
+ if (nl == -1) nl = string.length;
7691
+ var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
7692
+ var rt = line.indexOf("\r");
7693
+ if (rt != -1) {
7694
+ result.push(line.slice(0, rt));
7695
+ pos += rt + 1;
7696
+ } else {
7697
+ result.push(line);
7698
+ pos = nl + 1;
7699
+ }
7700
+ }
7701
+ return result;
7702
+ } : function(string){return string.split(/\r\n?|\n/);};
7703
+
7704
+ var hasSelection = window.getSelection ? function(te) {
7705
+ try { return te.selectionStart != te.selectionEnd; }
7706
+ catch(e) { return false; }
7707
+ } : function(te) {
7708
+ try {var range = te.ownerDocument.selection.createRange();}
7709
+ catch(e) {}
7710
+ if (!range || range.parentElement() != te) return false;
7711
+ return range.compareEndPoints("StartToEnd", range) != 0;
7712
+ };
7713
+
7714
+ var hasCopyEvent = (function() {
7715
+ var e = elt("div");
7716
+ if ("oncopy" in e) return true;
7717
+ e.setAttribute("oncopy", "return;");
7718
+ return typeof e.oncopy == "function";
7719
+ })();
7720
+
7721
+ var badZoomedRects = null;
7722
+ function hasBadZoomedRects(measure) {
7723
+ if (badZoomedRects != null) return badZoomedRects;
7724
+ var node = removeChildrenAndAdd(measure, elt("span", "x"));
7725
+ var normal = node.getBoundingClientRect();
7726
+ var fromRange = range(node, 0, 1).getBoundingClientRect();
7727
+ return badZoomedRects = Math.abs(normal.left - fromRange.left) > 1;
7728
+ }
7729
+
7730
+ // KEY NAMES
7731
+
7732
+ var keyNames = {3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
7733
+ 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
7734
+ 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
7735
+ 46: "Delete", 59: ";", 61: "=", 91: "Mod", 92: "Mod", 93: "Mod", 107: "=", 109: "-", 127: "Delete",
7736
+ 173: "-", 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
7737
+ 221: "]", 222: "'", 63232: "Up", 63233: "Down", 63234: "Left", 63235: "Right", 63272: "Delete",
7738
+ 63273: "Home", 63275: "End", 63276: "PageUp", 63277: "PageDown", 63302: "Insert"};
7739
+ CodeMirror.keyNames = keyNames;
7740
+ (function() {
7741
+ // Number keys
7742
+ for (var i = 0; i < 10; i++) keyNames[i + 48] = keyNames[i + 96] = String(i);
7743
+ // Alphabetic keys
7744
+ for (var i = 65; i <= 90; i++) keyNames[i] = String.fromCharCode(i);
7745
+ // Function keys
7746
+ for (var i = 1; i <= 12; i++) keyNames[i + 111] = keyNames[i + 63235] = "F" + i;
7747
+ })();
7748
+
7749
+ // BIDI HELPERS
7750
+
7751
+ function iterateBidiSections(order, from, to, f) {
7752
+ if (!order) return f(from, to, "ltr");
7753
+ var found = false;
7754
+ for (var i = 0; i < order.length; ++i) {
7755
+ var part = order[i];
7756
+ if (part.from < to && part.to > from || from == to && part.to == from) {
7757
+ f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr");
7758
+ found = true;
7759
+ }
7760
+ }
7761
+ if (!found) f(from, to, "ltr");
7762
+ }
7763
+
7764
+ function bidiLeft(part) { return part.level % 2 ? part.to : part.from; }
7765
+ function bidiRight(part) { return part.level % 2 ? part.from : part.to; }
7766
+
7767
+ function lineLeft(line) { var order = getOrder(line); return order ? bidiLeft(order[0]) : 0; }
7768
+ function lineRight(line) {
7769
+ var order = getOrder(line);
7770
+ if (!order) return line.text.length;
7771
+ return bidiRight(lst(order));
7772
+ }
7773
+
7774
+ function lineStart(cm, lineN) {
7775
+ var line = getLine(cm.doc, lineN);
7776
+ var visual = visualLine(line);
7777
+ if (visual != line) lineN = lineNo(visual);
7778
+ var order = getOrder(visual);
7779
+ var ch = !order ? 0 : order[0].level % 2 ? lineRight(visual) : lineLeft(visual);
7780
+ return Pos(lineN, ch);
7781
+ }
7782
+ function lineEnd(cm, lineN) {
7783
+ var merged, line = getLine(cm.doc, lineN);
7784
+ while (merged = collapsedSpanAtEnd(line)) {
7785
+ line = merged.find(1, true).line;
7786
+ lineN = null;
7787
+ }
7788
+ var order = getOrder(line);
7789
+ var ch = !order ? line.text.length : order[0].level % 2 ? lineLeft(line) : lineRight(line);
7790
+ return Pos(lineN == null ? lineNo(line) : lineN, ch);
7791
+ }
7792
+ function lineStartSmart(cm, pos) {
7793
+ var start = lineStart(cm, pos.line);
7794
+ var line = getLine(cm.doc, start.line);
7795
+ var order = getOrder(line);
7796
+ if (!order || order[0].level == 0) {
7797
+ var firstNonWS = Math.max(0, line.text.search(/\S/));
7798
+ var inWS = pos.line == start.line && pos.ch <= firstNonWS && pos.ch;
7799
+ return Pos(start.line, inWS ? 0 : firstNonWS);
7800
+ }
7801
+ return start;
7802
+ }
7803
+
7804
+ function compareBidiLevel(order, a, b) {
7805
+ var linedir = order[0].level;
7806
+ if (a == linedir) return true;
7807
+ if (b == linedir) return false;
7808
+ return a < b;
7809
+ }
7810
+ var bidiOther;
7811
+ function getBidiPartAt(order, pos) {
7812
+ bidiOther = null;
7813
+ for (var i = 0, found; i < order.length; ++i) {
7814
+ var cur = order[i];
7815
+ if (cur.from < pos && cur.to > pos) return i;
7816
+ if ((cur.from == pos || cur.to == pos)) {
7817
+ if (found == null) {
7818
+ found = i;
7819
+ } else if (compareBidiLevel(order, cur.level, order[found].level)) {
7820
+ if (cur.from != cur.to) bidiOther = found;
7821
+ return i;
7822
+ } else {
7823
+ if (cur.from != cur.to) bidiOther = i;
7824
+ return found;
7825
+ }
7826
+ }
7827
+ }
7828
+ return found;
7829
+ }
7830
+
7831
+ function moveInLine(line, pos, dir, byUnit) {
7832
+ if (!byUnit) return pos + dir;
7833
+ do pos += dir;
7834
+ while (pos > 0 && isExtendingChar(line.text.charAt(pos)));
7835
+ return pos;
7836
+ }
7837
+
7838
+ // This is needed in order to move 'visually' through bi-directional
7839
+ // text -- i.e., pressing left should make the cursor go left, even
7840
+ // when in RTL text. The tricky part is the 'jumps', where RTL and
7841
+ // LTR text touch each other. This often requires the cursor offset
7842
+ // to move more than one unit, in order to visually move one unit.
7843
+ function moveVisually(line, start, dir, byUnit) {
7844
+ var bidi = getOrder(line);
7845
+ if (!bidi) return moveLogically(line, start, dir, byUnit);
7846
+ var pos = getBidiPartAt(bidi, start), part = bidi[pos];
7847
+ var target = moveInLine(line, start, part.level % 2 ? -dir : dir, byUnit);
7848
+
7849
+ for (;;) {
7850
+ if (target > part.from && target < part.to) return target;
7851
+ if (target == part.from || target == part.to) {
7852
+ if (getBidiPartAt(bidi, target) == pos) return target;
7853
+ part = bidi[pos += dir];
7854
+ return (dir > 0) == part.level % 2 ? part.to : part.from;
7855
+ } else {
7856
+ part = bidi[pos += dir];
7857
+ if (!part) return null;
7858
+ if ((dir > 0) == part.level % 2)
7859
+ target = moveInLine(line, part.to, -1, byUnit);
7860
+ else
7861
+ target = moveInLine(line, part.from, 1, byUnit);
7862
+ }
7863
+ }
7864
+ }
7865
+
7866
+ function moveLogically(line, start, dir, byUnit) {
7867
+ var target = start + dir;
7868
+ if (byUnit) while (target > 0 && isExtendingChar(line.text.charAt(target))) target += dir;
7869
+ return target < 0 || target > line.text.length ? null : target;
7870
+ }
7871
+
7872
+ // Bidirectional ordering algorithm
7873
+ // See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
7874
+ // that this (partially) implements.
7875
+
7876
+ // One-char codes used for character types:
7877
+ // L (L): Left-to-Right
7878
+ // R (R): Right-to-Left
7879
+ // r (AL): Right-to-Left Arabic
7880
+ // 1 (EN): European Number
7881
+ // + (ES): European Number Separator
7882
+ // % (ET): European Number Terminator
7883
+ // n (AN): Arabic Number
7884
+ // , (CS): Common Number Separator
7885
+ // m (NSM): Non-Spacing Mark
7886
+ // b (BN): Boundary Neutral
7887
+ // s (B): Paragraph Separator
7888
+ // t (S): Segment Separator
7889
+ // w (WS): Whitespace
7890
+ // N (ON): Other Neutrals
7891
+
7892
+ // Returns null if characters are ordered as they appear
7893
+ // (left-to-right), or an array of sections ({from, to, level}
7894
+ // objects) in the order in which they occur visually.
7895
+ var bidiOrdering = (function() {
7896
+ // Character types for codepoints 0 to 0xff
7897
+ var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLN";
7898
+ // Character types for codepoints 0x600 to 0x6ff
7899
+ var arabicTypes = "rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmm";
7900
+ function charType(code) {
7901
+ if (code <= 0xf7) return lowTypes.charAt(code);
7902
+ else if (0x590 <= code && code <= 0x5f4) return "R";
7903
+ else if (0x600 <= code && code <= 0x6ed) return arabicTypes.charAt(code - 0x600);
7904
+ else if (0x6ee <= code && code <= 0x8ac) return "r";
7905
+ else if (0x2000 <= code && code <= 0x200b) return "w";
7906
+ else if (code == 0x200c) return "b";
7907
+ else return "L";
7908
+ }
7909
+
7910
+ var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
7911
+ var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/;
7912
+ // Browsers seem to always treat the boundaries of block elements as being L.
7913
+ var outerType = "L";
7914
+
7915
+ function BidiSpan(level, from, to) {
7916
+ this.level = level;
7917
+ this.from = from; this.to = to;
7918
+ }
7919
+
7920
+ return function(str) {
7921
+ if (!bidiRE.test(str)) return false;
7922
+ var len = str.length, types = [];
7923
+ for (var i = 0, type; i < len; ++i)
7924
+ types.push(type = charType(str.charCodeAt(i)));
7925
+
7926
+ // W1. Examine each non-spacing mark (NSM) in the level run, and
7927
+ // change the type of the NSM to the type of the previous
7928
+ // character. If the NSM is at the start of the level run, it will
7929
+ // get the type of sor.
7930
+ for (var i = 0, prev = outerType; i < len; ++i) {
7931
+ var type = types[i];
7932
+ if (type == "m") types[i] = prev;
7933
+ else prev = type;
7934
+ }
7935
+
7936
+ // W2. Search backwards from each instance of a European number
7937
+ // until the first strong type (R, L, AL, or sor) is found. If an
7938
+ // AL is found, change the type of the European number to Arabic
7939
+ // number.
7940
+ // W3. Change all ALs to R.
7941
+ for (var i = 0, cur = outerType; i < len; ++i) {
7942
+ var type = types[i];
7943
+ if (type == "1" && cur == "r") types[i] = "n";
7944
+ else if (isStrong.test(type)) { cur = type; if (type == "r") types[i] = "R"; }
7945
+ }
7946
+
7947
+ // W4. A single European separator between two European numbers
7948
+ // changes to a European number. A single common separator between
7949
+ // two numbers of the same type changes to that type.
7950
+ for (var i = 1, prev = types[0]; i < len - 1; ++i) {
7951
+ var type = types[i];
7952
+ if (type == "+" && prev == "1" && types[i+1] == "1") types[i] = "1";
7953
+ else if (type == "," && prev == types[i+1] &&
7954
+ (prev == "1" || prev == "n")) types[i] = prev;
7955
+ prev = type;
7956
+ }
7957
+
7958
+ // W5. A sequence of European terminators adjacent to European
7959
+ // numbers changes to all European numbers.
7960
+ // W6. Otherwise, separators and terminators change to Other
7961
+ // Neutral.
7962
+ for (var i = 0; i < len; ++i) {
7963
+ var type = types[i];
7964
+ if (type == ",") types[i] = "N";
7965
+ else if (type == "%") {
7966
+ for (var end = i + 1; end < len && types[end] == "%"; ++end) {}
7967
+ var replace = (i && types[i-1] == "!") || (end < len && types[end] == "1") ? "1" : "N";
7968
+ for (var j = i; j < end; ++j) types[j] = replace;
7969
+ i = end - 1;
7970
+ }
7971
+ }
7972
+
7973
+ // W7. Search backwards from each instance of a European number
7974
+ // until the first strong type (R, L, or sor) is found. If an L is
7975
+ // found, then change the type of the European number to L.
7976
+ for (var i = 0, cur = outerType; i < len; ++i) {
7977
+ var type = types[i];
7978
+ if (cur == "L" && type == "1") types[i] = "L";
7979
+ else if (isStrong.test(type)) cur = type;
7980
+ }
7981
+
7982
+ // N1. A sequence of neutrals takes the direction of the
7983
+ // surrounding strong text if the text on both sides has the same
7984
+ // direction. European and Arabic numbers act as if they were R in
7985
+ // terms of their influence on neutrals. Start-of-level-run (sor)
7986
+ // and end-of-level-run (eor) are used at level run boundaries.
7987
+ // N2. Any remaining neutrals take the embedding direction.
7988
+ for (var i = 0; i < len; ++i) {
7989
+ if (isNeutral.test(types[i])) {
7990
+ for (var end = i + 1; end < len && isNeutral.test(types[end]); ++end) {}
7991
+ var before = (i ? types[i-1] : outerType) == "L";
7992
+ var after = (end < len ? types[end] : outerType) == "L";
7993
+ var replace = before || after ? "L" : "R";
7994
+ for (var j = i; j < end; ++j) types[j] = replace;
7995
+ i = end - 1;
7996
+ }
7997
+ }
7998
+
7999
+ // Here we depart from the documented algorithm, in order to avoid
8000
+ // building up an actual levels array. Since there are only three
8001
+ // levels (0, 1, 2) in an implementation that doesn't take
8002
+ // explicit embedding into account, we can build up the order on
8003
+ // the fly, without following the level-based algorithm.
8004
+ var order = [], m;
8005
+ for (var i = 0; i < len;) {
8006
+ if (countsAsLeft.test(types[i])) {
8007
+ var start = i;
8008
+ for (++i; i < len && countsAsLeft.test(types[i]); ++i) {}
8009
+ order.push(new BidiSpan(0, start, i));
8010
+ } else {
8011
+ var pos = i, at = order.length;
8012
+ for (++i; i < len && types[i] != "L"; ++i) {}
8013
+ for (var j = pos; j < i;) {
8014
+ if (countsAsNum.test(types[j])) {
8015
+ if (pos < j) order.splice(at, 0, new BidiSpan(1, pos, j));
8016
+ var nstart = j;
8017
+ for (++j; j < i && countsAsNum.test(types[j]); ++j) {}
8018
+ order.splice(at, 0, new BidiSpan(2, nstart, j));
8019
+ pos = j;
8020
+ } else ++j;
8021
+ }
8022
+ if (pos < i) order.splice(at, 0, new BidiSpan(1, pos, i));
8023
+ }
8024
+ }
8025
+ if (order[0].level == 1 && (m = str.match(/^\s+/))) {
8026
+ order[0].from = m[0].length;
8027
+ order.unshift(new BidiSpan(0, 0, m[0].length));
8028
+ }
8029
+ if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
8030
+ lst(order).to -= m[0].length;
8031
+ order.push(new BidiSpan(0, len - m[0].length, len));
8032
+ }
8033
+ if (order[0].level != lst(order).level)
8034
+ order.push(new BidiSpan(order[0].level, len, len));
8035
+
8036
+ return order;
8037
+ };
8038
+ })();
8039
+
8040
+ // THE END
8041
+
8042
+ CodeMirror.version = "4.12.0";
8043
+
8044
+ return CodeMirror;
8045
+ });
vendor/codemirror/mode/clike/clike.js CHANGED
@@ -1,362 +1,489 @@
1
- CodeMirror.defineMode("clike", function(config, parserConfig) {
2
- var indentUnit = config.indentUnit,
3
- statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,
4
- dontAlignCalls = parserConfig.dontAlignCalls,
5
- keywords = parserConfig.keywords || {},
6
- builtin = parserConfig.builtin || {},
7
- blockKeywords = parserConfig.blockKeywords || {},
8
- atoms = parserConfig.atoms || {},
9
- hooks = parserConfig.hooks || {},
10
- multiLineStrings = parserConfig.multiLineStrings;
11
- var isOperatorChar = /[+\-*&%=<>!?|\/]/;
12
-
13
- var curPunc;
14
-
15
- function tokenBase(stream, state) {
16
- var ch = stream.next();
17
- if (hooks[ch]) {
18
- var result = hooks[ch](stream, state);
19
- if (result !== false) return result;
20
- }
21
- if (ch == '"' || ch == "'") {
22
- state.tokenize = tokenString(ch);
23
- return state.tokenize(stream, state);
24
- }
25
- if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
26
- curPunc = ch;
27
- return null;
28
- }
29
- if (/\d/.test(ch)) {
30
- stream.eatWhile(/[\w\.]/);
31
- return "number";
32
- }
33
- if (ch == "/") {
34
- if (stream.eat("*")) {
35
- state.tokenize = tokenComment;
36
- return tokenComment(stream, state);
37
- }
38
- if (stream.eat("/")) {
39
- stream.skipToEnd();
40
- return "comment";
41
- }
42
- }
43
- if (isOperatorChar.test(ch)) {
44
- stream.eatWhile(isOperatorChar);
45
- return "operator";
46
- }
47
- stream.eatWhile(/[\w\$_]/);
48
- var cur = stream.current();
49
- if (keywords.propertyIsEnumerable(cur)) {
50
- if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
51
- return "keyword";
52
- }
53
- if (builtin.propertyIsEnumerable(cur)) {
54
- if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
55
- return "builtin";
56
- }
57
- if (atoms.propertyIsEnumerable(cur)) return "atom";
58
- return "variable";
59
- }
60
-
61
- function tokenString(quote) {
62
- return function(stream, state) {
63
- var escaped = false, next, end = false;
64
- while ((next = stream.next()) != null) {
65
- if (next == quote && !escaped) {end = true; break;}
66
- escaped = !escaped && next == "\\";
67
- }
68
- if (end || !(escaped || multiLineStrings))
69
- state.tokenize = null;
70
- return "string";
71
- };
72
- }
73
-
74
- function tokenComment(stream, state) {
75
- var maybeEnd = false, ch;
76
- while (ch = stream.next()) {
77
- if (ch == "/" && maybeEnd) {
78
- state.tokenize = null;
79
- break;
80
- }
81
- maybeEnd = (ch == "*");
82
- }
83
- return "comment";
84
- }
85
-
86
- function Context(indented, column, type, align, prev) {
87
- this.indented = indented;
88
- this.column = column;
89
- this.type = type;
90
- this.align = align;
91
- this.prev = prev;
92
- }
93
- function pushContext(state, col, type) {
94
- var indent = state.indented;
95
- if (state.context && state.context.type == "statement")
96
- indent = state.context.indented;
97
- return state.context = new Context(indent, col, type, null, state.context);
98
- }
99
- function popContext(state) {
100
- var t = state.context.type;
101
- if (t == ")" || t == "]" || t == "}")
102
- state.indented = state.context.indented;
103
- return state.context = state.context.prev;
104
- }
105
-
106
- // Interface
107
-
108
- return {
109
- startState: function(basecolumn) {
110
- return {
111
- tokenize: null,
112
- context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
113
- indented: 0,
114
- startOfLine: true
115
- };
116
- },
117
-
118
- token: function(stream, state) {
119
- var ctx = state.context;
120
- if (stream.sol()) {
121
- if (ctx.align == null) ctx.align = false;
122
- state.indented = stream.indentation();
123
- state.startOfLine = true;
124
- }
125
- if (stream.eatSpace()) return null;
126
- curPunc = null;
127
- var style = (state.tokenize || tokenBase)(stream, state);
128
- if (style == "comment" || style == "meta") return style;
129
- if (ctx.align == null) ctx.align = true;
130
-
131
- if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && ctx.type == "statement") popContext(state);
132
- else if (curPunc == "{") pushContext(state, stream.column(), "}");
133
- else if (curPunc == "[") pushContext(state, stream.column(), "]");
134
- else if (curPunc == "(") pushContext(state, stream.column(), ")");
135
- else if (curPunc == "}") {
136
- while (ctx.type == "statement") ctx = popContext(state);
137
- if (ctx.type == "}") ctx = popContext(state);
138
- while (ctx.type == "statement") ctx = popContext(state);
139
- }
140
- else if (curPunc == ctx.type) popContext(state);
141
- else if (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') || (ctx.type == "statement" && curPunc == "newstatement"))
142
- pushContext(state, stream.column(), "statement");
143
- state.startOfLine = false;
144
- return style;
145
- },
146
-
147
- indent: function(state, textAfter) {
148
- if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass;
149
- var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
150
- if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
151
- var closing = firstChar == ctx.type;
152
- if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
153
- else if (ctx.align && (!dontAlignCalls || ctx.type != ")")) return ctx.column + (closing ? 0 : 1);
154
- else if (ctx.type == ")" && !closing) return ctx.indented + statementIndentUnit;
155
- else return ctx.indented + (closing ? 0 : indentUnit);
156
- },
157
-
158
- electricChars: "{}",
159
- blockCommentStart: "/*",
160
- blockCommentEnd: "*/",
161
- lineComment: "//",
162
- fold: "brace"
163
- };
164
- });
165
-
166
- (function() {
167
- function words(str) {
168
- var obj = {}, words = str.split(" ");
169
- for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
170
- return obj;
171
- }
172
- var cKeywords = "auto if break int case long char register continue return default short do sizeof " +
173
- "double static else struct entry switch extern typedef float union for unsigned " +
174
- "goto while enum void const signed volatile";
175
-
176
- function cppHook(stream, state) {
177
- if (!state.startOfLine) return false;
178
- for (;;) {
179
- if (stream.skipTo("\\")) {
180
- stream.next();
181
- if (stream.eol()) {
182
- state.tokenize = cppHook;
183
- break;
184
- }
185
- } else {
186
- stream.skipToEnd();
187
- state.tokenize = null;
188
- break;
189
- }
190
- }
191
- return "meta";
192
- }
193
-
194
- // C#-style strings where "" escapes a quote.
195
- function tokenAtString(stream, state) {
196
- var next;
197
- while ((next = stream.next()) != null) {
198
- if (next == '"' && !stream.eat('"')) {
199
- state.tokenize = null;
200
- break;
201
- }
202
- }
203
- return "string";
204
- }
205
-
206
- function mimes(ms, mode) {
207
- for (var i = 0; i < ms.length; ++i) CodeMirror.defineMIME(ms[i], mode);
208
- }
209
-
210
- mimes(["text/x-csrc", "text/x-c", "text/x-chdr"], {
211
- name: "clike",
212
- keywords: words(cKeywords),
213
- blockKeywords: words("case do else for if switch while struct"),
214
- atoms: words("null"),
215
- hooks: {"#": cppHook}
216
- });
217
- mimes(["text/x-c++src", "text/x-c++hdr"], {
218
- name: "clike",
219
- keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
220
- "static_cast typeid catch operator template typename class friend private " +
221
- "this using const_cast inline public throw virtual delete mutable protected " +
222
- "wchar_t"),
223
- blockKeywords: words("catch class do else finally for if struct switch try while"),
224
- atoms: words("true false null"),
225
- hooks: {"#": cppHook}
226
- });
227
- CodeMirror.defineMIME("text/x-java", {
228
- name: "clike",
229
- keywords: words("abstract assert boolean break byte case catch char class const continue default " +
230
- "do double else enum extends final finally float for goto if implements import " +
231
- "instanceof int interface long native new package private protected public " +
232
- "return short static strictfp super switch synchronized this throw throws transient " +
233
- "try void volatile while"),
234
- blockKeywords: words("catch class do else finally for if switch try while"),
235
- atoms: words("true false null"),
236
- hooks: {
237
- "@": function(stream) {
238
- stream.eatWhile(/[\w\$_]/);
239
- return "meta";
240
- }
241
- }
242
- });
243
- CodeMirror.defineMIME("text/x-csharp", {
244
- name: "clike",
245
- keywords: words("abstract as base break case catch checked class const continue" +
246
- " default delegate do else enum event explicit extern finally fixed for" +
247
- " foreach goto if implicit in interface internal is lock namespace new" +
248
- " operator out override params private protected public readonly ref return sealed" +
249
- " sizeof stackalloc static struct switch this throw try typeof unchecked" +
250
- " unsafe using virtual void volatile while add alias ascending descending dynamic from get" +
251
- " global group into join let orderby partial remove select set value var yield"),
252
- blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
253
- builtin: words("Boolean Byte Char DateTime DateTimeOffset Decimal Double" +
254
- " Guid Int16 Int32 Int64 Object SByte Single String TimeSpan UInt16 UInt32" +
255
- " UInt64 bool byte char decimal double short int long object" +
256
- " sbyte float string ushort uint ulong"),
257
- atoms: words("true false null"),
258
- hooks: {
259
- "@": function(stream, state) {
260
- if (stream.eat('"')) {
261
- state.tokenize = tokenAtString;
262
- return tokenAtString(stream, state);
263
- }
264
- stream.eatWhile(/[\w\$_]/);
265
- return "meta";
266
- }
267
- }
268
- });
269
- CodeMirror.defineMIME("text/x-scala", {
270
- name: "clike",
271
- keywords: words(
272
-
273
- /* scala */
274
- "abstract case catch class def do else extends false final finally for forSome if " +
275
- "implicit import lazy match new null object override package private protected return " +
276
- "sealed super this throw trait try trye type val var while with yield _ : = => <- <: " +
277
- "<% >: # @ " +
278
-
279
- /* package scala */
280
- "assert assume require print println printf readLine readBoolean readByte readShort " +
281
- "readChar readInt readLong readFloat readDouble " +
282
-
283
- "AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " +
284
- "Enumeration Equiv Error Exception Fractional Function IndexedSeq Integral Iterable " +
285
- "Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " +
286
- "Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " +
287
- "StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector :: #:: " +
288
-
289
- /* package java.lang */
290
- "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " +
291
- "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " +
292
- "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " +
293
- "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void"
294
-
295
-
296
- ),
297
- blockKeywords: words("catch class do else finally for forSome if match switch try while"),
298
- atoms: words("true false null"),
299
- hooks: {
300
- "@": function(stream) {
301
- stream.eatWhile(/[\w\$_]/);
302
- return "meta";
303
- }
304
- }
305
- });
306
- mimes(["x-shader/x-vertex", "x-shader/x-fragment"], {
307
- name: "clike",
308
- keywords: words("float int bool void " +
309
- "vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 " +
310
- "mat2 mat3 mat4 " +
311
- "sampler1D sampler2D sampler3D samplerCube " +
312
- "sampler1DShadow sampler2DShadow" +
313
- "const attribute uniform varying " +
314
- "break continue discard return " +
315
- "for while do if else struct " +
316
- "in out inout"),
317
- blockKeywords: words("for while do if else struct"),
318
- builtin: words("radians degrees sin cos tan asin acos atan " +
319
- "pow exp log exp2 sqrt inversesqrt " +
320
- "abs sign floor ceil fract mod min max clamp mix step smootstep " +
321
- "length distance dot cross normalize ftransform faceforward " +
322
- "reflect refract matrixCompMult " +
323
- "lessThan lessThanEqual greaterThan greaterThanEqual " +
324
- "equal notEqual any all not " +
325
- "texture1D texture1DProj texture1DLod texture1DProjLod " +
326
- "texture2D texture2DProj texture2DLod texture2DProjLod " +
327
- "texture3D texture3DProj texture3DLod texture3DProjLod " +
328
- "textureCube textureCubeLod " +
329
- "shadow1D shadow2D shadow1DProj shadow2DProj " +
330
- "shadow1DLod shadow2DLod shadow1DProjLod shadow2DProjLod " +
331
- "dFdx dFdy fwidth " +
332
- "noise1 noise2 noise3 noise4"),
333
- atoms: words("true false " +
334
- "gl_FragColor gl_SecondaryColor gl_Normal gl_Vertex " +
335
- "gl_MultiTexCoord0 gl_MultiTexCoord1 gl_MultiTexCoord2 gl_MultiTexCoord3 " +
336
- "gl_MultiTexCoord4 gl_MultiTexCoord5 gl_MultiTexCoord6 gl_MultiTexCoord7 " +
337
- "gl_FogCoord " +
338
- "gl_Position gl_PointSize gl_ClipVertex " +
339
- "gl_FrontColor gl_BackColor gl_FrontSecondaryColor gl_BackSecondaryColor " +
340
- "gl_TexCoord gl_FogFragCoord " +
341
- "gl_FragCoord gl_FrontFacing " +
342
- "gl_FragColor gl_FragData gl_FragDepth " +
343
- "gl_ModelViewMatrix gl_ProjectionMatrix gl_ModelViewProjectionMatrix " +
344
- "gl_TextureMatrix gl_NormalMatrix gl_ModelViewMatrixInverse " +
345
- "gl_ProjectionMatrixInverse gl_ModelViewProjectionMatrixInverse " +
346
- "gl_TexureMatrixTranspose gl_ModelViewMatrixInverseTranspose " +
347
- "gl_ProjectionMatrixInverseTranspose " +
348
- "gl_ModelViewProjectionMatrixInverseTranspose " +
349
- "gl_TextureMatrixInverseTranspose " +
350
- "gl_NormalScale gl_DepthRange gl_ClipPlane " +
351
- "gl_Point gl_FrontMaterial gl_BackMaterial gl_LightSource gl_LightModel " +
352
- "gl_FrontLightModelProduct gl_BackLightModelProduct " +
353
- "gl_TextureColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR gl_EyePlaneQ " +
354
- "gl_FogParameters " +
355
- "gl_MaxLights gl_MaxClipPlanes gl_MaxTextureUnits gl_MaxTextureCoords " +
356
- "gl_MaxVertexAttribs gl_MaxVertexUniformComponents gl_MaxVaryingFloats " +
357
- "gl_MaxVertexTextureImageUnits gl_MaxTextureImageUnits " +
358
- "gl_MaxFragmentUniformComponents gl_MaxCombineTextureImageUnits " +
359
- "gl_MaxDrawBuffers"),
360
- hooks: {"#": cppHook}
361
- });
362
- }());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
4
+ (function(mod) {
5
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
6
+ mod(require("../../lib/codemirror"));
7
+ else if (typeof define == "function" && define.amd) // AMD
8
+ define(["../../lib/codemirror"], mod);
9
+ else // Plain browser env
10
+ mod(CodeMirror);
11
+ })(function(CodeMirror) {
12
+ "use strict";
13
+
14
+ CodeMirror.defineMode("clike", function(config, parserConfig) {
15
+ var indentUnit = config.indentUnit,
16
+ statementIndentUnit = parserConfig.statementIndentUnit || indentUnit,
17
+ dontAlignCalls = parserConfig.dontAlignCalls,
18
+ keywords = parserConfig.keywords || {},
19
+ builtin = parserConfig.builtin || {},
20
+ blockKeywords = parserConfig.blockKeywords || {},
21
+ atoms = parserConfig.atoms || {},
22
+ hooks = parserConfig.hooks || {},
23
+ multiLineStrings = parserConfig.multiLineStrings,
24
+ indentStatements = parserConfig.indentStatements !== false;
25
+ var isOperatorChar = /[+\-*&%=<>!?|\/]/;
26
+
27
+ var curPunc;
28
+
29
+ function tokenBase(stream, state) {
30
+ var ch = stream.next();
31
+ if (hooks[ch]) {
32
+ var result = hooks[ch](stream, state);
33
+ if (result !== false) return result;
34
+ }
35
+ if (ch == '"' || ch == "'") {
36
+ state.tokenize = tokenString(ch);
37
+ return state.tokenize(stream, state);
38
+ }
39
+ if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
40
+ curPunc = ch;
41
+ return null;
42
+ }
43
+ if (/\d/.test(ch)) {
44
+ stream.eatWhile(/[\w\.]/);
45
+ return "number";
46
+ }
47
+ if (ch == "/") {
48
+ if (stream.eat("*")) {
49
+ state.tokenize = tokenComment;
50
+ return tokenComment(stream, state);
51
+ }
52
+ if (stream.eat("/")) {
53
+ stream.skipToEnd();
54
+ return "comment";
55
+ }
56
+ }
57
+ if (isOperatorChar.test(ch)) {
58
+ stream.eatWhile(isOperatorChar);
59
+ return "operator";
60
+ }
61
+ stream.eatWhile(/[\w\$_\xa1-\uffff]/);
62
+ var cur = stream.current();
63
+ if (keywords.propertyIsEnumerable(cur)) {
64
+ if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
65
+ return "keyword";
66
+ }
67
+ if (builtin.propertyIsEnumerable(cur)) {
68
+ if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
69
+ return "builtin";
70
+ }
71
+ if (atoms.propertyIsEnumerable(cur)) return "atom";
72
+ return "variable";
73
+ }
74
+
75
+ function tokenString(quote) {
76
+ return function(stream, state) {
77
+ var escaped = false, next, end = false;
78
+ while ((next = stream.next()) != null) {
79
+ if (next == quote && !escaped) {end = true; break;}
80
+ escaped = !escaped && next == "\\";
81
+ }
82
+ if (end || !(escaped || multiLineStrings))
83
+ state.tokenize = null;
84
+ return "string";
85
+ };
86
+ }
87
+
88
+ function tokenComment(stream, state) {
89
+ var maybeEnd = false, ch;
90
+ while (ch = stream.next()) {
91
+ if (ch == "/" && maybeEnd) {
92
+ state.tokenize = null;
93
+ break;
94
+ }
95
+ maybeEnd = (ch == "*");
96
+ }
97
+ return "comment";
98
+ }
99
+
100
+ function Context(indented, column, type, align, prev) {
101
+ this.indented = indented;
102
+ this.column = column;
103
+ this.type = type;
104
+ this.align = align;
105
+ this.prev = prev;
106
+ }
107
+ function pushContext(state, col, type) {
108
+ var indent = state.indented;
109
+ if (state.context && state.context.type == "statement")
110
+ indent = state.context.indented;
111
+ return state.context = new Context(indent, col, type, null, state.context);
112
+ }
113
+ function popContext(state) {
114
+ var t = state.context.type;
115
+ if (t == ")" || t == "]" || t == "}")
116
+ state.indented = state.context.indented;
117
+ return state.context = state.context.prev;
118
+ }
119
+
120
+ // Interface
121
+
122
+ return {
123
+ startState: function(basecolumn) {
124
+ return {
125
+ tokenize: null,
126
+ context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
127
+ indented: 0,
128
+ startOfLine: true
129
+ };
130
+ },
131
+
132
+ token: function(stream, state) {
133
+ var ctx = state.context;
134
+ if (stream.sol()) {
135
+ if (ctx.align == null) ctx.align = false;
136
+ state.indented = stream.indentation();
137
+ state.startOfLine = true;
138
+ }
139
+ if (stream.eatSpace()) return null;
140
+ curPunc = null;
141
+ var style = (state.tokenize || tokenBase)(stream, state);
142
+ if (style == "comment" || style == "meta") return style;
143
+ if (ctx.align == null) ctx.align = true;
144
+
145
+ if ((curPunc == ";" || curPunc == ":" || curPunc == ",") && ctx.type == "statement") popContext(state);
146
+ else if (curPunc == "{") pushContext(state, stream.column(), "}");
147
+ else if (curPunc == "[") pushContext(state, stream.column(), "]");
148
+ else if (curPunc == "(") pushContext(state, stream.column(), ")");
149
+ else if (curPunc == "}") {
150
+ while (ctx.type == "statement") ctx = popContext(state);
151
+ if (ctx.type == "}") ctx = popContext(state);
152
+ while (ctx.type == "statement") ctx = popContext(state);
153
+ }
154
+ else if (curPunc == ctx.type) popContext(state);
155
+ else if (indentStatements &&
156
+ (((ctx.type == "}" || ctx.type == "top") && curPunc != ';') ||
157
+ (ctx.type == "statement" && curPunc == "newstatement")))
158
+ pushContext(state, stream.column(), "statement");
159
+ state.startOfLine = false;
160
+ return style;
161
+ },
162
+
163
+ indent: function(state, textAfter) {
164
+ if (state.tokenize != tokenBase && state.tokenize != null) return CodeMirror.Pass;
165
+ var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
166
+ if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
167
+ var closing = firstChar == ctx.type;
168
+ if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : statementIndentUnit);
169
+ else if (ctx.align && (!dontAlignCalls || ctx.type != ")")) return ctx.column + (closing ? 0 : 1);
170
+ else if (ctx.type == ")" && !closing) return ctx.indented + statementIndentUnit;
171
+ else return ctx.indented + (closing ? 0 : indentUnit);
172
+ },
173
+
174
+ electricChars: "{}",
175
+ blockCommentStart: "/*",
176
+ blockCommentEnd: "*/",
177
+ lineComment: "//",
178
+ fold: "brace"
179
+ };
180
+ });
181
+
182
+ function words(str) {
183
+ var obj = {}, words = str.split(" ");
184
+ for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
185
+ return obj;
186
+ }
187
+ var cKeywords = "auto if break int case long char register continue return default short do sizeof " +
188
+ "double static else struct entry switch extern typedef float union for unsigned " +
189
+ "goto while enum void const signed volatile";
190
+
191
+ function cppHook(stream, state) {
192
+ if (!state.startOfLine) return false;
193
+ for (;;) {
194
+ if (stream.skipTo("\\")) {
195
+ stream.next();
196
+ if (stream.eol()) {
197
+ state.tokenize = cppHook;
198
+ break;
199
+ }
200
+ } else {
201
+ stream.skipToEnd();
202
+ state.tokenize = null;
203
+ break;
204
+ }
205
+ }
206
+ return "meta";
207
+ }
208
+
209
+ function cpp11StringHook(stream, state) {
210
+ stream.backUp(1);
211
+ // Raw strings.
212
+ if (stream.match(/(R|u8R|uR|UR|LR)/)) {
213
+ var match = stream.match(/"([^\s\\()]{0,16})\(/);
214
+ if (!match) {
215
+ return false;
216
+ }
217
+ state.cpp11RawStringDelim = match[1];
218
+ state.tokenize = tokenRawString;
219
+ return tokenRawString(stream, state);
220
+ }
221
+ // Unicode strings/chars.
222
+ if (stream.match(/(u8|u|U|L)/)) {
223
+ if (stream.match(/["']/, /* eat */ false)) {
224
+ return "string";
225
+ }
226
+ return false;
227
+ }
228
+ // Ignore this hook.
229
+ stream.next();
230
+ return false;
231
+ }
232
+
233
+ // C#-style strings where "" escapes a quote.
234
+ function tokenAtString(stream, state) {
235
+ var next;
236
+ while ((next = stream.next()) != null) {
237
+ if (next == '"' && !stream.eat('"')) {
238
+ state.tokenize = null;
239
+ break;
240
+ }
241
+ }
242
+ return "string";
243
+ }
244
+
245
+ // C++11 raw string literal is <prefix>"<delim>( anything )<delim>", where
246
+ // <delim> can be a string up to 16 characters long.
247
+ function tokenRawString(stream, state) {
248
+ // Escape characters that have special regex meanings.
249
+ var delim = state.cpp11RawStringDelim.replace(/[^\w\s]/g, '\\$&');
250
+ var match = stream.match(new RegExp(".*?\\)" + delim + '"'));
251
+ if (match)
252
+ state.tokenize = null;
253
+ else
254
+ stream.skipToEnd();
255
+ return "string";
256
+ }
257
+
258
+ function def(mimes, mode) {
259
+ if (typeof mimes == "string") mimes = [mimes];
260
+ var words = [];
261
+ function add(obj) {
262
+ if (obj) for (var prop in obj) if (obj.hasOwnProperty(prop))
263
+ words.push(prop);
264
+ }
265
+ add(mode.keywords);
266
+ add(mode.builtin);
267
+ add(mode.atoms);
268
+ if (words.length) {
269
+ mode.helperType = mimes[0];
270
+ CodeMirror.registerHelper("hintWords", mimes[0], words);
271
+ }
272
+
273
+ for (var i = 0; i < mimes.length; ++i)
274
+ CodeMirror.defineMIME(mimes[i], mode);
275
+ }
276
+
277
+ def(["text/x-csrc", "text/x-c", "text/x-chdr"], {
278
+ name: "clike",
279
+ keywords: words(cKeywords),
280
+ blockKeywords: words("case do else for if switch while struct"),
281
+ atoms: words("null"),
282
+ hooks: {"#": cppHook},
283
+ modeProps: {fold: ["brace", "include"]}
284
+ });
285
+
286
+ def(["text/x-c++src", "text/x-c++hdr"], {
287
+ name: "clike",
288
+ keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
289
+ "static_cast typeid catch operator template typename class friend private " +
290
+ "this using const_cast inline public throw virtual delete mutable protected " +
291
+ "wchar_t alignas alignof constexpr decltype nullptr noexcept thread_local final " +
292
+ "static_assert override"),
293
+ blockKeywords: words("catch class do else finally for if struct switch try while"),
294
+ atoms: words("true false null"),
295
+ hooks: {
296
+ "#": cppHook,
297
+ "u": cpp11StringHook,
298
+ "U": cpp11StringHook,
299
+ "L": cpp11StringHook,
300
+ "R": cpp11StringHook
301
+ },
302
+ modeProps: {fold: ["brace", "include"]}
303
+ });
304
+
305
+ def("text/x-java", {
306
+ name: "clike",
307
+ keywords: words("abstract assert boolean break byte case catch char class const continue default " +
308
+ "do double else enum extends final finally float for goto if implements import " +
309
+ "instanceof int interface long native new package private protected public " +
310
+ "return short static strictfp super switch synchronized this throw throws transient " +
311
+ "try void volatile while"),
312
+ blockKeywords: words("catch class do else finally for if switch try while"),
313
+ atoms: words("true false null"),
314
+ hooks: {
315
+ "@": function(stream) {
316
+ stream.eatWhile(/[\w\$_]/);
317
+ return "meta";
318
+ }
319
+ },
320
+ modeProps: {fold: ["brace", "import"]}
321
+ });
322
+
323
+ def("text/x-csharp", {
324
+ name: "clike",
325
+ keywords: words("abstract as base break case catch checked class const continue" +
326
+ " default delegate do else enum event explicit extern finally fixed for" +
327
+ " foreach goto if implicit in interface internal is lock namespace new" +
328
+ " operator out override params private protected public readonly ref return sealed" +
329
+ " sizeof stackalloc static struct switch this throw try typeof unchecked" +
330
+ " unsafe using virtual void volatile while add alias ascending descending dynamic from get" +
331
+ " global group into join let orderby partial remove select set value var yield"),
332
+ blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
333
+ builtin: words("Boolean Byte Char DateTime DateTimeOffset Decimal Double" +
334
+ " Guid Int16 Int32 Int64 Object SByte Single String TimeSpan UInt16 UInt32" +
335
+ " UInt64 bool byte char decimal double short int long object" +
336
+ " sbyte float string ushort uint ulong"),
337
+ atoms: words("true false null"),
338
+ hooks: {
339
+ "@": function(stream, state) {
340
+ if (stream.eat('"')) {
341
+ state.tokenize = tokenAtString;
342
+ return tokenAtString(stream, state);
343
+ }
344
+ stream.eatWhile(/[\w\$_]/);
345
+ return "meta";
346
+ }
347
+ }
348
+ });
349
+
350
+ function tokenTripleString(stream, state) {
351
+ var escaped = false;
352
+ while (!stream.eol()) {
353
+ if (!escaped && stream.match('"""')) {
354
+ state.tokenize = null;
355
+ break;
356
+ }
357
+ escaped = stream.next() != "\\" && !escaped;
358
+ }
359
+ return "string";
360
+ }
361
+
362
+ def("text/x-scala", {
363
+ name: "clike",
364
+ keywords: words(
365
+
366
+ /* scala */
367
+ "abstract case catch class def do else extends false final finally for forSome if " +
368
+ "implicit import lazy match new null object override package private protected return " +
369
+ "sealed super this throw trait try trye type val var while with yield _ : = => <- <: " +
370
+ "<% >: # @ " +
371
+
372
+ /* package scala */
373
+ "assert assume require print println printf readLine readBoolean readByte readShort " +
374
+ "readChar readInt readLong readFloat readDouble " +
375
+
376
+ "AnyVal App Application Array BufferedIterator BigDecimal BigInt Char Console Either " +
377
+ "Enumeration Equiv Error Exception Fractional Function IndexedSeq Integral Iterable " +
378
+ "Iterator List Map Numeric Nil NotNull Option Ordered Ordering PartialFunction PartialOrdering " +
379
+ "Product Proxy Range Responder Seq Serializable Set Specializable Stream StringBuilder " +
380
+ "StringContext Symbol Throwable Traversable TraversableOnce Tuple Unit Vector :: #:: " +
381
+
382
+ /* package java.lang */
383
+ "Boolean Byte Character CharSequence Class ClassLoader Cloneable Comparable " +
384
+ "Compiler Double Exception Float Integer Long Math Number Object Package Pair Process " +
385
+ "Runtime Runnable SecurityManager Short StackTraceElement StrictMath String " +
386
+ "StringBuffer System Thread ThreadGroup ThreadLocal Throwable Triple Void"
387
+ ),
388
+ multiLineStrings: true,
389
+ blockKeywords: words("catch class do else finally for forSome if match switch try while"),
390
+ atoms: words("true false null"),
391
+ indentStatements: false,
392
+ hooks: {
393
+ "@": function(stream) {
394
+ stream.eatWhile(/[\w\$_]/);
395
+ return "meta";
396
+ },
397
+ '"': function(stream, state) {
398
+ if (!stream.match('""')) return false;
399
+ state.tokenize = tokenTripleString;
400
+ return state.tokenize(stream, state);
401
+ }
402
+ }
403
+ });
404
+
405
+ def(["x-shader/x-vertex", "x-shader/x-fragment"], {
406
+ name: "clike",
407
+ keywords: words("float int bool void " +
408
+ "vec2 vec3 vec4 ivec2 ivec3 ivec4 bvec2 bvec3 bvec4 " +
409
+ "mat2 mat3 mat4 " +
410
+ "sampler1D sampler2D sampler3D samplerCube " +
411
+ "sampler1DShadow sampler2DShadow " +
412
+ "const attribute uniform varying " +
413
+ "break continue discard return " +
414
+ "for while do if else struct " +
415
+ "in out inout"),
416
+ blockKeywords: words("for while do if else struct"),
417
+ builtin: words("radians degrees sin cos tan asin acos atan " +
418
+ "pow exp log exp2 sqrt inversesqrt " +
419
+ "abs sign floor ceil fract mod min max clamp mix step smoothstep " +
420
+ "length distance dot cross normalize ftransform faceforward " +
421
+ "reflect refract matrixCompMult " +
422
+ "lessThan lessThanEqual greaterThan greaterThanEqual " +
423
+ "equal notEqual any all not " +
424
+ "texture1D texture1DProj texture1DLod texture1DProjLod " +
425
+ "texture2D texture2DProj texture2DLod texture2DProjLod " +
426
+ "texture3D texture3DProj texture3DLod texture3DProjLod " +
427
+ "textureCube textureCubeLod " +
428
+ "shadow1D shadow2D shadow1DProj shadow2DProj " +
429
+ "shadow1DLod shadow2DLod shadow1DProjLod shadow2DProjLod " +
430
+ "dFdx dFdy fwidth " +
431
+ "noise1 noise2 noise3 noise4"),
432
+ atoms: words("true false " +
433
+ "gl_FragColor gl_SecondaryColor gl_Normal gl_Vertex " +
434
+ "gl_MultiTexCoord0 gl_MultiTexCoord1 gl_MultiTexCoord2 gl_MultiTexCoord3 " +
435
+ "gl_MultiTexCoord4 gl_MultiTexCoord5 gl_MultiTexCoord6 gl_MultiTexCoord7 " +
436
+ "gl_FogCoord gl_PointCoord " +
437
+ "gl_Position gl_PointSize gl_ClipVertex " +
438
+ "gl_FrontColor gl_BackColor gl_FrontSecondaryColor gl_BackSecondaryColor " +
439
+ "gl_TexCoord gl_FogFragCoord " +
440
+ "gl_FragCoord gl_FrontFacing " +
441
+ "gl_FragData gl_FragDepth " +
442
+ "gl_ModelViewMatrix gl_ProjectionMatrix gl_ModelViewProjectionMatrix " +
443
+ "gl_TextureMatrix gl_NormalMatrix gl_ModelViewMatrixInverse " +
444
+ "gl_ProjectionMatrixInverse gl_ModelViewProjectionMatrixInverse " +
445
+ "gl_TexureMatrixTranspose gl_ModelViewMatrixInverseTranspose " +
446
+ "gl_ProjectionMatrixInverseTranspose " +
447
+ "gl_ModelViewProjectionMatrixInverseTranspose " +
448
+ "gl_TextureMatrixInverseTranspose " +
449
+ "gl_NormalScale gl_DepthRange gl_ClipPlane " +
450
+ "gl_Point gl_FrontMaterial gl_BackMaterial gl_LightSource gl_LightModel " +
451
+ "gl_FrontLightModelProduct gl_BackLightModelProduct " +
452
+ "gl_TextureColor gl_EyePlaneS gl_EyePlaneT gl_EyePlaneR gl_EyePlaneQ " +
453
+ "gl_FogParameters " +
454
+ "gl_MaxLights gl_MaxClipPlanes gl_MaxTextureUnits gl_MaxTextureCoords " +
455
+ "gl_MaxVertexAttribs gl_MaxVertexUniformComponents gl_MaxVaryingFloats " +
456
+ "gl_MaxVertexTextureImageUnits gl_MaxTextureImageUnits " +
457
+ "gl_MaxFragmentUniformComponents gl_MaxCombineTextureImageUnits " +
458
+ "gl_MaxDrawBuffers"),
459
+ hooks: {"#": cppHook},
460
+ modeProps: {fold: ["brace", "include"]}
461
+ });
462
+
463
+ def("text/x-nesc", {
464
+ name: "clike",
465
+ keywords: words(cKeywords + "as atomic async call command component components configuration event generic " +
466
+ "implementation includes interface module new norace nx_struct nx_union post provides " +
467
+ "signal task uses abstract extends"),
468
+ blockKeywords: words("case do else for if switch while struct"),
469
+ atoms: words("null"),
470
+ hooks: {"#": cppHook},
471
+ modeProps: {fold: ["brace", "include"]}
472
+ });
473
+
474
+ def("text/x-objectivec", {
475
+ name: "clike",
476
+ keywords: words(cKeywords + "inline restrict _Bool _Complex _Imaginery BOOL Class bycopy byref id IMP in " +
477
+ "inout nil oneway out Protocol SEL self super atomic nonatomic retain copy readwrite readonly"),
478
+ atoms: words("YES NO NULL NILL ON OFF"),
479
+ hooks: {
480
+ "@": function(stream) {
481
+ stream.eatWhile(/[\w\$]/);
482
+ return "keyword";
483
+ },
484
+ "#": cppHook
485
+ },
486
+ modeProps: {fold: "brace"}
487
+ });
488
+
489
+ });
vendor/codemirror/mode/php/php.js CHANGED
@@ -1,132 +1,226 @@
1
- (function() {
2
- function keywords(str) {
3
- var obj = {}, words = str.split(" ");
4
- for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
5
- return obj;
6
- }
7
- function heredoc(delim) {
8
- return function(stream, state) {
9
- if (stream.match(delim)) state.tokenize = null;
10
- else stream.skipToEnd();
11
- return "string";
12
- };
13
- }
14
- var phpConfig = {
15
- name: "clike",
16
- keywords: keywords("abstract and array as break case catch class clone const continue declare default " +
17
- "do else elseif enddeclare endfor endforeach endif endswitch endwhile extends final " +
18
- "for foreach function global goto if implements interface instanceof namespace " +
19
- "new or private protected public static switch throw trait try use var while xor " +
20
- "die echo empty exit eval include include_once isset list require require_once return " +
21
- "print unset __halt_compiler self static parent yield insteadof finally"),
22
- blockKeywords: keywords("catch do else elseif for foreach if switch try while finally"),
23
- atoms: keywords("true false null TRUE FALSE NULL __CLASS__ __DIR__ __FILE__ __LINE__ __METHOD__ __FUNCTION__ __NAMESPACE__ __TRAIT__"),
24
- builtin: keywords("func_num_args func_get_arg func_get_args strlen strcmp strncmp strcasecmp strncasecmp each error_reporting define defined trigger_error user_error set_error_handler restore_error_handler get_declared_classes get_loaded_extensions extension_loaded get_extension_funcs debug_backtrace constant bin2hex hex2bin sleep usleep time mktime gmmktime strftime gmstrftime strtotime date gmdate getdate localtime checkdate flush wordwrap htmlspecialchars htmlentities html_entity_decode md5 md5_file crc32 getimagesize image_type_to_mime_type phpinfo phpversion phpcredits strnatcmp strnatcasecmp substr_count strspn strcspn strtok strtoupper strtolower strpos strrpos strrev hebrev hebrevc nl2br basename dirname pathinfo stripslashes stripcslashes strstr stristr strrchr str_shuffle str_word_count strcoll substr substr_replace quotemeta ucfirst ucwords strtr addslashes addcslashes rtrim str_replace str_repeat count_chars chunk_split trim ltrim strip_tags similar_text explode implode setlocale localeconv parse_str str_pad chop strchr sprintf printf vprintf vsprintf sscanf fscanf parse_url urlencode urldecode rawurlencode rawurldecode readlink linkinfo link unlink exec system escapeshellcmd escapeshellarg passthru shell_exec proc_open proc_close rand srand getrandmax mt_rand mt_srand mt_getrandmax base64_decode base64_encode abs ceil floor round is_finite is_nan is_infinite bindec hexdec octdec decbin decoct dechex base_convert number_format fmod ip2long long2ip getenv putenv getopt microtime gettimeofday getrusage uniqid quoted_printable_decode set_time_limit get_cfg_var magic_quotes_runtime set_magic_quotes_runtime get_magic_quotes_gpc get_magic_quotes_runtime import_request_variables error_log serialize unserialize memory_get_usage var_dump var_export debug_zval_dump print_r highlight_file show_source highlight_string ini_get ini_get_all ini_set ini_alter ini_restore get_include_path set_include_path restore_include_path setcookie header headers_sent connection_aborted connection_status ignore_user_abort parse_ini_file is_uploaded_file move_uploaded_file intval floatval doubleval strval gettype settype is_null is_resource is_bool is_long is_float is_int is_integer is_double is_real is_numeric is_string is_array is_object is_scalar ereg ereg_replace eregi eregi_replace split spliti join sql_regcase dl pclose popen readfile rewind rmdir umask fclose feof fgetc fgets fgetss fread fopen fpassthru ftruncate fstat fseek ftell fflush fwrite fputs mkdir rename copy tempnam tmpfile file file_get_contents stream_select stream_context_create stream_context_set_params stream_context_set_option stream_context_get_options stream_filter_prepend stream_filter_append fgetcsv flock get_meta_tags stream_set_write_buffer set_file_buffer set_socket_blocking stream_set_blocking socket_set_blocking stream_get_meta_data stream_register_wrapper stream_wrapper_register stream_set_timeout socket_set_timeout socket_get_status realpath fnmatch fsockopen pfsockopen pack unpack get_browser crypt opendir closedir chdir getcwd rewinddir readdir dir glob fileatime filectime filegroup fileinode filemtime fileowner fileperms filesize filetype file_exists is_writable is_writeable is_readable is_executable is_file is_dir is_link stat lstat chown touch clearstatcache mail ob_start ob_flush ob_clean ob_end_flush ob_end_clean ob_get_flush ob_get_clean ob_get_length ob_get_level ob_get_status ob_get_contents ob_implicit_flush ob_list_handlers ksort krsort natsort natcasesort asort arsort sort rsort usort uasort uksort shuffle array_walk count end prev next reset current key min max in_array array_search extract compact array_fill range array_multisort array_push array_pop array_shift array_unshift array_splice array_slice array_merge array_merge_recursive array_keys array_values array_count_values array_reverse array_reduce array_pad array_flip array_change_key_case array_rand array_unique array_intersect array_intersect_assoc array_diff array_diff_assoc array_sum array_filter array_map array_chunk array_key_exists pos sizeof key_exists assert assert_options version_compare ftok str_rot13 aggregate session_name session_module_name session_save_path session_id session_regenerate_id session_decode session_register session_unregister session_is_registered session_encode session_start session_destroy session_unset session_set_save_handler session_cache_limiter session_cache_expire session_set_cookie_params session_get_cookie_params session_write_close preg_match preg_match_all preg_replace preg_replace_callback preg_split preg_quote preg_grep overload ctype_alnum ctype_alpha ctype_cntrl ctype_digit ctype_lower ctype_graph ctype_print ctype_punct ctype_space ctype_upper ctype_xdigit virtual apache_request_headers apache_note apache_lookup_uri apache_child_terminate apache_setenv apache_response_headers apache_get_version getallheaders mysql_connect mysql_pconnect mysql_close mysql_select_db mysql_create_db mysql_drop_db mysql_query mysql_unbuffered_query mysql_db_query mysql_list_dbs mysql_list_tables mysql_list_fields mysql_list_processes mysql_error mysql_errno mysql_affected_rows mysql_insert_id mysql_result mysql_num_rows mysql_num_fields mysql_fetch_row mysql_fetch_array mysql_fetch_assoc mysql_fetch_object mysql_data_seek mysql_fetch_lengths mysql_fetch_field mysql_field_seek mysql_free_result mysql_field_name mysql_field_table mysql_field_len mysql_field_type mysql_field_flags mysql_escape_string mysql_real_escape_string mysql_stat mysql_thread_id mysql_client_encoding mysql_get_client_info mysql_get_host_info mysql_get_proto_info mysql_get_server_info mysql_info mysql mysql_fieldname mysql_fieldtable mysql_fieldlen mysql_fieldtype mysql_fieldflags mysql_selectdb mysql_createdb mysql_dropdb mysql_freeresult mysql_numfields mysql_numrows mysql_listdbs mysql_listtables mysql_listfields mysql_db_name mysql_dbname mysql_tablename mysql_table_name pg_connect pg_pconnect pg_close pg_connection_status pg_connection_busy pg_connection_reset pg_host pg_dbname pg_port pg_tty pg_options pg_ping pg_query pg_send_query pg_cancel_query pg_fetch_result pg_fetch_row pg_fetch_assoc pg_fetch_array pg_fetch_object pg_fetch_all pg_affected_rows pg_get_result pg_result_seek pg_result_status pg_free_result pg_last_oid pg_num_rows pg_num_fields pg_field_name pg_field_num pg_field_size pg_field_type pg_field_prtlen pg_field_is_null pg_get_notify pg_get_pid pg_result_error pg_last_error pg_last_notice pg_put_line pg_end_copy pg_copy_to pg_copy_from pg_trace pg_untrace pg_lo_create pg_lo_unlink pg_lo_open pg_lo_close pg_lo_read pg_lo_write pg_lo_read_all pg_lo_import pg_lo_export pg_lo_seek pg_lo_tell pg_escape_string pg_escape_bytea pg_unescape_bytea pg_client_encoding pg_set_client_encoding pg_meta_data pg_convert pg_insert pg_update pg_delete pg_select pg_exec pg_getlastoid pg_cmdtuples pg_errormessage pg_numrows pg_numfields pg_fieldname pg_fieldsize pg_fieldtype pg_fieldnum pg_fieldprtlen pg_fieldisnull pg_freeresult pg_result pg_loreadall pg_locreate pg_lounlink pg_loopen pg_loclose pg_loread pg_lowrite pg_loimport pg_loexport http_response_code get_declared_traits getimagesizefromstring socket_import_stream stream_set_chunk_size trait_exists header_register_callback class_uses session_status session_register_shutdown echo print global static exit array empty eval isset unset die include require include_once require_once"),
25
- multiLineStrings: true,
26
- hooks: {
27
- "$": function(stream) {
28
- stream.eatWhile(/[\w\$_]/);
29
- return "variable-2";
30
- },
31
- "<": function(stream, state) {
32
- if (stream.match(/<</)) {
33
- stream.eatWhile(/[\w\.]/);
34
- state.tokenize = heredoc(stream.current().slice(3));
35
- return state.tokenize(stream, state);
36
- }
37
- return false;
38
- },
39
- "#": function(stream) {
40
- while (!stream.eol() && !stream.match("?>", false)) stream.next();
41
- return "comment";
42
- },
43
- "/": function(stream) {
44
- if (stream.eat("/")) {
45
- while (!stream.eol() && !stream.match("?>", false)) stream.next();
46
- return "comment";
47
- }
48
- return false;
49
- }
50
- }
51
- };
52
-
53
- CodeMirror.defineMode("php", function(config, parserConfig) {
54
- var htmlMode = CodeMirror.getMode(config, "text/html");
55
- var phpMode = CodeMirror.getMode(config, phpConfig);
56
-
57
- function dispatch(stream, state) {
58
- var isPHP = state.curMode == phpMode;
59
- if (stream.sol() && state.pending != '"') state.pending = null;
60
- if (!isPHP) {
61
- if (stream.match(/^<\?\w*/)) {
62
- state.curMode = phpMode;
63
- state.curState = state.php;
64
- return "meta";
65
- }
66
- if (state.pending == '"') {
67
- while (!stream.eol() && stream.next() != '"') {}
68
- var style = "string";
69
- } else if (state.pending && stream.pos < state.pending.end) {
70
- stream.pos = state.pending.end;
71
- var style = state.pending.style;
72
- } else {
73
- var style = htmlMode.token(stream, state.curState);
74
- }
75
- state.pending = null;
76
- var cur = stream.current(), openPHP = cur.search(/<\?/);
77
- if (openPHP != -1) {
78
- if (style == "string" && /\"$/.test(cur) && !/\?>/.test(cur)) state.pending = '"';
79
- else state.pending = {end: stream.pos, style: style};
80
- stream.backUp(cur.length - openPHP);
81
- }
82
- return style;
83
- } else if (isPHP && state.php.tokenize == null && stream.match("?>")) {
84
- state.curMode = htmlMode;
85
- state.curState = state.html;
86
- return "meta";
87
- } else {
88
- return phpMode.token(stream, state.curState);
89
- }
90
- }
91
-
92
- return {
93
- startState: function() {
94
- var html = CodeMirror.startState(htmlMode), php = CodeMirror.startState(phpMode);
95
- return {html: html,
96
- php: php,
97
- curMode: parserConfig.startOpen ? phpMode : htmlMode,
98
- curState: parserConfig.startOpen ? php : html,
99
- pending: null};
100
- },
101
-
102
- copyState: function(state) {
103
- var html = state.html, htmlNew = CodeMirror.copyState(htmlMode, html),
104
- php = state.php, phpNew = CodeMirror.copyState(phpMode, php), cur;
105
- if (state.curMode == htmlMode) cur = htmlNew;
106
- else cur = phpNew;
107
- return {html: htmlNew, php: phpNew, curMode: state.curMode, curState: cur,
108
- pending: state.pending};
109
- },
110
-
111
- token: dispatch,
112
-
113
- indent: function(state, textAfter) {
114
- if ((state.curMode != phpMode && /^\s*<\//.test(textAfter)) ||
115
- (state.curMode == phpMode && /^\?>/.test(textAfter)))
116
- return htmlMode.indent(state.html, textAfter);
117
- return state.curMode.indent(state.curState, textAfter);
118
- },
119
-
120
- electricChars: "/{}:",
121
- blockCommentStart: "/*",
122
- blockCommentEnd: "*/",
123
- lineComment: "//",
124
-
125
- innerMode: function(state) { return {state: state.curState, mode: state.curMode}; }
126
- };
127
- }, "htmlmixed", "clike");
128
-
129
- CodeMirror.defineMIME("application/x-httpd-php", "php");
130
- CodeMirror.defineMIME("application/x-httpd-php-open", {name: "php", startOpen: true});
131
- CodeMirror.defineMIME("text/x-php", phpConfig);
132
- })();
1
+ // CodeMirror, copyright (c) by Marijn Haverbeke and others
2
+ // Distributed under an MIT license: http://codemirror.net/LICENSE
3
+
4
+ (function(mod) {
5
+ if (typeof exports == "object" && typeof module == "object") // CommonJS
6
+ mod(require("../../lib/codemirror"), require("../htmlmixed/htmlmixed"), require("../clike/clike"));
7
+ else if (typeof define == "function" && define.amd) // AMD
8
+ define(["../../lib/codemirror", "../htmlmixed/htmlmixed", "../clike/clike"], mod);
9
+ else // Plain browser env
10
+ mod(CodeMirror);
11
+ })(function(CodeMirror) {
12
+ "use strict";
13
+
14
+ function keywords(str) {
15
+ var obj = {}, words = str.split(" ");
16
+ for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
17
+ return obj;
18
+ }
19
+
20
+ // Helper for stringWithEscapes
21
+ function matchSequence(list, end) {
22
+ if (list.length == 0) return stringWithEscapes(end);
23
+ return function (stream, state) {
24
+ var patterns = list[0];
25
+ for (var i = 0; i < patterns.length; i++) if (stream.match(patterns[i][0])) {
26
+ state.tokenize = matchSequence(list.slice(1), end);
27
+ return patterns[i][1];
28
+ }
29
+ state.tokenize = stringWithEscapes(end);
30
+ return "string";
31
+ };
32
+ }
33
+ function stringWithEscapes(closing) {
34
+ return function(stream, state) { return stringWithEscapes_(stream, state, closing); };
35
+ }
36
+ function stringWithEscapes_(stream, state, closing) {
37
+ // "Complex" syntax
38
+ if (stream.match("${", false) || stream.match("{$", false)) {
39
+ state.tokenize = null;
40
+ return "string";
41
+ }
42
+
43
+ // Simple syntax
44
+ if (stream.match(/^\$[a-zA-Z_][a-zA-Z0-9_]*/)) {
45
+ // After the variable name there may appear array or object operator.
46
+ if (stream.match("[", false)) {
47
+ // Match array operator
48
+ state.tokenize = matchSequence([
49
+ [["[", null]],
50
+ [[/\d[\w\.]*/, "number"],
51
+ [/\$[a-zA-Z_][a-zA-Z0-9_]*/, "variable-2"],
52
+ [/[\w\$]+/, "variable"]],
53
+ [["]", null]]
54
+ ], closing);
55
+ }
56
+ if (stream.match(/\-\>\w/, false)) {
57
+ // Match object operator
58
+ state.tokenize = matchSequence([
59
+ [["->", null]],
60
+ [[/[\w]+/, "variable"]]
61
+ ], closing);
62
+ }
63
+ return "variable-2";
64
+ }
65
+
66
+ var escaped = false;
67
+ // Normal string
68
+ while (!stream.eol() &&
69
+ (escaped || (!stream.match("{$", false) &&
70
+ !stream.match(/^(\$[a-zA-Z_][a-zA-Z0-9_]*|\$\{)/, false)))) {
71
+ if (!escaped && stream.match(closing)) {
72
+ state.tokenize = null;
73
+ state.tokStack.pop(); state.tokStack.pop();
74
+ break;
75
+ }
76
+ escaped = stream.next() == "\\" && !escaped;
77
+ }
78
+ return "string";
79
+ }
80
+
81
+ var phpKeywords = "abstract and array as break case catch class clone const continue declare default " +
82
+ "do else elseif enddeclare endfor endforeach endif endswitch endwhile extends final " +
83
+ "for foreach function global goto if implements interface instanceof namespace " +
84
+ "new or private protected public static switch throw trait try use var while xor " +
85
+ "die echo empty exit eval include include_once isset list require require_once return " +
86
+ "print unset __halt_compiler self static parent yield insteadof finally";
87
+ var phpAtoms = "true false null TRUE FALSE NULL __CLASS__ __DIR__ __FILE__ __LINE__ __METHOD__ __FUNCTION__ __NAMESPACE__ __TRAIT__";
88
+ var phpBuiltin = "func_num_args func_get_arg func_get_args strlen strcmp strncmp strcasecmp strncasecmp each error_reporting define defined trigger_error user_error set_error_handler restore_error_handler get_declared_classes get_loaded_extensions extension_loaded get_extension_funcs debug_backtrace constant bin2hex hex2bin sleep usleep time mktime gmmktime strftime gmstrftime strtotime date gmdate getdate localtime checkdate flush wordwrap htmlspecialchars htmlentities html_entity_decode md5 md5_file crc32 getimagesize image_type_to_mime_type phpinfo phpversion phpcredits strnatcmp strnatcasecmp substr_count strspn strcspn strtok strtoupper strtolower strpos strrpos strrev hebrev hebrevc nl2br basename dirname pathinfo stripslashes stripcslashes strstr stristr strrchr str_shuffle str_word_count strcoll substr substr_replace quotemeta ucfirst ucwords strtr addslashes addcslashes rtrim str_replace str_repeat count_chars chunk_split trim ltrim strip_tags similar_text explode implode setlocale localeconv parse_str str_pad chop strchr sprintf printf vprintf vsprintf sscanf fscanf parse_url urlencode urldecode rawurlencode rawurldecode readlink linkinfo link unlink exec system escapeshellcmd escapeshellarg passthru shell_exec proc_open proc_close rand srand getrandmax mt_rand mt_srand mt_getrandmax base64_decode base64_encode abs ceil floor round is_finite is_nan is_infinite bindec hexdec octdec decbin decoct dechex base_convert number_format fmod ip2long long2ip getenv putenv getopt microtime gettimeofday getrusage uniqid quoted_printable_decode set_time_limit get_cfg_var magic_quotes_runtime set_magic_quotes_runtime get_magic_quotes_gpc get_magic_quotes_runtime import_request_variables error_log serialize unserialize memory_get_usage var_dump var_export debug_zval_dump print_r highlight_file show_source highlight_string ini_get ini_get_all ini_set ini_alter ini_restore get_include_path set_include_path restore_include_path setcookie header headers_sent connection_aborted connection_status ignore_user_abort parse_ini_file is_uploaded_file move_uploaded_file intval floatval doubleval strval gettype settype is_null is_resource is_bool is_long is_float is_int is_integer is_double is_real is_numeric is_string is_array is_object is_scalar ereg ereg_replace eregi eregi_replace split spliti join sql_regcase dl pclose popen readfile rewind rmdir umask fclose feof fgetc fgets fgetss fread fopen fpassthru ftruncate fstat fseek ftell fflush fwrite fputs mkdir rename copy tempnam tmpfile file file_get_contents stream_select stream_context_create stream_context_set_params stream_context_set_option stream_context_get_options stream_filter_prepend stream_filter_append fgetcsv flock get_meta_tags stream_set_write_buffer set_file_buffer set_socket_blocking stream_set_blocking socket_set_blocking stream_get_meta_data stream_register_wrapper stream_wrapper_register stream_set_timeout socket_set_timeout socket_get_status realpath fnmatch fsockopen pfsockopen pack unpack get_browser crypt opendir closedir chdir getcwd rewinddir readdir dir glob fileatime filectime filegroup fileinode filemtime fileowner fileperms filesize filetype file_exists is_writable is_writeable is_readable is_executable is_file is_dir is_link stat lstat chown touch clearstatcache mail ob_start ob_flush ob_clean ob_end_flush ob_end_clean ob_get_flush ob_get_clean ob_get_length ob_get_level ob_get_status ob_get_contents ob_implicit_flush ob_list_handlers ksort krsort natsort natcasesort asort arsort sort rsort usort uasort uksort shuffle array_walk count end prev next reset current key min max in_array array_search extract compact array_fill range array_multisort array_push array_pop array_shift array_unshift array_splice array_slice array_merge array_merge_recursive array_keys array_values array_count_values array_reverse array_reduce array_pad array_flip array_change_key_case array_rand array_unique array_intersect array_intersect_assoc array_diff array_diff_assoc array_sum array_filter array_map array_chunk array_key_exists pos sizeof key_exists assert assert_options version_compare ftok str_rot13 aggregate session_name session_module_name session_save_path session_id session_regenerate_id session_decode session_register session_unregister session_is_registered session_encode session_start session_destroy session_unset session_set_save_handler session_cache_limiter session_cache_expire session_set_cookie_params session_get_cookie_params session_write_close preg_match preg_match_all preg_replace preg_replace_callback preg_split preg_quote preg_grep overload ctype_alnum ctype_alpha ctype_cntrl ctype_digit ctype_lower ctype_graph ctype_print ctype_punct ctype_space ctype_upper ctype_xdigit virtual apache_request_headers apache_note apache_lookup_uri apache_child_terminate apache_setenv apache_response_headers apache_get_version getallheaders mysql_connect mysql_pconnect mysql_close mysql_select_db mysql_create_db mysql_drop_db mysql_query mysql_unbuffered_query mysql_db_query mysql_list_dbs mysql_list_tables mysql_list_fields mysql_list_processes mysql_error mysql_errno mysql_affected_rows mysql_insert_id mysql_result mysql_num_rows mysql_num_fields mysql_fetch_row mysql_fetch_array mysql_fetch_assoc mysql_fetch_object mysql_data_seek mysql_fetch_lengths mysql_fetch_field mysql_field_seek mysql_free_result mysql_field_name mysql_field_table mysql_field_len mysql_field_type mysql_field_flags mysql_escape_string mysql_real_escape_string mysql_stat mysql_thread_id mysql_client_encoding mysql_get_client_info mysql_get_host_info mysql_get_proto_info mysql_get_server_info mysql_info mysql mysql_fieldname mysql_fieldtable mysql_fieldlen mysql_fieldtype mysql_fieldflags mysql_selectdb mysql_createdb mysql_dropdb mysql_freeresult mysql_numfields mysql_numrows mysql_listdbs mysql_listtables mysql_listfields mysql_db_name mysql_dbname mysql_tablename mysql_table_name pg_connect pg_pconnect pg_close pg_connection_status pg_connection_busy pg_connection_reset pg_host pg_dbname pg_port pg_tty pg_options pg_ping pg_query pg_send_query pg_cancel_query pg_fetch_result pg_fetch_row pg_fetch_assoc pg_fetch_array pg_fetch_object pg_fetch_all pg_affected_rows pg_get_result pg_result_seek pg_result_status pg_free_result pg_last_oid pg_num_rows pg_num_fields pg_field_name pg_field_num pg_field_size pg_field_type pg_field_prtlen pg_field_is_null pg_get_notify pg_get_pid pg_result_error pg_last_error pg_last_notice pg_put_line pg_end_copy pg_copy_to pg_copy_from pg_trace pg_untrace pg_lo_create pg_lo_unlink pg_lo_open pg_lo_close pg_lo_read pg_lo_write pg_lo_read_all pg_lo_import pg_lo_export pg_lo_seek pg_lo_tell pg_escape_string pg_escape_bytea pg_unescape_bytea pg_client_encoding pg_set_client_encoding pg_meta_data pg_convert pg_insert pg_update pg_delete pg_select pg_exec pg_getlastoid pg_cmdtuples pg_errormessage pg_numrows pg_numfields pg_fieldname pg_fieldsize pg_fieldtype pg_fieldnum pg_fieldprtlen pg_fieldisnull pg_freeresult pg_result pg_loreadall pg_locreate pg_lounlink pg_loopen pg_loclose pg_loread pg_lowrite pg_loimport pg_loexport http_response_code get_declared_traits getimagesizefromstring socket_import_stream stream_set_chunk_size trait_exists header_register_callback class_uses session_status session_register_shutdown echo print global static exit array empty eval isset unset die include require include_once require_once json_decode json_encode json_last_error json_last_error_msg curl_close curl_copy_handle curl_errno curl_error curl_escape curl_exec curl_file_create curl_getinfo curl_init curl_multi_add_handle curl_multi_close curl_multi_exec curl_multi_getcontent curl_multi_info_read curl_multi_init curl_multi_remove_handle curl_multi_select curl_multi_setopt curl_multi_strerror curl_pause curl_reset curl_setopt_array curl_setopt curl_share_close curl_share_init curl_share_setopt curl_strerror curl_unescape curl_version mysqli_affected_rows mysqli_autocommit mysqli_change_user mysqli_character_set_name mysqli_close mysqli_commit mysqli_connect_errno mysqli_connect_error mysqli_connect mysqli_data_seek mysqli_debug mysqli_dump_debug_info mysqli_errno mysqli_error_list mysqli_error mysqli_fetch_all mysqli_fetch_array mysqli_fetch_assoc mysqli_fetch_field_direct mysqli_fetch_field mysqli_fetch_fields mysqli_fetch_lengths mysqli_fetch_object mysqli_fetch_row mysqli_field_count mysqli_field_seek mysqli_field_tell mysqli_free_result mysqli_get_charset mysqli_get_client_info mysqli_get_client_stats mysqli_get_client_version mysqli_get_connection_stats mysqli_get_host_info mysqli_get_proto_info mysqli_get_server_info mysqli_get_server_version mysqli_info mysqli_init mysqli_insert_id mysqli_kill mysqli_more_results mysqli_multi_query mysqli_next_result mysqli_num_fields mysqli_num_rows mysqli_options mysqli_ping mysqli_prepare mysqli_query mysqli_real_connect mysqli_real_escape_string mysqli_real_query mysqli_reap_async_query mysqli_refresh mysqli_rollback mysqli_select_db mysqli_set_charset mysqli_set_local_infile_default mysqli_set_local_infile_handler mysqli_sqlstate mysqli_ssl_set mysqli_stat mysqli_stmt_init mysqli_store_result mysqli_thread_id mysqli_thread_safe mysqli_use_result mysqli_warning_count";
89
+ CodeMirror.registerHelper("hintWords", "php", [phpKeywords, phpAtoms, phpBuiltin].join(" ").split(" "));
90
+ CodeMirror.registerHelper("wordChars", "php", /[\w$]/);
91
+
92
+ var phpConfig = {
93
+ name: "clike",
94
+ helperType: "php",
95
+ keywords: keywords(phpKeywords),
96
+ blockKeywords: keywords("catch do else elseif for foreach if switch try while finally"),
97
+ atoms: keywords(phpAtoms),
98
+ builtin: keywords(phpBuiltin),
99
+ multiLineStrings: true,
100
+ hooks: {
101
+ "$": function(stream) {
102
+ stream.eatWhile(/[\w\$_]/);
103
+ return "variable-2";
104
+ },
105
+ "<": function(stream, state) {
106
+ if (stream.match(/<</)) {
107
+ stream.eatWhile(/[\w\.]/);
108
+ var delim = stream.current().slice(3);
109
+ if (delim) {
110
+ (state.tokStack || (state.tokStack = [])).push(delim, 0);
111
+ state.tokenize = stringWithEscapes(delim);
112
+ return "string";
113
+ }
114
+ }
115
+ return false;
116
+ },
117
+ "#": function(stream) {
118
+ while (!stream.eol() && !stream.match("?>", false)) stream.next();
119
+ return "comment";
120
+ },
121
+ "/": function(stream) {
122
+ if (stream.eat("/")) {
123
+ while (!stream.eol() && !stream.match("?>", false)) stream.next();
124
+ return "comment";
125
+ }
126
+ return false;
127
+ },
128
+ '"': function(_stream, state) {
129
+ (state.tokStack || (state.tokStack = [])).push('"'