@@ -72,8 +72,9 @@ define(function (require, exports, module) {
72
72
TokenUtils = require ( "utils/TokenUtils" ) ,
73
73
ViewUtils = require ( "utils/ViewUtils" ) ;
74
74
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
+
77
78
/** Editor preferences */
78
79
var _prefs = PreferencesManager . getPreferenceStorage ( module , defaultPrefs ) ;
79
80
//TODO: Remove preferences migration code
@@ -91,6 +92,15 @@ define(function (require, exports, module) {
91
92
/** @type {boolean } Global setting: Auto closes (, {, [, " and ' */
92
93
var _closeBrackets = _prefs . getValue ( "closeBrackets" ) ;
93
94
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
+
94
104
/** @type {boolean } Guard flag to prevent focus() reentrancy (via blur handlers), even across Editors */
95
105
var _duringFocus = false ;
96
106
@@ -345,9 +355,11 @@ define(function (require, exports, module) {
345
355
indentWithTabs : _useTabChar ,
346
356
tabSize : _tabSize ,
347
357
indentUnit : _indentUnit ,
348
- lineNumbers : true ,
358
+ lineNumbers : _showLineNumbers ,
359
+ lineWrapping : _wordWrap ,
360
+ styleActiveLine : _styleActiveLine ,
349
361
matchBrackets : true ,
350
- dragDrop : false , // work around issue #1123
362
+ dragDrop : true ,
351
363
extraKeys : codeMirrorKeyMap ,
352
364
autoCloseBrackets : _closeBrackets ,
353
365
autoCloseTags : {
@@ -1300,17 +1312,29 @@ define(function (require, exports, module) {
1300
1312
// Global settings that affect all Editor instances (both currently open Editors as well as those created
1301
1313
// in the future)
1302
1314
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
+
1303
1331
/**
1304
1332
* Sets whether to use tab characters (vs. spaces) when inserting new text. Affects all Editors.
1305
1333
* @param {boolean } value
1306
1334
*/
1307
1335
Editor . setUseTabChar = function ( value ) {
1308
1336
_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" ) ;
1314
1338
} ;
1315
1339
1316
1340
/** @type {boolean } Gets whether all Editors use tab characters (vs. spaces) when inserting new text */
@@ -1324,11 +1348,7 @@ define(function (require, exports, module) {
1324
1348
*/
1325
1349
Editor . setTabSize = function ( value ) {
1326
1350
_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" ) ;
1332
1352
} ;
1333
1353
1334
1354
/** @type {number } Get indent unit */
@@ -1342,11 +1362,7 @@ define(function (require, exports, module) {
1342
1362
*/
1343
1363
Editor . setIndentUnit = function ( value ) {
1344
1364
_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" ) ;
1350
1366
} ;
1351
1367
1352
1368
/** @type {number } Get indentation width */
@@ -1360,18 +1376,56 @@ define(function (require, exports, module) {
1360
1376
*/
1361
1377
Editor . setCloseBrackets = function ( value ) {
1362
1378
_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" ) ;
1368
1380
} ;
1369
1381
1370
1382
/** @type {boolean } Gets whether all Editors use auto close brackets */
1371
1383
Editor . getCloseBrackets = function ( ) {
1372
1384
return _closeBrackets ;
1373
1385
} ;
1374
1386
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
+
1375
1429
// Define public API
1376
1430
exports . Editor = Editor ;
1377
1431
exports . BOUNDARY_CHECK_NORMAL = BOUNDARY_CHECK_NORMAL ;
0 commit comments