Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.

Commit 8f35d64

Browse files
committed
Provide editor options "line numbers", "active line" and "word wrap" as new menu items under View menu.
1 parent d1569ae commit 8f35d64

File tree

10 files changed

+170
-5
lines changed

10 files changed

+170
-5
lines changed

src/brackets.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ define(function (require, exports, module) {
9999
require("command/DefaultMenus");
100100
require("document/ChangedDocumentTracker");
101101
require("editor/EditorCommandHandlers");
102+
require("editor/EditorOptionHandlers");
102103
require("view/ViewCommandHandlers");
103104
require("help/HelpCommandHandlers");
104105
require("search/FindInFiles");

src/command/Commands.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ define(function (require, exports, module) {
7878
exports.VIEW_INCREASE_FONT_SIZE = "view.increaseFontSize";
7979
exports.VIEW_DECREASE_FONT_SIZE = "view.decreaseFontSize";
8080
exports.VIEW_RESTORE_FONT_SIZE = "view.restoreFontSize";
81+
exports.TOGGLE_LINE_NUMBERS = "view.toggleLineNumbers";
82+
exports.TOGGLE_ACTIVE_LINE = "view.toggleActiveLine";
83+
exports.TOGGLE_WORD_WRAP = "view.toggleWordWrap";
8184
exports.TOGGLE_JSLINT = "debug.jslint";
8285
exports.SORT_WORKINGSET_BY_ADDED = "view.sortWorkingSetByAdded";
8386
exports.SORT_WORKINGSET_BY_NAME = "view.sortWorkingSetByName";

src/command/DefaultMenus.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ define(function (require, exports, module) {
108108
menu.addMenuItem(Commands.VIEW_DECREASE_FONT_SIZE);
109109
menu.addMenuItem(Commands.VIEW_RESTORE_FONT_SIZE);
110110
menu.addMenuDivider();
111+
menu.addMenuItem(Commands.TOGGLE_LINE_NUMBERS);
112+
menu.addMenuItem(Commands.TOGGLE_ACTIVE_LINE);
113+
menu.addMenuItem(Commands.TOGGLE_WORD_WRAP);
114+
menu.addMenuDivider();
111115
menu.addMenuItem(Commands.TOGGLE_JSLINT);
112116

113117
/*

src/editor/Editor.js

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ define(function (require, exports, module) {
7373
ViewUtils = require("utils/ViewUtils");
7474

7575
var PREFERENCES_CLIENT_ID = "com.adobe.brackets.Editor",
76-
defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4, closeBrackets: false };
76+
defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4, closeBrackets: false,
77+
showLineNumbers: true, styleActiveLine: true, wordWrap: true };
7778

7879
/** Editor preferences */
7980
var _prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, defaultPrefs);
@@ -90,6 +91,15 @@ define(function (require, exports, module) {
9091
/** @type {boolean} Global setting: Auto closes (, {, [, " and ' */
9192
var _closeBrackets = _prefs.getValue("closeBrackets");
9293

94+
/** @type {boolean} Global setting: Show line numbers in the gutter */
95+
var _showLineNumbers = _prefs.getValue("showLineNumbers");
96+
97+
/** @type {boolean} Global setting: Highlight the background of the line that has the cursor */
98+
var _styleActiveLine = _prefs.getValue("styleActiveLine");
99+
100+
/** @type {boolean} Global setting: Auto wrap lines */
101+
var _wordWrap = _prefs.getValue("wordWrap");
102+
93103
/** @type {boolean} Guard flag to prevent focus() reentrancy (via blur handlers), even across Editors */
94104
var _duringFocus = false;
95105

@@ -344,9 +354,11 @@ define(function (require, exports, module) {
344354
indentWithTabs: _useTabChar,
345355
tabSize: _tabSize,
346356
indentUnit: _indentUnit,
347-
lineNumbers: true,
357+
lineNumbers: _showLineNumbers,
358+
lineWrapping: _wordWrap,
359+
styleActiveLine: _styleActiveLine,
348360
matchBrackets: true,
349-
dragDrop: false, // work around issue #1123
361+
dragDrop: true,
350362
extraKeys: codeMirrorKeyMap,
351363
autoCloseBrackets: _closeBrackets,
352364
autoCloseTags: {
@@ -1363,6 +1375,60 @@ define(function (require, exports, module) {
13631375
return _closeBrackets;
13641376
};
13651377

1378+
/**
1379+
* Sets show line numbers option and reapply it to all open editors.
1380+
* @param {boolean} value
1381+
*/
1382+
Editor.setShowLineNumbers = function (value) {
1383+
_showLineNumbers = value;
1384+
_instances.forEach(function (editor) {
1385+
editor._codeMirror.setOption("lineNumbers", _showLineNumbers);
1386+
});
1387+
1388+
_prefs.setValue("showLineNumbers", Boolean(_showLineNumbers));
1389+
};
1390+
1391+
/** @type {boolean} Gets whether all editors are showing line numbers */
1392+
Editor.getShowLineNumbers = function () {
1393+
return _showLineNumbers;
1394+
};
1395+
1396+
/**
1397+
* Sets show active line option and reapply it to all open editors.
1398+
* @param {boolean} value
1399+
*/
1400+
Editor.setShowActiveLine = function (value) {
1401+
_styleActiveLine = value;
1402+
_instances.forEach(function (editor) {
1403+
editor._codeMirror.setOption("styleActiveLine", _styleActiveLine);
1404+
});
1405+
1406+
_prefs.setValue("styleActiveLine", Boolean(_styleActiveLine));
1407+
};
1408+
1409+
/** @type {boolean} Gets whether all editors are showing active line */
1410+
Editor.getShowActiveLine = function () {
1411+
return _styleActiveLine;
1412+
};
1413+
1414+
/**
1415+
* Sets word wrap option and reapply it to all open editors.
1416+
* @param {boolean} value
1417+
*/
1418+
Editor.setWordWrap = function (value) {
1419+
_wordWrap = value;
1420+
_instances.forEach(function (editor) {
1421+
editor._codeMirror.setOption("lineWrapping", _wordWrap);
1422+
});
1423+
1424+
_prefs.setValue("wordWrap", Boolean(_wordWrap));
1425+
};
1426+
1427+
/** @type {boolean} Gets whether all editors are enabled for word wrap */
1428+
Editor.getWordWrap = function () {
1429+
return _wordWrap;
1430+
};
1431+
13661432
// Define public API
13671433
exports.Editor = Editor;
13681434
exports.BOUNDARY_CHECK_NORMAL = BOUNDARY_CHECK_NORMAL;

src/editor/EditorOptionHandlers.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20+
* DEALINGS IN THE SOFTWARE.
21+
*
22+
*/
23+
24+
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */
25+
/*global define, window, $ */
26+
27+
define(function (require, exports, module) {
28+
"use strict";
29+
30+
var AppInit = require("utils/AppInit"),
31+
Editor = require("editor/Editor").Editor,
32+
Commands = require("command/Commands"),
33+
CommandManager = require("command/CommandManager"),
34+
Strings = require("strings");
35+
36+
/**
37+
* @private
38+
* Activates/Deactivates showing line numbers option
39+
*/
40+
function _toggleLineNumbers() {
41+
Editor.setShowLineNumbers(!Editor.getShowLineNumbers());
42+
CommandManager.get(Commands.TOGGLE_LINE_NUMBERS).setChecked(Editor.getShowLineNumbers());
43+
}
44+
45+
46+
/**
47+
* @private
48+
* Activates/Deactivates showing active line option
49+
*/
50+
function _toggleActiveLine() {
51+
Editor.setShowActiveLine(!Editor.getShowActiveLine());
52+
CommandManager.get(Commands.TOGGLE_ACTIVE_LINE).setChecked(Editor.getShowActiveLine());
53+
}
54+
55+
56+
/**
57+
* @private
58+
* Activates/Deactivates word wrap option
59+
*/
60+
function _toggleWordWrap() {
61+
Editor.setWordWrap(!Editor.getWordWrap());
62+
CommandManager.get(Commands.TOGGLE_WORD_WRAP).setChecked(Editor.getWordWrap());
63+
}
64+
65+
function _init() {
66+
CommandManager.get(Commands.TOGGLE_LINE_NUMBERS).setChecked(Editor.getShowLineNumbers());
67+
CommandManager.get(Commands.TOGGLE_ACTIVE_LINE).setChecked(Editor.getShowActiveLine());
68+
CommandManager.get(Commands.TOGGLE_WORD_WRAP).setChecked(Editor.getWordWrap());
69+
}
70+
71+
CommandManager.register(Strings.CMD_TOGGLE_LINE_NUMBERS, Commands.TOGGLE_LINE_NUMBERS, _toggleLineNumbers);
72+
CommandManager.register(Strings.CMD_TOGGLE_ACTIVE_LINE, Commands.TOGGLE_ACTIVE_LINE, _toggleActiveLine);
73+
CommandManager.register(Strings.CMD_TOGGLE_WORD_WRAP, Commands.TOGGLE_WORD_WRAP, _toggleWordWrap);
74+
75+
AppInit.htmlReady(_init);
76+
});

src/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,11 @@
101101
<script src="thirdparty/CodeMirror2/lib/codemirror.js"></script>
102102
<script src="thirdparty/CodeMirror2/addon/edit/matchbrackets.js"></script>
103103
<script src="thirdparty/CodeMirror2/addon/edit/closebrackets.js"></script>
104-
104+
<script src="thirdparty/CodeMirror2/addon/edit/closetag.js"></script>
105+
<script src="thirdparty/CodeMirror2/addon/selection/active-line.js"></script>
106+
105107
<!-- JS for CodeMirror search support -->
106108
<script src="thirdparty/CodeMirror2/addon/search/searchcursor.js"></script>
107-
<script src="thirdparty/CodeMirror2/addon/edit/closetag.js"></script>
108109

109110
</head>
110111
<body>

src/nls/root/strings.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ define({
211211
"CMD_INCREASE_FONT_SIZE" : "Increase Font Size",
212212
"CMD_DECREASE_FONT_SIZE" : "Decrease Font Size",
213213
"CMD_RESTORE_FONT_SIZE" : "Restore Font Size",
214+
"CMD_TOGGLE_LINE_NUMBERS" : "Show Line Numbers",
215+
"CMD_TOGGLE_ACTIVE_LINE" : "Show Active Line",
216+
"CMD_TOGGLE_WORD_WRAP" : "Enable Word Wrap",
214217
"CMD_SORT_WORKINGSET_BY_ADDED" : "Sort by Added",
215218
"CMD_SORT_WORKINGSET_BY_NAME" : "Sort by Name",
216219
"CMD_SORT_WORKINGSET_BY_TYPE" : "Sort by Type",

src/styles/brackets.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,10 @@ a, img {
570570
height: auto;
571571
}
572572

573+
.CodeMirror-activeline-background {
574+
background: darken(@activeline-bgcolor, @bc-color-step-size / 2) !important;
575+
}
576+
573577
.inline-editor-header {
574578
padding: 10px 10px 0px 10px;
575579

src/styles/brackets_codemirror_override.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444

4545
@code-padding: 15px;
4646

47+
.CodeMirror-activeline-background {
48+
background: @activeline-bgcolor !important;
49+
}
50+
4751
.cm-s-default {
4852
span.cm-keyword {color: @accent-keyword;}
4953
span.cm-atom {color: @accent-atom;}

src/styles/brackets_theme_default.less

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@
101101
@selection-color-focused: #d2dcf8;
102102
@selection-color-unfocused: #d9d9d9;
103103

104+
/* background color of the line that has the cursor */
105+
@activeline-bgcolor: #e8f2ff;
106+
104107
/* Code font formatting
105108
*
106109
* NOTE (JRB): In order to get the web font to load early enough, we have a div called "dummy-text" that

0 commit comments

Comments
 (0)