Code Editor: Define default `gutters` and toggle lint markers based on changes to `lint` option.

Explicitly define `gutters` in base `defaultSettings` to improve merges of multiple calls to `wp_enqueue_code_editor()`.

Props westonruter, georgestephanis for testing.
Amends [41974].
See #12423.


git-svn-id: https://develop.svn.wordpress.org/trunk@41992 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Weston Ruter 2017-10-24 16:34:12 +00:00
parent 18f91933fb
commit c0a61efdad
2 changed files with 8 additions and 1 deletions

View File

@ -136,13 +136,19 @@ if ( 'undefined' === typeof window.wp.codeEditor ) {
// Keep lint options populated.
editor.on( 'optionChange', function( cm, option ) {
var options;
var options, gutters, gutterName = 'CodeMirror-lint-markers';
if ( 'lint' !== option ) {
return;
}
gutters = editor.getOption( 'gutters' ) || [];
options = editor.getOption( 'lint' );
if ( true === options ) {
if ( ! _.contains( gutters, gutterName ) ) {
editor.setOption( 'gutters', [ gutterName ].concat( gutters ) );
}
editor.setOption( 'lint', getLintOptions() ); // Expand to include linting options.
} else if ( ! options ) {
editor.setOption( 'gutters', _.without( gutters, gutterName ) );
}
// Force update on error notice to show or hide.

View File

@ -3157,6 +3157,7 @@ function wp_enqueue_code_editor( $args ) {
'Alt-F' => 'findPersistent',
),
'direction' => 'ltr', // Code is shown in LTR even in RTL languages.
'gutters' => array(),
),
'csslint' => array(
'errors' => true, // Parsing errors.