@@ -72,8 +72,9 @@ define(function (require, exports, module) {
7272 TokenUtils = require ( "utils/TokenUtils" ) ,
7373 ViewUtils = require ( "utils/ViewUtils" ) ;
7474
75- var defaultPrefs = { useTabChar : false , tabSize : 4 , indentUnit : 4 , closeBrackets : false } ;
76-
75+ var defaultPrefs = { useTabChar : false , tabSize : 4 , indentUnit : 4 , closeBrackets : false ,
76+ showLineNumbers : true , styleActiveLine : true , wordWrap : true } ;
77+
7778 /** Editor preferences */
7879 var _prefs = PreferencesManager . getPreferenceStorage ( module , defaultPrefs ) ;
7980 //TODO: Remove preferences migration code
@@ -91,6 +92,15 @@ define(function (require, exports, module) {
9192 /** @type {boolean } Global setting: Auto closes (, {, [, " and ' */
9293 var _closeBrackets = _prefs . getValue ( "closeBrackets" ) ;
9394
95+ /** @type {boolean } Global setting: Show line numbers in the gutter */
96+ var _showLineNumbers = _prefs . getValue ( "showLineNumbers" ) ;
97+
98+ /** @type {boolean } Global setting: Highlight the background of the line that has the cursor */
99+ var _styleActiveLine = _prefs . getValue ( "styleActiveLine" ) ;
100+
101+ /** @type {boolean } Global setting: Auto wrap lines */
102+ var _wordWrap = _prefs . getValue ( "wordWrap" ) ;
103+
94104 /** @type {boolean } Guard flag to prevent focus() reentrancy (via blur handlers), even across Editors */
95105 var _duringFocus = false ;
96106
@@ -345,9 +355,11 @@ define(function (require, exports, module) {
345355 indentWithTabs : _useTabChar ,
346356 tabSize : _tabSize ,
347357 indentUnit : _indentUnit ,
348- lineNumbers : true ,
358+ lineNumbers : _showLineNumbers ,
359+ lineWrapping : _wordWrap ,
360+ styleActiveLine : _styleActiveLine ,
349361 matchBrackets : true ,
350- dragDrop : false , // work around issue #1123
362+ dragDrop : true ,
351363 extraKeys : codeMirrorKeyMap ,
352364 autoCloseBrackets : _closeBrackets ,
353365 autoCloseTags : {
@@ -1300,17 +1312,29 @@ define(function (require, exports, module) {
13001312 // Global settings that affect all Editor instances (both currently open Editors as well as those created
13011313 // in the future)
13021314
1315+
1316+ /**
1317+ * @private
1318+ * Updates Editor option and the corresponding preference with the given value. Affects all Editors.
1319+ * @param {boolean | number } value
1320+ * @param {string } cmOption - CodeMirror option string
1321+ * @param {string } prefName - preference name string
1322+ */
1323+ function _setEditorOptionAndPref ( value , cmOption , prefName ) {
1324+ _instances . forEach ( function ( editor ) {
1325+ editor . _codeMirror . setOption ( cmOption , value ) ;
1326+ } ) ;
1327+
1328+ _prefs . setValue ( prefName , ( typeof value === "boolean" ) ? Boolean ( value ) : value ) ;
1329+ }
1330+
13031331 /**
13041332 * Sets whether to use tab characters (vs. spaces) when inserting new text. Affects all Editors.
13051333 * @param {boolean } value
13061334 */
13071335 Editor . setUseTabChar = function ( value ) {
13081336 _useTabChar = value ;
1309- _instances . forEach ( function ( editor ) {
1310- editor . _codeMirror . setOption ( "indentWithTabs" , _useTabChar ) ;
1311- } ) ;
1312-
1313- _prefs . setValue ( "useTabChar" , Boolean ( _useTabChar ) ) ;
1337+ _setEditorOptionAndPref ( value , "indentWithTabs" , "useTabChar" ) ;
13141338 } ;
13151339
13161340 /** @type {boolean } Gets whether all Editors use tab characters (vs. spaces) when inserting new text */
@@ -1324,11 +1348,7 @@ define(function (require, exports, module) {
13241348 */
13251349 Editor . setTabSize = function ( value ) {
13261350 _tabSize = value ;
1327- _instances . forEach ( function ( editor ) {
1328- editor . _codeMirror . setOption ( "tabSize" , _tabSize ) ;
1329- } ) ;
1330-
1331- _prefs . setValue ( "tabSize" , _tabSize ) ;
1351+ _setEditorOptionAndPref ( value , "tabSize" , "tabSize" ) ;
13321352 } ;
13331353
13341354 /** @type {number } Get indent unit */
@@ -1342,11 +1362,7 @@ define(function (require, exports, module) {
13421362 */
13431363 Editor . setIndentUnit = function ( value ) {
13441364 _indentUnit = value ;
1345- _instances . forEach ( function ( editor ) {
1346- editor . _codeMirror . setOption ( "indentUnit" , _indentUnit ) ;
1347- } ) ;
1348-
1349- _prefs . setValue ( "indentUnit" , _indentUnit ) ;
1365+ _setEditorOptionAndPref ( value , "indentUnit" , "indentUnit" ) ;
13501366 } ;
13511367
13521368 /** @type {number } Get indentation width */
@@ -1360,18 +1376,56 @@ define(function (require, exports, module) {
13601376 */
13611377 Editor . setCloseBrackets = function ( value ) {
13621378 _closeBrackets = value ;
1363- _instances . forEach ( function ( editor ) {
1364- editor . _codeMirror . setOption ( "autoCloseBrackets" , _closeBrackets ) ;
1365- } ) ;
1366-
1367- _prefs . setValue ( "closeBrackets" , Boolean ( _closeBrackets ) ) ;
1379+ _setEditorOptionAndPref ( value , "autoCloseBrackets" , "closeBrackets" ) ;
13681380 } ;
13691381
13701382 /** @type {boolean } Gets whether all Editors use auto close brackets */
13711383 Editor . getCloseBrackets = function ( ) {
13721384 return _closeBrackets ;
13731385 } ;
13741386
1387+ /**
1388+ * Sets show line numbers option and reapply it to all open editors.
1389+ * @param {boolean } value
1390+ */
1391+ Editor . setShowLineNumbers = function ( value ) {
1392+ _showLineNumbers = value ;
1393+ _setEditorOptionAndPref ( value , "lineNumbers" , "showLineNumbers" ) ;
1394+ } ;
1395+
1396+ /** @type {boolean } Returns true if show line numbers is enabled for all editors */
1397+ Editor . getShowLineNumbers = function ( ) {
1398+ return _showLineNumbers ;
1399+ } ;
1400+
1401+ /**
1402+ * Sets show active line option and reapply it to all open editors.
1403+ * @param {boolean } value
1404+ */
1405+ Editor . setShowActiveLine = function ( value ) {
1406+ _styleActiveLine = value ;
1407+ _setEditorOptionAndPref ( value , "styleActiveLine" , "styleActiveLine" ) ;
1408+ } ;
1409+
1410+ /** @type {boolean } Returns true if show active line is enabled for all editors */
1411+ Editor . getShowActiveLine = function ( ) {
1412+ return _styleActiveLine ;
1413+ } ;
1414+
1415+ /**
1416+ * Sets word wrap option and reapply it to all open editors.
1417+ * @param {boolean } value
1418+ */
1419+ Editor . setWordWrap = function ( value ) {
1420+ _wordWrap = value ;
1421+ _setEditorOptionAndPref ( value , "lineWrapping" , "wordWrap" ) ;
1422+ } ;
1423+
1424+ /** @type {boolean } Returns true if word wrap is enabled for all editors */
1425+ Editor . getWordWrap = function ( ) {
1426+ return _wordWrap ;
1427+ } ;
1428+
13751429 // Define public API
13761430 exports . Editor = Editor ;
13771431 exports . BOUNDARY_CHECK_NORMAL = BOUNDARY_CHECK_NORMAL ;
0 commit comments