Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

separate tab width and indentUnit settings

  • Loading branch information...
commit 8b807aa46bfeeb821e377fd2e44b3c5eee2f41af 1 parent 03b949b
@jasonsanjose jasonsanjose authored
Showing with 45 additions and 21 deletions.
  1. +38 −19 src/editor/Editor.js
  2. +7 −2 src/editor/EditorManager.js
View
57 src/editor/Editor.js
@@ -73,7 +73,19 @@ define(function (require, exports, module) {
ViewUtils = require("utils/ViewUtils");
var PREFERENCES_CLIENT_ID = "com.adobe.brackets.Editor",
- defaultPrefs = { useTabChar: false, tabSize: 4 };
+ defaultPrefs = { useTabChar: false, tabSize: 4, indentUnit: 4 };
+
+ /** 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 */
+ var _tabSize = _prefs.getValue("tabSize");
+
+ /** @type {boolean} Global setting: Indent unit (i.e. number of spaces when indenting) */
+ var _indentUnit = _prefs.getValue("indentUnit");
/**
* @private
@@ -121,7 +133,7 @@ define(function (require, exports, module) {
if (instance.getOption("indentWithTabs")) {
CodeMirror.commands.insertTab(instance);
} else {
- var i, ins = "", numSpaces = instance.getOption("tabSize");
+ var i, ins = "", numSpaces = _indentUnit;
numSpaces -= to.ch % numSpaces;
for (i = 0; i < numSpaces; i++) {
ins += " ";
@@ -143,12 +155,11 @@ define(function (require, exports, module) {
var handled = false;
if (!instance.getOption("indentWithTabs")) {
var cursor = instance.getCursor(),
- tabSize = instance.getOption("tabSize"),
- jump = cursor.ch % tabSize,
+ jump = cursor.ch % _indentUnit,
line = instance.getLine(cursor.line);
if (direction === 1) {
- jump = tabSize - jump;
+ jump = _indentUnit - jump;
if (cursor.ch + jump > line.length) { // Jump would go beyond current line
return false;
@@ -167,7 +178,7 @@ define(function (require, exports, module) {
// If we are on the tab boundary, jump by the full amount,
// but not beyond the start of the line.
if (jump === 0) {
- jump = tabSize;
+ jump = _indentUnit;
}
// Search backwards to the first non-space character
@@ -228,9 +239,6 @@ define(function (require, exports, module) {
}
}
- /** Editor preferences */
- var _prefs = PreferencesManager.getPreferenceStorage(PREFERENCES_CLIENT_ID, defaultPrefs);
-
/**
* List of all current (non-destroy()ed) Editor instances. Needed when changing global preferences
* that affect all editors, e.g. tabbing or color scheme settings.
@@ -238,12 +246,6 @@ define(function (require, exports, module) {
*/
var _instances = [];
- /** @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 */
- var _tabSize = _prefs.getValue("tabSize");
-
/**
* @constructor
@@ -340,6 +342,7 @@ define(function (require, exports, module) {
electricChars: false, // we use our own impl of this to avoid CodeMirror bugs; see _checkElectricChars()
indentWithTabs: _useTabChar,
tabSize: _tabSize,
+ indentUnit: _indentUnit,
lineNumbers: true,
matchBrackets: true,
dragDrop: false, // work around issue #1123
@@ -1077,7 +1080,6 @@ define(function (require, exports, module) {
editor._codeMirror.setOption("indentWithTabs", _useTabChar);
});
- // Remember the setting across launches
_prefs.setValue("useTabChar", Boolean(_useTabChar));
};
@@ -1087,7 +1089,7 @@ define(function (require, exports, module) {
};
/**
- * Sets tab size for both tab and space indentation. Affects all Editors.
+ * Sets tab character width. Affects all Editors.
* @param {number} value
*/
Editor.setTabSize = function (value) {
@@ -1096,14 +1098,31 @@ define(function (require, exports, module) {
editor._codeMirror.setOption("tabSize", _tabSize);
});
- // Remember the setting across launches
_prefs.setValue("tabSize", _tabSize);
};
- /** @type {number} Get */
+ /** @type {number} Get indent unit */
Editor.getTabSize = function (value) {
return _tabSize;
};
+
+ /**
+ * Sets indentation width. Affects all Editors.
+ * @param {number} value
+ */
+ Editor.setIndentUnit = function (value) {
+ _indentUnit = value;
+ _instances.forEach(function (editor) {
+ editor._codeMirror.setOption("indentUnit", _indentUnit);
+ });
+
+ _prefs.setValue("indentUnit", _indentUnit);
+ };
+
+ /** @type {number} Get indentation width */
+ Editor.getIndentUnit = function (value) {
+ return _indentUnit;
+ };
// Global commands that affect the currently focused Editor instance, wherever it may be
CommandManager.register(Strings.CMD_SELECT_ALL, Commands.EDIT_SELECT_ALL, _handleSelectAll);
View
9 src/editor/EditorManager.js
@@ -595,16 +595,21 @@ define(function (require, exports, module) {
}
function _updateIndentSize(inc) {
- $indentWidth.text(Editor.getTabSize());
+ $indentWidth.text(Editor.getUseTabChar() ? Editor.getTabSize() : Editor.getIndentUnit());
}
function _toggleIndentType() {
Editor.setUseTabChar(!Editor.getUseTabChar());
_updateIndentType();
+ _updateIndentSize();
}
function _changeIndentSize(inc) {
- Editor.setTabSize(Editor.getTabSize() + inc);
+ if (Editor.getUseTabChar()) {
+ Editor.setTabSize(Editor.getTabSize() + inc);
+ } else {
+ Editor.setIndentUnit(Editor.getIndentUnit() + inc);
+ }
_updateIndentSize();
}
Please sign in to comment.
Something went wrong with that request. Please try again.