-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Provide editor options "line numbers", "active line" and "word wrap" as ... #3097
Changes from 13 commits
72536cf
8f35d64
cf60f0c
ca752e8
3d34f38
6ece1e2
5f5ef09
97a9774
47a3be3
5f8e4e8
e51f24a
38e572a
9c336f5
29e28f8
9996e84
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,8 +72,9 @@ define(function (require, exports, module) { | |
TokenUtils = require("utils/TokenUtils"), | ||
ViewUtils = require("utils/ViewUtils"); | ||
|
||
var defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4, closeBrackets: false }; | ||
|
||
defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4, closeBrackets: false, | ||
showLineNumbers: true, styleActiveLine: true, wordWrap: true }; | ||
|
||
/** Editor preferences */ | ||
var _prefs = PreferencesManager.getPreferenceStorage(module, defaultPrefs); | ||
//TODO: Remove preferences migration code | ||
|
@@ -91,6 +92,15 @@ define(function (require, exports, module) { | |
/** @type {boolean} Global setting: Auto closes (, {, [, " and ' */ | ||
var _closeBrackets = _prefs.getValue("closeBrackets"); | ||
|
||
/** @type {boolean} Global setting: Show line numbers in the gutter */ | ||
var _showLineNumbers = _prefs.getValue("showLineNumbers"); | ||
|
||
/** @type {boolean} Global setting: Highlight the background of the line that has the cursor */ | ||
var _styleActiveLine = _prefs.getValue("styleActiveLine"); | ||
|
||
/** @type {boolean} Global setting: Auto wrap lines */ | ||
var _wordWrap = _prefs.getValue("wordWrap"); | ||
|
||
/** @type {boolean} Guard flag to prevent focus() reentrancy (via blur handlers), even across Editors */ | ||
var _duringFocus = false; | ||
|
||
|
@@ -345,9 +355,11 @@ define(function (require, exports, module) { | |
indentWithTabs: _useTabChar, | ||
tabSize: _tabSize, | ||
indentUnit: _indentUnit, | ||
lineNumbers: true, | ||
lineNumbers: _showLineNumbers, | ||
lineWrapping: _wordWrap, | ||
styleActiveLine: _styleActiveLine, | ||
matchBrackets: true, | ||
dragDrop: false, // work around issue #1123 | ||
dragDrop: true, | ||
extraKeys: codeMirrorKeyMap, | ||
autoCloseBrackets: _closeBrackets, | ||
autoCloseTags: { | ||
|
@@ -1300,17 +1312,29 @@ define(function (require, exports, module) { | |
// Global settings that affect all Editor instances (both currently open Editors as well as those created | ||
// in the future) | ||
|
||
|
||
/** | ||
* @private | ||
* Updates Editor option and the corresponding preference with the given value. Affects all Editors. | ||
* @param {boolean | number} value | ||
* @param {string} cmOption - CodeMirror option string | ||
* @param {string} prefName - preference name string | ||
*/ | ||
function _setEditorOptionAndPref(value, cmOption, prefName) { | ||
_instances.forEach(function (editor) { | ||
editor._codeMirror.setOption(cmOption, value); | ||
}); | ||
|
||
_prefs.setValue(prefName, (typeof value === "boolean") ? Boolean(value) : value); | ||
} | ||
|
||
/** | ||
* Sets whether to use tab characters (vs. spaces) when inserting new text. Affects all Editors. | ||
* @param {boolean} value | ||
*/ | ||
Editor.setUseTabChar = function (value) { | ||
_useTabChar = value; | ||
_instances.forEach(function (editor) { | ||
editor._codeMirror.setOption("indentWithTabs", _useTabChar); | ||
}); | ||
|
||
_prefs.setValue("useTabChar", Boolean(_useTabChar)); | ||
_setEditorOptionAndPref(value, "indentWithTabs", "useTabChar"); | ||
}; | ||
|
||
/** @type {boolean} Gets whether all Editors use tab characters (vs. spaces) when inserting new text */ | ||
|
@@ -1324,11 +1348,7 @@ define(function (require, exports, module) { | |
*/ | ||
Editor.setTabSize = function (value) { | ||
_tabSize = value; | ||
_instances.forEach(function (editor) { | ||
editor._codeMirror.setOption("tabSize", _tabSize); | ||
}); | ||
|
||
_prefs.setValue("tabSize", _tabSize); | ||
_setEditorOptionAndPref(value, "tabSize", "tabSize"); | ||
}; | ||
|
||
/** @type {number} Get indent unit */ | ||
|
@@ -1342,11 +1362,7 @@ define(function (require, exports, module) { | |
*/ | ||
Editor.setIndentUnit = function (value) { | ||
_indentUnit = value; | ||
_instances.forEach(function (editor) { | ||
editor._codeMirror.setOption("indentUnit", _indentUnit); | ||
}); | ||
|
||
_prefs.setValue("indentUnit", _indentUnit); | ||
_setEditorOptionAndPref(value, "indentUnit", "indentUnit"); | ||
}; | ||
|
||
/** @type {number} Get indentation width */ | ||
|
@@ -1360,18 +1376,56 @@ define(function (require, exports, module) { | |
*/ | ||
Editor.setCloseBrackets = function (value) { | ||
_closeBrackets = value; | ||
_instances.forEach(function (editor) { | ||
editor._codeMirror.setOption("autoCloseBrackets", _closeBrackets); | ||
}); | ||
|
||
_prefs.setValue("closeBrackets", Boolean(_closeBrackets)); | ||
_setEditorOptionAndPref(value, "autoCloseBrackets", "closeBrackets"); | ||
}; | ||
|
||
/** @type {boolean} Gets whether all Editors use auto close brackets */ | ||
Editor.getCloseBrackets = function () { | ||
return _closeBrackets; | ||
}; | ||
|
||
/** | ||
* Sets show line numbers option and reapply it to all open editors. | ||
* @param {boolean} value | ||
*/ | ||
Editor.setShowLineNumbers = function (value) { | ||
_showLineNumbers = value; | ||
_setEditorOptionAndPref(value, "lineNumbers", "showLineNumbers"); | ||
}; | ||
|
||
/** @type {boolean} Returns true if show line numbers is enabled for all editors */ | ||
Editor.getShowLineNumbers = function () { | ||
return _showLineNumbers; | ||
}; | ||
|
||
/** | ||
* Sets show active line option and reapply it to all open editors. | ||
* @param {boolean} value | ||
*/ | ||
Editor.setShowActiveLine = function (value) { | ||
_styleActiveLine = value; | ||
_setEditorOptionAndPref(value, "styleActiveLine", "styleActiveLine"); | ||
}; | ||
|
||
/** @type {boolean} Returns true if show active line is enabled for all editors */ | ||
Editor.getShowActiveLine = function () { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wording..."Returns true if show active line is enabled for all editors" |
||
return _styleActiveLine; | ||
}; | ||
|
||
/** | ||
* Sets word wrap option and reapply it to all open editors. | ||
* @param {boolean} value | ||
*/ | ||
Editor.setWordWrap = function (value) { | ||
_wordWrap = value; | ||
_setEditorOptionAndPref(value, "lineWrapping", "wordWrap"); | ||
}; | ||
|
||
/** @type {boolean} Returns true if word wrap is enabled for all editors */ | ||
Editor.getWordWrap = function () { | ||
return _wordWrap; | ||
}; | ||
|
||
// Define public API | ||
exports.Editor = Editor; | ||
exports.BOUNDARY_CHECK_NORMAL = BOUNDARY_CHECK_NORMAL; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a | ||
* copy of this software and associated documentation files (the "Software"), | ||
* to deal in the Software without restriction, including without limitation | ||
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | ||
* and/or sell copies of the Software, and to permit persons to whom the | ||
* Software is furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
* DEALINGS IN THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, maxerr: 50 */ | ||
/*global define */ | ||
|
||
define(function (require, exports, module) { | ||
"use strict"; | ||
|
||
var AppInit = require("utils/AppInit"), | ||
Editor = require("editor/Editor").Editor, | ||
Commands = require("command/Commands"), | ||
CommandManager = require("command/CommandManager"), | ||
Strings = require("strings"); | ||
|
||
/** | ||
* @private | ||
* Activates/Deactivates showing line numbers option | ||
*/ | ||
function _toggleLineNumbers() { | ||
Editor.setShowLineNumbers(!Editor.getShowLineNumbers()); | ||
CommandManager.get(Commands.TOGGLE_LINE_NUMBERS).setChecked(Editor.getShowLineNumbers()); | ||
} | ||
|
||
|
||
/** | ||
* @private | ||
* Activates/Deactivates showing active line option | ||
*/ | ||
function _toggleActiveLine() { | ||
Editor.setShowActiveLine(!Editor.getShowActiveLine()); | ||
CommandManager.get(Commands.TOGGLE_ACTIVE_LINE).setChecked(Editor.getShowActiveLine()); | ||
} | ||
|
||
|
||
/** | ||
* @private | ||
* Activates/Deactivates word wrap option | ||
*/ | ||
function _toggleWordWrap() { | ||
Editor.setWordWrap(!Editor.getWordWrap()); | ||
CommandManager.get(Commands.TOGGLE_WORD_WRAP).setChecked(Editor.getWordWrap()); | ||
} | ||
|
||
/** | ||
* @private | ||
* Activates/Deactivates the automatic close brackets option | ||
*/ | ||
function _toggleCloseBrackets() { | ||
Editor.setCloseBrackets(!Editor.getCloseBrackets()); | ||
CommandManager.get(Commands.TOGGLE_CLOSE_BRACKETS).setChecked(Editor.getCloseBrackets()); | ||
} | ||
|
||
function _init() { | ||
CommandManager.get(Commands.TOGGLE_LINE_NUMBERS).setChecked(Editor.getShowLineNumbers()); | ||
CommandManager.get(Commands.TOGGLE_ACTIVE_LINE).setChecked(Editor.getShowActiveLine()); | ||
CommandManager.get(Commands.TOGGLE_WORD_WRAP).setChecked(Editor.getWordWrap()); | ||
CommandManager.get(Commands.CMD_TOGGLE_CLOSE_BRACKETS).setChecked(Editor.getCloseBrackets()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be |
||
} | ||
|
||
CommandManager.register(Strings.CMD_TOGGLE_LINE_NUMBERS, Commands.TOGGLE_LINE_NUMBERS, _toggleLineNumbers); | ||
CommandManager.register(Strings.CMD_TOGGLE_ACTIVE_LINE, Commands.TOGGLE_ACTIVE_LINE, _toggleActiveLine); | ||
CommandManager.register(Strings.CMD_TOGGLE_WORD_WRAP, Commands.TOGGLE_WORD_WRAP, _toggleWordWrap); | ||
CommandManager.register(Strings.CMD_TOGGLE_CLOSE_BRACKETS, Commands.TOGGLE_CLOSE_BRACKETS, _toggleCloseBrackets); | ||
|
||
AppInit.htmlReady(_init); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious...do we need to wait for htmlReady for either html or native menus? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm just trying to make sure that we successfully update the menu items. So let me know if I need to remove it. |
||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,10 +101,11 @@ | |
<script src="thirdparty/CodeMirror2/lib/codemirror.js"></script> | ||
<script src="thirdparty/CodeMirror2/addon/edit/matchbrackets.js"></script> | ||
<script src="thirdparty/CodeMirror2/addon/edit/closebrackets.js"></script> | ||
|
||
<script src="thirdparty/CodeMirror2/addon/edit/closetag.js"></script> | ||
<script src="thirdparty/CodeMirror2/addon/selection/active-line.js"></script> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep these dependencies in sync with SpecRunner.html and Gruntfile.js There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice to know! I'll update them. |
||
|
||
<!-- JS for CodeMirror search support --> | ||
<script src="thirdparty/CodeMirror2/addon/search/searchcursor.js"></script> | ||
<script src="thirdparty/CodeMirror2/addon/edit/closetag.js"></script> | ||
|
||
</head> | ||
<body> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,6 +215,9 @@ define({ | |
"CMD_RESTORE_FONT_SIZE" : "Restore Font Size", | ||
"CMD_SCROLL_LINE_UP" : "Scroll Line Up", | ||
"CMD_SCROLL_LINE_DOWN" : "Scroll Line Down", | ||
"CMD_TOGGLE_LINE_NUMBERS" : "Show Line Numbers", | ||
"CMD_TOGGLE_ACTIVE_LINE" : "Show Active Line", | ||
"CMD_TOGGLE_WORD_WRAP" : "Enable Word Wrap", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Somehow I didn't get them in when resolving the conflicts in merging master to my branch. |
||
"CMD_SORT_WORKINGSET_BY_ADDED" : "Sort by Added", | ||
"CMD_SORT_WORKINGSET_BY_NAME" : "Sort by Name", | ||
"CMD_SORT_WORKINGSET_BY_TYPE" : "Sort by Type", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -559,6 +559,10 @@ a, img { | |
height: auto; | ||
} | ||
|
||
.CodeMirror-activeline-background { | ||
background: darken(@activeline-bgcolor, @bc-color-step-size / 2) !important; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @GarthDB -- any suggestion on the adjustment of @activeline-bgcolor? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks ok to me. If we don't hear from @GarthDB, we can merge and address it later. I tested Find to confirm that search results still appear highlighted even with |
||
} | ||
|
||
.inline-editor-header { | ||
padding: 10px 10px 0px 10px; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -101,6 +101,9 @@ | |
@selection-color-focused: #d2dcf8; | ||
@selection-color-unfocused: #d9d9d9; | ||
|
||
/* background color of the line that has the cursor */ | ||
@activeline-bgcolor: #e8f2ff; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @GarthDB -- see if you have any comment on this color. |
||
|
||
/* Code font formatting | ||
* | ||
* NOTE (JRB): In order to get the web font to load early enough, we have a div called "dummy-text" that | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing the var now. Seems like this is what made the build fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I was unable to launch and still looking for the culprit.