-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Adding the CodeMirror built-in Auto Close Brackets addon #3040
Changes from all commits
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 |
---|---|---|
|
@@ -73,20 +73,23 @@ define(function (require, exports, module) { | |
ViewUtils = require("utils/ViewUtils"); | ||
|
||
var PREFERENCES_CLIENT_ID = "com.adobe.brackets.Editor", | ||
defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4 }; | ||
defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4, closeBrackets: false }; | ||
|
||
/** Editor preferences */ | ||
var _prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, defaultPrefs); | ||
|
||
/** @type {boolean} Global setting: When inserting new text, use tab characters? (instead of spaces) */ | ||
var _useTabChar = _prefs.getValue("useTabChar"); | ||
|
||
/** @type {boolean} Global setting: Tab size */ | ||
/** @type {number} Global setting: Tab size */ | ||
var _tabSize = _prefs.getValue("tabSize"); | ||
|
||
/** @type {boolean} Global setting: Indent unit (i.e. number of spaces when indenting) */ | ||
/** @type {number} Global setting: Indent unit (i.e. number of spaces when indenting) */ | ||
var _indentUnit = _prefs.getValue("indentUnit"); | ||
|
||
/** @type {boolean} Global setting: Auto closes (, {, [, " and ' */ | ||
var _closeBrackets = _prefs.getValue("closeBrackets"); | ||
|
||
/** @type {boolean} Guard flag to prevent focus() reentrancy (via blur handlers), even across Editors */ | ||
var _duringFocus = false; | ||
|
||
|
@@ -345,6 +348,7 @@ define(function (require, exports, module) { | |
matchBrackets: true, | ||
dragDrop: false, // work around issue #1123 | ||
extraKeys: codeMirrorKeyMap, | ||
autoCloseBrackets: _closeBrackets, | ||
autoCloseTags: { | ||
whenOpening: true, | ||
whenClosing: true, | ||
|
@@ -1301,7 +1305,7 @@ define(function (require, exports, module) { | |
}; | ||
|
||
/** @type {boolean} Gets whether all Editors use tab characters (vs. spaces) when inserting new text */ | ||
Editor.getUseTabChar = function (value) { | ||
Editor.getUseTabChar = function () { | ||
return _useTabChar; | ||
}; | ||
|
||
|
@@ -1319,7 +1323,7 @@ define(function (require, exports, module) { | |
}; | ||
|
||
/** @type {number} Get indent unit */ | ||
Editor.getTabSize = function (value) { | ||
Editor.getTabSize = function () { | ||
return _tabSize; | ||
}; | ||
|
||
|
@@ -1337,10 +1341,28 @@ define(function (require, exports, module) { | |
}; | ||
|
||
/** @type {number} Get indentation width */ | ||
Editor.getIndentUnit = function (value) { | ||
Editor.getIndentUnit = function () { | ||
return _indentUnit; | ||
}; | ||
|
||
/** | ||
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. Did you mean to remove the newline at the end of the document? I, personally, prefer to have them in, so unless this is required, I think it should be restored. 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. Not really, to update the file to the latest version, I copied the new version from Github and added my modifications again, just to make sure I didn't make any mistakes in the merge (since the automatic merge didnt worked in this file). So it was removed in that copy paste. I can added it again. |
||
* Sets the auto close brackets. Affects all Editors. | ||
* @param {boolean} value | ||
*/ | ||
Editor.setCloseBrackets = function (value) { | ||
_closeBrackets = value; | ||
_instances.forEach(function (editor) { | ||
editor._codeMirror.setOption("autoCloseBrackets", _closeBrackets); | ||
}); | ||
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. @RaymondLim I think you're researching preferences: Is this ok if changing the setting updates all editor windows? I think most other settings only update the current window. 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. All 3 tab/space indentation settings update all the editors, which is ok since are global settings. Close brackets is also a global setting, so I believe that they should change the settings on all the open instances. If it changes only one instance, it needs to became a local setting and would need to be setted for each instance, which doesn't sound great. 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. Yes, it is the right way to go. We want to update all instances of editor in the same Brackets window so that we will have consistent setting among all the editors (inline or a different editor when switching documents in the working set or opening new one from Search panel or JSLint panel). |
||
|
||
_prefs.setValue("closeBrackets", Boolean(_closeBrackets)); | ||
}; | ||
|
||
/** @type {boolean} Gets whether all Editors use auto close brackets */ | ||
Editor.getCloseBrackets = function () { | ||
return _closeBrackets; | ||
}; | ||
|
||
// Define public API | ||
exports.Editor = Editor; | ||
exports.BOUNDARY_CHECK_NORMAL = BOUNDARY_CHECK_NORMAL; | ||
|
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 for the code cleanup!