Skip to content
This repository was archived by the owner on Sep 6, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/brackets.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ define(function (require, exports, module) {
require("document/ChangedDocumentTracker");
require("editor/EditorStatusBar");
require("editor/EditorCommandHandlers");
require("editor/EditorOptionHandlers");
require("view/ViewCommandHandlers");
require("help/HelpCommandHandlers");
require("search/FindInFiles");
Expand Down
3 changes: 3 additions & 0 deletions src/command/Commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ define(function (require, exports, module) {
exports.VIEW_RESTORE_FONT_SIZE = "view.restoreFontSize";
exports.VIEW_SCROLL_LINE_UP = "view.scrollLineUp";
exports.VIEW_SCROLL_LINE_DOWN = "view.scrollLineDown";
exports.TOGGLE_LINE_NUMBERS = "view.toggleLineNumbers";
exports.TOGGLE_ACTIVE_LINE = "view.toggleActiveLine";
exports.TOGGLE_WORD_WRAP = "view.toggleWordWrap";
exports.TOGGLE_JSLINT = "debug.jslint";
exports.SORT_WORKINGSET_BY_ADDED = "view.sortWorkingSetByAdded";
exports.SORT_WORKINGSET_BY_NAME = "view.sortWorkingSetByName";
Expand Down
4 changes: 4 additions & 0 deletions src/command/DefaultMenus.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ define(function (require, exports, module) {
menu.addMenuItem(Commands.VIEW_DECREASE_FONT_SIZE);
menu.addMenuItem(Commands.VIEW_RESTORE_FONT_SIZE);
menu.addMenuDivider();
menu.addMenuItem(Commands.TOGGLE_LINE_NUMBERS);
menu.addMenuItem(Commands.TOGGLE_ACTIVE_LINE);
menu.addMenuItem(Commands.TOGGLE_WORD_WRAP);
menu.addMenuDivider();
menu.addMenuItem(Commands.TOGGLE_JSLINT);

/*
Expand Down
74 changes: 70 additions & 4 deletions src/editor/Editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ define(function (require, exports, module) {
ViewUtils = require("utils/ViewUtils");

var PREFERENCES_CLIENT_ID = PreferencesManager.getClientId(module.id),
defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4, closeBrackets: false };

defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4, closeBrackets: false,
showLineNumbers: true, styleActiveLine: true, wordWrap: true };
Copy link
Contributor

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.

Copy link
Contributor Author

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.


/** Editor preferences */
var _prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing an issue where the new default prefs (showLineNumbers, styleActiveLine and wordWrap) are not getting added to the _prefs object. I think this call here should be PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, defaultPrefs);. @TomMalbran you did the refactoring here recently...can you clarify?

Looking at PreferencesManager.handleClientIdChange() it looks like we ignore brand new defaults if we found non-empty preferences for the old ID.

The result here is that the first time I launch with @RaymondLim's changes I lose editor line numbers since showLineNumbers is undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Jason. I was seeing the same thing this morning on Mac. I'll look into it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there was a recent change, and there's another change coming (pull request: #3101). The following is correct:

    var _prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID);

The default prefs get set 2 lines later:

    PreferencesManager.handleClientIdChange(_prefs, "com.adobe.brackets.Editor", defaultPrefs);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@redmunds -- Does it mean I don't need to do anything in this pull request?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the code looks correct. The default prefs are only used if there are no other prefs, so I guess existing users will have to delete prefs to get the defaults.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked that I was getting an error when using getPreferenceStorage() and handleClientIdChange() both with defaults, and I didn't liked that the defaults had to be setted on the second function that will eventually be removed. So on my last commit I removed the defaults parameter from handleClientIdChange() and it can now be added to getPreferenceStorage() properly. I did the change, so it will get merged with my pull, or I can change it when this is merged.

//TODO: Remove preferences migration code
Expand All @@ -92,6 +93,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;

Expand Down Expand Up @@ -346,9 +356,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: {
Expand Down Expand Up @@ -1373,6 +1385,60 @@ define(function (require, exports, module) {
return _closeBrackets;
};

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Not sure how I got this in accidentally.

* Sets show line numbers option and reapply it to all open editors.
* @param {boolean} value
*/
Editor.setShowLineNumbers = function (value) {
_showLineNumbers = value;
_instances.forEach(function (editor) {
editor._codeMirror.setOption("lineNumbers", _showLineNumbers);
});

_prefs.setValue("showLineNumbers", Boolean(_showLineNumbers));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 5 lines are now repeated in 6 functions. It would be nicer to have a private function that given the option name and the value it would update the instances and the prefs, and call it from each function with the corresponding option and value. It could even be a normal function and not extended from Editor to make it really private.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice suggestion to refactor the repeated lines! Actually, these lines are in 7 functions. I leave out the first line since it is assigning to a different variable in the module scope and I'm not sure how to pass a variable by reference (in JavaScript) to the new private function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that is possible. The only other solution is use an object to save the preferences instead of a variable for each and could be initialized at the start with var _editorOptions = _prefs.getAllValues(). This could even make it possible to have 2 functions for all the options: Editor.getOption(option) and Editor.setOption(option, value), and checking in set if the option given is valid by looking it in _editorOptions.

};

/** @type {boolean} Gets whether all editors are showing line numbers */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wording "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;
_instances.forEach(function (editor) {
editor._codeMirror.setOption("styleActiveLine", _styleActiveLine);
});

_prefs.setValue("styleActiveLine", Boolean(_styleActiveLine));
};

/** @type {boolean} Gets whether all editors are showing active line */
Editor.getShowActiveLine = function () {
Copy link
Member

Choose a reason for hiding this comment

The 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;
_instances.forEach(function (editor) {
editor._codeMirror.setOption("lineWrapping", _wordWrap);
});

_prefs.setValue("wordWrap", Boolean(_wordWrap));
};

/** @type {boolean} Gets whether all editors are enabled for word wrap */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wording..."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;
Expand Down
13 changes: 0 additions & 13 deletions src/editor/EditorManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -684,21 +684,8 @@ define(function (require, exports, module) {
return result.promise();
}

/**
* @private
* Activates/Deactivates the automatic close brackets option
*/
function _toggleCloseBrackets() {
Editor.setCloseBrackets(!Editor.getCloseBrackets());
CommandManager.get(Commands.TOGGLE_CLOSE_BRACKETS).setChecked(Editor.getCloseBrackets());
}


// Initialize: command handlers
CommandManager.register(Strings.CMD_TOGGLE_QUICK_EDIT, Commands.TOGGLE_QUICK_EDIT, _toggleQuickEdit);
CommandManager.register(Strings.CMD_TOGGLE_CLOSE_BRACKETS, Commands.TOGGLE_CLOSE_BRACKETS, _toggleCloseBrackets)
.setChecked(Editor.getCloseBrackets());


// Initialize: register listeners
$(DocumentManager).on("currentDocumentChange", _onCurrentDocumentChange);
Expand Down
87 changes: 87 additions & 0 deletions src/editor/EditorOptionHandlers.js
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, window, $ */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

window and $ are unused globals. Remove.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


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());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be Commands.TOGGLE_CLOSE_BRACKETS

}

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);
Copy link
Member

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

});
5 changes: 3 additions & 2 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep these dependencies in sync with SpecRunner.html and Gruntfile.js

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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>
Expand Down
1 change: 1 addition & 0 deletions src/nls/root/strings.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ define({
"CMD_RESTORE_FONT_SIZE" : "Restore Font Size",
"CMD_SCROLL_LINE_UP" : "Scroll Line Up",
"CMD_SCROLL_LINE_DOWN" : "Scroll Line Down",
"CMD_TOGGLE_WORD_WRAP" : "Enable Word Wrap",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CMD_TOGGLE_LINE_NUMBERS and CMD_TOGGLE_ACTIVE_LINE are missing, causing the console errors I noted earlier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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",
Expand Down
4 changes: 4 additions & 0 deletions src/styles/brackets.less
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,10 @@ a, img {
height: auto;
}

.CodeMirror-activeline-background {
background: darken(@activeline-bgcolor, @bc-color-step-size / 2) !important;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GarthDB -- any suggestion on the adjustment of @activeline-bgcolor?

Copy link
Member

Choose a reason for hiding this comment

The 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 !important here.

}

.inline-editor-header {
padding: 10px 10px 0px 10px;

Expand Down
4 changes: 4 additions & 0 deletions src/styles/brackets_codemirror_override.less
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@

@code-padding: 15px;

.CodeMirror-activeline-background {
background: @activeline-bgcolor !important;
}

.cm-s-default {
span.cm-keyword {color: @accent-keyword;}
span.cm-atom {color: @accent-atom;}
Expand Down
3 changes: 3 additions & 0 deletions src/styles/brackets_theme_default.less
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@
@selection-color-focused: #d2dcf8;
@selection-color-unfocused: #d9d9d9;

/* background color of the line that has the cursor */
@activeline-bgcolor: #e8f2ff;
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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
Expand Down
1 change: 1 addition & 0 deletions test/UnitTestSuite.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ define(function (require, exports, module) {
require("spec/DocumentCommandHandlers-test");
require("spec/Editor-test");
require("spec/EditorCommandHandlers-test");
require("spec/EditorOptionHandlers-test");
require("spec/EditorManager-test");
require("spec/ExtensionUtils-test");
require("spec/FileIndexManager-test");
Expand Down
1 change: 1 addition & 0 deletions test/spec/EditorOptionHandlers-test-files/test.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions test/spec/EditorOptionHandlers-test-files/test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!doctype html>
<html>
<head>
<title>Simple Test</title>
<link rel="stylesheet" href="test.css">
</head>

<body>
<p class="longLineClass">Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome! Brackets is awesome!</p>
<p class="longLineClass">Brackets is awesome!</p>
</body>
</html>
Loading