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

Commit f41c78a

Browse files
committed
Merge remote-tracking branch 'origin/master' into randy/perf-status-bar
2 parents 17612b7 + da1f4a5 commit f41c78a

9 files changed

Lines changed: 255 additions & 175 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Together with your contributions, we're getting close to our first release candi
3030

3131
#### Download
3232

33-
Installers for the latest stable build for Mac, Windows and Linux (Debian/Ubuntu) can be [downloaded here](http://download.brackets.io/).
33+
Installers for the latest stable build for Mac, Windows and Linux (Debian/Ubuntu) can be [downloaded here](http://brackets.io/).
3434

3535
The Linux version has most of the features of the Mac and Windows versions, but
3636
is still missing a few things. See the [Linux wiki page](https://github.com/adobe/brackets/wiki/Linux-Version)

src/brackets.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ define(function (require, exports, module) {
5151
require("thirdparty/CodeMirror2/addon/edit/matchbrackets");
5252
require("thirdparty/CodeMirror2/addon/edit/closebrackets");
5353
require("thirdparty/CodeMirror2/addon/edit/closetag");
54+
require("thirdparty/CodeMirror2/addon/scroll/scrollpastend");
5455
require("thirdparty/CodeMirror2/addon/selection/active-line");
5556
require("thirdparty/CodeMirror2/addon/mode/multiplex");
5657
require("thirdparty/CodeMirror2/addon/mode/overlay");
@@ -99,15 +100,28 @@ define(function (require, exports, module) {
99100
ColorUtils = require("utils/ColorUtils"),
100101
CodeInspection = require("language/CodeInspection"),
101102
NativeApp = require("utils/NativeApp"),
103+
DeprecationWarning = require("utils/DeprecationWarning"),
104+
ViewCommandHandlers = require("view/ViewCommandHandlers"),
102105
_ = require("thirdparty/lodash");
103-
106+
107+
// DEPRECATED: In future we want to remove the global CodeMirror, but for now we
108+
// expose our required CodeMirror globally so as to avoid breaking extensions in the
109+
// interim.
110+
var CodeMirror = require("thirdparty/CodeMirror2/lib/codemirror");
111+
112+
Object.defineProperty(window, "CodeMirror", {
113+
get: function () {
114+
DeprecationWarning.deprecationWarning('Use brackets.getModule("thirdparty/CodeMirror2/lib/codemirror") instead of global CodeMirror.', true);
115+
return CodeMirror;
116+
}
117+
});
118+
104119
// Load modules that self-register and just need to get included in the main project
105120
require("command/DefaultMenus");
106121
require("document/ChangedDocumentTracker");
107122
require("editor/EditorStatusBar");
108123
require("editor/EditorCommandHandlers");
109124
require("editor/EditorOptionHandlers");
110-
require("view/ViewCommandHandlers");
111125
require("help/HelpCommandHandlers");
112126
require("search/FindInFiles");
113127
require("search/FindReplace");
@@ -220,6 +234,7 @@ define(function (require, exports, module) {
220234
// Load the initial project after extensions have loaded
221235
extensionLoaderPromise.always(function () {
222236
// Finish UI initialization
237+
ViewCommandHandlers.restoreFontSize();
223238
var initialProjectPath = ProjectManager.getInitialProjectPath();
224239
ProjectManager.openProject(initialProjectPath).always(function () {
225240
_initTest();

src/editor/Editor.js

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -64,53 +64,58 @@
6464
define(function (require, exports, module) {
6565
"use strict";
6666

67-
var CodeMirror = require("thirdparty/CodeMirror2/lib/codemirror"),
67+
var AnimationUtils = require("utils/AnimationUtils"),
68+
Async = require("utils/Async"),
69+
CodeMirror = require("thirdparty/CodeMirror2/lib/codemirror"),
6870
Menus = require("command/Menus"),
6971
PerfUtils = require("utils/PerfUtils"),
7072
PreferencesManager = require("preferences/PreferencesManager"),
7173
Strings = require("strings"),
7274
TextRange = require("document/TextRange").TextRange,
7375
TokenUtils = require("utils/TokenUtils"),
7476
ViewUtils = require("utils/ViewUtils"),
75-
Async = require("utils/Async"),
76-
AnimationUtils = require("utils/AnimationUtils"),
7777
_ = require("thirdparty/lodash");
7878

7979
/** Editor preferences */
80-
var SMART_INDENT = "smartIndent",
81-
USE_TAB_CHAR = "useTabChar",
82-
TAB_SIZE = "tabSize",
83-
SPACE_UNITS = "spaceUnits",
84-
CLOSE_BRACKETS = "closeBrackets",
80+
var CLOSE_BRACKETS = "closeBrackets",
81+
CLOSE_TAGS = "closeTags",
82+
SCROLL_PAST_END = "scrollPastEnd",
8583
SHOW_LINE_NUMBERS = "showLineNumbers",
84+
SMART_INDENT = "smartIndent",
85+
SOFT_TABS = "softTabs",
86+
SPACE_UNITS = "spaceUnits",
8687
STYLE_ACTIVE_LINE = "styleActiveLine",
88+
TAB_SIZE = "tabSize",
8789
WORD_WRAP = "wordWrap",
88-
CLOSE_TAGS = "closeTags",
89-
cmOptions = {};
90+
USE_TAB_CHAR = "useTabChar";
91+
92+
var cmOptions = {};
9093

9194
// Mappings from Brackets preferences to CodeMirror options
92-
cmOptions[SMART_INDENT] = "smartIndent";
93-
cmOptions[USE_TAB_CHAR] = "indentWithTabs";
94-
cmOptions[TAB_SIZE] = "indentUnit";
95-
cmOptions[SPACE_UNITS] = "indentUnit";
9695
cmOptions[CLOSE_BRACKETS] = "autoCloseBrackets";
96+
cmOptions[CLOSE_TAGS] = "autoCloseTags";
97+
cmOptions[SCROLL_PAST_END] = "scrollPastEnd";
9798
cmOptions[SHOW_LINE_NUMBERS] = "lineNumbers";
99+
cmOptions[SMART_INDENT] = "smartIndent";
100+
cmOptions[SPACE_UNITS] = "indentUnit";
98101
cmOptions[STYLE_ACTIVE_LINE] = "styleActiveLine";
102+
cmOptions[TAB_SIZE] = "indentUnit";
103+
cmOptions[USE_TAB_CHAR] = "indentWithTabs";
99104
cmOptions[WORD_WRAP] = "lineWrapping";
100-
cmOptions[CLOSE_TAGS] = "autoCloseTags";
101105

102-
PreferencesManager.definePreference(SMART_INDENT, "boolean", true);
103-
PreferencesManager.definePreference(USE_TAB_CHAR, "boolean", false);
104-
PreferencesManager.definePreference(TAB_SIZE, "number", 4);
105-
PreferencesManager.definePreference(SPACE_UNITS, "number", 4);
106-
PreferencesManager.definePreference(CLOSE_BRACKETS, "boolean", false);
106+
PreferencesManager.definePreference(CLOSE_BRACKETS, "boolean", false);
107+
PreferencesManager.definePreference(CLOSE_TAGS, "Object", { whenOpening: true, whenClosing: true, indentTags: [] });
108+
PreferencesManager.definePreference(SCROLL_PAST_END, "boolean", false);
107109
PreferencesManager.definePreference(SHOW_LINE_NUMBERS, "boolean", true);
110+
PreferencesManager.definePreference(SMART_INDENT, "boolean", true);
111+
PreferencesManager.definePreference(SOFT_TABS, "boolean", true);
112+
PreferencesManager.definePreference(SPACE_UNITS, "number", 4);
108113
PreferencesManager.definePreference(STYLE_ACTIVE_LINE, "boolean", false);
109-
PreferencesManager.definePreference(WORD_WRAP, "boolean", true);
110-
PreferencesManager.definePreference(CLOSE_TAGS, "Object", { whenOpening: true, whenClosing: true, indentTags: [] });
114+
PreferencesManager.definePreference(TAB_SIZE, "number", 4);
115+
PreferencesManager.definePreference(USE_TAB_CHAR, "boolean", false);
116+
PreferencesManager.definePreference(WORD_WRAP, "boolean", true);
111117

112-
var editorOptions = [SMART_INDENT, USE_TAB_CHAR, TAB_SIZE, SPACE_UNITS, CLOSE_BRACKETS,
113-
SHOW_LINE_NUMBERS, STYLE_ACTIVE_LINE, WORD_WRAP, CLOSE_TAGS];
118+
var editorOptions = Object.keys(cmOptions);
114119

115120
/** Editor preferences */
116121

@@ -231,22 +236,23 @@ define(function (require, exports, module) {
231236
// Create the CodeMirror instance
232237
// (note: CodeMirror doesn't actually require using 'new', but jslint complains without it)
233238
this._codeMirror = new CodeMirror(container, {
234-
electricChars: false, // we use our own impl of this to avoid CodeMirror bugs; see _checkElectricChars()
235-
smartIndent: currentOptions[SMART_INDENT],
236-
indentWithTabs: currentOptions[USE_TAB_CHAR],
237-
tabSize: currentOptions[TAB_SIZE],
238-
indentUnit: currentOptions[USE_TAB_CHAR] ? currentOptions[TAB_SIZE] : currentOptions[SPACE_UNITS],
239-
lineNumbers: currentOptions[SHOW_LINE_NUMBERS],
240-
lineWrapping: currentOptions[WORD_WRAP],
241-
styleActiveLine: currentOptions[STYLE_ACTIVE_LINE],
242-
coverGutterNextToScrollbar: true,
243-
matchBrackets: true,
244-
matchTags: {bothTags: true},
245-
dragDrop: false,
246-
extraKeys: codeMirrorKeyMap,
247-
autoCloseBrackets: currentOptions[CLOSE_BRACKETS],
248-
autoCloseTags: currentOptions[CLOSE_TAGS],
249-
cursorScrollMargin: 3
239+
autoCloseBrackets : currentOptions[CLOSE_BRACKETS],
240+
autoCloseTags : currentOptions[CLOSE_TAGS],
241+
coverGutterNextToScrollbar : true,
242+
cursorScrollMargin : 3,
243+
dragDrop : false,
244+
electricChars : false, // we use our own impl of this to avoid CodeMirror bugs; see _checkElectricChars()
245+
extraKeys : codeMirrorKeyMap,
246+
indentUnit : currentOptions[USE_TAB_CHAR] ? currentOptions[TAB_SIZE] : currentOptions[SPACE_UNITS],
247+
indentWithTabs : currentOptions[USE_TAB_CHAR],
248+
lineNumbers : currentOptions[SHOW_LINE_NUMBERS],
249+
lineWrapping : currentOptions[WORD_WRAP],
250+
matchBrackets : true,
251+
matchTags : { bothTags: true },
252+
scrollPastEnd : !range && currentOptions[SCROLL_PAST_END],
253+
smartIndent : currentOptions[SMART_INDENT],
254+
styleActiveLine : currentOptions[STYLE_ACTIVE_LINE],
255+
tabSize : currentOptions[TAB_SIZE]
250256
});
251257

252258
// Can't get CodeMirror's focused state without searching for
@@ -513,7 +519,7 @@ define(function (require, exports, module) {
513519
var instance = this._codeMirror,
514520
overallJump = null;
515521

516-
if (!instance.getOption("indentWithTabs")) {
522+
if (!instance.getOption("indentWithTabs") && PreferencesManager.get(SOFT_TABS)) {
517523
var indentUnit = instance.getOption("indentUnit");
518524

519525
_.each(this.getSelections(), function (sel) {
@@ -1154,7 +1160,7 @@ define(function (require, exports, module) {
11541160
* @param {number} centerOptions Option value, or 0 for no options; one of the BOUNDARY_* constants above.
11551161
*/
11561162
Editor.prototype.setSelections = function (selections, center, centerOptions) {
1157-
var primIndex;
1163+
var primIndex = selections.length - 1;
11581164
this._codeMirror.setSelections(_.map(selections, function (sel, index) {
11591165
if (sel.primary) {
11601166
primIndex = index;
@@ -1835,6 +1841,7 @@ define(function (require, exports, module) {
18351841

18361842
if (oldValue !== newValue) {
18371843
this._currentOptions[prefName] = newValue;
1844+
var useTabChar = this._currentOptions[USE_TAB_CHAR];
18381845

18391846
if (prefName === USE_TAB_CHAR) {
18401847
this._codeMirror.setOption(cmOptions[prefName], newValue);
@@ -1844,15 +1851,13 @@ define(function (require, exports, module) {
18441851
);
18451852
} else if (prefName === STYLE_ACTIVE_LINE) {
18461853
this._updateStyleActiveLine();
1854+
} else if (prefName === SCROLL_PAST_END && this._visibleRange) {
1855+
// Do not apply this option to inline editors
1856+
return;
1857+
} else if ((useTabChar && prefName === SPACE_UNITS) || (!useTabChar && prefName === TAB_SIZE)) {
1858+
// This change conflicts with the useTabChar setting, so do not change the CodeMirror option
1859+
return;
18471860
} else {
1848-
// Set the CodeMirror option as long as it's not a change
1849-
// that is in conflict with the useTabChar setting.
1850-
var useTabChar = this._currentOptions[USE_TAB_CHAR];
1851-
if ((useTabChar && prefName === SPACE_UNITS) ||
1852-
(!useTabChar && prefName === TAB_SIZE)) {
1853-
return;
1854-
}
1855-
18561861
this._codeMirror.setOption(cmOptions[prefName], newValue);
18571862
}
18581863

src/preferences/PreferenceStorage.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ define(function (require, exports, module) {
218218
var rule = rules[key];
219219
if (!rule && prefCheckCallback) {
220220
rule = prefCheckCallback(key);
221+
} else if (prefCheckCallback) {
222+
// Check whether we have a new preference key-value pair
223+
// for an old preference.
224+
var newRule = prefCheckCallback(key, prefs[key]);
225+
if (newRule) {
226+
rule = _.cloneDeep(newRule);
227+
}
221228
}
222229
if (!rule) {
223230
console.warn("Preferences conversion for ", self._clientID, " has no rule for", key);
@@ -238,6 +245,11 @@ define(function (require, exports, module) {
238245
manager.set(newKey, prefs[key], options);
239246
convertedKeys.push(key);
240247
}
248+
} else if (_.isObject(rule)) {
249+
Object.keys(rule).forEach(function (ruleKey) {
250+
manager.set(ruleKey, rule[ruleKey]);
251+
});
252+
convertedKeys.push(key);
241253
} else {
242254
complete = false;
243255
}

src/styles/brackets_theme_default.less

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,8 @@
144144
*/
145145
.code-font() {
146146
color: @content-color;
147-
// line-height must be specified in px not em because the code font and line number font sizes are different.
148-
// Sizing via em will cause the code and line numbers to misalign
149-
line-height: 15px;
150147
font-size: 12px;
148+
line-height: 1.25;
151149
font-family: "SourceCodePro-Medium", "MS ゴシック", "MS Gothic", monospace;
152150
}
153151

src/thirdparty/CodeMirror2

src/utils/DeprecationWarning.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,35 @@ define(function (require, exports, module) {
5858
* Show deprecation message with the call stack if it
5959
* has never been displayed before.
6060
* @param {!string} message The deprecation message to be displayed.
61+
* @param {boolean=} oncePerCaller If true, displays the message once for each unique call location.
62+
* If false (the default), only displays the message once no matter where it's called from.
63+
* Note that setting this to true can cause a slight performance hit (because it has to generate
64+
* a stack trace), so don't set this for functions that you expect to be called from performance-
65+
* sensitive code (e.g. tight loops).
6166
*/
62-
function deprecationWarning(message) {
63-
// If we have displayed this message before, then don't
64-
// show it again.
65-
if (!message || displayedWarnings[message]) {
67+
function deprecationWarning(message, oncePerCaller) {
68+
// If oncePerCaller isn't set, then only show the message once no matter who calls it.
69+
if (!message || (!oncePerCaller && displayedWarnings[message])) {
6670
return;
6771
}
6872

69-
console.warn(message + "\n" + _trimStack(new Error().stack));
70-
displayedWarnings[message] = true;
73+
// Don't show the warning again if we've already gotten it from the current caller.
74+
// The true caller location is the fourth line in the stack trace:
75+
// * 0 is the word "Error"
76+
// * 1 is this function
77+
// * 2 is the caller of this function (the one throwing the deprecation warning)
78+
// * 3 is the actual caller of the deprecated function.
79+
var stack = new Error().stack,
80+
callerLocation = stack.split("\n")[3];
81+
if (oncePerCaller && displayedWarnings[message] && displayedWarnings[message][callerLocation]) {
82+
return;
83+
}
84+
85+
console.warn(message + "\n" + _trimStack(stack));
86+
if (!displayedWarnings[message]) {
87+
displayedWarnings[message] = {};
88+
}
89+
displayedWarnings[message][callerLocation] = true;
7190
}
7291

7392
// Define public API

0 commit comments

Comments
 (0)