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.

Built from https://develop.svn.wordpress.org/trunk@41992


git-svn-id: http://core.svn.wordpress.org/trunk@41826 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Weston Ruter
2017-10-24 16:35:54 +00:00
parent 9eb75432b6
commit 226263bfec
4 changed files with 10 additions and 3 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.